%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/launchpadlib/tests/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/launchpadlib/tests/__pycache__/test_http.cpython-312.pyc

�

'[�a�$��T�dZddlmZddlmZddlZddlZ	ddlmZddl
mZddlm
Z
ddlmZmZdd	lmZd
Zei�j)d�ZGd�d
�ZGd�de�ZGd�de�ZGd�dej2�ZGd�de�ZGd�de�Zy#e$re	ZY��wxYw)z,Tests for the LaunchpadOAuthAwareHTTP class.�)�deque)�dumpsN)�JSONDecodeError)�Unauthorized)�UnencryptedFileCredentialStore)�	Launchpad�LaunchpadOAuthAwareHttp)�NoNetworkAuthorizationEngines�<?xml version="1.0"?>
<application xmlns="http://research.sun.com/wadl/2006/10">
  <resources base="http://www.example.com/">
    <resource path="" type="#service-root"/>
  </resources>

  <resource_type id="service-root">
    <method name="GET" id="service-root-get">
      <response>
        <representation href="#service-root-json"/>
      </response>
    </method>
  </resource_type>

  <representation id="service-root-json" mediaType="application/json"/>
</application>
zutf-8c��eZdZdZd�Zy)�ResponsezA fake HTTP response object.c� �||_||_y�N)�status�content)�selfrrs   �>/usr/lib/python3/dist-packages/launchpadlib/tests/test_http.py�__init__zResponse.__init__@s��������N)�__name__�
__module__�__qualname__�__doc__r�rrrr=s
��&�rrc�(��eZdZdZ�fd�Zd�Z�xZS)�SimulatedResponsesHttpz<Responds to HTTP requests by shifting responses off a stack.c�P��tt|�
|�g|_||_d|_y)z{Constructor.

        :param responses: A list of HttpResponse objects to use
            in response to requests.
        N)�superrr�sent_responses�unsent_responses�cache)r�	responses�args�	__class__s   �rrzSimulatedResponsesHttp.__init__Hs,���	�$�d�4�d�;� ��� )�����
rc��|jj�}|jj|�|j||j
g|���Sr)r�popleftr�append�retry_on_bad_tokenr)rr"�responses   r�_requestzSimulatedResponsesHttp._requestSsJ���(�(�0�0�2�����"�"�8�,�&�t�&�&�x��1A�1A�I�D�I�Ir)rrrrrr)�
__classcell__)r#s@rrrEs���F�	�Jrrc�&�eZdZgZd�Zed��Zy)�SimulatedResponsesLaunchpadc�X�tt|j�||jg|���Sr)rrr!�authorization_engine)rr"s  r�httpFactoryz'SimulatedResponsesLaunchpad.httpFactory_s-��%��$�.�.�!�4��)B�)B�
�EI�
�	
rc�D�ttj�d|�S)N�)r�tempfile�mkstemp)�cls�credential_save_faileds  r�credential_store_factoryz4SimulatedResponsesLaunchpad.credential_store_factoryds#��-�����q�!�#9�
�	
rN)rrrr!r/�classmethodr6rrrr,r,Ys"���I�
�
�
��
rr,c��eZdZdZd�Zd�Zy)�SimulatedResponsesTestCasezATest cases that give fake responses to launchpad's HTTP requests.c�<�gt_tdd�|_y)z*Clear out the list of simulated responses.zhttp://api.example.com/�application nameN)r,r!r
�engine�rs r�setUpz SimulatedResponsesTestCase.setUpns��02�#�-�2�%�'9�
��rc�Z�|t_tjd|j��S)aqUse simulated HTTP responses to get a Launchpad object.

        The given Response objects will be sent, in order, in response
        to launchpadlib's requests.

        :param responses: Some number of Response objects.
        :return: The Launchpad object, assuming that errors in the
            simulated requests didn't prevent one from being created.
        r;�r.)r,r!�
login_withr<)rr!s  r�launchpad_with_responsesz3SimulatedResponsesTestCase.launchpad_with_responsesus.��1:�#�-�*�5�5��T�[�[�6�
�	
rN)rrrrr>rBrrrr9r9ks��K�
�

rr9c�"�eZdZdZd�Zd�Zd�Zy)�TestAbilityToParseDataa_Test launchpadlib's ability to handle the sample data.

    To create a Launchpad object, two HTTP requests must succeed and
    return usable data: the requests for the WADL and JSON
    representations of the service root. This test shows that the
    minimal data in SIMPLE_WADL and SIMPLE_JSON is good enough to
    create a Launchpad object.
    c�`�|jtdt�tdt��y)z5Make sure that launchpadlib can use the minimal data.��N)rBr�SIMPLE_WADL�SIMPLE_JSONr=s r�test_minimal_dataz(TestAbilityToParseData.test_minimal_data�s#���%�%��S�+�&���k�(B�	
rc	�x�|jt|jtdd�tdt��y)z'Show that bad WADL causes an exception.rFsThis is not WADL.N)�assertRaises�SyntaxErrorrBrrHr=s r�
test_bad_wadlz$TestAbilityToParseData.test_bad_wadl�s1�������)�)��S�.�/��S�+�&�		
rc	�x�|jt|jtdt�tdd��y)z'Show that bad JSON causes an exception.rFsThis is not JSON.N)rKrrBrrGr=s r�
test_bad_jsonz$TestAbilityToParseData.test_bad_json�s1�������)�)��S�+�&��S�.�/�		
rN)rrrrrIrMrOrrrrDrD�s���
�
�
rrDc�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�TestTokenFailureDuringRequestaTest access token failures during a request.

    launchpadlib makes two HTTP requests on startup, to get the WADL
    and JSON representations of the service root. If Launchpad
    receives a 401 error during this process, it will acquire a fresh
    access token and try again.
    c�0�tdt�tdt�gt_|j|jjd�tjd|j��|j|jjd�y)z/If our token is good, we never get another one.rFrr;r@r1N�	rrGrHr,r!�assertEqualr<�access_tokens_obtainedrAr=s r�test_good_tokenz-TestTokenFailureDuringRequest.test_good_token�sw��
�S�+�&��S�+�&�1
�#�-�
	
������;�;�Q�?�#�.�.��T�[�[�	/�	
�	
������;�;�Q�?rc�F�tdd�tdt�tdt�gt_|j|jjd�tjd|j��|j|jjd�y)	z(If our token is bad, we get another one.��Invalid token.rFrr;r@�NrSr=s r�test_bad_tokenz,TestTokenFailureDuringRequest.test_bad_token�s���
�S�+�,��S�+�&��S�+�&�1
�#�-�	
������;�;�Q�?�#�.�.��T�[�[�	/�	
�	
������;�;�Q�?rc�F�tdd�tdt�tdt�gt_|j|jjd�tjd|j��|j|jjd�y)	z,If our token is expired, we get another one.rX�Expired token.rFrr;r@rZNrSr=s r�test_expired_tokenz0TestTokenFailureDuringRequest.test_expired_token�s���
�S�+�,��S�+�&��S�+�&�1
�#�-�	
������;�;�Q�?�#�.�.��T�[�[�	/�	
�	
������;�;�Q�?rc�F�tdd�tdt�tdt�gt_|j|jjd�tjd|j��|j|jjd�y)	z,If our token is unknown, we get another one.rXsUnknown access token.rFrr;r@rZNrSr=s r�test_unknown_tokenz0TestTokenFailureDuringRequest.test_unknown_token�s���
�S�2�3��S�+�&��S�+�&�1
�#�-�	
������;�;�Q�?�#�.�.��T�[�[�	/�	
�	
������;�;�Q�?rc�F�tdt�tdd�tdt�gt_|j|jjd�tjd|j��|j|jjd�y)	z6We get another token no matter when the error happens.rFrXr]rr;r@rZNrSr=s r�test_delayed_errorz0TestTokenFailureDuringRequest.test_delayed_error�s���
�S�+�&��S�+�,��S�+�&�1
�#�-�	
������;�;�Q�?�#�.�.��T�[�[�	/�	
�	
������;�;�Q�?rc�r�tdd�tdt�tdd�tdd�tdt�gt_|j|jjd�tjd|j��|j|jjd�y	)
z@We'll keep getting new tokens as long as tokens are the problem.rXrYrFr]rr;r@�NrSr=s r�test_many_errorsz.TestTokenFailureDuringRequest.test_many_errors�s���
�S�+�,��S�+�&��S�+�,��S�+�,��S�+�&�1
�#�-�	
������;�;�Q�?�#�.�.��T�[�[�	/�	
�	
������;�;�Q�?rc��tdd�gt_|jttj
d|j��y)z>If the token is not at fault, a 401 error raises an exception.rXsSome other error.r;r@N)rr,r!rKrrAr<r=s r�test_other_unauthorizedz5TestTokenFailureDuringRequest.test_other_unauthorizedsE��
�S�.�/�1
�#�-�	
����'�2�2��!%���		�	
rN)rrrrrVr[r^r`rbrergrrrrQrQ�s0���@�@�
@�
@�@�
@�
rrQ)r�collectionsr�jsonrr2�unittestr�ImportError�
ValueError�launchpadlib.errorsr�launchpadlib.credentialsr�launchpadlib.launchpadrr	�launchpadlib.testing.helpersr
rG�encoderHrrr,�TestCaser9rDrQrrr�<module>rss���"3�����!�$�-�C��F���&�B�i���w�'����J�4�J�(
�)�
�$
��!2�!2�
�4 
�7� 
�Fk
�$>�k
��]�!� �O�!�s�B�B'�&B'

Zerion Mini Shell 1.0