Skip to content

Commit

Permalink
fix: don't fetch list price unless redeemable
Browse files Browse the repository at this point in the history
ENT-7319
  • Loading branch information
iloveagent57 committed Jun 22, 2023
1 parent 2411e1f commit c3ff6f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1011,10 +1011,6 @@ def test_can_redeem_policy_none_redeemable(
test_content_key_2 = "course-v1:edX+edXPrivacy101+3T2020_2"
test_content_key_1_metadata_price = 29900
test_content_key_2_metadata_price = 81900
test_content_key_1_usd_price = 299
test_content_key_2_usd_price = 819
test_content_key_1_cents_price = 29900
test_content_key_2_cents_price = 81900

def mock_get_subsidy_content_data(*args, **kwargs):
if test_content_key_1 in args:
Expand Down Expand Up @@ -1051,10 +1047,9 @@ def mock_get_subsidy_content_data(*args, **kwargs):

# Check the response for the first content_key given.
assert response_list[0]["content_key"] == test_content_key_1
assert response_list[0]["list_price"] == {
"usd": test_content_key_1_usd_price,
"usd_cents": test_content_key_1_cents_price,
}
# We should not assume that a list price is fetchable if the
# content cant' be redeemed - the content may not be in any catalog for any policy.
assert response_list[0]["list_price"] is None
assert len(response_list[0]["redemptions"]) == 0
assert response_list[0]["has_successful_redemption"] is False
assert response_list[0]["redeemable_subsidy_access_policy"] is None
Expand All @@ -1080,10 +1075,8 @@ def mock_get_subsidy_content_data(*args, **kwargs):

# Check the response for the second content_key given.
assert response_list[1]["content_key"] == test_content_key_2
assert response_list[1]["list_price"] == {
"usd": test_content_key_2_usd_price,
"usd_cents": test_content_key_2_cents_price,
}
assert response_list[1]["list_price"] is None

assert len(response_list[1]["redemptions"]) == 0
assert response_list[1]["has_successful_redemption"] is False
assert response_list[1]["redeemable_subsidy_access_policy"] is None
Expand Down
6 changes: 5 additions & 1 deletion enterprise_access/apps/api/v1/views/subsidy_access_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ def can_redeem(self, request, enterprise_customer_uuid):
redeemable_policies = []
non_redeemable_policies = []
resolved_policy = None
list_price = None

redemptions_by_policy_uuid = redemptions_by_content_and_policy[content_key]
# Flatten dict of lists because the response doesn't need to be bucketed by policy_uuid.
Expand Down Expand Up @@ -632,9 +633,12 @@ def can_redeem(self, request, enterprise_customer_uuid):
if redeemable_policies:
resolved_policy = redeemable_policies[0]

if resolved_policy or has_successful_redemption:
list_price = self._get_list_price(enterprise_customer_uuid, content_key)

element_response = {
"content_key": content_key,
"list_price": self._get_list_price(enterprise_customer_uuid, content_key),
"list_price": list_price,
"redemptions": redemptions,
"has_successful_redemption": has_successful_redemption,
"redeemable_subsidy_access_policy": resolved_policy,
Expand Down

0 comments on commit c3ff6f7

Please sign in to comment.