Пример #1
0
    def test_entitlement_module_revoke(self):
        """ Test to revoke a Course Entitlement. """
        self.mock_access_token_response()
        httpretty.register_uri(httpretty.POST,
                               get_lms_entitlement_api_url() + 'entitlements/',
                               status=200,
                               body=json.dumps(self.return_data),
                               content_type='application/json')

        httpretty.register_uri(httpretty.DELETE,
                               get_lms_entitlement_api_url() +
                               'entitlements/111-222-333/',
                               status=200,
                               body={},
                               content_type='application/json')

        line = self.order.lines.first()

        # Fulfill order first to ensure we have all the line attributes set
        CourseEntitlementFulfillmentModule().fulfill_product(
            self.order, list(self.order.lines.all()))

        with LogCapture(LOGGER_NAME) as l:
            self.assertTrue(
                CourseEntitlementFulfillmentModule().revoke_line(line))

            l.check((
                LOGGER_NAME, 'INFO',
                'line_revoked: UUID="{}", certificate_type="{}", order_line_id="{}", order_number="{}", '
                'product_class="{}", user_id="{}"'.format(
                    line.product.attr.UUID,
                    getattr(line.product.attr, 'certificate_type',
                            ''), line.id, line.order.number,
                    line.product.get_product_class().name,
                    line.order.user.id)))
Пример #2
0
    def test_entitlement_supported_line(self):
        """ Test that support_line returns True for Course Entitlement lines. """
        line = self.order.lines.first()
        supports_line = CourseEntitlementFulfillmentModule().supports_line(line)
        self.assertTrue(supports_line)

        order = create_order()
        unsupported_line = order.lines.first()
        supports_line = CourseEntitlementFulfillmentModule().supports_line(unsupported_line)
        self.assertFalse(supports_line)
Пример #3
0
    def test_entitlement_module_fulfill_connection_error(self):
        """Test Course Entitlement Fulfillment with exception when posting to LMS."""

        self.mock_access_token_response()
        httpretty.register_uri(httpretty.POST,
                               get_lms_entitlement_api_url() + 'entitlements/',
                               status=408,
                               body={},
                               content_type='application/json')
        logger_name = 'ecommerce.extensions.fulfillment.modules'

        line = self.order.lines.first()

        with LogCapture(logger_name) as l:
            CourseEntitlementFulfillmentModule().fulfill_product(
                self.order, list(self.order.lines.all()))
            self.assertEqual(LINE.FULFILLMENT_SERVER_ERROR,
                             self.order.lines.all()[0].status)
            l.check((
                logger_name, 'INFO',
                'Attempting to fulfill "Course Entitlement" product types for order [{}]'
                .format(self.order.number)
            ), (
                logger_name, 'ERROR',
                'Unable to fulfill line [{}] of order [{}]'.format(
                    line.id, self.order.number)
            ), (logger_name, 'INFO',
                'Finished fulfilling "Course Entitlement" product types for order [{}]'
                .format(self.order.number)))
Пример #4
0
    def test_entitlement_module_fulfill(self):
        """ Test to ensure we can properly fulfill course entitlements. """

        self.mock_access_token_response()
        httpretty.register_uri(httpretty.POST,
                               get_lms_entitlement_api_url() + 'entitlements/',
                               status=200,
                               body=json.dumps(self.return_data),
                               content_type='application/json')

        # Attempt to fulfill entitlement.
        with LogCapture(LOGGER_NAME) as l:
            CourseEntitlementFulfillmentModule().fulfill_product(
                self.order, list(self.order.lines.all()))

            line = self.order.lines.get()
            l.check(
                (LOGGER_NAME, 'INFO',
                 'line_fulfilled: UUID="{}", mode="{}", order_line_id="{}", '
                 'order_number="{}", product_class="{}", user_id="{}"'.format(
                     line.product.attr.UUID,
                     mode_for_product(line.product),
                     line.id,
                     line.order.number,
                     line.product.get_product_class().name,
                     line.order.user.id,
                 )))

            course_entitlement_uuid = line.attributes.get(
                option=self.entitlement_option).value
            self.assertEqual(course_entitlement_uuid, '111-222-333')
            self.assertEqual(LINE.COMPLETE, line.status)
Пример #5
0
 def test_entitlement_module_fulfill_bad_attributes(self):
     """ Test the Entitlement Fulfillment Module fails when the product does not have proper attributes. """
     ProductAttribute.objects.get(
         product_class__name=COURSE_ENTITLEMENT_PRODUCT_CLASS_NAME,
         code='UUID').delete()
     CourseEntitlementFulfillmentModule().fulfill_product(
         self.order, list(self.order.lines.all()))
     self.assertEqual(LINE.FULFILLMENT_CONFIGURATION_ERROR,
                      self.order.lines.all()[0].status)
Пример #6
0
    def test_entitlement_module_revoke_error(self):
        """ Test to handle an error when revoking a Course Entitlement. """
        self.mock_access_token_response()

        httpretty.register_uri(httpretty.DELETE, get_lms_entitlement_api_url() +
                               'entitlements/111-222-333/', status=500, body={}, content_type='application/json')

        line = self.order.lines.first()

        self.assertFalse(CourseEntitlementFulfillmentModule().revoke_line(line))
Пример #7
0
    def test_entitlement_module_fulfill_network_error(self):
        """Test Course Entitlement Fulfillment with exceptions(Timeout/ConnectionError) when posting to LMS."""

        logger_name = 'ecommerce.extensions.fulfillment.modules'

        line = self.order.lines.first()
        with mock.patch('edx_rest_api_client.client.EdxRestApiClient',
                        side_effect=ConnectionError):
            with LogCapture(logger_name) as logger:
                CourseEntitlementFulfillmentModule().fulfill_product(self.order, list(self.order.lines.all()))
                self.assertEqual(LINE.FULFILLMENT_NETWORK_ERROR, self.order.lines.all()[0].status)
                logger.check_present(
                    (logger_name, 'INFO', 'Attempting to fulfill "Course Entitlement" product types for order [{}]'.
                     format(self.order.number)),
                    (logger_name, 'ERROR', 'Unable to fulfill line [{}] of order [{}] due to a network problem'.
                     format(line.id, self.order.number)),
                    (logger_name, 'INFO', 'Finished fulfilling "Course Entitlement" product types for order [{}]'.
                     format(self.order.number))
                )
Пример #8
0
 def test_get_entitlement_supported_lines(self):
     """ Test that Course Entitlement products lines are returned. """
     lines = self.order.lines.all()
     supported_lines = CourseEntitlementFulfillmentModule(
     ).get_supported_lines(lines)
     self.assertListEqual(supported_lines, list(lines))