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_HandleLogonResultCalls_SendHardwareInfo(self): """Checks if handleLogonResult calls sendHardwareInfo().""" mock = FunctionMock() connector = ThingsConectorBase("testid", "node", "descr", 1) message = {"messagetype" : "LogonResult", "data" : {"success": True}} connector.cutConnection = mock.mockDummy connector.sendNodeInfo = mock.mockSendHandwareInfo self.assertFalse(mock.mockSendHandwareInfoCalled) connector.handleLogonResult(None, message) self.assertTrue(mock.mockSendHandwareInfoCalled)
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)