X Tutup
Skip to content

Commit 4589704

Browse files
committed
Add invoice test and there's no EUD currency, whoops
1 parent 76db279 commit 4589704

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

tests/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def __init__(self, *args, **kwargs):
4444
self._channel_id = os.environ.get('CHANNEL_ID', '@pythontelegrambottests')
4545
self._bot = bot
4646
self._chat_id = chat_id
47+
self._payment_provider_token = os.environ.get('PAYMENT_PROVIDER_TOKEN',
48+
'284685063:TEST:ZGJlMmQxZDI3ZTc3 ')
4749

4850
@staticmethod
4951
def is_json(string):

tests/test_invoice.py

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,27 @@
2222
import sys
2323
import unittest
2424

25+
from flaky import flaky
26+
2527
sys.path.append('.')
2628

2729
import telegram
28-
from tests.base import BaseTest
30+
from tests.base import BaseTest, timeout
2931

3032

3133
class InvoiceTest(BaseTest, unittest.TestCase):
3234
"""This object represents Tests for Telegram Invoice."""
3335

3436
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+
3541
self.title = 'title'
3642
self.description = 'description'
3743
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])
4046

4147
self.json_dict = {
4248
'title': self.title,
@@ -66,6 +72,50 @@ def test_invoice_to_dict(self):
6672
self.assertTrue(self.is_dict(invoice))
6773
self.assertDictEqual(self.json_dict, invoice)
6874

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

70120
if __name__ == '__main__':
71121
unittest.main()

tests/test_precheckoutquery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def setUp(self):
3535
self.id = 5
3636
self.invoice_payload = 'invoice_payload'
3737
self.shipping_option_id = 'shipping_option_id'
38-
self.currency = 'EUD'
38+
self.currency = 'EUR'
3939
self.total_amount = 100
4040
self.from_user = telegram.User(0, '')
4141
self.order_info = telegram.OrderInfo()

tests/test_successfulpayment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class SuccessfulPaymentTest(BaseTest, unittest.TestCase):
3434
def setUp(self):
3535
self.invoice_payload = 'invoice_payload'
3636
self.shipping_option_id = 'shipping_option_id'
37-
self.currency = 'EUD'
37+
self.currency = 'EUR'
3838
self.total_amount = 100
3939
self.order_info = telegram.OrderInfo()
4040
self.telegram_payment_charge_id = 'telegram_payment_charge_id'

0 commit comments

Comments
 (0)
X Tutup