Ejemplo n.º 1
0
    def testLoadConfigWithRemote(self, fromPyro, logging):

        c = Controller()
        fakeSlave = MagicMock()
        fakeSlave.getVersion = MagicMock(return_value=c.getVersion())
        fakeSlave.hasDevice = MagicMock(return_value=True)

        incompatibleSlave = MagicMock()
        incompatibleSlave.getVersion = MagicMock(return_value="0.1.0")

        fromPyro.side_effect = [fakeSlave, incompatibleSlave, NamingError()]

        c.loadConfig(os.path.join(os.path.dirname(__file__), 'testConfigWithSlaves.json'))

        fromPyro.assert_has_calls([
            call('slave1'),  # Boba Fett? Boba Fett? Where?
            call('incompatible'),
            call('nonexistent')
        ])

        logging.error.assert_has_calls([
            call("This Controller is version {} but tried to add slave incompatible of version 0.1.0".format(c.getVersion())),
            call("Could not connect to slave with controller ID nonexistent")
        ])
        self.assertEqual(1, len(c.slaves))

        c.proxyDevice("fakeDevice")
        fakeSlave.proxyDevice.assert_called_once_with("fakeDevice")
Ejemplo n.º 2
0
 def testLoadConfigWithDuplicate(self):
     c = Controller()
     try:
         c.loadConfig(os.path.join(os.path.dirname(__file__), 'testDuplicateDevice.json'))
         self.fail("Didn't throw an exception when adding a duplicated device ID")
     except DuplicateDeviceIDError as e:
         self.assertEqual("Device already exists: Duplicate", str(e))
Ejemplo n.º 3
0
 def testLoadConfigWithDuplicate(self):
     c = Controller()
     try:
         c.loadConfig(os.path.join(os.path.dirname(__file__), 'testDuplicateDevice.json'))
         self.fail("Didn't throw an exception when adding a duplicated device ID")
     except DuplicateDeviceIDError as e:
         self.assertEqual("Device already exists: Duplicate", str(e))
Ejemplo n.º 4
0
    def testLoadConfigWithLogging(self, logging):
        mockLogger = MagicMock()
        logging.getLogger = MagicMock(return_value=mockLogger)

        c = Controller()
        c.loadConfig(os.path.join(os.path.dirname(__file__), 'testConfigWithLogging.json'), True)

        logging.config.dictConfig.assert_called_once_with({"key": "value", "key2": "value2"})
        mockLogger.setLevel.assert_called_once_with(logging.DEBUG)
        logging.info.assert_called_once_with("-d specified, overriding any specified default logger level to DEBUG")
Ejemplo n.º 5
0
    def testLoadConfig(self):
        c = Controller()
        c.loadConfig(os.path.join(os.path.dirname(__file__), 'testConfig.json'))

        self.assertTrue(c.hasDevice("Main"))
        self.assertTrue(c.hasDevice("Main Listener"))

        self.assertTrue(isinstance(c.getDevice("Main"), KramerVP88))
        self.assertTrue(isinstance(c.getDevice("Main Listener"), KramerVP88Listener))

        self.assertEqual("testController", c.controllerID)
Ejemplo n.º 6
0
    def testLoadConfig(self):
        c = Controller()
        c.loadConfig(os.path.join(os.path.dirname(__file__), 'testConfig.json'))

        self.assertTrue(c.hasDevice("Main"))
        self.assertTrue(c.hasDevice("Main Listener"))

        self.assertTrue(isinstance(c.getDevice("Main"), KramerVP88))
        self.assertTrue(isinstance(c.getDevice("Main Listener"), KramerVP88Listener))

        self.assertEqual("testController", c.controllerID)
Ejemplo n.º 7
0
    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"], [])
Ejemplo n.º 8
0
 def testLoadInvalidConfig(self, logging):
     c = Controller()
     c.loadConfig(os.path.join(os.path.dirname(__file__), 'notJson'))
     logging.exception.assert_called_once_with("Cannot parse config.json!")