HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/lib/python3/dist-packages/launchpadlib/tests/__pycache__/test_http.cpython-38.pyc
U

�ܛU&$�@sdZddlmZddlZddlZzddlmZeZWn$e	k
rXddl
mZmZYnXddlmZddl
mZddlmZmZdd	lmZd
Zei��d�ZGdd
�d
�ZGdd�de�ZGdd�de�ZGdd�dej�ZGdd�de�ZGdd�de�ZdS)z,Tests for the LaunchpadOAuthAwareHTTP class.�)�dequeN)�dumps)r�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@seZdZdZdd�ZdS)�ResponsezA fake HTTP response object.cCs||_||_dS�N)�status�content)�selfrr
�r�>/usr/lib/python3/dist-packages/launchpadlib/tests/test_http.py�__init__?szResponse.__init__N)�__name__�
__module__�__qualname__�__doc__rrrrrr
=sr
cs(eZdZdZ�fdd�Zdd�Z�ZS)�SimulatedResponsesHttpz<Responds to HTTP requests by shifting responses off a stack.cs&tt|�j|�g|_||_d|_dS)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__rrrGszSimulatedResponsesHttp.__init__cGs*|j��}|j�|�|j||jf|��Sr)r�popleftr�appendZretry_on_bad_tokenr
)rrZresponserrr�_requestRs
zSimulatedResponsesHttp._request)rrrrrr!�
__classcell__rrrrrDsrc@s$eZdZgZdd�Zedd��ZdS)�SimulatedResponsesLaunchpadcGstt|j�||jf|��Sr)rrr�authorization_engine)rrrrr�httpFactory^s��z'SimulatedResponsesLaunchpad.httpFactorycCstt��d|�S)N�)r�tempfileZmkstemp)�clsZcredential_save_failedrrr�credential_store_factorybs
�z4SimulatedResponsesLaunchpad.credential_store_factoryN)rrrrr%�classmethodr)rrrrr#Xsr#c@s eZdZdZdd�Zdd�ZdS)�SimulatedResponsesTestCasezATest cases that give fake responses to launchpad's HTTP requests.cCsgt_tdd�|_dS)z*Clear out the list of simulated responses.zhttp://api.example.com/�application nameN)r#rr	�engine�rrrr�setUpks
�z SimulatedResponsesTestCase.setUpcGs|t_tjd|jd�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-)rrrrr�launchpad_with_responsesqs

�z3SimulatedResponsesTestCase.launchpad_with_responsesN)rrrrr/r2rrrrr+hsr+c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�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.
    cCs|�tdt�tdt��dS)z5Make sure that launchpadlib can use the minimal data.��N)r2r
�SIMPLE_WADL�SIMPLE_JSONr.rrr�test_minimal_data�s�z(TestAbilityToParseData.test_minimal_datacCs"|�t|jtdd�tdt��dS)z'Show that bad WADL causes an exception.r4sThis is not WADL.N)�assertRaises�SyntaxErrorr2r
r6r.rrr�
test_bad_wadl�s�z$TestAbilityToParseData.test_bad_wadlcCs"|�t|jtdt�tdd��dS)z'Show that bad JSON causes an exception.r4sThis is not JSON.N)r8rr2r
r5r.rrr�
test_bad_json�s�z$TestAbilityToParseData.test_bad_jsonN)rrrrr7r:r;rrrrr3�s	r3c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�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.
    cCsJtdt�tdt�gt_|�|jjd�tjd|jd�|�|jjd�dS)z/If our token is good, we never get another one.r4rr,r0r&N�	r
r5r6r#rZassertEqualr-Zaccess_tokens_obtainedr1r.rrr�test_good_token�s��z-TestTokenFailureDuringRequest.test_good_tokencCsRtdd�tdt�tdt�gt_|�|jjd�tjd|jd�|�|jjd�dS)	z(If our token is bad, we get another one.��Invalid token.r4rr,r0�Nr=r.rrr�test_bad_token�s��z,TestTokenFailureDuringRequest.test_bad_tokencCsRtdd�tdt�tdt�gt_|�|jjd�tjd|jd�|�|jjd�dS)	z,If our token is expired, we get another one.r?�Expired token.r4rr,r0rANr=r.rrr�test_expired_token�s��z0TestTokenFailureDuringRequest.test_expired_tokencCsRtdd�tdt�tdt�gt_|�|jjd�tjd|jd�|�|jjd�dS)	z,If our token is unknown, we get another one.r?sUnknown access token.r4rr,r0rANr=r.rrr�test_unknown_token�s��z0TestTokenFailureDuringRequest.test_unknown_tokencCsRtdt�tdd�tdt�gt_|�|jjd�tjd|jd�|�|jjd�dS)	z6We get another token no matter when the error happens.r4r?rCrr,r0rANr=r.rrr�test_delayed_error�s��z0TestTokenFailureDuringRequest.test_delayed_errorcCsbtdd�tdt�tdd�tdd�tdt�gt_|�|jjd�tjd|jd�|�|jjd�d	S)
z@We'll keep getting new tokens as long as tokens are the problem.r?r@r4rCrr,r0�Nr=r.rrr�test_many_errors�s��z.TestTokenFailureDuringRequest.test_many_errorscCs(tdd�gt_|jttjd|jd�dS)z>If the token is not at fault, a 401 error raises an exception.r?sSome other error.r,r0N)r
r#rr8rr1r-r.rrr�test_other_unauthorized�s��z5TestTokenFailureDuringRequest.test_other_unauthorizedN)rrrrr>rBrDrErFrHrIrrrrr<�s


r<)r�collectionsrr'ZunittestZjsonr�
ValueErrorr�ImportErrorZ
simplejsonZlaunchpadlib.errorsrZlaunchpadlib.credentialsrZlaunchpadlib.launchpadrrZlaunchpadlib.testing.helpersr	r5�encoder6r
rr#ZTestCaser+r3r<rrrr�<module>s(