1
2
3 import turbogears
4 from turbogears import testutil, database, config
5 turbogears.update_config(configfile='dev.cfg', modulename='bodhi.config')
6 database.set_db_uri("sqlite:///:memory:")
7
8 import urllib
9 import cherrypy
10
11 from sqlobject import SQLObjectNotFound
12 from bodhi.model import Release, PackageUpdate, User, PackageBuild, Bugzilla
13 from bodhi.controllers import Root
14
15 cherrypy.root = Root()
16
18
20 pairs = urllib.urlencode(params)
21 url = '/updates/save?' + pairs
22 print url
23 testutil.createRequest(url, headers=session, method='POST')
24
29
30 - def login(self, username='lmacken', display_name='lmacken'):
31 guest = User(user_name=username, display_name=display_name)
32 guest.password = 'guest'
33 testutil.createRequest('/updates/login?tg_format=json&login=Login&forward_url=/updates/&user_name=%s&password=guest' % username, method='POST')
34 assert cherrypy.response.status == '200 OK'
35 cookies = filter(lambda x: x[0] == 'Set-Cookie',
36 cherrypy.response.header_list)
37 cookiehdr = ""
38 for cookie in zip(cookies[0], cookies[1])[1]:
39 cookiehdr += cookie.split(';')[0] + '\r\n '
40 cookiehdr = cookiehdr.strip()
41 return { 'Cookie' : cookiehdr }
42
44 x = testutil.createRequest('/updates/login?tg_format=json&login=Login&&user_name=lmacken&password=foo', method='POST')
45 assert "The credentials you supplied were not correct or did not grant access to this resource." in cherrypy.response.body[0]
46 print cherrypy.response.status
47
48
49
50
51
52
54 guest = User(user_name='lmacken')
55 guest.password = 'guest'
56 x = testutil.createRequest('/updates/login?tg_format=json&login=Login&user_name=lmacken&password=guest', method='POST')
57 assert cherrypy.response.status == '200 OK'
58
60 params = {
61 'builds' : 'TurboGears-1.0.2.2-2.fc7',
62 'release' : 'Fedora 7',
63 'type' : 'enhancement',
64 'bugs' : '1234 5678',
65 'cves' : 'CVE-2020-0001',
66 'notes' : 'foobar'
67 }
68 self.save_update(params)
69 assert "You must provide your credentials before accessing this resource." in cherrypy.response.body[0]
70
93
116
118 session = self.login()
119 params = {
120 'builds' : 'foobar',
121 'release' : 'Fedora 7',
122 'type' : 'enhancement',
123 'bugs' : '1234 5678',
124 'cves' : '',
125 'notes' : 'foobar'
126 }
127 self.save_update(params, session)
128 assert "Invalid package name; must be in package-version-release format" in cherrypy.response.body[0]
129
131 session = self.login()
132 params = {
133 'builds' : 'TurboGears-1.0.2.2-2.fc7',
134 'release' : 'Ubuntu Bitchy Beaver',
135 'type' : 'enhancement',
136 'bugs' : '',
137 'cves' : '',
138 'notes' : ''
139 }
140 self.save_update(params, session)
141 assert "Value must be one of: F7; Fedora 7 (not \'Ubuntu Bitchy Beaver\')" in cherrypy.response.body[0]
142
144 session = self.login()
145 params = {
146 'builds' : 'TurboGears-1.0.2.2-2.fc7',
147 'release' : 'Fedora 7',
148 'type' : 'REGRESSION!',
149 'bugs' : '',
150 'cves' : '',
151 'notes' : ''
152 }
153 self.save_update(params, session)
154 assert "Value must be one of: bugfix; enhancement; security (not \'REGRESSION!\')" in cherrypy.response.body[0]
155
173
175 session = self.login()
176 self.create_release()
177 params = {
178 'builds' : 'TurboGears-1.0.2.2-2.fc7',
179 'release' : 'Fedora 7',
180 'type' : 'enhancement',
181 'bugs' : '#1234, #567 89',
182 'cves' : '',
183 'notes' : 'foobar'
184 }
185 self.save_update(params, session)
186 update = PackageUpdate.byTitle(params['builds'])
187 assert update
188 assert update.title == params['builds']
189 assert update.builds[0].nvr == params['builds']
190 assert update.release.long_name == params['release']
191 for bug in params['bugs'].replace('#', '').replace(',', ' ').split():
192 assert int(bug) in map(lambda x: x.bz_id, update.bugs)
193 assert len(update.cves) == 0
194 assert update.notes == params['notes']
195 assert update.type == params['type']
196
231
233 session = self.login()
234 self.create_release()
235 params = {
236 'builds' : 'TurboGears-1.0.2.2-2.fc7',
237 'release' : 'Fedora 7',
238 'type' : 'bugfix',
239 'bugs' : '',
240 'cves' : '',
241 'notes' : ''
242 }
243 self.save_update(params, session)
244 update = PackageUpdate.byTitle(params['builds'])
245
246
247 params = {
248 'builds' : 'TurboGears-1.0.2.2-2.fc7 python-sqlobject-0.8.2-1.fc7',
249 'release' : 'Fedora 7',
250 'type' : 'bugfix',
251 'bugs' : '1',
252 'cves' : '',
253 'notes' : '',
254 'edited' : 'TurboGears-1.0.2.2-2.fc7'
255 }
256 self.save_update(params, session)
257 update = PackageUpdate.byTitle(','.join(params['builds'].split()))
258 assert len(update.builds) == 2
259 builds = map(lambda x: x.nvr, update.builds)
260 for build in params['builds'].split():
261 assert build in builds
262 x = PackageBuild.byNvr(build)
263 assert x.updates[0] == update
264 assert len(update.bugs) == 1
265 assert update.bugs[0].bz_id == int(params['bugs'])
266 bug = Bugzilla.byBz_id(int(params['bugs']))
267
268
269 params = {
270 'builds' : 'python-sqlobject-0.8.2-1.fc7',
271 'release' : 'Fedora 7',
272 'type' : 'bugfix',
273 'bugs' : '',
274 'cves' : '',
275 'notes' : 'foobar',
276 'edited' : 'TurboGears-1.0.2.2-2.fc7,python-sqlobject-0.8.2-1.fc7'
277 }
278 self.save_update(params, session)
279 update = PackageUpdate.byTitle(','.join(params['builds'].split()))
280 assert len(update.builds) == 1
281 build = PackageBuild.byNvr(params['builds'])
282 assert build.updates[0] == update
283 assert update.notes == params['notes']
284 assert len(update.bugs) == 0
285 try:
286 bug = Bugzilla.byBz_id(1)
287 assert False, "Bug #1 never got destroyed after edit"
288 except SQLObjectNotFound:
289 pass
290
292 session = self.login()
293 self.create_release()
294 params = {
295 'builds' : 'TurboGears-1.0.2.2-2.fc7,nethack-1.2.3-4',
296 'release' : 'Fedora 7',
297 'type' : 'bugfix',
298 'bugs' : '',
299 'cves' : '',
300 'notes' : ''
301 }
302 self.save_update(params, session)
303 update = PackageUpdate.byTitle(params['builds'])
304
305
306 x = testutil.createRequest('/updates/delete?update=%s' %
307 params['builds'], method='POST')
308 update = PackageUpdate.byTitle(params['builds'])
309 assert update
310
311
312 x = testutil.createRequest('/updates/delete?update=%s' %
313 params['builds'], method='POST',
314 headers=session)
315 try:
316 update = PackageUpdate.byTitle(params['builds'])
317 print update
318 assert False, "Update never deleted!"
319 except SQLObjectNotFound:
320 pass
321
322 for build in params['builds'].split(','):
323 try:
324 build = PackageBuild.byNvr(build)
325 print build
326 assert False, "Build never deleted!"
327 except SQLObjectNotFound:
328 pass
329
331 session = self.login()
332 self.create_release()
333 params = {
334 'builds' : 'TurboGears-1.0.2.2-2.fc7',
335 'release' : 'Fedora 7',
336 'type' : 'bugfix',
337 'bugs' : '',
338 'cves' : '',
339 'notes' : ''
340 }
341 self.save_update(params, session)
342 update = PackageUpdate.byTitle(params['builds'])
343 assert update.status == 'pending'
344 assert update.request == None
345
346 testutil.createRequest('/updates/push?nvr=%s' % params['builds'],
347 method='POST', headers=session)
348 update = PackageUpdate.byTitle(params['builds'])
349 print "update.request =", update.request
350 assert update.request == 'testing'
351 testutil.createRequest('/updates/unpush?nvr=%s' % params['builds'],
352 method='POST', headers=session)
353 update = PackageUpdate.byTitle(params['builds'])
354 assert update.request == 'obsolete'
355 testutil.createRequest('/updates/move?nvr=%s' % params['builds'],
356 method='POST', headers=session)
357 update = PackageUpdate.byTitle(params['builds'])
358 assert update.request == 'stable', update.request
359
361 session = self.login()
362 self.create_release()
363 params = {
364 'builds' : 'TurboGears-1.0.2.2-2.fc7',
365 'release' : 'Fedora 7',
366 'type' : 'enhancement',
367 'bugs' : 'foobar',
368 'cves' : '',
369 'notes' : ''
370 }
371 self.save_update(params, session)
372 assert "Invalid bug(s)." in cherrypy.response.body[0]
373
375 session = self.login()
376 self.create_release()
377 params = {
378 'builds' : 'TurboGears-1.0.2.2-2.fc7',
379 'release' : 'Fedora 7',
380 'type' : 'enhancement',
381 'bugs' : '',
382 'cves' : 'FOO',
383 'notes' : ''
384 }
385 self.save_update(params, session)
386 assert "Invalid CVE(s)." in cherrypy.response.body[0]
387
389 session = self.login(username='guest')
390 self.create_release()
391 params = {
392 'builds' : 'TurboGears-1.0.2.2-2.fc7',
393 'release' : 'Fedora 7',
394 'type' : 'enhancement',
395 'bugs' : '',
396 'cves' : '',
397 'notes' : ''
398 }
399 self.save_update(params, session)
400 assert "This resource resides temporarily" in cherrypy.response.body[0]
401