diff --git a/common/test/acceptance/tests/lms/test_lms_cohorted_courseware_search.py b/common/test/acceptance/tests/lms/test_lms_cohorted_courseware_search.py index dd699f7b5d..2038aa5807 100644 --- a/common/test/acceptance/tests/lms/test_lms_cohorted_courseware_search.py +++ b/common/test/acceptance/tests/lms/test_lms_cohorted_courseware_search.py @@ -16,9 +16,9 @@ from common.test.acceptance.pages.lms.staff_view import StaffCoursewarePage from common.test.acceptance.pages.studio.component_editor import ComponentVisibilityEditorView from common.test.acceptance.pages.studio.overview import CourseOutlinePage as StudioCourseOutlinePage from common.test.acceptance.pages.studio.settings_group_configurations import GroupConfigurationsPage +from common.test.acceptance.tests.discussion.helpers import CohortTestMixin from common.test.acceptance.tests.helpers import remove_file from common.test.acceptance.tests.studio.base_studio_test import ContainerBase -from common.test.acceptance.tests.discussion.helpers import CohortTestMixin @attr(shard=1) diff --git a/common/test/acceptance/tests/lms/test_lms_help.py b/common/test/acceptance/tests/lms/test_lms_help.py index 979a9b0445..c21a429c65 100644 --- a/common/test/acceptance/tests/lms/test_lms_help.py +++ b/common/test/acceptance/tests/lms/test_lms_help.py @@ -2,15 +2,12 @@ Test Help links in LMS """ -import json - -from common.test.acceptance.fixtures import LMS_BASE_URL from common.test.acceptance.fixtures.course import CourseFixture from common.test.acceptance.pages.lms.instructor_dashboard import InstructorDashboardPage +from common.test.acceptance.tests.discussion.helpers import CohortTestMixin from common.test.acceptance.tests.helpers import assert_opened_help_link_is_correct, url_for_help from common.test.acceptance.tests.lms.test_lms_instructor_dashboard import BaseInstructorDashboardTest from common.test.acceptance.tests.studio.base_studio_test import ContainerBase -from common.test.acceptance.tests.discussion.helpers import CohortTestMixin class TestCohortHelp(ContainerBase, CohortTestMixin): diff --git a/common/test/acceptance/tests/test_cohorted_courseware.py b/common/test/acceptance/tests/test_cohorted_courseware.py index d0509e987e..721dfeadba 100644 --- a/common/test/acceptance/tests/test_cohorted_courseware.py +++ b/common/test/acceptance/tests/test_cohorted_courseware.py @@ -2,8 +2,6 @@ End-to-end test for cohorted courseware. This uses both Studio and LMS. """ -import json - from bok_choy.page_object import XSS_INJECTION from nose.plugins.attrib import attr @@ -14,8 +12,8 @@ from common.test.acceptance.pages.lms.courseware import CoursewarePage from common.test.acceptance.pages.lms.instructor_dashboard import InstructorDashboardPage from common.test.acceptance.pages.studio.component_editor import ComponentVisibilityEditorView from common.test.acceptance.pages.studio.settings_group_configurations import GroupConfigurationsPage -from common.test.acceptance.tests.lms.test_lms_user_preview import verify_expected_problem_visibility from common.test.acceptance.tests.discussion.helpers import CohortTestMixin +from common.test.acceptance.tests.lms.test_lms_user_preview import verify_expected_problem_visibility from studio.base_studio_test import ContainerBase AUDIT_TRACK = "Audit" diff --git a/lms/djangoapps/discussion/tests/test_views.py b/lms/djangoapps/discussion/tests/test_views.py index da3579bc7c..0bdb26c49c 100644 --- a/lms/djangoapps/discussion/tests/test_views.py +++ b/lms/djangoapps/discussion/tests/test_views.py @@ -1,54 +1,55 @@ import json import logging - from datetime import datetime + import ddt +from mock import ANY, Mock, call, patch +from nose.tools import assert_true + +from course_modes.models import CourseMode +from course_modes.tests.factories import CourseModeFactory from django.core.urlresolvers import reverse from django.http import Http404 from django.test.client import Client, RequestFactory from django.test.utils import override_settings from django.utils import translation -from lms.lib.comment_client.utils import CommentClientPaginatedResult - -from course_modes.models import CourseMode -from course_modes.tests.factories import CourseModeFactory -from django_comment_common.utils import ThreadContext -from django_comment_common.models import ForumsConfig, CourseDiscussionSettings -from django_comment_client.permissions import get_team -from django_comment_client.tests.utils import config_course_discussions -from django_comment_client.tests.group_id import ( - GroupIdAssertionMixin, - CohortedTopicGroupIdTestMixin, - NonCohortedTopicGroupIdTestMixin, -) from django_comment_client.constants import TYPE_ENTRY, TYPE_SUBCATEGORY +from django_comment_client.permissions import get_team +from django_comment_client.tests.group_id import ( + CohortedTopicGroupIdTestMixin, + GroupIdAssertionMixin, + NonCohortedTopicGroupIdTestMixin +) from django_comment_client.tests.unicode import UnicodeTestMixin -from django_comment_client.tests.utils import CohortedTestCase, ForumsEnableMixin, topic_name_to_id +from django_comment_client.tests.utils import ( + CohortedTestCase, + ForumsEnableMixin, + config_course_discussions, + topic_name_to_id +) from django_comment_client.utils import strip_none +from django_comment_common.models import CourseDiscussionSettings, ForumsConfig +from django_comment_common.utils import ThreadContext +from lms.djangoapps.courseware.exceptions import CourseAccessRedirect from lms.djangoapps.discussion import views from lms.djangoapps.discussion.views import course_discussions_settings_handler -from student.tests.factories import UserFactory, CourseEnrollmentFactory -from util.testing import UrlResetMixin +from lms.djangoapps.teams.tests.factories import CourseTeamFactory +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 from openedx.core.djangoapps.util.testing import ContentGroupTestCase from openedx.features.enterprise_support.tests.mixins.enterprise import EnterpriseTestConsentRequired +from student.tests.factories import CourseEnrollmentFactory, UserFactory +from util.testing import UrlResetMixin from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ( - ModuleStoreTestCase, - SharedModuleStoreTestCase, TEST_DATA_MONGO_MODULESTORE, + ModuleStoreTestCase, + SharedModuleStoreTestCase ) -from xmodule.modulestore.tests.factories import check_mongo_calls, CourseFactory, ItemFactory - -from nose.tools import assert_true -from mock import patch, Mock, ANY, call - -from openedx.core.djangoapps.course_groups.models import CourseUserGroup - -from lms.djangoapps.courseware.exceptions import CourseAccessRedirect -from lms.djangoapps.teams.tests.factories import CourseTeamFactory +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls log = logging.getLogger(__name__) diff --git a/lms/djangoapps/discussion/views.py b/lms/djangoapps/discussion/views.py index 8ea4280657..3333e20e60 100644 --- a/lms/djangoapps/discussion/views.py +++ b/lms/djangoapps/discussion/views.py @@ -2,21 +2,50 @@ Views handling read (GET) requests for the Discussion tab and inline discussions. """ -from functools import wraps import logging +from contextlib import contextmanager +from functools import wraps from sets import Set +import django_comment_client.utils as utils +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 from django.conf import settings from django.contrib.auth.decorators import login_required -from django.core.context_processors import csrf -from django.core.urlresolvers import reverse from django.contrib.auth.models import User from django.contrib.staticfiles.storage import staticfiles_storage +from django.core.context_processors import csrf +from django.core.urlresolvers import reverse from django.http import Http404, HttpResponseServerError from django.shortcuts import render_to_response from django.template.loader import render_to_string from django.utils.translation import get_language_bidi -from django.views.decorators.http import require_GET +from django.views.decorators.csrf import ensure_csrf_cookie +from django.views.decorators.http import require_GET, require_http_methods +from django_comment_client.constants import TYPE_ENTRY +from django_comment_client.permissions import get_team, has_permission +from django_comment_client.utils import ( + add_courseware_context, + available_division_schemes, + course_discussion_division_enabled, + extract, + get_group_id_for_comments_service, + get_group_id_for_user, + get_group_names_by_id, + is_commentable_divided, + merge_dict, + strip_none +) +from django_comment_common.utils import ThreadContext, get_course_discussion_settings, set_course_discussion_settings +from opaque_keys.edx.keys import CourseKey +from openedx.core.djangoapps.plugin_api.views import EdxFragmentView +from rest_framework import status +from student.models import CourseEnrollment +from util.json_request import JsonResponse, expect_json +from web_fragments.fragment import Fragment +from xmodule.modulestore.django import modulestore log = logging.getLogger("edx.discussions") try: @@ -24,46 +53,6 @@ try: except ImportError: newrelic = None # pylint: disable=invalid-name -from django.views.decorators.csrf import ensure_csrf_cookie -from django.views.decorators.http import require_http_methods - -from rest_framework import status - -from web_fragments.fragment import Fragment - -from courseware.courses import get_course_with_access -from courseware.views.views import CourseTabView -from openedx.core.djangoapps.plugin_api.views import EdxFragmentView - -from courseware.access import has_access -from student.models import CourseEnrollment -from xmodule.modulestore.django import modulestore - -from django_comment_common.utils import ThreadContext, get_course_discussion_settings, set_course_discussion_settings - -from django_comment_client.constants import TYPE_ENTRY -from django_comment_client.permissions import has_permission, get_team -from django_comment_client.utils import ( - available_division_schemes, - merge_dict, - extract, - strip_none, - add_courseware_context, - get_group_id_for_comments_service, - course_discussion_division_enabled, - get_group_names_by_id, - is_commentable_divided, - get_group_id_for_user, -) - -import django_comment_client.utils as utils -import lms.lib.comment_client as cc - -from opaque_keys.edx.keys import CourseKey - -from contextlib import contextmanager -from util.json_request import expect_json, JsonResponse - THREADS_PER_PAGE = 20 INLINE_THREADS_PER_PAGE = 20 diff --git a/lms/djangoapps/discussion_api/api.py b/lms/djangoapps/discussion_api/api.py index 4afe988f0b..0e7979b454 100644 --- a/lms/djangoapps/discussion_api/api.py +++ b/lms/djangoapps/discussion_api/api.py @@ -1,56 +1,48 @@ """ Discussion API internal interface """ +import itertools from collections import defaultdict +from enum import Enum from urllib import urlencode from urlparse import urlunparse -from django.core.exceptions import ValidationError -from django.core.urlresolvers import reverse -from django.http import Http404 -import itertools -from enum import Enum -from openedx.core.djangoapps.user_api.accounts.views import AccountViewSet - -from rest_framework.exceptions import PermissionDenied - -from lms.djangoapps.courseware.exceptions import CourseAccessRedirect -from opaque_keys import InvalidKeyError -from opaque_keys.edx.locator import CourseKey from courseware.courses import get_course_with_access - -from discussion_api.exceptions import ThreadNotFoundError, CommentNotFoundError, DiscussionDisabledError +from discussion_api.exceptions import CommentNotFoundError, DiscussionDisabledError, ThreadNotFoundError from discussion_api.forms import CommentActionsForm, ThreadActionsForm from discussion_api.permissions import ( can_delete, get_editable_fields, get_initializable_comment_fields, - get_initializable_thread_fields, -) -from discussion_api.serializers import CommentSerializer, ThreadSerializer, get_context, DiscussionTopicSerializer -from django_comment_client.base.views import ( - track_comment_created_event, - track_thread_created_event, - track_voted_event, + get_initializable_thread_fields ) +from discussion_api.serializers import CommentSerializer, DiscussionTopicSerializer, ThreadSerializer, get_context +from django.core.exceptions import ValidationError +from django.core.urlresolvers import reverse +from django.http import Http404 +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.signals import ( - thread_created, - thread_edited, - thread_deleted, - thread_voted, comment_created, + comment_deleted, comment_edited, comment_voted, - comment_deleted, + thread_created, + thread_deleted, + thread_edited, + thread_voted ) from django_comment_common.utils import get_course_discussion_settings - -from django_comment_client.utils import get_accessible_discussion_xblocks, is_commentable_divided, get_group_id_for_user +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.lib.exceptions import CourseNotFoundError, PageNotFoundError, DiscussionNotFoundError +from opaque_keys import InvalidKeyError +from opaque_keys.edx.locator import CourseKey +from openedx.core.djangoapps.user_api.accounts.views import AccountViewSet +from openedx.core.lib.exceptions import CourseNotFoundError, DiscussionNotFoundError, PageNotFoundError +from rest_framework.exceptions import PermissionDenied class DiscussionTopic(object): diff --git a/lms/djangoapps/discussion_api/serializers.py b/lms/djangoapps/discussion_api/serializers.py index ce07ec1d9c..a11ff95ae6 100644 --- a/lms/djangoapps/discussion_api/serializers.py +++ b/lms/djangoapps/discussion_api/serializers.py @@ -4,31 +4,20 @@ Discussion API serializers from urllib import urlencode from urlparse import urlunparse +from discussion_api.permissions import NON_UPDATABLE_COMMENT_FIELDS, NON_UPDATABLE_THREAD_FIELDS, get_editable_fields +from discussion_api.render import render_body from django.contrib.auth.models import User as DjangoUser from django.core.exceptions import ValidationError from django.core.urlresolvers import reverse - -from rest_framework import serializers - -from discussion_api.permissions import ( - NON_UPDATABLE_COMMENT_FIELDS, - NON_UPDATABLE_THREAD_FIELDS, - get_editable_fields, -) -from discussion_api.render import render_body from django_comment_client.utils import is_comment_too_deep +from django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_MODERATOR, Role from django_comment_common.utils import get_course_discussion_settings -from django_comment_common.models import ( - FORUM_ROLE_ADMINISTRATOR, - FORUM_ROLE_COMMUNITY_TA, - FORUM_ROLE_MODERATOR, - Role, -) +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 lms.djangoapps.django_comment_client.utils import course_discussion_division_enabled, get_group_names_by_id +from rest_framework import serializers def get_context(course, request, thread=None): diff --git a/lms/djangoapps/discussion_api/tests/test_api.py b/lms/djangoapps/discussion_api/tests/test_api.py index c297fad147..11cc6f33f9 100644 --- a/lms/djangoapps/discussion_api/tests/test_api.py +++ b/lms/djangoapps/discussion_api/tests/test_api.py @@ -1,24 +1,16 @@ """ Tests for Discussion API internal interface """ -from datetime import datetime, timedelta import itertools -from urlparse import parse_qs, urlparse, urlunparse +from datetime import datetime, timedelta from urllib import urlencode +from urlparse import parse_qs, urlparse, urlunparse import ddt -import httpretty import mock from nose.plugins.attrib import attr -from pytz import UTC - -from django.core.exceptions import ValidationError -from django.test.client import RequestFactory - -from rest_framework.exceptions import PermissionDenied - -from opaque_keys.edx.locator import CourseLocator +import httpretty from common.test.utils import MockSignalHandlerMixin, disable_signal from courseware.tests.factories import BetaTesterFactory, StaffFactory from discussion_api import api @@ -30,29 +22,34 @@ from discussion_api.api import ( get_comment_list, get_course, get_course_topics, + get_thread, get_thread_list, update_comment, - update_thread, - get_thread, + update_thread ) -from discussion_api.exceptions import DiscussionDisabledError, ThreadNotFoundError, CommentNotFoundError +from discussion_api.exceptions import CommentNotFoundError, DiscussionDisabledError, ThreadNotFoundError from discussion_api.tests.utils import ( CommentsServiceMockMixin, make_minimal_cs_comment, make_minimal_cs_thread, - make_paginated_api_response, + make_paginated_api_response ) +from django.core.exceptions import ValidationError +from django.test.client import RequestFactory +from django_comment_client.tests.utils import ForumsEnableMixin from django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_MODERATOR, FORUM_ROLE_STUDENT, - Role, + Role ) -from django_comment_client.tests.utils import ForumsEnableMixin +from opaque_keys.edx.locator import CourseLocator from openedx.core.djangoapps.course_groups.models import CourseUserGroupPartitionGroup from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory from openedx.core.lib.exceptions import CourseNotFoundError, PageNotFoundError +from pytz import UTC +from rest_framework.exceptions import PermissionDenied from student.tests.factories import CourseEnrollmentFactory, UserFactory from util.testing import UrlResetMixin from xmodule.modulestore import ModuleStoreEnum diff --git a/lms/djangoapps/discussion_api/tests/test_serializers.py b/lms/djangoapps/discussion_api/tests/test_serializers.py index 084c30ad86..413a5b4a59 100644 --- a/lms/djangoapps/discussion_api/tests/test_serializers.py +++ b/lms/djangoapps/discussion_api/tests/test_serializers.py @@ -5,35 +5,30 @@ import itertools from urlparse import urlparse import ddt -import httpretty import mock from nose.plugins.attrib import attr -from django.test.client import RequestFactory - +import httpretty from discussion_api.serializers import CommentSerializer, ThreadSerializer, get_context -from discussion_api.tests.utils import ( - CommentsServiceMockMixin, - make_minimal_cs_thread, - make_minimal_cs_comment, -) +from discussion_api.tests.utils import CommentsServiceMockMixin, make_minimal_cs_comment, make_minimal_cs_thread +from django.test.client import RequestFactory +from django_comment_client.tests.utils import ForumsEnableMixin from django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_MODERATOR, FORUM_ROLE_STUDENT, - Role, + 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 from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory -from django_comment_client.tests.utils import ForumsEnableMixin @ddt.ddt diff --git a/lms/djangoapps/django_comment_client/tests/test_utils.py b/lms/djangoapps/django_comment_client/tests/test_utils.py index 33855765c5..c273ed88b3 100644 --- a/lms/djangoapps/django_comment_client/tests/test_utils.py +++ b/lms/djangoapps/django_comment_client/tests/test_utils.py @@ -1,42 +1,41 @@ # -*- coding: utf-8 -*- import datetime import json + import ddt import mock -from mock import patch, Mock +from mock import Mock, patch from nose.plugins.attrib import attr -from pytz import UTC -from django.utils.timezone import UTC as django_utc -from django.core.urlresolvers import reverse -from django.test import TestCase, RequestFactory -from edxmako import add_lookup - -from django_comment_client.tests.factories import RoleFactory -from django_comment_client.tests.unicode import UnicodeTestMixin -from django_comment_client.tests.utils import topic_name_to_id, config_course_discussions -from django_comment_client.constants import TYPE_ENTRY, TYPE_SUBCATEGORY import django_comment_client.utils as utils -from lms.lib.comment_client.utils import perform_request, CommentClientMaintenanceError -from django_comment_common.models import ForumsConfig, CourseDiscussionSettings -from django_comment_common.utils import get_course_discussion_settings, set_course_discussion_settings - from course_modes.models import CourseMode from course_modes.tests.factories import CourseModeFactory -from courseware.tests.factories import InstructorFactory from courseware.tabs import get_course_tab_list +from courseware.tests.factories import InstructorFactory +from django.core.urlresolvers import reverse +from django.test import RequestFactory, TestCase +from django.utils.timezone import UTC as django_utc +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.models import CourseDiscussionSettings, ForumsConfig +from django_comment_common.utils import get_course_discussion_settings, set_course_discussion_settings +from edxmako import add_lookup +from lms.djangoapps.teams.tests.factories import CourseTeamFactory +from lms.lib.comment_client.utils import CommentClientMaintenanceError, perform_request +from openedx.core.djangoapps.content.course_structures.models import CourseStructure 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 config_course_cohorts, CohortFactory -from student.tests.factories import UserFactory, AdminFactory, CourseEnrollmentFactory -from openedx.core.djangoapps.content.course_structures.models import CourseStructure +from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory, config_course_cohorts from openedx.core.djangoapps.util.testing import ContentGroupTestCase +from pytz import UTC from student.roles import CourseStaffRole +from student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, ToyCourseFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, TEST_DATA_MIXED_MODULESTORE from xmodule.modulestore.django import modulestore -from lms.djangoapps.teams.tests.factories import CourseTeamFactory +from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, ToyCourseFactory @attr(shard=1) diff --git a/lms/djangoapps/django_comment_client/tests/utils.py b/lms/djangoapps/django_comment_client/tests/utils.py index 5406ff828e..9400cef662 100644 --- a/lms/djangoapps/django_comment_client/tests/utils.py +++ b/lms/djangoapps/django_comment_client/tests/utils.py @@ -3,15 +3,15 @@ Utilities for tests within the django_comment_client module. """ from mock import patch +from django_comment_common.models import ForumsConfig, Role +from django_comment_common.utils import CourseDiscussionSettings, seed_permissions_roles, set_course_discussion_settings from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory -from django_comment_common.models import Role, ForumsConfig -from django_comment_common.utils import seed_permissions_roles, set_course_discussion_settings, CourseDiscussionSettings from student.tests.factories import CourseEnrollmentFactory, UserFactory from util.testing import UrlResetMixin from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class ForumsEnableMixin(object): diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index 01ec2710d0..a2591fff0f 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -1,38 +1,33 @@ -from collections import defaultdict -from datetime import datetime import json import logging -from django.conf import settings +from collections import defaultdict +from datetime import datetime +import pystache_custom as pystache import pytz +from courseware import courses +from courseware.access import has_access +from django.conf import settings from django.contrib.auth.models import User from django.core.urlresolvers import reverse from django.db import connection from django.http import HttpResponse from django.utils.timezone import UTC -import pystache_custom as pystache -from opaque_keys.edx.locations import i4xEncoder -from opaque_keys.edx.keys import CourseKey -from xmodule.modulestore.django import modulestore -from xmodule.partitions.partitions_service import PartitionService -from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID - from django_comment_client.constants import TYPE_ENTRY, TYPE_SUBCATEGORY -from django_comment_client.permissions import check_permissions_by_view, has_permission, get_team +from django_comment_client.permissions import check_permissions_by_view, get_team, has_permission from django_comment_client.settings import MAX_COMMENT_DEPTH -from django_comment_common.models import Role, FORUM_ROLE_STUDENT, CourseDiscussionSettings +from django_comment_common.models import FORUM_ROLE_STUDENT, CourseDiscussionSettings, Role from django_comment_common.utils import get_course_discussion_settings from edxmako import lookup_template - -from courseware import courses -from courseware.access import has_access +from opaque_keys.edx.keys import CourseKey +from opaque_keys.edx.locations import i4xEncoder from openedx.core.djangoapps.content.course_structures.models import CourseStructure -from openedx.core.djangoapps.course_groups.cohorts import ( - is_course_cohorted, get_cohort_id, get_cohort_names -) +from openedx.core.djangoapps.course_groups.cohorts import get_cohort_id, get_cohort_names, is_course_cohorted from request_cache.middleware import request_cached from student.roles import GlobalStaff - +from xmodule.modulestore.django import modulestore +from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID +from xmodule.partitions.partitions_service import PartitionService log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/course_groups/tests/helpers.py b/openedx/core/djangoapps/course_groups/tests/helpers.py index 9dd84b64ad..216ba458ff 100644 --- a/openedx/core/djangoapps/course_groups/tests/helpers.py +++ b/openedx/core/djangoapps/course_groups/tests/helpers.py @@ -2,18 +2,18 @@ Helper methods for testing cohorts. """ -from factory import post_generation, Sequence -from factory.django import DjangoModelFactory import json -from opaque_keys.edx.locations import SlashSeparatedCourseKey -from xmodule.modulestore.django import modulestore -from xmodule.modulestore import ModuleStoreEnum - -from ..cohorts import set_course_cohorted from django_comment_common.models import CourseDiscussionSettings from django_comment_common.utils import set_course_discussion_settings -from ..models import CourseUserGroup, CourseCohort, CourseCohortsSettings, CohortMembership +from factory import Sequence, post_generation +from factory.django import DjangoModelFactory +from opaque_keys.edx.locations import SlashSeparatedCourseKey +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore + +from ..cohorts import set_course_cohorted +from ..models import CohortMembership, CourseCohort, CourseCohortsSettings, CourseUserGroup class CohortFactory(DjangoModelFactory): diff --git a/openedx/core/djangoapps/course_groups/tests/test_cohorts.py b/openedx/core/djangoapps/course_groups/tests/test_cohorts.py index 722a5a1235..4b8171de26 100644 --- a/openedx/core/djangoapps/course_groups/tests/test_cohorts.py +++ b/openedx/core/djangoapps/course_groups/tests/test_cohorts.py @@ -5,13 +5,12 @@ Tests for cohorts import ddt from mock import call, patch from nose.plugins.attrib import attr -import before_after +import before_after from django.contrib.auth.models import User from django.db import IntegrityError from django.http import Http404 from django.test import TestCase - from opaque_keys.edx.locations import SlashSeparatedCourseKey from student.models import CourseEnrollment from student.tests.factories import UserFactory @@ -19,12 +18,9 @@ from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_MODULESTORE, ModuleStoreTestCase from xmodule.modulestore.tests.factories import ToyCourseFactory -from ..models import CourseUserGroup, CourseCohort, CourseUserGroupPartitionGroup from .. import cohorts -from ..tests.helpers import ( - config_course_cohorts, config_course_cohorts_legacy, - CohortFactory, CourseCohortFactory -) +from ..models import CourseCohort, CourseUserGroup, CourseUserGroupPartitionGroup +from ..tests.helpers import CohortFactory, CourseCohortFactory, config_course_cohorts, config_course_cohorts_legacy @attr(shard=2) diff --git a/openedx/core/djangoapps/course_groups/tests/test_views.py b/openedx/core/djangoapps/course_groups/tests/test_views.py index 432c1aa5af..fdd9343c3d 100644 --- a/openedx/core/djangoapps/course_groups/tests/test_views.py +++ b/openedx/core/djangoapps/course_groups/tests/test_views.py @@ -4,37 +4,32 @@ Tests for course group views # pylint: disable=attribute-defined-outside-init # pylint: disable=no-member import json - from collections import namedtuple + from nose.plugins.attrib import attr from django.contrib.auth.models import User from django.http import Http404 from django.test.client import RequestFactory - from django_comment_common.models import CourseDiscussionSettings from django_comment_common.utils import get_course_discussion_settings +from opaque_keys.edx.locations import SlashSeparatedCourseKey from student.models import CourseEnrollment from student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from opaque_keys.edx.locations import SlashSeparatedCourseKey - -from ..models import CourseUserGroup, CourseCohort +from ..cohorts import DEFAULT_COHORT_NAME, get_cohort, get_cohort_by_id, get_cohort_by_name, get_group_info_for_cohort +from ..models import CourseCohort, CourseUserGroup from ..views import ( + add_users_to_cohort, + cohort_handler, course_cohort_settings_handler, - cohort_handler, users_in_cohort, - add_users_to_cohort, remove_user_from_cohort, link_cohort_to_partition_group, + remove_user_from_cohort, + users_in_cohort ) -from ..cohorts import ( - get_cohort, get_cohort_by_name, get_cohort_by_id, - DEFAULT_COHORT_NAME, get_group_info_for_cohort -) -from .helpers import ( - config_course_cohorts, config_course_cohorts_legacy, CohortFactory, CourseCohortFactory -) +from .helpers import CohortFactory, CourseCohortFactory, config_course_cohorts, config_course_cohorts_legacy @attr(shard=2) diff --git a/openedx/core/djangoapps/verified_track_content/partition_scheme.py b/openedx/core/djangoapps/verified_track_content/partition_scheme.py index c783e16831..28eedbaf4d 100644 --- a/openedx/core/djangoapps/verified_track_content/partition_scheme.py +++ b/openedx/core/djangoapps/verified_track_content/partition_scheme.py @@ -1,20 +1,18 @@ """ UserPartitionScheme for enrollment tracks. """ -from django.conf import settings - +from course_modes.models import CourseMode from courseware.masquerade import ( get_course_masquerade, get_masquerading_user_group, is_masquerading_as_specific_student ) -from course_modes.models import CourseMode -from student.models import CourseEnrollment +from django.conf import settings from opaque_keys.edx.keys import CourseKey from openedx.core.djangoapps.verified_track_content.models import VerifiedTrackCohortedCourse +from student.models import CourseEnrollment from xmodule.partitions.partitions import Group, UserPartition - # These IDs must be less than 100 so that they do not overlap with Groups in # CohortUserPartition or RandomUserPartitionScheme # (CMS' course_group_config uses a minimum value of 100 for all generated IDs). diff --git a/openedx/core/djangoapps/verified_track_content/tests/test_models.py b/openedx/core/djangoapps/verified_track_content/tests/test_models.py index f4e62a93a5..ce841a61c0 100644 --- a/openedx/core/djangoapps/verified_track_content/tests/test_models.py +++ b/openedx/core/djangoapps/verified_track_content/tests/test_models.py @@ -4,23 +4,26 @@ Tests for Verified Track Cohorting models # pylint: disable=attribute-defined-outside-init # pylint: disable=no-member -from django.test import TestCase import mock from mock import patch +from django.test import TestCase from opaque_keys.edx.keys import CourseKey - -from openedx.core.djangoapps.course_groups.cohorts import get_cohort -from student.models import CourseMode -from student.tests.factories import UserFactory, CourseEnrollmentFactory -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory -from ..models import VerifiedTrackCohortedCourse, DEFAULT_VERIFIED_COHORT_NAME -from ..tasks import sync_cohort_with_mode from openedx.core.djangoapps.course_groups.cohorts import ( - set_course_cohorted, add_cohort, CourseCohort, DEFAULT_COHORT_NAME + DEFAULT_COHORT_NAME, + CourseCohort, + add_cohort, + get_cohort, + set_course_cohorted ) from openedx.core.djangolib.testing.utils import skip_unless_lms +from student.models import CourseMode +from student.tests.factories import CourseEnrollmentFactory, UserFactory +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory + +from ..models import DEFAULT_VERIFIED_COHORT_NAME, VerifiedTrackCohortedCourse +from ..tasks import sync_cohort_with_mode class TestVerifiedTrackCohortedCourse(TestCase):