o '[a$@sdZddlmZddlmZddlZddlZzddlmZWn ey)e ZYnwddl m Z ddl m Z ddlmZmZdd lmZd Zeid ZGd d d ZGdddeZGdddeZGdddejZGdddeZGdddeZdS)z,Tests for the LaunchpadOAuthAwareHTTP class.)deque)dumpsN)JSONDecodeError) Unauthorized)UnencryptedFileCredentialStore) LaunchpadLaunchpadOAuthAwareHttp)NoNetworkAuthorizationEngines zutf-8c@seZdZdZddZdS)ResponsezA fake HTTP response object.cCs||_||_dSN)statuscontent)selfr r r>/usr/lib/python3/dist-packages/launchpadlib/tests/test_http.py__init__@s zResponse.__init__N)__name__ __module__ __qualname____doc__rrrrrr =s r cs(eZdZdZfddZddZZS)SimulatedResponsesHttpzr@rrrrr7s   r7c@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ 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. cCsJtdttdtgt_||jjdtjd|jd||jjddS)z/If our token is good, we never get another one.r8rr0r4r(N r r9r:r%r assertEqualr1access_tokens_obtainedr5r2rrrtest_good_tokensz-TestTokenFailureDuringRequest.test_good_tokencCRtddtdttdtgt_||jjdtjd|jd||jjddS) z(If our token is bad, we get another one.Invalid token.r8rr0r4NrBr2rrrtest_bad_tokenz,TestTokenFailureDuringRequest.test_bad_tokencCrF) z,If our token is expired, we get another one.rGExpired token.r8rr0r4rINrBr2rrrtest_expired_tokenz0TestTokenFailureDuringRequest.test_expired_tokencCrF) z,If our token is unknown, we get another one.rGsUnknown access token.r8rr0r4rINrBr2rrrtest_unknown_tokenrNz0TestTokenFailureDuringRequest.test_unknown_tokencCsRtdttddtdtgt_||jjdtjd|jd||jjddS) z6We get another token no matter when the error happens.r8rGrLrr0r4rINrBr2rrrtest_delayed_errorrKz0TestTokenFailureDuringRequest.test_delayed_errorcCsbtddtdttddtddtdtgt_||jjdtjd|jd||jjdd S) z@We'll keep getting new tokens as long as tokens are the problem.rGrHr8rLrr0r4NrBr2rrrtest_many_errorssz.TestTokenFailureDuringRequest.test_many_errorscCs(tddgt_|jttjd|jddS)z>If the token is not at fault, a 401 error raises an exception.rGsSome other error.r0r4N)r r%rr<rr5r1r2rrrtest_other_unauthorizeds z5TestTokenFailureDuringRequest.test_other_unauthorizedN) rrrrrErJrMrOrPrRrSrrrrrAs  rA)r collectionsrjsonrr)unittestr ImportError ValueErrorlaunchpadlib.errorsrlaunchpadlib.credentialsrlaunchpadlib.launchpadrrlaunchpadlib.testing.helpersr r9encoder:r rr%TestCaser/r7rArrrrs,      #