aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/buildbot-0.8.8-py2.7.egg/buildbot/test/util/pbmanager.py
blob: ac21574407c67d01fe51a09e7771e58c9c74c0b0 (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
# 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.internet import defer

class PBManagerMixin:
    def setUpPBChangeSource(self):
        "Set up a fake self.pbmanager."
        self.registrations = []
        self.unregistrations = []
        pbm = self.pbmanager = mock.Mock()
        pbm.register = self._fake_register

    def _fake_register(self, portstr, username, password, factory):
        reg = mock.Mock()
        def unregister():
            self.unregistrations.append((portstr, username, password))
            return defer.succeed(None)
        reg.unregister = unregister
        self.registrations.append((portstr, username, password))
        return reg

    def assertNotRegistered(self):
        self.assertEqual(self.registrations, [])

    def assertRegistered(self, portstr, username, password):
        for ps, un, pw in self.registrations:
            if ps == portstr and username == un and pw == password:
                return
        self.fail("not registered: %r not in %s" %
                ((portstr, username, password), self.registrations))

    def assertUnregistered(self, portstr, username, password):
        for ps, un, pw in self.unregistrations:
            if ps == portstr and username == un and pw == password:
                return
        self.fail("still registered")