diff --git a/platform_plugin_turnitin/tests/test_filters.py b/platform_plugin_turnitin/tests/test_filters.py index 9231f72..3b0b702 100644 --- a/platform_plugin_turnitin/tests/test_filters.py +++ b/platform_plugin_turnitin/tests/test_filters.py @@ -4,7 +4,6 @@ from unittest.mock import Mock, patch from django.test.utils import override_settings -from opaque_keys.edx.keys import UsageKey from platform_plugin_turnitin.extensions.filters import ORASubmissionViewTurnitinWarning @@ -18,30 +17,23 @@ def setUp(self) -> None: self.template_name = "template_name" self.new_template_name = "turnitin/oa_response.html" - @patch("platform_plugin_turnitin.extensions.filters.modulestore") - @patch.object(UsageKey, "from_string") - def test_run_filter_turnitin_submission_disabled(self, mock_from_string: Mock, mock_modulestore: Mock): + @patch("platform_plugin_turnitin.extensions.filters.enabled_in_course") + def test_run_filter_turnitin_submission_disabled(self, mock_enabled_in_course: Mock): """ Test `run_filter` method when Turnitin submission is disabled. Expected result: The dictionary contains the same context and template name. """ - mock_from_string.return_value.course_key = "test_course_key" - mock_modulestore.return_value.get_course.return_value = Mock( - other_course_settings={"ENABLE_TURNITIN_SUBMISSION": False}, - ) + mock_enabled_in_course.return_value = False result = self.pipeline_step.run_filter(self.context, self.template_name) self.assertEqual(result["context"], self.context) self.assertEqual(result["template_name"], self.template_name) - @patch("platform_plugin_turnitin.extensions.filters.modulestore") - @patch.object(UsageKey, "from_string") + @patch("platform_plugin_turnitin.extensions.filters.enabled_in_course") @override_settings(ENABLE_TURNITIN_SUBMISSION=True) - def test_run_filter_turnitin_submission_enabled_by_global_setting( - self, mock_from_string: Mock, mock_modulestore: Mock - ): + def test_run_filter_turnitin_submission_enabled_by_global_setting(self, mock_enabled_in_course: Mock): """ Test `run_filter` method when Turnitin submission is enabled by the global setting. @@ -51,23 +43,16 @@ def test_run_filter_turnitin_submission_enabled_by_global_setting( self.assertEqual(result["context"], self.context) self.assertEqual(result["template_name"], self.new_template_name) - mock_from_string.assert_not_called() - mock_modulestore.assert_not_called() - - @patch("platform_plugin_turnitin.extensions.filters.modulestore") - @patch.object(UsageKey, "from_string") - def test_run_filter_turnitin_submission_enabled_by_course_setting( - self, mock_from_string: Mock, mock_modulestore: Mock - ): + mock_enabled_in_course.assert_not_called() + + @patch("platform_plugin_turnitin.extensions.filters.enabled_in_course") + def test_run_filter_turnitin_submission_enabled_by_course_setting(self, mock_enabled_in_course: Mock): """ Test `run_filter` method when Turnitin submission is enabled by the course setting. Expected result: The dictionary contains the context and the new template name. """ - mock_from_string.return_value.course_key = "test_course_key" - mock_modulestore.return_value.get_course.return_value = Mock( - other_course_settings={"ENABLE_TURNITIN_SUBMISSION": True}, - ) + mock_enabled_in_course.return_value = True result = self.pipeline_step.run_filter(self.context, self.template_name) diff --git a/platform_plugin_turnitin/tests/test_handlers.py b/platform_plugin_turnitin/tests/test_handlers.py index f13bcf5..e37f97d 100644 --- a/platform_plugin_turnitin/tests/test_handlers.py +++ b/platform_plugin_turnitin/tests/test_handlers.py @@ -12,44 +12,49 @@ class TestHandlers(TestCase): """Tests for the handlers module.""" def setUp(self) -> None: - self.submission = Mock(location="test_block_id") - - @patch("platform_plugin_turnitin.handlers.call_ora_submission_created_task") - @patch("platform_plugin_turnitin.handlers.modulestore") - @patch("platform_plugin_turnitin.handlers.UsageKey") - def test_ora_submission_created_all_disabled( - self, mock_usage_key: Mock, mock_modulestore: Mock, mock_call_task: Mock - ): - """Test `ora_submission_created` when Turnitin submission is disabled globally and for the course.""" - mock_usage_key.from_string.return_value.course_key = "course_key" - mock_modulestore.return_value.get_course.return_value = Mock( - other_course_settings={"ENABLE_TURNITIN_SUBMISSION": False}, + self.submission = Mock( + uuid="submission_uuid", + location="block_id", + anonymous_user_id="user_id", + answer=Mock(parts=[], file_names=[], file_urls=[]), ) + @patch("platform_plugin_turnitin.handlers.ora_submission_created_task.delay") + @patch("platform_plugin_turnitin.handlers.enabled_in_course") + def test_ora_submission_created_all_disabled(self, mock_enabled_in_course: Mock, mock_call_task: Mock): + """Test `ora_submission_created` when Turnitin submission is disabled globally and for the course.""" + mock_enabled_in_course.return_value = False + ora_submission_created(self.submission) mock_call_task.assert_not_called() @override_settings(ENABLE_TURNITIN_SUBMISSION=True) - @patch("platform_plugin_turnitin.handlers.call_ora_submission_created_task") + @patch("platform_plugin_turnitin.handlers.ora_submission_created_task.delay") def test_ora_submission_created_global_enabled(self, mock_call_task: Mock): """Test `ora_submission_created` when Turnitin submission is enabled globally.""" ora_submission_created(self.submission) - mock_call_task.assert_called_once_with(self.submission) + mock_call_task.assert_called_once_with( + self.submission.uuid, + self.submission.anonymous_user_id, + self.submission.answer.parts, + self.submission.answer.file_names, + self.submission.answer.file_urls, + ) - @patch("platform_plugin_turnitin.handlers.call_ora_submission_created_task") - @patch("platform_plugin_turnitin.handlers.modulestore") - @patch("platform_plugin_turnitin.handlers.UsageKey") - def test_ora_submission_created_course_enabled( - self, mock_usage_key: Mock, mock_modulestore: Mock, mock_call_task: Mock - ): + @patch("platform_plugin_turnitin.handlers.ora_submission_created_task.delay") + @patch("platform_plugin_turnitin.handlers.enabled_in_course") + def test_ora_submission_created_course_enabled(self, mock_enabled_in_course: Mock, mock_call_task: Mock): """Test `ora_submission_created` when Turnitin submission is enabled for the course.""" - mock_usage_key.from_string.return_value.course_key = "course_key" - mock_modulestore.return_value.get_course.return_value = Mock( - other_course_settings={"ENABLE_TURNITIN_SUBMISSION": True}, - ) + mock_enabled_in_course.return_value = True ora_submission_created(self.submission) - mock_call_task.assert_called_once_with(self.submission) + mock_call_task.assert_called_once_with( + self.submission.uuid, + self.submission.anonymous_user_id, + self.submission.answer.parts, + self.submission.answer.file_names, + self.submission.answer.file_urls, + )