def test_gettinghtml(): global logged capture_log("turbogears.controllers") create_request("/with_json") logged = get_log() body = cherrypy.response.body[0] print body assert "Paging all foo" in body
def test_getting_json_with_accept_but_using_tg_format(): capture_log("turbogears.controllers") create_request("/with_json_via_accept?tg_format=json") print_log() print "\n".join(logged) body = cherrypy.response.body[0] print body assert '"title": "Foobar"' in body
def test_update_str(self): bodhi = self.__get_bodhi_client() opts = self.__get_opts() testutil.capture_log(['bodhi.controllers', 'bodhi.util']) self.__save_update(self.build, opts, bodhi) testutil.print_log() update = bodhi.query()['updates'][0] assert update and isinstance(update, dict) assert bodhi.update_str(update).startswith(u'================================================================================\n TurboGears-1.0.3.2-1.fc7\n================================================================================\n Release: Fedora 7\n Status: pending\n Type: bugfix\n Karma: 0\n Request: testing\n Bugs: 12345 - None\n : 6789 - None\n Notes: foo\n Submitter: guest\n') assert bodhi.update_str(update).endswith(u' (karma 0)\n This update has been submitted for testing by guest.\n\n http://localhost:8084/updates/TurboGears-1.0.3.2-1.fc7\n')
def test_raise_sa_exception(): """If a controller causes an SA exception, it is raised properly.""" capture_log("turbogears.database") cherrypy.root = MyRoot() create_request("/create_person?id=20") output = cherrypy.response.body[0] assert 'No exceptions occurred' in output create_request("/create_person?id=20") output = cherrypy.response.body[0] # SA 0.3 uses SQLError, 0.4 DBAPIError, 0.5 IntegrityError assert ('SQLError' in output or 'DBAPIError' in output or 'IntegrityError' in output)
def test_implicit_trans_no_error(): """If a controller runs sucessfully, the transaction is commited.""" capture_log("turbogears.database") cherrypy.root = MyRoot() create_request("/no_error?name=A.%20Dent") print_log() try: session.expunge_all() except AttributeError: # SQLAlchemy < 0.5.1 session.clear() q = session.query(Person) arthur = q.filter_by(name="A. Dent").one()
def test_allowJsonConfig(self): "JSON output can be enabled via config." turbogears.config.update({'tg.allow_json':True}) testutil.capture_log("tubrogears.controllers") class JSONRoot(controllers.RootController): def allowjsonconfig(self): return dict(title="Foobar", mybool=False, someval="foo", tg_html="turbogears.tests.simple") allowjsonconfig = turbogears.expose(html="turbogears.tests.simple")(allowjsonconfig) testutil.print_log() cherrypy.root = JSONRoot() testutil.createRequest('/allowjsonconfig?tg_format=json') assert cherrypy.response.headers["Content-Type"]=="text/javascript" turbogears.config.update({'tg.allow_json':False})
def test_allowJsonConfigFalse(self): "Make sure JSON can still be restricted with a global config on." turbogears.config.update({'tg.allow_json':True}) testutil.capture_log("tubrogears.controllers") class JSONRoot(controllers.RootController): def allowjsonconfig(self): return dict(title="Foobar", mybool=False, someval="foo", tg_html="turbogears.tests.simple") allowjsonconfig = turbogears.expose(html="turbogears.tests.simple")(allowjsonconfig) testutil.print_log() cherrypy.root = JSONRoot() testutil.createRequest('/allowjson?tg_format=json') print cherrypy.response.body[0] assert cherrypy.response.headers["Content-Type"]=="text/html" turbogears.config.update({'tg.allow_json':False})
def test_allow_json(): class NewRoot(controllers.RootController): [expose(template="turbogears.test.simple", allow_json=True)] def test(self): return dict(title="Foobar", mybool=False, someval="niggles") cherrypy.root = NewRoot() capture_log("turbogears.controllers") create_request("/test", headers= dict(accept="text/javascript")) print_log() print cherrypy.response.body[0] values = simplejson.loads(cherrypy.response.body[0]) assert values == dict(title="Foobar", mybool=False, someval="niggles", tg_flash=None) assert cherrypy.response.headers["Content-Type"] == "text/javascript" create_request("/test?tg_format=json") print cherrypy.response.body[0] values = simplejson.loads(cherrypy.response.body[0]) assert values == dict(title="Foobar", mybool=False, someval="niggles", tg_flash=None) assert cherrypy.response.headers["Content-Type"] == "text/javascript"
def test_old_testing_nagmail(self): update = self.get_update() update.status = 'testing' update.status_comment() assert not update.nagged nagmail() assert not update.nagged update.comments[-1].timestamp = datetime.utcnow() - timedelta(days=20) update.date_pushed = datetime.utcnow() - timedelta(days=20) testutil.capture_log('bodhi.jobs') nagmail() log = testutil.get_log() assert "[old_testing] Nagging [email protected] about TurboGears-1.0.2.2-2.fc7" in log, log assert update.nagged, update.nagged assert 'old_testing' in update.nagged # Make sure it doesn't happen again testutil.capture_log('bodhi.jobs') nagmail() log = testutil.get_log() assert not "[old_testing] Nagging [email protected] about TurboGears-1.0.2.2-2.fc7" in log # Don't nag 6 days later newnag = update.nagged newnag['old_testing'] = update.nagged['old_testing'] - timedelta( days=6) update.nagged = newnag testutil.capture_log('bodhi.jobs') nagmail() log = testutil.get_log() assert not "[old_testing] Nagging [email protected] about TurboGears-1.0.2.2-2.fc7" in log # Nag again 1 week later newnag = update.nagged newnag['old_testing'] = update.nagged['old_testing'] - timedelta( days=7) update.nagged = newnag testutil.capture_log('bodhi.jobs') nagmail() log = testutil.get_log() assert "[old_testing] Nagging [email protected] about TurboGears-1.0.2.2-2.fc7" in log
def test_old_testing_nagmail(self): update = self.get_update() update.status = 'testing' update.status_comment() assert not update.nagged nagmail() assert not update.nagged update.comments[-1].timestamp = datetime.utcnow() - timedelta(days=20) update.date_pushed = datetime.utcnow() - timedelta(days=20) testutil.capture_log('bodhi.jobs') nagmail() log = testutil.get_log() assert "[old_testing] Nagging [email protected] about TurboGears-1.0.2.2-2.fc7" in log, log assert update.nagged, update.nagged assert update.nagged.has_key('old_testing') # Make sure it doesn't happen again testutil.capture_log('bodhi.jobs') nagmail() log = testutil.get_log() assert not "[old_testing] Nagging [email protected] about TurboGears-1.0.2.2-2.fc7" in log # Don't nag 6 days later newnag = update.nagged newnag['old_testing'] = update.nagged['old_testing'] - timedelta(days=6) update.nagged = newnag testutil.capture_log('bodhi.jobs') nagmail() log = testutil.get_log() assert not "[old_testing] Nagging [email protected] about TurboGears-1.0.2.2-2.fc7" in log # Nag again 1 week later newnag = update.nagged newnag['old_testing'] = update.nagged['old_testing'] - timedelta(days=7) update.nagged = newnag testutil.capture_log('bodhi.jobs') nagmail() log = testutil.get_log() assert "[old_testing] Nagging [email protected] about TurboGears-1.0.2.2-2.fc7" in log
def test_old_pending_nagmail(self): update = self.get_update() update.status = 'pending' assert not update.nagged nagmail() assert not update.nagged update.date_submitted = datetime.utcnow() - timedelta(days=20) testutil.capture_log('bodhi.jobs') nagmail() log = testutil.get_log() assert "[old_pending] Nagging [email protected] about TurboGears-1.0.2.2-2.fc7" in log assert update.nagged, update.nagged assert update.nagged.has_key('old_pending') # Make sure it doesn't happen again testutil.capture_log('bodhi.jobs') nagmail() log = testutil.get_log() assert not "[old_pending] Nagging [email protected] about TurboGears-1.0.2.2-2.fc7" in log # Don't nag 6 days later newnag = update.nagged newnag['old_pending'] = update.nagged['old_pending'] - timedelta(days=6) update.nagged = newnag testutil.capture_log('bodhi.jobs') nagmail() log = testutil.get_log() assert not "[old_pending] Nagging [email protected] about TurboGears-1.0.2.2-2.fc7" in log # Nag again 1 week later newnag = update.nagged newnag['old_pending'] = update.nagged['old_pending'] - timedelta(days=7) update.nagged = newnag testutil.capture_log('bodhi.jobs') nagmail() log = testutil.get_log() assert "[old_pending] Nagging [email protected] about TurboGears-1.0.2.2-2.fc7" in log
def test_old_pending_nagmail(self): update = self.get_update() update.status = 'pending' assert not update.nagged nagmail() assert not update.nagged update.date_submitted = datetime.utcnow() - timedelta(days=20) testutil.capture_log('bodhi.jobs') nagmail() log = testutil.get_log() assert "[old_pending] Nagging [email protected] about TurboGears-1.0.2.2-2.fc7" in log assert update.nagged, update.nagged assert 'old_pending' in update.nagged # Make sure it doesn't happen again testutil.capture_log('bodhi.jobs') nagmail() log = testutil.get_log() assert not "[old_pending] Nagging [email protected] about TurboGears-1.0.2.2-2.fc7" in log # Don't nag 6 days later newnag = update.nagged newnag['old_pending'] = update.nagged['old_pending'] - timedelta(days=6) update.nagged = newnag testutil.capture_log('bodhi.jobs') nagmail() log = testutil.get_log() assert not "[old_pending] Nagging [email protected] about TurboGears-1.0.2.2-2.fc7" in log # Nag again 1 week later newnag = update.nagged newnag['old_pending'] = update.nagged['old_pending'] - timedelta(days=7) update.nagged = newnag testutil.capture_log('bodhi.jobs') nagmail() log = testutil.get_log() assert "[old_pending] Nagging [email protected] about TurboGears-1.0.2.2-2.fc7" in log
def test_extended_metadata_updating_with_edited_updates(self): testutil.capture_log(['bodhi.metadata']) # grab the name of a build in updates-testing, and create it in our db koji = get_session() builds = koji.listTagged('dist-f13-updates-testing', latest=True) # Create all of the necessary database entries release = Release(name='F13', long_name='Fedora 13', id_prefix='FEDORA', dist_tag='dist-f13') package = Package(name=builds[0]['package_name']) update = PackageUpdate(title=builds[0]['nvr'], release=release, submitter=builds[0]['owner_name'], status='testing', notes='foobar', type='bugfix') build = PackageBuild(nvr=builds[0]['nvr'], package=package) update.addPackageBuild(build) update.assign_id() ## Initialize our temporary repo temprepo = join(tempfile.mkdtemp('bodhi'), 'f13-updates-testing') print "Inserting updateinfo into temprepo: %s" % temprepo mkmetadatadir(join(temprepo, 'i386')) repodata = join(temprepo, 'i386', 'repodata') assert exists(join(repodata, 'repomd.xml')) ## Generate the XML md = ExtendedMetadata(temprepo) ## Insert the updateinfo.xml into the repository md.insert_updateinfo() updateinfo = self.__verify_updateinfo(repodata) ## Read an verify the updateinfo.xml.gz uinfo = UpdateMetadata() uinfo.add(updateinfo) notice = uinfo.get_notice(('mutt', '1.5.14', '1.fc13')) assert not notice notice = uinfo.get_notice(get_nvr(update.title)) assert notice assert notice['status'] == update.status assert notice['updated'] == update.date_modified assert notice['from'] == str(config.get('bodhi_email')) assert notice['description'] == update.notes assert notice['issued'] is not None assert notice['update_id'] == update.updateid assert notice['title'] == update.title assert notice['release'] == update.release.long_name ## Edit the update and bump the build revision nvr = 'TurboGears-1.0.2.2-3.fc7' newbuild = PackageBuild(nvr=nvr, package=package) update.removePackageBuild(build) update.addPackageBuild(newbuild) update.title = nvr update.date_modified = datetime.utcnow() # Pretend -2 was unpushed assert len(koji.__untag__) == 0 koji.__untag__.append('TurboGears-1.0.2.2-2.fc7') ## Test out updateinfo.xml updating via our ExtendedMetadata md = ExtendedMetadata(temprepo, updateinfo) md.insert_updateinfo() updateinfo = self.__verify_updateinfo(repodata) ## Read an verify the updateinfo.xml.gz uinfo = UpdateMetadata() uinfo.add(updateinfo) print(testutil.get_log()) notice = uinfo.get_notice(('TurboGears', '1.0.2.2', '2.fc7')) assert not notice, "Old TG notice did not get pruned: %s" % notice notice = uinfo.get_notice(('TurboGears', '1.0.2.2', '3.fc7')) assert notice, uinfo assert notice['title'] == update.title num_notices = len(uinfo.get_notices()) assert num_notices == 1, num_notices ## Clean up shutil.rmtree(temprepo) del (koji.__untag__[:])
def _setUp(self): self.outp = StringIO() twill.set_output(self.outp) testutil.capture_log("gheimdall.controllers")
def test_extended_metadata_updating_with_old_stable_security(self): testutil.capture_log(['bodhi.metadata']) koji = get_session() del(koji.__untag__[:]) assert not koji.__untag__, koji.__untag__ builds = koji.listTagged('dist-f7-updates', latest=True) # Create all of the necessary database entries release = Release(name='F17', long_name='Fedora 17', id_prefix='FEDORA', dist_tag='dist-f17') package = Package(name='TurboGears') update = PackageUpdate(title='TurboGears-1.0.2.2-2.fc7', release=release, submitter=builds[0]['owner_name'], status='stable', notes='foobar', type='security') build = PackageBuild(nvr='TurboGears-1.0.2.2-2.fc7', package=package) update.addPackageBuild(build) update.assign_id() assert update.updateid ## Initialize our temporary repo temprepo = join(tempfile.mkdtemp('bodhi'), 'f7-updates') print "Inserting updateinfo into temprepo: %s" % temprepo mkmetadatadir(join(temprepo, 'i386')) repodata = join(temprepo, 'i386', 'repodata') assert exists(join(repodata, 'repomd.xml')) ## Generate the XML md = ExtendedMetadata(temprepo) ## Insert the updateinfo.xml into the repository md.insert_updateinfo() updateinfo = self.__verify_updateinfo(repodata) # Create a new non-security update for the same package newbuild = 'TurboGears-1.0.2.2-3.fc7' update = PackageUpdate(title=newbuild, release=release, submitter=builds[0]['owner_name'], status='stable', notes='foobar', type='enhancement') build = PackageBuild(nvr=newbuild, package=package) update.addPackageBuild(build) update.assign_id() koji.__untag__.append('TurboGears-1.0.2.2-2.fc7') ## Test out updateinfo.xml updating via our ExtendedMetadata md = ExtendedMetadata(temprepo, updateinfo) md.insert_updateinfo() updateinfo = self.__verify_updateinfo(repodata) ## Read an verify the updateinfo.xml.gz uinfo = UpdateMetadata() uinfo.add(updateinfo) print(testutil.get_log()) assert len(uinfo.get_notices()) == 2, len(uinfo.get_notices()) assert uinfo.get_notice(get_nvr('TurboGears-1.0.2.2-2.fc7')) notice = uinfo.get_notice(get_nvr(update.title)) assert notice, 'Cannot find update for %r' % get_nvr(update.title) assert notice['status'] == update.status assert notice['updated'] == update.date_modified assert notice['from'] == str(config.get('bodhi_email')) assert notice['description'] == update.notes assert notice['issued'] is not None assert notice['update_id'] == update.updateid ## Clean up shutil.rmtree(temprepo) del(koji.__untag__[:])
def test_extended_metadata_updating_with_edited_updates(self): testutil.capture_log(['bodhi.metadata']) # grab the name of a build in updates-testing, and create it in our db koji = get_session() builds = koji.listTagged('dist-f13-updates-testing', latest=True) # Create all of the necessary database entries release = Release(name='F13', long_name='Fedora 13', id_prefix='FEDORA', dist_tag='dist-f13') package = Package(name=builds[0]['package_name']) update = PackageUpdate(title=builds[0]['nvr'], release=release, submitter=builds[0]['owner_name'], status='testing', notes='foobar', type='bugfix') build = PackageBuild(nvr=builds[0]['nvr'], package=package) update.addPackageBuild(build) update.assign_id() ## Initialize our temporary repo temprepo = join(tempfile.mkdtemp('bodhi'), 'f13-updates-testing') print "Inserting updateinfo into temprepo: %s" % temprepo mkmetadatadir(join(temprepo, 'i386')) repodata = join(temprepo, 'i386', 'repodata') assert exists(join(repodata, 'repomd.xml')) ## Generate the XML md = ExtendedMetadata(temprepo) ## Insert the updateinfo.xml into the repository md.insert_updateinfo() updateinfo = self.__verify_updateinfo(repodata) ## Read an verify the updateinfo.xml.gz uinfo = UpdateMetadata() uinfo.add(updateinfo) notice = uinfo.get_notice(('mutt', '1.5.14', '1.fc13')) assert not notice notice = uinfo.get_notice(get_nvr(update.title)) assert notice assert notice['status'] == update.status assert notice['updated'] == update.date_modified assert notice['from'] == str(config.get('bodhi_email')) assert notice['description'] == update.notes assert notice['issued'] is not None assert notice['update_id'] == update.updateid assert notice['title'] == update.title assert notice['release'] == update.release.long_name ## Edit the update and bump the build revision nvr = 'TurboGears-1.0.2.2-3.fc7' newbuild = PackageBuild(nvr=nvr, package=package) update.removePackageBuild(build) update.addPackageBuild(newbuild) update.title = nvr update.date_modified = datetime.utcnow() # Pretend -2 was unpushed assert len(koji.__untag__) == 0 koji.__untag__.append('TurboGears-1.0.2.2-2.fc7') ## Test out updateinfo.xml updating via our ExtendedMetadata md = ExtendedMetadata(temprepo, updateinfo) md.insert_updateinfo() updateinfo = self.__verify_updateinfo(repodata) ## Read an verify the updateinfo.xml.gz uinfo = UpdateMetadata() uinfo.add(updateinfo) print(testutil.get_log()) notice = uinfo.get_notice(('TurboGears', '1.0.2.2', '2.fc7')) assert not notice, "Old TG notice did not get pruned: %s" % notice notice = uinfo.get_notice(('TurboGears', '1.0.2.2', '3.fc7')) assert notice, uinfo assert notice['title'] == update.title num_notices = len(uinfo.get_notices()) assert num_notices == 1, num_notices ## Clean up shutil.rmtree(temprepo) del(koji.__untag__[:])
def test_extended_metadata_updating_with_old_stable_security(self): testutil.capture_log(['bodhi.metadata']) koji = get_session() del (koji.__untag__[:]) assert not koji.__untag__, koji.__untag__ builds = koji.listTagged('dist-f7-updates', latest=True) # Create all of the necessary database entries release = Release(name='F17', long_name='Fedora 17', id_prefix='FEDORA', dist_tag='dist-f17') package = Package(name='TurboGears') update = PackageUpdate(title='TurboGears-1.0.2.2-2.fc7', release=release, submitter=builds[0]['owner_name'], status='stable', notes='foobar', type='security') build = PackageBuild(nvr='TurboGears-1.0.2.2-2.fc7', package=package) update.addPackageBuild(build) update.assign_id() assert update.updateid ## Initialize our temporary repo temprepo = join(tempfile.mkdtemp('bodhi'), 'f7-updates') print "Inserting updateinfo into temprepo: %s" % temprepo mkmetadatadir(join(temprepo, 'i386')) repodata = join(temprepo, 'i386', 'repodata') assert exists(join(repodata, 'repomd.xml')) ## Generate the XML md = ExtendedMetadata(temprepo) ## Insert the updateinfo.xml into the repository md.insert_updateinfo() updateinfo = self.__verify_updateinfo(repodata) # Create a new non-security update for the same package newbuild = 'TurboGears-1.0.2.2-3.fc7' update = PackageUpdate(title=newbuild, release=release, submitter=builds[0]['owner_name'], status='stable', notes='foobar', type='enhancement') build = PackageBuild(nvr=newbuild, package=package) update.addPackageBuild(build) update.assign_id() koji.__untag__.append('TurboGears-1.0.2.2-2.fc7') ## Test out updateinfo.xml updating via our ExtendedMetadata md = ExtendedMetadata(temprepo, updateinfo) md.insert_updateinfo() updateinfo = self.__verify_updateinfo(repodata) ## Read an verify the updateinfo.xml.gz uinfo = UpdateMetadata() uinfo.add(updateinfo) print(testutil.get_log()) assert len(uinfo.get_notices()) == 2, len(uinfo.get_notices()) assert uinfo.get_notice(get_nvr('TurboGears-1.0.2.2-2.fc7')) notice = uinfo.get_notice(get_nvr(update.title)) assert notice, 'Cannot find update for %r' % get_nvr(update.title) assert notice['status'] == update.status assert notice['updated'] == update.date_modified assert notice['from'] == str(config.get('bodhi_email')) assert notice['description'] == update.notes assert notice['issued'] is not None assert notice['update_id'] == update.updateid ## Clean up shutil.rmtree(temprepo) del (koji.__untag__[:])