Skip to content

Commit

Permalink
add an integration test that renders a new-style step
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Oct 12, 2014
1 parent 6c1361b commit 518522e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 12 deletions.
18 changes: 10 additions & 8 deletions master/buildbot/status/web/baseweb.py
Expand Up @@ -451,6 +451,15 @@ def __repr__(self):
return ("<WebStatus on port %s and path %s at %s>" %
(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
Expand All @@ -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:

Expand Down
17 changes: 13 additions & 4 deletions master/buildbot/test/fake/web.py
Expand Up @@ -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

Expand All @@ -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 = []

Expand Down
55 changes: 55 additions & 0 deletions 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)

0 comments on commit 518522e

Please sign in to comment.