| Server IP : 61.19.30.66 / Your IP : 216.73.216.15 Web Server : Apache/2.2.22 (Ubuntu) System : Linux klw 3.11.0-15-generic #25~precise1-Ubuntu SMP Thu Jan 30 17:39:31 UTC 2014 x86_64 User : www-data ( 33) PHP Version : 5.3.10-1ubuntu3.48 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /usr/lib/python2.7/dist-packages/launchpadlib/testing/ |
Upload File : |
ó
µÌØNc @ s¶ d Z d d l m Z d Z d e f d „ ƒ YZ d e f d „ ƒ YZ d „ Z d „ Z d
e f d „ ƒ YZ d e f d
„ ƒ YZ
d e f d „ ƒ YZ d e f d „ ƒ YZ d S( sò 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 <https://help.launchpad.net/API/Hacking>) 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.
iÿÿÿÿ( t datetimes application/jsont IntegrityErrorc B s e Z d Z RS( sE Raised when bad sample data is used with a L{FakeLaunchpad} instance.( t __name__t
__module__t __doc__( ( ( sB /usr/lib/python2.7/dist-packages/launchpadlib/testing/launchpad.pyR J s t
FakeLaunchpadc B sŒ e Z d Z d d d d d d d „ Z d „ Z d „ Z e d d d d d „ ƒ Z e d d d d d „ ƒ Z e d d d d d „ ƒ Z
RS( sÀ A 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.
c C s] | d k r( d d l m } | ƒ } n t | ƒ } | j j i | d 6| d 6| d 6ƒ d S( Niÿÿÿÿ( t get_applicationt credentialst _applicationt
_service_root( t Nonet launchpadlib.testing.resourcesR t FakeRoott __dict__t update( t selfR t service_roott cachet timeoutt
proxy_infot applicationR t
root_resource( ( sB /usr/lib/python2.7/dist-packages/launchpadlib/testing/launchpad.pyt __init__U s c C s | j } t | | | ƒ d S( sÇ Set 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 t setattr( R t namet valuesR ( ( sB /usr/lib/python2.7/dist-packages/launchpadlib/testing/launchpad.pyt __setattr___ s c C s t | j | ƒ S( sJ Get sample data.
@param name: The name of the attribute.
( t getattrR ( R R ( ( sB /usr/lib/python2.7/dist-packages/launchpadlib/testing/launchpad.pyt __getattr__i s c C s&