'[a$TdZddlmZddlmZddlZddlZ ddlmZddl m Z ddl m Z ddlmZmZdd lmZd Zeij)d ZGd d ZGddeZGddeZGddej2ZGddeZGddeZy#e$re ZYwxYw)z,Tests for the LaunchpadOAuthAwareHTTP class.)deque)dumpsN)JSONDecodeError) Unauthorized)UnencryptedFileCredentialStore) LaunchpadLaunchpadOAuthAwareHttp)NoNetworkAuthorizationEngines zutf-8ceZdZdZdZy)ResponsezA fake HTTP response object.c ||_||_yN)statuscontent)selfrrs >/usr/lib/python3/dist-packages/launchpadlib/tests/test_http.py__init__zResponse.__init__@s  N)__name__ __module__ __qualname____doc__rrrr r =s &rr c(eZdZdZfdZdZxZS)SimulatedResponsesHttpzrBrrrr9r9ksK   rr9c"eZdZdZdZdZdZy)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`|jtdttdty)z5Make sure that launchpadlib can use the minimal data.N)rBr SIMPLE_WADL SIMPLE_JSONr=s rtest_minimal_dataz(TestAbilityToParseData.test_minimal_datas# %% S+ &k(B rc x|jt|jtddtdty)z'Show that bad WADL causes an exception.rFsThis is not WADL.N) assertRaises SyntaxErrorrBr rHr=s r test_bad_wadlz$TestAbilityToParseData.test_bad_wadls1    ) ) S. / S+ &  rc x|jt|jtdttddy)z'Show that bad JSON causes an exception.rFsThis is not JSON.N)rKrrBr rGr=s r test_bad_jsonz$TestAbilityToParseData.test_bad_jsons1    ) ) S+ & S. /  rN)rrrrrIrMrOrrrrDrDs   rrDc:eZdZdZdZdZdZdZdZdZ dZ 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. c0tdttdtgt_|j |j jdtjd|j |j |j jdy)z/If our token is good, we never get another one.rFrr;r@r1N r rGrHr,r! assertEqualr<access_tokens_obtainedrAr=s rtest_good_tokenz-TestTokenFailureDuringRequest.test_good_tokensw S+ & S+ &1 #- ;;Q?#.. T[[ /  ;;Q?rcFtddtdttdtgt_|j |j jdtjd|j |j |j jdy) z(If our token is bad, we get another one.Invalid token.rFrr;r@NrSr=s rtest_bad_tokenz,TestTokenFailureDuringRequest.test_bad_tokens S+ , S+ & S+ &1 #- ;;Q?#.. T[[ /  ;;Q?rcFtddtdttdtgt_|j |j jdtjd|j |j |j jdy) z,If our token is expired, we get another one.rXExpired token.rFrr;r@rZNrSr=s rtest_expired_tokenz0TestTokenFailureDuringRequest.test_expired_tokens S+ , S+ & S+ &1 #- ;;Q?#.. T[[ /  ;;Q?rcFtddtdttdtgt_|j |j jdtjd|j |j |j jdy) z,If our token is unknown, we get another one.rXsUnknown access token.rFrr;r@rZNrSr=s rtest_unknown_tokenz0TestTokenFailureDuringRequest.test_unknown_tokens S2 3 S+ & S+ &1 #- ;;Q?#.. T[[ /  ;;Q?rcFtdttddtdtgt_|j |j jdtjd|j |j |j jdy) z6We get another token no matter when the error happens.rFrXr]rr;r@rZNrSr=s rtest_delayed_errorz0TestTokenFailureDuringRequest.test_delayed_errors S+ & S+ , S+ &1 #- ;;Q?#.. T[[ /  ;;Q?rcrtddtdttddtddtdtgt_|j |j jdtjd|j |j |j jdy ) z@We'll keep getting new tokens as long as tokens are the problem.rXrYrFr]rr;r@NrSr=s rtest_many_errorsz.TestTokenFailureDuringRequest.test_many_errorss S+ , S+ & S+ , S+ , S+ & 1 #- ;;Q?#.. T[[ /  ;;Q?rctddgt_|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 rtest_other_unauthorizedz5TestTokenFailureDuringRequest.test_other_unauthorizedsE S. /1 #-   ' 2 2 !%  rN) rrrrrVr[r^r`rbrergrrrrQrQs0 @ @ @ @ @ @  rrQ)r collectionsrjsonrr2unittestr ImportError ValueErrorlaunchpadlib.errorsrlaunchpadlib.credentialsrlaunchpadlib.launchpadrr launchpadlib.testing.helpersr rGencoderHr rr,TestCaser9rDrQrrrrss"3!$-CF &Biw' J4J( ) $ !2!2 4  7  Fk $>k ]! O!sBB'&B'