def test_success(self): product_price = 100 percentage_discount = 10 product = ProductFactory(stockrecords__price_excl_tax=product_price) voucher, product = prepare_voucher( _range=RangeFactory(products=[product]), benefit_value=percentage_discount) self.request.user = UserFactory() basket = prepare_basket(self.request, [product], voucher) ppr = PaymentProcessorResponse.objects.create(basket=basket, transaction_id='abc', processor_name='paypal') with mock.patch.object(Paypal, 'issue_credit') as mock_issue_credit: mock_issue_credit.return_value = None assert refund_basket_transactions(self.site, [basket.id]) == ( 1, 0, ) total = product_price * (100 - percentage_discount) / 100. mock_issue_credit.assert_called_once_with(basket.order_number, basket, ppr.transaction_id, total, basket.currency)
def test_with_expired_voucher(self): """ Test creates order when called with basket with expired voucher""" basket = create_basket() product = ProductFactory(stockrecords__price_excl_tax=100, stockrecords__partner=self.partner, stockrecords__price_currency='USD') voucher, product = prepare_voucher( code='TEST101', _range=RangeFactory(products=[product])) self.request.user = UserFactory() basket.add_product(product) basket.vouchers.add(voucher) basket.status = 'Frozen' basket.save() PaymentProcessorResponse.objects.create(basket=basket, transaction_id='PAY-123', processor_name='paypal', response={'state': 'approved'}) with mock.patch('oscar.apps.offer.applicator.Applicator.apply', side_effect=ValueError): assert FulfillFrozenBaskets().fulfill_basket(basket.id, self.site)
def test_success_with_cybersource(self): """ Test basket with cybersource payment basket.""" product_price = 100 percentage_discount = 10 product = ProductFactory(stockrecords__price_excl_tax=product_price) voucher, product = prepare_voucher( _range=RangeFactory(products=[product]), benefit_value=percentage_discount) self.request.user = UserFactory() basket = prepare_basket(self.request, [product], voucher) basket.status = 'Frozen' basket.save() card_number = '4111111111111111' response = { 'req_card_number': card_number, 'req_card_type': CARD_TYPES['visa']['cybersource_code'], u'decision': u'ACCEPT', } PaymentProcessorResponse.objects.create(basket=basket, transaction_id='abc', processor_name='cybersource', response=response) assert FulfillFrozenBaskets().fulfill_basket(basket.id, self.site) order = Order.objects.get(number=basket.order_number) assert order.status == 'Complete' total = product_price * (100 - percentage_discount) / 100. Source.objects.get(source_type__name=Cybersource.NAME, currency=order.currency, amount_allocated=total, amount_debited=total, label=card_number, card_type='visa') PaymentEvent.objects.get(event_type__name=PaymentEventTypeName.PAID, amount=total, processor_name=Cybersource.NAME)
def setUp(self): super(OfferDecoratorTests, self).setUp() self.condition = ConditionFactory() self.offer = ConditionalOfferFactory(condition=self.condition, site=self.site) self.user = UserFactory()