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
|
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""
Run the doctests and pagetests.
"""
import logging
import os
import unittest
from canonical.config import config
from canonical.database.sqlbase import commit
from canonical.launchpad.ftests import logout
from canonical.launchpad.testing.pages import PageTestSuite
from canonical.launchpad.testing.systemdocs import (
LayeredDocFileSuite,
setGlobs,
setUp,
tearDown,
)
from canonical.testing.layers import (
LaunchpadFunctionalLayer,
LaunchpadZopelessLayer,
)
here = os.path.dirname(os.path.realpath(__file__))
def lobotomize_stevea():
"""Set SteveA's email address' status to NEW.
Call this method first in a test's setUp where needed. Tests
using this function should be refactored to use the unaltered
sample data and this function eventually removed.
In the past, SteveA's account erroneously appeared in the old
ValidPersonOrTeamCache materialized view. This materialized view
has since been replaced and now SteveA is correctly listed as
invalid in the sampledata. This fix broke some tests testing
code that did not use the ValidPersonOrTeamCache to determine
validity.
"""
from lp.services.identity.model.emailaddress import EmailAddress
from lp.services.identity.interfaces.emailaddress import EmailAddressStatus
stevea_emailaddress = EmailAddress.byEmail(
'steve.alexander@ubuntulinux.com')
stevea_emailaddress.status = EmailAddressStatus.NEW
commit()
def uploaderSetUp(test):
"""setup the package uploader script tests."""
setUp(test)
LaunchpadZopelessLayer.switchDbUser('uploader')
def builddmasterSetUp(test):
"""Setup the connection for the build master tests."""
test_dbuser = config.builddmaster.dbuser
test.globs['test_dbuser'] = test_dbuser
LaunchpadZopelessLayer.switchDbUser(test_dbuser)
setGlobs(test)
def statisticianSetUp(test):
test_dbuser = config.statistician.dbuser
test.globs['test_dbuser'] = test_dbuser
LaunchpadZopelessLayer.switchDbUser(test_dbuser)
setUp(test)
def statisticianTearDown(test):
tearDown(test)
def distroseriesqueueSetUp(test):
setUp(test)
# The test requires that the umask be set to 022, and in fact this comment
# was made in irc on 13-Apr-2007:
#
# (04:29:18 PM) kiko: barry, cprov says that the local umask is controlled
# enough for us to rely on it
#
# Setting it here reproduces the environment that the doctest expects.
# Save the old umask so we can reset it in the tearDown().
test.old_umask = os.umask(022)
def distroseriesqueueTearDown(test):
os.umask(test.old_umask)
tearDown(test)
def uploadQueueSetUp(test):
lobotomize_stevea()
test_dbuser = config.uploadqueue.dbuser
LaunchpadZopelessLayer.switchDbUser(test_dbuser)
setUp(test)
test.globs['test_dbuser'] = test_dbuser
def uploaderBugsSetUp(test):
"""Set up a test suite using the 'uploader' db user.
Some aspects of the bug tracker are being used by the Soyuz uploader.
In order to test that these functions work as expected from the uploader,
we run them using the same db user used by the uploader.
"""
lobotomize_stevea()
test_dbuser = config.uploader.dbuser
LaunchpadZopelessLayer.switchDbUser(test_dbuser)
setUp(test)
test.globs['test_dbuser'] = test_dbuser
def uploaderBugsTearDown(test):
logout()
def uploadQueueTearDown(test):
logout()
def manageChrootSetup(test):
"""Set up the manage-chroot.txt test."""
setUp(test)
LaunchpadZopelessLayer.switchDbUser("fiera")
special = {
'buildd-scoring.txt': LayeredDocFileSuite(
'../doc/buildd-scoring.txt',
setUp=builddmasterSetUp,
layer=LaunchpadZopelessLayer,
),
'package-cache.txt': LayeredDocFileSuite(
'../doc/package-cache.txt',
setUp=statisticianSetUp, tearDown=statisticianTearDown,
layer=LaunchpadZopelessLayer
),
'distroarchseriesbinarypackage.txt': LayeredDocFileSuite(
'../doc/distroarchseriesbinarypackage.txt',
setUp=setUp, tearDown=tearDown,
layer=LaunchpadZopelessLayer
),
'distroseriesqueue-debian-installer.txt': LayeredDocFileSuite(
'../doc/distroseriesqueue-debian-installer.txt',
setUp=distroseriesqueueSetUp, tearDown=distroseriesqueueTearDown,
layer=LaunchpadFunctionalLayer
),
'closing-bugs-from-changelogs.txt': LayeredDocFileSuite(
'../doc/closing-bugs-from-changelogs.txt',
setUp=uploadQueueSetUp,
tearDown=uploadQueueTearDown,
layer=LaunchpadZopelessLayer
),
'closing-bugs-from-changelogs.txt-uploader': LayeredDocFileSuite(
'../doc/closing-bugs-from-changelogs.txt',
setUp=uploaderBugsSetUp,
tearDown=uploaderBugsTearDown,
layer=LaunchpadZopelessLayer
),
'soyuz-set-of-uploads.txt': LayeredDocFileSuite(
'../doc/soyuz-set-of-uploads.txt',
layer=LaunchpadZopelessLayer,
),
'package-relationship.txt': LayeredDocFileSuite(
'../doc/package-relationship.txt',
stdout_logging=False, layer=None),
'publishing.txt': LayeredDocFileSuite(
'../doc/publishing.txt',
setUp=setUp,
layer=LaunchpadZopelessLayer,
),
'sourcepackagerelease-build-lookup.txt': LayeredDocFileSuite(
'../doc/sourcepackagerelease-build-lookup.txt',
layer=LaunchpadZopelessLayer,
),
'manage-chroot.txt': LayeredDocFileSuite(
'../doc/manage-chroot.txt',
setUp=manageChrootSetup,
layer=LaunchpadZopelessLayer,
),
'package-arch-specific.txt': LayeredDocFileSuite(
'../doc/package-arch-specific.txt',
setUp=builddmasterSetUp,
layer=LaunchpadZopelessLayer,
),
'queuebuilder.txt': LayeredDocFileSuite(
'../doc/queuebuilder.txt',
setUp=builddmasterSetUp,
layer=LaunchpadZopelessLayer,
stdout_logging_level=logging.WARNING,
),
}
def test_suite():
suite = unittest.TestSuite()
stories_dir = os.path.join(os.path.pardir, 'stories')
suite.addTest(PageTestSuite(stories_dir))
stories_path = os.path.join(here, stories_dir)
for story_dir in os.listdir(stories_path):
full_story_dir = os.path.join(stories_path, story_dir)
if not os.path.isdir(full_story_dir):
continue
story_path = os.path.join(stories_dir, story_dir)
suite.addTest(PageTestSuite(story_path))
# Add special needs tests
for key in sorted(special):
special_suite = special[key]
suite.addTest(special_suite)
testsdir = os.path.abspath(
os.path.normpath(os.path.join(here, os.path.pardir, 'doc')))
# Add tests using default setup/teardown
filenames = [filename
for filename in os.listdir(testsdir)
if filename.endswith('.txt') and filename not in special]
# Sort the list to give a predictable order.
filenames.sort()
for filename in filenames:
path = os.path.join('../doc', filename)
one_test = LayeredDocFileSuite(
path, setUp=setUp, tearDown=tearDown,
layer=LaunchpadFunctionalLayer,
stdout_logging_level=logging.WARNING)
suite.addTest(one_test)
return suite
|