diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index e87c5441de..c0b4b86a9e 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -450,7 +450,7 @@ class ViewsTestCase(ModuleStoreTestCase): self.assertEqual(response.status_code, 200) self.assertIn(in_cart_span, response.content) - def assert_enrollment_link_present(self, is_anonymous, _id=False): + def assert_enrollment_link_present(self, is_anonymous): """ Prepare ecommerce checkout data and assert if the ecommerce link is contained in the response. @@ -474,17 +474,13 @@ class ViewsTestCase(ModuleStoreTestCase): # Set up the edxmako middleware for this request to create the RequestContext mako_middleware_process_request(request) - # Construct the link for each of the four possibilities: - # (1) shopping cart is disabled and the user is not logged in - # (2) shopping cart is disabled and the user is logged in - # (3) shopping cart is enabled and the user is not logged in - # (4) shopping cart is enabled and the user is logged in - href = '' if _id else ">" - ) + # Generate the course about page content response = views.course_about(request, unicode(course.id)) + + # Construct the link according the following scenarios and verify its presence in the response: + # (1) shopping cart is enabled and the user is not logged in + # (2) shopping cart is enabled and the user is logged in + href = ''.format(uri_stem=checkout_page, sku=sku) self.assertEqual(response.status_code, 200) self.assertIn(href, response.content) @@ -500,8 +496,13 @@ class ViewsTestCase(ModuleStoreTestCase): @unittest.skipUnless(settings.FEATURES.get('ENABLE_SHOPPING_CART'), 'Shopping Cart not enabled in settings') @patch.dict(settings.FEATURES, {'ENABLE_PAID_COURSE_REGISTRATION': True}) def test_ecommerce_checkout_shopping_cart_enabled(self, is_anonymous): + """ + Two scenarios are being validated here -- authenticated/known user and unauthenticated/anonymous user + For a known user we expect the checkout link to point to Otto in a scenario where the CommerceConfiguration + is active and the course mode is PROFESSIONAL. + """ if not is_anonymous: - self.assert_enrollment_link_present(is_anonymous=is_anonymous, _id=True) + self.assert_enrollment_link_present(is_anonymous=is_anonymous) else: request = self.request_factory.get("foo") self.assertEqual(EcommerceService().is_enabled(AnonymousUser()), False) diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index adbf0e0013..69890d894d 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -575,15 +575,17 @@ def course_about(request, course_id): # If the ecommerce checkout flow is enabled and the mode of the course is # professional or no id professional, we construct links for the enrollment # button to add the course to the ecommerce basket. + ecomm_service = EcommerceService() + ecommerce_checkout = ecomm_service.is_enabled(request.user) ecommerce_checkout_link = '' ecommerce_bulk_checkout_link = '' professional_mode = None - ecomm_service = EcommerceService() is_professional_mode = CourseMode.PROFESSIONAL in modes or CourseMode.NO_ID_PROFESSIONAL_MODE in modes - if ecomm_service.is_enabled(request.user) and (is_professional_mode): + if ecommerce_checkout and is_professional_mode: professional_mode = modes.get(CourseMode.PROFESSIONAL, '') or \ modes.get(CourseMode.NO_ID_PROFESSIONAL_MODE, '') - ecommerce_checkout_link = ecomm_service.checkout_page_url(professional_mode.sku) + if professional_mode.sku: + ecommerce_checkout_link = ecomm_service.checkout_page_url(professional_mode.sku) if professional_mode.bulk_sku: ecommerce_bulk_checkout_link = ecomm_service.checkout_page_url(professional_mode.bulk_sku) @@ -593,7 +595,9 @@ def course_about(request, course_id): settings.PAID_COURSE_REGISTRATION_CURRENCY[0] ) course_price = get_cosmetic_display_price(course, registration_price) - can_add_course_to_cart = _is_shopping_cart_enabled and registration_price + + # Determine which checkout workflow to use -- LMS shoppingcart or Otto basket + can_add_course_to_cart = _is_shopping_cart_enabled and registration_price and not ecommerce_checkout_link # Used to provide context to message to student if enrollment not allowed can_enroll = bool(has_access(request.user, 'enroll', course)) @@ -624,7 +628,7 @@ def course_about(request, course_id): 'is_cosmetic_price_enabled': settings.FEATURES.get('ENABLE_COSMETIC_DISPLAY_PRICE'), 'course_price': course_price, 'in_cart': in_cart, - 'ecommerce_checkout': ecomm_service.is_enabled(request.user), + 'ecommerce_checkout': ecommerce_checkout, 'ecommerce_checkout_link': ecommerce_checkout_link, 'ecommerce_bulk_checkout_link': ecommerce_bulk_checkout_link, 'professional_mode': professional_mode,