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
|
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Test the SoyuzScript base class.
We check that the base source and binary lookup methods are working
properly.
"""
import unittest
from zope.component import getUtility
from lp.registry.interfaces.person import IPersonSet
from lp.services.log.logger import BufferLogger
from lp.soyuz.scripts.ftpmasterbase import (
SoyuzScript,
SoyuzScriptError,
)
from lp.testing.layers import LaunchpadZopelessLayer
class TestSoyuzScript(unittest.TestCase):
"""Test the SoyuzScript class."""
layer = LaunchpadZopelessLayer
def getSoyuz(self, version=None, component=None, arch=None,
suite=None, distribution_name='ubuntu',
ppa=None, partner=False, ppa_name='ppa'):
"""Return a SoyuzScript instance.
Allow tests to use a set of default options and pass an
inactive logger to SoyuzScript.
"""
test_args = ['-d', distribution_name, '-y']
if suite is not None:
test_args.extend(['-s', suite])
if version is not None:
test_args.extend(['-e', version])
if arch is not None:
test_args.extend(['-a', arch])
if component is not None:
test_args.extend(['-c', component])
if ppa is not None:
test_args.extend(['-p', ppa])
test_args.extend(['--ppa-name', ppa_name])
if partner:
test_args.append('-j')
soyuz = SoyuzScript(name='soyuz-script', test_args=test_args)
# Store output messages, for future checks.
soyuz.logger = BufferLogger()
soyuz.setupLocation()
return soyuz
def testFindLatestPublishedSourceInPRIMARY(self):
"""Source lookup in PRIMARY archive."""
soyuz = self.getSoyuz()
src = soyuz.findLatestPublishedSource('pmount')
self.assertEqual(src.displayname, 'pmount 0.1-2 in hoary')
self.assertRaises(
SoyuzScriptError, soyuz.findLatestPublishedSource, 'marvin')
soyuz = self.getSoyuz(suite='hoary-security')
self.assertRaises(
SoyuzScriptError, soyuz.findLatestPublishedSource, 'pmount')
def testFindLatestPublishedSourceInPARTNER(self):
"""Source lookup in PARTNER archive."""
soyuz = self.getSoyuz(suite='breezy-autotest', partner=True)
src = soyuz.findLatestPublishedSource('commercialpackage')
self.assertEqual(
src.displayname, 'commercialpackage 1.0-1 in breezy-autotest')
self.assertRaises(
SoyuzScriptError, soyuz.findLatestPublishedSource, 'marvin')
soyuz = self.getSoyuz(suite='warty', partner=True)
self.assertRaises(
SoyuzScriptError, soyuz.findLatestPublishedSource,
'commercialpackage')
def testFindLatestPublishedSourceInPPA(self):
"""Source lookup in PPAs."""
soyuz = self.getSoyuz(ppa='cprov', suite='warty')
src = soyuz.findLatestPublishedSource('pmount')
self.assertEqual(src.displayname, 'pmount 0.1-1 in warty')
self.assertRaises(
SoyuzScriptError, soyuz.findLatestPublishedSource, 'marvin')
soyuz = self.getSoyuz(ppa='cprov', suite='warty-security')
self.assertRaises(
SoyuzScriptError, soyuz.findLatestPublishedSource, 'pmount')
# Bug 159151 occurred because we were printing unicode characters
# to an ascii codec in the exception, which originated in the PPA
# owner's name. Let's munge cprov's name to be unicode and ensure
# we still get the right exception raised (a UnicodeError is raised
# if the bug is present).
cprov = getUtility(IPersonSet).getByName('cprov')
cprov.displayname = u'\xe7\xe3o'
self.assertRaises(
SoyuzScriptError, soyuz.findLatestPublishedSource, 'pmount')
def testFindLatestPublishedSourceAndCheckComponent(self):
"""Before returning the source publication component is checked.
Despite of existing the found publication should match the given
component (if given) otherwise an error is raised.
"""
soyuz = self.getSoyuz(suite='hoary', component='main')
src = soyuz.findLatestPublishedSource('pmount')
self.assertEqual(src.displayname, 'pmount 0.1-2 in hoary')
soyuz = self.getSoyuz(component='multiverse')
self.assertRaises(
SoyuzScriptError, soyuz.findLatestPublishedSource, 'pmount')
def testFindLatestPublishedSourceWithSpecificVersion(self):
"""Source lookups for specific version."""
soyuz = self.getSoyuz(version='0.1-2')
src = soyuz.findLatestPublishedSource('pmount')
self.assertEqual(src.displayname, 'pmount 0.1-2 in hoary')
soyuz = self.getSoyuz(version='666')
self.assertRaises(
SoyuzScriptError, soyuz.findLatestPublishedSource, 'pmount')
def testFindLatestPublishedBinariesInPRIMARY(self):
"""Binary lookups in PRIMARY archive."""
soyuz = self.getSoyuz()
binaries = soyuz.findLatestPublishedBinaries('pmount')
self.assertEqual(
[b.displayname for b in binaries],
['pmount 2:1.9-1 in hoary hppa', 'pmount 0.1-1 in hoary i386'])
self.assertRaises(
SoyuzScriptError, soyuz.findLatestPublishedBinaries, 'marvin')
soyuz = self.getSoyuz(suite='warty-security')
self.assertRaises(
SoyuzScriptError, soyuz.findLatestPublishedBinaries, 'pmount')
def testFindLatestPublishedBinariesInPARTNER(self):
"""Binary lookups in PARTNER archive."""
soyuz = self.getSoyuz(suite='breezy-autotest', partner=True)
binaries = soyuz.findLatestPublishedBinaries('commercialpackage')
self.assertEqual(
[b.displayname for b in binaries],
['commercialpackage 1.0-1 in breezy-autotest i386'])
self.assertRaises(
SoyuzScriptError, soyuz.findLatestPublishedBinaries, 'marvin')
soyuz = self.getSoyuz(suite='warty-security')
self.assertRaises(
SoyuzScriptError, soyuz.findLatestPublishedBinaries,
'commercialpackage')
def testFindLatestPublishedBinariesInPPA(self):
"""Binary lookups in PPAs."""
soyuz = self.getSoyuz(ppa='cprov', suite='warty')
binaries = soyuz.findLatestPublishedBinaries('pmount')
self.assertEqual(
[b.displayname for b in binaries],
['pmount 0.1-1 in warty hppa', 'pmount 0.1-1 in warty i386'])
self.assertRaises(
SoyuzScriptError, soyuz.findLatestPublishedBinaries, 'marvin')
soyuz = self.getSoyuz(ppa='cprov', suite='warty-security')
self.assertRaises(
SoyuzScriptError, soyuz.findLatestPublishedBinaries, 'pmount')
def testFindLatestPublishedBinariesCheckComponent(self):
"""Each suitable binary publication component is checked.
For each one of them not matching the given component a warning
message is issued. If none of them match the given component (no
suitable binary found) an errors is raised.
"""
soyuz = self.getSoyuz(component='main')
binaries = soyuz.findLatestPublishedBinaries('pmount')
self.assertEqual(
[b.displayname for b in binaries],
['pmount 2:1.9-1 in hoary hppa'])
self.assertEqual(
soyuz.logger.getLogBuffer(),
'WARNING pmount 0.1-1 in hoary i386 was skipped '
'because it is not in MAIN component\n')
soyuz = self.getSoyuz(component='multiverse')
self.assertRaises(
SoyuzScriptError, soyuz.findLatestPublishedBinaries, 'pmount')
def testFindLatestPublishedBinariesWithSpecificVersion(self):
"""Binary lookups for specific version."""
soyuz = self.getSoyuz(version='0.1-1')
binaries = soyuz.findLatestPublishedBinaries('pmount')
self.assertEqual(
[b.displayname for b in binaries],
['pmount 0.1-1 in hoary i386'])
soyuz = self.getSoyuz(version='2:1.9-1')
binaries = soyuz.findLatestPublishedBinaries('pmount')
self.assertEqual(
[b.displayname for b in binaries],
['pmount 2:1.9-1 in hoary hppa'])
soyuz = self.getSoyuz(version='666')
self.assertRaises(
SoyuzScriptError, soyuz.findLatestPublishedBinaries, 'pmount')
def testFinishProcedure(self):
"""Make sure finishProcedure returns the correct boolean."""
soyuz = self.getSoyuz()
soyuz.txn = LaunchpadZopelessLayer.txn
soyuz.options.confirm_all = True
self.assertTrue(soyuz.finishProcedure())
# XXX Julian 2007-11-29 bug=172869:
# Setting confirm_all to False is pretty untestable because it
# asks the user for confirmation via raw_input.
soyuz.options.dryrun = True
self.assertFalse(soyuz.finishProcedure())
|