Changeset 12325
- Timestamp:
- 26 Dec 2014, 11:13:47 (10 years ago)
- 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 27 27 from zope import schema 28 28 from zope.component import queryUtility 29 from zope.container.interfaces import IContainer 29 30 from zope.interface import Interface, Attribute 30 31 from waeup.ikoba.interfaces import MessageFactory as _ … … 1126 1127 title = _(u'Credit Card (PayPal)') 1127 1128 1128 def get_credit_card( payer_id):1129 def get_credit_card(self, payer_id): 1129 1130 """Get an ICreditCard for `payer_id`. 1130 1131 1131 1132 `None` if the payer has (yet) no credit card stored with ikoba. 1132 1133 """ 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) 1134 1140 1135 1141 def create_payment(self, payer, payment_item, payee=None): -
main/waeup.ikoba/trunk/src/waeup/ikoba/payments/tests/test_paypal.py
r12322 r12325 16 16 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 17 ## 18 import grok 18 19 import decimal 19 20 import os … … 24 25 import paypalrestsdk 25 26 from zope.component import ( 26 getGlobalSiteManager, queryUtility, getUtilitiesFor,27 getGlobalSiteManager, queryUtility, 27 28 ) 29 from zope.component.hooks import setSite, clearSite 28 30 from zope.i18nmessageid.message import Message as i18nMessage 29 31 from zope.interface import implements … … 1081 1083 1082 1084 1083 class PayPalCreditCardServiceTests(unittest.TestCase): 1085 class 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 1084 1101 1085 1102 def test_iface(self): … … 1088 1105 verifyClass(IPaymentGatewayService, PayPalCreditCardService) 1089 1106 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 1090 1143 1091 1144 def DIStest_creditcard_service_can_create_payment(self):
Note: See TracChangeset for help on using the changeset viewer.