~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
=============================================
Using the webservice with commercial archives
=============================================

(See also soyuz/stories/webservice/xx-archive.txt and
soyuz/doc/archive-commercial.txt)

Start by making a commercial PPA that we can fetch via the webservice:

    >>> login("admin@canonical.com")
    >>> ppa = factory.makeArchive(private=True, name="cpppa")
    >>> from zope.security.proxy import removeSecurityProxy
    >>> removeSecurityProxy(ppa).commercial = True
    >>> import transaction
    >>> transaction.commit()
    >>> logout()

Commercial archives can be found with a custom method 'getCommercialPPAs'
that lives on the distribution object.

Using webservice directly:

    >>> ubuntu = webservice.get("/ubuntu").jsonBody()
    >>> cppas = webservice.named_get(
    ...     ubuntu['self_link'], 'getCommercialPPAs').jsonBody()
    >>> for entry in cppas['entries']:
    ...     print entry['name']
    cpppa

== Software Center Agent ==

Create the P3A marked commercial, and fetch the celebrity.

    >>> from zope.component import getUtility
    >>> from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities
    >>> login('admin@canonical.com')
    >>> celebrity = getUtility(ILaunchpadCelebrities).software_center_agent
    >>> archive = factory.makeArchive(name='commercial', private=True)
    >>> archive.commercial = True
    >>> url = "/~%s/+archive/commercial" % archive.owner.name
    >>> person = factory.makePerson(name='joe')
    >>> logout()

And fetch our objects:

    >>> from canonical.launchpad.testing.pages import webservice_for_person
    >>> from canonical.launchpad.webapp.interfaces import OAuthPermission
    >>> agent = webservice.get('/~software-center-agent').jsonBody()
    >>> joe = webservice.get('/~joe').jsonBody()
    >>> cprov = webservice.get('/~cprov').jsonBody()
    >>> cp3a = webservice.get(url).jsonBody()
    >>> agent_webservice = webservice_for_person(
    ...   celebrity, permission=OAuthPermission.WRITE_PRIVATE)

Subscribe our test user to the commercial archive.

    >>> joe_webservice = webservice_for_person(
    ...   person, permission=OAuthPermission.WRITE_PRIVATE)
    >>> response = agent_webservice.named_post(cp3a['self_link'],
    ...   'newSubscription', subscriber=joe['self_link'])
    >>> print response
    HTTP/1.1 201 Created
    ...
    Location: http://api.launchpad.dev/beta/.../+subscriptions/joe
    ...

The agent can query the sources.list entry for an archive for any user, which
will include an AuthToken, and create it if needed:

    >>> response = agent_webservice.named_post(
    ...   joe['self_link'], 'getArchiveSubscriptionURL', {},
    ...   archive=cp3a['self_link'])
    >>> print response
    HTTP/1.1 200 Ok
    ...
    "http://joe:...@private-ppa.launchpad.dev/.../commercial/ubuntu"

The agent can also query all sources.list entries for any user:

    >>> response = agent_webservice.named_get(
    ...   joe['self_link'], 'getArchiveSubscriptionURLs')
    >>> print response
    HTTP/1.1 200 Ok
    ...
    ["http://joe:...@private-ppa.launchpad.dev/.../commercial/ubuntu"]

Joe can query his own entry:

    >>> response = joe_webservice.named_post(
    ...   joe['self_link'], 'getArchiveSubscriptionURL', {},
    ...   archive=cp3a['self_link'])
    >>> print response
    HTTP/1.1 200 Ok
    ...
    "http://joe:...@private-ppa.launchpad.dev/.../commercial/ubuntu"

But Joe can not query the entry of cprov:

    >>> response = joe_webservice.named_post(
    ...   cprov['self_link'], 'getArchiveSubscriptionURL', {},
    ...   archive=cp3a['self_link'])
    >>> print response
    HTTP/1.1 401 Unauthorized
    ...