~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
106
= Archive dependencies =

`ArchiveDependency` records represent build-dependencies between
archives, and are exposed through the API.

Most of the tests live in
lib/lp/soyuz/stories/webservice/xx-archive.txt.

Firstly we need to set some things up: we need a PPA with a dependency.
We'll use Celso's PPA, and give it a custom dependency on the primary
archive, and then create a private PPA for Celso with a similar custom
dependency.

    >>> import simplejson
    >>> from zope.component import getUtility
    >>> from lp.registry.interfaces.person import IPersonSet
    >>> from lp.registry.interfaces.pocket import PackagePublishingPocket
    >>> from lp.soyuz.interfaces.component import IComponentSet
    >>> login('foo.bar@canonical.com')
    >>> cprov_db = getUtility(IPersonSet).getByName('cprov')
    >>> cprov_ppa_db = cprov_db.archive
    >>> dep = cprov_ppa_db.addArchiveDependency(
    ...     cprov_ppa_db.distribution.main_archive,
    ...     PackagePublishingPocket.RELEASE,
    ...     component=getUtility(IComponentSet)['universe'])
    >>> cprov_private_ppa_db = factory.makeArchive(
    ...     private=True, owner=cprov_db, name="p3a",
    ...     distribution=cprov_ppa_db.distribution,
    ...     description="packages to help my friends.")
    >>> dep = cprov_private_ppa_db.addArchiveDependency(
    ...     cprov_ppa_db.distribution.main_archive,
    ...     PackagePublishingPocket.RELEASE,
    ...     component=getUtility(IComponentSet)['universe'])
    >>> logout()

Any user can retrieve a public PPA's dependencies.

    >>> print user_webservice.get(
    ...     '/~cprov/+archive/ppa/dependencies')
    HTTP/1.1 200 Ok
    ...

    >>> print user_webservice.get(
    ...     '/~cprov/+archive/ppa/+dependency/1')
    HTTP/1.1 200 Ok
    ...

The dependencies of a private archive are private.  Unprivileged users
can't get a list of the dependencies.

    >>> print user_webservice.get(
    ...     '/~cprov/+archive/p3a/dependencies')
    HTTP/1.1 401 Unauthorized
    ...
    (<Archive at ...>, 'dependencies', 'launchpad.View')

Nor can said user craft a URL to a dependency.

    >>> print user_webservice.get(
    ...     '/~cprov/+archive/p3a/+dependency/1')
    HTTP/1.1 401 Unauthorized
    ...
    (<Archive at ...>, 'getArchiveDependency', 'launchpad.View')

Celso can see them if we grant private permissions, of course.

    >>> from canonical.launchpad.testing.pages import webservice_for_person
    >>> from canonical.launchpad.webapp.interfaces import OAuthPermission
    >>> cprov_webservice = webservice_for_person(
    ...     cprov_db, permission=OAuthPermission.WRITE_PRIVATE)
    >>> print cprov_webservice.get(
    ...     '/~cprov/+archive/p3a/dependencies')
    HTTP/1.1 200 Ok
    ...
    >>> print cprov_webservice.get(
    ...     '/~cprov/+archive/p3a/+dependency/1')
    HTTP/1.1 200 Ok
    ...

But even he can't write to a dependency.

    >>> mark_ppa = cprov_webservice.get(
    ...     '/~mark/+archive/ppa').jsonBody()
    >>> print cprov_webservice.patch(
    ...     '/~cprov/+archive/ppa/+dependency/1', 'application/json',
    ...     simplejson.dumps({'archive_link': mark_ppa['self_link']}))
    HTTP/1.1 400 Bad Request
    ...
    archive_link: You tried to modify a read-only attribute.
    <BLANKLINE>

    >>> print cprov_webservice.patch(
    ...     '/~cprov/+archive/ppa/+dependency/1', 'application/json',
    ...     simplejson.dumps({'dependency_link': mark_ppa['self_link']}))
    HTTP/1.1 400 Bad Request
    ...
    dependency_link: You tried to modify a read-only attribute.
    <BLANKLINE>

    >>> print cprov_webservice.patch(
    ...     '/~cprov/+archive/ppa/+dependency/1', 'application/json',
    ...     simplejson.dumps({'pocket': 'Security'}))
    HTTP/1.1 400 Bad Request
    ...
    pocket: You tried to modify a read-only attribute.
    <BLANKLINE>