class Enb(StateMachine): def __init__(self, name, port, configData): super(Enb, self).__init__() self.ioService = IoService(name, port) self.config = Configuration(configData, self.ioService) self.setContext({"config": self.config, "ioService": self.ioService}) def execute(self): self.ioService.addIncomingMessageCallback(self.handleIncomingMessage) self.ioService.start() self.config.addListener("control.adminState", self.__onAdminStateChanged__) self.changeState(Deregistered) if self.config.getValue("control.adminState"): self.handleCommand("register") def __onAdminStateChanged__(self, _, adminState): mapping = {True: "register", False: "deregister"} self.handleCommand(mapping[adminState]) def terminate(self): self.ioService.stop()
class TestConfiguration(unittest.TestCase): def setUp(self): self.ioService = IoService("service", 9000) self.ioService.start() self.cfg = Configuration( { "rrm": { "t3212": 64, "csEnabled": True, "psEnabled": False }, "son": { "enabled": True, "utrafdd": { "enabled": True, "scanOnBoot": True, "freqs": [10787, 9137], }, "gsm": { "enabled": True, "scanOnBoot": True, "freqs": [514, 516] } }, "oam": { "cliEnabled": True, "username": "******", "password": "******" } }, self.ioService) self.result = [None, None] def tearDown(self): self.ioService.stop() def test_setValue(self): self.cfg.setValue(("oam", "cliEnabled"), False) self.assertFalse(self.cfg.content["oam"]["cliEnabled"]) def test_setValueWithDotFormat(self): self.cfg.setValue("oam.cliEnabled", False) self.assertFalse(self.cfg.content["oam"]["cliEnabled"]) def test_getValue(self): self.assertEqual(self.cfg.getValue(("oam", "username")), "fap123") def test_getValueWithDotFormat(self): self.assertEqual(self.cfg.getValue("oam.username"), "fap123") def test_listenerCalledOnValueChanged(self): def onValueChanged(path, value): self.result = (path, value) self.cfg.addListener("oam", onValueChanged) self.cfg.setValue("oam.cliEnabled", False) time.sleep(0.1) self.assertListEqual(self.result[0], list(("oam", "cliEnabled"))) self.assertEqual(self.result[1], False) def test_listenerNotCalledOnValueChanged(self): self.listenerCalled = False def onValueChanged(path, value): self.listenerCalled = True self.cfg.addListener("oam.cliEnabled", onValueChanged) self.cfg.setValue("rrm.t3212", 10) time.sleep(0.1) self.assertFalse(self.listenerCalled)
class TestConfiguration(unittest.TestCase): def setUp(self): self.ioService = IoService("service", 9000) self.ioService.start() self.cfg = Configuration({ "rrm": { "t3212": 64, "csEnabled": True, "psEnabled": False }, "son": { "enabled": True, "utrafdd": { "enabled": True, "scanOnBoot": True, "freqs": [10787, 9137], }, "gsm": { "enabled": True, "scanOnBoot": True, "freqs": [514, 516] } }, "oam": { "cliEnabled": True, "username": "******", "password": "******" } }, self.ioService) self.result = [None, None] def tearDown(self): self.ioService.stop() def test_setValue(self): self.cfg.setValue(("oam", "cliEnabled"), False) self.assertFalse(self.cfg.content["oam"]["cliEnabled"]) def test_setValueWithDotFormat(self): self.cfg.setValue("oam.cliEnabled", False) self.assertFalse(self.cfg.content["oam"]["cliEnabled"]) def test_getValue(self): self.assertEqual(self.cfg.getValue(("oam", "username")), "fap123") def test_getValueWithDotFormat(self): self.assertEqual(self.cfg.getValue("oam.username"), "fap123") def test_listenerCalledOnValueChanged(self): def onValueChanged(path, value): self.result = (path, value) self.cfg.addListener("oam", onValueChanged) self.cfg.setValue("oam.cliEnabled", False) time.sleep(0.1) self.assertListEqual(self.result[0], list(("oam", "cliEnabled"))) self.assertEqual(self.result[1], False) def test_listenerNotCalledOnValueChanged(self): self.listenerCalled = False def onValueChanged(path, value): self.listenerCalled = True self.cfg.addListener("oam.cliEnabled", onValueChanged) self.cfg.setValue("rrm.t3212", 10) time.sleep(0.1) self.assertFalse(self.listenerCalled)