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

Last change on this file since 13807 was 12752, checked in by Henrik Bettermann, 10 years ago

propset

  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1import unittest
2from zope.component import queryUtility
3from zope.component.hooks import setSite
4from zope.interface.verify import verifyClass, verifyObject
5from waeup.ikoba.testing import (
6    FunctionalLayer, FunctionalTestCase,
7    )
8from waeup.ikoba.payments.interfaces import (
9    IPaymentGatewayService, IPayment, STATE_UNPAID,
10    )
11from waeup.ikoba.app import Company
12from waeup.ikoba.payments.payment import Payer, Payee, Payment
13from waeup.ikoba.payments.demo_provider import (
14    DemoCreditcardPaymentService, RE_CC_NUMBER, RE_CSC,
15    )
16from waeup.ikoba.payments.tests.test_payment import FakePayer, FakePayable
17
18
19class TestDemoProviderHelpers(unittest.TestCase):
20
21    def test_re_cc_number(self):
22        # we recognize valid numbers
23        assert RE_CC_NUMBER.match('a') is None
24        assert RE_CC_NUMBER.match('12345678') is None
25        assert RE_CC_NUMBER.match('1234a5678') is None
26        assert RE_CC_NUMBER.match('132456789') is not None
27        assert RE_CC_NUMBER.match('123456789012345') is not None
28
29    def test_re_csc(self):
30        # we recognize security numbers
31        assert RE_CSC.match('12') is None
32        assert RE_CSC.match('123') is not None
33        assert RE_CSC.match('1234') is not None
34        assert RE_CSC.match('12345') is None
35        assert RE_CSC.match('12A2') is None
36
37
38class DemoCreditcardPaymentServiceTests(FunctionalTestCase):
39
40    layer = FunctionalLayer
41
42    def setUp(self):
43        super(DemoCreditcardPaymentServiceTests, self).setUp()
44        self.app = Company()
45        self.getRootFolder()['app'] = self.app
46        setSite(self.app)
47
48    def test_iface(self):
49        # we fullfill all interface contracts
50        service = DemoCreditcardPaymentService()
51        verifyClass(IPaymentGatewayService, DemoCreditcardPaymentService)
52        verifyObject(IPaymentGatewayService, service)
53
54    def test_create_payment(self):
55        # we can get payments from payment gateways
56        service = DemoCreditcardPaymentService()
57        payer, payable, payee = Payer(), FakePayable(), Payee()
58        payer.payer_id = u'SOME_PAYER_ID'
59        result = service.create_payment(payer, payable, payee)
60        assert IPayment.providedBy(result)
61        assert result.gateway_service == u'demo_creditcard'
62        assert result.state == STATE_UNPAID
63
64    def test_create_payment_honors_payer(self):
65        # we inspect payers when creating their payments
66        service = DemoCreditcardPaymentService()
67        payer, payable, payee = Payer(), FakePayable(), Payee()
68        payer.payer_id = u'SOME_PAYER_ID'
69        result = service.create_payment(payer, payable, payee)
70        assert result.payer_id == payer.payer_id
71
72    def test_get_service_by_utility_name(self):
73        # we can get the demo credit card service by its utility name
74        service = queryUtility(
75            IPaymentGatewayService, name="demo_creditcard")
76        assert service is not None
77
78    def test_next_step_invalid_id(self):
79        # we cannot go to non-existent payments
80        service = DemoCreditcardPaymentService()
81        result = service.next_step('not-existent-payment-id')
82        assert result == (None, None)
83
84    def test_next_step(self):
85        # we are redirected to 'index' in the beginning
86        service = DemoCreditcardPaymentService()
87        p1 = Payment(FakePayer(), FakePayable())
88        self.app['payments']['1'] = p1
89        p_id = p1.payment_id
90        result = service.next_step(p_id)
91        assert result == (p1, 'demo_cc1')
Note: See TracBrowser for help on using the repository browser.