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 getAndCheck(self
, url
, substring
, show
=False):
32 d
= client
.getPage(url
)
33 def _show_weberror(why
):
35 self
.fail("error for %s: %s" % (url
, why
))
36 d
.addErrback(_show_weberror
)
37 d
.addCallback(self
._getAndCheck
, substring
, show
)
39 def _getAndCheck(self
, page
, substring
, show
):
42 self
.failUnlessIn(substring
, page
,
43 "Couldn't find substring '%s' in page:\n%s" %
48 from twisted.web import static
49 ws = html.WebStatus(http_port=0)
51 ws.putChild('child.html', static.Data('I am the child', 'text/plain'))
53 self
.startMaster(extraconfig
)
54 d
= self
.getAndCheck(self
.baseurl
+ "child.html",
61 from twisted.web import static
62 ws = html.WebStatus(http_port=0)
64 ws.putChild('child.html', static.Data('I am the child', 'text/plain'))
66 self
.startMaster(extraconfig
)
67 os
.mkdir(os
.path
.join("test_webparts", "public_html", "subdir"))
68 f
= open(os
.path
.join("test_webparts", "public_html", "foo.html"), "wt")
69 f
.write("see me foo\n")
71 f
= open(os
.path
.join("test_webparts", "public_html", "subdir",
73 f
.write("see me subdir/bar\n")
75 d
= self
.getAndCheck(self
.baseurl
+ "child.html", "I am the child")
76 d
.addCallback(lambda res
:
77 self
.getAndCheck(self
.baseurl
+"foo.html",
79 d
.addCallback(lambda res
:
80 self
.getAndCheck(self
.baseurl
+"subdir/bar.html",
84 def _check(self
, res
, suburl
, substring
, show
=False):
85 d
= self
.getAndCheck(self
.baseurl
+ suburl
, substring
, show
)
90 ws = html.WebStatus(http_port=0)
93 self
.startMaster(extraconfig
)
94 d
= defer
.succeed(None)
95 d
.addCallback(self
._check
, "", "Welcome to the Buildbot")
96 d
.addCallback(self
._check
, "waterfall", "current activity")
97 d
.addCallback(self
._check
, "about", "Buildbot is a free software")
98 d
.addCallback(self
._check
, "changes", "PBChangeSource listener")
99 d
.addCallback(self
._check
, "buildslaves", "Build Slaves")
100 d
.addCallback(self
._check
, "one_line_per_build",
101 "Last 20 finished builds")
102 d
.addCallback(self
._check
, "one_box_per_builder", "Latest builds")
103 d
.addCallback(self
._check
, "builders", "Builders")
104 d
.addCallback(self
._check
, "builders/builder1", "Builder: builder1")
105 d
.addCallback(self
._check
, "builders/builder1/builds", "") # dummy
106 # TODO: the pages beyond here would be great to test, but that would
107 # require causing a build to complete.
108 #d.addCallback(self._check, "builders/builder1/builds/1", "")
109 #d.addCallback(self._check, "builders/builder1/builds/1/steps", "")
110 #d.addCallback(self._check,
111 # "builders/builder1/builds/1/steps/compile", "")
112 #d.addCallback(self._check,
113 # "builders/builder1/builds/1/steps/compile/logs", "")
114 #d.addCallback(self._check,
115 # "builders/builder1/builds/1/steps/compile/logs/stdio","")
116 #d.addCallback(self._check,
117 # "builders/builder1/builds/1/steps/compile/logs/stdio/text", "")