-
Notifications
You must be signed in to change notification settings - Fork 6
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
Showing
4 changed files
with
29 additions
and
3 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
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 |
---|---|---|
|
@@ -51,7 +51,10 @@ class APITestBase(APITestMixin): | |
subsidy_access_policy_1_uuid = str(uuid.uuid4()) | ||
subsidy_access_policy_2_uuid = str(uuid.uuid4()) | ||
content_key_1 = "course-v1:edX+test+course.1" | ||
content_title_1 = "edx: Test Course 1" | ||
content_key_2 = "course-v1:edX+test+course.2" | ||
content_title_2 = "edx: Test Course 2" | ||
lms_user_email = '[email protected]' | ||
|
||
def setUp(self): | ||
super().setUp() | ||
|
@@ -69,17 +72,21 @@ def setUp(self): | |
quantity=-1000, | ||
ledger=self.subsidy_1.ledger, | ||
lms_user_id=STATIC_LMS_USER_ID, # This is the only transaction belonging to the requester. | ||
lms_user_email=self.lms_user_email, | ||
subsidy_access_policy_uuid=self.subsidy_access_policy_1_uuid, | ||
content_key=self.content_key_1, | ||
content_title=self.content_title_1, | ||
) | ||
self.subsidy_1_transaction_2 = TransactionFactory( | ||
uuid=self.subsidy_1_transaction_2_uuid, | ||
state=TransactionStateChoices.COMMITTED, | ||
quantity=-1000, | ||
ledger=self.subsidy_1.ledger, | ||
lms_user_id=STATIC_LMS_USER_ID+1000, | ||
lms_user_email=self.lms_user_email, | ||
subsidy_access_policy_uuid=self.subsidy_access_policy_2_uuid, | ||
content_key=self.content_key_2, | ||
content_title=self.content_title_2, | ||
) | ||
|
||
# Create an extra subsidy with the same enterprise_customer_uuid, but the learner does not have any transactions | ||
|
@@ -96,13 +103,15 @@ def setUp(self): | |
quantity=-1000, | ||
ledger=self.subsidy_2.ledger, | ||
lms_user_id=STATIC_LMS_USER_ID+1000, | ||
lms_user_email=self.lms_user_email, | ||
) | ||
TransactionFactory( | ||
uuid=self.subsidy_2_transaction_2_uuid, | ||
state=TransactionStateChoices.COMMITTED, | ||
quantity=-1000, | ||
ledger=self.subsidy_2.ledger, | ||
lms_user_id=STATIC_LMS_USER_ID+1000, | ||
lms_user_email=self.lms_user_email, | ||
) | ||
|
||
# Create third subsidy with a different enterprise_customer_uuid. Neither test learner nor the test admin | ||
|
@@ -119,13 +128,15 @@ def setUp(self): | |
quantity=-1000, | ||
ledger=self.subsidy_3.ledger, | ||
lms_user_id=STATIC_LMS_USER_ID+1000, | ||
lms_user_email=self.lms_user_email, | ||
) | ||
TransactionFactory( | ||
uuid=self.subsidy_3_transaction_2_uuid, | ||
state=TransactionStateChoices.COMMITTED, | ||
quantity=-1000, | ||
ledger=self.subsidy_3.ledger, | ||
lms_user_id=STATIC_LMS_USER_ID+1000, | ||
lms_user_email=self.lms_user_email, | ||
) | ||
|
||
self.all_initial_transactions = set([ | ||
|
@@ -254,14 +265,16 @@ def test_can_redeem_bad_request(self, query_params): | |
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||
|
||
@mock.patch('enterprise_subsidy.apps.api.v1.views.subsidy.can_redeem') | ||
@mock.patch("enterprise_subsidy.apps.subsidy.models.Subsidy.lms_user_client") | ||
@ddt.data(False, True) | ||
def test_can_redeem_happy_path(self, has_existing_transaction, mock_can_redeem): | ||
def test_can_redeem_happy_path(self, has_existing_transaction, mock_lms_user_client, mock_can_redeem): | ||
""" | ||
Tests that the result of ``api.can_redeem()`` is returned as the response | ||
payload for a POST to the can_redeem action, including any relevant | ||
existing transaction. | ||
""" | ||
self.set_up_admin(enterprise_uuids=[self.subsidy_1.enterprise_customer_uuid]) | ||
mock_lms_user_client.return_value.best_effort_user_data.return_value = {'email': '[email protected]'} | ||
expected_redeemable = True | ||
expected_active = True | ||
expected_price = 350 | ||
|
@@ -959,17 +972,20 @@ def test_retrieve_invalid_uuid(self): | |
@mock.patch("enterprise_subsidy.apps.subsidy.models.Subsidy.enterprise_client") | ||
@mock.patch("enterprise_subsidy.apps.subsidy.models.Subsidy.price_for_content") | ||
@mock.patch("enterprise_subsidy.apps.content_metadata.api.ContentMetadataApi.get_content_summary") | ||
def test_create(self, mock_get_content_summary, mock_price_for_content, mock_enterprise_client): | ||
@mock.patch("enterprise_subsidy.apps.subsidy.models.Subsidy.lms_user_client") | ||
def test_create(self, mock_lms_user_client, mock_get_content_summary, mock_price_for_content, mock_enterprise_client): | ||
""" | ||
Test create Transaction, happy case. | ||
""" | ||
mock_lms_user_client.return_value.best_effort_user_data.return_value = {'email': '[email protected]'} | ||
url = reverse("api:v1:transaction-list") | ||
test_enroll_enterprise_fulfillment_uuid = "test-enroll-reference-id" | ||
mock_enterprise_client.enroll.return_value = test_enroll_enterprise_fulfillment_uuid | ||
mock_price_for_content.return_value = 10000 | ||
mock_get_content_summary.return_value = { | ||
'content_uuid': 'course-v1:edX-test-course', | ||
'content_key': 'course-v1:edX-test-course', | ||
'content_title': 'edX: Test Course', | ||
'source': 'edX', | ||
'mode': 'verified', | ||
'content_price': 10000, | ||
|
@@ -994,7 +1010,9 @@ def test_create(self, mock_get_content_summary, mock_price_for_content, mock_ent | |
f"{self.transaction_status_api_url}/{create_response_data['uuid']}/" | ||
) | ||
assert create_response_data["content_key"] == post_data["content_key"] | ||
assert create_response_data["content_title"] == 'edX: Test Course' | ||
assert create_response_data["lms_user_id"] == post_data["lms_user_id"] | ||
assert create_response_data["lms_user_email"] == '[email protected]' | ||
assert create_response_data["subsidy_access_policy_uuid"] == post_data["subsidy_access_policy_uuid"] | ||
assert create_response_data["courseware_url"] == f"http://localhost:2000/course/{post_data['content_key']}/home" | ||
self.assertDictEqual(create_response_data["metadata"], {}) | ||
|
@@ -1011,6 +1029,7 @@ def test_create(self, mock_get_content_summary, mock_price_for_content, mock_ent | |
retrieve_response_data = retrieve_response.json() | ||
assert retrieve_response_data["uuid"] == create_response_data["uuid"] | ||
assert retrieve_response_data["idempotency_key"] == create_response_data["idempotency_key"] | ||
# assert retrieve_response_data["content_title"] == 'edX: Test Course' | ||
|
||
# Uncomment after Segment events are setup: | ||
# | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,8 @@ def setUpTestData(cls): | |
enterprise_customer_uuid=cls.enterprise_customer_uuid, | ||
) | ||
cls.subsidy.content_metadata_api = mock.MagicMock() | ||
#cls.subsidy.lms_user_client = mock.MagicMock() | ||
#cls.subsidy.lms_user_client.return_value.best_effort_user_data.return_value = {'email': '[email protected]'} | ||
super().setUpTestData() | ||
|
||
def test_price_for_content(self): | ||
|
@@ -198,6 +200,8 @@ def setUp(self): | |
self.subsidy = SubsidyFactory.create( | ||
enterprise_customer_uuid=self.enterprise_customer_uuid, | ||
) | ||
self.subsidy.lms_user_client = mock.MagicMock() | ||
self.subsidy.lms_user_client.return_value.best_effort_user_data.return_value = {'email': '[email protected]'} | ||
super().setUp() | ||
|
||
def test_get_committed_transaction_no_reversal(self): | ||
|
@@ -300,6 +304,7 @@ def test_redeem_with_metadata(self, mock_get_content_summary, mock_enterprise_cl | |
mock_get_content_summary.return_value = { | ||
'content_uuid': 'course-v1:edX+test+course', | ||
'content_key': 'course-v1:edX+test+course', | ||
'content_title': 'edx: Test Course', | ||
'source': 'edX', | ||
'mode': 'verified', | ||
'content_price': 10000, | ||
|