source: main/waeup.ikoba/trunk/src/waeup/ikoba/payments/tests/test_demo_provider.py @ 12700

Last change on this file since 12700 was 12671, checked in by uli, 10 years ago

Merge changes from uli-fake-gw-provider back into trunk.

File size: 2.5 KB
Line 
1import decimal
2from zope.interface.verify import verifyClass, verifyObject
3from waeup.ikoba.testing import (
4    FunctionalLayer, FunctionalTestCase,
5    )
6from waeup.ikoba.payments.interfaces import (
7    IPaymentGatewayService, IPayment, STATE_UNPAID,
8    )
9from waeup.ikoba.payments.payment import Payer, PaymentItem, Payee
10from waeup.ikoba.payments.demo_provider import (
11    DemoCreditcardPaymentService,
12    )
13
14
15class DemoCreditcarPaymentServiceTests(FunctionalTestCase):
16
17    layer = FunctionalLayer
18
19    def test_iface(self):
20        # we fullfill all interface contracts
21        service = DemoCreditcardPaymentService()
22        verifyClass(IPaymentGatewayService, DemoCreditcardPaymentService)
23        verifyObject(IPaymentGatewayService, service)
24
25    def test_create_payment(self):
26        # we can get payments from payment gateways
27        service = DemoCreditcardPaymentService()
28        payer, payment_item, payee = Payer(), PaymentItem(), Payee()
29        payer.payer_id = u'SOME_PAYER_ID'
30        result = service.create_payment(payer, [], payee)
31        assert IPayment.providedBy(result)
32        assert result.gateway_service == u'demo_creditcard'
33        assert result.state == STATE_UNPAID
34        assert len(result) == 0  # no items stored
35
36    def test_create_payment_honors_payment_item(self):
37        # we inspect payment items and take their values
38        service = DemoCreditcardPaymentService()
39        payer, payment_item, payee = Payer(), PaymentItem(), Payee()
40        payment_item.item_id = u'SOME_ITEM_ID'
41        payer.payer_id = u'SOME_PAYER_ID'
42        payment_item.amount = decimal.Decimal("300.99")
43        result = service.create_payment(payer, [payment_item], payee)
44        self.assertEqual(result.amount, payment_item.amount)
45        assert len(result) == 1
46
47    def test_create_payment_honors_payer(self):
48        # we inspect payers when creating their payments
49        service = DemoCreditcardPaymentService()
50        payer, payment_item, payee = Payer(), PaymentItem(), Payee()
51        payment_item.item_id = u'SOME_ITEM_ID'
52        payer.payer_id = u'SOME_PAYER_ID'
53        result = service.create_payment(payer, [payment_item], payee)
54        assert result.payer_id == payer.payer_id
55
56    def test_get_service_by_utility_name(self):
57        # we can get the demo credit card service by its utility name
58        from zope.component import queryUtility
59        service = queryUtility(
60            IPaymentGatewayService, name="demo_creditcard")
61        assert service is not None
Note: See TracBrowser for help on using the repository browser.