X Tutup
Skip to content

Commit c55c540

Browse files
committed
tests and corrections for inlinequery
1 parent d1dc32d commit c55c540

File tree

2 files changed

+86
-2
lines changed

2 files changed

+86
-2
lines changed

telegram/inlinequery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class InlineQuery(TelegramObject):
2929
* In Python `from` is a reserved word, use `from_user` instead.
3030
3131
Attributes:
32-
id (int):
32+
id (str):
3333
from_user (:class:`telegram.User`):
3434
query (str):
3535
offset (str):
@@ -48,7 +48,7 @@ def __init__(self,
4848
query,
4949
offset):
5050
# Required
51-
self.id = int(id)
51+
self.id = id
5252
self.from_user = from_user
5353
self.query = query
5454
self.offset = offset

tests/test_inlinequery.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
20+
"""This module contains a object that represents Tests for Telegram
21+
InlineQuery"""
22+
23+
import os
24+
import unittest
25+
import sys
26+
sys.path.append('.')
27+
28+
import telegram
29+
from tests.base import BaseTest
30+
31+
32+
class InlineQueryTest(BaseTest, unittest.TestCase):
33+
"""This object represents Tests for Telegram InlineQuery."""
34+
35+
def setUp(self):
36+
37+
user = telegram.User(1, 'First name')
38+
39+
self.id = 'id'
40+
self.from_user = user
41+
self.query = 'query text'
42+
self.offset = 'offset'
43+
44+
self.json_dict = {
45+
'id': self.id,
46+
'from': self.from_user.to_dict(),
47+
'query': self.query,
48+
'offset': self.offset
49+
}
50+
51+
def test_inlinequery_de_json(self):
52+
"""Test InlineQuery.de_json() method"""
53+
print('Testing InlineQuery.de_json()')
54+
55+
inlinequery = telegram.InlineQuery.de_json(self.json_dict)
56+
57+
self.assertEqual(inlinequery.id, self.id)
58+
self.assertEqual(inlinequery.from_user.to_dict(), self.from_user.to_dict())
59+
self.assertEqual(inlinequery.query, self.query)
60+
self.assertEqual(inlinequery.offset, self.offset)
61+
62+
def test_inlinequery_to_json(self):
63+
"""Test InlineQuery.to_json() method"""
64+
print('Testing InlineQuery.to_json()')
65+
66+
inlinequery = telegram.InlineQuery.de_json(self.json_dict)
67+
68+
self.assertTrue(self.is_json(inlinequery.to_json()))
69+
70+
def test_inlinequery_to_dict(self):
71+
"""Test InlineQuery.to_dict() method"""
72+
print('Testing InlineQuery.to_dict()')
73+
74+
inlinequery = telegram.InlineQuery.de_json(self.json_dict).to_dict()
75+
76+
self.assertTrue(self.is_dict(inlinequery))
77+
self.assertEqual(inlinequery['id'], self.id)
78+
self.assertEqual(inlinequery['from'], self.from_user.to_dict())
79+
self.assertEqual(inlinequery['query'], self.query)
80+
self.assertEqual(inlinequery['offset'], self.offset)
81+
82+
83+
if __name__ == '__main__':
84+
unittest.main()

0 commit comments

Comments
 (0)
X Tutup