connect discount display to applicability
This commit is contained in:
@@ -411,17 +411,37 @@ class TestCourseHomePageAccess(CourseHomePageTestCase):
|
||||
self.assertRedirects(response, expected_url)
|
||||
|
||||
@override_waffle_flag(FIRST_PURCHASE_OFFER_BANNER_DISPLAY, active=True)
|
||||
def test_first_purchase_offer_banner(self):
|
||||
@mock.patch('openedx.features.course_experience.utils.discount_percentage')
|
||||
@mock.patch('openedx.features.course_experience.utils.can_recieve_discount')
|
||||
@ddt.data(
|
||||
[True, 15],
|
||||
[True, 13],
|
||||
[True, 0],
|
||||
[False, 15])
|
||||
@ddt.unpack
|
||||
def test_first_purchase_offer_banner_display(self,
|
||||
applicability,
|
||||
percentage,
|
||||
can_recieve_discount_mock,
|
||||
discount_percentage_mock):
|
||||
"""
|
||||
Ensure first purchase offer banner displays correctly
|
||||
"""
|
||||
can_recieve_discount_mock.return_value = applicability
|
||||
discount_percentage_mock.return_value = percentage
|
||||
user = self.create_user_for_course(self.course, CourseUserType.ENROLLED)
|
||||
self.client.login(username=user.username, password=self.TEST_PASSWORD)
|
||||
url = course_home_url(self.course)
|
||||
response = self.client.get(url)
|
||||
bannerText = u'''<div class="first-purchase-offer-banner"><span class="first-purchase-offer-banner-bold">
|
||||
15% off your first upgrade.</span> Discount automatically applied.</div>'''
|
||||
self.assertContains(response, bannerText, html=True)
|
||||
bannerText = u'''<div class="first-purchase-offer-banner">
|
||||
<span class="first-purchase-offer-banner-bold">
|
||||
{}% off your first upgrade.
|
||||
</span> Discount automatically applied.
|
||||
</div>'''.format(percentage)
|
||||
if applicability:
|
||||
self.assertContains(response, bannerText, html=True)
|
||||
else:
|
||||
self.assertNotContains(response, bannerText, html=True)
|
||||
|
||||
@mock.patch.dict(settings.FEATURES, {'DISABLE_START_DATES': False})
|
||||
def test_course_does_not_expire_for_verified_user(self):
|
||||
|
||||
@@ -14,6 +14,7 @@ from lms.djangoapps.course_blocks.utils import get_student_module_as_dict
|
||||
from openedx.core.djangolib.markup import HTML
|
||||
from openedx.core.lib.cache_utils import request_cached
|
||||
from openedx.features.course_experience import FIRST_PURCHASE_OFFER_BANNER_DISPLAY
|
||||
from openedx.features.discounts.applicability import can_recieve_discount, discount_percentage
|
||||
from xmodule.modulestore.django import modulestore
|
||||
|
||||
|
||||
@@ -192,14 +193,18 @@ def get_resume_block(block):
|
||||
|
||||
|
||||
def get_first_purchase_offer_banner_fragment(user, course):
|
||||
if FIRST_PURCHASE_OFFER_BANNER_DISPLAY.is_enabled() and user and course:
|
||||
if (FIRST_PURCHASE_OFFER_BANNER_DISPLAY.is_enabled() and
|
||||
user and
|
||||
course and
|
||||
can_recieve_discount(user=user, course_key_string=unicode(course.id))):
|
||||
# Translator: xgettext:no-python-format
|
||||
offer_message = _(u'{banner_open}15% off your first upgrade.{span_close}'
|
||||
offer_message = _(u'{banner_open}{percentage}% off your first upgrade.{span_close}'
|
||||
u' Discount automatically applied.{div_close}')
|
||||
return Fragment(HTML(offer_message).format(
|
||||
banner_open=HTML(
|
||||
'<div class="first-purchase-offer-banner"><span class="first-purchase-offer-banner-bold">'
|
||||
),
|
||||
percentage=discount_percentage(),
|
||||
span_close=HTML('</span>'),
|
||||
div_close=HTML('</div>')
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user