diff --git a/master/buildbot/status/web/baseweb.py b/master/buildbot/status/web/baseweb.py index 445488e2c8e..f7fd79987ef 100644 --- a/master/buildbot/status/web/baseweb.py +++ b/master/buildbot/status/web/baseweb.py @@ -451,6 +451,15 @@ def __repr__(self): return ("" % (self.http_port, self.distrib_port, hex(id(self)))) + def setUpJinja2(self): + if self.revlink: + revlink = self.revlink + else: + revlink = self.master.config.revlink + self.templates = createJinjaEnv(revlink, self.changecommentlink, + self.repositories, self.projects, + self.jinja_loaders, self.master.basedir) + def setServiceParent(self, parent): # this class keeps a *separate* link to the buildmaster, rather than # just using self.parent, so that when we are "disowned" (and thus @@ -471,14 +480,7 @@ def either(a, b): # a if a else b for py2.4 rotateLength = either(self.logRotateLength, self.master.log_rotation.rotateLength) maxRotatedFiles = either(self.maxRotatedFiles, self.master.log_rotation.maxRotatedFiles) - # Set up the jinja templating engine. - if self.revlink: - revlink = self.revlink - else: - revlink = self.master.config.revlink - self.templates = createJinjaEnv(revlink, self.changecommentlink, - self.repositories, self.projects, - self.jinja_loaders, self.master.basedir) + self.setUpJinja2() if not self.site: diff --git a/master/buildbot/test/fake/web.py b/master/buildbot/test/fake/web.py index 4614acc92e9..e1d64d89f5e 100644 --- a/master/buildbot/test/fake/web.py +++ b/master/buildbot/test/fake/web.py @@ -16,6 +16,9 @@ from StringIO import StringIO from mock import Mock +from buildbot.status.web import baseweb +from buildbot.test.fake import fakemaster + from twisted.internet import defer from twisted.web import server @@ -34,13 +37,19 @@ class FakeRequest(Mock): failure = None def __init__(self, args={}, content=''): - Mock.__init__(self) + Mock.__init__(self, spec=server.Request) self.args = args self.content = StringIO(content) - self.site = Mock() - self.site.buildbot_service = Mock() - master = self.site.buildbot_service.master = Mock() + self.site = Mock(spec=server.Site) + webstatus = baseweb.WebStatus(site=self.site) + self.site.buildbot_service = webstatus + self.uri = '/' + self.prepath = [] + self.method = 'GET' + master = webstatus.master = fakemaster.make_master() + + webstatus.setUpJinja2() self.addedChanges = [] diff --git a/master/buildbot/test/integration/test_new_style_steps.py b/master/buildbot/test/integration/test_new_style_steps.py new file mode 100644 index 00000000000..d60c691ff82 --- /dev/null +++ b/master/buildbot/test/integration/test_new_style_steps.py @@ -0,0 +1,55 @@ +# This file is part of Buildbot. Buildbot is free software: you can +# redistribute it and/or modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation, version 2. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Copyright Buildbot Team Members + +from buildbot.process import buildstep +from buildbot.status import results +from buildbot.status.web import logs +from buildbot.test.fake.web import FakeRequest +from buildbot.test.util import steps +from twisted.internet import defer +from twisted.trial import unittest + + +class NewStyleStep(buildstep.BuildStep): + + @defer.inlineCallbacks + def run(self): + stdio = yield self.addLog('stdio') + yield stdio.addStdout(u'Some stdout content\n') + defer.returnValue(results.SUCCESS) + + +class TestNewStyleSteps(steps.BuildStepIntegrationMixin, unittest.TestCase): + + # New-style steps in eight have had a rocky start, as they are littered + # with assertions about old methods, but those methods are still used + # elsewhere in Buildbot. These tests try to replicate the conditions in an + # integrated fashion to flush out any similar errors." + + def setUp(self): + return self.setUpBuildStepIntegration() + + def tearDown(self): + return self.tearDownBuildStepIntegration() + + @defer.inlineCallbacks + def test_render_new_style_logs(self): # bug 2930 + self.setupStep(NewStyleStep()) + bs = yield self.runStep() + + # now try to render it in the WebStatus + log_rsrc = logs.TextLog(bs.getSteps()[0].getLogs()[0]) + request = FakeRequest() + yield request.test_render(log_rsrc)