def test__get_updates_call_getUpdates_api_correctly(self): tcb = TelegramController() tcb.TOKEN = "banana" expected_response = "banana_result" tcb._send_http = MagicMock(return_value=expected_response) updates = tcb._get_updates() self.assertEqual(updates, expected_response) tcb._send_http.assert_called_once_with( "https://api.telegram.org/banana/getUpdates?offset=1&timeout=10")
def test__handle_message_call__execute_command_with_correct_commands(self): tcb = TelegramController() tcb.CHAT_ID = 1234567890 tcb._execute_command = MagicMock() tcb._get_updates = MagicMock( return_value={ "ok": True, "result": [ { "update_id": 402107588, "message": { "message_id": 11, "from": { "id": 1234567890, "is_bot": False, "first_name": "msaltnet", "language_code": "ko", }, "chat": { "id": 1234567890, "first_name": "msaltnet", "type": "private" }, "date": 1627694419, "text": "3", }, }, { "update_id": 402107589, "message": { "message_id": 12, "from": { "id": 1234567891, "is_bot": False, "first_name": "msaltnet", "language_code": "ko", }, "chat": { "id": 1234567891, "first_name": "msaltnet", "type": "private" }, "date": 1627694420, "text": "4", }, }, { "update_id": 402107590, "message": { "message_id": 13, "from": { "id": 1234567890, "is_bot": False, "first_name": "msaltnet", "language_code": "ko", }, "chat": { "id": 1234567890, "first_name": "msaltnet", "type": "private" }, "date": 1627694420, "text": "5", }, }, ], }) tcb._handle_message() self.assertEqual(tcb._execute_command.call_args_list[0][0][0], "3") self.assertEqual(tcb._execute_command.call_args_list[1][0][0], "5") self.assertEqual(tcb.last_update_id, 402107590)