aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/buildbot-0.8.8-py2.7.egg/buildbot/test/unit/test_changes_manager.py
blob: 7eaec2eee3fe03d53fbb223e44badd758f214deb (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
# 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.application import service
from buildbot.changes import manager

class FakeChangeSource(service.Service):
    pass

class TestChangeManager(unittest.TestCase):
    def setUp(self):
        self.master = mock.Mock()
        self.cm = manager.ChangeManager(self.master)
        self.new_config = mock.Mock()

    def make_sources(self, n):
        for i in range(n):
            src = FakeChangeSource()
            src.setName('ChangeSource %d' % i)
            yield src

    def test_reconfigService_add(self):
        src1, src2 = self.make_sources(2)
        src1.setServiceParent(self.cm)
        self.new_config.change_sources = [ src1, src2 ]

        d = self.cm.reconfigService(self.new_config)
        @d.addCallback
        def check(_):
            self.assertIdentical(src2.parent, self.cm)
            self.assertIdentical(src2.master, self.master)
        return d

    def test_reconfigService_remove(self):
        src1, = self.make_sources(1)
        src1.setServiceParent(self.cm)
        self.new_config.change_sources = [ ]

        d = self.cm.reconfigService(self.new_config)
        @d.addCallback
        def check(_):
            self.assertIdentical(src1.parent, None)
            self.assertIdentical(src1.master, None)
        return d