def testBadClientDisconnect(self): c = Controller() c.registerClient("DOES_NOT_EXIST") self.assertEqual(["DOES_NOT_EXIST"], c.clients) c.callAllClients(lambda c: c.doesNotExist()) self.assertEqual([], c.clients)
def testCallsAllGoodClients(self, pyro4): c = Controller() c.registerClient("Bad") c.registerClient("Good") good = MagicMock() good.clientMethod = MagicMock() pyro4.Proxy = MagicMock() pyro4.Proxy.side_effect = [Exception("Foo"), good] c.callAllClients(lambda c: c.clientMethod("Bar")) pyro4.Proxy.assert_has_calls([ call("Bad"), call("Good") ]) good.clientMethod.assert_called_once_with("Bar")
def testPersistClientList(self): with create_temporary_copy(os.path.join(os.path.dirname(__file__), 'testConfig.json')) as confFile: c = Controller() c.loadConfig(confFile.name) c.registerClient("DOES_NOT_EXIST") withClient = json.load(confFile) print withClient self.assertEqual(withClient["clients"], ["DOES_NOT_EXIST"]) del c c2 = Controller() c2.loadConfig(confFile.name) self.assertEqual(c2.clients, ["DOES_NOT_EXIST"]) c2.callAllClients(lambda c: c.notARealMethod()) with open(confFile.name, "r") as cf2: withClient2 = json.load(cf2) self.assertEqual(withClient2["clients"], [])