o {a@sdZeZgdZddlmZddlZddlmZddl m Z m Z m Z e ZddZGd d d e ZGd d d eZGd ddeZeddZGdddZGdddZGdddZGdddZeddZeddZeddZdS)zlaunchpadlib testing helpers.) BadSaveKeyring fake_keyringFauxSocketModuleInMemoryKeyringNoNetworkAuthorizationEngineNoNetworkLaunchpadTestableLaunchpadnopriv_read_nonprivatesalgado_read_nonprivatesalgado_with_full_permissions)contextmanagerN) Launchpad) AccessToken CredentialsRequestTokenAuthorizationEnginecCsttjdttus JddS)Nkeyringz>During tests the real keyring module should never be imported.)getattr launchpadlib credentialsmissingrr>/usr/lib/python3/dist-packages/launchpadlib/testing/helpers.pyassert_keyring_not_imported2srcs4eZdZdZdZfddZddZddZZS) 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:84cs&tt|j|i|d|_d|_dS)Nr )superr__init__request_tokens_obtainedaccess_tokens_obtained)selfargskwargs __class__rrrBs z%NoNetworkAuthorizationEngine.__init__cCs|jd7_dS)zsPretend to get a request token from the server. We do this by simply returning a static token ID. zrequest_token:42)r)rrrrrget_request_tokenHsz.NoNetworkAuthorizationEngine.get_request_tokencCs t|jd|_|jd7_dS)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)rr request_tokenrrrmake_end_user_authorize_tokenPsz:NoNetworkAuthorizationEngine.make_end_user_authorize_token) __name__ __module__ __qualname____doc__r$rr#r' __classcell__rrr rr8s  rc@s$eZdZdZddZeddZdS)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 Cs*||_||_||_t|||||d|_dS)N service_rootcachetimeout proxy_infoversion)rauthorization_enginecredential_storedictpassed_in_args rrr3r4r.r/r0r1r2rrrrbs  zNoNetworkLaunchpad.__init__cGst|SN)r)clsrrrrauthorization_engine_factoryxsz/NoNetworkLaunchpad.authorization_engine_factoryN)r(r)r*r+r classmethodr:rrrrr[s rcs2eZdZdZddddddejffdd ZZS)rz5A base class for talking to the testing root service.Ntest_devc s$tt|j||||||||ddS)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'. r-N)rrrr7r rrrs  zTestableLaunchpad.__init__)r(r)r*r+r DEFAULT_VERSIONrr,rrr rr}srccs@t|tj_ttj_z dVWtj`tj`dStj`tj`w)zAA context manager which injects a testing keyring implementation.N)rrrr RuntimeErrorNoKeyringError)fakerrrrs rc@seZdZdZddZdS)rz:A socket module replacement that provides a fake hostname.cCsdS)NHOSTNAMErrrrr gethostnamezFauxSocketModule.gethostnameN)r(r)r*r+rCrrrrrs rc@s eZdZdZddZddZdS)rz6A keyring that generates errors when saving passwords.cCsdSr8rrserviceusernamerrr get_passwordrDzBadSaveKeyring.get_passwordcCstr8)r>rrFrGpasswordrrr set_passwordrDzBadSaveKeyring.set_passwordN)r(r)r*r+rHrKrrrrrs rc@s(eZdZdZddZddZddZdS) rz.A keyring that saves passwords only in memory.cCs i|_dSr8datarBrrrrs zInMemoryKeyring.__init__cCs||j||f<dSr8rLrIrrrrKszInMemoryKeyring.set_passwordcCs|j||fSr8)rMgetrErrrrHszInMemoryKeyring.get_passwordN)r(r)r*r+rrKrHrrrrrs  rc@s,eZdZdZddZdddejfddZdS) KnownTokensz'Known access token/secret combinations.cCs,||_||_t|||_td|jd|_dS)Nzlaunchpad-library) consumer_namer%) token_string access_secretrtokenrr)rrQrRrrrrs   zKnownTokens.__init__NcCst|j||||dS)z2Create a Launchpad object using these credentials.)r/r0r1r2)rr)rr/r0r1r2rrrloginszKnownTokens.login)r(r)r*r+rr r=rTrrrrrOs rOzsalgado-change-anythingtestzsalgado-read-nonprivatesecretznopriv-read-nonprivatemystery)r+type __metaclass____all__ contextlibr rlaunchpadlib.launchpadr launchpadlib.credentialsrrrobjectrrrrrrrrrrOr r rrrrrs*  #""