Changeset 12325


Ignore:
Timestamp:
26 Dec 2014, 11:13:47 (10 years ago)
Author:
uli
Message:

Credit Card services must be able to find credit cards in site.

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

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/payments/paypal.py

    r12321 r12325  
    2727from zope import schema
    2828from zope.component import queryUtility
     29from zope.container.interfaces import IContainer
    2930from zope.interface import Interface, Attribute
    3031from waeup.ikoba.interfaces import MessageFactory as _
     
    11261127    title = _(u'Credit Card (PayPal)')
    11271128
    1128     def get_credit_card(payer_id):
     1129    def get_credit_card(self, payer_id):
    11291130        """Get an ICreditCard for `payer_id`.
    11301131
    11311132        `None` if the payer has (yet) no credit card stored with ikoba.
    11321133        """
    1133         pass
     1134        site = grok.getSite()
     1135        if not IContainer.providedBy(site):
     1136            return None
     1137        if not 'creditcards' in site:
     1138            return None
     1139        return site['creditcards'].get(payer_id, None)
    11341140
    11351141    def create_payment(self, payer, payment_item,  payee=None):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/payments/tests/test_paypal.py

    r12322 r12325  
    1616## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    1717##
     18import grok
    1819import decimal
    1920import os
     
    2425import paypalrestsdk
    2526from zope.component import (
    26     getGlobalSiteManager, queryUtility, getUtilitiesFor,
     27    getGlobalSiteManager, queryUtility,
    2728    )
     29from zope.component.hooks import setSite, clearSite
    2830from zope.i18nmessageid.message import Message as i18nMessage
    2931from zope.interface import implements
     
    10811083
    10821084
    1083 class PayPalCreditCardServiceTests(unittest.TestCase):
     1085class PayPalCreditCardServiceTests(FunctionalTestCase):
     1086
     1087    layer = FunctionalLayer
     1088
     1089    def tearDown(self):
     1090        super(PayPalCreditCardServiceTests, self).tearDown()
     1091        clearSite()
     1092
     1093    def create_site(self):
     1094        # create a simple site in root.
     1095        class MyApp(grok.Application, grok.Container):
     1096            pass
     1097        site = MyApp()
     1098        self.getRootFolder()['app'] = site
     1099        setSite(site)
     1100        return site
    10841101
    10851102    def test_iface(self):
     
    10881105        verifyClass(IPaymentGatewayService, PayPalCreditCardService)
    10891106        verifyObject(IPaymentGatewayService, service)
     1107
     1108    def test_get_credit_card_no_site(self):
     1109        # we get simply None if no site is registered
     1110        service = PayPalCreditCardService()
     1111        assert service.get_credit_card('not-a-valid-payer-id') is None
     1112
     1113    def test_get_credit_card_site_not_a_container(self):
     1114        # we get simply None if site is not a container
     1115        site = grok.Application()  # does not provide IContainer
     1116        self.getRootFolder()['app'] = site
     1117        setSite(site)
     1118        service = PayPalCreditCardService()
     1119        assert service.get_credit_card('not-a-valid-payer-id') is None
     1120
     1121    def test_get_credit_card_no_container(self):
     1122        # we get simply None if no 'creditcards' container is in site
     1123        self.create_site()
     1124        service = PayPalCreditCardService()
     1125        assert service.get_credit_card('not-a-valid-payer-id') is None
     1126
     1127    def test_get_credit_card(self):
     1128        # we can get a credit card, if one was stored
     1129        class MyCard(grok.Model):
     1130            myid = 'CARD1'
     1131
     1132            def __eq__(self, obj):
     1133                return self.myid == obj.myid
     1134
     1135        site = self.create_site()
     1136        site['creditcards'] = grok.Container()
     1137        card = MyCard()
     1138        card.myid = 'CHANGED ID'
     1139        site['creditcards'][u'CARD1'] = card
     1140        service = PayPalCreditCardService()
     1141        assert service.get_credit_card(u'CARD1') == card
     1142        assert service.get_credit_card(u'CARD2') is None
    10901143
    10911144    def DIStest_creditcard_service_can_create_payment(self):
Note: See TracChangeset for help on using the changeset viewer.