|
| 1 | +#!/usr/bin/env python |
| 2 | +# |
| 3 | +# A library that provides a Python interface to the Telegram Bot API |
| 4 | +# Copyright (C) 2015-2017 |
| 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 an object that represents Tests for Telegram |
| 20 | +PreCheckoutQuery""" |
| 21 | + |
| 22 | +import sys |
| 23 | +import unittest |
| 24 | + |
| 25 | +sys.path.append('.') |
| 26 | + |
| 27 | +import telegram |
| 28 | +from tests.base import BaseTest |
| 29 | + |
| 30 | + |
| 31 | +class PreCheckoutQueryTest(BaseTest, unittest.TestCase): |
| 32 | + """This object represents Tests for Telegram PreCheckoutQuery.""" |
| 33 | + |
| 34 | + def setUp(self): |
| 35 | + self.id = 5 |
| 36 | + self.invoice_payload = 'invoice_payload' |
| 37 | + self.shipping_option_id = 'shipping_option_id' |
| 38 | + self.currency = 'EUD' |
| 39 | + self.total_amount = 100 |
| 40 | + self.from_user = telegram.User(0, '') |
| 41 | + self.order_info = telegram.OrderInfo() |
| 42 | + |
| 43 | + self.json_dict = { |
| 44 | + 'id': self.id, |
| 45 | + 'invoice_payload': self.invoice_payload, |
| 46 | + 'shipping_option_id': self.shipping_option_id, |
| 47 | + 'currency': self.currency, |
| 48 | + 'total_amount': self.total_amount, |
| 49 | + 'from': self.from_user.to_dict(), |
| 50 | + 'order_info': self.order_info.to_dict() |
| 51 | + } |
| 52 | + |
| 53 | + def test_precheckoutquery_de_json(self): |
| 54 | + precheckoutquery = telegram.PreCheckoutQuery.de_json(self.json_dict, self._bot) |
| 55 | + |
| 56 | + self.assertEqual(precheckoutquery.id, self.id) |
| 57 | + self.assertEqual(precheckoutquery.invoice_payload, self.invoice_payload) |
| 58 | + self.assertEqual(precheckoutquery.shipping_option_id, self.shipping_option_id) |
| 59 | + self.assertEqual(precheckoutquery.currency, self.currency) |
| 60 | + self.assertEqual(precheckoutquery.from_user, self.from_user) |
| 61 | + self.assertEqual(precheckoutquery.order_info, self.order_info) |
| 62 | + |
| 63 | + def test_precheckoutquery_to_json(self): |
| 64 | + precheckoutquery = telegram.PreCheckoutQuery.de_json(self.json_dict, self._bot) |
| 65 | + |
| 66 | + self.assertTrue(self.is_json(precheckoutquery.to_json())) |
| 67 | + |
| 68 | + def test_precheckoutquery_to_dict(self): |
| 69 | + precheckoutquery = telegram.PreCheckoutQuery.de_json(self.json_dict, self._bot).to_dict() |
| 70 | + |
| 71 | + self.assertTrue(self.is_dict(precheckoutquery)) |
| 72 | + self.assertDictEqual(self.json_dict, precheckoutquery) |
| 73 | + |
| 74 | + def test_equality(self): |
| 75 | + a = telegram.PreCheckoutQuery(self.id, self.from_user, self.currency, self.total_amount, |
| 76 | + self.invoice_payload) |
| 77 | + b = telegram.PreCheckoutQuery(self.id, self.from_user, self.currency, self.total_amount, |
| 78 | + self.invoice_payload) |
| 79 | + c = telegram.PreCheckoutQuery(self.id, None, '', 0, '') |
| 80 | + d = telegram.PreCheckoutQuery(0, self.from_user, self.currency, self.total_amount, |
| 81 | + self.invoice_payload) |
| 82 | + e = telegram.Update(self.id) |
| 83 | + |
| 84 | + self.assertEqual(a, b) |
| 85 | + self.assertEqual(hash(a), hash(b)) |
| 86 | + self.assertIsNot(a, b) |
| 87 | + |
| 88 | + self.assertEqual(a, c) |
| 89 | + self.assertEqual(hash(a), hash(c)) |
| 90 | + |
| 91 | + self.assertNotEqual(a, d) |
| 92 | + self.assertNotEqual(hash(a), hash(d)) |
| 93 | + |
| 94 | + self.assertNotEqual(a, e) |
| 95 | + self.assertNotEqual(hash(a), hash(e)) |
| 96 | + |
| 97 | + |
| 98 | +if __name__ == '__main__': |
| 99 | + unittest.main() |
0 commit comments