/usr/lib/python3/dist-packages/launchpadlib/testing/__pycache__
Edit: /usr/lib/python3/dist-packages/launchpadlib/testing/__pycache__/launchpad.cpython-310.pyc (20192B)
o
x۔aUX @ s d Z ddlmZ zddlmZ W n ey ddlmZ Y nw ddlZejd dkr-eZ dZ
G dd deZG d d
d
e
Zdd Zd
d ZG dd de
ZG dd deZG dd deZG dd deZdS )a Testing API allows fake data to be used in unit tests.
Testing launchpadlib code is tricky, because it depends so heavily on a
remote, unique webservice: Launchpad. This module helps you write tests for
your launchpadlib application that can be run locally and quickly.
Say you were writing some code that needed to call out to Launchpad and get
the branches owned by the logged-in person, and then do something to them. For
example, something like this::
def collect_unique_names(lp):
names = []
for branch in lp.me.getBranches():
names.append(branch.unique_name)
return names
To test it, you would first prepare a L{FakeLaunchpad} object, and give it
some sample data of your own devising::
lp = FakeLaunchpad()
my_branches = [dict(unique_name='~foo/bar/baz')]
lp.me = dict(getBranches: lambda status: my_branches)
Then, in the test, call your own code and assert that it behaves correctly
given the data.
names = collect_unique_names(lp)
self.assertEqual(['~foo/bar/baz'], names)
And that's it.
The L{FakeLaunchpad} code uses a WADL file to type-check any objects created
or returned. This means you can be sure that you won't accidentally store
sample data with misspelled attribute names.
The WADL file that we use by default is for version 1.0 of the Launchpad API.
If you want to work against a more recent version of the API, download the
WADL yourself (see
) and construct
your C{FakeLaunchpad} like this::
from wadllib.application import Application
lp = FakeLaunchpad(
Application('https://api.launchpad.net/devel/',
'/path/to/wadl.xml'))
Where 'https://api.launchpad.net/devel/' is the URL for the WADL file, found
also in the WADL file itelf.
)datetime)CallableN zapplication/jsonc @ e Zd ZdZdS )IntegrityErrorzERaised when bad sample data is used with a L{FakeLaunchpad} instance.N__name__
__module____qualname____doc__ r r @/usr/lib/python3/dist-packages/launchpadlib/testing/launchpad.pyr R r c @ sx e Zd ZdZ dddZdd Zdd Ze dd d
Ze dddZ e dd
dZ
dS )
FakeLaunchpadzA fake Launchpad API class for unit tests that depend on L{Launchpad}.
@param application: A C{wadllib.application.Application} instance for a
Launchpad WADL definition file.
Nc C s: |d u r
ddl m} | }t|}| j|||d d S )Nr get_application)credentials_application
_service_root)launchpadlib.testing.resourcesr FakeRoot__dict__update) selfr service_rootcachetimeout
proxy_infoapplicationr
root_resourcer r r
__init__] s zFakeLaunchpad.__init__c C s | j }t||| dS )zSet sample data.
@param name: The name of the attribute.
@param values: A dict representing an object matching a resource
defined in Launchpad's WADL definition.
N)r setattr)r namevaluesr r r r
__setattr__s s zFakeLaunchpad.__setattr__c C s t | j|S )JGet sample data.
@param name: The name of the attribute.
)getattrr )r r" r r r
__getattr__} s zFakeLaunchpad.__getattr__c C s ddl m} | t | dS )z.Convenience for setting up access credentials.r r r r r object) cls
consumer_nametoken_string
access_secretr r r r r r r r
login s zFakeLaunchpad.loginc C ddl m} | t | dS )z=Get credentials from Launchpad and log into the service root.r r r( r) )r+ r, r r r r r r r r
get_token_and_login
z!FakeLaunchpad.get_token_and_loginc C r0 )z5Log in to Launchpad with possibly cached credentials.r r r( r) )r+ r, r launchpadlib_dirr r r r r r
login_with r2 zFakeLaunchpad.login_with)NNNNNN)NNNN)r r r
r r r$ r' classmethodr/ r1 r4 r r r r
r V s:
r c s fdd| D S )z@Find children of element where attribute name is equal to value.c s g | ]}| kr|qS r get.0childr" valuer r