Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: not start rti tasks if not course-config #216

Merged
merged 6 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions eox_nelp/signals/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,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):
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 @@ -426,7 +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):
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
107 changes: 80 additions & 27 deletions eox_nelp/signals/tests/test_receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import unittest

from ddt import data, ddt
from django.conf import settings
from django.contrib.auth import get_user_model
from django.test import override_settings
from django.utils import timezone
Expand Down Expand Up @@ -697,7 +698,11 @@ def test_call_async_task(self, task_mock):
@ddt
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]

@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 @@ -706,20 +711,40 @@ def test_invalid_feature_flag(self, task_mock):
- real_time_import_task mock has not been called.
"""
instance = Mock()
instance.user_id = 17
course_id = "course-v1:test+Cx105+2022_T4"
instance.context_key = CourseKey.from_string(course_id)
instance.user_id = self.user_id
instance.context_key = CourseKey.from_string(self.course_id)

pearson_vue_course_completion_handler(instance)

task_mock.delay.assert_not_called()

@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_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_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_ENGINE_COURSES_ENABLED=course_exam_configuration,
)
@data( # is_complete and graded values respectively
(True, True),
(False, True),
(False, False),
)
@override_settings(PEARSON_RTI_ACTIVATE_COMPLETION_GATE=True)
@patch("eox_nelp.signals.receivers.get_completed_and_graded")
@patch("eox_nelp.signals.receivers.real_time_import_task")
def test_invalid_course_state(self, invalid_state, task_mock, get_completed_and_graded_mock):
Expand All @@ -729,16 +754,18 @@ def test_invalid_course_state(self, invalid_state, task_mock, get_completed_and_
- real_time_import_task mock has not been called.
"""
instance = Mock()
instance.user_id = 17
course_id = "course-v1:test+Cx105+2022_T4"
instance.context_key = CourseKey.from_string(course_id)
instance.user_id = self.user_id
instance.context_key = CourseKey.from_string(self.course_id)
get_completed_and_graded_mock.return_value = invalid_state

pearson_vue_course_completion_handler(instance)

task_mock.delay.assert_not_called()

@override_settings(PEARSON_RTI_ACTIVATE_COMPLETION_GATE=True)
@override_settings(
PEARSON_RTI_ACTIVATE_COMPLETION_GATE=True,
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")
def test_call_async_task(self, task_mock, get_completed_and_graded_mock):
Expand All @@ -748,19 +775,22 @@ def test_call_async_task(self, task_mock, get_completed_and_graded_mock):
- delay method is called with the right values.
"""
instance = Mock()
instance.user_id = 5
course_id = "course-v1:test+Cx105+2022_T4"
instance.context_key = CourseKey.from_string(course_id)
instance.user_id = self.user_id
instance.context_key = CourseKey.from_string(self.course_id)
get_completed_and_graded_mock.return_value = (True, False) # is_complete and graded values respectively

pearson_vue_course_completion_handler(instance)

task_mock.delay.assert_called_with(
user_id=instance.user_id,
course_id=course_id,
course_id=self.course_id,
)

@override_settings(PEARSON_RTI_ACTIVATE_COMPLETION_GATE=True, USE_PEARSON_ENGINE_SERVICE=True)
@override_settings(
PEARSON_RTI_ACTIVATE_COMPLETION_GATE=True,
USE_PEARSON_ENGINE_SERVICE=True,
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")
def test_call_async_task_v2(self, task_mock, get_completed_and_graded_mock):
Expand All @@ -770,70 +800,93 @@ def test_call_async_task_v2(self, task_mock, get_completed_and_graded_mock):
- delay method is called with the right values.
"""
instance = Mock()
instance.user_id = 5
course_id = "course-v1:test+Cx105+2022_T4"
instance.context_key = CourseKey.from_string(course_id)
instance.user_id = self.user_id
instance.context_key = CourseKey.from_string(self.course_id)
get_completed_and_graded_mock.return_value = (True, False) # is_complete and graded values respectively

pearson_vue_course_completion_handler(instance)

task_mock.delay.assert_called_with(
user_id=instance.user_id,
exam_id=course_id,
exam_id=self.course_id,
action_name="rti"
)


@ddt
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]

@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.

Expected behavior:
- real_time_import_task mock has not been called.
"""
course_id = "course-v1:test+Cx105+2022_T4"
user_instance, _ = User.objects.get_or_create(username="Severus")

pearson_vue_course_passed_handler(user_instance, CourseKey.from_string(course_id))
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)
@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_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_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_ENGINE_COURSES_ENABLED=course_exam_configuration,
)
@patch("eox_nelp.signals.receivers.real_time_import_task")
def test_call_async_task(self, task_mock):
"""Test that the async task is called with the right parameters

Expected behavior:
- delay method is called with the right values.
"""
course_id = "course-v1:test+Cx105+2022_T4"
user_instance, _ = User.objects.get_or_create(username="Severus")

pearson_vue_course_passed_handler(user_instance, CourseKey.from_string(course_id))
pearson_vue_course_passed_handler(user_instance, CourseKey.from_string(self.course_id))

task_mock.delay.assert_called_with(
course_id=course_id,
course_id=self.course_id,
user_id=user_instance.id,
)

@override_settings(PEARSON_RTI_ACTIVATE_GRADED_GATE=True, USE_PEARSON_ENGINE_SERVICE=True)
@override_settings(
PEARSON_RTI_ACTIVATE_GRADED_GATE=True,
USE_PEARSON_ENGINE_SERVICE=True,
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):
"""Test that the async task is called with the right parameters

Expected behavior:
- delay method is called with the right values.
"""
course_id = "course-v1:test+Cx105+2022_T4"
user_instance, _ = User.objects.get_or_create(username="Severus")

pearson_vue_course_passed_handler(user_instance, CourseKey.from_string(course_id))
pearson_vue_course_passed_handler(user_instance, CourseKey.from_string(self.course_id))

task_mock.delay.assert_called_with(
exam_id=course_id,
exam_id=self.course_id,
user_id=user_instance.id,
action_name="rti",
)
Expand Down
Loading