Basic tests for payment stuff

This commit is contained in:
Jacob Bom 2017-05-20 17:30:50 +02:00
parent 5f96c507b9
commit 9f6ec125b9
8 changed files with 691 additions and 0 deletions

71
tests/test_invoice.py Normal file
View file

@ -0,0 +1,71 @@
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2017
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents Tests for Telegram
Invoice"""
import sys
import unittest
sys.path.append('.')
import telegram
from tests.base import BaseTest
class InvoiceTest(BaseTest, unittest.TestCase):
"""This object represents Tests for Telegram Invoice."""
def setUp(self):
self.title = 'title'
self.description = 'description'
self.start_parameter = 'start_parameter'
self.currency = 'EUD'
self.total_amount = 100
self.json_dict = {
'title': self.title,
'description': self.description,
'start_parameter': self.start_parameter,
'currency': self.currency,
'total_amount': self.total_amount
}
def test_invoice_de_json(self):
invoice = telegram.Invoice.de_json(self.json_dict, self._bot)
self.assertEqual(invoice.title, self.title)
self.assertEqual(invoice.description, self.description)
self.assertEqual(invoice.start_parameter, self.start_parameter)
self.assertEqual(invoice.currency, self.currency)
self.assertEqual(invoice.total_amount, self.total_amount)
def test_invoice_to_json(self):
invoice = telegram.Invoice.de_json(self.json_dict, self._bot)
self.assertTrue(self.is_json(invoice.to_json()))
def test_invoice_to_dict(self):
invoice = telegram.Invoice.de_json(self.json_dict, self._bot).to_dict()
self.assertTrue(self.is_dict(invoice))
self.assertDictEqual(self.json_dict, invoice)
if __name__ == '__main__':
unittest.main()

View file

@ -0,0 +1,59 @@
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2017
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents Tests for Telegram
LabeledPrice"""
import sys
import unittest
sys.path.append('.')
import telegram
from tests.base import BaseTest
class LabeledPriceTest(BaseTest, unittest.TestCase):
"""This object represents Tests for Telegram LabeledPrice."""
def setUp(self):
self.label = 'label'
self.amount = 100
self.json_dict = {'label': self.label, 'amount': self.amount}
def test_labeledprice_de_json(self):
labeledprice = telegram.LabeledPrice.de_json(self.json_dict, self._bot)
self.assertEqual(labeledprice.label, self.label)
self.assertEqual(labeledprice.amount, self.amount)
def test_labeledprice_to_json(self):
labeledprice = telegram.LabeledPrice.de_json(self.json_dict, self._bot)
self.assertTrue(self.is_json(labeledprice.to_json()))
def test_labeledprice_to_dict(self):
labeledprice = telegram.LabeledPrice.de_json(self.json_dict, self._bot).to_dict()
self.assertTrue(self.is_dict(labeledprice))
self.assertDictEqual(self.json_dict, labeledprice)
if __name__ == '__main__':
unittest.main()

69
tests/test_orderinfo.py Normal file
View file

@ -0,0 +1,69 @@
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2017
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents Tests for Telegram
OrderInfo"""
import sys
import unittest
sys.path.append('.')
import telegram
from tests.base import BaseTest
class OrderInfoTest(BaseTest, unittest.TestCase):
"""This object represents Tests for Telegram OrderInfo."""
def setUp(self):
self.name = 'name'
self.phone_number = 'phone_number'
self.email = 'email'
self.shipping_address = telegram.ShippingAddress('GB', '', 'London', '12 Grimmauld Place',
'', 'WC1')
self.json_dict = {
'name': self.name,
'phone_number': self.phone_number,
'email': self.email,
'shipping_address': self.shipping_address.to_dict()
}
def test_orderinfo_de_json(self):
orderinfo = telegram.OrderInfo.de_json(self.json_dict, self._bot)
self.assertEqual(orderinfo.name, self.name)
self.assertEqual(orderinfo.phone_number, self.phone_number)
self.assertEqual(orderinfo.email, self.email)
self.assertEqual(orderinfo.shipping_address, self.shipping_address)
def test_orderinfo_to_json(self):
orderinfo = telegram.OrderInfo.de_json(self.json_dict, self._bot)
self.assertTrue(self.is_json(orderinfo.to_json()))
def test_orderinfo_to_dict(self):
orderinfo = telegram.OrderInfo.de_json(self.json_dict, self._bot).to_dict()
self.assertTrue(self.is_dict(orderinfo))
self.assertDictEqual(self.json_dict, orderinfo)
if __name__ == '__main__':
unittest.main()

View file

@ -0,0 +1,99 @@
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2017
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents Tests for Telegram
PreCheckoutQuery"""
import sys
import unittest
sys.path.append('.')
import telegram
from tests.base import BaseTest
class PreCheckoutQueryTest(BaseTest, unittest.TestCase):
"""This object represents Tests for Telegram PreCheckoutQuery."""
def setUp(self):
self.id = 5
self.invoice_payload = 'invoice_payload'
self.shipping_option_id = 'shipping_option_id'
self.currency = 'EUD'
self.total_amount = 100
self.from_user = telegram.User(0, '')
self.order_info = telegram.OrderInfo()
self.json_dict = {
'id': self.id,
'invoice_payload': self.invoice_payload,
'shipping_option_id': self.shipping_option_id,
'currency': self.currency,
'total_amount': self.total_amount,
'from': self.from_user.to_dict(),
'order_info': self.order_info.to_dict()
}
def test_precheckoutquery_de_json(self):
precheckoutquery = telegram.PreCheckoutQuery.de_json(self.json_dict, self._bot)
self.assertEqual(precheckoutquery.id, self.id)
self.assertEqual(precheckoutquery.invoice_payload, self.invoice_payload)
self.assertEqual(precheckoutquery.shipping_option_id, self.shipping_option_id)
self.assertEqual(precheckoutquery.currency, self.currency)
self.assertEqual(precheckoutquery.from_user, self.from_user)
self.assertEqual(precheckoutquery.order_info, self.order_info)
def test_precheckoutquery_to_json(self):
precheckoutquery = telegram.PreCheckoutQuery.de_json(self.json_dict, self._bot)
self.assertTrue(self.is_json(precheckoutquery.to_json()))
def test_precheckoutquery_to_dict(self):
precheckoutquery = telegram.PreCheckoutQuery.de_json(self.json_dict, self._bot).to_dict()
self.assertTrue(self.is_dict(precheckoutquery))
self.assertDictEqual(self.json_dict, precheckoutquery)
def test_equality(self):
a = telegram.PreCheckoutQuery(self.id, self.from_user, self.currency, self.total_amount,
self.invoice_payload)
b = telegram.PreCheckoutQuery(self.id, self.from_user, self.currency, self.total_amount,
self.invoice_payload)
c = telegram.PreCheckoutQuery(self.id, None, '', 0, '')
d = telegram.PreCheckoutQuery(0, self.from_user, self.currency, self.total_amount,
self.invoice_payload)
e = telegram.Update(self.id)
self.assertEqual(a, b)
self.assertEqual(hash(a), hash(b))
self.assertIsNot(a, b)
self.assertEqual(a, c)
self.assertEqual(hash(a), hash(c))
self.assertNotEqual(a, d)
self.assertNotEqual(hash(a), hash(d))
self.assertNotEqual(a, e)
self.assertNotEqual(hash(a), hash(e))
if __name__ == '__main__':
unittest.main()

View file

@ -0,0 +1,114 @@
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2017
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents Tests for Telegram
ShippingAddress"""
import sys
import unittest
sys.path.append('.')
import telegram
from tests.base import BaseTest
class ShippingAddressTest(BaseTest, unittest.TestCase):
"""This object represents Tests for Telegram ShippingAddress."""
def setUp(self):
self.country_code = 'GB'
self.state = 'state'
self.city = 'London'
self.street_line1 = '12 Grimmauld Place'
self.street_line2 = 'street_line2'
self.post_code = 'WC1'
self.json_dict = {
'country_code': self.country_code,
'state': self.state,
'city': self.city,
'street_line1': self.street_line1,
'street_line2': self.street_line2,
'post_code': self.post_code
}
def test_shippingaddress_de_json(self):
shippingaddress = telegram.ShippingAddress.de_json(self.json_dict, self._bot)
self.assertEqual(shippingaddress.country_code, self.country_code)
self.assertEqual(shippingaddress.state, self.state)
self.assertEqual(shippingaddress.city, self.city)
self.assertEqual(shippingaddress.street_line1, self.street_line1)
self.assertEqual(shippingaddress.street_line2, self.street_line2)
self.assertEqual(shippingaddress.post_code, self.post_code)
def test_shippingaddress_to_json(self):
shippingaddress = telegram.ShippingAddress.de_json(self.json_dict, self._bot)
self.assertTrue(self.is_json(shippingaddress.to_json()))
def test_shippingaddress_to_dict(self):
shippingaddress = telegram.ShippingAddress.de_json(self.json_dict, self._bot).to_dict()
self.assertTrue(self.is_dict(shippingaddress))
self.assertDictEqual(self.json_dict, shippingaddress)
def test_equality(self):
a = telegram.ShippingAddress(self.country_code, self.state, self.city, self.street_line1,
self.street_line2, self.post_code)
b = telegram.ShippingAddress(self.country_code, self.state, self.city, self.street_line1,
self.street_line2, self.post_code)
d = telegram.ShippingAddress('', self.state, self.city, self.street_line1,
self.street_line2, self.post_code)
d2 = telegram.ShippingAddress(self.country_code, '', self.city, self.street_line1,
self.street_line2, self.post_code)
d3 = telegram.ShippingAddress(self.country_code, self.state, '', self.street_line1,
self.street_line2, self.post_code)
d4 = telegram.ShippingAddress(self.country_code, self.state, self.city, '',
self.street_line2, self.post_code)
d5 = telegram.ShippingAddress(self.country_code, self.state, self.city, self.street_line1,
'', self.post_code)
d6 = telegram.ShippingAddress(self.country_code, self.state, self.city, self.street_line1,
self.street_line2, '')
self.assertEqual(a, b)
self.assertEqual(hash(a), hash(b))
self.assertIsNot(a, b)
self.assertNotEqual(a, d)
self.assertNotEqual(hash(a), hash(d))
self.assertNotEqual(a, d2)
self.assertNotEqual(hash(a), hash(d2))
self.assertNotEqual(a, d3)
self.assertNotEqual(hash(a), hash(d3))
self.assertNotEqual(a, d4)
self.assertNotEqual(hash(a), hash(d4))
self.assertNotEqual(a, d5)
self.assertNotEqual(hash(a), hash(d5))
self.assertNotEqual(a, d6)
self.assertNotEqual(hash(6), hash(d6))
if __name__ == '__main__':
unittest.main()

View file

@ -0,0 +1,88 @@
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2017
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents Tests for Telegram
ShippingOption"""
import sys
import unittest
sys.path.append('.')
import telegram
from tests.base import BaseTest
class ShippingOptionTest(BaseTest, unittest.TestCase):
"""This object represents Tests for Telegram ShippingOption."""
def setUp(self):
self.id = 'id'
self.title = 'title'
self.prices = [
telegram.LabeledPrice('Fish Container', 100),
telegram.LabeledPrice('Premium Fish Container', 1000)
]
self.json_dict = {
'id': self.id,
'title': self.title,
'prices': [x.to_dict() for x in self.prices]
}
def test_shippingoption_de_json(self):
shippingoption = telegram.ShippingOption.de_json(self.json_dict, self._bot)
self.assertEqual(shippingoption.id, self.id)
self.assertEqual(shippingoption.title, self.title)
self.assertEqual(shippingoption.prices, self.prices)
def test_shippingoption_to_json(self):
shippingoption = telegram.ShippingOption.de_json(self.json_dict, self._bot)
self.assertTrue(self.is_json(shippingoption.to_json()))
def test_shippingoption_to_dict(self):
shippingoption = telegram.ShippingOption.de_json(self.json_dict, self._bot).to_dict()
self.assertTrue(self.is_dict(shippingoption))
self.assertDictEqual(self.json_dict, shippingoption)
def test_equality(self):
a = telegram.ShippingOption(self.id, self.title, self.prices)
b = telegram.ShippingOption(self.id, self.title, self.prices)
c = telegram.ShippingOption(self.id, '', [])
d = telegram.ShippingOption(0, self.title, self.prices)
e = telegram.Voice(self.id, 0)
self.assertEqual(a, b)
self.assertEqual(hash(a), hash(b))
self.assertIsNot(a, b)
self.assertEqual(a, c)
self.assertEqual(hash(a), hash(c))
self.assertNotEqual(a, d)
self.assertNotEqual(hash(a), hash(d))
self.assertNotEqual(a, e)
self.assertNotEqual(hash(a), hash(e))
if __name__ == '__main__':
unittest.main()

View file

@ -0,0 +1,91 @@
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2017
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents Tests for Telegram
ShippingQuery"""
import sys
import unittest
sys.path.append('.')
import telegram
from tests.base import BaseTest
class ShippingQueryTest(BaseTest, unittest.TestCase):
"""This object represents Tests for Telegram ShippingQuery."""
def setUp(self):
self.id = 5
self.invoice_payload = 'invoice_payload'
self.from_user = telegram.User(0, '')
self.shipping_address = telegram.ShippingAddress('GB', '', 'London', '12 Grimmauld Place',
'', 'WC1')
self.json_dict = {
'id': self.id,
'invoice_payload': self.invoice_payload,
'from': self.from_user.to_dict(),
'shipping_address': self.shipping_address.to_dict()
}
def test_shippingquery_de_json(self):
shippingquery = telegram.ShippingQuery.de_json(self.json_dict, self._bot)
self.assertEqual(shippingquery.id, self.id)
self.assertEqual(shippingquery.invoice_payload, self.invoice_payload)
self.assertEqual(shippingquery.from_user, self.from_user)
self.assertEqual(shippingquery.shipping_address, self.shipping_address)
def test_shippingquery_to_json(self):
shippingquery = telegram.ShippingQuery.de_json(self.json_dict, self._bot)
self.assertTrue(self.is_json(shippingquery.to_json()))
def test_shippingquery_to_dict(self):
shippingquery = telegram.ShippingQuery.de_json(self.json_dict, self._bot).to_dict()
self.assertTrue(self.is_dict(shippingquery))
self.assertDictEqual(self.json_dict, shippingquery)
def test_equality(self):
a = telegram.ShippingQuery(self.id, self.from_user, self.invoice_payload,
self.shipping_address)
b = telegram.ShippingQuery(self.id, self.from_user, self.invoice_payload,
self.shipping_address)
c = telegram.ShippingQuery(self.id, None, '', None)
d = telegram.ShippingQuery(0, self.from_user, self.invoice_payload, self.shipping_address)
e = telegram.Update(self.id)
self.assertEqual(a, b)
self.assertEqual(hash(a), hash(b))
self.assertIsNot(a, b)
self.assertEqual(a, c)
self.assertEqual(hash(a), hash(c))
self.assertNotEqual(a, d)
self.assertNotEqual(hash(a), hash(d))
self.assertNotEqual(a, e)
self.assertNotEqual(hash(a), hash(e))
if __name__ == '__main__':
unittest.main()

View file

@ -0,0 +1,100 @@
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2017
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents Tests for Telegram
SuccessfulPayment"""
import sys
import unittest
sys.path.append('.')
import telegram
from tests.base import BaseTest
class SuccessfulPaymentTest(BaseTest, unittest.TestCase):
"""This object represents Tests for Telegram SuccessfulPayment."""
def setUp(self):
self.invoice_payload = 'invoice_payload'
self.shipping_option_id = 'shipping_option_id'
self.currency = 'EUD'
self.total_amount = 100
self.order_info = telegram.OrderInfo()
self.telegram_payment_charge_id = 'telegram_payment_charge_id'
self.provider_payment_charge_id = 'provider_payment_charge_id'
self.json_dict = {
'invoice_payload': self.invoice_payload,
'shipping_option_id': self.shipping_option_id,
'currency': self.currency,
'total_amount': self.total_amount,
'order_info': self.order_info.to_dict(),
'telegram_payment_charge_id': self.telegram_payment_charge_id,
'provider_payment_charge_id': self.provider_payment_charge_id
}
def test_successfulpayment_de_json(self):
successfulpayment = telegram.SuccessfulPayment.de_json(self.json_dict, self._bot)
self.assertEqual(successfulpayment.invoice_payload, self.invoice_payload)
self.assertEqual(successfulpayment.shipping_option_id, self.shipping_option_id)
self.assertEqual(successfulpayment.currency, self.currency)
self.assertEqual(successfulpayment.order_info, self.order_info)
self.assertEqual(successfulpayment.telegram_payment_charge_id,
self.telegram_payment_charge_id)
self.assertEqual(successfulpayment.provider_payment_charge_id,
self.provider_payment_charge_id)
def test_successfulpayment_to_json(self):
successfulpayment = telegram.SuccessfulPayment.de_json(self.json_dict, self._bot)
self.assertTrue(self.is_json(successfulpayment.to_json()))
def test_successfulpayment_to_dict(self):
successfulpayment = telegram.SuccessfulPayment.de_json(self.json_dict, self._bot).to_dict()
self.assertTrue(self.is_dict(successfulpayment))
self.assertDictEqual(self.json_dict, successfulpayment)
def test_equality(self):
a = telegram.SuccessfulPayment(self.currency, self.total_amount, self.invoice_payload,
self.telegram_payment_charge_id,
self.provider_payment_charge_id)
b = telegram.SuccessfulPayment(self.currency, self.total_amount, self.invoice_payload,
self.telegram_payment_charge_id,
self.provider_payment_charge_id)
c = telegram.SuccessfulPayment('', 0, '', self.telegram_payment_charge_id,
self.provider_payment_charge_id)
d = telegram.SuccessfulPayment(self.currency, self.total_amount, self.invoice_payload,
self.telegram_payment_charge_id, '')
self.assertEqual(a, b)
self.assertEqual(hash(a), hash(b))
self.assertIsNot(a, b)
self.assertEqual(a, c)
self.assertEqual(hash(a), hash(c))
self.assertNotEqual(a, d)
self.assertNotEqual(hash(a), hash(d))
if __name__ == '__main__':
unittest.main()