-
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
- Loading branch information
1 parent
990b386
commit c5707c2
Showing
8 changed files
with
138 additions
and
13 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. | ||
|
@@ -509,6 +517,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 +549,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, | ||
|
@@ -554,6 +566,8 @@ def test_allocate_happy_path_e2e( | |
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, | ||
state=LearnerContentAssignmentStateChoices.EXPIRED, | ||
|
@@ -594,6 +608,8 @@ 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, | ||
'state': LearnerContentAssignmentStateChoices.ALLOCATED, | ||
|
@@ -607,6 +623,7 @@ def test_allocate_happy_path_e2e( | |
'reason': AssignmentAutomaticExpiredReason.NINETY_DAYS_PASSED | ||
} | ||
}] | ||
|
||
self.assertEqual(response_payload['created'], expected_created_records) | ||
|
||
canceled_record = allocation_records_by_email['[email protected]'] | ||
|
@@ -617,6 +634,8 @@ 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, | ||
'state': LearnerContentAssignmentStateChoices.ALLOCATED, | ||
|
@@ -635,6 +654,8 @@ 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, | ||
'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
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
39 changes: 39 additions & 0 deletions
39
...nts/migrations/0023_historicallearnercontentassignment_is_assigned_course_run_and_more.py
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Generated by Django 4.2.15 on 2024-08-26 14:06 | ||
|
||
from django.db import migrations, models | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('content_assignments', '0022_allocated_at_not_null'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='historicallearnercontentassignment', | ||
name='is_assigned_course_run', | ||
field=models.BooleanField(default=False, help_text='Whether the content_key corresponds to a course run. If True, the content_key should be a course run key.'), | ||
), | ||
migrations.AddField( | ||
model_name='historicallearnercontentassignment', | ||
name='parent_content_key', | ||
field=models.CharField(blank=True, db_index=True, help_text='The globally unique content identifier of the parent content to assign to the learner. Joinable with ContentMetadata.content_key in enterprise-catalog.', max_length=255, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='learnercontentassignment', | ||
name='is_assigned_course_run', | ||
field=models.BooleanField(default=False, help_text='Whether the content_key corresponds to a course run. If True, the content_key should be a course run key.'), | ||
), | ||
migrations.AddField( | ||
model_name='learnercontentassignment', | ||
name='parent_content_key', | ||
field=models.CharField(blank=True, db_index=True, help_text='The globally unique content identifier of the parent content to assign to the learner. Joinable with ContentMetadata.content_key in enterprise-catalog.', max_length=255, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='historicallearnercontentassignment', | ||
name='allocated_at', | ||
field=models.DateTimeField(blank=True, default=django.utils.timezone.now, help_text='The last time the assignment was allocated. Cannot be null.'), | ||
), | ||
] |
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