Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests: add new unit tests for SlaveStatus
A few more tests in order to test Buildslave.status ... yes it's going away, but doenst hurt to have tests :)
- Loading branch information
1 parent
48c9dcb
commit d4e7720
Showing
1 changed file
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# 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 | ||
|
||
from twisted.trial import unittest | ||
from buildbot.status import slave | ||
from buildbot.util import eventual | ||
|
||
class TestSlaveStatus(unittest.TestCase): | ||
|
||
SLAVE_NAME = 'slavename' | ||
|
||
def makeStatus(self): | ||
s = slave.SlaveStatus(self.SLAVE_NAME) | ||
return s | ||
|
||
def test_getName(self): | ||
s = self.makeStatus() | ||
self.assertEqual(s.getName(), self.SLAVE_NAME) | ||
|
||
def test_getGraceful(self): | ||
s = self.makeStatus() | ||
self.assertFalse(s.getGraceful()) | ||
|
||
def test_setGraceful(self): | ||
s = self.makeStatus() | ||
|
||
s.setGraceful(True) | ||
|
||
self.assertTrue(s.getGraceful()) | ||
|
||
def test_addGracefulWatcher_noCallsWhenNotChanged(self): | ||
s = self.makeStatus() | ||
|
||
callbacks = [] | ||
def callback(graceful): | ||
callbacks.append(graceful) | ||
s.addGracefulWatcher(callback) | ||
|
||
d = eventual.flushEventualQueue() | ||
|
||
@d.addCallback | ||
def check(_): | ||
self.assertEqual(callbacks, []) | ||
|
||
return d | ||
|
||
def test_addGracefulWatcher_called(self): | ||
s = self.makeStatus() | ||
|
||
callbacks = [] | ||
def callback(graceful): | ||
callbacks.append(graceful) | ||
s.addGracefulWatcher(callback) | ||
|
||
s.setGraceful(True) | ||
|
||
d = eventual.flushEventualQueue() | ||
|
||
@d.addCallback | ||
def check(_): | ||
self.assertEqual(callbacks, [True]) | ||
|
||
return d | ||
|
||
def test_removeGracefulWatcher_removeBadObject(self): | ||
s = self.makeStatus() | ||
|
||
BOGUS_OBJECT = object() | ||
s.removeGracefulWatcher(BOGUS_OBJECT) | ||
|
||
def test_removeGracefulWatcher(self): | ||
s = self.makeStatus() | ||
|
||
callbacks = [] | ||
def callback(graceful): | ||
callbacks.append(graceful) | ||
|
||
s.addGracefulWatcher(callback) | ||
s.removeGracefulWatcher(callback) | ||
|
||
s.setGraceful(True) | ||
|
||
d = eventual.flushEventualQueue() | ||
|
||
@d.addCallback | ||
def check(_): | ||
# never called: | ||
self.assertEqual(callbacks, []) | ||
|
||
return d | ||
|
||
def test_getRunningBuilds_empty(self): | ||
s = self.makeStatus() | ||
|
||
builds = s.getRunningBuilds() | ||
|
||
self.assertEqual(builds, []) | ||
|
||
def test_getRunningBuilds_one(self): | ||
s = self.makeStatus() | ||
|
||
BUILD = 123 | ||
|
||
s.buildStarted(BUILD) | ||
|
||
builds = s.getRunningBuilds() | ||
|
||
self.assertEqual(builds, [BUILD]) | ||
|
||
def test_getRunningBuilds_removed(self): | ||
s = self.makeStatus() | ||
|
||
BUILD = 123 | ||
|
||
s.buildStarted(BUILD) | ||
s.buildFinished(BUILD) | ||
|
||
builds = s.getRunningBuilds() | ||
|
||
self.assertEqual(builds, []) | ||
|
||
def test_asDict(self): | ||
s = self.makeStatus() | ||
|
||
s.setHost('TheHost') | ||
s.setVersion('TheVersion') | ||
s.setAccessURI('TheUri') | ||
s.setAdmin('TheAdmin') | ||
|
||
slaveDict = s.asDict() | ||
|
||
self.assertEqual(slaveDict, { | ||
'host': 'TheHost', | ||
'version': 'TheVersion', | ||
'access_uri': 'TheUri', | ||
'admin': 'TheAdmin', | ||
'runningBuilds': [], | ||
'name': self.SLAVE_NAME, | ||
'connected': False | ||
}) |