U
    úœ^ë|  ã                   @   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k
rt   ddlmZ Y nX 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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)ƒZ*G dd„ de)ƒZ+G dd„ de
j#ƒZ,G dd„ de
j#ƒZ-d d!„ Z.dS )"zTests for the Launchpad class.é    )ÚcontextmanagerN)Úpatch)ÚServiceRoot)ÚAccessTokenÚCredentials)Úuris)Ú	Launchpad)Úassert_keyring_not_importedÚBadSaveKeyringÚfake_keyringÚFauxSocketModuleÚInMemoryKeyringÚNoNetworkAuthorizationEngineÚNoNetworkLaunchpad)ÚKeyringCredentialStoreúhttp://api.example.com/c                   @   s   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   ZRESOURCE_TYPE_CLASSESÚitemsÚassertEqualr   )ÚselfÚnameÚcls© r   úC/usr/lib/python3/dist-packages/launchpadlib/tests/test_launchpad.pyÚtest_resource_types?   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 dddddddgƒ| _d S )NÚ
productionZ	qastagingÚstagingZdogfoodZdevZtest_devÚedge)ÚsortedÚaliases©r   r   r   r   ÚsetUpI   s    
 ÿÿzTestNameLookups.setUpc              	   c   sd   t jddN}t  d¡ d V  |  t|ƒd¡ |\}|  t|jtƒ¡ |  	dt
|ƒ¡ W 5 Q R X d S )NT©ÚrecordÚalwaysé   zno longer exists)ÚwarningsÚcatch_warningsÚsimplefilterr   ÚlenÚ
assertTrueÚ
issubclassÚcategoryÚDeprecationWarningÚassertInÚstr)r   ÚcaughtZwarningr   r   r   Úedge_deprecation_errorN   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_names[   s    z TestNameLookups.test_short_namesc              	   C   s0   |   ¡  |  t d¡t d¡¡ W 5 Q R X d S ©Nr#   r!   ©r7   r   r   Úlookup_service_rootr&   r   r   r   Ú$test_edge_service_root_is_production`   s    
ÿz4TestNameLookups.test_edge_service_root_is_productionc              	   C   s0   |   ¡  |  t d¡t d¡¡ W 5 Q R X d S r<   ©r7   r   r   Úlookup_web_rootr&   r   r   r   Ú test_edge_web_root_is_productiong   s    
ÿz0TestNameLookups.test_edge_web_root_is_productionc              	   C   s2   |   ¡   |  t tj¡t d¡¡ W 5 Q R X d S ©Nr!   ©r7   r   r   r>   ZEDGE_SERVICE_ROOTr&   r   r   r   Ú-test_edge_service_root_url_becomes_productionn   s    
ÿz=TestNameLookups.test_edge_service_root_url_becomes_productionc              	   C   s2   |   ¡   |  t tj¡t d¡¡ W 5 Q R X d S rC   )r7   r   r   rA   ZEDGE_WEB_ROOTr&   r   r   r   Ú)test_edge_web_root_url_becomes_productions   s    
ÿz9TestNameLookups.test_edge_web_root_url_becomes_productionc              	   C   s2   |   ¡   |  t tj¡t d¡¡ W 5 Q R X d S rC   rD   r&   r   r   r   Ú/test_top_level_edge_constant_becomes_productionx   s    
ÿz?TestNameLookups.test_top_level_edge_constant_becomes_productionc              	   C   s0   |   ¡  |  t d¡t d¡¡ W 5 Q R X d S )Nzhttps://api.edge.launchpad.net/r!   r=   r&   r   r   r   Ú5test_edge_server_equivalent_string_becomes_production}   s
    
þzETestNameLookups.test_edge_server_equivalent_string_becomes_productionc              	   C   s0   |   ¡  |  t d¡t d¡¡ W 5 Q R X d S )Nzhttps://edge.launchpad.net/r!   r@   r&   r   r   r   Ú9test_edge_web_server_equivalent_string_becomes_productionƒ   s
    
þzITestNameLookups.test_edge_web_server_equivalent_string_becomes_productionc              	   C   sÀ   |   ¡ * | jD ]}|  t |¡tj| ¡ qW 5 Q R X |   ¡ * | jD ]}|  t |¡tj| ¡ qHW 5 Q R X d}|  t |¡|¡ |  t |¡|¡ d}|  t	tj|¡ |  t	tj|¡ dS )z=Ensure that short service names turn into long service names.zhttp://some-other-server.comz	not-a-urlN)
r7   r%   r   r   r>   r8   rA   r:   ÚassertRaisesÚ
ValueError)r   ÚaliasZ
other_rootZ	not_a_urlr   r   r   Útest_lookups‰   s$    

 ÿ

 ÿzTestNameLookups.test_lookupsN)r   r   r   r   r'   r   r7   r;   r?   rB   rE   rF   rG   rH   rI   rM   r   r   r   r   r    F   s   
r    c                   @   s   e Zd ZdZdd„ ZdS )Ú"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 n6 tk
r^ } z|  t|ƒ d¡¡ W 5 d }~X Y n
X tdƒ‚|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!ú/©rO   )r   r8   r   rK   r0   r5   Ú
startswithÚAssertionErrorrJ   r   ÚDEFAULT_VERSION)r   rP   ÚrootÚeZdefault_versionr   r   r   Ú'test_service_name_with_embedded_version³   s*    ÿÿ ÿÿzJTestServiceNameWithEmbeddedVersion.test_service_name_with_embedded_versionN)r   r   r   r   rX   r   r   r   r   rN   ¤   s   rN   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   ©rJ   rK   r   ÚSERVICE_ROOTr&   r   r   r   Útest_app_must_be_identifiedÔ   s
      ÿz?TestRequestTokenAuthorizationEngine.test_app_must_be_identifiedc                 C   s   t tdd d S ©Nr   )Úapplication_name©r   r[   r&   r   r   r   Ú$test_application_name_identifies_appØ   s    zHTestRequestTokenAuthorizationEngine.test_application_name_identifies_appc                 C   s   t tdd d S ©Nr   ©Úconsumer_namer_   r&   r   r   r   Ú!test_consumer_name_identifies_appÛ   s    zETestRequestTokenAuthorizationEngine.test_consumer_name_identifies_appc                 C   s,   | j tttddd | j tttddd d S )NZname1Zname2)r^   rc   r   rZ   r&   r   r   r   Ú#test_conflicting_app_identificationÞ   s       þ   þzGTestRequestTokenAuthorizationEngine.test_conflicting_app_identificationN)r   r   r   r   r\   r`   rd   re   r   r   r   r   rY   Ñ   s
   rY   c                   @   s    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)r^   Úcredentials_file)ÚtempfileÚmkstempr   Ú
login_withr   Zload_from_pathr   ÚconsumerÚkeyÚcredentialsÚosÚremove)r   ÚignoreÚfilenameÚ	launchpadrn   r   r   r   Útest_filenameî   s     ÿ

ÿz3TestLaunchpadLoginWithCredentialsFile.test_filenamec                 C   s6   t  ¡ \}}tƒ }| jttjd||d t |¡ d S )Nrg   )r^   rh   Úcredential_store)	ri   rj   r   rJ   rK   r   rk   ro   rp   )r   rq   rr   Ústorer   r   r   Ú+test_cannot_specify_both_filename_and_storeú   s      ýzQTestLaunchpadLoginWithCredentialsFile.test_cannot_specify_both_filename_and_storeN)r   r   r   r   rt   rw   r   r   r   r   rf   ë   s   rf   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚKeyringTestz*Base class for tests that use the keyring.c                 C   s   t ƒ  tƒ tj_d S r   )r	   r   Úlaunchpadlibrn   Úkeyringr&   r   r   r   r'     s    zKeyringTest.setUpc                 C   s
   t j`d S r   )ry   rn   rz   r&   r   r   r   ÚtearDown  s    zKeyringTest.tearDownN)r   r   r   r   r'   r{   r   r   r   r   rx     s   rx   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'   ri   ÚmkdtempÚtemp_dirr&   ©Ú	__class__r   r   r'     s    zTestLaunchpadLoginWith.setUpc                    s   t t| ƒ ¡  t | j¡ d S r   )r}   r|   r{   ÚshutilÚrmtreer   r&   r€   r   r   r{     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 )Nry   rg   ©rO   Úlaunchpadlib_dirúapi.example.comÚcachern   )
ro   ÚpathÚjoinr   r   rk   r[   r0   ÚisdirÚassertFalse)r   r…   Zservice_pathÚcredentials_pathr   r   r   Útest_dirs_created  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 )Nry   ií  rg   r„   )ro   rˆ   r‰   r   ÚmkdirÚchmodr0   rŠ   ÚstatÚS_IMODEÚst_modeÚassertNotEqualÚS_IWRITEÚS_IREADÚS_IEXECr   rk   r[   r   ©r   r…   ZstatinfoÚmoder   r   r   Ú'test_dirs_created_are_changed_to_secure4  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 )Nry   rg   r„   )ro   rˆ   r‰   r   r   rk   r[   r0   rŠ   r   r‘   r’   r   r”   r•   r–   r—   r   r   r   Útest_dirs_created_are_secureE  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 )Nry   rg   Úfoo)rO   r…   rP   rP   Zbar)	ro   rˆ   r‰   r   r   rk   r[   r   Úpassed_in_args©r   r…   rs   r   r   r   Útest_version_is_propagatedP  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 )Nry   zvery importantr„   )ro   rˆ   r‰   r   r   rk   r[   r   rn   rl   r^   r   r   r   r   Ú#test_application_name_is_propagatedc  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_enginer+   )r   r[   r   rk   r   Zrequest_tokens_obtainedZaccess_tokens_obtained©r   Zenginer   r   r   Ú'test_authorization_engine_is_propagatedz  s     ÿz>TestLaunchpadLoginWith.test_authorization_engine_is_propagatedc                 C   s   |   ttj¡ d S r   )rJ   rK   r   rk   r&   r   r   r   Ú)test_login_with_must_identify_application„  s    z@TestLaunchpadLoginWith.test_login_with_must_identify_applicationc                 C   s   t jdd d S r]   ©r   rk   r&   r   r   r   r`   ‰  s    z;TestLaunchpadLoginWith.test_application_name_identifies_appc                 C   s   t jdd d S ra   r¦   r&   r   r   r   rd   Ž  s    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   r[   rJ   rK   r   rk   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§   NZconsumer_name1rb   Z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.rl   ÚFOO©rc   Úallow_access_levelsNZBAR)rc   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   s   d S r   r   r   r   r   r   Ú	callback1²  s    zRTestLaunchpadLoginWith.test_inconsistent_credential_save_failed.<locals>.callback1)Úcredential_save_failedc                   S   s   d S r   r   r   r   r   r   Ú	callback2¶  s    zRTestLaunchpadLoginWith.test_inconsistent_credential_save_failed.<locals>.callback2úapp name)ru   r°   )r   rJ   rK   r   rk   )r   r¯   rv   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 )Nrl   r«   r¬   )	r   rk   r   rn   rl   rm   r^   r¢   r­   ©r   rs   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   rk   r   r¢   r­   r´   r   r   r   Ú<test_desktop_integration_doesnt_happen_without_consumer_nameÈ  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…   rO   ÚtimeoutÚ
proxy_infor¶   r†   r‡   )rO   r‡   r¸   r¹   rP   )Úobjectr   rk   r   r[   r   rn   Úaccess_tokenrm   r   ZACCESS_TOKEN_KEYrl   r^   r¢   r­   Údictro   rˆ   r‰   rU   rœ   )r   r¸   r¹   rs   Úexpected_argumentsr   r   r   Ú*test_no_credentials_creates_new_credentialÒ  s4       þÿÿ
ÿû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…   rO   Ú r†   rn   N)r   Zlogin_anonymouslyr   r[   r   rn   r»   rm   Úsecretro   rˆ   r‰   r‹   Úexists)r   rs   rŒ   r   r   r   Útest_anonymous_loginê  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| }
|  |
|	¡ qšd S )Nr†   rn   r²   zconsumer_secret:42zaccess_key:84zaccess_secret:168)Zconsumer_secretr»   r›   )r…   rO   r¸   r¹   rP   r‡   )rO   r¸   r¹   rP   r‡   )ro   Úmakedirsrˆ   r‰   r   r   r   Zsave_to_pathrº   r   rk   r[   r¼   r   rœ   r   )r   Zcredentials_file_pathrn   r¸   r¹   rP   rs   r½   rm   ZexpectedZactualr   r   r   Ú-test_existing_credentials_arguments_passed_onø  sH    ÿ   ÿ þ
   ýû
zDTestLaunchpadLoginWith.test_existing_credentials_arguments_passed_onc              	   C   sž   t j d¡}| jt jd< tjdtd}|d k	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²   rR   r‡   z..z.launchpadlibr†   )ro   ÚenvironÚgetr   r   rk   r[   rœ   rˆ   Úabspathr‰   r   r0   rÁ   )r   Zold_homers   Z	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"   rO   z"https://api.staging.launchpad.net/)r²   zhttps://r›   )r   rk   r   rœ   r   r8   rJ   rK   r´   r   r   r   Útest_short_service_name*  s(    þ ÿþ   ÿz.TestLaunchpadLoginWith.test_short_service_namec                 C   s   t jddd d S )Nrg   é   )Zmax_failed_attemptsr¦   r&   r   r   r   Ú!test_max_failed_attempts_accepted?  s     ÿz8TestLaunchpadLoginWith.test_max_failed_attempts_accepted)r   r   r   r   r'   r{   r   r™   rš   rž   rŸ   r¤   r¥   r`   rd   r©   rª   r®   r³   rµ   r·   r¾   rÂ   rÄ   rÉ   rÊ   rÌ   Ú__classcell__r   r   r€   r   r|     s0   
	
r|   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTestDeprecatedLoginMethodsz2Make sure the deprecated login methods still work.c              	   C   sb   t jddL}t  d¡ t  dt¡ t ddd¡ |  t|ƒd¡ |  |d	 jt	¡ W 5 Q R X d S )
NTr(   r*   rq   rl   ÚtokenrÀ   r+   r   )
r,   r-   r.   ÚPendingDeprecationWarningr   Zloginr   r/   r2   r3   ©r   r6   r   r   r   Útest_login_is_deprecatedI  s    
z3TestDeprecatedLoginMethods.test_login_is_deprecatedc              	   C   s^   t jddH}t  d¡ t  dt¡ t d¡ |  t|ƒd¡ |  |d jt	¡ W 5 Q R X d S )NTr(   r*   rq   rl   r+   r   )
r,   r-   r.   rÐ   r   Zget_token_and_loginr   r/   r2   r3   rÑ   r   r   r   Ú&test_get_token_and_login_is_deprecatedR  s    

zATestDeprecatedLoginMethods.test_get_token_and_login_is_deprecatedN)r   r   r   r   rÒ   rÓ   r   r   r   r   rÎ   F  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   s   t ƒ tj_t ¡ | _d S r   ©r   ry   rs   Úsocketri   r~   r   r&   r   r   r   r'   `  s    
z'TestCredenitialSaveFailedCallback.setUpc                 C   s   t tj_ t | j¡ d S r   ©rÖ   ry   rs   r‚   rƒ   r   r&   r   r   r   r{   g  s    z*TestCredenitialSaveFailedCallback.tearDownÚ_is_sudoc                   C   s   dS ©NFr   r   r   r   r   Ú<lambda>k  ó    z*TestCredenitialSaveFailedCallback.<lambda>c              	      s`   g ‰ ‡ fdd„}t j | jd¡}d}ttƒ ƒ( tjd|||d |  t	ˆ ƒd¡ W 5 Q R X d S )Nc                      s   ˆ   d ¡ d S r   )Úappendr   ©Zcallback_calledr   r   Úcallbackq  s    zPTestCredenitialSaveFailedCallback.test_credentials_save_failed.<locals>.callbackry   r   rg   )rO   r…   r°   r+   )
ro   rˆ   r‰   r   r   r
   r   rk   r   r/   )r   rÞ   r…   rO   r   rÝ   r   Útest_credentials_save_failedk  s     ýz>TestCredenitialSaveFailedCallback.test_credentials_save_failedc                   C   s   dS rÙ   r   r   r   r   r   rÚ     rÛ   c              	   C   sD   t j | jd¡}d}ttƒ ƒ | jttj	d||d W 5 Q R X d S ©Nry   r   rg   r„   )
ro   rˆ   r‰   r   r   r
   rJ   ÚRuntimeErrorr   rk   ©r   r…   rO   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   s   dS )NTr   r   r   r   r   rÚ   Œ  rÛ   c              	   C   s>   t j | jd¡}d}ttƒ ƒ tjd||d W 5 Q R X d S rà   )ro   rˆ   r‰   r   r   r
   r   rk   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   s   t ƒ tj_t ¡ | _d S r   rÕ   r&   r   r   r   r'     s    
zTestMultipleSites.setUpc                 C   s   t tj_ t | j¡ d S r   r×   r&   r   r   r   r{   ¤  s    zTestMultipleSites.tearDownrØ   c                   C   s   dS 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 5 Q R X t|j ¡ ƒd d }|  ||¡ |  ||¡ |  ||d | ¡ d S )Nry   r   zSuper App 3000r„   r   r+   ú@)ro   rˆ   r‰   r   r   r   r   rk   rn   rl   rm   ÚlistÚdatar9   r4   r   )r   r…   rz   rO   r^   rs   rc   Zapplication_keyr   r   r   Ú"test_components_of_application_key¨  s    
 þz4TestMultipleSites.test_components_of_application_keyc                   C   s   dS rÙ   r   r   r   r   r   rÚ   Á  rÛ   c              	   C   sª   t j | jd¡}tƒ }|jr$tdƒ‚t|ƒ& tj	dd|d tj	dd|d W 5 Q R X t
|j ¡ ƒdksnt‚t|j ¡ ƒd d	 }t|j ¡ ƒd	 d	 }|  ||¡ d S )
Nry   z$oops, a fresh keyring has data in itr    zhttp://alpha.example.com/r„   zhttp://beta.example.com/é   r   r+   )ro   rˆ   r‰   r   r   ré   rT   r   r   rk   r/   r9   rè   r“   )r   r…   rz   Zapplication_key_1Zapplication_key_2r   r   r   Útest_same_app_different_serversÁ  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   )ÚunittestZ
TestLoaderZloadTestsFromNamer   r   r   r   r   Ú
test_suiteÚ  s    rî   )/r   ÚtypeZ__metaclass__Ú
contextlibr   ro   r‚   rÖ   r   ri   rí   Zunittest.mockr   ÚImportErrorZmockr,   Zlazr.restfulclient.resourcer   Zlaunchpadlib.credentialsr   r   ry   r   Zlaunchpadlib.launchpadr   Zlaunchpadlib.testing.helpersr	   r
   r   r   r   r   r   r   r[   ZTestCaser   r    rN   rY   rf   rx   r|   rÎ   rÔ   ræ   rî   r   r   r   r   Ú<module>   sD   $	
^-  5<B