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
107
108
109
110
111
112
113
|
Source Package API
==================
Prelude
-------
>>> login(ANONYMOUS)
>>> a_distro = factory.makeDistribution(name='my-distro')
>>> a_series = factory.makeDistroSeries(
... name='my-series', distribution=a_distro)
>>> evolution_package = factory.makeSourcePackage(
... sourcepackagename='evolution', distroseries=a_series)
>>> logout()
Getting source packages
-----------------------
We can get source packages that are bound to a distribution series from the
distribution series.
>>> my_series = webservice.get('/my-distro/my-series').jsonBody()
>>> evolution = webservice.named_get(
... my_series['self_link'], 'getSourcePackage',
... name='evolution').jsonBody()
>>> from lazr.restful.testing.webservice import pprint_entry
>>> pprint_entry(evolution)
bug_reported_acknowledgement: None
bug_reporting_guidelines: None
displayname: u'evolution in My-distro My-series'
distribution_link: u'http://.../my-distro'
distroseries_link: u'http://.../my-distro/my-series'
latest_published_component_name: None
name: u'evolution'
official_bug_tags: []
productseries_link: None
resource_type_link: ...
self_link: u'http://api.../my-distro/my-series/+source/evolution'
web_link: u'http://.../+source/evolution'
Getting official branches
-------------------------
Then we can get the branches that are bound to various pockets of this
distribution series. By default, there are none bound to evolution.
>>> branch = webservice.named_get(
... evolution['self_link'], 'getBranch', pocket='Release').jsonBody()
>>> print branch
None
Setting official branches
-------------------------
We can even set a branch for the series. First we need to *make* a branch
though.
>>> login(ANONYMOUS)
>>> owner = factory.makePerson(name='devo')
>>> branch = factory.makePackageBranch(
... sourcepackage=evolution_package, owner=owner, name='branch')
>>> print branch.unique_name
~devo/my-distro/my-series/evolution/branch
>>> branch_url = '/' + branch.unique_name
>>> logout()
Then we set the branch on the evolution package:
>>> from canonical.launchpad.testing.pages import webservice_for_person
>>> from canonical.launchpad.webapp.interfaces import OAuthPermission
>>> webservice = webservice_for_person(
... evolution_package.distribution.owner,
... permission=OAuthPermission.WRITE_PRIVATE)
>>> branch = webservice.get(branch_url).jsonBody()
>>> response = webservice.named_post(
... evolution['self_link'], 'setBranch', pocket='Release',
... branch=branch['self_link'])
>>> print response.jsonBody()
None
I guess this means that if we get the branch for the RELEASE pocket again,
we'll get the new branch.
>>> branch = webservice.named_get(evolution['self_link'], 'getBranch',
... pocket='Release').jsonBody()
>>> print branch['unique_name']
~devo/my-distro/my-series/evolution/branch
>>> linked_branches = webservice.named_get(
... evolution['self_link'], 'linkedBranches').jsonBody()
>>> print linked_branches.keys()
[u'RELEASE']
>>> branch = linked_branches[u'RELEASE']
>>> print branch['unique_name']
~devo/my-distro/.../branch
Of course, we're also allowed to change our minds. If we set the branch for
the RELEASE pocket to 'null' (i.e. the JSON for Python' None), then there is
no longer an official branch for that pocket.
>>> response = webservice.named_post(
... evolution['self_link'], 'setBranch', pocket='Release',
... branch='null')
>>> print response.jsonBody()
None
>>> branch = webservice.named_get(evolution['self_link'], 'getBranch',
... pocket='Release').jsonBody()
>>> print branch
None
|