Skip to content

Commit

Permalink
chore: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstankiewicz committed Sep 19, 2024
1 parent 7474847 commit d3fe581
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ def handle(self, *args, **options):
if datetime_start_date is not None
else False
)

print(
'NUDGE?!?!?!:',
{
'assignment_uuid': str(assignment.uuid),
'content_key': assignment.content_key,
'parent_content_key': assignment.parent_content_key,
'start_date': start_date,
'datetime_start_date': datetime_start_date,
'num_days': days_before_course_start_date,
'result': can_send_nudge_notification_in_advance,
},
)

if not can_send_nudge_notification_in_advance:
logger.info(
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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': [
{
Expand Down Expand Up @@ -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': {
Expand Down Expand Up @@ -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': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ class Meta:
lms_user_id = factory.LazyAttribute(lambda _: FAKER.pyint())
content_key = factory.LazyAttribute(lambda _: random_content_key())
parent_content_key = factory.LazyAttribute(lambda _: random_parent_content_key())
is_assigned_course_run = factory.LazyAttribute(lambda _: FAKER.pybool())
is_assigned_course_run = True
content_title = factory.LazyAttribute(lambda _: f'{FAKER.word()}: a master class')
content_quantity = factory.LazyAttribute(lambda _: FAKER.pyfloat(positive=False, right_digits=0))
54 changes: 45 additions & 9 deletions enterprise_access/apps/content_assignments/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down
Loading

0 comments on commit d3fe581

Please sign in to comment.