Mercurial > bitten > bitten-test
changeset 824:a4676056c8d3
Changed notification to always use Genshi `NewTextTemplate` which lets us keep just one template for both Trac 0.11 and 0.12+.
author | osimons |
---|---|
date | Thu, 16 Sep 2010 13:01:17 +0000 |
parents | 172826bf87ac |
children | 77c3de8f5c46 |
files | bitten/notify.py bitten/templates/bitten_notify_email.txt bitten/tests/notify.py |
diffstat | 3 files changed, 18 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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>
--- 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('<http://example.org/trac.cgi/changeset/123>' in output) + # TODO functional tests of generated mails