def test_send_message(self): self.mocked_response.json = lambda: json.loads(testdata. MESSAGE_RESPONSE) self.mocked_requests.post.return_value = self.mocked_response chat_id = 1337 testmessage = "testmessage" response = self.connector.send_message(chat_id, testmessage) expected_full_url = api.send_message_url(self.expected_base_url) expected_params = {"chat_id": str(chat_id), "text": testmessage} self.mocked_requests.post.assert_called_once_with( expected_full_url, \ params=expected_params, files={})
def test_send_message(self): self.mocked_response.json = lambda: json.loads(testdata.MESSAGE_RESPONSE) self.mocked_requests.post.return_value = self.mocked_response chat_id = 1337 testmessage = "testmessage" response = self.connector.send_message(chat_id, testmessage) expected_full_url = api.send_message_url(self.expected_base_url) expected_params = { "chat_id": str(chat_id), "text": testmessage} self.mocked_requests.post.assert_called_once_with( expected_full_url, \ params=expected_params, files={})
def test_send_message_optional_args(self): self.mocked_response.json = lambda: json.loads(testdata.MESSAGE_RESPONSE) self.mocked_requests.post.return_value = self.mocked_response chat_id = 1337 testmessage = "testmessage" optionals = {"disable_web_page_preview": True, \ "reply_to_message_id": 42, \ "reply_markup": None} response = self.connector.send_message(chat_id, testmessage, optionals=optionals) expected_full_url = api.send_message_url(self.expected_base_url) expected_params = { "chat_id": str(chat_id), "text": testmessage} expected_params.update(optionals) self.mocked_requests.post.assert_called_once_with( expected_full_url, \ params=expected_params, files={})
def test_send_message_optional_args(self): self.mocked_response.json = lambda: json.loads(testdata. MESSAGE_RESPONSE) self.mocked_requests.post.return_value = self.mocked_response chat_id = 1337 testmessage = "testmessage" optionals = {"disable_web_page_preview": True, \ "reply_to_message_id": 42, \ "reply_markup": None} response = self.connector.send_message(chat_id, testmessage, optionals=optionals) expected_full_url = api.send_message_url(self.expected_base_url) expected_params = {"chat_id": str(chat_id), "text": testmessage} expected_params.update(optionals) self.mocked_requests.post.assert_called_once_with( expected_full_url, \ params=expected_params, files={})
def send_message(self, chat_id, message, optionals={}): params = self._default_params(chat_id, optionals) params["text"] = message return self._do_post(api.send_message_url(self.base_url), params)