From a93faad78bac5764fb19ba5347c0faa823cfc684 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Mon, 10 Nov 2014 18:57:23 -0500 Subject: [PATCH] try importing the exact references we need rather than deferencing it from the djangoapp module --- .../courseware/tests/test_microsites.py | 33 ++++++++++++++++++- lms/djangoapps/courseware/views.py | 5 ++- .../shoppingcart/context_processor.py | 9 ++--- lms/envs/test.py | 2 ++ lms/templates/courseware/course_about.html | 9 ++--- 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/lms/djangoapps/courseware/tests/test_microsites.py b/lms/djangoapps/courseware/tests/test_microsites.py index 2f34de8e14..b9a916dd8c 100644 --- a/lms/djangoapps/courseware/tests/test_microsites.py +++ b/lms/djangoapps/courseware/tests/test_microsites.py @@ -10,7 +10,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from helpers import LoginEnrollmentTestCase from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE - +from course_modes.models import CourseMode from xmodule.course_module import ( CATALOG_VISIBILITY_CATALOG_AND_ABOUT, CATALOG_VISIBILITY_NONE) @@ -55,6 +55,7 @@ class TestMicrosites(ModuleStoreTestCase, LoginEnrollmentTestCase): self.course_with_visibility = CourseFactory.create( display_name='visible_course', org='TestMicrositeX', + course="foo", catalog_visibility=CATALOG_VISIBILITY_CATALOG_AND_ABOUT, ) @@ -189,3 +190,33 @@ class TestMicrosites(ModuleStoreTestCase, LoginEnrollmentTestCase): url = reverse('about_course', args=[self.course_hidden_visibility.id.to_deprecated_string()]) resp = self.client.get(url, HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME) self.assertEqual(resp.status_code, 404) + + @override_settings(SITE_NAME=settings.MICROSITE_TEST_HOSTNAME) + def test_paid_course_registration(self): + """ + Make sure that Microsite overrides on the ENABLE_SHOPPING_CART and + ENABLE_PAID_COURSE_ENROLLMENTS are honored + """ + course_mode = CourseMode( + course_id=self.course_with_visibility.id, + mode_slug="honor", + mode_display_name="honor cert", + min_price=10, + ) + course_mode.save() + + # first try on the non microsite, which + # should pick up the global configuration (where ENABLE_PAID_COURSE_REGISTRATIONS = False) + url = reverse('about_course', args=[self.course_with_visibility.id.to_deprecated_string()]) + resp = self.client.get(url) + self.assertEqual(resp.status_code, 200) + self.assertIn("Register for {}".format(self.course_with_visibility.id.course), resp.content) + self.assertNotIn("Add {} to Cart ($10)".format(self.course_with_visibility.id.course), resp.content) + + # now try on the microsite + url = reverse('about_course', args=[self.course_with_visibility.id.to_deprecated_string()]) + resp = self.client.get(url, HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME) + self.assertEqual(resp.status_code, 200) + self.assertNotIn("Register for {}".format(self.course_with_visibility.id.course), resp.content) + self.assertIn("Add {} to Cart ($10)".format(self.course_with_visibility.id.course), resp.content) + self.assertIn('$("#add_to_cart_post").click', resp.content) diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index cf44331ec7..2ecaab3d37 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -733,7 +733,8 @@ def course_about(request, course_id): in_cart = False reg_then_add_to_cart_link = "" - if (is_shopping_cart_enabled()): + _is_shopping_cart_enabled = is_shopping_cart_enabled() + if (_is_shopping_cart_enabled): registration_price = CourseMode.min_course_price_for_currency(course_key, settings.PAID_COURSE_REGISTRATION_CURRENCY[0]) if request.user.is_authenticated(): @@ -775,6 +776,8 @@ def course_about(request, course_id): # We do not want to display the internal courseware header, which is used when the course is found in the # context. This value is therefor explicitly set to render the appropriate header. 'disable_courseware_header': True, + 'is_shopping_cart_enabled': _is_shopping_cart_enabled, + 'cart_link': reverse('shoppingcart.views.show_cart'), }) diff --git a/lms/djangoapps/shoppingcart/context_processor.py b/lms/djangoapps/shoppingcart/context_processor.py index 20e096155b..5fc9439025 100644 --- a/lms/djangoapps/shoppingcart/context_processor.py +++ b/lms/djangoapps/shoppingcart/context_processor.py @@ -6,7 +6,8 @@ navigation. We want to do this in the context_processor to 2) because navigation.html is "called" by being included in other templates, there's no "views.py" to put this. """ -import shoppingcart +from .models import Order, PaidCourseRegistration, CourseRegCodeItem +from .utils import is_shopping_cart_enabled def user_has_cart_context_processor(request): @@ -19,11 +20,11 @@ def user_has_cart_context_processor(request): # user is logged in and request.user.is_authenticated() and # do we have the feature turned on - shoppingcart.utils.is_shopping_cart_enabled() and + is_shopping_cart_enabled() and # user's cart has PaidCourseRegistrations - shoppingcart.models.Order.user_cart_has_items( + Order.user_cart_has_items( request.user, - [shoppingcart.models.PaidCourseRegistration, shoppingcart.models.CourseRegCodeItem] + [PaidCourseRegistration, CourseRegCodeItem] ) ) diff --git a/lms/envs/test.py b/lms/envs/test.py index 049fdf7b89..2810337e63 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -352,6 +352,8 @@ MICROSITE_CONFIGURATION = { "ALWAYS_REDIRECT_HOMEPAGE_TO_DASHBOARD_FOR_AUTHENTICATED_USER": False, "COURSE_CATALOG_VISIBILITY_PERMISSION": "see_in_catalog", "COURSE_ABOUT_VISIBILITY_PERMISSION": "see_about_page", + "ENABLE_SHOPPING_CART": True, + "ENABLE_PAID_COURSE_REGISTRATION": True, }, "default": { "university": "default_university", diff --git a/lms/templates/courseware/course_about.html b/lms/templates/courseware/course_about.html index 77063c099c..0859f2247b 100644 --- a/lms/templates/courseware/course_about.html +++ b/lms/templates/courseware/course_about.html @@ -4,11 +4,6 @@ from courseware.courses import course_image_url, get_course_about_section from django.conf import settings from edxmako.shortcuts import marketing_link - - if settings.FEATURES.get('ENABLE_SHOPPING_CART'): - cart_link = reverse('shoppingcart.views.show_cart') - else: - cart_link = "" %> <%namespace name='static' file='../static_content.html'/> <%! from microsite_configuration import microsite %> @@ -42,7 +37,7 @@ event.preventDefault(); }); - % if settings.FEATURES.get('ENABLE_SHOPPING_CART') and settings.FEATURES.get('ENABLE_PAID_COURSE_REGISTRATION'): + % if is_shopping_cart_enabled: add_course_complete_handler = function(jqXHR, textStatus) { if (jqXHR.status == 200) { location.href = "${cart_link}"; @@ -162,7 +157,7 @@ ## so that they can register and become a real user that can enroll. % elif not is_shib_course and not can_enroll: ${_("Enrollment is Closed")} - %elif settings.FEATURES.get('ENABLE_PAID_COURSE_REGISTRATION') and registration_price: + %elif is_shopping_cart_enabled and registration_price: <% if user.is_authenticated(): reg_href = "#"