Skip to content

Commit cb46b03

Browse files
committed
Add MessageEntityTest and reformatting.
1 parent 35f6de3 commit cb46b03

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

tests/test_messageentity.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env python
2+
#
3+
# A library that provides a Python interface to the Telegram Bot API
4+
# Copyright (C) 2015-2016
5+
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program. If not, see [http://www.gnu.org/licenses/].
19+
"""This module contains a object that represents Tests for Telegram
20+
MessageEntity"""
21+
22+
import sys
23+
24+
if sys.version_info[0:2] == (2, 6):
25+
import unittest2 as unittest
26+
else:
27+
import unittest
28+
29+
sys.path.append('.')
30+
31+
import telegram
32+
from tests.base import BaseTest
33+
34+
35+
class MessageEntityTest(BaseTest, unittest.TestCase):
36+
"""This object represents Tests for Telegram MessageEntity."""
37+
38+
def setUp(self):
39+
self.type = 'type'
40+
self.offset = 1
41+
self.length = 2
42+
self.url = 'url'
43+
44+
self.json_dict = {
45+
'type': self.type,
46+
'offset': self.offset,
47+
'length': self.length,
48+
'url': self.url
49+
}
50+
51+
def test_sticker_de_json(self):
52+
sticker = telegram.MessageEntity.de_json(self.json_dict)
53+
54+
self.assertEqual(sticker.type, self.type)
55+
self.assertEqual(sticker.offset, self.offset)
56+
self.assertEqual(sticker.length, self.length)
57+
58+
def test_sticker_to_json(self):
59+
sticker = telegram.MessageEntity.de_json(self.json_dict)
60+
61+
self.assertTrue(self.is_json(sticker.to_json()))
62+
63+
def test_sticker_to_dict(self):
64+
sticker = telegram.MessageEntity.de_json(self.json_dict).to_dict()
65+
66+
self.assertTrue(self.is_dict(sticker))
67+
self.assertDictEqual(self.json_dict, sticker)
68+
69+
70+
if __name__ == '__main__':
71+
unittest.main()

0 commit comments

Comments
 (0)