diff --git a/lms/djangoapps/discussion/django_comment_client/base/tests.py b/lms/djangoapps/discussion/django_comment_client/base/tests.py index e2906e7ba1c7..a2f5af11f050 100644 --- a/lms/djangoapps/discussion/django_comment_client/base/tests.py +++ b/lms/djangoapps/discussion/django_comment_client/base/tests.py @@ -91,6 +91,19 @@ class CreateThreadGroupIdTestCase( ): cs_endpoint = "/threads" + def setUp(self): + super().setUp() + patcher = mock.patch( + "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" + ) + self.mock_get_course_id_by_thread = patcher.start() + self.addCleanup(patcher.stop) + patcher = mock.patch( + "openedx.core.djangoapps.django_comment_common.comment_client.models.forum_api.get_course_id_by_comment" + ) + self.mock_get_course_id_by_comment = patcher.start() + self.addCleanup(patcher.stop) + def call_view(self, mock_is_forum_v2_enabled, mock_request, commentable_id, user, group_id, pass_group_id=True): mock_is_forum_v2_enabled.return_value = False self._set_mock_request_data(mock_request, {}) @@ -140,7 +153,7 @@ def call_view( patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) mock_is_forum_v2_enabled.return_value = False self._set_mock_request_data( @@ -415,7 +428,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) def count_queries(func): # pylint: disable=no-self-argument @@ -497,7 +510,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) # Patch the comment client user save method so it does not try # to create a new cc user when creating a django user @@ -1175,7 +1188,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) def test_pin_thread_as_student(self, mock_is_forum_v2_enabled, mock_request): @@ -1321,7 +1334,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) @classmethod @@ -1375,7 +1388,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) @classmethod @@ -1705,7 +1718,7 @@ def _setup_mock(self, user, mock_is_forum_v2_enabled, mock_request, data): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) self.client.login(username=user.username, password=self.password) @@ -1920,7 +1933,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) @classmethod diff --git a/lms/djangoapps/discussion/rest_api/tests/test_api.py b/lms/djangoapps/discussion/rest_api/tests/test_api.py index 802aae1f534b..f8ec767612dc 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_api.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_api.py @@ -1259,7 +1259,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) self.maxDiff = None # pylint: disable=invalid-name self.user = UserFactory.create() @@ -2225,7 +2225,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) self.user = UserFactory.create() self.register_get_user_response(self.user) @@ -2624,7 +2624,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) self.user = UserFactory.create() @@ -3201,7 +3201,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) self.user = UserFactory.create() self.register_get_user_response(self.user) @@ -3731,7 +3731,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) self.user = UserFactory.create() self.register_get_user_response(self.user) @@ -3897,7 +3897,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) self.user = UserFactory.create() self.register_get_user_response(self.user) @@ -4073,7 +4073,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) self.user = UserFactory.create() self.register_get_user_response(self.user) diff --git a/lms/djangoapps/discussion/rest_api/tests/test_views.py b/lms/djangoapps/discussion/rest_api/tests/test_views.py index 1ef0d34f79c2..2393a70bd901 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_views.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_views.py @@ -1471,7 +1471,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) def test_basic(self): @@ -1623,7 +1623,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) def test_basic(self): @@ -1976,7 +1976,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) def create_source_comment(self, overrides=None): @@ -2443,7 +2443,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) def test_basic(self): @@ -2496,7 +2496,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) def test_basic(self): @@ -2611,7 +2611,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) self.register_get_user_response(self.user) self.url = reverse("comment-detail", kwargs={"comment_id": "test_comment"}) @@ -2739,14 +2739,14 @@ def setUp(self): patcher.start() self.addCleanup(patcher.stop) patcher = mock.patch( - "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" + "openedx.core.djangoapps.django_comment_common.comment_client.models.forum_api.get_course_id_by_comment" ) self.mock_get_course_id_by_comment = patcher.start() self.addCleanup(patcher.stop) patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) def test_basic(self): @@ -2812,7 +2812,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) def make_comment_data(self, comment_id, parent_id=None, children=[]): # pylint: disable=W0102 diff --git a/lms/djangoapps/discussion/tests/test_tasks.py b/lms/djangoapps/discussion/tests/test_tasks.py index 22855076e457..6fdaf21f428e 100644 --- a/lms/djangoapps/discussion/tests/test_tasks.py +++ b/lms/djangoapps/discussion/tests/test_tasks.py @@ -243,7 +243,7 @@ def setUp(self): patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) - self.mock_get_course_id_by_comment = patcher.start() + self.mock_get_course_id_by_thread = patcher.start() self.addCleanup(patcher.stop) def tearDown(self): diff --git a/lms/djangoapps/discussion/tests/test_views.py b/lms/djangoapps/discussion/tests/test_views.py index f9ac0852a7d5..5e7fed4ae717 100644 --- a/lms/djangoapps/discussion/tests/test_views.py +++ b/lms/djangoapps/discussion/tests/test_views.py @@ -945,6 +945,11 @@ def setUp(self): patcher = mock.patch('lms.djangoapps.discussion.toggles.ENABLE_FORUM_V2.is_enabled', return_value=False) patcher.start() self.addCleanup(patcher.stop) + patcher = mock.patch( + "openedx.core.djangoapps.django_comment_common.comment_client.models.forum_api.get_course_id_by_comment" + ) + self.mock_get_course_id_by_comment = patcher.start() + self.addCleanup(patcher.stop) patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) @@ -1255,6 +1260,11 @@ class UserProfileDiscussionGroupIdTestCase(CohortedTestCase, CohortedTopicGroupI def setUp(self): super().setUp() + patcher = mock.patch( + "openedx.core.djangoapps.django_comment_common.comment_client.models.forum_api.get_course_id_by_comment" + ) + self.mock_get_course_id_by_comment = patcher.start() + self.addCleanup(patcher.stop) patcher = mock.patch( "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" ) @@ -1707,6 +1717,19 @@ class CommentsServiceRequestHeadersTestCase(ForumsEnableMixin, UrlResetMixin, Mo @patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) def setUp(self): super().setUp() + patcher = mock.patch('lms.djangoapps.discussion.toggles.ENABLE_FORUM_V2.is_enabled', return_value=False) + patcher.start() + self.addCleanup(patcher.stop) + patcher = mock.patch( + "openedx.core.djangoapps.django_comment_common.comment_client.models.forum_api.get_course_id_by_comment" + ) + self.mock_get_course_id_by_comment = patcher.start() + self.addCleanup(patcher.stop) + patcher = mock.patch( + "openedx.core.djangoapps.django_comment_common.comment_client.thread.forum_api.get_course_id_by_thread" + ) + self.mock_get_course_id_by_thread = patcher.start() + self.addCleanup(patcher.stop) username = "foo" password = "bar"