Move comment_client into django_comment_common

This commit is contained in:
Nimisha Asthagiri
2019-04-29 00:26:02 -04:00
parent 4d907a4263
commit 2839851bde
33 changed files with 76 additions and 74 deletions

2
.gitignore vendored
View File

@@ -132,7 +132,7 @@ build
/src/
\#*\#
.env/
lms/lib/comment_client/python
django_comment_common/comment_client/python
autodeploy.properties
.ws_migrations_complete
dist

View File

@@ -1,4 +1,4 @@
from lms.lib.comment_client import models, settings
from django_comment_common.comment_client import models, settings
from .thread import Thread, _url_for_flag_abuse_thread, _url_for_unflag_abuse_thread
from .utils import CommentClientRequestError, perform_request

View File

@@ -1,5 +1,5 @@
"""Provides base Commentable model class"""
from lms.lib.comment_client import models, settings
from django_comment_common.comment_client import models, settings
class Commentable(models.Model):

View File

@@ -50,8 +50,8 @@ from six import text_type
from slumber.exceptions import HttpClientError, HttpServerError
from user_util import user_util
import django_comment_common.comment_client as cc
from edx_django_utils.cache import RequestCache
import lms.lib.comment_client as cc
from student.signals import UNENROLL_DONE, ENROLL_STATUS_CHANGE, ENROLLMENT_TRACK_UPDATED
from lms.djangoapps.certificates.models import GeneratedCertificate
from course_modes.models import CourseMode, get_cosmetic_verified_display_price

View File

@@ -14,7 +14,6 @@ Discussions related functionality is scattered across a number of places and sho
* ``lms/djangoapps/django_comment_client``
* ``lms/djangoapps/notification_prefs``
* ``lms/djangoapps/notifier_api``
* ``lms/lib/comment_client``
* ``openedx/core/lib/xblock_builtin/xblock_discussion``
Ideally, what we want in the long term is for all of this extracted into a new repository that holds the code for both the inline discussion XBlock as well as all the Django apps. Use of the notifier API should be replaced with edx-ace.

View File

@@ -11,14 +11,14 @@ from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from celery_utils.logged_task import LoggedTask
import django_comment_common.comment_client as cc
from django_comment_common.models import DiscussionsIdMapping
from edx_ace import ace
from edx_ace.utils import date
from edx_ace.recipient import Recipient
from eventtracking import tracker
from opaque_keys.edx.keys import CourseKey
from lms.djangoapps.django_comment_client.utils import permalink, get_accessible_discussion_xblocks_by_course_id
import lms.lib.comment_client as cc
from opaque_keys.edx.keys import CourseKey
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from openedx.core.djangoapps.ace_common.template_context import get_base_template_context

View File

@@ -9,7 +9,7 @@ import ddt
from django.contrib.sites.models import Site
import mock
import lms.lib.comment_client as cc
import django_comment_common.comment_client as cc
from django_comment_common.models import ForumsConfig
from django_comment_common.signals import comment_created

View File

@@ -29,6 +29,7 @@ from django_comment_client.tests.utils import (
topic_name_to_id
)
from django_comment_client.utils import strip_none
from django_comment_common.comment_client.utils import CommentClientPaginatedResult
from django_comment_common.models import (
CourseDiscussionSettings,
ForumsConfig,
@@ -40,7 +41,6 @@ from lms.djangoapps.discussion import views
from lms.djangoapps.discussion.views import _get_discussion_default_topic_id
from lms.djangoapps.discussion.views import course_discussions_settings_handler
from lms.djangoapps.teams.tests.factories import CourseTeamFactory, CourseTeamMembershipFactory
from lms.lib.comment_client.utils import CommentClientPaginatedResult
from openedx.core.djangoapps.course_groups.models import CourseUserGroup
from openedx.core.djangoapps.course_groups.tests.helpers import config_course_cohorts
from openedx.core.djangoapps.course_groups.tests.test_views import CohortViewsTestCase
@@ -559,7 +559,7 @@ class SingleCohortedThreadTestCase(CohortedTestCase):
self.assertRegexpMatches(html, r'"group_name": "student_cohort"')
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
class SingleThreadAccessTestCase(CohortedTestCase):
def call_view(self, mock_request, commentable_id, user, group_id, thread_group_id=None, pass_group_id=True):
@@ -647,7 +647,7 @@ class SingleThreadAccessTestCase(CohortedTestCase):
self.assertEqual(resp.status_code, 200)
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
class SingleThreadGroupIdTestCase(CohortedTestCase, GroupIdAssertionMixin):
cs_endpoint = "/threads/dummy_thread_id"
@@ -888,7 +888,7 @@ class SingleThreadContentGroupTestCase(ForumsEnableMixin, UrlResetMixin, Content
self.assert_can_access(self.beta_user, self.alpha_module.discussion_id, thread_id, True)
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
class InlineDiscussionContextTestCase(ForumsEnableMixin, ModuleStoreTestCase):
def setUp(self):
@@ -925,7 +925,7 @@ class InlineDiscussionContextTestCase(ForumsEnableMixin, ModuleStoreTestCase):
self.assertEqual(json_response['discussion_data'][0]['context'], ThreadContext.STANDALONE)
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
class InlineDiscussionGroupIdTestCase(
CohortedTestCase,
CohortedTopicGroupIdTestMixin,
@@ -976,7 +976,7 @@ class InlineDiscussionGroupIdTestCase(
)
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
class ForumFormDiscussionGroupIdTestCase(CohortedTestCase, CohortedTopicGroupIdTestMixin):
cs_endpoint = "/threads"
@@ -1022,7 +1022,7 @@ class ForumFormDiscussionGroupIdTestCase(CohortedTestCase, CohortedTopicGroupIdT
)
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
class UserProfileDiscussionGroupIdTestCase(CohortedTestCase, CohortedTopicGroupIdTestMixin):
cs_endpoint = "/active_threads"
@@ -1183,7 +1183,7 @@ class UserProfileDiscussionGroupIdTestCase(CohortedTestCase, CohortedTopicGroupI
verify_group_id_not_present(profiled_user=self.moderator, pass_group_id=False)
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
class FollowedThreadsDiscussionGroupIdTestCase(CohortedTestCase, CohortedTopicGroupIdTestMixin):
cs_endpoint = "/subscribed_threads"
@@ -1220,7 +1220,7 @@ class FollowedThreadsDiscussionGroupIdTestCase(CohortedTestCase, CohortedTopicGr
)
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
class InlineDiscussionTestCase(ForumsEnableMixin, ModuleStoreTestCase):
def setUp(self):
@@ -1480,7 +1480,7 @@ class InlineDiscussionUnicodeTestCase(ForumsEnableMixin, SharedModuleStoreTestCa
def setUp(self):
super(InlineDiscussionUnicodeTestCase, self).setUp()
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def _test_unicode_data(self, text, mock_request):
mock_request.side_effect = make_mock_request_impl(course=self.course, text=text)
request = RequestFactory().get("dummy_url")
@@ -1513,7 +1513,7 @@ class ForumFormDiscussionUnicodeTestCase(ForumsEnableMixin, SharedModuleStoreTes
def setUp(self):
super(ForumFormDiscussionUnicodeTestCase, self).setUp()
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def _test_unicode_data(self, text, mock_request):
mock_request.side_effect = make_mock_request_impl(course=self.course, text=text)
request = RequestFactory().get("dummy_url")
@@ -1528,7 +1528,7 @@ class ForumFormDiscussionUnicodeTestCase(ForumsEnableMixin, SharedModuleStoreTes
@ddt.ddt
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
class ForumDiscussionXSSTestCase(ForumsEnableMixin, UrlResetMixin, ModuleStoreTestCase):
@patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True})
@@ -1601,7 +1601,7 @@ class ForumDiscussionSearchUnicodeTestCase(ForumsEnableMixin, SharedModuleStoreT
def setUp(self):
super(ForumDiscussionSearchUnicodeTestCase, self).setUp()
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def _test_unicode_data(self, text, mock_request):
mock_request.side_effect = make_mock_request_impl(course=self.course, text=text)
data = {
@@ -1637,7 +1637,7 @@ class SingleThreadUnicodeTestCase(ForumsEnableMixin, SharedModuleStoreTestCase,
def setUp(self):
super(SingleThreadUnicodeTestCase, self).setUp()
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def _test_unicode_data(self, text, mock_request):
thread_id = "test_thread_id"
mock_request.side_effect = make_mock_request_impl(course=self.course, text=text, thread_id=thread_id)
@@ -1670,7 +1670,7 @@ class UserProfileUnicodeTestCase(ForumsEnableMixin, SharedModuleStoreTestCase, U
def setUp(self):
super(UserProfileUnicodeTestCase, self).setUp()
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def _test_unicode_data(self, text, mock_request):
mock_request.side_effect = make_mock_request_impl(course=self.course, text=text)
request = RequestFactory().get("dummy_url")
@@ -1702,7 +1702,7 @@ class FollowedThreadsUnicodeTestCase(ForumsEnableMixin, SharedModuleStoreTestCas
def setUp(self):
super(FollowedThreadsUnicodeTestCase, self).setUp()
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def _test_unicode_data(self, text, mock_request):
mock_request.side_effect = make_mock_request_impl(course=self.course, text=text)
request = RequestFactory().get("dummy_url")
@@ -1729,7 +1729,7 @@ class EnrollmentTestCase(ForumsEnableMixin, ModuleStoreTestCase):
self.student = UserFactory.create()
@patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True})
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def test_unenrolled(self, mock_request):
mock_request.side_effect = make_mock_request_impl(course=self.course, text='dummy')
request = RequestFactory().get('dummy_url')
@@ -2111,7 +2111,7 @@ class ThreadViewedEventTestCase(EventTestMixin, ForumsEnableMixin, UrlResetMixin
self.client.login(username=self.student.username, password=PASSWORD)
@patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True})
@patch('lms.lib.comment_client.utils.perform_request')
@patch('django_comment_common.comment_client.utils.perform_request')
def test_thread_viewed_event(self, mock_perform_request):
mock_perform_request.side_effect = make_mock_perform_request_impl(
course=self.course,

View File

@@ -24,8 +24,8 @@ from rest_framework import status
from web_fragments.fragment import Fragment
import django_comment_client.utils as utils
import django_comment_common.comment_client as cc
from lms.djangoapps.experiments.utils import get_experiment_user_metadata_context
import lms.lib.comment_client as cc
from courseware.access import has_access
from courseware.courses import get_course_with_access
from courseware.views.views import CourseTabView

View File

@@ -26,6 +26,9 @@ from discussion_api.permissions import (
from discussion_api.serializers import CommentSerializer, DiscussionTopicSerializer, ThreadSerializer, get_context
from django_comment_client.base.views import track_comment_created_event, track_thread_created_event, track_voted_event
from django_comment_client.utils import get_accessible_discussion_xblocks, get_group_id_for_user, is_commentable_divided
from django_comment_common.comment_client.comment import Comment
from django_comment_common.comment_client.thread import Thread
from django_comment_common.comment_client.utils import CommentClientRequestError
from django_comment_common.signals import (
comment_created,
comment_deleted,
@@ -39,9 +42,6 @@ from django_comment_common.signals import (
from django_comment_common.utils import get_course_discussion_settings
from lms.djangoapps.courseware.exceptions import CourseAccessRedirect
from lms.djangoapps.discussion_api.pagination import DiscussionAPIPagination
from lms.lib.comment_client.comment import Comment
from lms.lib.comment_client.thread import Thread
from lms.lib.comment_client.utils import CommentClientRequestError
from openedx.core.djangoapps.user_api.accounts.views import AccountViewSet
from openedx.core.lib.exceptions import CourseNotFoundError, DiscussionNotFoundError, PageNotFoundError

View File

@@ -1,8 +1,8 @@
"""
Discussion API permission logic
"""
from lms.lib.comment_client.comment import Comment
from lms.lib.comment_client.thread import Thread
from django_comment_common.comment_client.comment import Comment
from django_comment_common.comment_client.thread import Thread
def _is_author(cc_content, context):

View File

@@ -19,12 +19,12 @@ from django_comment_common.models import (
FORUM_ROLE_MODERATOR,
Role,
)
from django_comment_common.comment_client.comment import Comment
from django_comment_common.comment_client.thread import Thread
from django_comment_common.comment_client.user import User as CommentClientUser
from django_comment_common.comment_client.utils import CommentClientRequestError
from django_comment_common.utils import get_course_discussion_settings
from lms.djangoapps.django_comment_client.utils import course_discussion_division_enabled, get_group_names_by_id
from lms.lib.comment_client.comment import Comment
from lms.lib.comment_client.thread import Thread
from lms.lib.comment_client.user import User as CommentClientUser
from lms.lib.comment_client.utils import CommentClientRequestError
from student.models import get_user_by_username_or_email

View File

@@ -11,9 +11,9 @@ from discussion_api.permissions import (
get_initializable_comment_fields,
get_initializable_thread_fields
)
from lms.lib.comment_client.comment import Comment
from lms.lib.comment_client.thread import Thread
from lms.lib.comment_client.user import User
from django_comment_common.comment_client.comment import Comment
from django_comment_common.comment_client.thread import Thread
from django_comment_common.comment_client.user import User
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory

View File

@@ -12,6 +12,8 @@ from django.test.client import RequestFactory
from discussion_api.serializers import CommentSerializer, ThreadSerializer, get_context
from discussion_api.tests.utils import CommentsServiceMockMixin, make_minimal_cs_comment, make_minimal_cs_thread
from django_comment_client.tests.utils import ForumsEnableMixin
from django_comment_common.comment_client.comment import Comment
from django_comment_common.comment_client.thread import Thread
from django_comment_common.models import (
FORUM_ROLE_ADMINISTRATOR,
FORUM_ROLE_COMMUNITY_TA,
@@ -19,8 +21,6 @@ from django_comment_common.models import (
FORUM_ROLE_STUDENT,
Role
)
from lms.lib.comment_client.comment import Comment
from lms.lib.comment_client.thread import Thread
from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory
from student.tests.factories import UserFactory
from util.testing import UrlResetMixin

View File

@@ -18,11 +18,11 @@ from rest_framework.viewsets import ViewSet
from six import text_type
from django_comment_client.utils import available_division_schemes
from django_comment_common import comment_client
from django_comment_common.models import Role
from django_comment_common.utils import get_course_discussion_settings, set_course_discussion_settings
from instructor.access import update_forum_role
from lms.lib import comment_client
from discussion.views import get_divided_discussions
from discussion_api.api import (
create_comment,

View File

@@ -26,6 +26,7 @@ from django_comment_client.tests.group_id import (
)
from django_comment_client.tests.unicode import UnicodeTestMixin
from django_comment_client.tests.utils import CohortedTestCase, ForumsEnableMixin
from django_comment_common.comment_client import Thread
from django_comment_common.models import (
assign_role,
CourseDiscussionSettings,
@@ -34,7 +35,6 @@ from django_comment_common.models import (
)
from django_comment_common.utils import ThreadContext, seed_permissions_roles, set_course_discussion_settings
from lms.djangoapps.teams.tests.factories import CourseTeamFactory, CourseTeamMembershipFactory
from lms.lib.comment_client import Thread
from openedx.core.djangoapps.course_groups.cohorts import set_course_cohorted
from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory
from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES
@@ -72,7 +72,7 @@ class MockRequestSetupMixin(object):
mock_request.return_value = self._create_response_mock(data)
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
class CreateThreadGroupIdTestCase(
MockRequestSetupMixin,
CohortedTestCase,
@@ -107,7 +107,7 @@ class CreateThreadGroupIdTestCase(
self._assert_json_response_contains_group_info(response)
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@disable_signal(views, 'thread_edited')
@disable_signal(views, 'thread_voted')
@disable_signal(views, 'thread_deleted')
@@ -365,7 +365,7 @@ class ViewsTestCaseMixin(object):
@ddt.ddt
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@disable_signal(views, 'thread_created')
@disable_signal(views, 'thread_edited')
class ViewsQueryCountTestCase(
@@ -418,7 +418,7 @@ class ViewsQueryCountTestCase(
@ddt.ddt
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
class ViewsTestCase(
ForumsEnableMixin,
UrlResetMixin,
@@ -1062,7 +1062,7 @@ class ViewsTestCase(
self.assertEqual(response.status_code, 200)
@patch("lms.lib.comment_client.utils.requests.request", autospec=True)
@patch("django_comment_common.comment_client.utils.requests.request", autospec=True)
@disable_signal(views, 'comment_endorsed')
class ViewPermissionsTestCase(ForumsEnableMixin, UrlResetMixin, SharedModuleStoreTestCase, MockRequestSetupMixin):
@@ -1191,7 +1191,7 @@ class CreateThreadUnicodeTestCase(
cls.student = UserFactory.create()
CourseEnrollmentFactory(user=cls.student, course_id=cls.course.id)
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def _test_unicode_data(self, text, mock_request,):
"""
Test to make sure unicode data in a thread doesn't break it.
@@ -1234,7 +1234,7 @@ class UpdateThreadUnicodeTestCase(
CourseEnrollmentFactory(user=cls.student, course_id=cls.course.id)
@patch('django_comment_client.utils.get_discussion_categories_ids', return_value=["test_commentable"])
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def _test_unicode_data(self, text, mock_request, mock_get_discussion_id_map):
self._set_mock_request_data(mock_request, {
"user_id": str(self.student.id),
@@ -1275,7 +1275,7 @@ class CreateCommentUnicodeTestCase(
cls.student = UserFactory.create()
CourseEnrollmentFactory(user=cls.student, course_id=cls.course.id)
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def _test_unicode_data(self, text, mock_request):
commentable_id = "non_team_dummy_id"
self._set_mock_request_data(mock_request, {
@@ -1322,7 +1322,7 @@ class UpdateCommentUnicodeTestCase(
cls.student = UserFactory.create()
CourseEnrollmentFactory(user=cls.student, course_id=cls.course.id)
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def _test_unicode_data(self, text, mock_request):
self._set_mock_request_data(mock_request, {
"user_id": str(self.student.id),
@@ -1362,7 +1362,7 @@ class CreateSubCommentUnicodeTestCase(
cls.student = UserFactory.create()
CourseEnrollmentFactory(user=cls.student, course_id=cls.course.id)
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def _test_unicode_data(self, text, mock_request):
"""
Create a comment with unicode in it.
@@ -1390,7 +1390,7 @@ class CreateSubCommentUnicodeTestCase(
@ddt.ddt
@patch("lms.lib.comment_client.utils.requests.request", autospec=True)
@patch("django_comment_common.comment_client.utils.requests.request", autospec=True)
@disable_signal(views, 'thread_voted')
@disable_signal(views, 'thread_edited')
@disable_signal(views, 'comment_created')
@@ -1757,7 +1757,7 @@ class ForumEventTestCase(ForumsEnableMixin, SharedModuleStoreTestCase, MockReque
CourseAccessRoleFactory(course_id=cls.course.id, user=cls.student, role='Wizard')
@patch('eventtracking.tracker.emit')
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def test_thread_created_event(self, __, mock_emit):
request = RequestFactory().post(
"dummy_url", {
@@ -1786,7 +1786,7 @@ class ForumEventTestCase(ForumsEnableMixin, SharedModuleStoreTestCase, MockReque
self.assertEquals(event['anonymous_to_peers'], False)
@patch('eventtracking.tracker.emit')
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def test_response_event(self, mock_request, mock_emit):
"""
Check to make sure an event is fired when a user responds to a thread.
@@ -1812,7 +1812,7 @@ class ForumEventTestCase(ForumsEnableMixin, SharedModuleStoreTestCase, MockReque
self.assertEqual(event['options']['followed'], True)
@patch('eventtracking.tracker.emit')
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def test_comment_event(self, mock_request, mock_emit):
"""
Ensure an event is fired when someone comments on a response.
@@ -1839,7 +1839,7 @@ class ForumEventTestCase(ForumsEnableMixin, SharedModuleStoreTestCase, MockReque
self.assertEqual(event['options']['followed'], False)
@patch('eventtracking.tracker.emit')
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@ddt.data((
'create_thread',
'edx.forum.thread.created', {
@@ -1891,7 +1891,7 @@ class ForumEventTestCase(ForumsEnableMixin, SharedModuleStoreTestCase, MockReque
)
@ddt.unpack
@patch('eventtracking.tracker.emit')
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def test_thread_voted_event(self, view_name, obj_id_name, obj_type, mock_request, mock_emit):
undo = view_name.startswith('undo')
@@ -1953,7 +1953,7 @@ class UsersEndpointTestCase(ForumsEnableMixin, SharedModuleStoreTestCase, MockRe
request.view_name = "users"
return views.users(request, course_id=text_type(course_id))
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def test_finds_exact_match(self, mock_request):
self.set_post_counts(mock_request)
response = self.make_request(username="other")
@@ -1963,7 +1963,7 @@ class UsersEndpointTestCase(ForumsEnableMixin, SharedModuleStoreTestCase, MockRe
[{"id": self.other_user.id, "username": self.other_user.username}]
)
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def test_finds_no_match(self, mock_request):
self.set_post_counts(mock_request)
response = self.make_request(username="othor")
@@ -2000,7 +2000,7 @@ class UsersEndpointTestCase(ForumsEnableMixin, SharedModuleStoreTestCase, MockRe
self.assertIn("errors", content)
self.assertNotIn("users", content)
@patch('lms.lib.comment_client.utils.requests.request', autospec=True)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
def test_requires_matched_user_has_forum_content(self, mock_request):
self.set_post_counts(mock_request, 0, 0)
response = self.make_request(username="other")

View File

@@ -21,7 +21,7 @@ from opaque_keys.edx.keys import CourseKey
from six import text_type
import django_comment_client.settings as cc_settings
import lms.lib.comment_client as cc
import django_comment_common.comment_client as cc
from courseware.access import has_access
from courseware.courses import get_course_by_id, get_course_overview_with_access, get_course_with_access
from django_comment_client.permissions import check_permissions_by_view, get_team, has_permission

View File

@@ -3,7 +3,7 @@ Reload forum (comment client) users from existing users.
"""
from __future__ import print_function
import lms.lib.comment_client as cc
import django_comment_common.comment_client as cc
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand

View File

@@ -3,7 +3,7 @@ One-off script to sync all user information to the
discussion service (later info will be synced automatically)
"""
import lms.lib.comment_client as cc
import django_comment_common.comment_client as cc
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand

View File

@@ -4,7 +4,7 @@ import logging
from six import text_type
from django_comment_client.utils import JsonError
from lms.lib.comment_client import CommentClientRequestError
from django_comment_common.comment_client import CommentClientRequestError
log = logging.getLogger(__name__)

View File

@@ -8,10 +8,10 @@ from types import NoneType
from edx_django_utils.cache import DEFAULT_REQUEST_CACHE
from opaque_keys.edx.keys import CourseKey
from django_comment_common.comment_client import Thread
from django_comment_common.models import CourseDiscussionSettings, all_permissions_for_user_in_course
from django_comment_common.utils import get_course_discussion_settings
from lms.djangoapps.teams.models import CourseTeam
from lms.lib.comment_client import Thread
from openedx.core.lib.cache_utils import request_cached

View File

@@ -5,7 +5,7 @@ from django.test import TestCase
from six import text_type
import django_comment_client.middleware as middleware
import lms.lib.comment_client
import django_comment_common.comment_client
class AjaxExceptionTestCase(TestCase):
@@ -15,9 +15,9 @@ class AjaxExceptionTestCase(TestCase):
self.a = middleware.AjaxExceptionMiddleware()
self.request1 = django.http.HttpRequest()
self.request0 = django.http.HttpRequest()
self.exception1 = lms.lib.comment_client.CommentClientRequestError('{}', 401)
self.exception2 = lms.lib.comment_client.CommentClientRequestError('Foo!', 404)
self.exception0 = lms.lib.comment_client.CommentClient500Error("Holy crap the server broke!")
self.exception1 = django_comment_common.comment_client.CommentClientRequestError('{}', 401)
self.exception2 = django_comment_common.comment_client.CommentClientRequestError('Foo!', 404)
self.exception0 = django_comment_common.comment_client.CommentClient500Error("Holy crap the server broke!")
self.request1.META['HTTP_X_REQUESTED_WITH'] = "XMLHttpRequest"
self.request0.META['HTTP_X_REQUESTED_WITH'] = "SHADOWFAX"

View File

@@ -21,6 +21,7 @@ from django_comment_client.constants import TYPE_ENTRY, TYPE_SUBCATEGORY
from django_comment_client.tests.factories import RoleFactory
from django_comment_client.tests.unicode import UnicodeTestMixin
from django_comment_client.tests.utils import config_course_discussions, topic_name_to_id
from django_comment_common.comment_client.utils import CommentClientMaintenanceError, perform_request
from django_comment_common.models import (
CourseDiscussionSettings,
ForumsConfig,
@@ -33,7 +34,6 @@ from django_comment_common.utils import (
set_course_discussion_settings
)
from lms.djangoapps.teams.tests.factories import CourseTeamFactory
from lms.lib.comment_client.utils import CommentClientMaintenanceError, perform_request
from openedx.core.djangoapps.course_groups import cohorts
from openedx.core.djangoapps.course_groups.cohorts import set_course_cohorted
from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory, config_course_cohorts

View File

@@ -768,8 +768,11 @@ class TestCreateAccountValidation(TestCase):
@mock.patch.dict("student.models.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True})
@mock.patch("lms.lib.comment_client.User.base_url", TEST_CS_URL)
@mock.patch("lms.lib.comment_client.utils.requests.request", return_value=mock.Mock(status_code=200, text='{}'))
@mock.patch("django_comment_common.comment_client.User.base_url", TEST_CS_URL)
@mock.patch(
"django_comment_common.comment_client.utils.requests.request",
return_value=mock.Mock(status_code=200, text='{}')
)
class TestCreateCommentsServiceUser(TransactionTestCase):
""" Tests for creating comments service user. """