Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/launchpadlib/tests/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyc


Nc@s*dZddlmZddlZddlZddlmZmZddlm	Z	ddl
mZddlm
Z
mZddlmZmZd	ZeiZd
ddYZdefd
YZde
fdYZdejfdYZdefdYZdefdYZdS(s,Tests for the LaunchpadOAuthAwareHTTP class.i(tdequeN(tdumpstJSONDecodeError(tUnauthorized(tUnencryptedFileCredentialStore(t	LaunchpadtLaunchpadOAuthAwareHttp(tNoNetworkAuthorizationEnginetNoNetworkLaunchpads<?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>
tResponsecBseZdZdZRS(sA fake HTTP response object.cCs||_||_dS(N(tstatustcontent(tselfR
R((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyt__init__>s	(t__name__t
__module__t__doc__R
(((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyR	<stSimulatedResponsesHttpcBs eZdZdZdZRS(s<Responds to HTTP requests by shifting responses off a stack.cGs5tt|j|g|_||_d|_dS(s{Constructor.

        :param responses: A list of HttpResponse objects to use
            in response to requests.
        N(tsuperRR
tsent_responsestunsent_responsestNonetcache(Rt	responsestargs((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyR
Fs		cGs5|jj}|jj||j||j|S(N(RtpopleftRtappendtretry_on_bad_tokenR(RRtresponse((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyt_requestQs(RRRR
R(((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyRCs	tSimulatedResponsesLaunchpadcBs&eZgZdZedZRS(cGstt|j||j|S(N(RRRtauthorization_engine(RR((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pythttpFactory]scCsttjd|S(Ni(Rttempfiletmkstemp(tclstcredential_save_failed((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pytcredential_store_factoryas(RRRR tclassmethodR%(((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyRWs	tSimulatedResponsesTestCasecBs eZdZdZdZRS(sATest cases that give fake responses to launchpad's HTTP requests.cCsgt_tdd|_dS(s*Clear out the list of simulated responses.shttp://api.example.com/sapplication nameN(RRRtengine(R((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pytsetUpjs	cGs|t_tjdd|jS(sqUse 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.
        sapplication nameR(RRt
login_withR((RR((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pytlaunchpad_with_responsesps
	(RRRR)R+(((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyR'gs	tTestAbilityToParseDatacBs)eZdZdZdZdZRS(s_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(|jtdttdt}dS(s5Make sure that launchpadlib can use the minimal data.iN(R+R	tSIMPLE_WADLtSIMPLE_JSON(Rt	launchpad((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyttest_minimal_datascCs/|jt|jtddtdtdS(s'Show that bad WADL causes an exception.isThis is not WADL.N(tassertRaisestSyntaxErrorR+R	R.(R((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyt
test_bad_wadls	cCs/|jt|jtdttdddS(s'Show that bad JSON causes an exception.isThis is not JSON.N(R1RR+R	R-(R((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyt
test_bad_jsons	(RRRR0R3R4(((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyR,s		tTestTokenFailureDuringRequestcBsMeZdZdZdZdZdZdZdZdZ	RS(sTest 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.
    cCsitdttdtgt_|j|jjdtjdd|j}|j|jjddS(s/If our token is good, we never get another one.iisapplication nameRiN(	R	R-R.RRtassertEqualsR(taccess_tokens_obtainedR*(RR/((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyttest_good_tokenscCsutddtdttdtgt_|j|jjdtjdd|j}|j|jjddS(	s(If our token is bad, we get another one.isInvalid token.iisapplication nameRiN(	R	R-R.RRR6R(R7R*(RR/((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyttest_bad_tokenscCsutddtdttdtgt_|j|jjdtjdd|j}|j|jjddS(	s,If our token is expired, we get another one.isExpired token.iisapplication nameRiN(	R	R-R.RRR6R(R7R*(RR/((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyttest_expired_tokenscCsutddtdttdtgt_|j|jjdtjdd|j}|j|jjddS(	s,If our token is unknown, we get another one.isUnknown access token.iisapplication nameRiN(	R	R-R.RRR6R(R7R*(RR/((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyttest_unknown_tokenscCsutdttddtdtgt_|j|jjdtjdd|j}|j|jjddS(	s6We get another token no matter when the error happens.iisExpired token.isapplication nameRiN(	R	R-R.RRR6R(R7R*(RR/((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyttest_delayed_errorscCstddtdttddtddtdtgt_|j|jjdtjdd|j}|j|jjdd	S(
s@We'll keep getting new tokens as long as tokens are the problem.isInvalid token.isExpired token.isapplication nameRiN(	R	R-R.RRR6R(R7R*(RR/((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyttest_many_errorsscCs8tddgt_|jttjdd|jdS(s>If the token is not at fault, a 401 error raises an exception.isSome other error.sapplication nameRN(R	RRR1RR*R((R((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyttest_other_unauthorizeds	(
RRRR8R9R:R;R<R=R>(((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyR5s			
	
		
((RtcollectionsRR!tunittestt
simplejsonRRtlaunchpadlib.errorsRtlaunchpadlib.credentialsRtlaunchpadlib.launchpadRRtlaunchpadlib.testing.helpersRRR-R.R	RRtTestCaseR'R,R5(((s@/usr/lib/python2.7/dist-packages/launchpadlib/tests/test_http.pyt<module>s