Merge pull request #20540 from edx/emma-green/REVEM-282/D/Connect-discount-lms-display-and-applicability-calc
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_receive_discount')
|
||||
@ddt.data(
|
||||
[True, 15],
|
||||
[True, 13],
|
||||
[True, 0],
|
||||
[False, 15])
|
||||
@ddt.unpack
|
||||
def test_first_purchase_offer_banner_display(self,
|
||||
applicability,
|
||||
percentage,
|
||||
can_receive_discount_mock,
|
||||
discount_percentage_mock):
|
||||
"""
|
||||
Ensure first purchase offer banner displays correctly
|
||||
"""
|
||||
can_receive_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_receive_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_receive_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>')
|
||||
))
|
||||
|
||||
@@ -23,10 +23,10 @@ DISCOUNT_APPLICABILITY_FLAG = WaffleFlag(
|
||||
)
|
||||
|
||||
|
||||
def can_recieve_discount(user, course_key_string): # pylint: disable=unused-argument
|
||||
def can_receive_discount(user, course_key_string): # pylint: disable=unused-argument
|
||||
"""
|
||||
Check all the business logic about whether this combination of user and course
|
||||
can recieve a discount.
|
||||
can receive a discount.
|
||||
"""
|
||||
# Always disable discounts until we are ready to enable this feature
|
||||
if not DISCOUNT_APPLICABILITY_FLAG.is_enabled():
|
||||
|
||||
@@ -5,7 +5,7 @@ from student.tests.factories import UserFactory
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
|
||||
from ..applicability import can_recieve_discount
|
||||
from ..applicability import can_receive_discount
|
||||
|
||||
|
||||
class TestApplicability(ModuleStoreTestCase):
|
||||
@@ -19,7 +19,7 @@ class TestApplicability(ModuleStoreTestCase):
|
||||
self.user = UserFactory.create()
|
||||
self.course = CourseFactory.create(run='test', display_name='test')
|
||||
|
||||
def test_can_recieve_discount(self):
|
||||
# Right now, no one should be able to recieve the discount
|
||||
applicability = can_recieve_discount(user=self.user, course_key_string=self.course.id)
|
||||
def test_can_receive_discount(self):
|
||||
# Right now, no one should be able to receive the discount
|
||||
applicability = can_receive_discount(user=self.user, course_key_string=self.course.id)
|
||||
self.assertEqual(applicability, False)
|
||||
|
||||
@@ -17,7 +17,7 @@ from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
from django.utils.decorators import method_decorator
|
||||
|
||||
from .applicability import can_recieve_discount, discount_percentage
|
||||
from .applicability import can_receive_discount, discount_percentage
|
||||
|
||||
|
||||
class CourseUserDiscount(DeveloperErrorViewMixin, APIView):
|
||||
@@ -34,7 +34,7 @@ class CourseUserDiscount(DeveloperErrorViewMixin, APIView):
|
||||
|
||||
Body consists of the following fields:
|
||||
discount_applicable:
|
||||
whether the user can recieve a discount for this course
|
||||
whether the user can receive a discount for this course
|
||||
jwt:
|
||||
the jwt with user information and discount information
|
||||
|
||||
@@ -65,7 +65,7 @@ class CourseUserDiscount(DeveloperErrorViewMixin, APIView):
|
||||
"""
|
||||
Return the discount percent, if the user has appropriate permissions.
|
||||
"""
|
||||
discount_applicable = can_recieve_discount(user=request.user, course_key_string=course_key_string)
|
||||
discount_applicable = can_receive_discount(user=request.user, course_key_string=course_key_string)
|
||||
discount_percent = discount_percentage()
|
||||
payload = {'discount_applicable': discount_applicable, 'discount_percent': discount_percent}
|
||||
return Response({
|
||||
|
||||
Reference in New Issue
Block a user