Skip to content

Commit

Permalink
feat: use only PEARSON_ENGINE_COURSES_ENABLED
Browse files Browse the repository at this point in the history
This settings must to be a list with the course_id strings enabled
  • Loading branch information
johanseto committed Sep 11, 2024
1 parent fb927dd commit e1af959
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
14 changes: 6 additions & 8 deletions eox_nelp/signals/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,13 @@ def pearson_vue_course_completion_handler(instance, **kwargs): # pylint: disabl
the pearson vue real_time_import_task , that basically runs the RTI pipeline
on the completion logic.
This sends only the user_id and course_id kwargs.
user_id -> instance.user_id
course_key -> instance.context_key
Arguments:
instance<Blockcompletion>: Instance of BlockCompletion model.
"""
if not getattr(settings, "PEARSON_RTI_ACTIVATE_COMPLETION_GATE", False) or not getattr(
settings, "PEARSON_RTI_COURSES_DATA", {}
).get(str(instance.context_key)):
if not getattr(settings, "PEARSON_RTI_ACTIVATE_COMPLETION_GATE", False) or not str(instance.context_key) in getattr(
settings, "PEARSON_ENGINE_COURSES_ENABLED", []
):
return

is_complete, graded = get_completed_and_graded(user_id=instance.user_id, course_id=str(instance.context_key))
Expand Down Expand Up @@ -430,9 +428,9 @@ def pearson_vue_course_passed_handler(user, course_id, **kwargs): # pylint: dis
user <User>: Instance of auth user model.
course_id <CourseLocator>: Course locator.
"""
if not getattr(settings, "PEARSON_RTI_ACTIVATE_GRADED_GATE", False) or not getattr(
settings, "PEARSON_RTI_COURSES_DATA", {}
).get(str(course_id)):
if not getattr(settings, "PEARSON_RTI_ACTIVATE_GRADED_GATE", False) or not str(course_id) in getattr(
settings, "PEARSON_ENGINE_COURSES_ENABLED", []
):
return

LOGGER.info(
Expand Down
43 changes: 18 additions & 25 deletions eox_nelp/signals/tests/test_receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,14 +700,9 @@ class PearsonVueCompletionHandlerTestCase(unittest.TestCase):
"""Test class for pearson_vue_course_completion_handler function."""
course_id = "course-v1:test+Cx105+2022_T4"
user_id = 5
course_exam_configuration = {
course_id: {
"exam_authorization_count": 3,
"exam_series_code": "OTT"
},
}

@override_settings(PEARSON_RTI_COURSES_DATA=course_exam_configuration)
course_exam_configuration = [course_id]

@override_settings(PEARSON_ENGINE_COURSES_ENABLED=course_exam_configuration)
@patch("eox_nelp.signals.receivers.real_time_import_task")
def test_invalid_feature_flag(self, task_mock):
"""Test when the PEARSON_RTI_ACTIVATE_COMPLETION_GATE settings is False.
Expand All @@ -723,27 +718,27 @@ def test_invalid_feature_flag(self, task_mock):

task_mock.delay.assert_not_called()

@data({}, {"course-v1:notdesired": {"exam_series_code": "OTT"}}, {"key": 6})
@data({}, [], ["exam_series_code"], ["key"], ["wrong_course_id"])
@override_settings(PEARSON_RTI_ACTIVATE_COMPLETION_GATE=True)
@patch("eox_nelp.signals.receivers.real_time_import_task")
def test_invalid_course_configuration(self, wrong_course_config, task_mock):
"""Test when the PEARSON_RTI_ACTIVATE_COMPLETION_GATE settings is True,
but invalid course configuration for PEARSON_RTI_COURSES_DATA.
but invalid course configuration for PEARSON_ENGINE_COURSES_ENABLED.
Expected behavior:
- real_time_import_task mock has not been called.
"""
instance = Mock()
instance.user_id = self.user_id
instance.context_key = CourseKey.from_string(self.course_id)
setattr(settings, "PEARSON_RTI_COURSES_DATA", wrong_course_config)
setattr(settings, "PEARSON_ENGINE_COURSES_ENABLED", wrong_course_config)

pearson_vue_course_completion_handler(instance)

task_mock.delay.assert_not_called()

@override_settings(
PEARSON_RTI_ACTIVATE_COMPLETION_GATE=True,
PEARSON_RTI_COURSES_DATA=course_exam_configuration,
PEARSON_ENGINE_COURSES_ENABLED=course_exam_configuration,
)
@data( # is_complete and graded values respectively
(True, True),
Expand All @@ -769,7 +764,7 @@ def test_invalid_course_state(self, invalid_state, task_mock, get_completed_and_

@override_settings(
PEARSON_RTI_ACTIVATE_COMPLETION_GATE=True,
PEARSON_RTI_COURSES_DATA=course_exam_configuration,
PEARSON_ENGINE_COURSES_ENABLED=course_exam_configuration,
)
@patch("eox_nelp.signals.receivers.get_completed_and_graded")
@patch("eox_nelp.signals.receivers.real_time_import_task")
Expand All @@ -794,7 +789,7 @@ def test_call_async_task(self, task_mock, get_completed_and_graded_mock):
@override_settings(
PEARSON_RTI_ACTIVATE_COMPLETION_GATE=True,
USE_PEARSON_ENGINE_SERVICE=True,
PEARSON_RTI_COURSES_DATA=course_exam_configuration,
PEARSON_ENGINE_COURSES_ENABLED=course_exam_configuration,
)
@patch("eox_nelp.signals.receivers.get_completed_and_graded")
@patch("eox_nelp.signals.receivers.real_time_import_task_v2")
Expand Down Expand Up @@ -822,12 +817,10 @@ def test_call_async_task_v2(self, task_mock, get_completed_and_graded_mock):
class PearsonVueCoursePassedHandlerTestCase(unittest.TestCase):
"""Test class for mt_course_passed_handler function."""
course_id = "course-v1:test+Cz105+2022_T4"
course_exam_configuration = {
course_id: True,
}
course_exam_configuration = [course_id]

@override_settings(PEARSON_RTI_COURSES_DATA=course_exam_configuration)
@patch("eox_nelp.signals.receivers.update_mt_training_stage")
@override_settings(PEARSON_ENGINE_COURSES_ENABLED=course_exam_configuration)
@patch("eox_nelp.signals.receivers.real_time_import_task")
def test_invalid_feature_flag(self, task_mock):
"""Test when the PEARSON_RTI_ACTIVATE_GRADED_GATE settings is False.
Expand All @@ -841,24 +834,24 @@ def test_invalid_feature_flag(self, task_mock):
task_mock.delay.assert_not_called()

@override_settings(PEARSON_RTI_ACTIVATE_GRADED_GATE=True)
@data({}, {"course-v1:notdesired": True}, {"key": 6})
@patch("eox_nelp.signals.receivers.update_mt_training_stage")
@data({}, [], ["exam_series_code"], ["key"], ["wrong_course_id"])
@patch("eox_nelp.signals.receivers.real_time_import_task")
def test_invalid_course_configuration(self, wrong_course_config, task_mock):
"""Test when the PEARSON_RTI_ACTIVATE_GRADED_GATE settings is True,
but invalid course configuration for PEARSON_RTI_COURSES_DATA
but invalid course configuration for PEARSON_ENGINE_COURSES_ENABLED
Expected behavior:
- real_time_import_task mock has not been called.
"""
user_instance, _ = User.objects.get_or_create(username="Severus")
setattr(settings, "PEARSON_RTI_COURSES_DATA", wrong_course_config)
setattr(settings, "PEARSON_ENGINE_COURSES_ENABLED", wrong_course_config)
pearson_vue_course_passed_handler(user_instance, CourseKey.from_string(self.course_id))

task_mock.delay.assert_not_called()

@override_settings(
PEARSON_RTI_ACTIVATE_GRADED_GATE=True,
PEARSON_RTI_COURSES_DATA=course_exam_configuration,
PEARSON_ENGINE_COURSES_ENABLED=course_exam_configuration,
)
@patch("eox_nelp.signals.receivers.real_time_import_task")
def test_call_async_task(self, task_mock):
Expand All @@ -879,7 +872,7 @@ def test_call_async_task(self, task_mock):
@override_settings(
PEARSON_RTI_ACTIVATE_GRADED_GATE=True,
USE_PEARSON_ENGINE_SERVICE=True,
PEARSON_RTI_COURSES_DATA=course_exam_configuration,
PEARSON_ENGINE_COURSES_ENABLED=course_exam_configuration,
)
@patch("eox_nelp.signals.receivers.real_time_import_task_v2")
def test_call_async_task_v2(self, task_mock):
Expand Down

0 comments on commit e1af959

Please sign in to comment.