From f1ebee433f6aba40a3ad5f36f406cb9f65815d3d Mon Sep 17 00:00:00 2001 From: Michael Frey Date: Mon, 22 Feb 2016 07:58:11 -0500 Subject: [PATCH 1/3] Only allow ecommerce checkout if user is also activated --- common/djangoapps/course_modes/views.py | 2 +- common/djangoapps/student/views.py | 2 +- lms/djangoapps/commerce/tests/test_utils.py | 12 +++++++++--- lms/djangoapps/commerce/utils.py | 7 ++++--- lms/djangoapps/courseware/tests/test_views.py | 15 +++++++++++++-- lms/djangoapps/courseware/views.py | 4 ++-- 6 files changed, 30 insertions(+), 12 deletions(-) diff --git a/common/djangoapps/course_modes/views.py b/common/djangoapps/course_modes/views.py index eb23262f21..d40bb7d41c 100644 --- a/common/djangoapps/course_modes/views.py +++ b/common/djangoapps/course_modes/views.py @@ -151,7 +151,7 @@ class ChooseModeView(View): if verified_mode.sku: ecommerce_service = EcommerceService() - context["use_ecommerce_payment_flow"] = ecommerce_service.is_enabled() + context["use_ecommerce_payment_flow"] = ecommerce_service.is_enabled(request) context["ecommerce_payment_page"] = ecommerce_service.payment_page_url() context["sku"] = verified_mode.sku diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 95506455b5..21097d6377 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -739,7 +739,7 @@ def dashboard(request): } ecommerce_service = EcommerceService() - if ecommerce_service.is_enabled(): + if ecommerce_service.is_enabled(request): context.update({ 'use_ecommerce_payment_flow': True, 'ecommerce_payment_page': ecommerce_service.payment_page_url(), diff --git a/lms/djangoapps/commerce/tests/test_utils.py b/lms/djangoapps/commerce/tests/test_utils.py index 90c446982e..8f343014c6 100644 --- a/lms/djangoapps/commerce/tests/test_utils.py +++ b/lms/djangoapps/commerce/tests/test_utils.py @@ -5,6 +5,8 @@ from mock import patch from commerce.utils import audit_log, EcommerceService from commerce.models import CommerceConfiguration +from django.test.client import RequestFactory +from student.tests.factories import UserFactory class AuditLogTests(TestCase): @@ -25,6 +27,10 @@ class EcommerceServiceTests(TestCase): SKU = 'TESTSKU' def setUp(self): + self.request_factory = RequestFactory() + self.user = UserFactory.create() + self.request = self.request_factory.get("foo") + self.request.user = self.user CommerceConfiguration.objects.create( checkout_on_ecommerce_service=True, single_course_checkout_page='/test_basket/' @@ -33,20 +39,20 @@ class EcommerceServiceTests(TestCase): def test_is_enabled(self): """Verify that is_enabled() returns True when ecomm checkout is enabled. """ - is_enabled = EcommerceService().is_enabled() + is_enabled = EcommerceService().is_enabled(self.request) self.assertTrue(is_enabled) config = CommerceConfiguration.current() config.checkout_on_ecommerce_service = False config.save() - is_not_enabled = EcommerceService().is_enabled() + is_not_enabled = EcommerceService().is_enabled(self.request) self.assertFalse(is_not_enabled) @patch('openedx.core.djangoapps.theming.helpers.is_request_in_themed_site') def test_is_enabled_for_microsites(self, is_microsite): """Verify that is_enabled() returns False if used for a microsite.""" is_microsite.return_value = True - is_not_enabled = EcommerceService().is_enabled() + is_not_enabled = EcommerceService().is_enabled(self.request) self.assertFalse(is_not_enabled) @override_settings(ECOMMERCE_PUBLIC_URL_ROOT='http://ecommerce_url') diff --git a/lms/djangoapps/commerce/utils.py b/lms/djangoapps/commerce/utils.py index 00ff3bb99f..e07ec1d9b7 100644 --- a/lms/djangoapps/commerce/utils.py +++ b/lms/djangoapps/commerce/utils.py @@ -44,9 +44,10 @@ class EcommerceService(object): def __init__(self): self.config = CommerceConfiguration.current() - def is_enabled(self): - """ Check if the service is enabled and that the site is not a microsite. """ - return self.config.checkout_on_ecommerce_service and not helpers.is_request_in_themed_site() + def is_enabled(self, request): + """ Check if the user is activated, if the service is enabled and that the site is not a microsite. """ + return (request.user.is_active and self.config.checkout_on_ecommerce_service and not + helpers.is_request_in_themed_site()) def payment_page_url(self): """ Return the URL for the checkout page. diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 889fafa4f6..e26f4470a1 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -39,6 +39,7 @@ from courseware.testutils import RenderXBlockTestMixin from courseware.tests.factories import StudentModuleFactory from courseware.user_state_client import DjangoXBlockUserStateClient from edxmako.tests import mako_middleware_process_request +from lms.djangoapps.commerce.utils import EcommerceService # pylint: disable=import-error from milestones.tests.utils import MilestonesTestCaseMixin from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration from openedx.core.lib.gating import api as gating_api @@ -271,13 +272,23 @@ class ViewsTestCase(ModuleStoreTestCase): @ddt.data(True, False) def test_ecommerce_checkout(self, is_anonymous): - self.assert_enrollment_link_present(is_anonymous=is_anonymous) + if not is_anonymous: + self.assert_enrollment_link_present(is_anonymous=is_anonymous) + else: + request = self.request_factory.get("foo") + request.user = AnonymousUser() + self.assertEqual(EcommerceService().is_enabled(request), False) @ddt.data(True, False) @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): - self.assert_enrollment_link_present(is_anonymous=is_anonymous, _id=True) + if not is_anonymous: + self.assert_enrollment_link_present(is_anonymous=is_anonymous, _id=True) + else: + request = self.request_factory.get("foo") + request.user = AnonymousUser() + self.assertEqual(EcommerceService().is_enabled(request), False) def test_user_groups(self): # depreciated function diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index 60e16b873e..73a43345c1 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -906,7 +906,7 @@ def course_about(request, course_id): ecommerce_checkout_link = '' professional_mode = '' ecomm_service = EcommerceService() - if ecomm_service.is_enabled() and ( + if ecomm_service.is_enabled(request) and ( CourseMode.PROFESSIONAL in modes or CourseMode.NO_ID_PROFESSIONAL_MODE in modes ): professional_mode = modes.get(CourseMode.PROFESSIONAL, '') or \ @@ -944,7 +944,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(), + 'ecommerce_checkout': ecomm_service.is_enabled(request), 'ecommerce_checkout_link': ecommerce_checkout_link, 'professional_mode': professional_mode, 'reg_then_add_to_cart_link': reg_then_add_to_cart_link, From 2cb48742b23d570f173dc046095753fd2f5a0101 Mon Sep 17 00:00:00 2001 From: Adam Palay Date: Mon, 22 Feb 2016 15:49:39 -0500 Subject: [PATCH 2/3] mark discussion deletion test as flaky --- common/test/acceptance/tests/discussion/test_discussion.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/test/acceptance/tests/discussion/test_discussion.py b/common/test/acceptance/tests/discussion/test_discussion.py index 2eed018bdc..f4510760d5 100644 --- a/common/test/acceptance/tests/discussion/test_discussion.py +++ b/common/test/acceptance/tests/discussion/test_discussion.py @@ -5,6 +5,7 @@ Tests for discussion pages import datetime from uuid import uuid4 +from flaky import flaky from nose.plugins.attrib import attr from pytz import UTC @@ -400,6 +401,7 @@ class DiscussionCommentDeletionTest(BaseDiscussionTestCase): ) view.push() + @flaky # TODO: TNL-4151 def test_comment_deletion_as_student(self): self.setup_user() self.setup_view() From c63dcf0dfe7e79781fa4b0f83db63e74d51c519c Mon Sep 17 00:00:00 2001 From: Adam Palay Date: Mon, 22 Feb 2016 10:08:55 -0500 Subject: [PATCH 3/3] render mathjax in svg by default (TNL-4145) mathjax preview should be inline by default --- cms/static/cms/js/require-config.js | 2 +- cms/static/coffee/spec/main.coffee | 2 +- cms/static/coffee/spec/main_squire.coffee | 2 +- common/djangoapps/terrain/ui_helpers.py | 2 +- common/lib/capa/capa/templates/formulaequationinput.html | 2 +- common/static/js/capa/spec/formula_equation_preview_spec.js | 4 ++-- common/static/js/capa/src/formula_equation_preview.js | 2 +- common/templates/mathjax_include.html | 2 +- common/test/acceptance/pages/lms/discussion.py | 2 +- common/test/acceptance/pages/lms/problem.py | 4 ++-- common/test/acceptance/pages/lms/tab_nav.py | 2 +- lms/static/js/spec/main.js | 2 +- 12 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cms/static/cms/js/require-config.js b/cms/static/cms/js/require-config.js index fc08e4fe0c..43a497049e 100644 --- a/cms/static/cms/js/require-config.js +++ b/cms/static/cms/js/require-config.js @@ -91,7 +91,7 @@ // end of Annotation tool files // externally hosted files - "mathjax": "//cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_CHTML&delayStartupUntil=configured", // jshint ignore:line + "mathjax": "//cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured", // jshint ignore:line "youtube": [ // youtube URL does not end in ".js". We add "?noext" to the path so // that require.js adds the ".js" to the query component of the URL, diff --git a/cms/static/coffee/spec/main.coffee b/cms/static/coffee/spec/main.coffee index 84ddaafa96..985f5e67ad 100644 --- a/cms/static/coffee/spec/main.coffee +++ b/cms/static/coffee/spec/main.coffee @@ -51,7 +51,7 @@ requirejs.config({ "URI": "xmodule_js/common_static/js/vendor/URI.min", "mock-ajax": "xmodule_js/common_static/js/vendor/mock-ajax", - "mathjax": "//cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_CHTML&delayStartupUntil=configured", + "mathjax": "//cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured", "youtube": "//www.youtube.com/player_api?noext", "coffee/src/ajax_prefix": "xmodule_js/common_static/coffee/src/ajax_prefix", diff --git a/cms/static/coffee/spec/main_squire.coffee b/cms/static/coffee/spec/main_squire.coffee index bc0607996b..d09cdfd393 100644 --- a/cms/static/coffee/spec/main_squire.coffee +++ b/cms/static/coffee/spec/main_squire.coffee @@ -42,7 +42,7 @@ requirejs.config({ "domReady": "xmodule_js/common_static/js/vendor/domReady", "URI": "xmodule_js/common_static/js/vendor/URI.min", - "mathjax": "//cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_CHTML&delayStartupUntil=configured", + "mathjax": "//cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured", "youtube": "//www.youtube.com/player_api?noext", "coffee/src/ajax_prefix": "xmodule_js/common_static/coffee/src/ajax_prefix" diff --git a/common/djangoapps/terrain/ui_helpers.py b/common/djangoapps/terrain/ui_helpers.py index 78baf07e49..749a68e122 100644 --- a/common/djangoapps/terrain/ui_helpers.py +++ b/common/djangoapps/terrain/ui_helpers.py @@ -346,7 +346,7 @@ def css_contains_text(css_selector, partial_text, index=0): # If we're expecting a non-empty string, give the page # a chance to fill in text fields. if partial_text: - wait_for(lambda _: css_html(css_selector, index=index)) + wait_for(lambda _: css_html(css_selector, index=index), timeout=8) actual_text = css_html(css_selector, index=index) diff --git a/common/lib/capa/capa/templates/formulaequationinput.html b/common/lib/capa/capa/templates/formulaequationinput.html index 6db42f953a..417c95e073 100644 --- a/common/lib/capa/capa/templates/formulaequationinput.html +++ b/common/lib/capa/capa/templates/formulaequationinput.html @@ -20,7 +20,7 @@

- \[\] + \(\) Loading
diff --git a/common/static/js/capa/spec/formula_equation_preview_spec.js b/common/static/js/capa/spec/formula_equation_preview_spec.js index 0bf4ffacb8..11c2dd422d 100644 --- a/common/static/js/capa/spec/formula_equation_preview_spec.js +++ b/common/static/js/capa/spec/formula_equation_preview_spec.js @@ -139,7 +139,7 @@ describe("Formula Equation Preview", function () { // Either it makes a request or jumps straight into displaying ''. waitsFor(function () { // (Short circuit if `inputAjax` is indeed called) - return Problem.inputAjax.wasCalled || + return Problem.inputAjax.wasCalled || // jshint ignore:line MathJax.Hub.Queue.wasCalled; }, "AJAX never called on user input", 1000); @@ -266,7 +266,7 @@ describe("Formula Equation Preview", function () { // We should look in the preview div for the MathJax. var previewElement = $("#input_THE_ID_preview")[0]; - expect(previewElement.firstChild.data).toEqual("\\[THE_FORMULA\\]"); + expect(previewElement.firstChild.data).toEqual("\\(THE_FORMULA\\)"); // Refresh the MathJax. expect(MathJax.Hub.Queue).toHaveBeenCalledWith( diff --git a/common/static/js/capa/src/formula_equation_preview.js b/common/static/js/capa/src/formula_equation_preview.js index 3c01cab909..b466a5854c 100644 --- a/common/static/js/capa/src/formula_equation_preview.js +++ b/common/static/js/capa/src/formula_equation_preview.js @@ -145,7 +145,7 @@ formulaEquationPreview.enable = function () { console.log("[FormulaEquationInput] Oops no mathjax for ", latex); // Fall back to modifying the actual element. var textNode = previewElement.childNodes[0]; - textNode.data = "\\[" + latex + "\\]"; + textNode.data = "\\(" + latex + "\\)"; MathJax.Hub.Queue(["Typeset", MathJax.Hub, previewElement]); } }); diff --git a/common/templates/mathjax_include.html b/common/templates/mathjax_include.html index a378636689..c41818c3e5 100644 --- a/common/templates/mathjax_include.html +++ b/common/templates/mathjax_include.html @@ -76,4 +76,4 @@ - + diff --git a/common/test/acceptance/pages/lms/discussion.py b/common/test/acceptance/pages/lms/discussion.py index 0f0559761b..e6854b8592 100644 --- a/common/test/acceptance/pages/lms/discussion.py +++ b/common/test/acceptance/pages/lms/discussion.py @@ -126,7 +126,7 @@ class DiscussionThreadPage(PageObject, DiscussionPageMixin): def verify_mathjax_rendered(self): """ Checks that MathJax css class is present """ self.wait_for( - lambda: self._is_element_visible(".MathJax_CHTML"), + lambda: self._is_element_visible(".MathJax_SVG"), description="MathJax Preview is rendered" ) diff --git a/common/test/acceptance/pages/lms/problem.py b/common/test/acceptance/pages/lms/problem.py index f406bee2cf..1fd47cb313 100644 --- a/common/test/acceptance/pages/lms/problem.py +++ b/common/test/acceptance/pages/lms/problem.py @@ -49,7 +49,7 @@ class ProblemPage(PageObject): """ def mathjax_present(): """ Returns True if MathJax css is present in the problem body """ - mathjax_container = self.q(css="div.problem p .MathJax_CHTML") + mathjax_container = self.q(css="div.problem p .MathJax_SVG") return mathjax_container.visible and mathjax_container.present self.wait_for( @@ -63,7 +63,7 @@ class ProblemPage(PageObject): """ def mathjax_present(): """ Returns True if MathJax css is present in the problem body """ - mathjax_container = self.q(css="div.problem div.problem-hint .MathJax_CHTML") + mathjax_container = self.q(css="div.problem div.problem-hint .MathJax_SVG") return mathjax_container.visible and mathjax_container.present self.wait_for( diff --git a/common/test/acceptance/pages/lms/tab_nav.py b/common/test/acceptance/pages/lms/tab_nav.py index b9ba6f9d67..17be2a44bf 100644 --- a/common/test/acceptance/pages/lms/tab_nav.py +++ b/common/test/acceptance/pages/lms/tab_nav.py @@ -40,7 +40,7 @@ class TabNavPage(PageObject): """ Check that MathJax has rendered in tab content """ - mathjax_container = self.q(css=".static_tab_wrapper .MathJax_CHTML") + mathjax_container = self.q(css=".static_tab_wrapper .MathJax_SVG") EmptyPromise( lambda: mathjax_container.present and mathjax_container.visible, "MathJax is not visible" diff --git a/lms/static/js/spec/main.js b/lms/static/js/spec/main.js index ba58c0a9e8..e473ea0a9a 100644 --- a/lms/static/js/spec/main.js +++ b/lms/static/js/spec/main.js @@ -49,7 +49,7 @@ 'jasmine.async': 'xmodule_js/common_static/js/vendor/jasmine.async', 'draggabilly': 'xmodule_js/common_static/js/vendor/draggabilly.pkgd', 'domReady': 'xmodule_js/common_static/js/vendor/domReady', - 'mathjax': '//cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_CHTML&delayStartupUntil=configured', // jshint ignore:line + 'mathjax': '//cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured', // jshint ignore:line 'youtube': '//www.youtube.com/player_api?noext', 'coffee/src/ajax_prefix': 'xmodule_js/common_static/coffee/src/ajax_prefix', 'coffee/src/instructor_dashboard/student_admin': 'coffee/src/instructor_dashboard/student_admin',