|
22 | 22 | import sys |
23 | 23 | import unittest |
24 | 24 |
|
| 25 | +from flaky import flaky |
| 26 | + |
25 | 27 | sys.path.append('.') |
26 | 28 |
|
27 | 29 | import telegram |
28 | | -from tests.base import BaseTest |
| 30 | +from tests.base import BaseTest, timeout |
29 | 31 |
|
30 | 32 |
|
31 | 33 | class InvoiceTest(BaseTest, unittest.TestCase): |
32 | 34 | """This object represents Tests for Telegram Invoice.""" |
33 | 35 |
|
34 | 36 | def setUp(self): |
| 37 | + self.payload = 'payload' |
| 38 | + self.provider_token = self._payment_provider_token |
| 39 | + self.prices = [telegram.LabeledPrice('Fish', 100), telegram.LabeledPrice('Fish Tax', 1000)] |
| 40 | + |
35 | 41 | self.title = 'title' |
36 | 42 | self.description = 'description' |
37 | 43 | self.start_parameter = 'start_parameter' |
38 | | - self.currency = 'EUD' |
39 | | - self.total_amount = 100 |
| 44 | + self.currency = 'EUR' |
| 45 | + self.total_amount = sum([p.amount for p in self.prices]) |
40 | 46 |
|
41 | 47 | self.json_dict = { |
42 | 48 | 'title': self.title, |
@@ -66,6 +72,50 @@ def test_invoice_to_dict(self): |
66 | 72 | self.assertTrue(self.is_dict(invoice)) |
67 | 73 | self.assertDictEqual(self.json_dict, invoice) |
68 | 74 |
|
| 75 | + @flaky(3, 1) |
| 76 | + @timeout(10) |
| 77 | + def test_send_invoice_required_args_only(self): |
| 78 | + message = self._bot.send_invoice(self._chat_id, self.title, self.description, self.payload, |
| 79 | + self.provider_token, self.start_parameter, self.currency, |
| 80 | + self.prices) |
| 81 | + invoice = message.invoice |
| 82 | + |
| 83 | + self.assertEqual(invoice.currency, self.currency) |
| 84 | + self.assertEqual(invoice.start_parameter, self.start_parameter) |
| 85 | + self.assertEqual(invoice.description, self.description) |
| 86 | + self.assertEqual(invoice.title, self.title) |
| 87 | + self.assertEqual(invoice.total_amount, self.total_amount) |
| 88 | + |
| 89 | + @flaky(3, 1) |
| 90 | + @timeout(10) |
| 91 | + def test_send_invoice_all_args(self): |
| 92 | + message = self._bot.send_invoice( |
| 93 | + self._chat_id, |
| 94 | + self.title, |
| 95 | + self.description, |
| 96 | + self.payload, |
| 97 | + self.provider_token, |
| 98 | + self.start_parameter, |
| 99 | + self.currency, |
| 100 | + self.prices, |
| 101 | + photo_url='https://raw.githubusercontent.com/' |
| 102 | + 'python-telegram-bot/logos/master/' |
| 103 | + 'logo/png/ptb-logo_240.png', |
| 104 | + photo_size=240, |
| 105 | + photo_width=240, |
| 106 | + photo_height=240, |
| 107 | + need_name=True, |
| 108 | + need_phone_number=True, |
| 109 | + need_shipping_address=True, |
| 110 | + is_flexible=True) |
| 111 | + invoice = message.invoice |
| 112 | + |
| 113 | + self.assertEqual(invoice.currency, self.currency) |
| 114 | + self.assertEqual(invoice.start_parameter, self.start_parameter) |
| 115 | + self.assertEqual(invoice.description, self.description) |
| 116 | + self.assertEqual(invoice.title, self.title) |
| 117 | + self.assertEqual(invoice.total_amount, self.total_amount) |
| 118 | + |
69 | 119 |
|
70 | 120 | if __name__ == '__main__': |
71 | 121 | unittest.main() |
0 commit comments