Changeset 12701


Ignore:
Timestamp:
9 Mar 2015, 05:07:04 (10 years ago)
Author:
uli
Message:

Add next_step for demo provider.

Location:
main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments/demo_provider.py

    r12688 r12701  
    22from waeup.ikoba.interfaces import MessageFactory as _
    33from waeup.ikoba.payments.interfaces import IPaymentGatewayService
    4 from waeup.ikoba.payments.payment import Payment
     4from waeup.ikoba.payments.payment import Payment, get_payment
    55
    66
     
    2121        payment.gateway_service = 'demo_creditcard'  # must be grok.name above
    2222        payment.payer_id = payer.payer_id
     23        # XXX: we should not have to store a payment before adding items
     24        site = grok.getSite()
     25        site['payments'][payment.payment_id] = payment
    2326        for item in payment_item_list:
    2427            payment.add_payment_item(item)
    2528        return payment
     29
     30    def next_step(self, payment_id):
     31        """Tell where to go next.
     32
     33        Returns (context, view_name). Both may be none.
     34        """
     35        payment = get_payment(payment_id)
     36        if payment is None:
     37            return None, None
     38        return payment, 'index'
  • main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments/interfaces.py

    r12671 r12701  
    102102        """
    103103
     104    def next_step(payment_id):
     105        """Returns a payment (as context) and a view name.
     106
     107        May result in (None, None).
     108        """
     109
    104110
    105111class IPaymentGatewayServicesLister(Interface):
  • main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments/tests/test_demo_provider.py

    r12671 r12701  
    11import decimal
     2from zope.component import queryUtility
     3from zope.component.hooks import setSite
    24from zope.interface.verify import verifyClass, verifyObject
    35from waeup.ikoba.testing import (
     
    79    IPaymentGatewayService, IPayment, STATE_UNPAID,
    810    )
    9 from waeup.ikoba.payments.payment import Payer, PaymentItem, Payee
     11from waeup.ikoba.app import Company
     12from waeup.ikoba.payments.payment import Payer, PaymentItem, Payee, Payment
    1013from waeup.ikoba.payments.demo_provider import (
    1114    DemoCreditcardPaymentService,
     
    1619
    1720    layer = FunctionalLayer
     21
     22    def setUp(self):
     23        super(DemoCreditcarPaymentServiceTests, self).setUp()
     24        self.app = Company()
     25        self.getRootFolder()['app'] = self.app
     26        setSite(self.app)
    1827
    1928    def test_iface(self):
     
    5665    def test_get_service_by_utility_name(self):
    5766        # we can get the demo credit card service by its utility name
    58         from zope.component import queryUtility
    5967        service = queryUtility(
    6068            IPaymentGatewayService, name="demo_creditcard")
    6169        assert service is not None
     70
     71    def test_next_step_invalid_id(self):
     72        # we cannot go to non-existent payments
     73        service = DemoCreditcardPaymentService()
     74        result = service.next_step('not-existent-payment-id')
     75        assert result == (None, None)
     76
     77    def test_next_step(self):
     78        # we are redirected to 'index' in the beginning
     79        service = DemoCreditcardPaymentService()
     80        p1 = Payment()
     81        self.app['payments']['1'] = p1
     82        p_id = p1.payment_id
     83        result = service.next_step(p_id)
     84        assert result == (p1, 'index')
Note: See TracChangeset for help on using the changeset viewer.