o
    ;¿êa�…  ã                   @   sÆ  d Z eZddlmZ ddlZddlZddlZddlZddl	Z	ddl
Z
zddlmZ W n ey9   ddlmZ Y nw ddlZddlmZ ddlmZmZ ddlmZ ddlZddlmZ dd	lmZ dd
lmZmZmZmZmZm Z m!Z! ddlm"Z" dZ#G dd„ de
j$ƒZ%G dd„ de
j$ƒZ&G dd„ de
j$ƒZ'G dd„ de
j$ƒZ(G dd„ de
j$ƒZ)G dd„ de
j$ƒZ*G dd„ de
j$ƒZ+G dd„ de+ƒZ,G dd„ de+ƒZ-G dd „ d e
j$ƒZ.G d!d"„ d"e
j$ƒZ/d#d$„ Z0dS )%zTests for the Launchpad class.é    )ÚcontextmanagerN)Úpatch)ÚServiceRoot)ÚAccessTokenÚCredentials)Úuris)Ú	Launchpad)ÚUnencryptedFileCredentialStore)Úassert_keyring_not_importedÚBadSaveKeyringÚfake_keyringÚFauxSocketModuleÚInMemoryKeyringÚNoNetworkAuthorizationEngineÚNoNetworkLaunchpad)ÚKeyringCredentialStoreúhttp://api.example.com/c                   @   ó   e Zd ZdZdd„ ZdS )ÚTestResourceTypeClassesz<launchpadlib must know about restfulclient's resource types.c                 C   s*   t j ¡ D ]\}}|  tj| |¡ qd S ©N)r   ÚRESOURCE_TYPE_CLASSESÚitemsÚassertEqualr   )ÚselfÚnameÚcls© r   úC/usr/lib/python3/dist-packages/launchpadlib/tests/test_launchpad.pyÚtest_resource_typesB   s   ÿz+TestResourceTypeClasses.test_resource_typesN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   ?   s    r   c                   @   sl   e Zd ZdZdd„ Zedd„ ƒZdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚTestNameLookupsz0Test the utility functions in the 'uris' module.c                 C   s   t g d¢ƒ| _d S )N)Ú
productionÚ	qastagingÚstagingÚdogfoodÚdevÚtest_devÚedge)ÚsortedÚaliases©r   r   r   r   ÚsetUpL   s   
ÿzTestNameLookups.setUpc                 c   s|   � t jdd��-}t  d¡ d V  |  t|ƒd¡ |\}|  t|jtƒ¡ |  	dt
|ƒ¡ W d   ƒ d S 1 s7w   Y  d S )NT©ÚrecordÚalwaysé   zno longer exists)ÚwarningsÚcatch_warningsÚsimplefilterr   ÚlenÚ
assertTrueÚ
issubclassÚcategoryÚDeprecationWarningÚassertInÚstr)r   ÚcaughtÚwarningr   r   r   Úedge_deprecation_errorY   s   €
"ùz&TestNameLookups.edge_deprecation_errorc                 C   s4   |   ttj ¡ ƒ| j¡ |   ttj ¡ ƒ| j¡ d S r   )r   r+   r   Úservice_rootsÚkeysr,   Ú	web_rootsr-   r   r   r   Útest_short_namesf   s   z TestNameLookups.test_short_namesc                 C   óF   |   ¡ � |  t d¡t d¡¡ W d   ƒ d S 1 sw   Y  d S ©Nr*   r$   ©r?   r   r   Úlookup_service_rootr-   r   r   r   Ú$test_edge_service_root_is_productionk   ó   
þ"ÿz4TestNameLookups.test_edge_service_root_is_productionc                 C   rD   rE   ©r?   r   r   Úlookup_web_rootr-   r   r   r   Ú test_edge_web_root_is_productiont   rI   z0TestNameLookups.test_edge_web_root_is_productionc                 C   óH   |   ¡ � |  t tj¡t d¡¡ W d   ƒ d S 1 sw   Y  d S ©Nr$   ©r?   r   r   rG   ÚEDGE_SERVICE_ROOTr-   r   r   r   Ú-test_edge_service_root_url_becomes_production}   ó   

þ"ÿz=TestNameLookups.test_edge_service_root_url_becomes_productionc                 C   rM   rN   )r?   r   r   rK   ÚEDGE_WEB_ROOTr-   r   r   r   Ú)test_edge_web_root_url_becomes_production„   rR   z9TestNameLookups.test_edge_web_root_url_becomes_productionc                 C   rM   rN   rO   r-   r   r   r   Ú/test_top_level_edge_constant_becomes_production‹   rR   z?TestNameLookups.test_top_level_edge_constant_becomes_productionc                 C   rD   )Nzhttps://api.edge.launchpad.net/r$   rF   r-   r   r   r   Ú5test_edge_server_equivalent_string_becomes_production’   ó   
þ"ÿzETestNameLookups.test_edge_server_equivalent_string_becomes_productionc                 C   rD   )Nzhttps://edge.launchpad.net/r$   rJ   r-   r   r   r   Ú9test_edge_web_server_equivalent_string_becomes_production™   rW   zITestNameLookups.test_edge_web_server_equivalent_string_becomes_productionc                 C   sè   |   ¡ � | jD ]}|  t |¡tj| ¡ qW d  ƒ n1 s!w   Y  |   ¡ � | jD ]}|  t |¡tj| ¡ q.W d  ƒ n1 sGw   Y  d}|  t |¡|¡ |  t |¡|¡ d}|  t	tj|¡ |  t	tj|¡ dS )z=Ensure that short service names turn into long service names.Nzhttp://some-other-server.comz	not-a-url)
r?   r,   r   r   rG   r@   rK   rB   ÚassertRaisesÚ
ValueError)r   ÚaliasÚ
other_rootÚ	not_a_urlr   r   r   Útest_lookups    s(   

ÿÿÿ

ÿÿÿzTestNameLookups.test_lookupsN)r   r    r!   r"   r.   r   r?   rC   rH   rL   rQ   rT   rU   rV   rX   r^   r   r   r   r   r#   I   s    
		r#   c                   @   r   )Ú"TestServiceNameWithEmbeddedVersiona3  Reject service roots that include the version at the end of the URL.

    If the service root is "http://api.launchpad.net/beta/" and the
    version is "beta", the launchpadlib constructor will raise an
    exception.

    This happens with scripts that were written against old versions
    of launchpadlib. The alternative is to try to silently fix it (the
    fix will eventually break as new versions of the web service are
    released) or to go ahead and make a request to
    http://api.launchpad.net/beta/beta/, and cause an unhelpful 404
    error.
    c              
   C   sº   d}t jd | }ztd d d ||d� W tdƒ‚ ty3 } z|  t|ƒ d¡¡ W Y d }~nd }~ww |d7 }| jttd d d ||d� t	j
}t jd | d }| jttd d d |d� d S )Nzversion-foor&   )Úservice_rootÚversionzoIt looks like you're using a service root that incorporates the name of the web service version ("version-foo")z*Expected a ValueError that was not thrown!ú/©r`   )r   r@   r   rZ   r7   r<   Ú
startswithÚAssertionErrorrY   r   ÚDEFAULT_VERSION)r   ra   ÚrootÚeÚdefault_versionr   r   r   Ú'test_service_name_with_embedded_versionÌ   s8   
÷ÿÿ€ÿù
ÿzJTestServiceNameWithEmbeddedVersion.test_service_name_with_embedded_versionN)r   r    r!   r"   rj   r   r   r   r   r_   ½   s    r_   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )Ú#TestRequestTokenAuthorizationEnginez4Tests for the RequestTokenAuthorizationEngine class.c                 C   s   |   ttt¡ d S r   ©rY   rZ   r   ÚSERVICE_ROOTr-   r   r   r   Útest_app_must_be_identifiedø   s   ÿz?TestRequestTokenAuthorizationEngine.test_app_must_be_identifiedc                 C   ó   t tdd� d S ©Nr   ©Úapplication_name©r   rm   r-   r   r   r   Ú$test_application_name_identifies_appý   ó   zHTestRequestTokenAuthorizationEngine.test_application_name_identifies_appc                 C   ro   ©Nr   ©Úconsumer_namers   r-   r   r   r   Ú!test_consumer_name_identifies_app   ru   zETestRequestTokenAuthorizationEngine.test_consumer_name_identifies_appc                 C   s,   | j tttddd� | j tttddd� d S )NÚname1Úname2)rr   rx   r   rl   r-   r   r   r   Ú#test_conflicting_app_identification  s   û

ûzGTestRequestTokenAuthorizationEngine.test_conflicting_app_identificationN)r   r    r!   r"   rn   rt   ry   r|   r   r   r   r   rk   õ   s    rk   c                   @   ó    e Zd ZdZdd„ Zdd„ ZdS )Ú%TestLaunchpadLoginWithCredentialsFilez9Tests for Launchpad.login_with() with a credentials file.c                 C   sH   t  ¡ \}}tjd|d�}t |¡}|  |jj|j	jj¡ t
 |¡ d S )Núnot important)rr   Úcredentials_file)ÚtempfileÚmkstempr   Ú
login_withr   Úload_from_pathr   ÚconsumerÚkeyÚcredentialsÚosÚremove)r   ÚignoreÚfilenameÚ	launchpadr‡   r   r   r   Útest_filename  s   ÿ
ÿz3TestLaunchpadLoginWithCredentialsFile.test_filenamec                 C   s6   t  ¡ \}}tƒ }| jttjd||d� t |¡ d S )Nr   )rr   r€   Úcredential_store)	r�   r‚   r   rY   rZ   r   rƒ   rˆ   r‰   )r   rŠ   r‹   Ústorer   r   r   Ú+test_cannot_specify_both_filename_and_store)  s   ûzQTestLaunchpadLoginWithCredentialsFile.test_cannot_specify_both_filename_and_storeN)r   r    r!   r"   r�   r�   r   r   r   r   r~     s    r~   c                   @   s   e Zd Zdd„ ZdS )Ú4TestLaunchpadLoginWithCredentialsFileFromEnvVariablec                 C   sr   t  ¡ \}}|tjd< tjdd�}|  |jt¡ |  	|jj
|¡ t d¡ tjd= |  tj d¡¡ t |¡ d S )NÚLP_CREDENTIALS_FILEr   rq   )r�   r‚   rˆ   Úenvironr   rƒ   ÚassertIsInstancerŽ   r	   r   r‹   ÚunsetenvÚassertIsNoneÚgetr‰   )r   rŠ   r‹   rŒ   r   r   r   r�   :  s   
ÿÿ
zBTestLaunchpadLoginWithCredentialsFileFromEnvVariable.test_filenameN)r   r    r!   r�   r   r   r   r   r‘   6  s    r‘   c                   @   r}   )ÚKeyringTestz*Base class for tests that use the keyring.c                 C   s   t ƒ  tƒ tj_d S r   )r
   r   Úlaunchpadlibr‡   Úkeyringr-   r   r   r   r.   R  s   zKeyringTest.setUpc                 C   s
   t j`d S r   )r™   r‡   rš   r-   r   r   r   ÚtearDownY  s   
zKeyringTest.tearDownN)r   r    r!   r"   r.   r›   r   r   r   r   r˜   O  s    r˜   c                       sÔ   e Zd ZdZ‡ fdd„Z‡ fdd„Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Z‡  ZS )0ÚTestLaunchpadLoginWithz!Tests for Launchpad.login_with().c                    s   t t| ƒ ¡  t ¡ | _d S r   )Úsuperrœ   r.   r�   ÚmkdtempÚtemp_dirr-   ©Ú	__class__r   r   r.   a  s   zTestLaunchpadLoginWith.setUpc                    s   t t| ƒ ¡  t | j¡ d S r   )r�   rœ   r›   ÚshutilÚrmtreerŸ   r-   r    r   r   r›   e  s   zTestLaunchpadLoginWith.tearDownc                 C   s’   t j | jd¡}tjdt|d� |  t j |¡¡ t j |d¡}|  t j |¡¡ |  t j t j |d¡¡¡ t j |d¡}|  	t j |¡¡ d S )Nr™   r   ©r`   Úlaunchpadlib_dirúapi.example.comÚcacher‡   )
rˆ   ÚpathÚjoinrŸ   r   rƒ   rm   r7   ÚisdirÚassertFalse)r   r¥   Úservice_pathÚcredentials_pathr   r   r   Útest_dirs_createdi  s   ýz(TestLaunchpadLoginWith.test_dirs_createdc                 C   s¬   t j | jd¡}t  |¡ t  |d¡ |  t j |¡¡ t  |¡}t 	|j
¡}|  |tjtjB tjB ¡ tjdt|d� t  |¡}t 	|j
¡}|  |tjtjB tjB ¡ d S )Nr™   ií  r   r¤   )rˆ   r¨   r©   rŸ   ÚmkdirÚchmodr7   rª   ÚstatÚS_IMODEÚst_modeÚassertNotEqualÚS_IWRITEÚS_IREADÚS_IEXECr   rƒ   rm   r   ©r   r¥   ÚstatinfoÚmoder   r   r   Ú'test_dirs_created_are_changed_to_secure€  s   

ý
z>TestLaunchpadLoginWith.test_dirs_created_are_changed_to_securec                 C   sf   t j | jd¡}tjdt|d� |  t j |¡¡ t  	|¡}t	 
|j¡}|  |t	jt	jB t	jB ¡ d S )Nr™   r   r¤   )rˆ   r¨   r©   rŸ   r   rƒ   rm   r7   rª   r±   r²   r³   r   rµ   r¶   r·   r¸   r   r   r   Útest_dirs_created_are_secure“  s   ý
z3TestLaunchpadLoginWith.test_dirs_created_are_securec                 C   s\   t j | jd¡}tjdt|dd�}|  |jd d¡ tjdt|dd�}|  |jd d¡ d S )Nr™   r   Úfoo)r`   r¥   ra   ra   Úbar)	rˆ   r¨   r©   rŸ   r   rƒ   rm   r   Úpassed_in_args©r   r¥   rŒ   r   r   r   Útest_version_is_propagated   s   üüz1TestLaunchpadLoginWith.test_version_is_propagatedc                 C   sX   t j | jd¡}tjdt|d�}|  |jj	j
d¡ tjdt|d�}|  |jj	j
d¡ d S )Nr™   zvery importantr¤   )rˆ   r¨   r©   rŸ   r   rƒ   rm   r   r‡   r…   rr   rÀ   r   r   r   Ú#test_application_name_is_propagated¹  s"   ý
ÿ	ý
ÿz:TestLaunchpadLoginWith.test_application_name_is_propagatedc                 C   s6   t tdƒ}tj|d� |  |jd¡ |  |jd¡ d S )Núapplication name©Úauthorization_enginer2   )r   rm   r   rƒ   r   Úrequest_tokens_obtainedÚaccess_tokens_obtained©r   Úenginer   r   r   Ú'test_authorization_engine_is_propagatedÖ  s   
z>TestLaunchpadLoginWith.test_authorization_engine_is_propagatedc                 C   s   |   ttj¡ d S r   )rY   rZ   r   rƒ   r-   r   r   r   Ú)test_login_with_must_identify_applicationß  ó   z@TestLaunchpadLoginWith.test_login_with_must_identify_applicationc                 C   ó   t jdd� d S rp   ©r   rƒ   r-   r   r   r   rt   ä  ó   z;TestLaunchpadLoginWith.test_application_name_identifies_appc                 C   rÍ   rv   rÎ   r-   r   r   r   ry   é  rÏ   z8TestLaunchpadLoginWith.test_consumer_name_identifies_appc                 C   s"   t tdƒ}| jttjd|d� dS )ú;Catch an attempt to specify inconsistent application_names.zapplication name1zapplication name2rÄ   N©r   rm   rY   rZ   r   rƒ   rÈ   r   r   r   Ú+test_inconsistent_application_name_rejectedî  s   ÿ
üzBTestLaunchpadLoginWith.test_inconsistent_application_name_rejectedc                 C   s&   t tddd�}| jttjd|d� dS )rÐ   NÚconsumer_name1rw   Úconsumer_name2rÄ   rÑ   rÈ   r   r   r   Ú(test_inconsistent_consumer_name_rejectedú  s   ÿ
üz?TestLaunchpadLoginWith.test_inconsistent_consumer_name_rejectedc                 C   s.   t tddgd�}| jttjdddg|d� dS )z=Catch an attempt to specify inconsistent allow_access_levels.r…   ÚFOO©rx   Úallow_access_levelsNÚBAR)rx   rØ   rÅ   rÑ   rÈ   r   r   r   Ú.test_inconsistent_allow_access_levels_rejected  s   ÿ
úzETestLaunchpadLoginWith.test_inconsistent_allow_access_levels_rejectedc                 C   s4   dd„ }t |d�}dd„ }| jttjd||d� d S )Nc                   S   ó   d S r   r   r   r   r   r   Ú	callback1  ó   zRTestLaunchpadLoginWith.test_inconsistent_credential_save_failed.<locals>.callback1)Úcredential_save_failedc                   S   rÛ   r   r   r   r   r   r   Ú	callback2  rÝ   zRTestLaunchpadLoginWith.test_inconsistent_credential_save_failed.<locals>.callback2úapp name)rŽ   rÞ   )r   rY   rZ   r   rƒ   )r   rÜ   r�   rß   r   r   r   Ú(test_inconsistent_credential_save_failed  s   

ûz?TestLaunchpadLoginWith.test_inconsistent_credential_save_failedc                 C   sJ   t jddgd�}|  |jjjd¡ |  |jjjd ¡ |  |jjdg¡ d S )Nr…   rÖ   r×   )	r   rƒ   r   r‡   r…   r†   rr   rÅ   rØ   ©r   rŒ   r   r   r   Útest_non_desktop_integration)  s   ÿ
ÿz3TestLaunchpadLoginWith.test_non_desktop_integrationc                 C   s&   t jddgd�}|  |jjdg¡ d S )NrÃ   rÖ   )rØ   ÚDESKTOP_INTEGRATION)r   rƒ   r   rÅ   rØ   râ   r   r   r   Ú<test_desktop_integration_doesnt_happen_without_consumer_name6  s   ÿþzSTestLaunchpadLoginWith.test_desktop_integration_doesnt_happen_without_consumer_namec                 C   sŽ   t ƒ }t ƒ }tjd| jt||d�}|  |jjjt	j
¡ |  |jjjd¡ |  |jjdg¡ tttj | jdd¡||tjd�}|  |j|¡ d S )Nrà   )r¥   r`   ÚtimeoutÚ
proxy_inforä   r¦   r§   )r`   r§   ræ   rç   ra   )Úobjectr   rƒ   rŸ   rm   r   r‡   Úaccess_tokenr†   r   ÚACCESS_TOKEN_KEYr…   rr   rÅ   rØ   Údictrˆ   r¨   r©   rf   r¿   )r   ræ   rç   rŒ   Úexpected_argumentsr   r   r   Ú*test_no_credentials_creates_new_credentialC  s8   ûþ
ÿþûzATestLaunchpadLoginWith.test_no_credentials_creates_new_credentialc                 C   s`   t jd| jtd�}|  |jjjd¡ |  |jjjd¡ t	j
 | jddd¡}|  t	j
 |¡¡ dS )z)Test the anonymous login helper function.zanonymous access)r¥   r`   Ú r¦   r‡   N)r   Úlogin_anonymouslyrŸ   rm   r   r‡   ré   r†   Úsecretrˆ   r¨   r©   r«   Úexists)r   rŒ   r­   r   r   r   Útest_anonymous_logine  s   ý
ÿz+TestLaunchpadLoginWith.test_anonymous_loginc              
   C   s¾   t  t j | jdd¡¡ t j | jddd¡}tddtddƒd�}| |¡ tƒ }tƒ }d}t	j
d| jt|||d	�}tt|||t j | jdd
¡d�}| ¡ D ]\}}	|j| }
|  |
|	¡ qMd S )Nr¦   r‡   rà   zconsumer_secret:42zaccess_key:84zaccess_secret:168)Úconsumer_secretré   r½   )r¥   r`   ræ   rç   ra   r§   )r`   ræ   rç   ra   r§   )rˆ   Úmakedirsr¨   r©   rŸ   r   r   Úsave_to_pathrè   r   rƒ   rm   rë   r   r¿   r   )r   Úcredentials_file_pathr‡   ræ   rç   ra   rŒ   rì   r†   ÚexpectedÚactualr   r   r   Ú-test_existing_credentials_arguments_passed_onu  sD   ÿ
ÿý
úû
þzDTestLaunchpadLoginWith.test_existing_credentials_arguments_passed_onc              	   C   sž   t j d¡}| jt jd< tjdtd�}|d ur|t jd< nt jd= |jd }t j 	t j 
|dd¡¡}|  |t j 
| jd¡¡ |  t j t j 
|dd¡¡¡ d S )NÚHOMErà   rc   r§   z..z.launchpadlibr¦   )rˆ   r“   r—   rŸ   r   rƒ   rm   r¿   r¨   Úabspathr©   r   r7   rñ   )r   Úold_homerŒ   Ú	cache_dirr¥   r   r   r   Útest_None_launchpadlib_dir›  s$   ÿ
ÿÿÿz1TestLaunchpadLoginWith.test_None_launchpadlib_dirc                 C   sb   t  dd¡}|  |jd d¡ t  dtjd ¡}|  |jd tjd ¡ d}|  tt jdd¡ d S )Nrà   r&   r`   z"https://api.staging.launchpad.net/)rà   zhttps://r½   )r   rƒ   r   r¿   r   r@   rY   rZ   râ   r   r   r   Útest_short_service_name´  s    þ
ÿþ
ÿz.TestLaunchpadLoginWith.test_short_service_namec                 C   s   t jddd� d S )Nr   é   )Úmax_failed_attemptsrÎ   r-   r   r   r   Ú!test_max_failed_attempts_acceptedÍ  rÌ   z8TestLaunchpadLoginWith.test_max_failed_attempts_accepted)r   r    r!   r"   r.   r›   r®   r»   r¼   rÁ   rÂ   rÊ   rË   rt   ry   rÒ   rÕ   rÚ   rá   rã   rå   rí   rò   rù   rþ   rÿ   r  Ú__classcell__r   r   r    r   rœ   ^  s2    	"&rœ   c                   @   r}   )ÚTestDeprecatedLoginMethodsz2Make sure the deprecated login methods still work.c                 C   sx   t jdd��,}t  d¡ t  dt¡ t ddd¡ |  t|ƒd¡ |  |d	 jt	¡ W d   ƒ d S 1 s5w   Y  d S )
NTr/   r1   rŠ   r…   Útokenrð   r2   r   )
r3   r4   r5   ÚPendingDeprecationWarningr   Úloginr   r6   r9   r:   ©r   r=   r   r   r   Útest_login_is_deprecatedÖ  s   
"ûz3TestDeprecatedLoginMethods.test_login_is_deprecatedc                 C   s€   t jdd��0}t  d¡ t  dt¡ t  dd¡ t d¡ |  t|ƒd¡ |  |d j	t
¡ W d   ƒ d S 1 s9w   Y  d S )	NTr/   r1   rŠ   z.*next release of cryptographyr…   r2   r   )r3   r4   r5   r  Úfilterwarningsr   Úget_token_and_loginr   r6   r9   r:   r  r   r   r   Ú&test_get_token_and_login_is_deprecatedß  s   
ÿ
"øzATestDeprecatedLoginMethods.test_get_token_and_login_is_deprecatedN)r   r    r!   r"   r	  r  r   r   r   r   r  Ó  s    	r  c                   @   sv   e Zd Zdd„ Zdd„ Ze ededd„ ƒ¡dd	„ ƒZ	e eded
d„ ƒ¡dd„ ƒZ
e ededd„ ƒ¡dd„ ƒZdS )Ú!TestCredenitialSaveFailedCallbackc                 C   ó   t ƒ tj_t ¡ | _d S r   ©r   r™   rŒ   Úsocketr�   rž   rŸ   r-   r   r   r   r.   ð  ó   
z'TestCredenitialSaveFailedCallback.setUpc                 C   ó   t tj_ t | j¡ d S r   ©r  r™   rŒ   r¢   r£   rŸ   r-   r   r   r   r›   ÷  ó   z*TestCredenitialSaveFailedCallback.tearDownÚ_is_sudoc                   C   ó   dS ©NFr   r   r   r   r   Ú<lambda>û  ó    z*TestCredenitialSaveFailedCallback.<lambda>c                    sv   g ‰ ‡ fdd„}t j | jd¡}d}ttƒ ƒ� tjd|||d� |  t	ˆ ƒd¡ W d   ƒ d S 1 s4w   Y  d S )Nc                      s   ˆ   d ¡ d S r   )Úappendr   ©Úcallback_calledr   r   Úcallback  s   zPTestCredenitialSaveFailedCallback.test_credentials_save_failed.<locals>.callbackr™   r   r   )r`   r¥   rÞ   r2   )
rˆ   r¨   r©   rŸ   r   r   r   rƒ   r   r6   )r   r  r¥   r`   r   r  r   Útest_credentials_save_failedû  s   ü"ùz>TestCredenitialSaveFailedCallback.test_credentials_save_failedc                   C   r  r  r   r   r   r   r   r    r  c                 C   sZ   t j | jd¡}d}ttƒ ƒ� | jttj	d||d� W d   ƒ d S 1 s&w   Y  d S ©Nr™   r   r   r¤   )
rˆ   r¨   r©   rŸ   r   r   rY   ÚRuntimeErrorr   rƒ   ©r   r¥   r`   r   r   r   Ú:test_default_credentials_save_failed_is_to_raise_exception  s   û"ÿz\TestCredenitialSaveFailedCallback.test_default_credentials_save_failed_is_to_raise_exceptionc                   C   r  )NTr   r   r   r   r   r  !  r  c                 C   sT   t j | jd¡}d}ttƒ ƒ� tjd||d� W d   ƒ d S 1 s#w   Y  d S r  )rˆ   r¨   r©   rŸ   r   r   r   rƒ   r!  r   r   r   Ú>test_credentials_save_fail_under_sudo_does_not_raise_exception!  s   ý"ÿz`TestCredenitialSaveFailedCallback.test_credentials_save_fail_under_sudo_does_not_raise_exceptionN)r   r    r!   r.   r›   r   rè   r   Ústaticmethodr  r"  r#  r   r   r   r   r  ì  s    

r  c                   @   sX   e Zd Zdd„ Zdd„ Ze ededd„ ƒ¡dd	„ ƒZ	e eded
d„ ƒ¡dd„ ƒZ
dS )ÚTestMultipleSitesc                 C   r  r   r  r-   r   r   r   r.   4  r  zTestMultipleSites.setUpc                 C   r  r   r  r-   r   r   r   r›   ;  r  zTestMultipleSites.tearDownr  c                   C   r  r  r   r   r   r   r   r  ?  r  zTestMultipleSites.<lambda>c                 C   s¦   t j | jd¡}tƒ }d}d}t|ƒ� tj|||d�}|jj	j
}W d   ƒ n1 s+w   Y  t|j ¡ ƒd d }|  ||¡ |  ||¡ |  ||d | ¡ d S )Nr™   r   zSuper App 3000r¤   r   r2   ú@)rˆ   r¨   r©   rŸ   r   r   r   rƒ   r‡   r…   r†   ÚlistÚdatarA   r;   r   )r   r¥   rš   r`   rr   rŒ   rx   Úapplication_keyr   r   r   Ú"test_components_of_application_key?  s    
ýúz4TestMultipleSites.test_components_of_application_keyc                   C   r  r  r   r   r   r   r   r  Z  r  c                 C   s¾   t j | jd¡}tƒ }|jrJ dƒ‚t|ƒ� tjdd|d� tjdd|d� W d   ƒ n1 s1w   Y  t	|j 
¡ ƒdksAJ ‚t|j 
¡ ƒd d	 }t|j 
¡ ƒd	 d	 }|  ||¡ d S )
Nr™   z$oops, a fresh keyring has data in itrÃ   zhttp://alpha.example.com/r¤   zhttp://beta.example.com/é   r   r2   )rˆ   r¨   r©   rŸ   r   r(  r   r   rƒ   r6   rA   r'  r´   )r   r¥   rš   Úapplication_key_1Úapplication_key_2r   r   r   Útest_same_app_different_serversZ  s&   
ýýøz1TestMultipleSites.test_same_app_different_serversN)r   r    r!   r.   r›   r   rè   r   r$  r*  r.  r   r   r   r   r%  /  s    
r%  c                   C   s   t  ¡  t¡S r   )ÚunittestÚ
TestLoaderÚloadTestsFromNamer   r   r   r   r   Ú
test_suitew  s   r2  )1r"   ÚtypeÚ__metaclass__Ú
contextlibr   rˆ   r¢   r  r±   r�   r/  Úunittest.mockr   ÚImportErrorÚmockr3   Úlazr.restfulclient.resourcer   Úlaunchpadlib.credentialsr   r   r™   r   Úlaunchpadlib.launchpadr   r	   Úlaunchpadlib.testing.helpersr
   r   r   r   r   r   r   r   rm   ÚTestCaser   r#   r_   rk   r~   r‘   r˜   rœ   r  r  r%  r2  r   r   r   r   Ú<module>   sL   ÿ$	
t8#  wCH