Skip to content

Commit

Permalink
feat: elegibility_appt_dates runtime calculations (#198)
Browse files Browse the repository at this point in the history
* feat: elegibility_appt_data runtime calculations

* feat: pr recommendation, check correct keys
  • Loading branch information
johanseto authored Jul 16, 2024
1 parent 4ccb809 commit 3bf8ece
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
8 changes: 6 additions & 2 deletions eox_nelp/pearson_vue/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,14 @@ def get_exam_data(user_id, course_id, **kwargs): # pylint: disable=unused-argum
User.objects.get(id=user_id),
course_id,
)
# configure eligibility appt date with settings course delta starting from now. Default one year.
elegibility_appt_delta_days = exam_metadata.get("elegibility_appt_delta_days", 365)
exam_metadata["eligibility_appt_date_first"] = timezone.now().strftime("%Y/%m/%d %H:%M:%S")
exam_metadata["eligibility_appt_date_last"] = (
timezone.now() + timezone.timedelta(days=elegibility_appt_delta_days)
).strftime("%Y/%m/%d %H:%M:%S")

required_fields = {
"eligibility_appt_date_first",
"eligibility_appt_date_last",
"exam_authorization_count",
"exam_series_code",
}
Expand Down
18 changes: 11 additions & 7 deletions eox_nelp/pearson_vue/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,29 +597,34 @@ def tearDown(self):
"""Restore mocks' state"""
CourseEnrollment.reset_mock()

@patch.object(timezone, "now")
@override_settings()
def test_get_exam_data_success(self):
def test_get_exam_data_success(self, mock_now):
"""
Test that the get_exam_data function return the set values.
Expected behavior:
- The result is the expected value.
"""
mock_now.return_value = timezone.datetime(2024, 5, 20, 12, 0, 0)
course_id = self.course_id
exam_data = {
"eligibility_appt_date_first": "2024/05/05 12:00:00",
"eligibility_appt_date_last": "2025/05/05 12:00:00",
"exam_authorization_count": 3,
"exam_series_code": "ABD",
}
course_id = self.course_id
course_settings = {
course_id: exam_data
}
setattr(settings, "PEARSON_RTI_COURSES_DATA", course_settings)
expected_data = {
**exam_data,
"eligibility_appt_date_first": mock_now().strftime("%Y/%m/%d %H:%M:%S"),
"eligibility_appt_date_last": (mock_now() + timezone.timedelta(days=365)).strftime("%Y/%m/%d %H:%M:%S"),
}

result = get_exam_data(self.user.id, course_id)

self.assertEqual(result["exam_metadata"], exam_data)
for key, value in expected_data.items():
self.assertEqual(result["exam_metadata"][key], value)

@override_settings()
def test_get_exam_data_failure(self):
Expand All @@ -634,7 +639,6 @@ def test_get_exam_data_failure(self):
course_settings = {
course_id: {
"invalid_key": "test",
"eligibility_appt_date_last": "2024/05/05 12:00:00",
"exam_authorization_count": 4,
}
}
Expand Down

0 comments on commit 3bf8ece

Please sign in to comment.