o
    ¹Š%U  ã                   @   sb   d Z eZddlZddlmZmZmZmZm	Z	m
Z
mZmZmZ G dd„ deƒZG dd„ dejƒZdS )z(Tests for the error_for helper function.é    N)	ÚClientErrorÚConflictÚMethodNotAllowedÚNotFoundÚPreconditionFailedÚResponseErrorÚServerErrorÚUnauthorizedÚ	error_forc                   @   s   e Zd ZdZdd„ ZdS )ÚDummyRequestz-Just enough of a request to fool error_for().c                 C   s
   || _ d S )N)Ústatus©Úselfr   © r   úE/usr/lib/python3/dist-packages/lazr/restfulclient/tests/test_error.pyÚ__init__   s   
zDummyRequest.__init__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s    r   c                   @   sf   e Zd Zddd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )ÚTestErrorForÚ c                 C   sJ   t |ƒ}t||ƒ}|du r|  |¡ dS |  t||ƒ¡ |  ||j¡ dS )z9Make sure error_for returns the right HTTPError subclass.N)r   r
   ÚassertIsNoneÚ
assertTrueÚ
isinstanceÚassertEqualÚcontent)r   r   Úexpected_errorr   ÚrequestÚerrorr   r   r   Úerror_for_status%   s   
zTestErrorFor.error_for_statusc                 C   ó   dD ]}|   |d¡ qdS )z.Make sure a 2xx response code yields no error.)éÈ   éÉ   éÑ   i+  N©r    r   r   r   r   Útest_no_error_for_2xx/   ó   ÿz"TestErrorFor.test_no_error_for_2xxc                 C   r!   )z.Make sure a 3xx response code yields no error.)i-  i.  i/  i0  i�  Nr%   r   r   r   r   Útest_no_error_for_3xx4   r'   z"TestErrorFor.test_no_error_for_3xxc                 C   ó   |   dtd¡ dS )z3Make sure a 400 response code yields ResponseError.i�  úerror messageN)r    r   ©r   r   r   r   Útest_error_for_4009   ó   zTestErrorFor.test_error_for_400c                 C   r)   )z2Make sure a 401 response code yields Unauthorized.i‘  r*   N)r    r	   r+   r   r   r   Útest_error_for_401=   r-   zTestErrorFor.test_error_for_401c                 C   r)   )z/Make sure a 404 response code yields Not Found.i”  r*   N)r    r   r+   r   r   r   Útest_error_for_404A   r-   zTestErrorFor.test_error_for_404c                 C   r)   )z6Make sure a 405 response code yields MethodNotAllowed.i•  r*   N)r    r   r+   r   r   r   Útest_error_for_405E   r-   zTestErrorFor.test_error_for_405c                 C   r)   )z.Make sure a 409 response code yields Conflict.i™  r*   N)r    r   r+   r   r   r   Útest_error_for_409I   r-   zTestErrorFor.test_error_for_409c                 C   r)   )z8Make sure a 412 response code yields PreconditionFailed.iœ  r*   N)r    r   r+   r   r   r   Útest_error_for_412M   r-   zTestErrorFor.test_error_for_412c                 C   r)   )z?Make sure an unrexognized 4xx response code yields ClientError.ió  r*   N)r    r   r+   r   r   r   Útest_error_for_4xxQ   r-   zTestErrorFor.test_error_for_4xxc                 C   s   dD ]}|   |t¡ qdS )z2Make sure a 5xx response codes yields ServerError.)iô  iö  i÷  iW  N)r    r   r   r   r   r   Útest_no_error_for_5xxU   r'   z"TestErrorFor.test_no_error_for_5xxN)r   )r   r   r   r    r&   r(   r,   r.   r/   r0   r1   r2   r3   r4   r   r   r   r   r   #   s    

r   )r   ÚtypeÚ__metaclass__ÚunittestÚlazr.restfulclient.errorsr   r   r   r   r   r   r   r	   r
   Úobjectr   ÚTestCaser   r   r   r   r   Ú<module>   s   ,