-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: can_redeem checks for enrollment deadline #538
Merged
+171
−8
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
SYSTEM_ENTERPRISE_OPERATOR_ROLE | ||
) | ||
from enterprise_access.apps.subsidy_access_policy.constants import ( | ||
REASON_BEYOND_ENROLLMENT_DEADLINE, | ||
REASON_LEARNER_ASSIGNMENT_CANCELLED, | ||
REASON_LEARNER_ASSIGNMENT_FAILED, | ||
REASON_LEARNER_NOT_ASSIGNED_CONTENT, | ||
|
@@ -2202,6 +2203,57 @@ def test_can_redeem_policy_no_price(self, mock_lms_client, mock_transactions_cac | |
'detail': f'Could not determine price for content_key: {test_content_key}', | ||
} | ||
|
||
@mock.patch('enterprise_access.apps.subsidy_access_policy.subsidy_api.get_and_cache_transactions_for_learner') | ||
@mock.patch('enterprise_access.apps.api.v1.views.subsidy_access_policy.LmsApiClient') | ||
def test_can_redeem_policy_beyond_enrollment_deadline(self, mock_lms_client, mock_transactions_cache_for_learner): | ||
""" | ||
Test that the can_redeem endpoint successfully serializes a response for content whose | ||
enrollment deadline has passed. | ||
""" | ||
test_content_key = "course-v1:demox+1234+2T2023" | ||
mock_lms_client.return_value.get_enterprise_customer_data.return_value = { | ||
'slug': 'sluggy', | ||
'admin_users': [{'email': '[email protected]'}], | ||
} | ||
|
||
self.mock_get_content_metadata.return_value = { | ||
"content_price": 1234, | ||
"enroll_by_date": '2001-01-01T00:00:00Z', | ||
} | ||
|
||
mock_transactions_cache_for_learner.return_value = { | ||
'transactions': [], | ||
'aggregates': { | ||
'total_quantity': 0, | ||
}, | ||
} | ||
|
||
mocked_content_data_from_view = { | ||
"content_uuid": str(uuid4()), | ||
"content_key": test_content_key, | ||
"source": "edX", | ||
"content_price": 1234, | ||
"enroll_by_date": '2001-01-01T00:00:00Z', | ||
} | ||
|
||
with mock.patch( | ||
'enterprise_access.apps.subsidy_access_policy.content_metadata_api.get_and_cache_content_metadata', | ||
return_value=mocked_content_data_from_view, | ||
): | ||
query_params = {'content_key': test_content_key} | ||
response = self.client.get(self.subsidy_access_policy_can_redeem_endpoint, query_params) | ||
|
||
assert response.status_code == status.HTTP_200_OK | ||
response_list = response.json() | ||
assert response_list[0]["reasons"] == [ | ||
{ | ||
"reason": REASON_BEYOND_ENROLLMENT_DEADLINE, | ||
"user_message": MissingSubsidyAccessReasonUserMessages.BEYOND_ENROLLMENT_DEADLINE, | ||
"metadata": mock.ANY, | ||
"policy_uuids": [str(self.redeemable_policy.uuid)], | ||
}, | ||
] | ||
|
||
@mock.patch('enterprise_access.apps.subsidy_access_policy.subsidy_api.get_versioned_subsidy_client') | ||
def test_can_redeem_subsidy_client_http_error(self, mock_get_client): | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In local testing, I noticed I wasn't getting any
reasons
in my test responses even when I can an expectedcan_redeem=False
result. I tend to use reversals a lot to set up test state, so I have many unsuccessful redemptions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems reasonable!