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
12 class Webparts(BaseWeb
, unittest
.TestCase
):
14 def find_webstatus(self
, master
):
15 return filter(lambda child
: isinstance(child
, html
.WebStatus
),
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",
25 self
.master
= m
= ConfiguredMaster("test_webparts", config
)
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
31 def reconfigMaster(self
, extraconfig
):
32 config
= base_config
+ extraconfig
33 d
= self
.master
.loadConfig(config
)
36 port
= list(self
.find_webstatus(m
)[0])[0]._port
.getHost().port
37 self
.baseurl
= "http://localhost:%d/" % port
41 def getAndCheck(self
, url
, substring
, show
=False):
42 d
= client
.getPage(url
)
43 def _show_weberror(why
):
45 self
.fail("error for %s: %s" % (url
, why
))
46 d
.addErrback(_show_weberror
)
47 d
.addCallback(self
._getAndCheck
, substring
, show
)
49 def _getAndCheck(self
, page
, substring
, show
):
52 self
.failUnlessIn(substring
, page
,
53 "Couldn't find substring '%s' in page:\n%s" %
58 from twisted.web import static
59 ws = html.WebStatus(http_port=0)
61 ws.putChild('child.html', static.Data('I am the child', 'text/plain'))
63 self
.startMaster(extraconfig
)
64 d
= self
.getAndCheck(self
.baseurl
+ "child.html",
71 from twisted.web import static
72 ws = html.WebStatus(http_port=0)
74 ws.putChild('child.html', static.Data('I am the child', 'text/plain'))
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")
81 f
= open(os
.path
.join("test_webparts", "public_html", "subdir",
83 f
.write("see me subdir/bar\n")
85 d
= self
.getAndCheck(self
.baseurl
+ "child.html", "I am the child")
86 d
.addCallback(lambda res
:
87 self
.getAndCheck(self
.baseurl
+"foo.html",
89 d
.addCallback(lambda res
:
90 self
.getAndCheck(self
.baseurl
+"subdir/bar.html",
94 def _check(self
, res
, suburl
, substring
, show
=False):
95 d
= self
.getAndCheck(self
.baseurl
+ suburl
, substring
, show
)
100 ws = html.WebStatus(http_port=0)
103 self
.startMaster(extraconfig
)
104 d
= defer
.succeed(None)
105 d
.addCallback(self
._do
_page
_tests
)
107 ws = html.WebStatus(http_port=0, allowForce=True)
110 d
.addCallback(lambda res
: self
.reconfigMaster(extraconfig2
))
111 d
.addCallback(self
._do
_page
_tests
)
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", "")