Skip to content

Commit

Permalink
feat: use different setting per case
Browse files Browse the repository at this point in the history
  • Loading branch information
johanseto committed Sep 4, 2024
1 parent 7785b9b commit 609622d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
16 changes: 10 additions & 6 deletions eox_nelp/signals/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,7 @@ def pearson_vue_course_completion_handler(instance, **kwargs): # pylint: disabl
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):
return

is_complete, graded = get_completed_and_graded(user_id=instance.user_id, course_id=str(instance.context_key))
Expand All @@ -408,12 +406,16 @@ def pearson_vue_course_completion_handler(instance, **kwargs): # pylint: disabl
)

if getattr(settings, "USE_PEARSON_ENGINE_SERVICE", False):
if not getattr(settings, "PEARSON_RTI_COURSES_DATA", {}).get(str(instance.context_key)):
return
real_time_import_task_v2.delay(
user_id=instance.user_id,
exam_id=str(instance.context_key),
action_name="rti",
)
else:
if not getattr(settings, "PEARSON_RTI_COURSES_DATA", {}).get(str(instance.context_key)):
return
real_time_import_task.delay(
user_id=instance.user_id,
course_id=str(instance.context_key),
Expand All @@ -430,9 +432,7 @@ 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):
return

LOGGER.info(
Expand All @@ -441,12 +441,16 @@ def pearson_vue_course_passed_handler(user, course_id, **kwargs): # pylint: dis
)

if getattr(settings, "USE_PEARSON_ENGINE_SERVICE", False):
if not getattr(settings, "PEARSON_RTI_COURSES_DATA", {}).get(str(course_id)):
return
real_time_import_task_v2.delay(
user_id=user.id,
exam_id=str(course_id),
action_name="rti",
)
else:
if not getattr(settings, "PEARSON_RTI_COURSES_DATA", {}).get(str(course_id)):
return
real_time_import_task.delay(
course_id=str(course_id),
user_id=user.id,
Expand Down
6 changes: 4 additions & 2 deletions eox_nelp/signals/tests/test_receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,11 @@ def test_invalid_feature_flag(self, task_mock):

task_mock.delay.assert_not_called()

@data({}, {"course-v1:notdesired": {"exam_series_code": "OTT"}}, {"key": 6})
@override_settings(PEARSON_RTI_ACTIVATE_COMPLETION_GATE=True)
@data({}, {"course-v1:notdesired": {"exam_series_code": "OTT"}}, {"key": 6})
@patch("eox_nelp.signals.receivers.get_completed_and_graded")
@patch("eox_nelp.signals.receivers.real_time_import_task")
def test_invalid_course_configuration(self, wrong_course_config, task_mock):
def test_invalid_course_configuration(self, wrong_course_config, task_mock, get_completed_and_graded_mock):
"""Test when the PEARSON_RTI_ACTIVATE_COMPLETION_GATE settings is True,
but invalid course configuration for PEARSON_RTI_COURSES_DATA.
Expected behavior:
Expand All @@ -735,6 +736,7 @@ def test_invalid_course_configuration(self, wrong_course_config, task_mock):
instance = Mock()
instance.user_id = self.user_id
instance.context_key = CourseKey.from_string(self.course_id)
get_completed_and_graded_mock.return_value = (True, False)
setattr(settings, "PEARSON_RTI_COURSES_DATA", wrong_course_config)

pearson_vue_course_completion_handler(instance)
Expand Down

0 comments on commit 609622d

Please sign in to comment.