@@ -96,9 +96,6 @@ def can_receive_discount(user, course, discount_expiration_date=None):
|
||||
return False
|
||||
|
||||
# TODO: Add additional conditions to return False here
|
||||
# Turn holdback on
|
||||
if _is_in_holdback(user):
|
||||
return False
|
||||
|
||||
# Check if discount has expired
|
||||
if not discount_expiration_date:
|
||||
@@ -139,12 +136,17 @@ def can_receive_discount(user, course, discount_expiration_date=None):
|
||||
if is_enterprise_learner(user):
|
||||
return False
|
||||
|
||||
# Turn holdback on
|
||||
if _is_in_holdback_and_bucket(user):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def _is_in_holdback(user):
|
||||
def _is_in_holdback_and_bucket(user):
|
||||
"""
|
||||
Return whether the specified user is in the first-purchase-discount holdback group.
|
||||
This will also stable bucket the user.
|
||||
"""
|
||||
if datetime(2020, 8, 1, tzinfo=pytz.UTC) <= datetime.now(tz=pytz.UTC):
|
||||
return False
|
||||
|
||||
@@ -23,7 +23,7 @@ from student.tests.factories import CourseEnrollmentFactory, UserFactory
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
|
||||
from ..applicability import DISCOUNT_APPLICABILITY_FLAG, _is_in_holdback, can_receive_discount
|
||||
from ..applicability import DISCOUNT_APPLICABILITY_FLAG, _is_in_holdback_and_bucket, can_receive_discount
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
@@ -44,7 +44,9 @@ class TestApplicability(ModuleStoreTestCase):
|
||||
user=self.user, experiment_id=REV1008_EXPERIMENT_ID, key=str(self.course), value=now_time
|
||||
)
|
||||
|
||||
holdback_patcher = patch('openedx.features.discounts.applicability._is_in_holdback', return_value=False)
|
||||
holdback_patcher = patch(
|
||||
'openedx.features.discounts.applicability._is_in_holdback_and_bucket', return_value=False
|
||||
)
|
||||
self.mock_holdback = holdback_patcher.start()
|
||||
self.addCleanup(holdback_patcher.stop)
|
||||
|
||||
@@ -165,7 +167,7 @@ class TestApplicability(ModuleStoreTestCase):
|
||||
@ddt.unpack
|
||||
def test_holdback_group_ids(self, group_number, in_holdback):
|
||||
with patch('openedx.features.discounts.applicability.stable_bucketing_hash_group', return_value=group_number):
|
||||
assert _is_in_holdback(self.user) == in_holdback
|
||||
assert _is_in_holdback_and_bucket(self.user) == in_holdback
|
||||
|
||||
def test_holdback_expiry(self):
|
||||
with patch('openedx.features.discounts.applicability.stable_bucketing_hash_group', return_value=0):
|
||||
@@ -173,4 +175,4 @@ class TestApplicability(ModuleStoreTestCase):
|
||||
'openedx.features.discounts.applicability.datetime',
|
||||
Mock(now=Mock(return_value=datetime(2020, 8, 1, 0, 1, tzinfo=pytz.UTC)), wraps=datetime),
|
||||
):
|
||||
assert not _is_in_holdback(self.user)
|
||||
assert not _is_in_holdback_and_bucket(self.user)
|
||||
|
||||
Reference in New Issue
Block a user