Changeset 6866 for main


Ignore:
Timestamp:
7 Oct 2011, 07:24:45 (13 years ago)
Author:
Henrik Bettermann
Message:

Online payments must be importable. So we might need a factory.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/payments
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/payments/payment.py

    r6864 r6866  
    1919import grok
    2020from grok import index
     21from zope.component.interfaces import IFactory
     22from zope.interface import implementedBy
    2123from waeup.sirp.payments.interfaces import (
    2224    IPayment, ISCPayment, IOnlinePayment)
     
    5759
    5860OnlinePayment = attrs_to_fields(OnlinePayment)
     61
     62# Online payments must be importable. So we might need a factory.
     63class OnlinePaymentFactory(grok.GlobalUtility):
     64    """A factory for online payments.
     65    """
     66    grok.implements(IFactory)
     67    grok.name(u'waeup.OnlinePayment')
     68    title = u"Create a new online payment.",
     69    description = u"This factory instantiates new online payment instances."
     70
     71    def __call__(self, *args, **kw):
     72        return OnlinePayment()
     73
     74    def getInterfaces(self):
     75        return implementedBy(OnlinePayment)
  • main/waeup.sirp/trunk/src/waeup/sirp/payments/tests.py

    r6864 r6866  
    2222from waeup.sirp.payments.container import PaymentsContainer
    2323from waeup.sirp.payments.payment import (
    24     SCPayment, OnlinePayment)
     24    SCPayment, OnlinePayment, OnlinePaymentFactory)
    2525from waeup.sirp.testing import (FunctionalLayer, FunctionalTestCase)
    2626
     
    6464        self.assertRaises(
    6565            NotImplementedError, container.clear)
     66
     67class OnlinePaymentFactoryTest(FunctionalTestCase):
     68
     69    layer = FunctionalLayer
     70
     71    def setUp(self):
     72        super(OnlinePaymentFactoryTest, self).setUp()
     73        self.factory = OnlinePaymentFactory()
     74        return
     75
     76    def tearDown(self):
     77        super(OnlinePaymentFactoryTest, self).tearDown()
     78        return
     79
     80    def test_factory(self):
     81        obj = self.factory()
     82        assert isinstance(obj, OnlinePayment)
     83
     84    def test_getInterfaces(self):
     85        implemented_by = self.factory.getInterfaces()
     86        assert implemented_by.isOrExtends(IOnlinePayment)
Note: See TracChangeset for help on using the changeset viewer.