{a4dZeZgdZddlmZddlZddlmZddl m Z m Z m Z e ZdZGdd e ZGd d eZGd d eZedZGddZGddZGddZGddZeddZeddZeddZy)zlaunchpadlib testing helpers.) BadSaveKeyring fake_keyringFauxSocketModuleInMemoryKeyringNoNetworkAuthorizationEngineNoNetworkLaunchpadTestableLaunchpadnopriv_read_nonprivatesalgado_read_nonprivatesalgado_with_full_permissions)contextmanagerN) Launchpad) AccessToken CredentialsRequestTokenAuthorizationEnginec\ttjdttusJdy)Nkeyringz>During tests the real keyring module should never be imported.)getattr launchpadlib credentialsmissing>/usr/lib/python3/dist-packages/launchpadlib/testing/helpers.pyassert_keyring_not_importedr2s+ (()W=HHGHHrc2eZdZdZdZfdZdZdZxZS)raAn authorization engine that doesn't open a web browser. You can use this to test the creation of Launchpad objects and the storing of credentials. You can't use it to interact with the web service, since it only pretends to authorize its OAuth request tokens. z access_key:84cHtt| |i|d|_d|_y)Nr )superr__init__request_tokens_obtainedaccess_tokens_obtained)selfargskwargs __class__s rrz%NoNetworkAuthorizationEngine.__init__Bs( *D:DKFK'($&'#rc.|xjdz c_y)zsPretend to get a request token from the server. We do this by simply returning a static token ID. zrequest_token:42)r )r"rs rget_request_tokenz.NoNetworkAuthorizationEngine.get_request_tokenHs $$)$!rcdt|jd|_|xjdz c_y)zPretend to exchange a request token for an access token. We do this by simply setting the access_token property. zaccess_secret:168r'N)rACCESS_TOKEN_KEY access_tokenr!)r"r request_tokens rmake_end_user_authorize_tokenz:NoNetworkAuthorizationEngine.make_end_user_authorize_tokenPs0 $/  ! !#6$   ##q(#r) __name__ __module__ __qualname____doc__r*rr(r- __classcell__r%s@rrr8s'( ")rrc&eZdZdZdZedZy)rzA Launchpad instance for tests with no network access. It's only useful for making sure that certain methods were called. It can't be used to interact with the API. c X||_||_||_t||||||_y)N service_rootcachetimeout proxy_infoversion)rauthorization_enginecredential_storedictpassed_in_args) r"rr<r=r7r8r9r:r;s rrzNoNetworkLaunchpad.__init__bs8'$8! 0"%!  rct|SN)r)clsr#s rauthorization_engine_factoryz/NoNetworkLaunchpad.authorization_engine_factoryxs +T22rN)r.r/r0r1r classmethodrCrrrrr[s   ,33rrcFeZdZdZddddddej ffd ZxZS)rz5A base class for talking to the testing root service.Ntest_devc <tt| ||||||||y)a\Provide test-friendly defaults. :param authorization_engine: Defaults to None, since a test environment can't use an authorization engine. :param credential_store: Defaults to None, since tests generally pass in fully-formed Credentials objects. :param service_root: Defaults to 'test_dev'. r6N)rrr) r"rr<r=r7r8r9r:r;r%s rrzTestableLaunchpad.__init__s2& /  %! 0 r)r.r/r0r1rDEFAULT_VERSIONrr2r3s@rrr}s-? "))  rrc#Kt|tj_ttj_ dtj`tj`y#tj`tj`wxYww)zAA context manager which injects a testing keyring implementation.N)rrrr RuntimeErrorNoKeyringError)fakes rrrse !'+L$.:L+4  $ $ ,  $ $ 3  $ $ ,  $ $ 3s9BA!!B!"BBceZdZdZdZy)rz:A socket module replacement that provides a fake hostname.cy)NHOSTNAMErr"s r gethostnamezFauxSocketModule.gethostnamesrN)r.r/r0r1rQrrrrrs DrrceZdZdZdZdZy)rz6A keyring that generates errors when saving passwords.cyrArr"serviceusernames r get_passwordzBadSaveKeyring.get_passwordsrctrA)rJr"rUrVpasswords r set_passwordzBadSaveKeyring.set_passwordsrN)r.r/r0r1rWr[rrrrrs@rrc"eZdZdZdZdZdZy)rz.A keyring that saves passwords only in memory.ci|_yrAdatarPs rrzInMemoryKeyring.__init__s  rc&||j||f<yrAr^rYs rr[zInMemoryKeyring.set_passwords'/ '8#$rc<|jj||fSrA)r_getrTs rrWzInMemoryKeyring.get_passwordsyy}}gx011rN)r.r/r0r1rr[rWrrrrrs802rrc:eZdZdZdZdddej fdZy) KnownTokensz'Known access token/secret combinations.cz||_||_t|||_t d|j|_y)Nzlaunchpad-library) consumer_namer+) token_string access_secretrtokenrr)r"rgrhs rrzKnownTokens.__init__s6(* }= &-DJJ rNc6t|j||||S)z2Create a Launchpad object using these credentials.)r8r9r:r;)rr)r"r8r9r:r;s rloginzKnownTokens.logins&!   !   r)r.r/r0r1rrrHrkrrrrdrds#1 ))  rrdzsalgado-change-anythingtestzsalgado-read-nonprivatesecretznopriv-read-nonprivatemystery)r1type __metaclass____all__ contextlibr rlaunchpadlib.launchpadrlaunchpadlib.credentialsrrrobjectrrrrrrrrrrdr r r rrrrvs&$  &, (H )#B )F33D  D 4 4 2 2  8!,,Ev N%&?J$%=yIr