-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add fields parent_content_key and is_assigned_course_run for as…
…signments (#549) Incrementally supports course run-based assignment allocation, while remaining backwards compatible with course-based assignments.
- Loading branch information
1 parent
8fbda7f
commit aec0b74
Showing
8 changed files
with
171 additions
and
31 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 |
---|---|---|
|
@@ -122,7 +122,8 @@ def setUp(self): | |
self.mock_catalog_result = { | ||
'count': 2, | ||
'results': [ | ||
{'key': 'course+A', 'data': 'things'}, {'key': 'course+B', 'data': 'stuff'}, | ||
{'key': 'course+A', 'data': 'things'}, | ||
{'key': 'course+B', 'data': 'stuff'}, | ||
], | ||
} | ||
|
||
|
@@ -229,6 +230,8 @@ def test_allocate_happy_path(self, mock_catalog_client, mock_allocate, mock_subs | |
'learner_email': '[email protected]', | ||
'lms_user_id': None, | ||
'content_key': self.content_key, | ||
'parent_content_key': None, | ||
'is_assigned_course_run': False, | ||
'content_title': self.content_title, | ||
'content_quantity': -123, | ||
'state': LearnerContentAssignmentStateChoices.ERRORED, | ||
|
@@ -249,6 +252,8 @@ def test_allocate_happy_path(self, mock_catalog_client, mock_allocate, mock_subs | |
'learner_email': '[email protected]', | ||
'lms_user_id': None, | ||
'content_key': self.content_key, | ||
'parent_content_key': None, | ||
'is_assigned_course_run': False, | ||
'content_title': self.content_title, | ||
'content_quantity': -456, | ||
'state': LearnerContentAssignmentStateChoices.ALLOCATED, | ||
|
@@ -269,6 +274,8 @@ def test_allocate_happy_path(self, mock_catalog_client, mock_allocate, mock_subs | |
'learner_email': '[email protected]', | ||
'lms_user_id': None, | ||
'content_key': self.content_key, | ||
'parent_content_key': None, | ||
'is_assigned_course_run': False, | ||
'content_title': self.content_title, | ||
'content_quantity': -789, | ||
'state': LearnerContentAssignmentStateChoices.ALLOCATED, | ||
|
@@ -420,7 +427,8 @@ class TestSubsidyAccessPolicyAllocationEndToEnd(APITestWithMocks): | |
def setUpTestData(cls): | ||
super().setUpTestData() | ||
cls.enterprise_uuid = OTHER_TEST_ENTERPRISE_UUID | ||
cls.content_key = 'course-v1:edX+edXPrivacy101+3T2020' | ||
cls.content_key = 'course-v1:edX+Privacy101+3T2020' | ||
cls.parent_content_key = 'edX+Privacy101' | ||
cls.content_title = 'edX: Privacy 101' | ||
|
||
# Create a pair of AssignmentConfiguration + SubsidyAccessPolicy for the main test customer. | ||
|
@@ -435,6 +443,18 @@ def setUpTestData(cls): | |
spend_limit=10000 * 100, | ||
) | ||
|
||
# Mock results from the catalog content metadata API endpoint. | ||
cls.mock_catalog_result = { | ||
'count': 2, | ||
'results': [ | ||
{ | ||
'key': cls.content_key, | ||
'parent_content_key': cls.parent_content_key, | ||
'data': 'things', | ||
}, | ||
], | ||
} | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.maxDiff = None | ||
|
@@ -453,14 +473,6 @@ def setUp(self): | |
def delete_assignments(): | ||
return self.assignment_configuration.assignments.all().delete() | ||
|
||
# Mock results from the catalog content metadata API endpoint. | ||
self.mock_catalog_result = { | ||
'count': 2, | ||
'results': [ | ||
{'key': 'course+A', 'data': 'things'}, {'key': 'course+B', 'data': 'stuff'}, | ||
], | ||
} | ||
|
||
self.addCleanup(delete_assignments) | ||
|
||
@mock.patch.object( | ||
|
@@ -509,6 +521,8 @@ def test_allocate_happy_path_e2e( | |
""" | ||
mock_get_and_cache_content_metadata.return_value = { | ||
'content_title': self.content_title, | ||
'content_key': self.parent_content_key, | ||
'course_run_key': self.content_key, | ||
} | ||
mock_get_content_price.return_value = 123.45 * 100 | ||
mock_aggregates_for_policy.return_value = { | ||
|
@@ -539,6 +553,8 @@ def test_allocate_happy_path_e2e( | |
lms_user_id=None, | ||
cancelled_at=timezone.now(), | ||
content_key=self.content_key, | ||
parent_content_key=self.parent_content_key, | ||
is_assigned_course_run=True, | ||
content_title=self.content_title, | ||
content_quantity=-12345, | ||
state=LearnerContentAssignmentStateChoices.CANCELLED, | ||
|
@@ -547,15 +563,18 @@ def test_allocate_happy_path_e2e( | |
email='[email protected]', | ||
lms_user_id=4277 | ||
) | ||
assignment_content_quantity_usd_cents = 12345 | ||
LearnerContentAssignmentFactory( | ||
assignment_configuration=self.assignment_configuration, | ||
learner_email='[email protected]', | ||
lms_user_id=expired_user.lms_user_id, | ||
expired_at=timezone.now(), | ||
errored_at=timezone.now(), | ||
content_key=self.content_key, | ||
parent_content_key=self.parent_content_key, | ||
is_assigned_course_run=True, | ||
content_title=self.content_title, | ||
content_quantity=-12345, | ||
content_quantity=-assignment_content_quantity_usd_cents, | ||
state=LearnerContentAssignmentStateChoices.EXPIRED, | ||
) | ||
|
||
|
@@ -571,7 +590,7 @@ def test_allocate_happy_path_e2e( | |
allocate_payload = { | ||
'learner_emails': ['[email protected]', '[email protected]', '[email protected]'], | ||
'content_key': self.content_key, | ||
'content_price_cents': 123.45 * 100, # policy limit is 100000.00 USD, so this should be well below limit | ||
'content_price_cents': assignment_content_quantity_usd_cents, # this should be well below limit | ||
} | ||
|
||
response = self.client.post(allocate_url, data=allocate_payload) | ||
|
@@ -581,7 +600,7 @@ def test_allocate_happy_path_e2e( | |
for assignment in self.assignment_configuration.assignments.filter( | ||
state=LearnerContentAssignmentStateChoices.ALLOCATED, | ||
content_key=self.content_key, | ||
content_quantity=-123.45 * 100, | ||
content_quantity=-assignment_content_quantity_usd_cents | ||
) | ||
} | ||
self.assertEqual(3, len(allocation_records_by_email)) | ||
|
@@ -594,8 +613,10 @@ def test_allocate_happy_path_e2e( | |
'learner_email': '[email protected]', | ||
'lms_user_id': foo_user.lms_user_id, | ||
'content_key': self.content_key, | ||
'parent_content_key': self.parent_content_key, | ||
'is_assigned_course_run': True, | ||
'content_title': self.content_title, | ||
'content_quantity': -123.45 * 100, | ||
'content_quantity': -assignment_content_quantity_usd_cents, | ||
'state': LearnerContentAssignmentStateChoices.ALLOCATED, | ||
'transaction_uuid': None, | ||
'uuid': str(foo_record.uuid), | ||
|
@@ -617,8 +638,10 @@ def test_allocate_happy_path_e2e( | |
'learner_email': '[email protected]', | ||
'lms_user_id': None, | ||
'content_key': self.content_key, | ||
'parent_content_key': self.parent_content_key, | ||
'is_assigned_course_run': True, | ||
'content_title': self.content_title, | ||
'content_quantity': -123.45 * 100, | ||
'content_quantity': -assignment_content_quantity_usd_cents, | ||
'state': LearnerContentAssignmentStateChoices.ALLOCATED, | ||
'transaction_uuid': None, | ||
'uuid': str(canceled_record.uuid), | ||
|
@@ -635,8 +658,10 @@ def test_allocate_happy_path_e2e( | |
'learner_email': '[email protected]', | ||
'lms_user_id': expired_user.lms_user_id, | ||
'content_key': self.content_key, | ||
'parent_content_key': self.parent_content_key, | ||
'is_assigned_course_run': True, | ||
'content_title': self.content_title, | ||
'content_quantity': -123.45 * 100, | ||
'content_quantity': -assignment_content_quantity_usd_cents, | ||
'state': LearnerContentAssignmentStateChoices.ALLOCATED, | ||
'transaction_uuid': None, | ||
'uuid': str(expired_record.uuid), | ||
|
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 |
---|---|---|
|
@@ -1560,7 +1560,8 @@ def test_credits_available_endpoint_with_content_assignments( | |
learner credit access policies. | ||
""" | ||
self.maxDiff = None | ||
content_key = 'demoX' | ||
parent_content_key = 'edX+DemoX' | ||
content_key = 'course-v1:edX+DemoX+T2024a' | ||
content_title = 'edx: Demo 101' | ||
content_price_cents = 100 | ||
# Create a pair of AssignmentConfiguration + SubsidyAccessPolicy for the main test customer. | ||
|
@@ -1579,6 +1580,8 @@ def test_credits_available_endpoint_with_content_assignments( | |
learner_email='[email protected]', | ||
lms_user_id=1234, | ||
content_key=content_key, | ||
parent_content_key=parent_content_key, | ||
is_assigned_course_run=True, | ||
content_title=content_title, | ||
content_quantity=-content_price_cents, | ||
state=LearnerContentAssignmentStateChoices.ALLOCATED, | ||
|
@@ -1594,6 +1597,8 @@ def test_credits_available_endpoint_with_content_assignments( | |
learner_email='[email protected]', | ||
lms_user_id=12345, | ||
content_key=content_key, | ||
parent_content_key=parent_content_key, | ||
is_assigned_course_run=True, | ||
content_title=content_title, | ||
content_quantity=-content_price_cents, | ||
state=LearnerContentAssignmentStateChoices.ACCEPTED, | ||
|
@@ -1643,6 +1648,8 @@ def test_credits_available_endpoint_with_content_assignments( | |
'learner_email': '[email protected]', | ||
'lms_user_id': 1234, | ||
'content_key': content_key, | ||
'parent_content_key': parent_content_key, | ||
'is_assigned_course_run': True, | ||
'content_title': content_title, | ||
'content_quantity': -content_price_cents, | ||
'state': LearnerContentAssignmentStateChoices.ALLOCATED, | ||
|
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.