X Tutup
Skip to content

Commit 060442e

Browse files
committed
Much better, such wow Sticker tests
1 parent 2254440 commit 060442e

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

tests/test_sticker.py

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/usr/bin/env python
2+
#
3+
# A library that provides a Python interface to the Telegram Bot API
4+
# Copyright (C) 2015 Leandro Toledo de Souza <leandrotoeldodesouza@gmail.com>
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see [http://www.gnu.org/licenses/].
18+
19+
"""This module contains a object that represents Tests for Telegram Sticker"""
20+
21+
import os
22+
import unittest
23+
import sys
24+
sys.path.append('.')
25+
26+
import telegram
27+
from tests.base import BaseTest
28+
29+
30+
class StickerTest(BaseTest, unittest.TestCase):
31+
"""This object represents Tests for Telegram Sticker."""
32+
33+
def setUp(self):
34+
self.sticker_file_id = 'BQADAQADHAADyIsGAAFZfq1bphjqlgI'
35+
self.width = 510
36+
self.height = 512
37+
self.thumb = {'width': 90,
38+
'height': 90,
39+
'file_id': 'BQADAQADoQADHyP1B0mzJMVyzcB0Ag',
40+
'file_size': 2364}
41+
self.file_size = 39518
42+
43+
self.json_dict = {
44+
'file_id': self.sticker_file_id,
45+
'width': self.width,
46+
'height': self.height,
47+
'thumb': self.thumb,
48+
'file_size': self.file_size
49+
}
50+
51+
def test_send_sticker_file(self):
52+
pass
53+
54+
def test_send_sticker_resend(self):
55+
"""Test telegram.Bot sendSticker method"""
56+
print('Testing bot.sendSticker - Resend by file_id')
57+
58+
message = self._bot.sendSticker(chat_id=self._chat_id,
59+
sticker=self.sticker_file_id)
60+
61+
sticker = message.sticker
62+
63+
self.assertEqual(sticker.file_id, self.sticker_file_id)
64+
self.assertEqual(sticker.width, self.width)
65+
self.assertEqual(sticker.height, self.height)
66+
self.assertTrue(isinstance(sticker.thumb, telegram.PhotoSize))
67+
self.assertEqual(sticker.file_size, self.file_size)
68+
69+
def test_sticker_de_json(self):
70+
"""Test Sticker.de_json() method"""
71+
print('Testing Sticker.de_json()')
72+
73+
sticker = telegram.Sticker.de_json(self.json_dict)
74+
75+
self.assertEqual(sticker.file_id, self.sticker_file_id)
76+
self.assertEqual(sticker.width, self.width)
77+
self.assertEqual(sticker.height, self.height)
78+
self.assertTrue(isinstance(sticker.thumb, telegram.PhotoSize))
79+
self.assertEqual(sticker.file_size, self.file_size)
80+
81+
def test_sticker_to_json(self):
82+
"""Test Sticker.to_json() method"""
83+
print('Testing Sticker.to_json()')
84+
85+
sticker = telegram.Sticker.de_json(self.json_dict)
86+
87+
self.assertTrue(self.is_json(sticker.to_json()))
88+
89+
def test_sticker_to_dict(self):
90+
"""Test Sticker.to_dict() method"""
91+
print('Testing Sticker.to_dict()')
92+
93+
sticker = telegram.Sticker.de_json(self.json_dict)
94+
95+
self.assertEqual(sticker['file_id'], self.sticker_file_id)
96+
self.assertEqual(sticker['width'], self.width)
97+
self.assertEqual(sticker['height'], self.height)
98+
self.assertTrue(isinstance(sticker['thumb'], telegram.PhotoSize))
99+
self.assertEqual(sticker['file_size'], self.file_size)
100+
101+
def test_error_send_sticker_empty_file(self):
102+
print('Testing bot.sendSticker - Null file')
103+
104+
json_dict = self.json_dict
105+
106+
del(json_dict['file_id'])
107+
json_dict['sticker'] = open(os.devnull, 'rb')
108+
109+
self.assertRaises(telegram.TelegramError,
110+
lambda: self._bot.sendSticker(chat_id=self._chat_id,
111+
**json_dict))
112+
113+
def test_error_send_sticker_empty_file_id(self):
114+
print('Testing bot.sendSticker - Empty file_id')
115+
116+
json_dict = self.json_dict
117+
118+
del(json_dict['file_id'])
119+
json_dict['sticker'] = ''
120+
121+
self.assertRaises(telegram.TelegramError,
122+
lambda: self._bot.sendSticker(chat_id=self._chat_id,
123+
**json_dict))
124+
125+
def test_error_sticker_without_required_args(self):
126+
print('Testing bot.sendSticker - Without required arguments')
127+
128+
json_dict = self.json_dict
129+
130+
del(json_dict['file_id'])
131+
132+
self.assertRaises(TypeError,
133+
lambda: self._bot.sendSticker(chat_id=self._chat_id,
134+
**json_dict))
135+
136+
if __name__ == '__main__':
137+
unittest.main()

0 commit comments

Comments
 (0)
X Tutup