X Tutup
Skip to content

Commit 9f6ec12

Browse files
committed
Basic tests for payment stuff
1 parent 5f96c50 commit 9f6ec12

File tree

8 files changed

+691
-0
lines changed

8 files changed

+691
-0
lines changed

tests/test_invoice.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
Invoice"""
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 InvoiceTest(BaseTest, unittest.TestCase):
32+
"""This object represents Tests for Telegram Invoice."""
33+
34+
def setUp(self):
35+
self.title = 'title'
36+
self.description = 'description'
37+
self.start_parameter = 'start_parameter'
38+
self.currency = 'EUD'
39+
self.total_amount = 100
40+
41+
self.json_dict = {
42+
'title': self.title,
43+
'description': self.description,
44+
'start_parameter': self.start_parameter,
45+
'currency': self.currency,
46+
'total_amount': self.total_amount
47+
}
48+
49+
def test_invoice_de_json(self):
50+
invoice = telegram.Invoice.de_json(self.json_dict, self._bot)
51+
52+
self.assertEqual(invoice.title, self.title)
53+
self.assertEqual(invoice.description, self.description)
54+
self.assertEqual(invoice.start_parameter, self.start_parameter)
55+
self.assertEqual(invoice.currency, self.currency)
56+
self.assertEqual(invoice.total_amount, self.total_amount)
57+
58+
def test_invoice_to_json(self):
59+
invoice = telegram.Invoice.de_json(self.json_dict, self._bot)
60+
61+
self.assertTrue(self.is_json(invoice.to_json()))
62+
63+
def test_invoice_to_dict(self):
64+
invoice = telegram.Invoice.de_json(self.json_dict, self._bot).to_dict()
65+
66+
self.assertTrue(self.is_dict(invoice))
67+
self.assertDictEqual(self.json_dict, invoice)
68+
69+
70+
if __name__ == '__main__':
71+
unittest.main()

tests/test_labeledprice.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
LabeledPrice"""
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 LabeledPriceTest(BaseTest, unittest.TestCase):
32+
"""This object represents Tests for Telegram LabeledPrice."""
33+
34+
def setUp(self):
35+
self.label = 'label'
36+
self.amount = 100
37+
38+
self.json_dict = {'label': self.label, 'amount': self.amount}
39+
40+
def test_labeledprice_de_json(self):
41+
labeledprice = telegram.LabeledPrice.de_json(self.json_dict, self._bot)
42+
43+
self.assertEqual(labeledprice.label, self.label)
44+
self.assertEqual(labeledprice.amount, self.amount)
45+
46+
def test_labeledprice_to_json(self):
47+
labeledprice = telegram.LabeledPrice.de_json(self.json_dict, self._bot)
48+
49+
self.assertTrue(self.is_json(labeledprice.to_json()))
50+
51+
def test_labeledprice_to_dict(self):
52+
labeledprice = telegram.LabeledPrice.de_json(self.json_dict, self._bot).to_dict()
53+
54+
self.assertTrue(self.is_dict(labeledprice))
55+
self.assertDictEqual(self.json_dict, labeledprice)
56+
57+
58+
if __name__ == '__main__':
59+
unittest.main()

tests/test_orderinfo.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
OrderInfo"""
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 OrderInfoTest(BaseTest, unittest.TestCase):
32+
"""This object represents Tests for Telegram OrderInfo."""
33+
34+
def setUp(self):
35+
self.name = 'name'
36+
self.phone_number = 'phone_number'
37+
self.email = 'email'
38+
self.shipping_address = telegram.ShippingAddress('GB', '', 'London', '12 Grimmauld Place',
39+
'', 'WC1')
40+
41+
self.json_dict = {
42+
'name': self.name,
43+
'phone_number': self.phone_number,
44+
'email': self.email,
45+
'shipping_address': self.shipping_address.to_dict()
46+
}
47+
48+
def test_orderinfo_de_json(self):
49+
orderinfo = telegram.OrderInfo.de_json(self.json_dict, self._bot)
50+
51+
self.assertEqual(orderinfo.name, self.name)
52+
self.assertEqual(orderinfo.phone_number, self.phone_number)
53+
self.assertEqual(orderinfo.email, self.email)
54+
self.assertEqual(orderinfo.shipping_address, self.shipping_address)
55+
56+
def test_orderinfo_to_json(self):
57+
orderinfo = telegram.OrderInfo.de_json(self.json_dict, self._bot)
58+
59+
self.assertTrue(self.is_json(orderinfo.to_json()))
60+
61+
def test_orderinfo_to_dict(self):
62+
orderinfo = telegram.OrderInfo.de_json(self.json_dict, self._bot).to_dict()
63+
64+
self.assertTrue(self.is_dict(orderinfo))
65+
self.assertDictEqual(self.json_dict, orderinfo)
66+
67+
68+
if __name__ == '__main__':
69+
unittest.main()

tests/test_precheckoutquery.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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

Comments
 (0)
X Tutup