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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Test PackageLocation class."""
from zope.component import getUtility
from canonical.testing.layers import LaunchpadZopelessLayer
from lp.soyuz.adapters.packagelocation import (
build_package_location,
PackageLocationError,
)
from lp.soyuz.enums import ArchivePurpose
from lp.soyuz.interfaces.component import IComponentSet
from lp.testing import TestCaseWithFactory
from lp.testing.factory import remove_security_proxy_and_shout_at_engineer
class TestPackageLocation(TestCaseWithFactory):
"""Test the `PackageLocation` class."""
layer = LaunchpadZopelessLayer
def getPackageLocation(self, distribution_name='ubuntu', suite=None,
purpose=None, person_name=None,
archive_name=None, packageset_names=None):
"""Use a helper method to setup a `PackageLocation` object."""
return build_package_location(
distribution_name, suite, purpose, person_name, archive_name,
packageset_names=packageset_names)
def testSetupLocationForCOPY(self):
"""`PackageLocation` for COPY archives."""
# First create a copy archive for the default Ubuntu primary
ubuntu = self.getPackageLocation().distribution
returned_location = self.factory.makeCopyArchiveLocation(
distribution=ubuntu, name='now-comes-the-mystery',
owner=self.factory.makePerson(name='mysteryman'))
copy_archive = remove_security_proxy_and_shout_at_engineer(
returned_location).archive
# Now use the created copy archive to test the build_package_location
# helper (called via getPackageLocation):
location = self.getPackageLocation(purpose=ArchivePurpose.COPY,
archive_name=copy_archive.name)
self.assertEqual(location.distribution.name, 'ubuntu')
self.assertEqual(location.distroseries.name, 'hoary')
self.assertEqual(location.pocket.name, 'RELEASE')
self.assertEqual(location.archive.displayname,
'Copy archive now-comes-the-mystery for Mysteryman')
self.assertEqual([], location.packagesets)
def testSetupLocationForPRIMARY(self):
"""`PackageLocation` for PRIMARY archives."""
location = self.getPackageLocation()
self.assertEqual(location.distribution.name, 'ubuntu')
self.assertEqual(location.distroseries.name, 'hoary')
self.assertEqual(location.pocket.name, 'RELEASE')
self.assertEqual(location.archive.displayname,
'Primary Archive for Ubuntu Linux')
self.assertEqual([], location.packagesets)
def testSetupLocationForPPA(self):
"""`PackageLocation` for PPA archives."""
location = self.getPackageLocation(purpose=ArchivePurpose.PPA,
person_name='cprov',
archive_name="ppa")
self.assertEqual(location.distribution.name, 'ubuntu')
self.assertEqual(location.distroseries.name, 'hoary')
self.assertEqual(location.pocket.name, 'RELEASE')
self.assertEqual(location.archive.displayname,
'PPA for Celso Providelo')
self.assertEqual([], location.packagesets)
def testSetupLocationForPARTNER(self):
"""`PackageLocation` for PARTNER archives."""
location = self.getPackageLocation(purpose=ArchivePurpose.PARTNER)
self.assertEqual(location.distribution.name, 'ubuntu')
self.assertEqual(location.distroseries.name, 'hoary')
self.assertEqual(location.pocket.name, 'RELEASE')
self.assertEqual(location.archive.displayname,
'Partner Archive for Ubuntu Linux')
self.assertEqual([], location.packagesets)
def testSetupLocationWithPackagesets(self):
packageset_name1 = u"foo-packageset"
packageset_name2 = u"bar-packageset"
packageset1 = self.factory.makePackageset(name=packageset_name1)
packageset2 = self.factory.makePackageset(name=packageset_name2)
location = self.getPackageLocation(
packageset_names=[packageset_name1, packageset_name2])
self.assertEqual([packageset1, packageset2], location.packagesets)
def testSetupLocationUnknownDistribution(self):
"""`PackageLocationError` is raised on unknown distribution."""
self.assertRaises(
PackageLocationError,
self.getPackageLocation,
distribution_name='beeblebrox')
def testSetupLocationUnknownSuite(self):
"""`PackageLocationError` is raised on unknown suite."""
self.assertRaises(
PackageLocationError,
self.getPackageLocation,
suite='beeblebrox')
def testSetupLocationUnknownPerson(self):
"""`PackageLocationError` is raised on unknown person."""
self.assertRaises(
PackageLocationError,
self.getPackageLocation,
purpose=ArchivePurpose.PPA,
person_name='beeblebrox',
archive_name="ppa")
def testSetupLocationUnknownPPA(self):
"""`PackageLocationError` is raised on unknown PPA."""
self.assertRaises(
PackageLocationError,
self.getPackageLocation,
purpose=ArchivePurpose.PPA,
person_name='kiko',
archive_name="ppa")
def test_build_package_location_when_partner_missing(self):
"""`PackageLocationError` is raised when PARTNER does not exist."""
self.assertRaises(
PackageLocationError,
self.getPackageLocation,
distribution_name='debian',
purpose=ArchivePurpose.PARTNER)
def test_build_package_location_when_packageset_unknown(self):
"""`PackageLocationError` is raised on unknown packageset."""
self.assertRaises(
PackageLocationError,
self.getPackageLocation,
distribution_name='debian',
packageset_names=[u"unknown"])
def test_build_package_location_when_one_packageset_unknown(self):
"""Test that with one of two packagesets unknown."""
packageset_name = u"foo-packageset"
self.factory.makePackageset(name=packageset_name)
self.assertRaises(
PackageLocationError,
self.getPackageLocation,
distribution_name='debian',
packageset_names=[packageset_name, u"unknown"])
def testSetupLocationPPANotMatchingDistribution(self):
"""`PackageLocationError` is raised when PPA does not match the
distribution."""
self.assertRaises(
PackageLocationError,
self.getPackageLocation,
distribution_name='ubuntutest',
purpose=ArchivePurpose.PPA,
person_name='cprov',
archive_name="ppa")
def testComparison(self):
"""Check if PackageLocation objects can be compared."""
location_ubuntu_hoary = self.getPackageLocation()
location_ubuntu_hoary_again = self.getPackageLocation()
self.assertEqual(location_ubuntu_hoary, location_ubuntu_hoary_again)
self.assertTrue(location_ubuntu_hoary.component is None)
self.assertTrue(location_ubuntu_hoary_again.component is None)
universe = getUtility(IComponentSet)['universe']
restricted = getUtility(IComponentSet)['restricted']
location_ubuntu_hoary.component = universe
self.assertNotEqual(
location_ubuntu_hoary, location_ubuntu_hoary_again)
location_ubuntu_hoary_again.component = universe
self.assertEqual(location_ubuntu_hoary, location_ubuntu_hoary_again)
location_ubuntu_hoary.component = restricted
self.assertNotEqual(
location_ubuntu_hoary, location_ubuntu_hoary_again)
location_ubuntu_warty_security = self.getPackageLocation(
suite='warty-security')
self.assertNotEqual(location_ubuntu_hoary,
location_ubuntu_warty_security)
location_ubuntutest = self.getPackageLocation(
distribution_name='ubuntutest')
self.assertNotEqual(location_ubuntu_hoary, location_ubuntutest)
location_cprov_ppa = self.getPackageLocation(
distribution_name='ubuntu', purpose=ArchivePurpose.PPA,
person_name='cprov', archive_name="ppa")
self.assertNotEqual(location_cprov_ppa, location_ubuntutest)
location_ubuntu_partner = self.getPackageLocation(
distribution_name='ubuntu', purpose=ArchivePurpose.PARTNER)
self.assertNotEqual(location_ubuntu_partner, location_cprov_ppa)
def testComparePackagesets(self):
location_ubuntu_hoary = self.getPackageLocation()
location_ubuntu_hoary_again = self.getPackageLocation()
packageset = self.factory.makePackageset()
location_ubuntu_hoary.packagesets = [packageset]
self.assertNotEqual(
location_ubuntu_hoary, location_ubuntu_hoary_again)
location_ubuntu_hoary_again.packagesets = [packageset]
self.assertEqual(
location_ubuntu_hoary, location_ubuntu_hoary_again)
def testRepresentation(self):
"""Check if PackageLocation is represented correctly."""
location_ubuntu_hoary = self.getPackageLocation()
self.assertEqual(str(location_ubuntu_hoary),
'Primary Archive for Ubuntu Linux: hoary-RELEASE')
universe = getUtility(IComponentSet)['universe']
location_ubuntu_hoary.component = universe
self.assertEqual(
str(location_ubuntu_hoary),
'Primary Archive for Ubuntu Linux: hoary-RELEASE (universe)')
location_ubuntu_warty_security = self.getPackageLocation(
suite='warty-security')
self.assertEqual(str(location_ubuntu_warty_security),
'Primary Archive for Ubuntu Linux: warty-SECURITY')
location_ubuntutest = self.getPackageLocation(
distribution_name='ubuntutest')
self.assertEqual(
str(location_ubuntutest),
'Primary Archive for Ubuntu Test: hoary-test-RELEASE')
location_cprov_ppa = self.getPackageLocation(
distribution_name='ubuntu', purpose=ArchivePurpose.PPA,
person_name='cprov', archive_name="ppa")
self.assertEqual(
str(location_cprov_ppa),
'cprov: hoary-RELEASE')
location_ubuntu_partner = self.getPackageLocation(
distribution_name='ubuntu', purpose=ArchivePurpose.PARTNER)
self.assertEqual(
str(location_ubuntu_partner),
'Partner Archive for Ubuntu Linux: hoary-RELEASE')
self.factory.makePackageset(name=u"foo-packageset")
location_ubuntu_packageset = self.getPackageLocation(
packageset_names=[u"foo-packageset"])
self.assertEqual(
str(location_ubuntu_packageset),
'Primary Archive for Ubuntu Linux: '
'hoary-RELEASE [foo-packageset]')
|