feat: Add override on percentage config to the First Purchase Discount (#35167)

REV-4098
This commit is contained in:
Juliana Kang
2024-07-23 15:43:34 -04:00
committed by GitHub
parent 896b011e88
commit 40ddfeb3b8
6 changed files with 29 additions and 17 deletions

View File

@@ -184,11 +184,11 @@ class OutlineTabTestViews(BaseCourseHomeTests):
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.
@@ -199,12 +199,16 @@ class OutlineTabTestViews(BaseCourseHomeTests):
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)
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
# 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)

View File

@@ -4295,6 +4295,10 @@ SOCIAL_PLATFORMS = {
}
}
# 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'

View File

@@ -239,9 +239,6 @@ if FEATURES.get('ENABLE_THIRD_PARTY_AUTH') and (
########################## 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'

View File

@@ -92,9 +92,6 @@ WIKI_ENABLED = True
# 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.

View File

@@ -13,6 +13,7 @@ from datetime import datetime, timedelta
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

View File

@@ -90,9 +90,11 @@ class TestOfferData(TestCase):
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