|
20 | 20 |
|
21 | 21 | import pytest |
22 | 22 |
|
| 23 | +from telegram import ParseMode |
23 | 24 | from telegram import (Update, Message, User, MessageEntity, Chat, Audio, Document, |
24 | 25 | Game, PhotoSize, Sticker, Video, Voice, VideoNote, Contact, Location, Venue, |
25 | 26 | Invoice, SuccessfulPayment) |
@@ -241,6 +242,55 @@ def test(*args, **kwargs): |
241 | 242 | assert message.reply_text('test', quote=True) |
242 | 243 | assert message.reply_text('test', reply_to_message_id=message.message_id, quote=True) |
243 | 244 |
|
| 245 | + def test_reply_markdown(self, monkeypatch, message): |
| 246 | + test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/) and ' |
| 247 | + '```pre```. http://google.com') |
| 248 | + |
| 249 | + def test(*args, **kwargs): |
| 250 | + cid = args[1] == message.chat_id |
| 251 | + markdown_text = args[2] == test_md_string |
| 252 | + markdown_enabled = kwargs['parse_mode'] == ParseMode.MARKDOWN |
| 253 | + if kwargs.get('reply_to_message_id'): |
| 254 | + reply = kwargs['reply_to_message_id'] == message.message_id |
| 255 | + else: |
| 256 | + reply = True |
| 257 | + return all([cid, markdown_text, reply, markdown_enabled]) |
| 258 | + |
| 259 | + text_markdown = self.test_message.text_markdown |
| 260 | + assert text_markdown == test_md_string |
| 261 | + |
| 262 | + monkeypatch.setattr('telegram.Bot.send_message', test) |
| 263 | + assert message.reply_markdown(self.test_message.text_markdown) |
| 264 | + assert message.reply_markdown(self.test_message.text_markdown, quote=True) |
| 265 | + assert message.reply_markdown(self.test_message.text_markdown, |
| 266 | + reply_to_message_id=message.message_id, |
| 267 | + quote=True) |
| 268 | + |
| 269 | + def test_reply_html(self, monkeypatch, message): |
| 270 | + test_html_string = ('Test for <<b>bold</b>, <i>ita_lic</i>, <code>code</code>, ' |
| 271 | + '<a href="http://github.com/">links</a> and <pre>pre</pre>. ' |
| 272 | + 'http://google.com') |
| 273 | + |
| 274 | + def test(*args, **kwargs): |
| 275 | + cid = args[1] == message.chat_id |
| 276 | + html_text = args[2] == test_html_string |
| 277 | + html_enabled = kwargs['parse_mode'] == ParseMode.HTML |
| 278 | + if kwargs.get('reply_to_message_id'): |
| 279 | + reply = kwargs['reply_to_message_id'] == message.message_id |
| 280 | + else: |
| 281 | + reply = True |
| 282 | + return all([cid, html_text, reply, html_enabled]) |
| 283 | + |
| 284 | + text_html = self.test_message.text_html |
| 285 | + assert text_html == test_html_string |
| 286 | + |
| 287 | + monkeypatch.setattr('telegram.Bot.send_message', test) |
| 288 | + assert message.reply_html(self.test_message.text_html) |
| 289 | + assert message.reply_html(self.test_message.text_html, quote=True) |
| 290 | + assert message.reply_html(self.test_message.text_html, |
| 291 | + reply_to_message_id=message.message_id, |
| 292 | + quote=True) |
| 293 | + |
244 | 294 | def test_reply_photo(self, monkeypatch, message): |
245 | 295 | def test(*args, **kwargs): |
246 | 296 | id = args[1] == message.chat_id |
|
0 commit comments