Skip to content

Commit

Permalink
clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Dec 3, 2012
1 parent b836f38 commit 7006097
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 32 deletions.
30 changes: 6 additions & 24 deletions master/buildbot/test/unit/test_config.py
Expand Up @@ -50,7 +50,7 @@
multiMaster=False,
debugPassword=None,
manhole=None,
www=dict(port=None, url='http://localhost:8080/', public_html=None),
www=dict(port=None, url='http://localhost:8080/'),
)


Expand Down Expand Up @@ -711,35 +711,17 @@ def test_load_user_managers(self):

def test_load_www_default(self):
self.cfg.load_www(self.filename, {}, self.errors)
self.assertResults(www=dict(port=None, url='http://localhost:8080/',
public_html=None))
self.assertResults(www=dict(port=None, url='http://localhost:8080/'))

def test_load_www_port(self):
pwd = os.getcwd()
self.cfg.load_www(self.filename,
dict(www=dict(port=9888, public_html=pwd)), self.errors)
self.assertResults(www=dict(port=9888, url='http://localhost:9888/',
public_html=pwd))
dict(www=dict(port=9888)), self.errors)
self.assertResults(www=dict(port=9888, url='http://localhost:9888/'))

def test_load_www_url_no_slash(self):
pwd = os.getcwd()
self.cfg.load_www(self.filename,
dict(www=dict(url='http://foo', port=20, public_html=pwd)), self.errors)
self.assertResults(www=dict(port=20, url='http://foo/',
public_html=pwd))

def test_load_www_public_html(self):
pwd = os.getcwd()
self.cfg.load_www(self.filename,
dict(www=dict(public_html=pwd)), self.errors)
self.assertResults(www=dict(port=None, url='http://localhost:8080/',
public_html=pwd))

def test_load_www_public_html_does_not_exist(self):
self.cfg.load_www(self.filename,
dict(www=dict(public_html=r'/does/not\exist/no')),
self.errors)
self.assertConfigError(self.errors, 'must be an existing directory')
dict(www=dict(url='http://foo', port=20)), self.errors)
self.assertResults(www=dict(port=20, url='http://foo/'))


class MasterConfig_checkers(ConfigErrorsMixin, unittest.TestCase):
Expand Down
7 changes: 1 addition & 6 deletions master/buildbot/test/unit/test_www_service.py
Expand Up @@ -89,12 +89,7 @@ def test_setupSite(self):
# root
root = site.resource
req = mock.Mock()
self.assertIsInstance(root.getChildWithDefault('ui', req),
self.assertIsInstance(root.getChildWithDefault('', req),
ui.UIResource)
self.assertIsInstance(root.getChildWithDefault('api', req),
rest.RestRootResource)

# ..and that the / URI redirects properly
req = self.make_request([''])
self.render_resource(site.getResourceFor(req), request=req)
self.assertEqual(self.request.redirected_to, 'h:/ui/')
38 changes: 36 additions & 2 deletions master/buildbot/test/unit/test_www_ui.py
Expand Up @@ -13,19 +13,53 @@
#
# Copyright Buildbot Team Members

import json
import re
import buildbot
from buildbot.www import ui
from buildbot.test.util import www
from twisted.trial import unittest

class Test(www.WwwTestMixin, unittest.TestCase):
class Application:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)

def test_render(self):
master = self.make_master(url='h:/a/b/')
rsrc = ui.UIResource(master, extra_routes=[], index_html='base_url:"h:/a/b/"')
rsrc = ui.UIResource(master, {
'base' : self.Application(description='B',
version='1.0',
static_dir='/static',
packages=['pkg1', 'pkg2'],
routes=[{'name':'rt1'}]),
})

d = self.render_resource(rsrc, [''])
@d.addCallback
def check(rv):
self.assertIn('base_url:"h:/a/b/"', rv)
# extract the dojoConfig JSON and compare
mo = re.search("<script>var dojoConfig = (.*?);</script>", rv, re.S)
if not mo:
self.fail("could not find dojoConfig")
dojoConfig = json.loads(mo.group(1))
self.assertEqual(dojoConfig, {
'async': 1,
'baseUrl': 'h:/a/b',
'bb': {
'appInfo': [
{'description': 'B', 'name': 'base', 'version': '1.0'}
],
'buildbotVersion': buildbot.version,
'routes': [{'name': 'rt1'}],
'wsUrl': 'h:/a/b/ws',
},
'packages': [
{'location': 'app/base/pkg1', 'name': 'pkg1'},
{'location': 'app/base/pkg2', 'name': 'pkg2'},
],
'tlmSiblingOfDojo': 0,
})
return d

class TestGhostPy(www.WwwTestMixin,www.WwwGhostTestMixin, unittest.TestCase):
Expand Down

0 comments on commit 7006097

Please sign in to comment.