class ChatClientSendTests(unittest.TestCase): """Tests checking that the send methods works as expected""" def setUp(self): """set up a test case""" # Arrange self.chat_service_mock = ChatServiceMock() self.chat_client = ChatClient(self.chat_service_mock) def test_login_using_mock(self): """login calls our mock with a properly encoded message""" # Act self.chat_client.login("user-name", "passw0rd") # Assert expected_message = {"command": "login", "user": "******", "password": "******"} self.assertEquals(expected_message, self.chat_service_mock.sent_message) def test_logout_using_mock(self): """logout calls our mock with a properly encoded message""" # Act self.chat_client.logout() # Assert expected_message = {"command": "logout"} self.assertEquals(expected_message, self.chat_service_mock.sent_message) def test_send_message_using_mock(self): """send_message calls our mock with a properly encoded message""" # Act self.chat_client.send_message("user123", "Hello") # Assert expected_message = {"command": "send-message", "to": "user123", "message": "Hello"} self.assertEquals(expected_message, self.chat_service_mock.sent_message) def test_send_friend_request_using_mock(self): """send_friend_request calls our mock with a properly encoded message""" # Act self.chat_client.send_friend_request("user123") # Assert expected_message = {"command": "send-friend-request", "to": "user123"} self.assertEquals(expected_message, self.chat_service_mock.sent_message) def test_set_status_using_mock(self): """set_status calls our mock with a properly encoded message""" # Act self.chat_client.set_status("away") # Assert expected_message = {"command": "set-status", "value": "away"} self.assertEquals(expected_message, self.chat_service_mock.sent_message)
def setUp(self): """set up a test case""" # Arrange self.chat_service_mock = ChatServiceMock() self.chat_client = ChatClient(self.chat_service_mock)