Skip to content
Snippets Groups Projects
Commit 4783aed9 authored by Emma Green's avatar Emma Green
Browse files

Enterprise users should not get the first purchase discount.

parent e7a509fa
No related merge requests found
......@@ -78,6 +78,12 @@ def can_receive_discount(user, course): # pylint: disable=unused-argument
if CourseEntitlement.objects.filter(user=user).exists():
return False
# We can't import this at Django load time within the openedx tests settings context
from openedx.features.enterprise_support.utils import is_enterprise_learner
# Don't give discount to enterprise users
if is_enterprise_learner(user):
return False
# Excute holdback
if _is_in_holdback(user):
return False
......
......@@ -7,11 +7,13 @@ from datetime import datetime, timedelta
import ddt
import pytz
from django.contrib.sites.models import Site
from django.utils.timezone import now
from mock import Mock, patch
from course_modes.models import CourseMode
from course_modes.tests.factories import CourseModeFactory
from enterprise.models import EnterpriseCustomer, EnterpriseCustomerUser
from entitlements.tests.factories import CourseEntitlementFactory
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag
......@@ -32,6 +34,7 @@ class TestApplicability(ModuleStoreTestCase):
def setUp(self):
super(TestApplicability, self).setUp()
self.site, _ = Site.objects.get_or_create(domain='example.com')
self.user = UserFactory.create()
self.course = CourseFactory.create(run='test', display_name='test')
CourseModeFactory.create(course_id=self.course.id, mode_slug='verified')
......@@ -105,6 +108,23 @@ class TestApplicability(ModuleStoreTestCase):
applicability = can_receive_discount(user=self.user, course=self.course)
assert applicability == (entitlement_mode is None)
@override_waffle_flag(DISCOUNT_APPLICABILITY_FLAG, active=True)
def test_can_receive_discount_false_enterprise(self):
"""
Ensure that enterprise users do not receive the discount.
"""
enterprise_customer = EnterpriseCustomer.objects.create(
name='Test EnterpriseCustomer',
site=self.site
)
EnterpriseCustomerUser.objects.create(
user_id=self.user.id,
enterprise_customer=enterprise_customer
)
applicability = can_receive_discount(user=self.user, course=self.course)
self.assertEqual(applicability, False)
@override_waffle_flag(DISCOUNT_APPLICABILITY_FLAG, active=True)
def test_holdback_denies_discount(self):
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment