Пример #1
0
    def test_ecommerce_refund_not_verified_notification_for_entitlement(
            self, mock_send_notification):
        """
        Note that we are currently notifying Support whenever a refund require approval for entitlements as
        Entitlements are only available in paid modes. This test should be updated if this logic changes
        in the future.

        PROFESSIONAL mode is used here although we never auto approve PROFESSIONAL refunds right now
        """
        httpretty.register_uri(httpretty.POST,
                               settings.ECOMMERCE_API_URL + 'refunds/',
                               status=201,
                               body='[1]',
                               content_type='application/json')
        httpretty.register_uri(httpretty.PUT,
                               settings.ECOMMERCE_API_URL +
                               'refunds/1/process/',
                               status=400,
                               body='{}',
                               content_type='application/json')
        course_entitlement = CourseEntitlementFactory.create(
            mode=CourseMode.PROFESSIONAL)
        refund_success = refund_entitlement(course_entitlement)
        assert mock_send_notification.is_called
        call_args = list(mock_send_notification.call_args)
        assert call_args[0] == (course_entitlement.user, [1])
        assert refund_success
Пример #2
0
 def test_ecommerce_successful_refund(self):
     httpretty.register_uri(httpretty.POST,
                            settings.ECOMMERCE_API_URL + 'refunds/',
                            status=201,
                            body='[1]',
                            content_type='application/json')
     httpretty.register_uri(httpretty.PUT,
                            settings.ECOMMERCE_API_URL +
                            'refunds/1/process/',
                            status=200,
                            body=json.dumps({
                                "id": 9,
                                "created": "2017-12-21T18:23:49.468298Z",
                                "modified": "2017-12-21T18:24:02.741426Z",
                                "total_credit_excl_tax": "100.00",
                                "currency": "USD",
                                "status": "Complete",
                                "order": 15,
                                "user": 5
                            }),
                            content_type='application/json')
     course_entitlement = CourseEntitlementFactory.create(
         mode=CourseMode.VERIFIED)
     refund_success = refund_entitlement(course_entitlement)
     assert refund_success
Пример #3
0
 def test_no_ecommerce_connection_and_failure(self):
     httpretty.register_uri(httpretty.POST,
                            settings.ECOMMERCE_API_URL + 'refunds/',
                            status=404,
                            body='{}',
                            content_type='application/json')
     course_entitlement = CourseEntitlementFactory.create(
         mode=CourseMode.VERIFIED)
     refund_success = refund_entitlement(course_entitlement)
     assert not refund_success
Пример #4
0
 def refund(self):
     """
     Initiate refund process for the entitlement.
     """
     refund_successful = refund_entitlement(course_entitlement=self)
     if not refund_successful:
         # This state is achieved in most cases by a failure in the ecommerce service to process the refund.
         log.warn(
             u'Entitlement Refund failed for Course Entitlement [%s], alert User',
             self.uuid)
         # Force Transaction reset with an Integrity error exception, this will revert all previous transactions
         raise IntegrityError
Пример #5
0
 def test_ecommerce_refund_failed_process_notification_sent(
         self, mock_send_notification):
     httpretty.register_uri(httpretty.POST,
                            settings.ECOMMERCE_API_URL + 'refunds/',
                            status=201,
                            body='[1]',
                            content_type='application/json')
     httpretty.register_uri(httpretty.PUT,
                            settings.ECOMMERCE_API_URL +
                            'refunds/1/process/',
                            status=400,
                            body='{}',
                            content_type='application/json')
     course_entitlement = CourseEntitlementFactory.create(
         mode=CourseMode.VERIFIED)
     refund_success = refund_entitlement(course_entitlement)
     assert mock_send_notification.is_called
     call_args = list(mock_send_notification.call_args)
     assert call_args[0] == (course_entitlement.user, [1])
     assert refund_success
Пример #6
0
def _process_revoke_and_unenroll_entitlement(course_entitlement,
                                             is_refund=False):
    """
    Process the revoke of the Course Entitlement and refund if needed

    Arguments:
        course_entitlement: Course Entitlement Object

        is_refund (bool): True if a refund should be processed

    Exceptions:
        IntegrityError if there is an issue that should reverse the database changes
    """
    if course_entitlement.expired_at is None:
        course_entitlement.expired_at = timezone.now()
        log.info('Set expired_at to [%s] for course entitlement [%s]',
                 course_entitlement.expired_at, course_entitlement.uuid)
        course_entitlement.save()

    if course_entitlement.enrollment_course_run is not None:
        course_id = course_entitlement.enrollment_course_run.course_id
        _unenroll_entitlement(course_entitlement, course_id)
        log.info(
            'Unenrolled user [%s] from course run [%s] as part of revocation of course entitlement [%s]',
            course_entitlement.user.username, course_id,
            course_entitlement.uuid)

    if is_refund:
        refund_successful = refund_entitlement(
            course_entitlement=course_entitlement)
        if not refund_successful:
            # This state is achieved in most cases by a failure in the ecommerce service to process the refund.
            log.warn(
                'Entitlement Refund failed for Course Entitlement [%s], alert User',
                course_entitlement.uuid)
            # Force Transaction reset with an Integrity error exception, this will revert all previous transactions
            raise IntegrityError
Пример #7
0
 def test_ecommerce_service_not_configured(self, mock_commerce_configured):
     course_entitlement = CourseEntitlementFactory.create(
         mode=CourseMode.VERIFIED)
     refund_success = refund_entitlement(course_entitlement)
     assert mock_commerce_configured.is_called
     assert not refund_success