def test_enrollment_module_not_configured(self): """Test that lines receive a configuration error status if fulfillment configuration is invalid.""" EnrollmentFulfillmentModule().fulfill_product( self.order, list(self.order.lines.all())) self.assertEqual(LINE.FULFILLMENT_CONFIGURATION_ERROR, self.order.lines.all()[0].status)
def test_enrollment_module_network_error(self): """Test that lines receive a network error status if a fulfillment request experiences a network error.""" EnrollmentFulfillmentModule().fulfill_product( self.order, list(self.order.lines.all())) self.assertEqual(LINE.FULFILLMENT_NETWORK_ERROR, self.order.lines.all()[0].status)
def test_enrollment_module_request_timeout(self): """Test that lines receive a timeout error status if a fulfillment request times out.""" EnrollmentFulfillmentModule().fulfill_product( self.order, list(self.order.lines.all())) self.assertEqual(LINE.FULFILLMENT_TIMEOUT_ERROR, self.order.lines.all()[0].status)
def test_enrollment_module_support(self): """Test that we get the correct values back for supported product lines.""" supported_lines = EnrollmentFulfillmentModule().get_supported_lines( list(self.order.lines.all())) self.assertEqual(1, len(supported_lines))
def test_enrollment_module_fulfill_bad_attributes(self): """Test that use of the Fulfillment Module fails when the product does not have attributes.""" ProductAttribute.objects.get(product_class__name=SEAT_PRODUCT_CLASS_NAME, code='course_key').delete() EnrollmentFulfillmentModule().fulfill_product(self.order, list(self.order.lines.all())) self.assertEqual(LINE.FULFILLMENT_CONFIGURATION_ERROR, self.order.lines.all()[0].status)
def test_enrollment_module_fulfill(self): """Happy path test to ensure we can properly fulfill enrollments.""" httpretty.register_uri(httpretty.POST, get_lms_enrollment_api_url(), status=200, body='{}', content_type=JSON) # Attempt to enroll. with LogCapture(LOGGER_NAME) as logger: EnrollmentFulfillmentModule().fulfill_product( self.order, list(self.order.lines.all())) line = self.order.lines.get() logger.check_present(( LOGGER_NAME, 'INFO', 'line_fulfilled: course_id="{}", credit_provider="{}", mode="{}", order_line_id="{}", ' 'order_number="{}", product_class="{}", user_id="{}"'.format( line.product.attr.course_key, None, mode_for_product(line.product), line.id, line.order.number, line.product.get_product_class().name, line.order.user.id, ))) self.assertEqual(LINE.COMPLETE, line.status) last_request = httpretty.last_request() actual_body = json.loads(last_request.body.decode('utf-8')) actual_headers = last_request.headers expected_body = { 'user': self.order.user.username, 'is_active': True, 'mode': self.certificate_type, 'course_details': { 'course_id': self.course_id, }, 'enrollment_attributes': [{ 'namespace': 'order', 'name': 'order_number', 'value': self.order.number }, { 'namespace': 'order', 'name': 'date_placed', 'value': self.order.date_placed.strftime(ISO_8601_FORMAT) }] } expected_headers = { 'X-Edx-Ga-Client-Id': self.user.tracking_context['ga_client_id'], 'X-Forwarded-For': self.user.tracking_context['lms_ip'], } self.assertDictContainsSubset(expected_headers, actual_headers) self.assertEqual(expected_body, actual_body)
def test_enrollment_module_fulfill_bad_attributes(self): """Test that use of the Fulfillment Module fails when the product does not have attributes.""" # Attempt to enroll without creating the product attributes. EnrollmentFulfillmentModule().fulfill_product(self.order, list(self.order.lines.all())) self.assertEqual(LINE.FULFILLMENT_CONFIGURATION_ERROR, self.order.lines.all()[0].status)
def test_enrollment_module_revoke(self): """Test that use of this method due to "not implemented" error.""" EnrollmentFulfillmentModule().revoke_product(self.order, list(self.order.lines.all()))