From 1936c70b62ef22aa97340ba55037b69ccb0ecc52 Mon Sep 17 00:00:00 2001 From: Johan Castiblanco Date: Fri, 12 Jul 2024 18:05:21 -0500 Subject: [PATCH 1/2] feat: elegibility_appt_data runtime calculations --- eox_nelp/pearson_vue/pipeline.py | 6 ++++++ eox_nelp/pearson_vue/tests/test_pipeline.py | 15 ++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/eox_nelp/pearson_vue/pipeline.py b/eox_nelp/pearson_vue/pipeline.py index 0fa0134d..361aab20 100644 --- a/eox_nelp/pearson_vue/pipeline.py +++ b/eox_nelp/pearson_vue/pipeline.py @@ -323,6 +323,12 @@ 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", diff --git a/eox_nelp/pearson_vue/tests/test_pipeline.py b/eox_nelp/pearson_vue/tests/test_pipeline.py index 2eb66614..84532d79 100644 --- a/eox_nelp/pearson_vue/tests/test_pipeline.py +++ b/eox_nelp/pearson_vue/tests/test_pipeline.py @@ -597,29 +597,31 @@ 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) 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", + "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"), } course_id = self.course_id course_settings = { - course_id: exam_data + course_id: exam_data.copy() } setattr(settings, "PEARSON_RTI_COURSES_DATA", course_settings) result = get_exam_data(self.user.id, course_id) - - self.assertEqual(result["exam_metadata"], exam_data) + for key, value in exam_data.items(): + self.assertEqual(result["exam_metadata"][key], value) @override_settings() def test_get_exam_data_failure(self): @@ -634,7 +636,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, } } From fe6749b5af8427d8b810a64161cf090f2d41d17b Mon Sep 17 00:00:00 2001 From: Johan Castiblanco Date: Tue, 16 Jul 2024 14:57:00 -0500 Subject: [PATCH 2/2] feat: pr recommendation, check correct keys --- eox_nelp/pearson_vue/pipeline.py | 2 -- eox_nelp/pearson_vue/tests/test_pipeline.py | 13 ++++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/eox_nelp/pearson_vue/pipeline.py b/eox_nelp/pearson_vue/pipeline.py index 361aab20..769e6354 100644 --- a/eox_nelp/pearson_vue/pipeline.py +++ b/eox_nelp/pearson_vue/pipeline.py @@ -331,8 +331,6 @@ def get_exam_data(user_id, course_id, **kwargs): # pylint: disable=unused-argum ).strftime("%Y/%m/%d %H:%M:%S") required_fields = { - "eligibility_appt_date_first", - "eligibility_appt_date_last", "exam_authorization_count", "exam_series_code", } diff --git a/eox_nelp/pearson_vue/tests/test_pipeline.py b/eox_nelp/pearson_vue/tests/test_pipeline.py index 84532d79..2c5ac2dd 100644 --- a/eox_nelp/pearson_vue/tests/test_pipeline.py +++ b/eox_nelp/pearson_vue/tests/test_pipeline.py @@ -607,20 +607,23 @@ def test_get_exam_data_success(self, mock_now): - 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 = { "exam_authorization_count": 3, "exam_series_code": "ABD", - "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"), } - course_id = self.course_id course_settings = { - course_id: exam_data.copy() + 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) - for key, value in exam_data.items(): + for key, value in expected_data.items(): self.assertEqual(result["exam_metadata"][key], value) @override_settings()