-
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
7474847
commit d3fe581
Showing
5 changed files
with
243 additions
and
56 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 |
---|---|---|
|
@@ -49,7 +49,9 @@ def setUp(self): | |
assignment_configuration=self.assignment_configuration, | ||
learner_email='[email protected]', | ||
lms_user_id=None, | ||
content_key='edX+edXPrivacy101', | ||
content_key='course-v1:edX+edXPrivacy101+1T2022', | ||
parent_content_key='edX+edXPrivacy101', | ||
is_assigned_course_run=True, | ||
preferred_course_run_key='course-v1:edX+edXPrivacy101+1T2022', | ||
content_title='edx: Privacy 101', | ||
content_quantity=-123, | ||
|
@@ -61,6 +63,8 @@ def setUp(self): | |
learner_email='[email protected]', | ||
lms_user_id=None, | ||
content_key='edX+edXAccessibility101', | ||
parent_content_key=None, | ||
is_assigned_course_run=False, | ||
preferred_course_run_key='course-v1:edX+edXAccessibility101+1T2022', | ||
content_title='edx: Accessibility 101', | ||
content_quantity=-456, | ||
|
@@ -72,6 +76,8 @@ def setUp(self): | |
learner_email='[email protected]', | ||
lms_user_id=None, | ||
content_key='edX+edXQuadrilateral306090', | ||
parent_content_key=None, | ||
is_assigned_course_run=False, | ||
preferred_course_run_key='course-v1:edX+edXQuadrilateral306090+1T2022', | ||
content_title='edx: Quadrilateral 306090', | ||
content_quantity=-456, | ||
|
@@ -82,6 +88,8 @@ def setUp(self): | |
learner_email='[email protected]', | ||
lms_user_id=None, | ||
content_key='edX+edXTesseract4D', | ||
parent_content_key=None, | ||
is_assigned_course_run=False, | ||
preferred_course_run_key='course-v1:edX+edXTesseract4D+1T2022', | ||
content_title='edx: Tesseract 4D', | ||
content_quantity=-456, | ||
|
@@ -93,6 +101,8 @@ def setUp(self): | |
learner_email='[email protected]', | ||
lms_user_id=None, | ||
content_key='edX+edXIsoscelesPyramid2012', | ||
parent_content_key=None, | ||
is_assigned_course_run=False, | ||
preferred_course_run_key='course-v1:edX+edXIsoscelesPyramid2012+1T2022', | ||
content_title='edx: IsoscelesPyramid 2012', | ||
content_quantity=-456, | ||
|
@@ -103,6 +113,8 @@ def setUp(self): | |
learner_email='[email protected]', | ||
lms_user_id=None, | ||
content_key='edX+edXBeeHivesAlive0220', | ||
parent_content_key=None, | ||
is_assigned_course_run=False, | ||
preferred_course_run_key='course-v1:edX+edXBeeHivesAlive0220+1T2022', | ||
content_title='edx: BeeHivesAlive 0220', | ||
content_quantity=-456, | ||
|
@@ -229,7 +241,9 @@ def test_command( | |
}, | ||
'course_type': 'executive-education-2u', | ||
}, | ||
'edX+edXPrivacy101': { | ||
# `self.alice_assignment` is an assignment for a course run, so its run-based content_key | ||
# should be used as the key in this dict. | ||
'course-v1:edX+edXPrivacy101+1T2022': { | ||
'key': 'edX+edXPrivacy101', | ||
'normalized_metadata': { | ||
'start_date': start_date.strftime("%Y-%m-%dT%H:%M:%SZ"), | ||
|
@@ -367,7 +381,9 @@ def test_command_multiple_assignment_dates( | |
}, | ||
'course_type': 'executive-education-2u', | ||
}, | ||
'edX+edXPrivacy101': { | ||
# `self.alice_assignment` is an assignment for a course run, so its run-based content_key | ||
# should be used as the key in this dict. | ||
'course-v1:edX+edXPrivacy101+1T2022': { | ||
'key': 'edX+edXPrivacy101', | ||
'course_runs': [ | ||
{ | ||
|
@@ -458,7 +474,9 @@ def test_command_multiple_assignment_course_types( | |
}, | ||
}, | ||
}, | ||
'edX+edXPrivacy101': { | ||
# `self.alice_assignment` is an assignment for a course run, so its run-based content_key | ||
# should be used as the key in this dict. | ||
'course-v1:edX+edXPrivacy101+1T2022': { | ||
'key': 'edX+edXPrivacy101', | ||
'course_type': 'executive-education-2u', | ||
'normalized_metadata': { | ||
|
@@ -587,7 +605,9 @@ def test_command_multiple_assignment_states( | |
}, | ||
}, | ||
}, | ||
'edX+edXPrivacy101': { | ||
# `self.alice_assignment` is an assignment for a course run, so its run-based content_key | ||
# should be used as the key in this dict. | ||
'course-v1:edX+edXPrivacy101+1T2022': { | ||
'key': 'edX+edXPrivacy101', | ||
'course_type': 'executive-education-2u', | ||
'normalized_metadata': { | ||
|
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 |
---|---|---|
|
@@ -42,6 +42,22 @@ def delta_t(as_string=False, **kwargs): | |
return datetime_obj | ||
|
||
|
||
def expirable_assignments_with_content_type(): | ||
""" | ||
Returns a list of tuples containing expirable assignment states and the corresponding | ||
assignment content type (course-level or run-based). | ||
Each tuple contains: | ||
- expirable_assignment_state: The current state of the assignment. | ||
- is_assigned_course_run: Boolean indicating if the assignment is course-level (True) or run-based (False). | ||
""" | ||
return [ | ||
(expirable_assignment_state, is_assigned_course_run) | ||
for expirable_assignment_state in LearnerContentAssignmentStateChoices.EXPIRABLE_STATES | ||
for is_assigned_course_run in [True, False] | ||
] | ||
|
||
|
||
@ddt.ddt | ||
class TestContentAssignmentApi(TestCase): | ||
""" | ||
|
@@ -962,23 +978,33 @@ def test_expire_one_assignment_automatically( | |
mock_expired_email.delay.assert_called_once_with(assignment.uuid) | ||
|
||
@ddt.data( | ||
*LearnerContentAssignmentStateChoices.EXPIRABLE_STATES | ||
*expirable_assignments_with_content_type() | ||
) | ||
@ddt.unpack | ||
@mock.patch('enterprise_access.apps.content_assignments.api.send_assignment_automatically_expired_email') | ||
def test_expire_assignments_with_passed_enroll_by_date( | ||
self, | ||
assignment_state, | ||
expirable_assignment_state, | ||
is_assigned_course_run, | ||
mock_expired_email, | ||
): | ||
""" | ||
Tests that we expire assignments with a passed enroll_by_date | ||
""" | ||
content_key = 'edX+DemoX' | ||
course_key = 'edX+DemoX' | ||
course_run_key = 'course-v1:edX+DemoX+T2024' | ||
content_key = course_key | ||
parent_content_key = None | ||
if is_assigned_course_run: | ||
content_key = course_run_key | ||
parent_content_key = course_key | ||
|
||
assignment = LearnerContentAssignmentFactory.create( | ||
content_key='demoX', | ||
content_key=content_key, | ||
parent_content_key=parent_content_key, | ||
is_assigned_course_run=is_assigned_course_run, | ||
assignment_configuration=self.assignment_configuration, | ||
state=assignment_state, | ||
state=expirable_assignment_state, | ||
learner_email='[email protected]', | ||
lms_user_id=12345, | ||
) | ||
|
@@ -1009,23 +1035,33 @@ def test_expire_assignments_with_passed_enroll_by_date( | |
mock_expired_email.delay.assert_called_once_with(assignment.uuid) | ||
|
||
@ddt.data( | ||
*LearnerContentAssignmentStateChoices.EXPIRABLE_STATES | ||
*expirable_assignments_with_content_type() | ||
) | ||
@ddt.unpack | ||
@mock.patch('enterprise_access.apps.content_assignments.api.send_assignment_automatically_expired_email') | ||
def test_expire_assignments_with_expired_subsidy( | ||
self, | ||
assignment_state, | ||
expirable_assignment_state, | ||
is_assigned_course_run, | ||
mock_expired_email, | ||
): | ||
""" | ||
Tests that we expire assignments with an underlying subsidy that has expired. | ||
""" | ||
content_key = 'edX+DemoX' | ||
course_key = 'edX+DemoX' | ||
course_run_key = 'course-v1:edX+DemoX+T2024' | ||
content_key = course_key | ||
parent_content_key = None | ||
if is_assigned_course_run: | ||
content_key = course_run_key | ||
parent_content_key = course_key | ||
|
||
assignment = LearnerContentAssignmentFactory.create( | ||
assignment_configuration=self.assignment_configuration, | ||
content_key=content_key, | ||
state=assignment_state, | ||
parent_content_key=parent_content_key, | ||
is_assigned_course_run=is_assigned_course_run, | ||
state=expirable_assignment_state, | ||
learner_email='[email protected]', | ||
lms_user_id=12345, | ||
) | ||
|
Oops, something went wrong.