o ;a@sdZeZddlmZddlZddlZddlZddlZddl Z ddl Z zddl m Z Wne y9ddlm Z YnwddlZddlmZddlmZmZddlmZddlZddlmZdd lmZdd lmZmZmZmZmZm Z m!Z!dd lm"Z"d Z#Gd dde j$Z%Gddde j$Z&Gddde j$Z'Gddde j$Z(Gddde j$Z)Gddde j$Z*Gddde j$Z+Gddde+Z,Gddde+Z-Gdd d e j$Z.Gd!d"d"e j$Z/d#d$Z0dS)%zTests for the Launchpad class.)contextmanagerN)patch) ServiceRoot) AccessToken Credentials)uris) Launchpad)UnencryptedFileCredentialStore)assert_keyring_not_importedBadSaveKeyring fake_keyringFauxSocketModuleInMemoryKeyringNoNetworkAuthorizationEngineNoNetworkLaunchpad)KeyringCredentialStorehttp://api.example.com/c@eZdZdZddZdS)TestResourceTypeClasseszTestLaunchpadLoginWith.test_dirs_created_are_changed_to_securecCsftj|jd}tjdt|d|tj|t |}t |j }| |t j t jBt jBdS)Nrrr)rrrrrrrmr7rrrrrrrrrrrrtest_dirs_created_are_secures  z3TestLaunchpadLoginWith.test_dirs_created_are_securecCs\tj|jd}tjdt|dd}||jddtjdt|dd}||jdddS)Nrrfoo)r`rrarabar) rrrrrrrmrpassed_in_argsrrrrrrtest_version_is_propagatedsz1TestLaunchpadLoginWith.test_version_is_propagatedcCsXtj|jd}tjdt|d}||jj j dtjdt|d}||jj j ddS)Nrzvery importantr) rrrrrrrmrrrrrrrrr#test_application_name_is_propagateds"   z:TestLaunchpadLoginWith.test_application_name_is_propagatedcCs6ttd}tj|d||jd||jddS)Napplication nameauthorization_enginer2)rrmrrrrequest_tokens_obtainedaccess_tokens_obtainedrenginerrr'test_authorization_engine_is_propagateds  z>TestLaunchpadLoginWith.test_authorization_engine_is_propagatedcCs|ttjdSr)rYrZrrr-rrr)test_login_with_must_identify_applicationz@TestLaunchpadLoginWith.test_login_with_must_identify_applicationcCtjdddSrprrr-rrrrtz;TestLaunchpadLoginWith.test_application_name_identifies_appcCrrvrr-rrrryrz8TestLaunchpadLoginWith.test_consumer_name_identifies_appcCs"ttd}|jttjd|ddS);Catch an attempt to specify inconsistent application_names.zapplication name1zapplication name2rNrrmrYrZrrrrrr+test_inconsistent_application_name_rejecteds zBTestLaunchpadLoginWith.test_inconsistent_application_name_rejectedcCs&ttddd}|jttjd|ddS)rNconsumer_name1rwconsumer_name2rrrrrr(test_inconsistent_consumer_name_rejecteds z?TestLaunchpadLoginWith.test_inconsistent_consumer_name_rejectedcCs.ttddgd}|jttjdddg|ddS)z=Catch an attempt to specify inconsistent allow_access_levels.rFOOrxallow_access_levelsNBAR)rxrrrrrrr.test_inconsistent_allow_access_levels_rejecteds zETestLaunchpadLoginWith.test_inconsistent_allow_access_levels_rejectedcCs4dd}t|d}dd}|jttjd||ddS)NcSdSrrrrrr callback1zRTestLaunchpadLoginWith.test_inconsistent_credential_save_failed..callback1)credential_save_failedcSrrrrrrr callback2rzRTestLaunchpadLoginWith.test_inconsistent_credential_save_failed..callback2app name)rr)rrYrZrr)rrrrrrr(test_inconsistent_credential_save_faileds  z?TestLaunchpadLoginWith.test_inconsistent_credential_save_failedcCsJtjddgd}||jjjd||jjjd||jjdgdS)Nrrr) rrrrrrrrrrrrrrrtest_non_desktop_integration)s z3TestLaunchpadLoginWith.test_non_desktop_integrationcCs&tjddgd}||jjdgdS)Nrr)rDESKTOP_INTEGRATION)rrrrrrrrrz*TestCredenitialSaveFailedCallback.csvgfdd}tj|jd}d}tttjd|||d|t dWddS1s4wYdS)NcsddSr)appendrcallback_calledrrcallbackszPTestCredenitialSaveFailedCallback.test_credentials_save_failed..callbackrrr)r`rrr2) rrrrr r rrrr6)rrrr`rrrtest_credentials_save_faileds  "z>TestCredenitialSaveFailedCallback.test_credentials_save_failedcCrrrrrrrrrcCsZtj|jd}d}tt|jttj d||dWddS1s&wYdSNrrrr) rrrrr r rY RuntimeErrorrrrrr`rrr:test_default_credentials_save_failed_is_to_raise_exceptions "z\TestCredenitialSaveFailedCallback.test_default_credentials_save_failed_is_to_raise_exceptioncCr)NTrrrrrr!rcCsTtj|jd}d}tttjd||dWddS1s#wYdSr)rrrrr r rrr!rrr>test_credentials_save_fail_under_sudo_does_not_raise_exception!s "z`TestCredenitialSaveFailedCallback.test_credentials_save_fail_under_sudo_does_not_raise_exceptionN) rr r!r.rrrr staticmethodrr"r#rrrrr s  r c@sXeZdZddZddZeededddd Z eeded dd d Z d S)TestMultipleSitescCrrrr-rrrr.4rzTestMultipleSites.setUpcCrrrr-rrrr;rzTestMultipleSites.tearDownrcCrrrrrrrr?rzTestMultipleSites.cCstj|jd}t}d}d}t|tj|||d}|jj j }Wdn1s+wYt |j dd}|||||||||d|dS)NrrzSuper App 3000rrr2@)rrrrrr rrrrrlistdatarAr;r)rrrr`rrrrxapplication_keyrrr"test_components_of_application_key?s     z4TestMultipleSites.test_components_of_application_keycCrrrrrrrrZrcCstj|jd}t}|jrJdt|tjdd|dtjdd|dWdn1s1wYt |j dksAJt |j dd }t |j d d }| ||dS) Nrz$oops, a fresh keyring has data in itrzhttp://alpha.example.com/rzhttp://beta.example.com/rr2) rrrrrr(r rrr6rAr'r)rrrapplication_key_1application_key_2rrrtest_same_app_different_serversZs& z1TestMultipleSites.test_same_app_different_serversN) rr r!r.rrrrr$r*r.rrrrr%/s r%cCsttSr)unittest TestLoaderloadTestsFromNamerrrrr test_suitewsr2)1r"type __metaclass__ contextlibrrrrrrr/ unittest.mockr ImportErrormockr3lazr.restfulclient.resourcerlaunchpadlib.credentialsrrrrlaunchpadlib.launchpadrr launchpadlib.testing.helpersr r r r rrrrrmTestCaserr#r_rkr~rrrrr r%r2rrrrsL      $  t8#wC H