From 7eae7495e43691d143f4eb7bdd887494d04b5cd1 Mon Sep 17 00:00:00 2001 From: Juliana Kang Date: Tue, 23 Jul 2024 15:43:34 -0400 Subject: [PATCH] feat: Add override on percentage config to the First Purchase Discount (#35167) REV-4098 --- .../outline/tests/test_view.py | 22 +++++++++++-------- lms/envs/common.py | 4 ++++ lms/envs/devstack.py | 3 --- lms/envs/test.py | 3 --- openedx/features/discounts/applicability.py | 8 +++++++ .../features/discounts/tests/test_utils.py | 8 ++++--- 6 files changed, 30 insertions(+), 18 deletions(-) diff --git a/lms/djangoapps/course_home_api/outline/tests/test_view.py b/lms/djangoapps/course_home_api/outline/tests/test_view.py index c092e9e2a506..76928846f080 100644 --- a/lms/djangoapps/course_home_api/outline/tests/test_view.py +++ b/lms/djangoapps/course_home_api/outline/tests/test_view.py @@ -184,11 +184,11 @@ def test_welcome_message(self, welcome_message_is_dismissed): assert welcome_message_html == (None if welcome_message_is_dismissed else '

Welcome

') @ddt.data( - (False, 'EDXWELCOME'), - (True, 'NOTEDXWELCOME'), + (False, 'EDXWELCOME', 15), + (True, 'NOTEDXWELCOME', 30), ) @ddt.unpack - def test_offer(self, is_fpd_override_waffle_flag_on, fpd_code): + def test_offer(self, is_fpd_override_waffle_flag_on, fpd_code, fpd_percentage): """ Test that the offer data contains the correct code for the first purchase discount, which can be overriden via a waffle flag from the default EDXWELCOME. @@ -199,12 +199,16 @@ def test_offer(self, is_fpd_override_waffle_flag_on, fpd_code): assert response.data['offer'] is None with override_settings(FIRST_PURCHASE_DISCOUNT_OVERRIDE_CODE='NOTEDXWELCOME'): - with override_waffle_flag(DISCOUNT_APPLICABILITY_FLAG, active=True): - with override_waffle_flag(FIRST_PURCHASE_DISCOUNT_OVERRIDE_FLAG, active=is_fpd_override_waffle_flag_on): - response = self.client.get(self.url) - - # Just a quick spot check that the dictionary looks like what we expect - assert response.data['offer']['code'] == fpd_code + with override_settings(FIRST_PURCHASE_DISCOUNT_OVERRIDE_PERCENTAGE=fpd_percentage): + with override_waffle_flag(DISCOUNT_APPLICABILITY_FLAG, active=True): + with override_waffle_flag( + FIRST_PURCHASE_DISCOUNT_OVERRIDE_FLAG, active=is_fpd_override_waffle_flag_on + ): + response = self.client.get(self.url) + + # Just a quick spot check that the dictionary looks like what we expect + assert response.data['offer']['code'] == fpd_code + assert response.data['offer']['percentage'] == fpd_percentage def test_access_expiration(self): enrollment = CourseEnrollment.enroll(self.user, self.course.id, CourseMode.VERIFIED) diff --git a/lms/envs/common.py b/lms/envs/common.py index 9a56680d4da2..26073335a267 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -4295,6 +4295,10 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring } } +# Enable First Purchase Discount offer override +FIRST_PURCHASE_DISCOUNT_OVERRIDE_CODE = '' +FIRST_PURCHASE_DISCOUNT_OVERRIDE_PERCENTAGE = 15 + # E-Commerce API Configuration ECOMMERCE_PUBLIC_URL_ROOT = 'http://localhost:8002' ECOMMERCE_API_URL = 'http://localhost:8002/api/v2' diff --git a/lms/envs/devstack.py b/lms/envs/devstack.py index 7de34f9146e0..611017962852 100644 --- a/lms/envs/devstack.py +++ b/lms/envs/devstack.py @@ -239,9 +239,6 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing ########################## Authn MFE Context API ####################### ENABLE_DYNAMIC_REGISTRATION_FIELDS = True -########################## Discount/Coupons ####################### -FIRST_PURCHASE_DISCOUNT_OVERRIDE_CODE = '' - ############## ECOMMERCE API CONFIGURATION SETTINGS ############### ECOMMERCE_PUBLIC_URL_ROOT = 'http://localhost:18130' ECOMMERCE_API_URL = 'http://edx.devstack.ecommerce:18130/api/v2' diff --git a/lms/envs/test.py b/lms/envs/test.py index 2a41e5499060..3c4bb9564927 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -92,9 +92,6 @@ # Enable a parental consent age limit for testing PARENTAL_CONSENT_AGE_LIMIT = 13 -# Enable First Purchase Discount offer override -FIRST_PURCHASE_DISCOUNT_OVERRIDE_CODE = '' - # Local Directories TEST_ROOT = path("test_root") # Want static files in the same dir for running on jenkins. diff --git a/openedx/features/discounts/applicability.py b/openedx/features/discounts/applicability.py index b158a5f45a42..2a9bc34c2dc0 100644 --- a/openedx/features/discounts/applicability.py +++ b/openedx/features/discounts/applicability.py @@ -13,6 +13,7 @@ import pytz from crum import get_current_request, impersonate +from django.conf import settings from django.utils import timezone from django.utils.dateparse import parse_datetime from edx_toggles.toggles import WaffleFlag @@ -227,6 +228,13 @@ def discount_percentage(course): """ Get the configured discount amount. """ + if FIRST_PURCHASE_DISCOUNT_OVERRIDE_FLAG.is_enabled(): + return getattr( + settings, + 'FIRST_PURCHASE_DISCOUNT_OVERRIDE_PERCENTAGE', + 15 + ) + configured_percentage = DiscountPercentageConfig.current(course_key=course.id).percentage if configured_percentage: return configured_percentage diff --git a/openedx/features/discounts/tests/test_utils.py b/openedx/features/discounts/tests/test_utils.py index d91d61839c8b..6bd9d1cd1593 100644 --- a/openedx/features/discounts/tests/test_utils.py +++ b/openedx/features/discounts/tests/test_utils.py @@ -90,9 +90,11 @@ def test_spanish_code(self): def test_override(self): with override_settings(FIRST_PURCHASE_DISCOUNT_OVERRIDE_CODE='NOTEDXWELCOME'): - with override_waffle_flag(DISCOUNT_APPLICABILITY_FLAG, active=True): - with override_waffle_flag(FIRST_PURCHASE_DISCOUNT_OVERRIDE_FLAG, active=True): - assert utils.generate_offer_data(self.user, self.overview)['code'] == 'NOTEDXWELCOME' + with override_settings(FIRST_PURCHASE_DISCOUNT_OVERRIDE_PERCENTAGE=30): + with override_waffle_flag(DISCOUNT_APPLICABILITY_FLAG, active=True): + with override_waffle_flag(FIRST_PURCHASE_DISCOUNT_OVERRIDE_FLAG, active=True): + assert utils.generate_offer_data(self.user, self.overview)['code'] == 'NOTEDXWELCOME' + assert utils.generate_offer_data(self.user, self.overview)['percentage'] == 30 def test_anonymous(self): assert utils.generate_offer_data(AnonymousUser(), self.overview) is None