Package bodhi :: Package tests :: Module test_controllers
[hide private]
[frames] | no frames]

Source Code for Module bodhi.tests.test_controllers

  1  # $Id: test_controllers.py,v 1.3 2006/12/31 09:10:25 lmacken Exp $ 
  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   
17 -class TestControllers(testutil.DBTest):
18
19 - def save_update(self, params, session={}):
20 pairs = urllib.urlencode(params) 21 url = '/updates/save?' + pairs 22 print url 23 testutil.createRequest(url, headers=session, method='POST')
24
25 - def create_release(self):
26 rel = Release(name='fc7', long_name='Fedora 7', id_prefix='FEDORA', 27 dist_tag='dist-fc7') 28 assert rel
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
43 - def test_bad_password(self):
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 # We commented out the cherrypy.response.status = '403' in 49 # our login controller to get the cli tool working. This may be a 50 # good/bad thing? 51 #assert cherrypy.response.status == '403 Forbidden' 52
53 - def test_good_password(self):
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
71 - def test_new_update(self):
72 session = self.login() 73 self.create_release() 74 params = { 75 'builds' : 'TurboGears-1.0.2.2-2.fc7', 76 'release' : 'Fedora 7', 77 'type' : 'enhancement', 78 'bugs' : '1234', 79 'cves' : 'CVE-2020-0001', 80 'notes' : 'foobar' 81 } 82 self.save_update(params, session) 83 update = PackageUpdate.byTitle(params['builds']) 84 assert update 85 assert update.title == params['builds'] 86 assert update.builds[0].nvr == params['builds'] 87 assert update.release.long_name == params['release'] 88 assert update.bugs[0].bz_id == int(params['bugs']) 89 assert update.cves[0].cve_id == params['cves'] 90 assert update.notes == params['notes'] 91 # we specified a CVE, so bodhi will automatically change the type 92 assert update.type == 'security'
93
94 - def test_multibuild_update(self):
95 session = self.login() 96 self.create_release() 97 params = { 98 'builds' : 'TurboGears-1.0.2.2-2.fc7 python-sqlobject-0.8.2-1.fc7', 99 'release' : 'Fedora 7', 100 'type' : 'enhancement', 101 'bugs' : '1234 5678', 102 'cves' : '', 103 'notes' : 'foobar' 104 } 105 self.save_update(params, session) 106 update = PackageUpdate.byTitle(','.join(params['builds'].split())) 107 assert update 108 builds = map(lambda x: x.nvr, update.builds) 109 for build in params['builds'].split(): 110 assert build in builds 111 assert update.release.long_name == params['release'] 112 assert update.type == params['type'] 113 assert update.notes == params['notes'] 114 for bug in params['bugs'].split(): 115 assert int(bug) in map(lambda x: x.bz_id, update.bugs)
116
117 - def test_bad_build(self):
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
130 - def test_bad_release(self):
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
143 - def test_bad_type(self):
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
156 - def test_user_notes_encoding(self):
157 session = self.login(username='lmacken', display_name='foo\xc3\xa9bar') 158 self.create_release() 159 params = { 160 'builds' : 'TurboGears-1.0.2.2-2.fc7', 161 'release' : 'Fedora 7', 162 'type' : 'bugfix', 163 'bugs' : '', 164 'cves' : '', 165 'notes' : 'Foo\u2019bar' 166 } 167 self.save_update(params, session) 168 update = PackageUpdate.byTitle(params['builds']) 169 assert update.title == params['builds'] 170 assert update.builds[0].nvr == params['builds'] 171 assert update.release.long_name == params['release'] 172 assert update.notes == params['notes']
173
174 - def test_bugs_update(self):
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
197 - def test_comment(self):
198 session = self.login() 199 self.create_release() 200 params = { 201 'builds' : 'TurboGears-1.0.2.2-2.fc7', 202 'release' : 'Fedora 7', 203 'type' : 'bugfix', 204 'bugs' : '', 205 'cves' : '', 206 'notes' : '' 207 } 208 self.save_update(params, session) 209 update = PackageUpdate.byTitle(params['builds']) 210 x = testutil.createRequest('/updates/comment?text=foobar&title=%s&karma=1' % 211 params['builds'], method='POST', 212 headers=session) 213 assert len(update.comments) == 1 214 assert update.karma == 1 215 assert update.comments[0].author == 'lmacken' 216 assert update.comments[0].text == 'foobar' 217 218 # Allow users to negate their original comment 219 x = testutil.createRequest('/updates/comment?text=bizbaz&title=%s&karma=-1' % 220 params['builds'], method='POST', 221 headers=session) 222 update = PackageUpdate.byTitle(params['builds']) 223 assert update.karma == 0 224 225 # but don't let them do it again 226 x = testutil.createRequest('/updates/comment?text=bizbaz&title=%s&karma=-1' % 227 params['builds'], method='POST', 228 headers=session) 229 update = PackageUpdate.byTitle(params['builds']) 230 assert update.karma == 0
231
232 - def test_edit(self):
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 # Add another build, and a bug 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 # Remove a build and bug 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
291 - def test_delete(self):
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 # Try unauthenticated first 306 x = testutil.createRequest('/updates/delete?update=%s' % 307 params['builds'], method='POST') 308 update = PackageUpdate.byTitle(params['builds']) 309 assert update 310 311 # Now try again with our authenticated session cookie 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
330 - def test_requests(self):
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
360 - def test_bad_bugs(self):
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
374 - def test_bad_cves(self):
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
388 - def test_not_owner(self):
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