Mercurial > bitten > bitten-test
changeset 320:a8b713254286
Fixes for compatibility with Trac trunk and 0.9.3.
author | cmlenz |
---|---|
date | Wed, 04 Jan 2006 18:30:52 +0000 |
parents | cd95e1c6e648 |
children | 8e8d40d50001 |
files | bitten/tests/model.py bitten/tests/queue.py bitten/tests/snapshot.py bitten/trac_ext/compat.py bitten/trac_ext/summarizers.py bitten/trac_ext/tests/charts.py bitten/trac_ext/tests/web_ui.py bitten/trac_ext/web_ui.py bitten/upgrades.py setup.py |
diffstat | 10 files changed, 97 insertions(+), 63 deletions(-) [+] |
line wrap: on
line diff
--- a/bitten/tests/model.py +++ b/bitten/tests/model.py @@ -12,16 +12,18 @@ from trac.test import EnvironmentStub from bitten.model import BuildConfig, TargetPlatform, Build, BuildStep, \ BuildLog, Report, schema +from bitten.trac_ext.compat import schema_to_sql class BuildConfigTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() + self.env.path = '' db = self.env.get_db_cnx() cursor = db.cursor() for table in schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) db.commit() @@ -153,10 +155,11 @@ def setUp(self): self.env = EnvironmentStub() + self.env.path = '' db = self.env.get_db_cnx() cursor = db.cursor() for table in TargetPlatform._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) db.commit() @@ -207,10 +210,11 @@ def setUp(self): self.env = EnvironmentStub() + self.env.path = '' db = self.env.get_db_cnx() cursor = db.cursor() for table in Build._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) db.commit() @@ -313,10 +317,11 @@ def setUp(self): self.env = EnvironmentStub() + self.env.path = '' db = self.env.get_db_cnx() cursor = db.cursor() for table in BuildStep._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) db.commit() @@ -412,10 +417,11 @@ def setUp(self): self.env = EnvironmentStub() + self.env.path = '' db = self.env.get_db_cnx() cursor = db.cursor() for table in BuildLog._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) db.commit() @@ -526,10 +532,11 @@ def setUp(self): self.env = EnvironmentStub() + self.env.path = '' db = self.env.get_db_cnx() cursor = db.cursor() for table in Report._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) db.commit()
--- a/bitten/tests/queue.py +++ b/bitten/tests/queue.py @@ -15,6 +15,7 @@ from trac.test import EnvironmentStub, Mock from bitten.model import BuildConfig, TargetPlatform, Build, BuildStep, schema from bitten.queue import BuildQueue, collect_changes +from bitten.trac_ext.compat import schema_to_sql class CollectChangesTestCase(unittest.TestCase): @@ -28,7 +29,7 @@ db = self.env.get_db_cnx() cursor = db.cursor() for table in schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) self.config = BuildConfig(self.env, name='test', path='somepath') self.config.insert(db=db) @@ -124,7 +125,7 @@ db = self.env.get_db_cnx() cursor = db.cursor() for table in schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) db.commit()
--- a/bitten/tests/snapshot.py +++ b/bitten/tests/snapshot.py @@ -17,6 +17,7 @@ from trac.test import EnvironmentStub, Mock from bitten.model import BuildConfig from bitten.snapshot import SnapshotManager +from bitten.trac_ext.compat import schema_to_sql from bitten.util import md5sum @@ -29,7 +30,7 @@ db = self.env.get_db_cnx() cursor = db.cursor() for table in BuildConfig._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) db.commit() self.config = BuildConfig(self.env, name='foo', path='trunk')
new file mode 100644 --- /dev/null +++ b/bitten/trac_ext/compat.py @@ -0,0 +1,20 @@ +# -*- coding: iso8859-1 -*- +# +# Copyright (C) 2006 Christopher Lenz <cmlenz@gmx.de> +# All rights reserved. +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at http://bitten.cmlenz.net/wiki/License. + +"""Various methods for backwards compatibility with older Trac versions.""" + +def schema_to_sql(env, db, table): + try: + # Trac >= 0.10 + from trac.db import DatabaseManager + connector, _ = DatabaseManager(env)._get_connector() + return connector.to_sql(table) + except ImportError: + # Trac 0.9.x + return db.to_sql(table)
--- a/bitten/trac_ext/summarizers.py +++ b/bitten/trac_ext/summarizers.py @@ -61,7 +61,7 @@ hdf = HDFWrapper(loadpaths=Chrome(self.env).get_all_templates_dirs()) hdf['data'] = data hdf['totals'] = {'success': total_success, 'failure': total_failure, - 'error': total_error} + 'error': total_error} return hdf.render('bitten_summary_tests.cs')
--- a/bitten/trac_ext/tests/charts.py +++ b/bitten/trac_ext/tests/charts.py @@ -13,16 +13,18 @@ from trac.web.clearsilver import HDFWrapper from bitten.model import * from bitten.trac_ext.charts import * +from bitten.trac_ext.compat import schema_to_sql class TestResultsChartGeneratorTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() + self.env.path = '' db = self.env.get_db_cnx() cursor = db.cursor() for table in schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) def test_supported_categories(self): @@ -98,10 +100,11 @@ def setUp(self): self.env = EnvironmentStub() + self.env.path = '' db = self.env.get_db_cnx() cursor = db.cursor() for table in schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) def test_supported_categories(self):
--- a/bitten/trac_ext/tests/web_ui.py +++ b/bitten/trac_ext/tests/web_ui.py @@ -18,6 +18,7 @@ from trac.web.clearsilver import HDFWrapper from trac.web.main import Request, RequestDone from bitten.model import BuildConfig, TargetPlatform, Build, schema +from bitten.trac_ext.compat import schema_to_sql from bitten.trac_ext.main import BuildSystem from bitten.trac_ext.web_ui import BuildConfigController @@ -32,7 +33,7 @@ db = self.env.get_db_cnx() cursor = db.cursor() for table in schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) # Set up permissions
--- a/bitten/trac_ext/web_ui.py +++ b/bitten/trac_ext/web_ui.py @@ -21,7 +21,7 @@ import pkg_resources from trac.core import * from trac.Timeline import ITimelineEventProvider -from trac.util import escape, pretty_timedelta, format_datetime, shorten_line +from trac.util import pretty_timedelta, format_datetime, shorten_line, Markup from trac.web import IRequestHandler from trac.web.chrome import INavigationContributor, ITemplateProvider, \ add_link, add_stylesheet @@ -66,23 +66,7 @@ class BittenChrome(Component): """Provides the Bitten templates and static resources.""" - implements(ITemplateProvider) - - # ITemplatesProvider methods - - def get_htdocs_dirs(self): - """Return the directories containing static resources.""" - return [('bitten', pkg_resources.resource_filename(__name__, 'htdocs'))] - - def get_templates_dirs(self): - """Return the directories containing templates.""" - return [pkg_resources.resource_filename(__name__, 'templates')] - - -class BuildConfigController(Component): - """Implements the web interface for build configurations.""" - - implements(INavigationContributor, IRequestHandler) + implements(INavigationContributor, ITemplateProvider) # INavigationContributor methods @@ -99,9 +83,25 @@ the Trac navigation bar.""" if not req.perm.has_permission('BUILD_VIEW'): return - yield 'mainnav', 'build', \ - '<a href="%s" accesskey="5">Build Status</a>' \ - % self.env.href.build() + yield ('mainnav', 'build', \ + Markup('<a href="%s" accesskey="5">Build Status</a>', + self.env.href.build())) + + # ITemplatesProvider methods + + def get_htdocs_dirs(self): + """Return the directories containing static resources.""" + return [('bitten', pkg_resources.resource_filename(__name__, 'htdocs'))] + + def get_templates_dirs(self): + """Return the directories containing templates.""" + return [pkg_resources.resource_filename(__name__, 'templates')] + + +class BuildConfigController(Component): + """Implements the web interface for build configurations.""" + + implements(IRequestHandler) # IRequestHandler methods @@ -367,7 +367,7 @@ chgset = repos.get_changeset(rev) req.hdf[prefix + '.youngest_rev'] = { 'id': rev, 'href': self.env.href.changeset(rev), - 'author': escape(chgset.author) or 'anonymous', + 'author': chgset.author or 'anonymous', 'date': format_datetime(chgset.date), 'message': wiki_to_oneliner( shorten_line(chgset.message), self.env) @@ -377,11 +377,11 @@ prev_rev = rev if build: build_hdf = _build_to_hdf(self.env, req, build) - build_hdf['platform'] = escape(platform.name) + build_hdf['platform'] = platform.name req.hdf[prefix + '.builds.%d' % platform.id] = build_hdf else: req.hdf[prefix + '.builds.%d' % platform.id] = { - 'platform': escape(platform.name), 'status': 'pending' + 'platform': platform.name, 'status': 'pending' } req.hdf['page.mode'] = 'overview' @@ -392,7 +392,7 @@ config = BuildConfig.fetch(self.env, config_name, db=db) req.hdf['title'] = 'Build Configuration "%s"' \ - % escape(config.label or config.name) + % config.label or config.name add_link(req, 'up', self.env.href.build(), 'Build Status') description = config.description if description: @@ -428,7 +428,7 @@ ] charts_license = self.config.get('bitten', 'charts_license') if charts_license: - req.hdf['config.charts_license'] = escape(charts_license) + req.hdf['config.charts_license'] = charts_license page = max(1, int(req.args.get('page', 1))) more = False @@ -452,7 +452,7 @@ db=db): req.hdf['%s.%s.steps.%s' % (prefix, platform.id, step.name)] = { - 'description': escape(step.description), + 'description': step.description, 'duration': datetime.fromtimestamp(step.stopped) - \ datetime.fromtimestamp(step.started), 'failed': not step.successful, @@ -475,7 +475,7 @@ req.perm.assert_permission('BUILD_DELETE') config = BuildConfig.fetch(self.env, config_name) req.hdf['title'] = 'Delete Build Configuration "%s"' \ - % escape(config.label or config.name) + % config.label or config.name req.hdf['config'] = {'name': config.name} req.hdf['page.mode'] = 'delete_config' @@ -492,7 +492,7 @@ } req.hdf['title'] = 'Edit Build Configuration "%s"' \ - % escape(config.label or config.name) + % config.label or config.name for idx, platform in enumerate(TargetPlatform.select(self.env, config_name)): req.hdf['config.platforms.%d' % idx] = { @@ -508,8 +508,7 @@ def _render_platform_form(self, req, platform): req.perm.assert_permission('BUILD_MODIFY') if platform.exists: - req.hdf['title'] = 'Edit Target Platform "%s"' \ - % escape(platform.name) + req.hdf['title'] = 'Edit Target Platform "%s"' % platform.name else: req.hdf['title'] = 'Add Target Platform' req.hdf['platform'] = { @@ -634,12 +633,11 @@ for step in BuildStep.select(self.env, build=id, status=BuildStep.FAILURE, db=db): - errors += [(escape(step.name), escape(error)) for error + errors += [(step.name, error) for error in step.errors] - title = 'Build of <em>%s [%s]</em> on %s %s' \ - % (escape(label), escape(rev), escape(platform), - _status_label[status]) + title = Markup('Build of <em>%s [%s]</em> on %s %s', label, rev, + platform, _status_label[status]) message = '' if req.args.get('format') == 'rss': href = self.env.abs_href.build(config, id) @@ -652,9 +650,9 @@ buf.write('</ul>') buf.write('<p>Step %s failed:</p><ul>' % step) prev_step = step - buf.write('<li>%s</li>' % escape(error)) + buf.write('<li>%s</li>' % error) buf.write('</ul>') - message = buf.getvalue() + message = Markup(buf.getvalue()) else: href = self.env.href.build(config, id) if errors: @@ -662,16 +660,16 @@ for step, error in errors: if step not in steps: steps.append(step) - steps = ['<em>%s</em>' % step for step in steps] + steps = [Markup('<em>%s</em>', step) for step in steps] if len(steps) < 2: message = steps[0] elif len(steps) == 2: - message = ' and '.join(steps) + message = Markup(' and ').join(steps) elif len(steps) > 2: - message = ', '.join(steps[:-1]) + ', and ' + \ + message = Markup(', ').join(steps[:-1]) + ', and ' + \ steps[-1] - message = 'Step%s ' % (len(steps) != 1 and 's' or '') \ - + message + ' failed' + message = Markup('Step%s %s failed', + len(steps) != 1 and 's' or '', message) yield event_kinds[status], href, title, stopped, None, message # Internal methods @@ -710,7 +708,8 @@ report.category) else: summary = None - reports.append({'category': report.category, 'summary': summary}) + reports.append({'category': report.category, + 'summary': Markup(summary)}) return reports
--- a/bitten/upgrades.py +++ b/bitten/upgrades.py @@ -13,13 +13,15 @@ import os import sys +from bitten.trac_ext.compat import schemaschema_to_sql + def add_log_table(env, db): """Add a table for storing the builds logs.""" from bitten.model import BuildLog, BuildStep cursor = db.cursor() for table in BuildLog._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(env, db, table): cursor.execute(stmt) cursor.execute("SELECT build,name,log FROM bitten_step " @@ -32,7 +34,7 @@ cursor.execute("CREATE TEMP TABLE old_step AS SELECT * FROM bitten_step") cursor.execute("DROP TABLE bitten_step") for table in BuildStep._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(env, db, table): cursor.execute(stmt) cursor.execute("INSERT INTO bitten_step (build,name,description,status," "started,stopped) SELECT build,name,description,status," @@ -49,7 +51,7 @@ "SELECT * FROM bitten_config") cursor.execute("DROP TABLE bitten_config") for table in BuildConfig._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(env, db, table): cursor.execute(stmt) cursor.execute("INSERT INTO bitten_config (name,path,active,recipe,min_rev," "max_rev,label,description) SELECT name,path,0,'',NULL," @@ -109,7 +111,7 @@ cursor.execute("CREATE TEMP TABLE old_log AS " "SELECT * FROM bitten_log") cursor.execute("DROP TABLE bitten_log") - for stmt in db.to_sql(BuildLog._schema[0]): + for stmt in schema_to_sql(env, db, BuildLog._schema[0]): cursor.execute(stmt) cursor.execute("INSERT INTO bitten_log (id,build,step,generator,orderno) " "SELECT id,build,step,type,0 FROM old_log") @@ -120,7 +122,7 @@ cursor = db.cursor() for table in Report._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(env, db, table): cursor.execute(stmt) def xmldb_to_db(env, db): @@ -264,7 +266,7 @@ Column('orderno', type='int') ] cursor = db.cursor() - for stmt in db.to_sql(table): + for stmt in schema_to_sql(env, db, table): cursor.execute(stmt) map = {
--- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ description='Framework for collecting software metrics via continuous ' 'integration', license='BSD', - packages=find_packages(exclude=['ez_setup', '*.tests*']), + packages=find_packages(exclude=['*.tests*']), package_data={ 'bitten.trac_ext': ['htdocs/*.*', 'htdocs/charts_library/*.swf',