U
    %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   sH   t |}t||}|dkr&| | n| 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   s   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/   s    z"TestErrorFor.test_no_error_for_2xxc                 C   s   dD ]}|  |d qdS )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   s    z"TestErrorFor.test_no_error_for_3xxc                 C   s   |  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   s    zTestErrorFor.test_error_for_400c                 C   s   |  dtd dS )z2Make sure a 401 response code yields Unauthorized.i  r"   N)r   r	   r#   r   r   r   test_error_for_401=   s    zTestErrorFor.test_error_for_401c                 C   s   |  dtd dS )z/Make sure a 404 response code yields Not Found.i  r"   N)r   r   r#   r   r   r   test_error_for_404A   s    zTestErrorFor.test_error_for_404c                 C   s   |  dtd dS )z6Make sure a 405 response code yields MethodNotAllowed.i  r"   N)r   r   r#   r   r   r   test_error_for_405E   s    zTestErrorFor.test_error_for_405c                 C   s   |  dtd dS )z.Make sure a 409 response code yields Conflict.i  r"   N)r   r   r#   r   r   r   test_error_for_409I   s    zTestErrorFor.test_error_for_409c                 C   s   |  dtd dS )z8Make sure a 412 response code yields PreconditionFailed.i  r"   N)r   r   r#   r   r   r   test_error_for_412M   s    zTestErrorFor.test_error_for_412c                 C   s   |  dtd dS )z?Make sure an unrexognized 4xx response code yields ClientError.i  r"   N)r   r   r#   r   r   r   test_error_for_4xxQ   s    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   s    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
   ,