Skip to content

Commit 40ddfeb

Browse files
authored
feat: Add override on percentage config to the First Purchase Discount (#35167)
REV-4098
1 parent 896b011 commit 40ddfeb

6 files changed

Lines changed: 30 additions & 18 deletions

File tree

lms/djangoapps/course_home_api/outline/tests/test_view.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ def test_welcome_message(self, welcome_message_is_dismissed):
184184
assert welcome_message_html == (None if welcome_message_is_dismissed else '<p>Welcome</p>')
185185

186186
@ddt.data(
187-
(False, 'EDXWELCOME'),
188-
(True, 'NOTEDXWELCOME'),
187+
(False, 'EDXWELCOME', 15),
188+
(True, 'NOTEDXWELCOME', 30),
189189
)
190190
@ddt.unpack
191-
def test_offer(self, is_fpd_override_waffle_flag_on, fpd_code):
191+
def test_offer(self, is_fpd_override_waffle_flag_on, fpd_code, fpd_percentage):
192192
"""
193193
Test that the offer data contains the correct code for the first purchase discount,
194194
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):
199199
assert response.data['offer'] is None
200200

201201
with override_settings(FIRST_PURCHASE_DISCOUNT_OVERRIDE_CODE='NOTEDXWELCOME'):
202-
with override_waffle_flag(DISCOUNT_APPLICABILITY_FLAG, active=True):
203-
with override_waffle_flag(FIRST_PURCHASE_DISCOUNT_OVERRIDE_FLAG, active=is_fpd_override_waffle_flag_on):
204-
response = self.client.get(self.url)
205-
206-
# Just a quick spot check that the dictionary looks like what we expect
207-
assert response.data['offer']['code'] == fpd_code
202+
with override_settings(FIRST_PURCHASE_DISCOUNT_OVERRIDE_PERCENTAGE=fpd_percentage):
203+
with override_waffle_flag(DISCOUNT_APPLICABILITY_FLAG, active=True):
204+
with override_waffle_flag(
205+
FIRST_PURCHASE_DISCOUNT_OVERRIDE_FLAG, active=is_fpd_override_waffle_flag_on
206+
):
207+
response = self.client.get(self.url)
208+
209+
# Just a quick spot check that the dictionary looks like what we expect
210+
assert response.data['offer']['code'] == fpd_code
211+
assert response.data['offer']['percentage'] == fpd_percentage
208212

209213
def test_access_expiration(self):
210214
enrollment = CourseEnrollment.enroll(self.user, self.course.id, CourseMode.VERIFIED)

lms/envs/common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4295,6 +4295,10 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring
42954295
}
42964296
}
42974297

4298+
# Enable First Purchase Discount offer override
4299+
FIRST_PURCHASE_DISCOUNT_OVERRIDE_CODE = ''
4300+
FIRST_PURCHASE_DISCOUNT_OVERRIDE_PERCENTAGE = 15
4301+
42984302
# E-Commerce API Configuration
42994303
ECOMMERCE_PUBLIC_URL_ROOT = 'http://localhost:8002'
43004304
ECOMMERCE_API_URL = 'http://localhost:8002/api/v2'

lms/envs/devstack.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,6 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing
239239
########################## Authn MFE Context API #######################
240240
ENABLE_DYNAMIC_REGISTRATION_FIELDS = True
241241

242-
########################## Discount/Coupons #######################
243-
FIRST_PURCHASE_DISCOUNT_OVERRIDE_CODE = ''
244-
245242
############## ECOMMERCE API CONFIGURATION SETTINGS ###############
246243
ECOMMERCE_PUBLIC_URL_ROOT = 'http://localhost:18130'
247244
ECOMMERCE_API_URL = 'http://edx.devstack.ecommerce:18130/api/v2'

lms/envs/test.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@
9292
# Enable a parental consent age limit for testing
9393
PARENTAL_CONSENT_AGE_LIMIT = 13
9494

95-
# Enable First Purchase Discount offer override
96-
FIRST_PURCHASE_DISCOUNT_OVERRIDE_CODE = ''
97-
9895
# Local Directories
9996
TEST_ROOT = path("test_root")
10097
# Want static files in the same dir for running on jenkins.

openedx/features/discounts/applicability.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import pytz
1515
from crum import get_current_request, impersonate
16+
from django.conf import settings
1617
from django.utils import timezone
1718
from django.utils.dateparse import parse_datetime
1819
from edx_toggles.toggles import WaffleFlag
@@ -227,6 +228,13 @@ def discount_percentage(course):
227228
"""
228229
Get the configured discount amount.
229230
"""
231+
if FIRST_PURCHASE_DISCOUNT_OVERRIDE_FLAG.is_enabled():
232+
return getattr(
233+
settings,
234+
'FIRST_PURCHASE_DISCOUNT_OVERRIDE_PERCENTAGE',
235+
15
236+
)
237+
230238
configured_percentage = DiscountPercentageConfig.current(course_key=course.id).percentage
231239
if configured_percentage:
232240
return configured_percentage

openedx/features/discounts/tests/test_utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ def test_spanish_code(self):
9090

9191
def test_override(self):
9292
with override_settings(FIRST_PURCHASE_DISCOUNT_OVERRIDE_CODE='NOTEDXWELCOME'):
93-
with override_waffle_flag(DISCOUNT_APPLICABILITY_FLAG, active=True):
94-
with override_waffle_flag(FIRST_PURCHASE_DISCOUNT_OVERRIDE_FLAG, active=True):
95-
assert utils.generate_offer_data(self.user, self.overview)['code'] == 'NOTEDXWELCOME'
93+
with override_settings(FIRST_PURCHASE_DISCOUNT_OVERRIDE_PERCENTAGE=30):
94+
with override_waffle_flag(DISCOUNT_APPLICABILITY_FLAG, active=True):
95+
with override_waffle_flag(FIRST_PURCHASE_DISCOUNT_OVERRIDE_FLAG, active=True):
96+
assert utils.generate_offer_data(self.user, self.overview)['code'] == 'NOTEDXWELCOME'
97+
assert utils.generate_offer_data(self.user, self.overview)['percentage'] == 30
9698

9799
def test_anonymous(self):
98100
assert utils.generate_offer_data(AnonymousUser(), self.overview) is None

0 commit comments

Comments
 (0)