# HG changeset patch # User osimons # Date 1284642077 0 # Node ID a4676056c8d3f6986f1ee51ce49eea62811c3c41 # Parent 172826bf87ac480e4c1dc776a9ef40fa2388b98a Changed notification to always use Genshi `NewTextTemplate` which lets us keep just one template for both Trac 0.11 and 0.12+. diff --git a/bitten/notify.py b/bitten/notify.py --- a/bitten/notify.py +++ b/bitten/notify.py @@ -6,8 +6,9 @@ # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. +from genshi.template.text import NewTextTemplate from trac.core import Component, implements -from trac.web.chrome import ITemplateProvider +from trac.web.chrome import ITemplateProvider, Chrome from trac.config import BoolOption from trac.notification import NotifyEmail from bitten.api import IBuildListener @@ -90,6 +91,10 @@ def __init__(self, env): NotifyEmail.__init__(self, env) + # Override the template type to always use NewTextTemplate + if not isinstance(self.template, NewTextTemplate): + self.template = Chrome(env).templates.load( + self.template.filepath, cls=NewTextTemplate) def notify(self, build): self.build = build diff --git a/bitten/templates/bitten_notify_email.txt b/bitten/templates/bitten_notify_email.txt --- a/bitten/templates/bitten_notify_email.txt +++ b/bitten/templates/bitten_notify_email.txt @@ -7,18 +7,18 @@ Build Configuration: $build.config Build Slave: $build.slave Build Number: $build.id - <${build.link}> -#if build.failed_steps +{% if build.failed_steps %}\ Failures: -#for step in build.failed_steps +{% for step in build.failed_steps %}\ Step: $step.name Errors: ${', '.join(step.errors)} Log: - #for lvl, msg in step.log_messages +{% for lvl, msg in step.log_messages %}\ [${lvl.upper().ljust(8)}] $msg - #end -#end -#end +{% end for %}\ +{% end for %}\ +{% end if %}\ -- Build URL: <$build.link> diff --git a/bitten/tests/notify.py b/bitten/tests/notify.py --- a/bitten/tests/notify.py +++ b/bitten/tests/notify.py @@ -83,6 +83,12 @@ self.assertTrue('author' in self.notifications_sent_to, 'Recipient list should contain the author') + def test_notification_body_render(self): + self.email.notify(self.build) + output = self.email.template.generate(**self.email.data).render('text') + self.assertTrue('Successful build of My Project [123]' in output) + self.assertTrue('' in output) + # TODO functional tests of generated mails