-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dda40f5
commit 08b78e4
Showing
3 changed files
with
178 additions
and
8 deletions.
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
from uuid import UUID, uuid4 | ||
|
||
import ddt | ||
import requests | ||
from django.conf import settings | ||
from rest_framework import status | ||
from rest_framework.reverse import reverse | ||
|
@@ -682,6 +683,52 @@ def test_redeem_policy(self, mock_transactions_cache_for_learner): # pylint: di | |
), | ||
) | ||
|
||
@mock.patch('enterprise_access.apps.subsidy_access_policy.models.get_and_cache_transactions_for_learner') | ||
@mock.patch('enterprise_access.apps.api.v1.views.subsidy_access_policy.LmsApiClient') | ||
@ddt.data( | ||
{ | ||
'subsidy_error_code': 'fulfillment_error', | ||
'subsidy_error_detail': [{'message': 'woozit duplicate order woohoo!'}], | ||
'expected_redeem_error_payload': { | ||
'reason': 'the-reason', | ||
'user-message': 'the-user-message', | ||
'metadata': { | ||
'enterprise_administrators': '[email protected]', | ||
}, | ||
}, | ||
}, | ||
) | ||
def test_redeem_policy_subsidy_api_error( | ||
self, mock_lms_api_client, mock_transactions_cache_for_learner, | ||
subsidy_error_code, subsidy_error_detail, expected_redeem_error_payload | ||
): | ||
""" | ||
Verify that SubsidyAccessPolicyRedeemViewset redeem endpoint returns a well-structured | ||
error response payload when the subsidy API call to redeem/fulfill responds with an error. | ||
""" | ||
mock_lms_api_client().get_enterprise_customer_data.return_value = { | ||
'slug': 'the-slug', | ||
'admin_users': [{'email': '[email protected]'}], | ||
} | ||
self.mock_get_content_metadata.return_value = {'content_price': 123} | ||
mock_response = mock.MagicMock() | ||
mock_response.json.return_value = { | ||
'code': subsidy_error_code, | ||
'detail': subsidy_error_detail, | ||
} | ||
self.redeemable_policy.subsidy_client.create_subsidy_transaction.side_effect = requests.exceptions.HTTPError( | ||
response=mock_response | ||
) | ||
|
||
payload = { | ||
'lms_user_id': 1234, | ||
'content_key': 'course-v1:edX+edXPrivacy101+3T2020', | ||
} | ||
|
||
response = self.client.post(self.subsidy_access_policy_redeem_endpoint, payload) | ||
|
||
response_json = self.load_json(response.content) | ||
|
||
@mock.patch('enterprise_access.apps.subsidy_access_policy.models.get_and_cache_transactions_for_learner') | ||
def test_redeem_policy_with_metadata(self, mock_transactions_cache_for_learner): # pylint: disable=unused-argument | ||
""" | ||
|
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