Skip to content

Commit

Permalink
feat: Add override on percentage config to the First Purchase Discount (
Browse files Browse the repository at this point in the history
openedx#35167)

REV-4098
  • Loading branch information
julianajlk authored Jul 23, 2024
1 parent 896b011 commit 40ddfeb
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
22 changes: 13 additions & 9 deletions lms/djangoapps/course_home_api/outline/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ def test_welcome_message(self, welcome_message_is_dismissed):
assert welcome_message_html == (None if welcome_message_is_dismissed else '<p>Welcome</p>')

@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.
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 0 additions & 3 deletions lms/envs/devstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 0 additions & 3 deletions lms/envs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions openedx/features/discounts/applicability.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions openedx/features/discounts/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 40ddfeb

Please sign in to comment.