Skip to content

Commit

Permalink
Move django_comment_common from common to openedx
Browse files Browse the repository at this point in the history
  • Loading branch information
nasthagiri committed May 3, 2019
1 parent c606aae commit dfa3728
Show file tree
Hide file tree
Showing 96 changed files with 323 additions and 279 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ build
/src/
\#*\#
.env/
django_comment_common/comment_client/python
openedx/core/djangoapps/django_comment_common/comment_client/python
autodeploy.properties
.ws_migrations_complete
dist
Expand Down
2 changes: 1 addition & 1 deletion cms/djangoapps/contentstore/management/commands/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Script for importing courseware from XML format
"""
from django.core.management.base import BaseCommand
from django_comment_common.utils import are_permissions_roles_seeded, seed_permissions_roles
from openedx.core.djangoapps.django_comment_common.utils import are_permissions_roles_seeded, seed_permissions_roles
from xmodule.contentstore.django import contentstore
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.core.management import call_command
from path import Path as path

from django_comment_common.utils import are_permissions_roles_seeded
from openedx.core.djangoapps.django_comment_common.utils import are_permissions_roles_seeded
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
Expand Down
2 changes: 1 addition & 1 deletion cms/djangoapps/contentstore/tests/test_contentstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from contentstore.config import waffle
from course_action_state.managers import CourseActionStateItemNotFoundError
from course_action_state.models import CourseRerunState, CourseRerunUIStateManager
from django_comment_common.utils import are_permissions_roles_seeded
from openedx.core.djangoapps.django_comment_common.utils import are_permissions_roles_seeded
from openedx.core.lib.tempdir import mkdtemp_clean
from student import auth
from student.models import CourseEnrollment
Expand Down
4 changes: 2 additions & 2 deletions cms/djangoapps/contentstore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from pytz import UTC
from six import text_type

from django_comment_common.models import assign_default_role
from django_comment_common.utils import seed_permissions_roles
from openedx.core.djangoapps.django_comment_common.models import assign_default_role
from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles
from openedx.core.djangoapps.site_configuration.models import SiteConfiguration
from openedx.features.content_type_gating.models import ContentTypeGatingConfig
from openedx.features.content_type_gating.partitions import CONTENT_TYPE_GATING_SCHEME
Expand Down
4 changes: 2 additions & 2 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,8 +1055,8 @@
# Ability to detect and special-case crawler behavior
'openedx.core.djangoapps.crawlers',

# comment common
'django_comment_common',
# Discussion
'openedx.core.djangoapps.django_comment_common',

# for course creator table
'django.contrib.admin',
Expand Down
4 changes: 2 additions & 2 deletions common/djangoapps/student/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@
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
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
from courseware.models import (
CourseDynamicUpgradeDeadlineConfiguration,
Expand All @@ -62,7 +60,9 @@
)
from enrollment.api import _default_course_mode

from lms.djangoapps.certificates.models import GeneratedCertificate
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
import openedx.core.djangoapps.django_comment_common.comment_client as cc
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangoapps.xmodule_django.models import NoneToEmptyManager
from openedx.core.djangolib.model_mixins import DeletableByUserValue
Expand Down
2 changes: 1 addition & 1 deletion common/djangoapps/student/role_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Helpers for student roles
"""
from django_comment_common.models import (
from openedx.core.djangoapps.django_comment_common.models import (
FORUM_ROLE_ADMINISTRATOR,
FORUM_ROLE_MODERATOR,
FORUM_ROLE_GROUP_MODERATOR,
Expand Down
1 change: 0 additions & 1 deletion docs/common_djangoapps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ LMS and Studio.
common/djangoapps/course_action_state/modules
common/djangoapps/course_modes/modules
common/djangoapps/database_fixups/modules
common/djangoapps/django_comment_common/modules
common/djangoapps/edxmako/modules
common/djangoapps/enrollment/modules
common/djangoapps/entitlements/modules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from django.db import migrations
from django.http import Http404

from django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, \
from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, \
FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_STUDENT
from django_comment_common.utils import STUDENT_ROLE_PERMISSIONS, MODERATOR_ROLE_PERMISSIONS, \
from openedx.core.djangoapps.django_comment_common.utils import STUDENT_ROLE_PERMISSIONS, MODERATOR_ROLE_PERMISSIONS, \
ADMINISTRATOR_ROLE_PERMISSIONS

log = logging.getLogger("edx.ccx")
Expand Down
6 changes: 3 additions & 3 deletions lms/djangoapps/ccx/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
from courseware.tests.factories import StudentModuleFactory
from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.testutils import FieldOverrideTestMixin
from lms.djangoapps.discussion.django_comment_client.utils import has_forum_access
from django_comment_common.models import FORUM_ROLE_ADMINISTRATOR
from django_comment_common.utils import are_permissions_roles_seeded
from edx_django_utils.cache import RequestCache
from edxmako.shortcuts import render_to_response
from lms.djangoapps.ccx.models import CustomCourseForEdX
Expand All @@ -34,9 +31,12 @@
from lms.djangoapps.ccx.tests.utils import CcxTestCase, flatten
from lms.djangoapps.ccx.utils import ccx_course, is_email
from lms.djangoapps.ccx.views import get_date
from lms.djangoapps.discussion.django_comment_client.utils import has_forum_access
from lms.djangoapps.grades.tasks import compute_all_grades_for_course
from lms.djangoapps.instructor.access import allow_access, list_with_level
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_ADMINISTRATOR
from openedx.core.djangoapps.django_comment_common.utils import are_permissions_roles_seeded
from student.models import CourseEnrollment, CourseEnrollmentAllowed
from student.roles import CourseCcxCoachRole, CourseInstructorRole, CourseStaffRole
from student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory
Expand Down
6 changes: 3 additions & 3 deletions lms/djangoapps/ccx/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@

from courseware.access import has_access
from courseware.courses import get_course_by_id
from lms.djangoapps.courseware.field_overrides import disable_overrides
from django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, assign_role
from django_comment_common.utils import seed_permissions_roles
from edxmako.shortcuts import render_to_response
from lms.djangoapps.ccx.models import CustomCourseForEdX
from lms.djangoapps.ccx.overrides import (
Expand All @@ -48,9 +45,12 @@
get_enrollment_action_and_identifiers,
parse_date,
)
from lms.djangoapps.courseware.field_overrides import disable_overrides
from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory
from lms.djangoapps.instructor.enrollment import enroll_email, get_email_params
from lms.djangoapps.instructor.views.gradebook_api import get_grade_book_page
from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, assign_role
from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles
from student.models import CourseEnrollment
from student.roles import CourseCcxCoachRole
from xmodule.modulestore.django import SignalHandler
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/discussion/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Direction: Move and Extract
===========================
Discussions related functionality is scattered across a number of places and should be better consolidated. Today we have:

* ``common/djangoapps/django_comment_common``
* ``lms/djangoapps/discussion``
* ``openedx/core/djangoapps/django_comment_common``
* ``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.
Expand Down
46 changes: 24 additions & 22 deletions lms/djangoapps/discussion/django_comment_client/base/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@
)
from lms.djangoapps.discussion.django_comment_client.tests.unicode import UnicodeTestMixin
from lms.djangoapps.discussion.django_comment_client.tests.utils import CohortedTestCase, ForumsEnableMixin
from django_comment_common.comment_client import Thread
from django_comment_common.models import (
from openedx.core.djangoapps.django_comment_common.comment_client import Thread
from openedx.core.djangoapps.django_comment_common.models import (
assign_role,
CourseDiscussionSettings,
FORUM_ROLE_STUDENT,
Role
)
from django_comment_common.utils import ThreadContext, seed_permissions_roles, set_course_discussion_settings
from lms.djangoapps.teams.tests.factories import CourseTeamFactory, CourseTeamMembershipFactory
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.django_comment_common.utils import (
ThreadContext, seed_permissions_roles, set_course_discussion_settings
)
from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES
from student.roles import CourseStaffRole, UserBasedRole
from student.tests.factories import CourseAccessRoleFactory, CourseEnrollmentFactory, UserFactory
Expand Down Expand Up @@ -73,7 +75,7 @@ def _set_mock_request_data(self, mock_request, data):
mock_request.return_value = self._create_response_mock(data)


@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True)
class CreateThreadGroupIdTestCase(
MockRequestSetupMixin,
CohortedTestCase,
Expand Down Expand Up @@ -108,7 +110,7 @@ def test_group_info_in_response(self, mock_request):
self._assert_json_response_contains_group_info(response)


@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@patch('openedx.core.djangoapps.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')
Expand Down Expand Up @@ -366,7 +368,7 @@ def update_thread_helper(self, mock_request):


@ddt.ddt
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True)
@disable_signal(views, 'thread_created')
@disable_signal(views, 'thread_edited')
class ViewsQueryCountTestCase(
Expand Down Expand Up @@ -419,7 +421,7 @@ def test_update_thread(self, mock_request):


@ddt.ddt
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True)
class ViewsTestCase(
ForumsEnableMixin,
UrlResetMixin,
Expand Down Expand Up @@ -1066,7 +1068,7 @@ def test_endorse_comment(self, mock_request):
self.assertEqual(response.status_code, 200)


@patch("django_comment_common.comment_client.utils.requests.request", autospec=True)
@patch("openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request", autospec=True)
@disable_signal(views, 'comment_endorsed')
class ViewPermissionsTestCase(ForumsEnableMixin, UrlResetMixin, SharedModuleStoreTestCase, MockRequestSetupMixin):

Expand Down Expand Up @@ -1195,7 +1197,7 @@ def setUpTestData(cls):
cls.student = UserFactory.create()
CourseEnrollmentFactory(user=cls.student, course_id=cls.course.id)

@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@patch('openedx.core.djangoapps.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.
Expand Down Expand Up @@ -1241,7 +1243,7 @@ def setUpTestData(cls):
'lms.djangoapps.discussion.django_comment_client.utils.get_discussion_categories_ids',
return_value=["test_commentable"],
)
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@patch('openedx.core.djangoapps.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),
Expand Down Expand Up @@ -1282,7 +1284,7 @@ def setUpTestData(cls):
cls.student = UserFactory.create()
CourseEnrollmentFactory(user=cls.student, course_id=cls.course.id)

@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@patch('openedx.core.djangoapps.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, {
Expand Down Expand Up @@ -1329,7 +1331,7 @@ def setUpTestData(cls):
cls.student = UserFactory.create()
CourseEnrollmentFactory(user=cls.student, course_id=cls.course.id)

@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@patch('openedx.core.djangoapps.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),
Expand Down Expand Up @@ -1369,7 +1371,7 @@ def setUpTestData(cls):
cls.student = UserFactory.create()
CourseEnrollmentFactory(user=cls.student, course_id=cls.course.id)

@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@patch('openedx.core.djangoapps.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.
Expand Down Expand Up @@ -1397,7 +1399,7 @@ def _test_unicode_data(self, text, mock_request):


@ddt.ddt
@patch("django_comment_common.comment_client.utils.requests.request", autospec=True)
@patch("openedx.core.djangoapps.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')
Expand Down Expand Up @@ -1764,7 +1766,7 @@ def setUpTestData(cls):
CourseAccessRoleFactory(course_id=cls.course.id, user=cls.student, role='Wizard')

@patch('eventtracking.tracker.emit')
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True)
def test_thread_created_event(self, __, mock_emit):
request = RequestFactory().post(
"dummy_url", {
Expand Down Expand Up @@ -1793,7 +1795,7 @@ def test_thread_created_event(self, __, mock_emit):
self.assertEquals(event['anonymous_to_peers'], False)

@patch('eventtracking.tracker.emit')
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@patch('openedx.core.djangoapps.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.
Expand All @@ -1819,7 +1821,7 @@ def test_response_event(self, mock_request, mock_emit):
self.assertEqual(event['options']['followed'], True)

@patch('eventtracking.tracker.emit')
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@patch('openedx.core.djangoapps.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.
Expand All @@ -1846,7 +1848,7 @@ def test_comment_event(self, mock_request, mock_emit):
self.assertEqual(event['options']['followed'], False)

@patch('eventtracking.tracker.emit')
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@patch('openedx.core.djangoapps.django_comment_common.comment_client.utils.requests.request', autospec=True)
@ddt.data((
'create_thread',
'edx.forum.thread.created', {
Expand Down Expand Up @@ -1898,7 +1900,7 @@ def test_team_events(self, view_name, event_name, view_data, view_kwargs, mock_r
)
@ddt.unpack
@patch('eventtracking.tracker.emit')
@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@patch('openedx.core.djangoapps.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')

Expand Down Expand Up @@ -1960,7 +1962,7 @@ def make_request(self, method='get', course_id=None, **kwargs):
request.view_name = "users"
return views.users(request, course_id=text_type(course_id))

@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@patch('openedx.core.djangoapps.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")
Expand All @@ -1970,7 +1972,7 @@ def test_finds_exact_match(self, mock_request):
[{"id": self.other_user.id, "username": self.other_user.username}]
)

@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@patch('openedx.core.djangoapps.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")
Expand Down Expand Up @@ -2007,7 +2009,7 @@ def test_requires_requestor_enrolled_in_course(self):
self.assertIn("errors", content)
self.assertNotIn("users", content)

@patch('django_comment_common.comment_client.utils.requests.request', autospec=True)
@patch('openedx.core.djangoapps.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")
Expand Down
Loading

0 comments on commit dfa3728

Please sign in to comment.