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

Source Code for Module bodhi.tests.test_model

  1  # $Id: test_model.py,v 1.5 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 os 
  9  import sys 
 10  import time 
 11  import shutil 
 12  import tempfile 
 13   
 14  from os.path import join, exists, basename 
 15  from bodhi.util import mkmetadatadir 
 16  from bodhi.model import (Release, Package, PackageUpdate, Bugzilla, CVE, 
 17                           PackageBuild, Comment, User) 
 18  from bodhi.exceptions import (DuplicateEntryError, SQLiteIntegrityError, 
 19                                PostgresIntegrityError, RPMNotFound) 
 20   
 21  from yum.update_md import UpdateMetadata 
 22   
23 -class TestPackageUpdate(testutil.DBTest):
24
25 - def get_pkg(self, name='TurboGears'):
26 return Package(name=name)
27
28 - def get_rel(self):
29 rel = Release(name='fc7', long_name='Fedora 7', id_prefix='FEDORA', 30 dist_tag='dist-fc7') 31 return rel
32
33 - def get_build(self, nvr='TurboGears-1.0.2.2-2.fc7'):
34 package = self.get_pkg('-'.join(nvr.split('-')[:-2])) 35 build = PackageBuild(nvr=nvr, package=package) 36 return build
37
38 - def get_update(self, name='TurboGears-1.0.2.2-2.fc7'):
39 update = PackageUpdate(title=name, 40 release=self.get_rel(), 41 submitter='foo@bar.com', 42 status='testing', 43 notes='foobar', 44 type='security') 45 build = self.get_build(name) 46 update.addPackageBuild(build) 47 return update
48
49 - def get_bug(self):
50 return Bugzilla(bz_id=1)
51
52 - def get_cve(self):
53 return CVE(cve_id="CVE-2007-0000")
54
55 - def get_comment(self, update):
56 return Comment(author='bodhi', text='foobar', karma=0, update=update)
57
58 - def test_dupe(self):
59 update1 = self.get_update() 60 try: 61 update2 = self.get_update() 62 except (DuplicateEntryError, PostgresIntegrityError, 63 SQLiteIntegrityError): 64 return 65 assert False
66
67 - def test_mail_notices(self):
68 """ Make sure all of our mail notices can expand properly """ 69 from bodhi.mail import messages 70 me = User(user_name='guest', display_name='Guest') 71 update = self.get_update() 72 self.get_comment(update) 73 for title, data in messages.items(): 74 assert data['body'] % data['fields'](update)
75
76 - def test_creation(self):
77 update = self.get_update() 78 assert update.title == 'TurboGears-1.0.2.2-2.fc7' 79 assert update.builds[0].package.name == 'TurboGears' 80 assert update.release.name == 'fc7' 81 assert update.release.updates[0] == update 82 assert update.status == 'testing' 83 assert update.type == 'security' 84 assert update.notes == 'foobar' 85 bug = self.get_bug() 86 cve = self.get_cve() 87 update.addBugzilla(bug) 88 update.addCVE(cve) 89 assert update.bugs[0].bz_id == 1 90 assert update.cves[0].cve_id == 'CVE-2007-0000'
91
92 - def test_id(self):
93 update = self.get_update() 94 update.assign_id() 95 assert update.update_id == '%s-%s-0001' % (update.release.id_prefix, 96 time.localtime()[0])
97
98 - def test_multibuild(self):
99 from bodhi import util 100 builds = ('yum-3.2.1-1.fc7', 'httpd-2.2.4-4.1.fc7') 101 pkg_builds = [] 102 for build in builds: 103 nvr = util.get_nvr(build) 104 pkg = Package(name=nvr[0]) 105 b = PackageBuild(nvr=build, package=pkg) 106 pkg_builds.append(b) 107 release = self.get_rel() 108 update = PackageUpdate(title=','.join(builds), release=release, 109 submitter='foo@bar.com', notes='Testing!', 110 type='bugfix') 111 map(update.addPackageBuild, pkg_builds) 112 assert update.builds[0].nvr == builds[0] 113 assert update.builds[1].nvr == builds[1] 114 assert update.title == ','.join(builds) 115 assert update.release.name == 'fc7' 116 assert release.updates[0] == update 117 assert update.status == 'pending' 118 assert update.type == 'bugfix' 119 assert update.notes == 'Testing!'
120
121 - def test_encoding(self, buildnvr='yum-3.2.1-1.fc7'):
122 update = PackageUpdate(title=buildnvr, 123 release=self.get_rel(), 124 submitter=u'Foo \xc3\xa9 Bar <foo@bar.com>', 125 notes=u'Testing \u2019t stuff', 126 type='security') 127 assert update 128 assert update.notes == u'Testing \u2019t stuff' 129 assert update.submitter == u'Foo \xc3\xa9 Bar <foo@bar.com>' 130 build = self.get_build(buildnvr) 131 update.addPackageBuild(build) 132 return update
133
134 - def _verify_updateinfo(self, update, repo):
135 """ Verify that the updateinfo.xml.gz for a given repo matches the 136 data for a given update 137 """ 138 print "_verify_updateinfo(%s, %s)" % (update.nvr, repo) 139 uinfo = UpdateMetadata() 140 uinfo.add(repo) 141 notice = uinfo.get_notice(update.nvr) 142 assert notice 143 assert notice['from'] == 'updates@fedora.com' 144 assert notice['title'] == update.nvr 145 assert notice['release'] == update.release.long_name 146 assert notice['type'] == update.type 147 assert notice['status'] == update.status 148 assert notice['update_id'] == update.update_id 149 assert notice['issued'] == str(update.date_pushed) 150 assert notice['description'] == update.notes 151 for collection in notice['pkglist']: 152 numfiles = 0 153 for archfiles in update.filelist.values(): 154 for file in archfiles: 155 numfiles += 1 156 assert len(collection['packages']) == numfiles 157 for pkg in collection['packages']: 158 assert pkg['arch'] in update.filelist.keys() 159 found = False 160 for file in update.filelist[pkg['arch']]: 161 if pkg['filename'] in file: 162 found = True 163 break 164 assert found
165
166 - def test_email(self):
167 from bodhi import mail 168 update = self.get_update(name='TurboGears-1.0.2.2-2.fc7') 169 bug = self.get_bug() 170 cve = self.get_cve() 171 update.addBugzilla(bug) 172 update.addCVE(cve) 173 update.assign_id() 174 print update 175 try: 176 templates = mail.get_template(update) 177 except RPMNotFound: 178 # We're assuming we can find any real packages if we're a 179 # development instance.. so just skip this test for now 180 if config.get('buildsystem') == 'dev': 181 return 182 else: 183 raise 184 assert templates 185 from pprint import pprint 186 pprint(templates) 187 assert templates[0][0] == u'[SECURITY] Fedora 7 Test Update: TurboGears-1.0.2.2-2.fc7' 188 assert templates[0][1] == u'--------------------------------------------------------------------------------\nFedora Test Update Notification\nFEDORA-2007-0001\nNone\n--------------------------------------------------------------------------------\n\nName : TurboGears\nProduct : Fedora 7\nVersion : 1.0.2.2\nRelease : 2.fc7\nURL : http://www.turbogears.org\nSummary : Back-to-front web development in Python\nDescription :\nTurboGears brings together four major pieces to create an\neasy to install, easy to use web megaframework. It covers\neverything from front end (MochiKit JavaScript for the browser,\nKid for templates in Python) to the controllers (CherryPy) to\nthe back end (SQLObject).\n\nThe TurboGears project is focused on providing documentation\nand integration with these tools without losing touch\nwith the communities that already exist around those tools.\n\nTurboGears is easy to use for a wide range of web applications.\n\n--------------------------------------------------------------------------------\nUpdate Information:\n\nfoobar\n--------------------------------------------------------------------------------\nReferences:\n\n [ 1 ] Bug #1 - test bug\n https://bugzilla.redhat.com/show_bug.cgi?id=1\n [ 2 ] CVE-2007-0000\n http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-0000\n--------------------------------------------------------------------------------\nUpdated packages:\n\n57e80ee8eb6d666c79c498e0b2efecd74ab52063 TurboGears-1.0.2.2-2.fc7.src.rpm\n85e05a4d52143ce38f43f7fdd244251e18f9d408 TurboGears-1.0.2.2-2.fc7.noarch.rpm\n\nThis update can be installed with the "yum" update program. Use \nsu -c \'yum update TurboGears\' \nat the command line. For more information, refer to "Managing Software\nwith yum", available at http://docs.fedoraproject.org/yum/.\n--------------------------------------------------------------------------------\n' or templates[0][1] == u'--------------------------------------------------------------------------------\nFedora Test Update Notification\nFEDORA-2007-0001\nNone\n--------------------------------------------------------------------------------\n\nName : TurboGears\nProduct : Fedora 7\nVersion : 1.0.2.2\nRelease : 2.fc7\nURL : http://www.turbogears.org\nSummary : Back-to-front web development in Python\nDescription :\nTurboGears brings together four major pieces to create an\neasy to install, easy to use web megaframework. It covers\neverything from front end (MochiKit JavaScript for the browser,\nKid for templates in Python) to the controllers (CherryPy) to\nthe back end (SQLObject).\n\nThe TurboGears project is focused on providing documentation\nand integration with these tools without losing touch\nwith the communities that already exist around those tools.\n\nTurboGears is easy to use for a wide range of web applications.\n\n--------------------------------------------------------------------------------\nUpdate Information:\n\nfoobar\n--------------------------------------------------------------------------------\nReferences:\n\n [ 1 ] Bug #1 - None\n https://bugzilla.redhat.com/show_bug.cgi?id=1\n [ 2 ] CVE-2007-0000\n http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-0000\n--------------------------------------------------------------------------------\nUpdated packages:\n\n57e80ee8eb6d666c79c498e0b2efecd74ab52063 TurboGears-1.0.2.2-2.fc7.src.rpm\n85e05a4d52143ce38f43f7fdd244251e18f9d408 TurboGears-1.0.2.2-2.fc7.noarch.rpm\n\nThis update can be installed with the "yum" update program. Use \nsu -c \'yum update TurboGears\' \nat the command line. For more information, refer to "Managing Software\nwith yum", available at http://docs.fedoraproject.org/yum/.\n--------------------------------------------------------------------------------\n' or templates[0][1] == u'--------------------------------------------------------------------------------\nFedora Test Update Notification\nFEDORA-2007-0001\nNone\n--------------------------------------------------------------------------------\n\nName : TurboGears\nProduct : Fedora 7\nVersion : 1.0.2.2\nRelease : 2.fc7\nURL : http://www.turbogears.org\nSummary : Back-to-front web development in Python\nDescription :\nTurboGears brings together four major pieces to create an\neasy to install, easy to use web megaframework. It covers\neverything from front end (MochiKit JavaScript for the browser,\nKid for templates in Python) to the controllers (CherryPy) to\nthe back end (SQLObject).\n\nThe TurboGears project is focused on providing documentation\nand integration with these tools without losing touch\nwith the communities that already exist around those tools.\n\nTurboGears is easy to use for a wide range of web applications.\n\n--------------------------------------------------------------------------------\nUpdate Information:\n\nfoobar\n--------------------------------------------------------------------------------\nReferences:\n\n [ 1 ] Bug #1 - None\n https://bugzilla.redhat.com/show_bug.cgi?id=1\n [ 2 ] CVE-2007-0000\n http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-0000\n--------------------------------------------------------------------------------\nUpdated packages:\n\n57e80ee8eb6d666c79c498e0b2efecd74ab52063 TurboGears-1.0.2.2-2.fc7.src.rpm\n85e05a4d52143ce38f43f7fdd244251e18f9d408 TurboGears-1.0.2.2-2.fc7.noarch.rpm\n\nThis update can be installed with the "yum" update program. Use \nsu -c \'yum --enablerepo=updates-testing update TurboGears\' \nat the command line. For more information, refer to "Managing Software\nwith yum", available at http://docs.fedoraproject.org/yum/.\n--------------------------------------------------------------------------------\n'
189 190
191 - def test_latest(self):
192 update = self.get_update(name='yum-3.2.1-1.fc7') 193 if config.get('buildsystem') == 'koji': 194 latest = update.builds[0].get_latest() 195 assert latest 196 assert latest == '/mnt/koji/packages/yum/3.2.0/1.fc7/src/yum-3.2.0-1.fc7.src.rpm'
197
198 - def test_changelog(self):
199 if config.get('buildsystem') != 'koji': return 200 import rpm 201 from bodhi.util import rpm_fileheader 202 update = self.get_update(name='yum-3.2.1-1.fc7') 203 oldh = rpm_fileheader(update.builds[0].get_latest()) 204 oldtime = oldh[rpm.RPMTAG_CHANGELOGTIME] 205 text = oldh[rpm.RPMTAG_CHANGELOGTEXT] 206 oldtime = oldtime[0] 207 changelog = update.builds[0].get_changelog(oldtime) 208 assert changelog == '* Thu Jun 21 2007 Seth Vidal <skvidal at fedoraproject.org> - 3.2.1-1\n- bump to 3.2.1\n'
209 210
211 -class TestBugzilla(testutil.DBTest):
212
213 - def get_model(self):
214 return Bugzilla
215
216 - def test_creation(self):
217 bug = Bugzilla(bz_id=1)
218
219 - def test_security_bug(self):
220 bug = Bugzilla(bz_id=237533) 221 assert bug 222 if config.get('bodhi_password'): 223 assert bug.title == 'CVE-2007-2165: proftpd auth bypass vulnerability' 224 assert bug.security == True 225 assert bug.bz_id == 237533
226