| OLD | NEW |
| (Empty) |
| 1 | |
| 2 import os | |
| 3 from twisted.trial import unittest | |
| 4 from twisted.internet import defer | |
| 5 from twisted.web import client | |
| 6 from twisted.web.error import Error as WebError | |
| 7 from buildbot.slave.commands import rmdirRecursive | |
| 8 from buildbot.status import html | |
| 9 from test_web import BaseWeb, base_config, ConfiguredMaster | |
| 10 from buildbot.scripts import runner | |
| 11 | |
| 12 class Webparts(BaseWeb, unittest.TestCase): | |
| 13 | |
| 14 def find_webstatus(self, master): | |
| 15 return filter(lambda child: isinstance(child, html.WebStatus), | |
| 16 list(master)) | |
| 17 | |
| 18 def startMaster(self, extraconfig): | |
| 19 config = base_config + extraconfig | |
| 20 rmdirRecursive("test_webparts") | |
| 21 os.mkdir("test_webparts") | |
| 22 runner.upgradeMaster({'basedir': "test_webparts", | |
| 23 'quiet': True, | |
| 24 }) | |
| 25 self.master = m = ConfiguredMaster("test_webparts", config) | |
| 26 m.startService() | |
| 27 # hack to find out what randomly-assigned port it is listening on | |
| 28 port = list(self.find_webstatus(m)[0])[0]._port.getHost().port | |
| 29 self.baseurl = "http://localhost:%d/" % port | |
| 30 | |
| 31 def reconfigMaster(self, extraconfig): | |
| 32 config = base_config + extraconfig | |
| 33 d = self.master.loadConfig(config) | |
| 34 def _done(res): | |
| 35 m = self.master | |
| 36 port = list(self.find_webstatus(m)[0])[0]._port.getHost().port | |
| 37 self.baseurl = "http://localhost:%d/" % port | |
| 38 d.addCallback(_done) | |
| 39 return d | |
| 40 | |
| 41 def getAndCheck(self, url, substring, show=False): | |
| 42 d = client.getPage(url) | |
| 43 def _show_weberror(why): | |
| 44 why.trap(WebError) | |
| 45 self.fail("error for %s: %s" % (url, why)) | |
| 46 d.addErrback(_show_weberror) | |
| 47 d.addCallback(self._getAndCheck, substring, show) | |
| 48 return d | |
| 49 def _getAndCheck(self, page, substring, show): | |
| 50 if show: | |
| 51 print page | |
| 52 self.failUnlessIn(substring, page, | |
| 53 "Couldn't find substring '%s' in page:\n%s" % | |
| 54 (substring, page)) | |
| 55 | |
| 56 def testInit(self): | |
| 57 extraconfig = """ | |
| 58 from twisted.web import static | |
| 59 ws = html.WebStatus(http_port=0) | |
| 60 c['status'] = [ws] | |
| 61 ws.putChild('child.html', static.Data('I am the child', 'text/plain')) | |
| 62 """ | |
| 63 self.startMaster(extraconfig) | |
| 64 d = self.getAndCheck(self.baseurl + "child.html", | |
| 65 "I am the child") | |
| 66 return d | |
| 67 testInit.timeout = 10 | |
| 68 | |
| 69 def testStatic(self): | |
| 70 extraconfig = """ | |
| 71 from twisted.web import static | |
| 72 ws = html.WebStatus(http_port=0) | |
| 73 c['status'] = [ws] | |
| 74 ws.putChild('child.html', static.Data('I am the child', 'text/plain')) | |
| 75 """ | |
| 76 self.startMaster(extraconfig) | |
| 77 os.mkdir(os.path.join("test_webparts", "public_html", "subdir")) | |
| 78 f = open(os.path.join("test_webparts", "public_html", "foo.html"), "wt") | |
| 79 f.write("see me foo\n") | |
| 80 f.close() | |
| 81 f = open(os.path.join("test_webparts", "public_html", "subdir", | |
| 82 "bar.html"), "wt") | |
| 83 f.write("see me subdir/bar\n") | |
| 84 f.close() | |
| 85 d = self.getAndCheck(self.baseurl + "child.html", "I am the child") | |
| 86 d.addCallback(lambda res: | |
| 87 self.getAndCheck(self.baseurl+"foo.html", | |
| 88 "see me foo")) | |
| 89 d.addCallback(lambda res: | |
| 90 self.getAndCheck(self.baseurl+"subdir/bar.html", | |
| 91 "see me subdir/bar")) | |
| 92 return d | |
| 93 | |
| 94 def _check(self, res, suburl, substring, show=False): | |
| 95 d = self.getAndCheck(self.baseurl + suburl, substring, show) | |
| 96 return d | |
| 97 | |
| 98 def testPages(self): | |
| 99 extraconfig = """ | |
| 100 ws = html.WebStatus(http_port=0) | |
| 101 c['status'] = [ws] | |
| 102 """ | |
| 103 self.startMaster(extraconfig) | |
| 104 d = defer.succeed(None) | |
| 105 d.addCallback(self._do_page_tests) | |
| 106 extraconfig2 = """ | |
| 107 ws = html.WebStatus(http_port=0, allowForce=True) | |
| 108 c['status'] = [ws] | |
| 109 """ | |
| 110 d.addCallback(lambda res: self.reconfigMaster(extraconfig2)) | |
| 111 d.addCallback(self._do_page_tests) | |
| 112 return d | |
| 113 | |
| 114 def _do_page_tests(self, res): | |
| 115 d = defer.succeed(None) | |
| 116 d.addCallback(self._check, "", "Welcome to the Buildbot") | |
| 117 d.addCallback(self._check, "waterfall", "current activity") | |
| 118 d.addCallback(self._check, "about", "Buildbot is a free software") | |
| 119 d.addCallback(self._check, "changes", "PBChangeSource listener") | |
| 120 d.addCallback(self._check, "buildslaves", "Build Slaves") | |
| 121 d.addCallback(self._check, "one_line_per_build", | |
| 122 "Last 20 finished builds") | |
| 123 d.addCallback(self._check, "one_box_per_builder", "Latest builds") | |
| 124 d.addCallback(self._check, "builders", "Builders") | |
| 125 d.addCallback(self._check, "builders/builder1", "Builder: builder1") | |
| 126 d.addCallback(self._check, "builders/builder1/builds", "") # dummy | |
| 127 # TODO: the pages beyond here would be great to test, but that would | |
| 128 # require causing a build to complete. | |
| 129 #d.addCallback(self._check, "builders/builder1/builds/1", "") | |
| 130 # it'd be nice to assert that the Build page has a "Stop Build" button | |
| 131 #d.addCallback(self._check, "builders/builder1/builds/1/steps", "") | |
| 132 #d.addCallback(self._check, | |
| 133 # "builders/builder1/builds/1/steps/compile", "") | |
| 134 #d.addCallback(self._check, | |
| 135 # "builders/builder1/builds/1/steps/compile/logs", "") | |
| 136 #d.addCallback(self._check, | |
| 137 # "builders/builder1/builds/1/steps/compile/logs/stdio","") | |
| 138 #d.addCallback(self._check, | |
| 139 # "builders/builder1/builds/1/steps/compile/logs/stdio/text
", "") | |
| 140 return d | |
| 141 | |
| OLD | NEW |