2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-06 00:45:23 +00:00

[1451] address review comments

This commit is contained in:
Jelte Jansen
2011-12-15 16:16:50 +01:00
parent 2103ad2196
commit a593cb487f
4 changed files with 125 additions and 35 deletions

View File

@@ -17,10 +17,55 @@
import unittest
import isc
import ddns
import isc.config
class TestInitialization(unittest.TestCase):
def test_noop(self):
self.assertTrue(True)
class MyCCSession(isc.config.ConfigData):
'''Fake session with minimal interface compliance'''
def __init__(self):
module_spec = isc.config.module_spec_from_file(
ddns.SPECFILE_LOCATION)
isc.config.ConfigData.__init__(self, module_spec)
self._started = False
def start(self):
'''Called by DDNSServer initialization, but not used in tests'''
self._started = True
class TestDDNSServer(unittest.TestCase):
def setUp(self):
cc_session = MyCCSession()
self.assertFalse(cc_session._started)
self.ddns_server = ddns.DDNSServer(cc_session)
self.assertTrue(cc_session._started)
def test_config_handler(self):
# Config handler does not do anything yet, but should at least
# return 'ok' for now.
new_config = {}
answer = self.ddns_server.config_handler(new_config)
self.assertEqual((0, None), isc.config.parse_answer(answer))
def test_shutdown_command(self):
'''Test whether the shutdown command works'''
self.assertFalse(self.ddns_server._shutdown)
answer = self.ddns_server.command_handler('shutdown', None)
self.assertEqual((0, None), isc.config.parse_answer(answer))
self.assertTrue(self.ddns_server._shutdown)
def test_command_handler(self):
'''Test some commands.'''
# this command should not exist
answer = self.ddns_server.command_handler('bad_command', None)
self.assertEqual((1, 'Unknown command: bad_command'),
isc.config.parse_answer(answer))
def test_signal_handler(self):
'''Test whether signal_handler calls shutdown()'''
signal_handler = ddns.create_signal_handler(self.ddns_server)
self.assertFalse(self.ddns_server._shutdown)
signal_handler(None, None)
self.assertTrue(self.ddns_server._shutdown)
if __name__== "__main__":
isc.log.resetUnitTestRootLogger()