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
   ZassertIsNoneZ
assertTrue
isinstanceZassertEqualcontent)r   r   Zexpected_errorr   Z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*   r+   r,   r-   r.   r/   r   r   r   r   r   #   s    

r   )r   typeZ__metaclass__ZunittestZlazr.restfulclient.errorsr   r   r   r   r   r   r   r	   r
   objectr   ZTestCaser   r   r   r   r   <module>   s   ,