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 763343d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 43 deletions.
30 changes: 12 additions & 18 deletions eox_nelp/signals/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,12 @@ def emit_initialized_course_event(instance, **kwargs): # pylint: disable=unused
"block_id": str(instance.block_key),
"modified": instance.modified,
"created": instance.created,
}
},
)


def course_grade_changed_progress_publisher(
user,
course_key,
course_grade,
**kwargs
user, course_key, course_grade, **kwargs
): # pylint: disable=unused-argument
"""This receiver is connected to the COURSE_GRADE_CHANGED signal
and will publish user course progress based on the given data.
Expand Down Expand Up @@ -209,9 +206,9 @@ def enrollment_publisher(instance, **kwargs): # pylint: disable=unused-argument
),
mode=instance.mode,
grade=course_grade.percent,
current_status='downloadable' if course_grade.passed else 'not-passing',
download_url='',
name='',
current_status="downloadable" if course_grade.passed else "not-passing",
download_url="",
name="",
)

create_external_certificate.delay(
Expand Down Expand Up @@ -320,10 +317,7 @@ def emit_subsection_attempt_event(usage_id, user_id, *args, **kwargs): # pylint
"""This emits the 'nelc.eox_nelp.grades.subsection.submitted' event
when a graded subsection has been attempted.
"""
emit_subsection_attempt_event_task.delay(
usage_id=usage_id,
user_id=user_id
)
emit_subsection_attempt_event_task.delay(usage_id=usage_id, user_id=user_id)


def mt_course_completion_handler(instance, **kwargs): # pylint: disable=unused-argument
Expand Down Expand Up @@ -392,9 +386,9 @@ 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) 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 +424,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 763343d

Please sign in to comment.