|
| 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