Skip to content

Commit

Permalink
Merge pull request #341 from openedx/bbeggs/ENT-7991
Browse files Browse the repository at this point in the history
chore: Function content_would_exceed_limit now returns no longer returns false when content price + allocations = budget limit
  • Loading branch information
macdiesel authored Nov 29, 2023
2 parents 94154cf + b2ed69b commit 0bd24b9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ def test_allocate_too_much_existing_allocation_e2e(
subsidy_balance = 300
mock_subsidy_balance.return_value = subsidy_balance
mock_aggregates_for_policy.return_value = {
'total_quantity': (subsidy_balance - 2) * -1,
'total_quantity': (subsidy_balance - 1) * -1,
}

allocate_url = _allocation_url(self.assigned_learner_credit_policy.uuid)
Expand Down
2 changes: 1 addition & 1 deletion enterprise_access/apps/subsidy_access_policy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def content_would_exceed_limit(spent_amount, limit_to_check, content_price):
raise Exception('Expected a sum of transaction quantities <= 0')

positive_spent_amount = spent_amount * -1
return (positive_spent_amount + content_price) >= limit_to_check
return (positive_spent_amount + content_price) > limit_to_check

def will_exceed_spend_limit(self, content_key, content_metadata=None):
"""
Expand Down
18 changes: 18 additions & 0 deletions enterprise_access/apps/subsidy_access_policy/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,24 @@ def test_content_would_exceed_limit_positive_spent_amount(self):
with self.assertRaisesRegex(Exception, 'Expected a sum of transaction quantities <= 0'):
self.per_learner_enroll_policy.content_would_exceed_limit(10, 100, 15)

def test_spend_limit_sum_and_content_price_equal_to_remaining_budget(self):
"""
Ensures that passing a spent_amount equal to the remaining budget will return False.
"""
self.assertFalse(self.per_learner_enroll_policy.content_would_exceed_limit(-90, 100, 10))

def test_spend_limit_sum_and_content_price_less_than_remaining_budget(self):
"""
Ensures that passing a spent_amount less than the remaining budget will return False.
"""
self.assertFalse(self.per_learner_enroll_policy.content_would_exceed_limit(-90, 100, 5))

def test_spend_limit_sum_and_content_price_greater_than_remaining_budget(self):
"""
Ensures that passing a spent_amount equal to the remaining budget will return True.
"""
self.assertTrue(self.per_learner_enroll_policy.content_would_exceed_limit(-90, 100, 11))

def test_mock_subsidy_datetimes(self):
yesterday = datetime.utcnow() - timedelta(days=1)
tomorrow = datetime.utcnow() + timedelta(days=1)
Expand Down

0 comments on commit 0bd24b9

Please sign in to comment.