aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/buildbot-0.8.8-py2.7.egg/buildbot/test/unit/test_status_master.py
blob: 04ae51363ae6290846b6e4726be222d10fef264f (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
# This file is part of Buildbot.  Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members

import mock
from twisted.trial import unittest
from twisted.internet import defer
from buildbot.status import master, base
from buildbot.test.fake import fakedb

class FakeStatusReceiver(base.StatusReceiver):
    pass

class TestStatus(unittest.TestCase):

    def makeStatus(self):
        m = mock.Mock(name='master')
        self.db = m.db = fakedb.FakeDBConnector(self)
        m.basedir = r'C:\BASEDIR'
        s = master.Status(m)
        return s

    def test_getBuildSets(self):
        s = self.makeStatus()
        self.db.insertTestData([
            fakedb.Buildset(id=91, sourcestampsetid=234, complete=0,
                    complete_at=298297875, results=-1, submitted_at=266761875,
                    external_idstring='extid', reason='rsn1'),
            fakedb.Buildset(id=92, sourcestampsetid=234, complete=1,
                    complete_at=298297876, results=7, submitted_at=266761876,
                    external_idstring='extid', reason='rsn2'),
        ])

        d = s.getBuildSets()
        def check(bslist):
            self.assertEqual([ bs.id for bs in bslist ], [ 91 ])
        d.addCallback(check)
        return d

    @defer.inlineCallbacks
    def test_reconfigService(self):
        m = mock.Mock(name='master')
        status = master.Status(m)
        status.startService()

        config = mock.Mock()

        # add a status reciever
        sr0 = FakeStatusReceiver()
        config.status = [ sr0 ]

        yield status.reconfigService(config)

        self.assertTrue(sr0.running)
        self.assertIdentical(sr0.master, m)

        # add a status reciever
        sr1 = FakeStatusReceiver()
        sr2 = FakeStatusReceiver()
        config.status = [ sr1, sr2 ]

        yield status.reconfigService(config)

        self.assertFalse(sr0.running)
        self.assertIdentical(sr0.master, None)
        self.assertTrue(sr1.running)
        self.assertIdentical(sr1.master, m)
        self.assertTrue(sr2.running)
        self.assertIdentical(sr2.master, m)

        # reconfig with those two (a regression check)
        sr1 = FakeStatusReceiver()
        sr2 = FakeStatusReceiver()
        config.status = [ sr1, sr2 ]

        yield status.reconfigService(config)

        # and back to nothing
        config.status = [ ]
        yield status.reconfigService(config)

        self.assertIdentical(sr0.master, None)
        self.assertIdentical(sr1.master, None)
        self.assertIdentical(sr2.master, None)