+
    Z4i$                     2   R t ^ RIHt ^ RIHtHt ^ RIt^ RIt^ RIH	t	 ^ RI
Ht ^ RIHtHt ^ RIHt Rt]! / 4      P%                  R	4      t ! R
 R4      t ! R R]4      t ! R R]4      t ! R R]P.                  4      t ! R R]4      t ! R R]4      tR# )z,Tests for the LaunchpadOAuthAwareHTTP class.)deque)dumpsJSONDecodeErrorN)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>
zutf-8c                   *   a  ] tR t^8t o RtR tRtV tR# )ResponsezA fake HTTP response object.c                    Wn         W n        R # N)statuscontent)selfr   r   s   &&&>/usr/lib/python3/dist-packages/launchpadlib/tests/test_http.py__init__Response.__init__;   s        )r   r   N)__name__
__module____qualname____firstlineno____doc__r   __static_attributes____classdictcell____classdict__s   @r   r   r   8   s     & r   r   c                   <   a a ] tR t^@t oRtV 3R ltR tRtVtV ;t	# )SimulatedResponsesHttpz<Responds to HTTP requests by shifting responses off a stack.c                L   < \         SV `  ! V!   . V n        Wn        RV n        R# )zcConstructor.

:param responses: A list of HttpResponse objects to use
    in response to requests.
N)superr   sent_responsesunsent_responsescache)r   	responsesargs	__class__s   &&*r   r   SimulatedResponsesHttp.__init__C   s'     	$  )
r   c                    V P                   P                  4       pV P                  P                  V4       V P                  ! W"P
                  .VO5!  # r   )r#   popleftr"   appendretry_on_bad_tokenr   )r   r&   responses   &* r   _requestSimulatedResponsesHttp._requestN   sF    ((002""8,&&x1A1AIDIIr   )r$   r"   r#   )
r   r   r   r   r   r   r.   r   r   __classcell__)r'   r   s   @@r   r   r   @   s     F	J Jr   r   c                   :   a  ] tR t^Tt o . tR t]R 4       tRtV t	R# )SimulatedResponsesLaunchpadc                X    \        \        V P                  4      W P                  .VO5!  # r   )r   r   r%   authorization_engine)r   r&   s   &*r   httpFactory'SimulatedResponsesLaunchpad.httpFactoryZ   s+    %$..!4)B)B
EI
 	
r   c                N    \        \        P                  ! 4       ^,          V4      # )   )r   tempfilemkstemp)clscredential_save_faileds   &&r   credential_store_factory4SimulatedResponsesLaunchpad.credential_store_factory_   s#    -q!#9
 	
r    N)
r   r   r   r   r%   r5   classmethodr=   r   r   r   s   @r   r2   r2   T   s%      I

 
 
r   r2   c                   0   a  ] tR t^ft o RtR tR tRtV tR# )SimulatedResponsesTestCasezATest cases that give fake responses to launchpad's HTTP requests.c                >    . \         n        \        RR4      V n        R# )z*Clear out the list of simulated responses.zhttp://api.example.com/application nameN)r2   r%   r	   enginer   s   &r   setUp SimulatedResponsesTestCase.setUpi   s    02#-2%'9
r   c                Z    V\         n        \         P                  RV P                  R7      # )aA  Use 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.
rD   r4   )r2   r%   
login_withrE   )r   r%   s   &*r   launchpad_with_responses3SimulatedResponsesTestCase.launchpad_with_responsesp   s.     1:#-*55T[[ 6 
 	
r   )rE   N)	r   r   r   r   r   rG   rL   r   r   r   s   @r   rB   rB   f   s     K

 
r   rB   c                   6   a  ] tR t^t o RtR tR tR tRtV t	R# )TestAbilityToParseDataaG  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                b    V P                  \        ^\        4      \        ^\        4      4       R# )z5Make sure that launchpadlib can use the minimal data.N)rL   r   SIMPLE_WADLSIMPLE_JSONrF   s   &r   test_minimal_data(TestAbilityToParseData.test_minimal_data   s#    %%S+&k(B	
r   c           	     z    V P                  \        V P                  \        ^R4      \        ^\        4      4       R# )z'Show that bad WADL causes an exception.s   This is not WADL.N)assertRaisesSyntaxErrorrL   r   rR   rF   s   &r   test_bad_wadl$TestAbilityToParseData.test_bad_wadl   s1    ))S./S+&		
r   c           	     z    V P                  \        V P                  \        ^\        4      \        ^R4      4       R# )z'Show that bad JSON causes an exception.s   This is not JSON.N)rV   r   rL   r   rQ   rF   s   &r   test_bad_json$TestAbilityToParseData.test_bad_json   s1    ))S+&S./		
r   r?   N)
r   r   r   r   r   rS   rX   r[   r   r   r   s   @r   rO   rO      s     


 
r   rO   c                   N   a  ] tR t^t o RtR tR tR tR tR t	R t
R tR	tV tR
# )TestTokenFailureDuringRequesta  Test 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                2   \        ^\        4      \        ^\        4      .\        n        V P                  V P                  P                  ^ 4       \        P                  RV P                  R7       V P                  V P                  P                  ^4       R# )z/If our token is good, we never get another one.rD   rJ   N	r   rQ   rR   r2   r%   assertEqualrE   access_tokens_obtainedrK   rF   s   &r   test_good_token-TestTokenFailureDuringRequest.test_good_token   sw     S+&S+&1
#-
 	;;Q?#..T[[ 	/ 	
 	;;Q?r   c                H   \        RR4      \        ^\        4      \        ^\        4      .\        n        V P                  V P                  P                  ^ 4       \        P                  RV P                  R7       V P                  V P                  P                  ^4       R# )z(If our token is bad, we get another one.     Invalid token.rD   rJ   Nr`   rF   s   &r   test_bad_token,TestTokenFailureDuringRequest.test_bad_token   s     S+,S+&S+&1
#- 	;;Q?#..T[[ 	/ 	
 	;;Q?r   c                H   \        RR4      \        ^\        4      \        ^\        4      .\        n        V P                  V P                  P                  ^ 4       \        P                  RV P                  R7       V P                  V P                  P                  ^4       R# )z,If our token is expired, we get another one.rf      Expired token.rD   rJ   Nr`   rF   s   &r   test_expired_token0TestTokenFailureDuringRequest.test_expired_token   s     S+,S+&S+&1
#- 	;;Q?#..T[[ 	/ 	
 	;;Q?r   c                H   \        RR4      \        ^\        4      \        ^\        4      .\        n        V P                  V P                  P                  ^ 4       \        P                  RV P                  R7       V P                  V P                  P                  ^4       R# )z,If our token is unknown, we get another one.rf   s   Unknown access token.rD   rJ   Nr`   rF   s   &r   test_unknown_token0TestTokenFailureDuringRequest.test_unknown_token   s     S23S+&S+&1
#- 	;;Q?#..T[[ 	/ 	
 	;;Q?r   c                H   \        ^\        4      \        RR4      \        ^\        4      .\        n        V P                  V P                  P                  ^ 4       \        P                  RV P                  R7       V P                  V P                  P                  ^4       R# )z6We get another token no matter when the error happens.rf   rk   rD   rJ   Nr`   rF   s   &r   test_delayed_error0TestTokenFailureDuringRequest.test_delayed_error   s     S+&S+,S+&1
#- 	;;Q?#..T[[ 	/ 	
 	;;Q?r   c                t   \        RR4      \        ^\        4      \        RR4      \        RR4      \        ^\        4      .\        n        V P                  V P                  P                  ^ 4       \        P                  RV P                  R7       V P                  V P                  P                  ^4       R# )z@We'll keep getting new tokens as long as tokens are the problem.rf   rg   rk   rD   rJ   Nr`   rF   s   &r   test_many_errors.TestTokenFailureDuringRequest.test_many_errors   s     S+,S+&S+,S+,S+&1
#- 	;;Q?#..T[[ 	/ 	
 	;;Q?r   c                    \        RR4      .\        n        V P                  \        \        P
                  RV P                  R7       R# )z>If the token is not at fault, a 401 error raises an exception.rf   s   Some other error.rD   rJ   N)r   r2   r%   rV   r   rK   rE   rF   s   &r   test_other_unauthorized5TestTokenFailureDuringRequest.test_other_unauthorized  sE     S./1
#- 	'22!%	 	 	
r   r?   N)r   r   r   r   r   rc   rh   rl   ro   rr   ru   rx   r   r   r   s   @r   r^   r^      s8     @@@@@@
 
r   r^   )r   collectionsr   jsonr   r   r9   unittestlaunchpadlib.errorsr   launchpadlib.credentialsr   launchpadlib.launchpadr   r   launchpadlib.testing.helpersr	   rQ   encoderR   r   r   r2   TestCaserB   rO   r^   r?   r   r   <module>r      s   " 3  '   , C F& Biw' J4 J(
) 
$
!2!2 
4 
7  
Fk
$> k
r   