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 testInvalidRequests(self):
        m = MagicMock()
        handleRequest("not-a-valid-path", None, m)
        m.assert_called_once_with(400, "Incorrectly formatted URL: not-a-valid-path")
        m.reset_mock()

        c = MagicMock()
        c.hasDevice = MagicMock(return_value=False)

        handleRequest("/not-a-device/method/arg", c, m)
        c.hasDevice.assert_called_once_with('not-a-device')
        m.assert_called_once_with(404, "No such device: not-a-device")
        m.reset_mock()

        d = MagicMock()
        d.httpAccessible = False
        c2 = MagicMock()
        c2.hasDevice = MagicMock(return_value=True)
        c2.getDevice = MagicMock(return_value=d)

        handleRequest("/testDevice/method/arg", c2, m)
        c2.hasDevice.assert_called_once_with('testDevice')
        c2.getDevice.assert_called_once_with('testDevice')
        m.assert_called_once_with(403, "Not permitted to access device testDevice over HTTP.")
        m.reset_mock()

        d3 = MagicMock()
        d3.httpAccessible = True
        d3.method = None
        c3 = MagicMock()
        c3.hasDevice = MagicMock(return_value=True)
        c3.getDevice = MagicMock(return_value=d3)

        handleRequest("/testDevice/method/arg", c3, m)
        c2.hasDevice.assert_called_once_with('testDevice')
        c2.getDevice.assert_called_once_with('testDevice')
        m.assert_called_once_with(400, "No such function: method")
Ejemplo n.º 3
0
    def testValidRequest(self):
        d = MagicMock()
        d.httpAccessible = True
        d.method = MagicMock(return_value="Happy times")
        c = MagicMock()
        c.hasDevice = MagicMock(return_value=True)
        c.getDevice = MagicMock(return_value=d)

        m = MagicMock()

        handleRequest("/testDevice/method/arg", c, m)
        c.hasDevice.assert_called_once_with('testDevice')
        c.getDevice.assert_called_once_with('testDevice')
        d.method.assert_called_once_with('arg')
        m.assert_called_once_with(200, "OK Happy times")