def test_MessageTypeRefresh(self):
     """Checks if Refresh message calls prepareRefresh"""
     mock = FunctionMock()
     message = {"messagetype" : "Refresh", "data" : ""}
     connector = ThingsConectorBase("testid", "node", "descr", 1)
     connector.prepareRefresh = mock.mockRefresh
     connector.parseJsonMessage(None, message)
     self.assertTrue(mock.mockCalled)
 def test_MessageTypeLogonResult_setsAuthenticated(self):
     """Checks if authenticated property is set to true"""
     mock = FunctionMock()
     message = {"messagetype" : "LogonResult", "data" : {"success": True}}
     connector = ThingsConectorBase("testid", "node", "descr", 1)
     connector.cutConnection = mock.mockDummy
     self.assertFalse(connector.authenticated)
     connector.sendNodeInfo = mock.mockSendHandwareInfo
     connector.parseJsonMessage(None, message)
     self.assertTrue(connector.authenticated)
    def test_MessageTypeUIMessage(self):
        """Checks if UI-Message calls handleUiMessage."""
        mock = FunctionMock()
        connector = ThingsConectorBase("testid", "node", "descr", 1)
        connector.cutConnection = mock.mockDummy

        message = {"messagetype" : "UI-Message", "data" : ""}
        connector.handleUIMessage = mock.mockHandleUIMessage
        self.assertFalse(mock.mockCalled)
        connector.parseJsonMessage(None, message)
        self.assertTrue(mock.mockCalled)
 def test_MessageTypeLogonResult_cuts_Connection(self):
     """Checks if message LogonResult calls cut connection if authentication fails."""
     mock = FunctionMock()
     message = {"messagetype" : "LogonResult", "data" : {"success": False}}
     connector = ThingsConectorBase("testid", "node", "descr", 1)
     connector.cutConnection = mock.mockDummy
     self.assertFalse(connector.authenticated)
     connector.parseJsonMessage(None, message)
     # check if authenticated is false
     self.assertFalse(connector.authenticated)
     # check if cutConnection() was called
     self.assertTrue(mock.dummyCalled)