Ejemplo n.º 1
0
 def setUp(self):
     super(RefundTestMixin, self).setUp()
     self.course_id = u'edX/DemoX/Demo_Course'
     self.course = CourseFactory(self.course_id, u'edX Demó Course')
     self.honor_product = self.course.add_mode('honor', 0)
     self.verified_product = self.course.add_mode('verified', Decimal(10.00), id_verification_required=True)
Ejemplo n.º 2
0
class RefundTestMixin(object):
    def setUp(self):
        super(RefundTestMixin, self).setUp()
        self.course_id = u'edX/DemoX/Demo_Course'
        self.course = CourseFactory(self.course_id, u'edX Demó Course')
        self.honor_product = self.course.add_mode('honor', 0)
        self.verified_product = self.course.add_mode('verified', Decimal(10.00), id_verification_required=True)

    def create_order(self, user=None, multiple_lines=False, free=False):
        user = user or self.user
        basket = BasketFactory(owner=user)

        if multiple_lines:
            basket.add_product(self.verified_product)
            basket.add_product(self.honor_product)
        elif free:
            basket.add_product(self.honor_product)
        else:
            basket.add_product(self.verified_product)

        order = create_order(basket=basket, user=user)
        order.status = ORDER.COMPLETE
        order.save()
        return order

    def assert_refund_matches_order(self, refund, order):
        """ Verify the refund corresponds to the given order. """
        self.assertEqual(refund.order, order)
        self.assertEqual(refund.user, order.user)
        self.assertEqual(refund.status, settings.OSCAR_INITIAL_REFUND_STATUS)
        self.assertEqual(refund.total_credit_excl_tax, order.total_excl_tax)
        self.assertEqual(refund.lines.count(), order.lines.count())

        refund_lines = refund.lines.all()
        order_lines = order.lines.all().order_by('refund_lines')
        for refund_line, order_line in zip(refund_lines, order_lines):
            self.assertEqual(refund_line.status, settings.OSCAR_INITIAL_REFUND_LINE_STATUS)
            self.assertEqual(refund_line.order_line, order_line)
            self.assertEqual(refund_line.line_credit_excl_tax, order_line.line_price_excl_tax)
            self.assertEqual(refund_line.quantity, order_line.quantity)

    def create_refund(self, processor_name=DummyProcessor.NAME):
        refund = RefundFactory()
        order = refund.order
        source_type, __ = SourceType.objects.get_or_create(name=processor_name)
        Source.objects.create(source_type=source_type, order=order, currency=refund.currency,
                              amount_allocated=order.total_incl_tax, amount_debited=order.total_incl_tax)

        return refund

    @override_settings(PAYMENT_PROCESSORS=['ecommerce.extensions.payment.tests.processors.DummyProcessor'])
    def approve(self, refund):
        def _revoke_lines(r):
            for line in r.lines.all():
                line.set_status(REFUND_LINE.COMPLETE)

            r.set_status(REFUND.COMPLETE)

        with mock.patch.object(Refund, '_revoke_lines', side_effect=_revoke_lines, autospec=True):
            with mock_signal_receiver(post_refund) as receiver:
                self.assertEqual(receiver.call_count, 0)
                self.assertTrue(refund.approve())
                self.assertEqual(receiver.call_count, 1)