- Timestamp:
- 11 Mar 2015, 17:08:34 (10 years ago)
- Location:
- main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments/tests
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments/tests/test_demo_provider.py
r12712 r12734 1 import decimal2 1 from zope.component import queryUtility 3 2 from zope.component.hooks import setSite … … 10 9 ) 11 10 from waeup.ikoba.app import Company 12 from waeup.ikoba.payments.payment import Payer, Pay mentItem, Payee, Payment11 from waeup.ikoba.payments.payment import Payer, Payee, Payment 13 12 from waeup.ikoba.payments.demo_provider import ( 14 13 DemoCreditcardPaymentService, 15 14 ) 15 from waeup.ikoba.payments.tests.test_payment import FakePayer, FakePayable 16 16 17 17 … … 35 35 # we can get payments from payment gateways 36 36 service = DemoCreditcardPaymentService() 37 payer, pay ment_item, payee = Payer(), PaymentItem(), Payee()37 payer, payable, payee = Payer(), FakePayable(), Payee() 38 38 payer.payer_id = u'SOME_PAYER_ID' 39 result = service.create_payment(payer, [], payee)39 result = service.create_payment(payer, payable, payee) 40 40 assert IPayment.providedBy(result) 41 41 assert result.gateway_service == u'demo_creditcard' 42 42 assert result.state == STATE_UNPAID 43 assert len(result) == 0 # no items stored44 45 def test_create_payment_honors_payment_item(self):46 # we inspect payment items and take their values47 service = DemoCreditcardPaymentService()48 payer, payment_item, payee = Payer(), PaymentItem(), Payee()49 payment_item.item_id = u'SOME_ITEM_ID'50 payer.payer_id = u'SOME_PAYER_ID'51 payment_item.amount = decimal.Decimal("300.99")52 result = service.create_payment(payer, [payment_item], payee)53 self.assertEqual(result.amount, payment_item.amount)54 assert len(result) == 155 43 56 44 def test_create_payment_honors_payer(self): 57 45 # we inspect payers when creating their payments 58 46 service = DemoCreditcardPaymentService() 59 payer, payment_item, payee = Payer(), PaymentItem(), Payee() 60 payment_item.item_id = u'SOME_ITEM_ID' 47 payer, payable, payee = Payer(), FakePayable(), Payee() 61 48 payer.payer_id = u'SOME_PAYER_ID' 62 result = service.create_payment(payer, [payment_item], payee)49 result = service.create_payment(payer, payable, payee) 63 50 assert result.payer_id == payer.payer_id 64 51 … … 78 65 # we are redirected to 'index' in the beginning 79 66 service = DemoCreditcardPaymentService() 80 p1 = Payment( )67 p1 = Payment(FakePayer(), FakePayable()) 81 68 self.app['payments']['1'] = p1 82 69 p_id = p1.payment_id -
main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments/tests/test_payment.py
r12719 r12734 24 24 ) 25 25 from zope.component.hooks import setSite 26 from zope.interface import implements 26 from zope.interface import implements, implementer 27 27 from zope.interface.verify import verifyClass, verifyObject 28 28 from waeup.ikoba.payments.interfaces import ( 29 29 IPayment, STATE_UNPAID, STATE_PAID, STATE_FAILED, 30 30 IPaymentGatewayService, IPaymentItem, IPaymentGatewayServicesLister, 31 IPayableFinder, 31 IPayableFinder, IPayable, IPayer, 32 32 ) 33 33 from waeup.ikoba.app import Company … … 37 37 ) 38 38 from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase) 39 40 41 @implementer(IPayer) 42 class FakePayer(object): 43 44 def __init__( 45 self, payer_id=u'PAYER_01', first_name=u'Anna', last_name='Tester'): 46 self.payer_id = payer_id 47 self.first_name = first_name 48 self.last_name = last_name 49 50 51 FAKE_PAYMENT_ITEMS = ( 52 PaymentItem(u'ITEM1', u'Item title 1', decimal.Decimal("1.00")), 53 PaymentItem(u'ITEM2', u'Item title 2', decimal.Decimal("2.2")), 54 ) 55 56 57 @implementer(IPayable) 58 class FakePayable(object): 59 60 payable_id = u'id1' 61 items = ( 62 (u'item 1', decimal.Decimal("1.00")), 63 (u'item 2', decimal.Decimal("2.12")), 64 ) 65 66 def __init__(self, payable_id=u'PAYABLE_01', title=u'title', 67 currency=u'USD', payment_items=FAKE_PAYMENT_ITEMS): 68 self.payable_id = payable_id 69 self.title = title 70 self.currency = currency 71 self.payment_items = payment_items 39 72 40 73 … … 103 136 assert len(util()) > 0 104 137 105 def test_add_payment_item(self):106 # we can add payment items107 p1 = Payment()108 item1 = PaymentItem()109 result = p1.add_payment_item(item1)110 assert len(p1) == 1 # do not make assumptions about result content111 assert isinstance(result, basestring)112 113 138 def test_get_payment(self): 114 139 # we can lookup payments. … … 116 141 app = self.getRootFolder()['app'] 117 142 setSite(app) 118 p1 = Payment() 119 item1 = PaymentItem() 143 p1 = Payment(FakePayer(), FakePayable()) 120 144 app['payments']['1'] = p1 121 p1.add_payment_item(item1)122 145 p_id = p1.payment_id 123 146 result = get_payment(p_id) … … 155 178 156 179 157 class PaymentTests(unittest.TestCase): 180 class PaymentTests(FunctionalTestCase): 181 182 layer = FunctionalLayer 183 184 def setUp(self): 185 super(PaymentTests, self).setUp() 186 self.payer = FakePayer() 187 self.payable = FakePayable() 158 188 159 189 def test_iface(self): 160 190 # Payments fullfill any interface contracts 161 obj = Payment( )191 obj = Payment(self.payer, self.payable) 162 192 verifyClass(IPayment, Payment) 163 193 verifyObject(IPayment, obj) 164 194 195 def test_initial_values(self): 196 # important attributes are set initially 197 payer = self.payer 198 payer.payer_id = u'PAYER_ID' 199 payable = self.payable 200 payable.payable_id = u'PAYABLE_ID' 201 payable.title = u'PAYABLE-TITLE' 202 payable.currency = 'NGN' 203 payment = Payment(payer, payable) 204 assert payment.payer_id == u'PAYER_ID' 205 assert payment.payable_id == u'PAYABLE_ID' 206 assert payment.title == u'PAYABLE-TITLE' 207 assert payment.currency == 'NGN' 208 assert isinstance(payment.creation_date, datetime.datetime) 209 assert payment.payment_date is None 210 165 211 def test_payment_id_unique(self): 166 212 # we get unique payment ids 167 p1, p2 = Payment(), Payment() 213 p1 = Payment(self.payer, self.payable) 214 p2 = Payment(self.payer, self.payable) 168 215 id1, id2 = p1.payment_id, p2.payment_id 169 216 assert id1 != id2 … … 171 218 def test_payment_id_format(self): 172 219 # payment ids have a special format: "PAY_<32 hex digits>" 173 id1 = Payment( ).payment_id220 id1 = Payment(self.payer, self.payable).payment_id 174 221 assert isinstance(id1, basestring) 175 222 assert re.match('PAY_[0-9a-f]{32}', id1) … … 177 224 def test_initial_state_is_unpaid(self): 178 225 # the initial state of payments is <unpaid> 179 p1 = Payment( )226 p1 = Payment(self.payer, self.payable) 180 227 assert p1.state == STATE_UNPAID 181 228 182 229 def test_approve(self): 183 230 # we can approve payments 184 p1 = Payment( )231 p1 = Payment(self.payer, self.payable) 185 232 p1.approve() 186 233 assert p1.state == STATE_PAID … … 190 237 def test_approve_datetime_given(self): 191 238 # we can give a datetime 192 p1 = Payment( )239 p1 = Payment(self.payer, self.payable) 193 240 some_datetime = datetime.datetime(2014, 1, 1, 0, 0, 0) 194 241 p1.approve(payment_date=some_datetime) … … 198 245 # if we do not give a datetime, current one will be used 199 246 current = datetime.datetime.utcnow() 200 p1 = Payment( )247 p1 = Payment(self.payer, self.payable) 201 248 p1.approve() 202 249 assert p1.payment_date >= current … … 204 251 def test_mark_failed(self): 205 252 # we can mark payments as failed 206 p1 = Payment( )253 p1 = Payment(self.payer, self.payable) 207 254 p1.mark_failed() 208 255 assert p1.state == STATE_FAILED 209 256 210 def test_add_payment_item(self):211 # we can add payment items212 p1 = Payment()213 item1 = PaymentItem()214 result = p1.add_payment_item(item1)215 assert len(p1) == 1 # do not make assumptions about result content216 assert isinstance(result, basestring)217 218 def test_add_payment_item_multiple(self):219 # we can add several items220 p1 = Payment()221 item1 = PaymentItem()222 item2 = PaymentItem()223 result1 = p1.add_payment_item(item1)224 result2 = p1.add_payment_item(item2)225 assert len(p1) == 2 # do not make assumptions about result content226 assert isinstance(result1, basestring)227 assert isinstance(result2, basestring)228 229 257 def test_amount(self): 230 258 # the amount of a payment is the sum of amounts of its items 231 p1 = Payment() 232 item1 = PaymentItem() 233 item2 = PaymentItem() 234 p1.add_payment_item(item1) 235 p1.add_payment_item(item2) 236 item1.amount = decimal.Decimal("12.25") 237 item2.amount = decimal.Decimal("0.5") 259 payable = self.payable 260 payable.payment_items[0].amount = decimal.Decimal("12.25") 261 payable.payment_items[1].amount = decimal.Decimal("0.5") 262 p1 = Payment(self.payer, self.payable) 238 263 assert p1.amount == decimal.Decimal("12.75") 239 264 240 265 def test_amount_negative(self): 241 266 # we can sum up negative numbers 242 p1 = Payment() 243 item1 = PaymentItem() 244 item2 = PaymentItem() 245 p1.add_payment_item(item1) 246 p1.add_payment_item(item2) 247 item1.amount = decimal.Decimal("2.21") 248 item2.amount = decimal.Decimal("-3.23") 267 payable = self.payable 268 payable.payment_items[0].amount = decimal.Decimal("2.21") 269 payable.payment_items[1].amount = decimal.Decimal("-3.23") 270 p1 = Payment(self.payer, payable) 249 271 assert p1.amount == decimal.Decimal("-1.02") 250 272 251 273 def test_amount_empty(self): 252 # the amount of zero items is 0.00.253 p 1 = Payment()254 assert p1.amount == decimal.Decimal("0.00")255 assert isinstance(p1.amount, decimal.Decimal)274 # the amount of zero items is None. 275 payable = FakePayable(payment_items=()) 276 p1 = Payment(self.payer, payable) 277 self.assertEqual(p1.amount, decimal.Decimal("0.00")) 256 278 257 279 -
main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments/tests/test_paypal.py
r12498 r12734 1174 1174 def test_store_credit_card_invalid(self): 1175 1175 # an exception is raised with invalid credit cards. 1176 s ite = self.create_site()1176 self.create_site() 1177 1177 service = PayPalCreditCardService() 1178 1178 credit_card = CreditCard( … … 1203 1203 # we can actually create payments 1204 1204 service = PayPalCreditCardService() 1205 s ite = self.create_site()1205 self.create_site() 1206 1206 credit_card = self.get_credit_card() 1207 1207 result = service.store_credit_card(credit_card)
Note: See TracChangeset for help on using the changeset viewer.