HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/launchpadlib/tests/__pycache__/test_launchpad.cpython-38.pyc
U

��^�|�@s�dZeZddlmZddlZddlZddlZddlZddl	Z	ddl
Z
zddlmZWn e
k
rtddlmZYnXddlZddlmZddlmZmZddlmZddlZddlmZdd	lmZmZmZmZmZmZm Z dd
lm!Z!dZ"Gdd
�d
e
j#�Z$Gdd�de
j#�Z%Gdd�de
j#�Z&Gdd�de
j#�Z'Gdd�de
j#�Z(Gdd�de
j#�Z)Gdd�de)�Z*Gdd�de)�Z+Gdd�de
j#�Z,Gdd�de
j#�Z-d d!�Z.dS)"zTests 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@seZdZdZdd�ZdS)�TestResourceTypeClassesz<launchpadlib must know about restfulclient's resource types.cCs*tj��D]\}}|�tj||�q
dS�N)rZRESOURCE_TYPE_CLASSES�items�assertEqualr)�self�name�cls�r�C/usr/lib/python3/dist-packages/launchpadlib/tests/test_launchpad.py�test_resource_types?sz+TestResourceTypeClasses.test_resource_typesN)�__name__�
__module__�__qualname__�__doc__rrrrrr<src@sleZdZdZdd�Zedd��Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�TestNameLookupsz0Test the utility functions in the 'uris' module.cCstdddddddg�|_dS)N�
productionZ	qastaging�stagingZdogfoodZdevZtest_dev�edge)�sorted�aliases�rrrr�setUpIs
��zTestNameLookups.setUpc	csdtjdd��N}t�d�dV|�t|�d�|\}|�t|jt��|�	dt
|��W5QRXdS)NT��record�always�zno longer exists)�warnings�catch_warnings�simplefilterr�len�
assertTrue�
issubclass�category�DeprecationWarning�assertIn�str)r�caughtZwarningrrr�edge_deprecation_errorNs
z&TestNameLookups.edge_deprecation_errorcCs4|�ttj���|j�|�ttj���|j�dSr)rr$r�
service_roots�keysr%�	web_rootsr&rrr�test_short_names[sz TestNameLookups.test_short_namesc	Cs0|���|�t�d�t�d��W5QRXdS�Nr#r!�r7rr�lookup_service_rootr&rrr�$test_edge_service_root_is_production`s
�z4TestNameLookups.test_edge_service_root_is_productionc	Cs0|���|�t�d�t�d��W5QRXdSr<�r7rr�lookup_web_rootr&rrr� test_edge_web_root_is_productiongs
�z0TestNameLookups.test_edge_web_root_is_productionc	Cs2|��� |�t�tj�t�d��W5QRXdS�Nr!�r7rrr>ZEDGE_SERVICE_ROOTr&rrr�-test_edge_service_root_url_becomes_productionns
�z=TestNameLookups.test_edge_service_root_url_becomes_productionc	Cs2|��� |�t�tj�t�d��W5QRXdSrC)r7rrrAZ
EDGE_WEB_ROOTr&rrr�)test_edge_web_root_url_becomes_productionss
�z9TestNameLookups.test_edge_web_root_url_becomes_productionc	Cs2|��� |�t�tj�t�d��W5QRXdSrCrDr&rrr�/test_top_level_edge_constant_becomes_productionxs
�z?TestNameLookups.test_top_level_edge_constant_becomes_productionc	Cs0|���|�t�d�t�d��W5QRXdS)Nzhttps://api.edge.launchpad.net/r!r=r&rrr�5test_edge_server_equivalent_string_becomes_production}s

�zETestNameLookups.test_edge_server_equivalent_string_becomes_productionc	Cs0|���|�t�d�t�d��W5QRXdS)Nzhttps://edge.launchpad.net/r!r@r&rrr�9test_edge_web_server_equivalent_string_becomes_production�s

�zITestNameLookups.test_edge_web_server_equivalent_string_becomes_productionc	Cs�|���*|jD]}|�t�|�tj|�qW5QRX|���*|jD]}|�t�|�tj|�qHW5QRXd}|�t�|�|�|�t�|�|�d}|�t	tj|�|�t	tj|�dS)z=Ensure that short service names turn into long service names.zhttp://some-other-server.comz	not-a-urlN)
r7r%rrr>r8rAr:�assertRaises�
ValueError)r�aliasZ
other_rootZ	not_a_urlrrr�test_lookups�s$

�

�zTestNameLookups.test_lookupsN)rrrrr'rr7r;r?rBrErFrGrHrIrMrrrrr Fs
r c@seZdZdZdd�ZdS)�"TestServiceNameWithEmbeddedVersiona3Reject 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
Cs�d}tjd|}ztddd||d�Wn6tk
r^}z|�t|��d��W5d}~XYn
Xtd��|d7}|jttddd||d�t	j
}tjd|d}|jttddd|d�dS)Nzversion-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)rr8rrKr0r5�
startswith�AssertionErrorrJr�DEFAULT_VERSION)rrP�root�eZdefault_versionrrr�'test_service_name_with_embedded_version�s*����zJTestServiceNameWithEmbeddedVersion.test_service_name_with_embedded_versionN)rrrrrXrrrrrN�srNc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�#TestRequestTokenAuthorizationEnginez4Tests for the RequestTokenAuthorizationEngine class.cCs|�ttt�dSr�rJrKr�SERVICE_ROOTr&rrr�test_app_must_be_identified�s
�z?TestRequestTokenAuthorizationEngine.test_app_must_be_identifiedcCsttdd�dS�Nr)�application_name�rr[r&rrr�$test_application_name_identifies_app�szHTestRequestTokenAuthorizationEngine.test_application_name_identifies_appcCsttdd�dS�Nr��
consumer_namer_r&rrr�!test_consumer_name_identifies_app�szETestRequestTokenAuthorizationEngine.test_consumer_name_identifies_appcCs,|jtttddd�|jtttddd�dS)NZname1Zname2)r^rcrrZr&rrr�#test_conflicting_app_identification�s��zGTestRequestTokenAuthorizationEngine.test_conflicting_app_identificationN)rrrrr\r`rdrerrrrrY�s
rYc@s eZdZdZdd�Zdd�ZdS)�%TestLaunchpadLoginWithCredentialsFilez9Tests for Launchpad.login_with() with a credentials file.cCsHt��\}}tjd|d�}t�|�}|�|jj|j	jj�t
�|�dS)N�
not important)r^�credentials_file)�tempfile�mkstempr�
login_withrZload_from_pathr�consumer�key�credentials�os�remove)r�ignore�filename�	launchpadrnrrr�
test_filename�s�

�z3TestLaunchpadLoginWithCredentialsFile.test_filenamecCs6t��\}}t�}|jttjd||d�t�|�dS)Nrg)r^rh�credential_store)	rirjrrJrKrrkrorp)rrqrr�storerrr�+test_cannot_specify_both_filename_and_store�s�zQTestLaunchpadLoginWithCredentialsFile.test_cannot_specify_both_filename_and_storeN)rrrrrtrwrrrrrf�srfc@s eZdZdZdd�Zdd�ZdS)�KeyringTestz*Base class for tests that use the keyring.cCst�t�tj_dSr)r	r
�launchpadlibrn�keyringr&rrrr'szKeyringTest.setUpcCs
tj`dSr)ryrnrzr&rrr�tearDownszKeyringTest.tearDownN)rrrrr'r{rrrrrxsrxcs�eZdZdZ�fdd�Z�fdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Z�ZS)0�TestLaunchpadLoginWithz!Tests for Launchpad.login_with().cstt|���t��|_dSr)�superr|r'ri�mkdtemp�temp_dirr&��	__class__rrr'szTestLaunchpadLoginWith.setUpcstt|���t�|j�dSr)r}r|r{�shutil�rmtreerr&r�rrr{szTestLaunchpadLoginWith.tearDowncCs�tj�|jd�}tjdt|d�|�tj�|��tj�|d�}|�tj�|��|�tj�tj�|d���tj�|d�}|�	tj�|��dS)Nryrg�rO�launchpadlib_dir�api.example.com�cachern)
ro�path�joinrrrkr[r0�isdir�assertFalse)rr�Zservice_path�credentials_pathrrr�test_dirs_createds��z(TestLaunchpadLoginWith.test_dirs_createdcCs�tj�|jd�}t�|�t�|d�|�tj�|��t�|�}t�	|j
�}|�|tjtj
BtjB�tjdt|d�t�|�}t�	|j
�}|�|tjtj
BtjB�dS)Nryi�rgr�)ror�r�r�mkdir�chmodr0r��stat�S_IMODE�st_mode�assertNotEqual�S_IWRITE�S_IREAD�S_IEXECrrkr[r�rr�Zstatinfo�moderrr�'test_dirs_created_are_changed_to_secure4s

�
z>TestLaunchpadLoginWith.test_dirs_created_are_changed_to_securecCsftj�|jd�}tjdt|d�|�tj�|��t�	|�}t	�
|j�}|�|t	j
t	jBt	jB�dS)Nryrgr�)ror�r�rrrkr[r0r�r�r�r�rr�r�r�r�rrr�test_dirs_created_are_secureEs�
z3TestLaunchpadLoginWith.test_dirs_created_are_securecCs\tj�|jd�}tjdt|dd�}|�|jdd�tjdt|dd�}|�|jdd�dS)Nryrg�foo)rOr�rPrPZbar)	ror�r�rrrkr[r�passed_in_args�rr�rsrrr�test_version_is_propagatedPs��z1TestLaunchpadLoginWith.test_version_is_propagatedcCsXtj�|jd�}tjdt|d�}|�|jj	j
d�tjdt|d�}|�|jj	j
d�dS)Nryzvery importantr�)ror�r�rrrkr[rrnrlr^r�rrr�#test_application_name_is_propagatedcs&����z:TestLaunchpadLoginWith.test_application_name_is_propagatedcCs6ttd�}tj|d�|�|jd�|�|jd�dS)N�application name��authorization_enginer+)rr[rrkrZrequest_tokens_obtainedZaccess_tokens_obtained�rZenginerrr�'test_authorization_engine_is_propagatedzs�z>TestLaunchpadLoginWith.test_authorization_engine_is_propagatedcCs|�ttj�dSr)rJrKrrkr&rrr�)test_login_with_must_identify_application�sz@TestLaunchpadLoginWith.test_login_with_must_identify_applicationcCstjdd�dSr]�rrkr&rrrr`�sz;TestLaunchpadLoginWith.test_application_name_identifies_appcCstjdd�dSrar�r&rrrrd�sz8TestLaunchpadLoginWith.test_consumer_name_identifies_appcCs"ttd�}|jttjd|d�dS)�;Catch an attempt to specify inconsistent application_names.zapplication name1zapplication name2r�N�rr[rJrKrrkr�rrr�+test_inconsistent_application_name_rejected�s�
�zBTestLaunchpadLoginWith.test_inconsistent_application_name_rejectedcCs&ttddd�}|jttjd|d�dS)r�NZconsumer_name1rbZconsumer_name2r�r�r�rrr�(test_inconsistent_consumer_name_rejected�s�
�z?TestLaunchpadLoginWith.test_inconsistent_consumer_name_rejectedcCs.ttddgd�}|jttjdddg|d�dS)z=Catch an attempt to specify inconsistent allow_access_levels.rl�FOO�rc�allow_access_levelsNZBAR)rcr�r�r�r�rrr�.test_inconsistent_allow_access_levels_rejected�s�
�zETestLaunchpadLoginWith.test_inconsistent_allow_access_levels_rejectedcCs4dd�}t|d�}dd�}|jttjd||d�dS)NcSsdSrrrrrr�	callback1�szRTestLaunchpadLoginWith.test_inconsistent_credential_save_failed.<locals>.callback1)�credential_save_failedcSsdSrrrrrr�	callback2�szRTestLaunchpadLoginWith.test_inconsistent_credential_save_failed.<locals>.callback2�app name)rur�)rrJrKrrk)rr�rvr�rrr�(test_inconsistent_credential_save_failed�s

�z?TestLaunchpadLoginWith.test_inconsistent_credential_save_failedcCsJtjddgd�}|�|jjjd�|�|jjjd�|�|jjdg�dS)Nrlr�r�)	rrkrrnrlrmr^r�r��rrsrrr�test_non_desktop_integration�s��
�z3TestLaunchpadLoginWith.test_non_desktop_integrationcCs&tjddgd�}|�|jjdg�dS)Nr�r�)r��DESKTOP_INTEGRATION)rrkrr�r�r�rrr�<test_desktop_integration_doesnt_happen_without_consumer_name�s�
�zSTestLaunchpadLoginWith.test_desktop_integration_doesnt_happen_without_consumer_namecCs�t�}t�}tjd|jt||d�}|�|jjjt	j
�|�|jjjd�|�|j
jdg�tttj�|jdd�||tjd�}|�|j|�dS)Nr�)r�rO�timeout�
proxy_infor�r�r�)rOr�r�r�rP)�objectrrkrr[rrn�access_tokenrmrZACCESS_TOKEN_KEYrlr^r�r��dictror�r�rUr�)rr�r�rs�expected_argumentsrrr�*test_no_credentials_creates_new_credential�s4���
��zATestLaunchpadLoginWith.test_no_credentials_creates_new_credentialcCs`tjd|jtd�}|�|jjjd�|�|jjjd�t	j
�|jddd�}|�t	j
�
|��dS)z)Test the anonymous login helper function.zanonymous access)r�rO�r�rnN)rZlogin_anonymouslyrr[rrnr�rm�secretror�r�r��exists)rrsr�rrr�test_anonymous_login�s��z+TestLaunchpadLoginWith.test_anonymous_loginc
Cs�t�tj�|jdd��tj�|jddd�}tddtdd�d�}|�|�t�}t�}d}t	j
d|jt|||d	�}tt|||tj�|jdd
�d�}|�
�D]\}}	|j|}
|�|
|	�q�dS)Nr�rnr�zconsumer_secret:42z
access_key:84zaccess_secret:168)Zconsumer_secretr�r�)r�rOr�r�rPr�)rOr�r�rPr�)ro�makedirsr�r�rrrZsave_to_pathr�rrkr[r�rr�r)rZcredentials_file_pathrnr�r�rPrsr�rmZexpectedZactualrrr�-test_existing_credentials_arguments_passed_on�sH���
��
zDTestLaunchpadLoginWith.test_existing_credentials_arguments_passed_onc	Cs�tj�d�}|jtjd<tjdtd�}|dk	r:|tjd<ntjd=|jd}tj�	tj�
|dd��}|�|tj�
|jd��|�tj�
tj�
|dd���dS)N�HOMEr�rRr�z..z
.launchpadlibr�)ro�environ�getrrrkr[r�r��abspathr�rr0r�)rZold_homersZ	cache_dirr�rrr�test_None_launchpadlib_dirs(�
��
�z1TestLaunchpadLoginWith.test_None_launchpadlib_dircCsbt�dd�}|�|jdd�t�dtjd�}|�|jdtjd�d}|�ttjdd�dS)Nr�r"rOz"https://api.staging.launchpad.net/)r�zhttps://r�)rrkrr�rr8rJrKr�rrr�test_short_service_name*s(����z.TestLaunchpadLoginWith.test_short_service_namecCstjddd�dS)Nrg�)Zmax_failed_attemptsr�r&rrr�!test_max_failed_attempts_accepted?s�z8TestLaunchpadLoginWith.test_max_failed_attempts_accepted)rrrrr'r{r�r�r�r�r�r�r�r`rdr�r�r�r�r�r�r�r�r�r�r�r��
__classcell__rrr�rr|s0
	

r|c@s eZdZdZdd�Zdd�ZdS)�TestDeprecatedLoginMethodsz2Make sure the deprecated login methods still work.c	Csbtjdd��L}t�d�t�dt�t�ddd�|�t|�d�|�|d	jt	�W5QRXdS)
NTr(r*rqrl�tokenr�r+r)
r,r-r.�PendingDeprecationWarningrZloginrr/r2r3�rr6rrr�test_login_is_deprecatedIs
z3TestDeprecatedLoginMethods.test_login_is_deprecatedc	Cs^tjdd��H}t�d�t�dt�t�d�|�t|�d�|�|djt	�W5QRXdS)NTr(r*rqrlr+r)
r,r-r.r�rZget_token_and_loginrr/r2r3r�rrr�&test_get_token_and_login_is_deprecatedRs

zATestDeprecatedLoginMethods.test_get_token_and_login_is_deprecatedN)rrrrr�r�rrrrr�Fs	r�c@sveZdZdd�Zdd�Ze�ededd���dd	��Z	e�eded
d���dd��Z
e�eded
d���dd��ZdS)�!TestCredenitialSaveFailedCallbackcCst�tj_t��|_dSr�rryrs�socketrir~rr&rrrr'`s
z'TestCredenitialSaveFailedCallback.setUpcCsttj_t�|j�dSr�r�ryrsr�r�rr&rrrr{gsz*TestCredenitialSaveFailedCallback.tearDown�_is_sudocCsdS�NFrrrrr�<lambda>k�z*TestCredenitialSaveFailedCallback.<lambda>c	s`g��fdd�}tj�|jd�}d}tt���(tjd|||d�|�t	��d�W5QRXdS)Ncs��d�dSr)�appendr�Zcallback_calledrr�callbackqszPTestCredenitialSaveFailedCallback.test_credentials_save_failed.<locals>.callbackryrrg)rOr�r�r+)
ror�r�rrr
rrkrr/)rr�r�rOrr�r�test_credentials_save_failedks�z>TestCredenitialSaveFailedCallback.test_credentials_save_failedcCsdSr�rrrrrr�r�c	CsDtj�|jd�}d}tt���|jttj	d||d�W5QRXdS�Nryrrgr�)
ror�r�rrr
rJ�RuntimeErrorrrk�rr�rOrrr�:test_default_credentials_save_failed_is_to_raise_exceptions�z\TestCredenitialSaveFailedCallback.test_default_credentials_save_failed_is_to_raise_exceptioncCsdS)NTrrrrrr��r�c	Cs>tj�|jd�}d}tt���tjd||d�W5QRXdSr�)ror�r�rrr
rrkr�rrr�>test_credentials_save_fail_under_sudo_does_not_raise_exception�s�z`TestCredenitialSaveFailedCallback.test_credentials_save_fail_under_sudo_does_not_raise_exceptionN)rrrr'r{rr�r�staticmethodr�r�r�rrrrr�\s

r�c@sXeZdZdd�Zdd�Ze�ededd���dd	��Z	e�eded
d���dd��Z
d
S)�TestMultipleSitescCst�tj_t��|_dSrr�r&rrrr'�s
zTestMultipleSites.setUpcCsttj_t�|j�dSrr�r&rrrr{�szTestMultipleSites.tearDownr�cCsdSr�rrrrrr��r�zTestMultipleSites.<lambda>c	Cs�tj�|jd�}t�}d}d}t|�� tj|||d�}|jj	j
}W5QRXt|j�
��dd}|�||�|�||�|�||d|�dS)NryrzSuper App 3000r�rr+�@)ror�r�rr
rrrkrnrlrm�list�datar9r4r)rr�rzrOr^rsrcZapplication_keyrrr�"test_components_of_application_key�s
�z4TestMultipleSites.test_components_of_application_keycCsdSr�rrrrrr��r�c	Cs�tj�|jd�}t�}|jr$td��t|��&tj	dd|d�tj	dd|d�W5QRXt
|j���dksnt�t|j���dd	}t|j���d	d	}|�
||�dS)
Nryz$oops, a fresh keyring has data in itr�zhttp://alpha.example.com/r�zhttp://beta.example.com/�rr+)ror�r�rr
r�rTrrrkr/r9r�r�)rr�rzZapplication_key_1Zapplication_key_2rrr�test_same_app_different_servers�s$
��z1TestMultipleSites.test_same_app_different_serversN)rrrr'r{rr�rr�r�r�rrrrr��s
r�cCst���t�Sr)�unittestZ
TestLoaderZloadTestsFromNamerrrrr�
test_suite�sr�)/r�typeZ
__metaclass__�
contextlibrror�r�r�rir�Z
unittest.mockr�ImportErrorZmockr,Zlazr.restfulclient.resourcerZlaunchpadlib.credentialsrrryrZlaunchpadlib.launchpadrZlaunchpadlib.testing.helpersr	r
rrr
rrrr[ZTestCaserr rNrYrfrxr|r�r�r�r�rrrr�<module>sD$	
^-5<B