Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/buildbot/buildbot/test/test_webparts.py
blob: 71dd59e367522092e071d909f70b01555f6e88fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141

import os
from twisted.trial import unittest
from twisted.internet import defer
from twisted.web import client
from twisted.web.error import Error as WebError
from buildbot.slave.commands import rmdirRecursive
from buildbot.status import html
from test_web import BaseWeb, base_config, ConfiguredMaster
from buildbot.scripts import runner

class Webparts(BaseWeb, unittest.TestCase):

    def find_webstatus(self, master):
        return filter(lambda child: isinstance(child, html.WebStatus),
                      list(master))

    def startMaster(self, extraconfig):
        config = base_config + extraconfig
        rmdirRecursive("test_webparts")
        os.mkdir("test_webparts")
        runner.upgradeMaster({'basedir': "test_webparts",
                              'quiet': True,
                              })
        self.master = m = ConfiguredMaster("test_webparts", config)
        m.startService()
        # hack to find out what randomly-assigned port it is listening on
        port = list(self.find_webstatus(m)[0])[0]._port.getHost().port
        self.baseurl = "http://localhost:%d/" % port

    def reconfigMaster(self, extraconfig):
        config = base_config + extraconfig
        d = self.master.loadConfig(config)
        def _done(res):
            m = self.master
            port = list(self.find_webstatus(m)[0])[0]._port.getHost().port
            self.baseurl = "http://localhost:%d/" % port
        d.addCallback(_done)
        return d

    def getAndCheck(self, url, substring, show=False):
        d = client.getPage(url)
        def _show_weberror(why):
            why.trap(WebError)
            self.fail("error for %s: %s" % (url, why))
        d.addErrback(_show_weberror)
        d.addCallback(self._getAndCheck, substring, show)
        return d
    def _getAndCheck(self, page, substring, show):
        if show:
            print page
        self.failUnlessIn(substring, page,
                          "Couldn't find substring '%s' in page:\n%s" %
                          (substring, page))

    def testInit(self):
        extraconfig = """
from twisted.web import static
ws = html.WebStatus(http_port=0)
c['status'] = [ws]
ws.putChild('child.html', static.Data('I am the child', 'text/plain'))
"""
        self.startMaster(extraconfig)
        d = self.getAndCheck(self.baseurl + "child.html",
                             "I am the child")
        return d
    testInit.timeout = 10

    def testStatic(self):
        extraconfig = """
from twisted.web import static
ws = html.WebStatus(http_port=0)
c['status'] = [ws]
ws.putChild('child.html', static.Data('I am the child', 'text/plain'))
"""
        self.startMaster(extraconfig)
        os.mkdir(os.path.join("test_webparts", "public_html", "subdir"))
        f = open(os.path.join("test_webparts", "public_html", "foo.html"), "wt")
        f.write("see me foo\n")
        f.close()
        f = open(os.path.join("test_webparts", "public_html", "subdir",
                              "bar.html"), "wt")
        f.write("see me subdir/bar\n")
        f.close()
        d = self.getAndCheck(self.baseurl + "child.html", "I am the child")
        d.addCallback(lambda res:
                      self.getAndCheck(self.baseurl+"foo.html",
                                       "see me foo"))
        d.addCallback(lambda res:
                      self.getAndCheck(self.baseurl+"subdir/bar.html",
                                       "see me subdir/bar"))
        return d

    def _check(self, res, suburl, substring, show=False):
        d = self.getAndCheck(self.baseurl + suburl, substring, show)
        return d

    def testPages(self):
        extraconfig = """
ws = html.WebStatus(http_port=0)
c['status'] = [ws]
"""
        self.startMaster(extraconfig)
        d = defer.succeed(None)
        d.addCallback(self._do_page_tests)
        extraconfig2 = """
ws = html.WebStatus(http_port=0, allowForce=True)
c['status'] = [ws]
"""
        d.addCallback(lambda res: self.reconfigMaster(extraconfig2))
        d.addCallback(self._do_page_tests)
        return d

    def _do_page_tests(self, res):
        d = defer.succeed(None)
        d.addCallback(self._check, "", "Welcome to the Buildbot")
        d.addCallback(self._check, "waterfall", "current activity")
        d.addCallback(self._check, "about", "Buildbot is a free software")
        d.addCallback(self._check, "changes", "PBChangeSource listener")
        d.addCallback(self._check, "buildslaves", "Build Slaves")
        d.addCallback(self._check, "one_line_per_build",
                      "Last 20 finished builds")
        d.addCallback(self._check, "one_box_per_builder", "Latest builds")
        d.addCallback(self._check, "builders", "Builders")
        d.addCallback(self._check, "builders/builder1", "Builder: builder1")
        d.addCallback(self._check, "builders/builder1/builds", "") # dummy
        # TODO: the pages beyond here would be great to test, but that would
        # require causing a build to complete.
        #d.addCallback(self._check, "builders/builder1/builds/1", "")
        # it'd be nice to assert that the Build page has a "Stop Build" button
        #d.addCallback(self._check, "builders/builder1/builds/1/steps", "")
        #d.addCallback(self._check,
        #              "builders/builder1/builds/1/steps/compile", "")
        #d.addCallback(self._check,
        #              "builders/builder1/builds/1/steps/compile/logs", "")
        #d.addCallback(self._check,
        #              "builders/builder1/builds/1/steps/compile/logs/stdio","")
        #d.addCallback(self._check,
        #              "builders/builder1/builds/1/steps/compile/logs/stdio/text", "")
        return d