diff --git a/cms/celery.py b/cms/celery.py index 3ea455b66f..eb534e25a1 100644 --- a/cms/celery.py +++ b/cms/celery.py @@ -5,9 +5,12 @@ and auto discover tasks in all installed django apps. Taken from: http://celery.readthedocs.org/en/latest/django/first-steps-with-django.html """ from __future__ import absolute_import + import os + from celery import Celery from django.conf import settings + from openedx.core.lib.celery.routers import AlternateEnvironmentRouter # set the default Django settings module for the 'celery' program. diff --git a/cms/djangoapps/cms_user_tasks/signals.py b/cms/djangoapps/cms_user_tasks/signals.py index e21924080c..6640ab2a18 100644 --- a/cms/djangoapps/cms_user_tasks/signals.py +++ b/cms/djangoapps/cms_user_tasks/signals.py @@ -4,13 +4,14 @@ Receivers of signals sent from django-user-tasks from __future__ import absolute_import, print_function, unicode_literals import logging -from six.moves.urllib.parse import urljoin # pylint: disable=import-error from django.core.urlresolvers import reverse from django.dispatch import receiver from user_tasks.models import UserTaskArtifact from user_tasks.signals import user_task_stopped +from six.moves.urllib.parse import urljoin # pylint: disable=import-error + from .tasks import send_task_complete_email LOGGER = logging.getLogger(__name__) diff --git a/cms/djangoapps/cms_user_tasks/tasks.py b/cms/djangoapps/cms_user_tasks/tasks.py index 8233e14ed7..ff27715a76 100644 --- a/cms/djangoapps/cms_user_tasks/tasks.py +++ b/cms/djangoapps/cms_user_tasks/tasks.py @@ -2,11 +2,10 @@ Celery tasks used by cms_user_tasks """ -from celery.task import task -from celery.exceptions import MaxRetriesExceededError -from celery.utils.log import get_task_logger from boto.exception import NoAuthHandlerFound - +from celery.exceptions import MaxRetriesExceededError +from celery.task import task +from celery.utils.log import get_task_logger from django.conf import settings from django.core import mail diff --git a/cms/djangoapps/cms_user_tasks/tests.py b/cms/djangoapps/cms_user_tasks/tests.py index ae967d0c77..4672fc4915 100644 --- a/cms/djangoapps/cms_user_tasks/tests.py +++ b/cms/djangoapps/cms_user_tasks/tests.py @@ -4,21 +4,20 @@ Unit tests for integration of the django-user-tasks app and its REST API. from __future__ import absolute_import, print_function, unicode_literals -from uuid import uuid4 import logging +from uuid import uuid4 import mock from boto.exception import NoAuthHandlerFound -from rest_framework.test import APITestCase - +from django.conf import settings from django.contrib.auth.models import User +from django.core import mail from django.core.urlresolvers import reverse from django.test import override_settings -from django.conf import settings -from django.core import mail - +from rest_framework.test import APITestCase from user_tasks.models import UserTaskArtifact, UserTaskStatus from user_tasks.serializers import ArtifactSerializer, StatusSerializer + from .signals import user_task_stopped diff --git a/cms/djangoapps/contentstore/admin.py b/cms/djangoapps/contentstore/admin.py index 21904959f8..c28a5355e8 100644 --- a/cms/djangoapps/contentstore/admin.py +++ b/cms/djangoapps/contentstore/admin.py @@ -2,10 +2,10 @@ Admin site bindings for contentstore """ +from config_models.admin import ConfigurationModelAdmin from django.contrib import admin -from config_models.admin import ConfigurationModelAdmin -from contentstore.models import VideoUploadConfig, PushNotificationConfig +from contentstore.models import PushNotificationConfig, VideoUploadConfig admin.site.register(VideoUploadConfig, ConfigurationModelAdmin) admin.site.register(PushNotificationConfig, ConfigurationModelAdmin) diff --git a/cms/djangoapps/contentstore/course_group_config.py b/cms/djangoapps/contentstore/course_group_config.py index 6bcbee47a7..9e8285a505 100644 --- a/cms/djangoapps/contentstore/course_group_config.py +++ b/cms/djangoapps/contentstore/course_group_config.py @@ -4,12 +4,12 @@ Class for manipulating groups configuration on a course object. import json import logging -from util.db import generate_int_id, MYSQL_MAX_INT - from django.utils.translation import ugettext as _ + from contentstore.utils import reverse_usage_url from openedx.core.djangoapps.course_groups.partition_scheme import get_cohorted_user_partition -from xmodule.partitions.partitions import UserPartition, MINIMUM_STATIC_PARTITION_ID +from util.db import MYSQL_MAX_INT, generate_int_id +from xmodule.partitions.partitions import MINIMUM_STATIC_PARTITION_ID, UserPartition from xmodule.partitions.partitions_service import get_all_partitions_for_course from xmodule.split_test_module import get_split_user_partitions diff --git a/cms/djangoapps/contentstore/course_info_model.py b/cms/djangoapps/contentstore/course_info_model.py index c5632b3373..d5631d9e94 100644 --- a/cms/djangoapps/contentstore/course_info_model.py +++ b/cms/djangoapps/contentstore/course_info_model.py @@ -12,18 +12,17 @@ Current db representation: } """ -import re import logging +import re from django.http import HttpResponseBadRequest from django.utils.translation import ugettext as _ -from xmodule.modulestore.exceptions import ItemNotFoundError -from xmodule.modulestore.django import modulestore -from xmodule.html_module import CourseInfoModule - -from openedx.core.lib.xblock_utils import get_course_update_items from cms.djangoapps.contentstore.push_notification import enqueue_push_course_update +from openedx.core.lib.xblock_utils import get_course_update_items +from xmodule.html_module import CourseInfoModule +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.exceptions import ItemNotFoundError # # This should be in a class which inherits from XmlDescriptor log = logging.getLogger(__name__) diff --git a/cms/djangoapps/contentstore/courseware_index.py b/cms/djangoapps/contentstore/courseware_index.py index ea4b819283..2b4f146427 100644 --- a/cms/djangoapps/contentstore/courseware_index.py +++ b/cms/djangoapps/contentstore/courseware_index.py @@ -1,23 +1,25 @@ """ Code to allow module store to interface with courseware index """ from __future__ import absolute_import -from abc import ABCMeta, abstractmethod -from datetime import timedelta + import logging import re -from six import add_metaclass +from abc import ABCMeta, abstractmethod +from datetime import timedelta from django.conf import settings -from django.utils.translation import ugettext_lazy, ugettext as _ from django.core.urlresolvers import resolve +from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext_lazy +from search.search_engine_base import SearchEngine +from six import add_metaclass from contentstore.course_group_config import GroupConfiguration from course_modes.models import CourseMode from eventtracking import tracker from openedx.core.lib.courses import course_image_url -from search.search_engine_base import SearchEngine from xmodule.annotator_mixin import html_to_text -from xmodule.modulestore import ModuleStoreEnum from xmodule.library_tools import normalize_key_for_search +from xmodule.modulestore import ModuleStoreEnum # REINDEX_AGE is the default amount of time that we look back for changes # that might have happened. If we are provided with a time at which the diff --git a/cms/djangoapps/contentstore/debug_file_uploader.py b/cms/djangoapps/contentstore/debug_file_uploader.py index d783e16192..12acfe95c3 100644 --- a/cms/djangoapps/contentstore/debug_file_uploader.py +++ b/cms/djangoapps/contentstore/debug_file_uploader.py @@ -1,6 +1,7 @@ -from django.core.files.uploadhandler import FileUploadHandler import time +from django.core.files.uploadhandler import FileUploadHandler + class DebugFileUploader(FileUploadHandler): def __init__(self, request=None): diff --git a/cms/djangoapps/contentstore/features/advanced_settings.py b/cms/djangoapps/contentstore/features/advanced_settings.py index 56cad31ad6..5125fac12f 100644 --- a/cms/djangoapps/contentstore/features/advanced_settings.py +++ b/cms/djangoapps/contentstore/features/advanced_settings.py @@ -1,9 +1,10 @@ # pylint: disable=missing-docstring # pylint: disable=redefined-outer-name -from lettuce import world, step -from nose.tools import assert_false, assert_equal, assert_regexp_matches -from common import type_in_codemirror, press_the_notification_button, get_codemirror_value +from lettuce import step, world +from nose.tools import assert_equal, assert_false, assert_regexp_matches + +from common import get_codemirror_value, press_the_notification_button, type_in_codemirror KEY_CSS = '.key h3.title' DISPLAY_NAME_KEY = "Course Display Name" diff --git a/cms/djangoapps/contentstore/features/common.py b/cms/djangoapps/contentstore/features/common.py index cb7ad41be0..70ce70d0ae 100644 --- a/cms/djangoapps/contentstore/features/common.py +++ b/cms/djangoapps/contentstore/features/common.py @@ -2,21 +2,21 @@ # pylint: disable=redefined-outer-name import os -from lettuce import world, step -from nose.tools import assert_true, assert_in +from logging import getLogger + from django.conf import settings - -from student.roles import CourseStaffRole, CourseInstructorRole, GlobalStaff -from student.models import get_user - +from lettuce import step, world +from nose.tools import assert_in, assert_true from selenium.webdriver.common.keys import Keys -from logging import getLogger -from student.tests.factories import AdminFactory from student import auth +from student.models import get_user +from student.roles import CourseInstructorRole, CourseStaffRole, GlobalStaff +from student.tests.factories import AdminFactory +from terrain.browser import reset_data + logger = getLogger(__name__) -from terrain.browser import reset_data TEST_ROOT = settings.COMMON_TEST_DATA_ROOT diff --git a/cms/djangoapps/contentstore/features/component.py b/cms/djangoapps/contentstore/features/component.py index ce470fe81e..a884f08fa0 100644 --- a/cms/djangoapps/contentstore/features/component.py +++ b/cms/djangoapps/contentstore/features/component.py @@ -5,8 +5,8 @@ # argument name "step" instead of "_step" and pylint does not like that. # pylint: disable=unused-argument -from lettuce import world, step -from nose.tools import assert_true, assert_in, assert_equal +from lettuce import step, world +from nose.tools import assert_equal, assert_in, assert_true DISPLAY_NAME = "Display Name" diff --git a/cms/djangoapps/contentstore/features/component_settings_editor_helpers.py b/cms/djangoapps/contentstore/features/component_settings_editor_helpers.py index 0a342f08e8..a8474d70e6 100644 --- a/cms/djangoapps/contentstore/features/component_settings_editor_helpers.py +++ b/cms/djangoapps/contentstore/features/component_settings_editor_helpers.py @@ -3,10 +3,11 @@ from lettuce import world from nose.tools import assert_equal, assert_in -from terrain.steps import reload_the_page -from common import type_in_codemirror from selenium.webdriver.common.keys import Keys +from common import type_in_codemirror +from terrain.steps import reload_the_page + @world.absorb def create_component_instance(step, category, component_type=None, is_advanced=False, advanced_component=None): diff --git a/cms/djangoapps/contentstore/features/course-settings.py b/cms/djangoapps/contentstore/features/course-settings.py index df44ef9917..9df6a5f091 100644 --- a/cms/djangoapps/contentstore/features/course-settings.py +++ b/cms/djangoapps/contentstore/features/course-settings.py @@ -1,12 +1,12 @@ # pylint: disable=missing-docstring # pylint: disable=redefined-outer-name -from lettuce import world, step -from selenium.webdriver.common.keys import Keys -from cms.djangoapps.contentstore.features.common import type_in_codemirror from django.conf import settings +from lettuce import step, world +from nose.tools import assert_false, assert_true +from selenium.webdriver.common.keys import Keys -from nose.tools import assert_true, assert_false +from cms.djangoapps.contentstore.features.common import type_in_codemirror TEST_ROOT = settings.COMMON_TEST_DATA_ROOT diff --git a/cms/djangoapps/contentstore/features/course-updates.py b/cms/djangoapps/contentstore/features/course-updates.py index 3a9d0103c6..286d44848b 100644 --- a/cms/djangoapps/contentstore/features/course-updates.py +++ b/cms/djangoapps/contentstore/features/course-updates.py @@ -1,9 +1,10 @@ # pylint: disable=missing-docstring -from cms.djangoapps.contentstore.features.common import type_in_codemirror, get_codemirror_value -from lettuce import world, step +from lettuce import step, world from nose.tools import assert_in +from cms.djangoapps.contentstore.features.common import get_codemirror_value, type_in_codemirror + @step(u'I go to the course updates page') def go_to_updates(_step): diff --git a/cms/djangoapps/contentstore/features/course_import.py b/cms/djangoapps/contentstore/features/course_import.py index c8293c5d11..e75db207bc 100644 --- a/cms/djangoapps/contentstore/features/course_import.py +++ b/cms/djangoapps/contentstore/features/course_import.py @@ -3,8 +3,9 @@ # pylint: disable=unused-argument import os -from lettuce import world, step + from django.conf import settings +from lettuce import step, world def import_file(filename): diff --git a/cms/djangoapps/contentstore/features/courses.py b/cms/djangoapps/contentstore/features/courses.py index 218faded58..de94f437ae 100644 --- a/cms/djangoapps/contentstore/features/courses.py +++ b/cms/djangoapps/contentstore/features/courses.py @@ -2,9 +2,11 @@ # pylint: disable=redefined-outer-name # pylint: disable=unused-argument -from lettuce import world, step +from lettuce import step, world + from common import * + ############### ACTIONS #################### diff --git a/cms/djangoapps/contentstore/features/discussion-editor.py b/cms/djangoapps/contentstore/features/discussion-editor.py index e7f52df8e6..804fedcc7e 100644 --- a/cms/djangoapps/contentstore/features/discussion-editor.py +++ b/cms/djangoapps/contentstore/features/discussion-editor.py @@ -1,7 +1,7 @@ # disable missing docstring # pylint: disable=missing-docstring -from lettuce import world, step +from lettuce import step, world @step('I have created a Discussion Tag$') diff --git a/cms/djangoapps/contentstore/features/grading.py b/cms/djangoapps/contentstore/features/grading.py index 1ed6855389..c86a9a1cd9 100644 --- a/cms/djangoapps/contentstore/features/grading.py +++ b/cms/djangoapps/contentstore/features/grading.py @@ -1,12 +1,13 @@ # pylint: disable=missing-docstring # pylint: disable=redefined-outer-name -from lettuce import world, step -from common import * -from terrain.steps import reload_the_page +from lettuce import step, world +from nose.tools import assert_equal, assert_in, assert_not_equal from selenium.common.exceptions import InvalidElementStateException + +from common import * from contentstore.utils import reverse_course_url -from nose.tools import assert_in, assert_equal, assert_not_equal +from terrain.steps import reload_the_page @step(u'I am viewing the grading settings') diff --git a/cms/djangoapps/contentstore/features/html-editor.py b/cms/djangoapps/contentstore/features/html-editor.py index 6aebaa4b85..a858fabbf0 100644 --- a/cms/djangoapps/contentstore/features/html-editor.py +++ b/cms/djangoapps/contentstore/features/html-editor.py @@ -3,9 +3,10 @@ from collections import OrderedDict -from lettuce import world, step -from nose.tools import assert_in, assert_false, assert_true, assert_equal -from common import type_in_codemirror, get_codemirror_value +from lettuce import step, world +from nose.tools import assert_equal, assert_false, assert_in, assert_true + +from common import get_codemirror_value, type_in_codemirror CODEMIRROR_SELECTOR_PREFIX = "$('iframe').contents().find" diff --git a/cms/djangoapps/contentstore/features/pages.py b/cms/djangoapps/contentstore/features/pages.py index f16aec9d60..9004a5a0a2 100644 --- a/cms/djangoapps/contentstore/features/pages.py +++ b/cms/djangoapps/contentstore/features/pages.py @@ -2,10 +2,9 @@ # pylint: disable=redefined-outer-name # pylint: disable=unused-argument -from lettuce import world, step +from lettuce import step, world from nose.tools import assert_equal, assert_in - CSS_FOR_TAB_ELEMENT = "li[data-tab-id='{0}'] input.toggle-checkbox" diff --git a/cms/djangoapps/contentstore/features/problem-editor.py b/cms/djangoapps/contentstore/features/problem-editor.py index b1d7c97159..8ff30ef7df 100644 --- a/cms/djangoapps/contentstore/features/problem-editor.py +++ b/cms/djangoapps/contentstore/features/problem-editor.py @@ -2,10 +2,12 @@ # pylint: disable=missing-docstring import json -from lettuce import world, step + +from lettuce import step, world from nose.tools import assert_equal, assert_true -from common import type_in_codemirror, open_new_course -from advanced_settings import change_value, ADVANCED_MODULES_KEY + +from advanced_settings import ADVANCED_MODULES_KEY, change_value +from common import open_new_course, type_in_codemirror from course_import import import_file DISPLAY_NAME = "Display Name" diff --git a/cms/djangoapps/contentstore/features/signup.py b/cms/djangoapps/contentstore/features/signup.py index 1a8d9c2002..dfcf29e279 100644 --- a/cms/djangoapps/contentstore/features/signup.py +++ b/cms/djangoapps/contentstore/features/signup.py @@ -1,8 +1,8 @@ # pylint: disable=missing-docstring # pylint: disable=redefined-outer-name -from lettuce import world, step -from nose.tools import assert_true, assert_false +from lettuce import step, world +from nose.tools import assert_false, assert_true @step('I fill in the registration form$') diff --git a/cms/djangoapps/contentstore/features/textbooks.py b/cms/djangoapps/contentstore/features/textbooks.py index 9b46dabc51..3d86eea7ed 100644 --- a/cms/djangoapps/contentstore/features/textbooks.py +++ b/cms/djangoapps/contentstore/features/textbooks.py @@ -1,10 +1,11 @@ # pylint: disable=missing-docstring -from lettuce import world, step from django.conf import settings -from common import upload_file +from lettuce import step, world from nose.tools import assert_equal +from common import upload_file + TEST_ROOT = settings.COMMON_TEST_DATA_ROOT diff --git a/cms/djangoapps/contentstore/features/transcripts.py b/cms/djangoapps/contentstore/features/transcripts.py index 87f41b3a9f..177fe3c12d 100644 --- a/cms/djangoapps/contentstore/features/transcripts.py +++ b/cms/djangoapps/contentstore/features/transcripts.py @@ -2,14 +2,14 @@ # pylint: disable=missing-docstring import os -from lettuce import world, step from django.conf import settings +from lettuce import step, world +from splinter.request_handler.request_handler import RequestHandler from xmodule.contentstore.content import StaticContent from xmodule.contentstore.django import contentstore from xmodule.exceptions import NotFoundError -from splinter.request_handler.request_handler import RequestHandler TEST_ROOT = settings.COMMON_TEST_DATA_ROOT diff --git a/cms/djangoapps/contentstore/features/upload.py b/cms/djangoapps/contentstore/features/upload.py index d46c29eff9..dfa7f16601 100644 --- a/cms/djangoapps/contentstore/features/upload.py +++ b/cms/djangoapps/contentstore/features/upload.py @@ -1,17 +1,19 @@ # pylint: disable=missing-docstring # pylint: disable=redefined-outer-name -from lettuce import world, step -from lettuce.django import django_url -from django.conf import settings -import requests -import string -import random import os +import random +import string + +import requests +from django.conf import settings from django.contrib.auth.models import User -from student.models import CourseEnrollment +from lettuce import step, world +from lettuce.django import django_url from nose.tools import assert_equal, assert_not_equal +from student.models import CourseEnrollment + TEST_ROOT = settings.COMMON_TEST_DATA_ROOT ASSET_NAMES_CSS = 'td.name-col > span.title > a.filename' diff --git a/cms/djangoapps/contentstore/features/video.py b/cms/djangoapps/contentstore/features/video.py index cf650589bc..e8d9e1fe35 100644 --- a/cms/djangoapps/contentstore/features/video.py +++ b/cms/djangoapps/contentstore/features/video.py @@ -1,6 +1,6 @@ # pylint: disable=missing-docstring -from lettuce import world, step +from lettuce import step, world SELECTORS = { 'spinner': '.video-wrapper .spinner', diff --git a/cms/djangoapps/contentstore/management/commands/clean_cert_name.py b/cms/djangoapps/contentstore/management/commands/clean_cert_name.py index 8914069b7c..923e38c633 100644 --- a/cms/djangoapps/contentstore/management/commands/clean_cert_name.py +++ b/cms/djangoapps/contentstore/management/commands/clean_cert_name.py @@ -7,8 +7,8 @@ from collections import namedtuple from django.core.management.base import BaseCommand -from xmodule.modulestore.django import modulestore from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore Result = namedtuple("Result", ["course_key", "cert_name_short", "cert_name_long", "should_clean"]) diff --git a/cms/djangoapps/contentstore/management/commands/cleanup_assets.py b/cms/djangoapps/contentstore/management/commands/cleanup_assets.py index 7896aca3ec..c3524c51c6 100644 --- a/cms/djangoapps/contentstore/management/commands/cleanup_assets.py +++ b/cms/djangoapps/contentstore/management/commands/cleanup_assets.py @@ -5,8 +5,8 @@ or with filename which starts with "._") for all courses import logging from django.core.management.base import BaseCommand -from xmodule.contentstore.django import contentstore +from xmodule.contentstore.django import contentstore log = logging.getLogger(__name__) diff --git a/cms/djangoapps/contentstore/management/commands/clone_course.py b/cms/djangoapps/contentstore/management/commands/clone_course.py index bbd94e52eb..2430fb0e8e 100644 --- a/cms/djangoapps/contentstore/management/commands/clone_course.py +++ b/cms/djangoapps/contentstore/management/commands/clone_course.py @@ -2,12 +2,13 @@ Script for cloning a course """ from django.core.management.base import BaseCommand, CommandError -from xmodule.modulestore.django import modulestore -from student.roles import CourseInstructorRole, CourseStaffRole -from opaque_keys.edx.keys import CourseKey from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locations import SlashSeparatedCourseKey + +from student.roles import CourseInstructorRole, CourseStaffRole from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore # diff --git a/cms/djangoapps/contentstore/management/commands/create_course.py b/cms/djangoapps/contentstore/management/commands/create_course.py index 19d88a597e..5908990a09 100644 --- a/cms/djangoapps/contentstore/management/commands/create_course.py +++ b/cms/djangoapps/contentstore/management/commands/create_course.py @@ -1,11 +1,12 @@ """ Django management command to create a course in a specific modulestore """ -from django.core.management.base import BaseCommand, CommandError from django.contrib.auth.models import User -from xmodule.modulestore import ModuleStoreEnum -from contentstore.views.course import create_new_course_in_store +from django.core.management.base import BaseCommand, CommandError + from contentstore.management.commands.utils import user_from_str +from contentstore.views.course import create_new_course_in_store +from xmodule.modulestore import ModuleStoreEnum class Command(BaseCommand): diff --git a/cms/djangoapps/contentstore/management/commands/delete_course.py b/cms/djangoapps/contentstore/management/commands/delete_course.py index 3f91828f12..989aa6c5b9 100644 --- a/cms/djangoapps/contentstore/management/commands/delete_course.py +++ b/cms/djangoapps/contentstore/management/commands/delete_course.py @@ -8,13 +8,15 @@ none """ from django.core.management.base import BaseCommand, CommandError -from .prompt import query_yes_no -from contentstore.utils import delete_course_and_groups -from opaque_keys.edx.keys import CourseKey from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey + +from contentstore.utils import delete_course_and_groups from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore +from .prompt import query_yes_no + class Command(BaseCommand): """ diff --git a/cms/djangoapps/contentstore/management/commands/delete_orphans.py b/cms/djangoapps/contentstore/management/commands/delete_orphans.py index 48e2689e9f..c765cda23a 100644 --- a/cms/djangoapps/contentstore/management/commands/delete_orphans.py +++ b/cms/djangoapps/contentstore/management/commands/delete_orphans.py @@ -1,8 +1,9 @@ """Script for deleting orphans""" from django.core.management.base import BaseCommand, CommandError -from contentstore.views.item import _delete_orphans -from opaque_keys.edx.keys import CourseKey from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey + +from contentstore.views.item import _delete_orphans from xmodule.modulestore import ModuleStoreEnum diff --git a/cms/djangoapps/contentstore/management/commands/edit_course_tabs.py b/cms/djangoapps/contentstore/management/commands/edit_course_tabs.py index 65d45bf0b2..e63a4f97cb 100644 --- a/cms/djangoapps/contentstore/management/commands/edit_course_tabs.py +++ b/cms/djangoapps/contentstore/management/commands/edit_course_tabs.py @@ -8,14 +8,14 @@ # from optparse import make_option from django.core.management.base import BaseCommand, CommandError -from .prompt import query_yes_no - -from courseware.courses import get_course_by_id +from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey +from opaque_keys.edx.locations import SlashSeparatedCourseKey from contentstore.views import tabs -from opaque_keys import InvalidKeyError -from opaque_keys.edx.locations import SlashSeparatedCourseKey -from opaque_keys.edx.keys import CourseKey +from courseware.courses import get_course_by_id + +from .prompt import query_yes_no def print_course(course): diff --git a/cms/djangoapps/contentstore/management/commands/empty_asset_trashcan.py b/cms/djangoapps/contentstore/management/commands/empty_asset_trashcan.py index 9466471fbc..91cc8b3c24 100644 --- a/cms/djangoapps/contentstore/management/commands/empty_asset_trashcan.py +++ b/cms/djangoapps/contentstore/management/commands/empty_asset_trashcan.py @@ -1,10 +1,12 @@ from django.core.management.base import BaseCommand, CommandError +from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey +from opaque_keys.edx.locations import SlashSeparatedCourseKey + from xmodule.contentstore.utils import empty_asset_trashcan from xmodule.modulestore.django import modulestore -from opaque_keys.edx.keys import CourseKey + from .prompt import query_yes_no -from opaque_keys import InvalidKeyError -from opaque_keys.edx.locations import SlashSeparatedCourseKey class Command(BaseCommand): diff --git a/cms/djangoapps/contentstore/management/commands/export.py b/cms/djangoapps/contentstore/management/commands/export.py index 44923c6abf..7cb621dfae 100644 --- a/cms/djangoapps/contentstore/management/commands/export.py +++ b/cms/djangoapps/contentstore/management/commands/export.py @@ -4,13 +4,14 @@ Script for exporting courseware from Mongo to a tar.gz file import os from django.core.management.base import BaseCommand, CommandError -from xmodule.modulestore.xml_exporter import export_course_to_xml -from xmodule.modulestore.django import modulestore -from opaque_keys.edx.keys import CourseKey -from xmodule.contentstore.django import contentstore from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locations import SlashSeparatedCourseKey +from xmodule.contentstore.django import contentstore +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.xml_exporter import export_course_to_xml + class Command(BaseCommand): """ diff --git a/cms/djangoapps/contentstore/management/commands/export_all_courses.py b/cms/djangoapps/contentstore/management/commands/export_all_courses.py index c5ab34c421..54f6b11f03 100644 --- a/cms/djangoapps/contentstore/management/commands/export_all_courses.py +++ b/cms/djangoapps/contentstore/management/commands/export_all_courses.py @@ -2,9 +2,10 @@ Script for exporting all courseware from Mongo to a directory and listing the courses which failed to export """ from django.core.management.base import BaseCommand, CommandError -from xmodule.modulestore.xml_exporter import export_course_to_xml -from xmodule.modulestore.django import modulestore + from xmodule.contentstore.django import contentstore +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.xml_exporter import export_course_to_xml class Command(BaseCommand): diff --git a/cms/djangoapps/contentstore/management/commands/export_olx.py b/cms/djangoapps/contentstore/management/commands/export_olx.py index 67a14fcad2..72ac1f1f26 100644 --- a/cms/djangoapps/contentstore/management/commands/export_olx.py +++ b/cms/djangoapps/contentstore/management/commands/export_olx.py @@ -19,17 +19,16 @@ import os import re import shutil import tarfile -from tempfile import mktemp, mkdtemp +from tempfile import mkdtemp, mktemp from textwrap import dedent -from path import Path as path - from django.core.management.base import BaseCommand, CommandError +from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey +from path import Path as path from xmodule.modulestore.django import modulestore from xmodule.modulestore.xml_exporter import export_course_to_xml -from opaque_keys import InvalidKeyError -from opaque_keys.edx.keys import CourseKey class Command(BaseCommand): diff --git a/cms/djangoapps/contentstore/management/commands/fix_not_found.py b/cms/djangoapps/contentstore/management/commands/fix_not_found.py index c31c4d446c..ddf00f9c97 100644 --- a/cms/djangoapps/contentstore/management/commands/fix_not_found.py +++ b/cms/djangoapps/contentstore/management/commands/fix_not_found.py @@ -3,8 +3,10 @@ Script for fixing the item not found errors in a course """ from django.core.management.base import BaseCommand, CommandError from opaque_keys.edx.keys import CourseKey -from xmodule.modulestore.django import modulestore + from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore + # To run from command line: ./manage.py cms fix_not_found course-v1:org+course+run diff --git a/cms/djangoapps/contentstore/management/commands/force_publish.py b/cms/djangoapps/contentstore/management/commands/force_publish.py index 96f68334b4..6dcea6f95f 100644 --- a/cms/djangoapps/contentstore/management/commands/force_publish.py +++ b/cms/djangoapps/contentstore/management/commands/force_publish.py @@ -2,13 +2,16 @@ Script for force publishing a course """ from django.core.management.base import BaseCommand, CommandError -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.django import modulestore from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey + +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore + from .prompt import query_yes_no from .utils import get_course_versions + # To run from command line: ./manage.py cms force_publish course-v1:org+course+run diff --git a/cms/djangoapps/contentstore/management/commands/git_export.py b/cms/djangoapps/contentstore/management/commands/git_export.py index 1edb195345..cafa7bab33 100644 --- a/cms/djangoapps/contentstore/management/commands/git_export.py +++ b/cms/djangoapps/contentstore/management/commands/git_export.py @@ -18,12 +18,12 @@ from optparse import make_option from django.core.management.base import BaseCommand, CommandError from django.utils.translation import ugettext as _ +from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey +from opaque_keys.edx.locations import SlashSeparatedCourseKey import contentstore.git_export_utils as git_export_utils -from opaque_keys.edx.locations import SlashSeparatedCourseKey -from opaque_keys import InvalidKeyError from contentstore.git_export_utils import GitExportError -from opaque_keys.edx.keys import CourseKey log = logging.getLogger(__name__) diff --git a/cms/djangoapps/contentstore/management/commands/import.py b/cms/djangoapps/contentstore/management/commands/import.py index 9a9483cbc1..9cd6467033 100644 --- a/cms/djangoapps/contentstore/management/commands/import.py +++ b/cms/djangoapps/contentstore/management/commands/import.py @@ -4,12 +4,12 @@ Script for importing courseware from XML format from optparse import make_option from django.core.management.base import BaseCommand, CommandError -from django_comment_common.utils import (seed_permissions_roles, - are_permissions_roles_seeded) -from xmodule.modulestore.xml_importer import import_course_from_xml + +from 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 -from xmodule.contentstore.django import contentstore +from xmodule.modulestore.xml_importer import import_course_from_xml class Command(BaseCommand): diff --git a/cms/djangoapps/contentstore/management/commands/migrate_to_split.py b/cms/djangoapps/contentstore/management/commands/migrate_to_split.py index 2a2634f5bc..3613a26c5e 100644 --- a/cms/djangoapps/contentstore/management/commands/migrate_to_split.py +++ b/cms/djangoapps/contentstore/management/commands/migrate_to_split.py @@ -2,14 +2,15 @@ Django management command to migrate a course from the old Mongo modulestore to the new split-Mongo modulestore. """ -from django.core.management.base import BaseCommand, CommandError from django.contrib.auth.models import User +from django.core.management.base import BaseCommand, CommandError +from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey + +from contentstore.management.commands.utils import user_from_str +from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.split_migrator import SplitMigrator -from opaque_keys.edx.keys import CourseKey -from opaque_keys import InvalidKeyError -from xmodule.modulestore import ModuleStoreEnum -from contentstore.management.commands.utils import user_from_str class Command(BaseCommand): diff --git a/cms/djangoapps/contentstore/management/commands/populate_creators.py b/cms/djangoapps/contentstore/management/commands/populate_creators.py index f56b3a635e..fa5a848028 100644 --- a/cms/djangoapps/contentstore/management/commands/populate_creators.py +++ b/cms/djangoapps/contentstore/management/commands/populate_creators.py @@ -3,13 +3,14 @@ Script for granting existing course instructors course creator privileges. This script is only intended to be run once on a given environment. """ -from course_creators.views import add_user_with_status_granted, add_user_with_status_unrequested -from django.core.management.base import BaseCommand - from django.contrib.auth.models import User +from django.core.management.base import BaseCommand from django.db.utils import IntegrityError + +from course_creators.views import add_user_with_status_granted, add_user_with_status_unrequested from student.roles import CourseInstructorRole, CourseStaffRole + #------------ to run: ./manage.py cms populate_creators --settings=dev diff --git a/cms/djangoapps/contentstore/management/commands/reindex_course.py b/cms/djangoapps/contentstore/management/commands/reindex_course.py index 56cb1008af..796783ca57 100644 --- a/cms/djangoapps/contentstore/management/commands/reindex_course.py +++ b/cms/djangoapps/contentstore/management/commands/reindex_course.py @@ -1,21 +1,20 @@ """ Management command to update courses' search index """ import logging -from django.core.management import BaseCommand, CommandError from optparse import make_option from textwrap import dedent -from contentstore.courseware_index import CoursewareSearchIndexer -from search.search_engine_base import SearchEngine +from django.core.management import BaseCommand, CommandError from elasticsearch import exceptions - -from opaque_keys.edx.keys import CourseKey from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import CourseLocator +from search.search_engine_base import SearchEngine + +from contentstore.courseware_index import CoursewareSearchIndexer +from xmodule.modulestore.django import modulestore from .prompt import query_yes_no -from xmodule.modulestore.django import modulestore - class Command(BaseCommand): """ diff --git a/cms/djangoapps/contentstore/management/commands/reindex_library.py b/cms/djangoapps/contentstore/management/commands/reindex_library.py index 2c9cabc070..99d984f66e 100644 --- a/cms/djangoapps/contentstore/management/commands/reindex_library.py +++ b/cms/djangoapps/contentstore/management/commands/reindex_library.py @@ -1,19 +1,18 @@ """ Management command to update libraries' search index """ -from django.core.management import BaseCommand, CommandError from optparse import make_option from textwrap import dedent -from contentstore.courseware_index import LibrarySearchIndexer - -from opaque_keys.edx.keys import CourseKey +from django.core.management import BaseCommand, CommandError from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locations import SlashSeparatedCourseKey from opaque_keys.edx.locator import LibraryLocator -from .prompt import query_yes_no - +from contentstore.courseware_index import LibrarySearchIndexer from xmodule.modulestore.django import modulestore +from .prompt import query_yes_no + class Command(BaseCommand): """ diff --git a/cms/djangoapps/contentstore/management/commands/restore_asset_from_trashcan.py b/cms/djangoapps/contentstore/management/commands/restore_asset_from_trashcan.py index 7513b8b47c..fa314ddbd3 100644 --- a/cms/djangoapps/contentstore/management/commands/restore_asset_from_trashcan.py +++ b/cms/djangoapps/contentstore/management/commands/restore_asset_from_trashcan.py @@ -1,4 +1,5 @@ from django.core.management.base import BaseCommand, CommandError + from xmodule.contentstore.utils import restore_asset_from_trashcan diff --git a/cms/djangoapps/contentstore/management/commands/utils.py b/cms/djangoapps/contentstore/management/commands/utils.py index 03502f8441..0b248ca526 100644 --- a/cms/djangoapps/contentstore/management/commands/utils.py +++ b/cms/djangoapps/contentstore/management/commands/utils.py @@ -3,6 +3,7 @@ Common methods for cms commands to use """ from django.contrib.auth.models import User from opaque_keys.edx.keys import CourseKey + from xmodule.modulestore.django import modulestore diff --git a/cms/djangoapps/contentstore/management/commands/xlint.py b/cms/djangoapps/contentstore/management/commands/xlint.py index 9c08e2de5d..afb7c73980 100644 --- a/cms/djangoapps/contentstore/management/commands/xlint.py +++ b/cms/djangoapps/contentstore/management/commands/xlint.py @@ -2,6 +2,7 @@ Verify the structure of courseware as to it's suitability for import """ from django.core.management.base import BaseCommand, CommandError + from xmodule.modulestore.xml_importer import perform_xlint diff --git a/cms/djangoapps/contentstore/migrations/0001_initial.py b/cms/djangoapps/contentstore/migrations/0001_initial.py index 88126406e3..ef69433f2a 100644 --- a/cms/djangoapps/contentstore/migrations/0001_initial.py +++ b/cms/djangoapps/contentstore/migrations/0001_initial.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import migrations, models import django.db.models.deletion from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/cms/djangoapps/contentstore/models.py b/cms/djangoapps/contentstore/models.py index 12435dd9c2..7fa8efe4f9 100644 --- a/cms/djangoapps/contentstore/models.py +++ b/cms/djangoapps/contentstore/models.py @@ -2,9 +2,8 @@ Models for contentstore """ -from django.db.models.fields import TextField - from config_models.models import ConfigurationModel +from django.db.models.fields import TextField class VideoUploadConfig(ConfigurationModel): diff --git a/cms/djangoapps/contentstore/proctoring.py b/cms/djangoapps/contentstore/proctoring.py index 4731e18946..70d0cbd46e 100644 --- a/cms/djangoapps/contentstore/proctoring.py +++ b/cms/djangoapps/contentstore/proctoring.py @@ -5,24 +5,20 @@ Code related to the handling of Proctored Exams in Studio import logging from django.conf import settings +from edx_proctoring.api import ( + create_exam, + create_exam_review_policy, + get_all_exams_for_course, + get_exam_by_content_id, + remove_review_policy, + update_exam, + update_review_policy +) +from edx_proctoring.exceptions import ProctoredExamNotFoundException, ProctoredExamReviewPolicyNotFoundException +from contentstore.views.helpers import is_item_in_course_tree from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError -from contentstore.views.helpers import is_item_in_course_tree - -from edx_proctoring.api import ( - get_exam_by_content_id, - update_exam, - create_exam, - get_all_exams_for_course, - update_review_policy, - create_exam_review_policy, - remove_review_policy, -) -from edx_proctoring.exceptions import ( - ProctoredExamNotFoundException, - ProctoredExamReviewPolicyNotFoundException -) log = logging.getLogger(__name__) diff --git a/cms/djangoapps/contentstore/push_notification.py b/cms/djangoapps/contentstore/push_notification.py index ec99d61713..ed038e07dd 100644 --- a/cms/djangoapps/contentstore/push_notification.py +++ b/cms/djangoapps/contentstore/push_notification.py @@ -2,16 +2,17 @@ Helper methods for push notifications from Studio. """ -from uuid import uuid4 -from django.conf import settings from logging import exception as log_exception +from uuid import uuid4 + +from django.conf import settings -from contentstore.tasks import push_course_update_task from contentstore.models import PushNotificationConfig -from xmodule.modulestore.django import modulestore -from parse_rest.installation import Push +from contentstore.tasks import push_course_update_task from parse_rest.connection import register from parse_rest.core import ParseError +from parse_rest.installation import Push +from xmodule.modulestore.django import modulestore def push_notification_enabled(): diff --git a/cms/djangoapps/contentstore/signals/handlers.py b/cms/djangoapps/contentstore/signals/handlers.py index 2742832420..89edd300a3 100644 --- a/cms/djangoapps/contentstore/signals/handlers.py +++ b/cms/djangoapps/contentstore/signals/handlers.py @@ -2,17 +2,16 @@ import logging from datetime import datetime -from pytz import UTC from django.dispatch import receiver +from pytz import UTC -from xmodule.modulestore.django import modulestore, SignalHandler from contentstore.courseware_index import CoursewareSearchIndexer, LibrarySearchIndexer from contentstore.proctoring import register_special_exams from openedx.core.djangoapps.credit.signals import on_course_publish from openedx.core.lib.gating import api as gating_api from util.module_utils import yield_dynamic_descriptor_descendants - +from xmodule.modulestore.django import SignalHandler, modulestore log = logging.getLogger(__name__) diff --git a/cms/djangoapps/contentstore/storage.py b/cms/djangoapps/contentstore/storage.py index 72dc99d062..76bd5b54bd 100644 --- a/cms/djangoapps/contentstore/storage.py +++ b/cms/djangoapps/contentstore/storage.py @@ -5,7 +5,6 @@ from __future__ import absolute_import from django.conf import settings from django.core.files.storage import get_storage_class - from storages.backends.s3boto import S3BotoStorage from storages.utils import setting diff --git a/cms/djangoapps/contentstore/tasks.py b/cms/djangoapps/contentstore/tasks.py index 55341cb22d..3061987f80 100644 --- a/cms/djangoapps/contentstore/tasks.py +++ b/cms/djangoapps/contentstore/tasks.py @@ -13,11 +13,6 @@ from tempfile import NamedTemporaryFile, mkdtemp from celery.task import task from celery.utils.log import get_task_logger -from organizations.models import OrganizationCourse -from path import Path as path -from pytz import UTC -from six import iteritems, text_type - from django.conf import settings from django.contrib.auth.models import User from django.core.exceptions import SuspiciousOperation @@ -25,8 +20,13 @@ from django.core.files import File from django.test import RequestFactory from django.utils.text import get_valid_filename from django.utils.translation import ugettext as _ - from djcelery.common import respect_language +from opaque_keys.edx.keys import CourseKey +from opaque_keys.edx.locator import LibraryLocator +from organizations.models import OrganizationCourse +from path import Path as path +from pytz import UTC +from six import iteritems, text_type from user_tasks.models import UserTaskArtifact, UserTaskStatus from user_tasks.tasks import UserTask @@ -36,9 +36,7 @@ from contentstore.storage import course_import_export_storage from contentstore.utils import initialize_permissions, reverse_usage_url from course_action_state.models import CourseRerunState from models.settings.course_metadata import CourseMetadata -from opaque_keys.edx.keys import CourseKey -from opaque_keys.edx.locator import LibraryLocator -from openedx.core.djangoapps.embargo.models import RestrictedCourse, CountryAccessRule +from openedx.core.djangoapps.embargo.models import CountryAccessRule, RestrictedCourse from openedx.core.lib.extract_tar import safetar_extractall from student.auth import has_course_author_access from xmodule.contentstore.django import contentstore @@ -50,7 +48,6 @@ from xmodule.modulestore.exceptions import DuplicateCourseError, ItemNotFoundErr from xmodule.modulestore.xml_exporter import export_course_to_xml, export_library_to_xml from xmodule.modulestore.xml_importer import import_course_from_xml, import_library_from_xml - LOGGER = get_task_logger(__name__) FILE_READ_CHUNK = 1024 # bytes FULL_COURSE_REINDEX_THRESHOLD = 1 diff --git a/cms/djangoapps/contentstore/tests/test_clone_course.py b/cms/djangoapps/contentstore/tests/test_clone_course.py index a0c9428dd0..82b931a54f 100644 --- a/cms/djangoapps/contentstore/tests/test_clone_course.py +++ b/cms/djangoapps/contentstore/tests/test_clone_course.py @@ -2,21 +2,21 @@ Unit tests for cloning a course between the same and different module stores. """ import json -from django.conf import settings +from django.conf import settings +from mock import Mock, patch from opaque_keys.edx.locator import CourseLocator -from xmodule.modulestore import ModuleStoreEnum, EdxJSONEncoder -from contentstore.tests.utils import CourseTestCase + from contentstore.tasks import rerun_course -from student.auth import has_course_author_access -from course_action_state.models import CourseRerunState +from contentstore.tests.utils import CourseTestCase from course_action_state.managers import CourseRerunUIStateManager -from mock import patch, Mock +from course_action_state.models import CourseRerunState +from student.auth import has_course_author_access from xmodule.contentstore.content import StaticContent from xmodule.contentstore.django import contentstore +from xmodule.modulestore import EdxJSONEncoder, ModuleStoreEnum from xmodule.modulestore.tests.factories import CourseFactory - TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 921ca75507..f7f52f42f1 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -1,63 +1,54 @@ # -*- coding: utf-8 -*- import copy -import mock import shutil -import lxml.html -from lxml import etree -import ddt - from datetime import timedelta -from fs.osfs import OSFS -from json import loads -from path import Path as path -from textwrap import dedent -from uuid import uuid4 from functools import wraps +from json import loads +from textwrap import dedent from unittest import SkipTest +from uuid import uuid4 +import ddt +import lxml.html +import mock from django.conf import settings from django.contrib.auth.models import User from django.test import TestCase from django.test.utils import override_settings - -from openedx.core.lib.tempdir import mkdtemp_clean -from common.test.utils import XssTestMixin -from contentstore.tests.utils import parse_json, AjaxEnabledTestClient, CourseTestCase -from contentstore.views.component import ADVANCED_COMPONENT_TYPES - from edxval.api import create_video, get_videos_for_course - -from xmodule.contentstore.django import contentstore -from xmodule.contentstore.utils import restore_asset_from_trashcan, empty_asset_trashcan -from xmodule.exceptions import InvalidVersionError -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.exceptions import ItemNotFoundError -from xmodule.modulestore.inheritance import own_metadata -from opaque_keys.edx.keys import UsageKey, CourseKey +from fs.osfs import OSFS +from lxml import etree +from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey, UsageKey from opaque_keys.edx.locations import AssetLocation, CourseLocator -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, LibraryFactory, check_mongo_calls -from xmodule.modulestore.xml_exporter import export_course_to_xml -from xmodule.modulestore.xml_importer import import_course_from_xml, perform_xlint +from path import Path as path -from xmodule.capa_module import CapaDescriptor -from xmodule.course_module import CourseDescriptor, Textbook -from xmodule.seq_module import SequenceDescriptor - -from contentstore.utils import delete_course_and_groups, reverse_url, reverse_course_url +from common.test.utils import XssTestMixin +from contentstore.tests.utils import AjaxEnabledTestClient, CourseTestCase, get_url, parse_json +from contentstore.utils import delete_course_and_groups, reverse_course_url, reverse_url +from contentstore.views.component import ADVANCED_COMPONENT_TYPES +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.lib.tempdir import mkdtemp_clean from student import auth from student.models import CourseEnrollment from student.roles import CourseCreatorRole, CourseInstructorRole -from opaque_keys import InvalidKeyError -from contentstore.tests.utils import get_url -from course_action_state.models import CourseRerunState, CourseRerunUIStateManager - -from course_action_state.managers import CourseActionStateItemNotFoundError +from xmodule.capa_module import CapaDescriptor from xmodule.contentstore.content import StaticContent +from xmodule.contentstore.django import contentstore +from xmodule.contentstore.utils import empty_asset_trashcan, restore_asset_from_trashcan +from xmodule.course_module import CourseDescriptor, Textbook +from xmodule.exceptions import InvalidVersionError +from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore - +from xmodule.modulestore.exceptions import ItemNotFoundError +from xmodule.modulestore.inheritance import own_metadata +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, LibraryFactory, check_mongo_calls +from xmodule.modulestore.xml_exporter import export_course_to_xml +from xmodule.modulestore.xml_importer import import_course_from_xml, perform_xlint +from xmodule.seq_module import SequenceDescriptor TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex diff --git a/cms/djangoapps/contentstore/tests/test_core_caching.py b/cms/djangoapps/contentstore/tests/test_core_caching.py index 853aff077e..f2d08dc001 100644 --- a/cms/djangoapps/contentstore/tests/test_core_caching.py +++ b/cms/djangoapps/contentstore/tests/test_core_caching.py @@ -3,9 +3,9 @@ Tests core caching facilities. """ from django.test import TestCase - from opaque_keys.edx.locations import Location -from openedx.core.djangoapps.contentserver.caching import get_cached_content, set_cached_content, del_cached_content + +from openedx.core.djangoapps.contentserver.caching import del_cached_content, get_cached_content, set_cached_content class Content(object): diff --git a/cms/djangoapps/contentstore/tests/test_course_create_rerun.py b/cms/djangoapps/contentstore/tests/test_course_create_rerun.py index e70fc9a671..9912416c9c 100644 --- a/cms/djangoapps/contentstore/tests/test_course_create_rerun.py +++ b/cms/djangoapps/contentstore/tests/test_course_create_rerun.py @@ -1,26 +1,23 @@ """ Test view handler for rerun (and eventually create) """ -import ddt -from mock import patch +from datetime import datetime -from django.test.client import RequestFactory +import ddt from django.core.urlresolvers import reverse +from django.test.client import RequestFactory +from mock import patch from opaque_keys.edx.keys import CourseKey -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.django import modulestore +from contentstore.tests.utils import AjaxEnabledTestClient, parse_json from student.roles import CourseInstructorRole, CourseStaffRole from student.tests.factories import UserFactory -from contentstore.tests.utils import AjaxEnabledTestClient, parse_json -from datetime import datetime +from util.organizations_helpers import add_organization, get_course_organizations from xmodule.course_module import CourseFields -from util.organizations_helpers import ( - add_organization, - get_course_organizations, -) +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory @ddt.ddt diff --git a/cms/djangoapps/contentstore/tests/test_course_listing.py b/cms/djangoapps/contentstore/tests/test_course_listing.py index cf34eb9013..1e7cdf4a87 100644 --- a/cms/djangoapps/contentstore/tests/test_course_listing.py +++ b/cms/djangoapps/contentstore/tests/test_course_listing.py @@ -4,43 +4,40 @@ by reversing group name formats. """ import random -from chrono import Timer -from mock import patch, Mock import ddt - -from django.conf import settings from ccx_keys.locator import CCXLocator +from chrono import Timer +from django.conf import settings from django.test import RequestFactory from django.test.client import Client +from mock import Mock, patch +from opaque_keys.edx.locations import CourseLocator from common.test.utils import XssTestMixin -from xmodule.course_module import CourseSummary - +from contentstore.tests.utils import AjaxEnabledTestClient +from contentstore.utils import delete_course_and_groups from contentstore.views.course import ( + AccessListFallback, _accessible_courses_iter, _accessible_courses_list_from_groups, - AccessListFallback, - get_courses_accessible_to_user, _accessible_courses_summary_iter, + get_courses_accessible_to_user ) -from contentstore.utils import delete_course_and_groups -from contentstore.tests.utils import AjaxEnabledTestClient -from student.tests.factories import UserFactory +from course_action_state.models import CourseRerunState from student.roles import ( CourseInstructorRole, CourseStaffRole, GlobalStaff, - OrgStaffRole, OrgInstructorRole, - UserBasedRole, + OrgStaffRole, + UserBasedRole ) +from student.tests.factories import UserFactory +from xmodule.course_module import CourseSummary +from xmodule.error_module import ErrorDescriptor +from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls -from xmodule.modulestore import ModuleStoreEnum -from opaque_keys.edx.locations import CourseLocator -from xmodule.error_module import ErrorDescriptor -from course_action_state.models import CourseRerunState - TOTAL_COURSES_COUNT = 10 USER_COURSES_COUNT = 1 diff --git a/cms/djangoapps/contentstore/tests/test_course_settings.py b/cms/djangoapps/contentstore/tests/test_course_settings.py index 5fe8f575e4..4311c5c60b 100644 --- a/cms/djangoapps/contentstore/tests/test_course_settings.py +++ b/cms/djangoapps/contentstore/tests/test_course_settings.py @@ -1,24 +1,25 @@ """ Tests for Studio Course Settings. """ -import datetime -import ddt -import json import copy -import mock -from mock import Mock, patch +import datetime +import json import unittest +import ddt +import mock from django.conf import settings -from django.utils.timezone import UTC from django.test.utils import override_settings +from django.utils.timezone import UTC +from milestones.tests.utils import MilestonesTestCaseMixin +from mock import Mock, patch from contentstore.utils import reverse_course_url, reverse_usage_url from models.settings.course_grading import CourseGradingModel from models.settings.course_metadata import CourseMetadata from models.settings.encoder import CourseSettingsEncoder -from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration from openedx.core.djangoapps.models.course_details import CourseDetails +from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration from student.roles import CourseInstructorRole, CourseStaffRole from student.tests.factories import UserFactory from xblock_django.models import XBlockStudioConfigurationFlag @@ -27,9 +28,8 @@ from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.factories import CourseFactory from xmodule.tabs import InvalidTabsException -from milestones.tests.utils import MilestonesTestCaseMixin -from .utils import CourseTestCase, AjaxEnabledTestClient +from .utils import AjaxEnabledTestClient, CourseTestCase def get_url(course_id, handler_name='settings_handler'): diff --git a/cms/djangoapps/contentstore/tests/test_courseware_index.py b/cms/djangoapps/contentstore/tests/test_courseware_index.py index aaa305f0c3..b6d91b3a04 100644 --- a/cms/djangoapps/contentstore/tests/test_courseware_index.py +++ b/cms/djangoapps/contentstore/tests/test_courseware_index.py @@ -1,19 +1,29 @@ """ Testing indexing of the courseware as it is changed """ -import ddt import json -from lazy.lazy import lazy import time from datetime import datetime +from unittest import skip +from uuid import uuid4 + +import ddt from dateutil.tz import tzutc +from django.conf import settings +from lazy.lazy import lazy from mock import patch from pytz import UTC -from uuid import uuid4 -from unittest import skip - -from django.conf import settings +from search.search_engine_base import SearchEngine +from contentstore.courseware_index import ( + CourseAboutSearchIndexer, + CoursewareSearchIndexer, + LibrarySearchIndexer, + SearchIndexingError +) +from contentstore.signals.handlers import listen_for_course_publish, listen_for_library_update +from contentstore.tests.utils import CourseTestCase +from contentstore.utils import reverse_course_url, reverse_usage_url from course_modes.models import CourseMode from openedx.core.djangoapps.models.course_details import CourseDetails from xmodule.library_tools import normalize_key_for_search @@ -25,28 +35,19 @@ from xmodule.modulestore.mixed import MixedModuleStore from xmodule.modulestore.tests.django_utils import ( TEST_DATA_MONGO_MODULESTORE, TEST_DATA_SPLIT_MODULESTORE, - SharedModuleStoreTestCase) -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, LibraryFactory -from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST -from xmodule.modulestore.tests.utils import ( - create_modulestore_instance, LocationMixin, - MixedSplitTestCase, MongoContentstoreBuilder + SharedModuleStoreTestCase ) +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, LibraryFactory +from xmodule.modulestore.tests.mongo_connection import MONGO_HOST, MONGO_PORT_NUM +from xmodule.modulestore.tests.utils import ( + LocationMixin, + MixedSplitTestCase, + MongoContentstoreBuilder, + create_modulestore_instance +) +from xmodule.partitions.partitions import UserPartition from xmodule.tests import DATA_DIR from xmodule.x_module import XModuleMixin -from xmodule.partitions.partitions import UserPartition - -from search.search_engine_base import SearchEngine - -from contentstore.courseware_index import ( - CoursewareSearchIndexer, - LibrarySearchIndexer, - SearchIndexingError, - CourseAboutSearchIndexer, -) -from contentstore.signals.handlers import listen_for_course_publish, listen_for_library_update -from contentstore.utils import reverse_course_url, reverse_usage_url -from contentstore.tests.utils import CourseTestCase COURSE_CHILD_STRUCTURE = { "course": "chapter", diff --git a/cms/djangoapps/contentstore/tests/test_crud.py b/cms/djangoapps/contentstore/tests/test_crud.py index 4153646f97..4626c06b40 100644 --- a/cms/djangoapps/contentstore/tests/test_crud.py +++ b/cms/djangoapps/contentstore/tests/test_crud.py @@ -1,12 +1,12 @@ from xmodule import templates -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, TEST_DATA_SPLIT_MODULESTORE -from xmodule.course_module import CourseDescriptor -from xmodule.seq_module import SequenceDescriptor from xmodule.capa_module import CapaDescriptor +from xmodule.course_module import CourseDescriptor from xmodule.html_module import HtmlDescriptor +from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.exceptions import DuplicateCourseError +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from xmodule.seq_module import SequenceDescriptor class TemplateTests(ModuleStoreTestCase): diff --git a/cms/djangoapps/contentstore/tests/test_export_git.py b/cms/djangoapps/contentstore/tests/test_export_git.py index 7054b6b439..29d9276c45 100644 --- a/cms/djangoapps/contentstore/tests/test_export_git.py +++ b/cms/djangoapps/contentstore/tests/test_export_git.py @@ -11,10 +11,11 @@ from uuid import uuid4 from django.conf import settings from django.test.utils import override_settings -from .utils import CourseTestCase import contentstore.git_export_utils as git_export_utils -from xmodule.modulestore.django import modulestore from contentstore.utils import reverse_course_url +from xmodule.modulestore.django import modulestore + +from .utils import CourseTestCase TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex diff --git a/cms/djangoapps/contentstore/tests/test_gating.py b/cms/djangoapps/contentstore/tests/test_gating.py index 202798e8ca..b488cd31d8 100644 --- a/cms/djangoapps/contentstore/tests/test_gating.py +++ b/cms/djangoapps/contentstore/tests/test_gating.py @@ -1,12 +1,13 @@ """ Unit tests for the gating feature in Studio """ -from contentstore.signals.handlers import handle_item_deleted from milestones.tests.utils import MilestonesTestCaseMixin from mock import patch + +from contentstore.signals.handlers import handle_item_deleted from openedx.core.lib.gating import api as gating_api from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory class TestHandleItemDeleted(ModuleStoreTestCase, MilestonesTestCaseMixin): diff --git a/cms/djangoapps/contentstore/tests/test_i18n.py b/cms/djangoapps/contentstore/tests/test_i18n.py index 82e568cb40..b33a4f7148 100644 --- a/cms/djangoapps/contentstore/tests/test_i18n.py +++ b/cms/djangoapps/contentstore/tests/test_i18n.py @@ -1,17 +1,19 @@ """ Tests for validate Internationalization and Module i18n service. """ -import mock import gettext from unittest import skip + +import mock from django.contrib.auth.models import User -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from contentstore.tests.utils import AjaxEnabledTestClient -from xmodule.modulestore.django import ModuleI18nService from django.utils import translation from django.utils.translation import get_language -from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory + +from contentstore.tests.utils import AjaxEnabledTestClient from contentstore.views.preview import _preview_module_system +from xmodule.modulestore.django import ModuleI18nService +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory class FakeTranslations(ModuleI18nService): diff --git a/cms/djangoapps/contentstore/tests/test_import.py b/cms/djangoapps/contentstore/tests/test_import.py index 6b271d7c82..005a59ddd5 100644 --- a/cms/djangoapps/contentstore/tests/test_import.py +++ b/cms/djangoapps/contentstore/tests/test_import.py @@ -4,22 +4,23 @@ Tests for import_course_from_xml using the mongo modulestore. """ +import copy +from uuid import uuid4 + +import ddt +from django.conf import settings from django.test.client import Client from django.test.utils import override_settings -from django.conf import settings -import ddt -import copy from mock import patch from openedx.core.djangoapps.content.course_structures.tests import SignalDisconnectTestMixin -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.contentstore.django import contentstore +from xmodule.exceptions import NotFoundError from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore -from xmodule.contentstore.django import contentstore +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import check_exact_number_of_calls, check_number_of_calls from xmodule.modulestore.xml_importer import import_course_from_xml -from xmodule.exceptions import NotFoundError -from uuid import uuid4 TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex diff --git a/cms/djangoapps/contentstore/tests/test_import_draft_order.py b/cms/djangoapps/contentstore/tests/test_import_draft_order.py index eaf9f676f3..68d6488cf9 100644 --- a/cms/djangoapps/contentstore/tests/test_import_draft_order.py +++ b/cms/djangoapps/contentstore/tests/test_import_draft_order.py @@ -1,12 +1,12 @@ """ Tests Draft import order. """ -from xmodule.modulestore.xml_importer import import_course_from_xml - -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.django import modulestore from django.conf import settings +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.xml_importer import import_course_from_xml + TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT diff --git a/cms/djangoapps/contentstore/tests/test_import_pure_xblock.py b/cms/djangoapps/contentstore/tests/test_import_pure_xblock.py index fe4fb57f85..05d2079fd3 100644 --- a/cms/djangoapps/contentstore/tests/test_import_pure_xblock.py +++ b/cms/djangoapps/contentstore/tests/test_import_pure_xblock.py @@ -2,15 +2,15 @@ Integration tests for importing courses containing pure XBlocks. """ +from django.conf import settings from xblock.core import XBlock from xblock.fields import String -from xmodule.modulestore.django import modulestore from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.xml_importer import import_course_from_xml -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.django import modulestore from xmodule.modulestore.mongo.draft import as_draft -from django.conf import settings +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.xml_importer import import_course_from_xml TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT diff --git a/cms/djangoapps/contentstore/tests/test_libraries.py b/cms/djangoapps/contentstore/tests/test_libraries.py index cf8f113a0d..455f562f7a 100644 --- a/cms/djangoapps/contentstore/tests/test_libraries.py +++ b/cms/djangoapps/contentstore/tests/test_libraries.py @@ -1,31 +1,35 @@ """ Content library unit tests that require the CMS runtime. """ +import ddt from django.test.utils import override_settings +from mock import Mock, patch +from opaque_keys.edx.locator import CourseKey, LibraryLocator + from contentstore.tests.utils import AjaxEnabledTestClient, parse_json -from contentstore.utils import reverse_url, reverse_usage_url, reverse_library_url +from contentstore.utils import reverse_library_url, reverse_url, reverse_usage_url from contentstore.views.item import _duplicate_item from contentstore.views.preview import _load_preview_module from contentstore.views.tests.test_library import LIBRARY_REST_URL -import ddt -from mock import patch +from course_creators.views import add_user_with_status_granted +from openedx.core.djangoapps.content.course_structures.tests import SignalDisconnectTestMixin +from student import auth from student.auth import has_studio_read_access, has_studio_write_access from student.roles import ( - CourseInstructorRole, CourseStaffRole, LibraryUserRole, - OrgStaffRole, OrgInstructorRole, OrgLibraryUserRole, + CourseInstructorRole, + CourseStaffRole, + LibraryUserRole, + OrgInstructorRole, + OrgLibraryUserRole, + OrgStaffRole ) +from student.tests.factories import UserFactory +from xblock_django.user_service import DjangoXBlockUserService from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory -from mock import Mock -from opaque_keys.edx.locator import CourseKey, LibraryLocator -from openedx.core.djangoapps.content.course_structures.tests import SignalDisconnectTestMixin -from xblock_django.user_service import DjangoXBlockUserService from xmodule.x_module import STUDIO_VIEW -from student import auth -from student.tests.factories import UserFactory -from course_creators.views import add_user_with_status_granted class LibraryTestCase(ModuleStoreTestCase): diff --git a/cms/djangoapps/contentstore/tests/test_orphan.py b/cms/djangoapps/contentstore/tests/test_orphan.py index f48d47aa50..52c6bd80b5 100644 --- a/cms/djangoapps/contentstore/tests/test_orphan.py +++ b/cms/djangoapps/contentstore/tests/test_orphan.py @@ -2,11 +2,12 @@ Test finding orphans via the view and django config """ import json + import ddt +from opaque_keys.edx.locator import BlockUsageLocator from contentstore.tests.utils import CourseTestCase from contentstore.utils import reverse_course_url -from opaque_keys.edx.locator import BlockUsageLocator from student.models import CourseEnrollment from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.search import path_to_location diff --git a/cms/djangoapps/contentstore/tests/test_permissions.py b/cms/djangoapps/contentstore/tests/test_permissions.py index 7fb8509c39..138034c4ff 100644 --- a/cms/djangoapps/contentstore/tests/test_permissions.py +++ b/cms/djangoapps/contentstore/tests/test_permissions.py @@ -5,11 +5,11 @@ import copy from django.contrib.auth.models import User -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from contentstore.tests.utils import AjaxEnabledTestClient -from contentstore.utils import reverse_url, reverse_course_url -from student.roles import CourseInstructorRole, CourseStaffRole, OrgStaffRole, OrgInstructorRole +from contentstore.utils import reverse_course_url, reverse_url from student import auth +from student.roles import CourseInstructorRole, CourseStaffRole, OrgInstructorRole, OrgStaffRole +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase class TestCourseAccess(ModuleStoreTestCase): diff --git a/cms/djangoapps/contentstore/tests/test_proctoring.py b/cms/djangoapps/contentstore/tests/test_proctoring.py index b0514b2cea..b497874459 100644 --- a/cms/djangoapps/contentstore/tests/test_proctoring.py +++ b/cms/djangoapps/contentstore/tests/test_proctoring.py @@ -2,19 +2,16 @@ Tests for the edx_proctoring integration into Studio """ -from mock import patch -import ddt from datetime import datetime, timedelta + +import ddt +from edx_proctoring.api import get_all_exams_for_course, get_review_policy_by_exam_id +from mock import patch from pytz import UTC -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from contentstore.signals.handlers import listen_for_course_publish - -from edx_proctoring.api import ( - get_all_exams_for_course, - get_review_policy_by_exam_id -) +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory @ddt.ddt diff --git a/cms/djangoapps/contentstore/tests/test_request_event.py b/cms/djangoapps/contentstore/tests/test_request_event.py index 166187ee58..529fe4abb2 100644 --- a/cms/djangoapps/contentstore/tests/test_request_event.py +++ b/cms/djangoapps/contentstore/tests/test_request_event.py @@ -1,8 +1,8 @@ """Tests for CMS's requests to logs""" import mock - -from django.test import TestCase from django.core.urlresolvers import reverse +from django.test import TestCase + from contentstore.views.helpers import event as cms_user_track diff --git a/cms/djangoapps/contentstore/tests/test_tasks.py b/cms/djangoapps/contentstore/tests/test_tasks.py index f2c7cd7056..9b732b28c7 100644 --- a/cms/djangoapps/contentstore/tests/test_tasks.py +++ b/cms/djangoapps/contentstore/tests/test_tasks.py @@ -15,13 +15,13 @@ from opaque_keys.edx.locator import CourseLocator from organizations.models import OrganizationCourse from organizations.tests.factories import OrganizationFactory from user_tasks.models import UserTaskArtifact, UserTaskStatus -from xmodule.modulestore.django import modulestore from contentstore.tasks import export_olx, rerun_course from contentstore.tests.test_libraries import LibraryTestCase from contentstore.tests.utils import CourseTestCase from course_action_state.models import CourseRerunState -from openedx.core.djangoapps.embargo.models import RestrictedCourse, CountryAccessRule, Country +from openedx.core.djangoapps.embargo.models import Country, CountryAccessRule, RestrictedCourse +from xmodule.modulestore.django import modulestore TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex diff --git a/cms/djangoapps/contentstore/tests/test_transcripts_utils.py b/cms/djangoapps/contentstore/tests/test_transcripts_utils.py index 61ae89702d..c7658f411e 100644 --- a/cms/djangoapps/contentstore/tests/test_transcripts_utils.py +++ b/cms/djangoapps/contentstore/tests/test_transcripts_utils.py @@ -1,24 +1,23 @@ # -*- coding: utf-8 -*- """ Tests for transcripts_utils. """ -import unittest -from uuid import uuid4 import copy import textwrap -from mock import patch, Mock +import unittest +from uuid import uuid4 -from django.test.utils import override_settings from django.conf import settings +from django.test.utils import override_settings from django.utils import translation - +from mock import Mock, patch from nose.plugins.skip import SkipTest -from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.contentstore.content import StaticContent -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.exceptions import NotFoundError -from xmodule.contentstore.django import contentstore -from xmodule.video_module import transcripts_utils from contentstore.tests.utils import mock_requests_get +from xmodule.contentstore.content import StaticContent +from xmodule.contentstore.django import contentstore +from xmodule.exceptions import NotFoundError +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory +from xmodule.video_module import transcripts_utils TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex diff --git a/cms/djangoapps/contentstore/tests/test_users_default_role.py b/cms/djangoapps/contentstore/tests/test_users_default_role.py index 326b7cf155..0817195525 100644 --- a/cms/djangoapps/contentstore/tests/test_users_default_role.py +++ b/cms/djangoapps/contentstore/tests/test_users_default_role.py @@ -5,9 +5,8 @@ after deleting it creates same course again from contentstore.tests.utils import AjaxEnabledTestClient from contentstore.utils import delete_course_and_groups, reverse_url from courseware.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase - from student.models import CourseEnrollment +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase class TestUsersDefaultRole(ModuleStoreTestCase): diff --git a/cms/djangoapps/contentstore/tests/test_utils.py b/cms/djangoapps/contentstore/tests/test_utils.py index f73447e4b2..6e84ea9681 100644 --- a/cms/djangoapps/contentstore/tests/test_utils.py +++ b/cms/djangoapps/contentstore/tests/test_utils.py @@ -2,19 +2,18 @@ import collections from datetime import datetime, timedelta -from pytz import UTC from django.test import TestCase -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase from opaque_keys.edx.locations import SlashSeparatedCourseKey -from xmodule.modulestore.django import modulestore -from xmodule.partitions.partitions import UserPartition, Group - -from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration_context +from pytz import UTC from contentstore import utils from contentstore.tests.utils import CourseTestCase +from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration_context +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from xmodule.partitions.partitions import Group, UserPartition class LMSLinksTestCase(TestCase): diff --git a/cms/djangoapps/contentstore/tests/tests.py b/cms/djangoapps/contentstore/tests/tests.py index 69400a008a..3e78b40b56 100644 --- a/cms/djangoapps/contentstore/tests/tests.py +++ b/cms/djangoapps/contentstore/tests/tests.py @@ -1,27 +1,26 @@ """ This test file will test registration, login, activation, and session activity timeouts """ +import datetime import time -import mock import unittest -from ddt import ddt, data, unpack -from django.test import TestCase -from django.test.utils import override_settings -from django.core.cache import cache +import mock +from ddt import data, ddt, unpack from django.conf import settings from django.contrib.auth.models import User +from django.core.cache import cache from django.core.urlresolvers import reverse +from django.test import TestCase +from django.test.utils import override_settings +from freezegun import freeze_time +from pytz import UTC from contentstore.models import PushNotificationConfig from contentstore.tests.test_course_settings import CourseTestCase -from contentstore.tests.utils import parse_json, user, registration, AjaxEnabledTestClient +from contentstore.tests.utils import AjaxEnabledTestClient, parse_json, registration, user from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -import datetime -from pytz import UTC - -from freezegun import freeze_time class ContentStoreTestCase(ModuleStoreTestCase): diff --git a/cms/djangoapps/contentstore/tests/utils.py b/cms/djangoapps/contentstore/tests/utils.py index af5e7b8e52..0c62bddbc9 100644 --- a/cms/djangoapps/contentstore/tests/utils.py +++ b/cms/djangoapps/contentstore/tests/utils.py @@ -3,23 +3,23 @@ Utilities for contentstore tests ''' import json import textwrap -from mock import Mock from django.conf import settings from django.contrib.auth.models import User from django.test.client import Client -from opaque_keys.edx.locations import SlashSeparatedCourseKey, AssetLocation +from mock import Mock +from opaque_keys.edx.locations import AssetLocation, SlashSeparatedCourseKey from contentstore.utils import reverse_url from student.models import Registration -from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore from xmodule.contentstore.django import contentstore from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.inheritance import own_metadata +from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.xml_importer import import_course_from_xml from xmodule.modulestore.tests.utils import ProceduralCourseTestMixin +from xmodule.modulestore.xml_importer import import_course_from_xml TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index a414f5815c..d41c313e7d 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -4,26 +4,24 @@ Common utility functions useful throughout the contentstore import logging from datetime import datetime -from pytz import UTC from django.conf import settings from django.core.urlresolvers import reverse from django.utils.translation import ugettext as _ +from opaque_keys.edx.keys import CourseKey, UsageKey +from pytz import UTC + from django_comment_common.models import assign_default_role from django_comment_common.utils import seed_permissions_roles - from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration from openedx.core.djangoapps.site_configuration.models import SiteConfiguration -from xmodule.partitions.partitions_service import get_all_partitions_for_course - +from student import auth +from student.models import CourseEnrollment +from student.roles import CourseInstructorRole, CourseStaffRole from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError -from opaque_keys.edx.keys import UsageKey, CourseKey -from student.roles import CourseInstructorRole, CourseStaffRole -from student.models import CourseEnrollment -from student import auth - +from xmodule.partitions.partitions_service import get_all_partitions_for_course log = logging.getLogger(__name__) diff --git a/cms/djangoapps/contentstore/views/access.py b/cms/djangoapps/contentstore/views/access.py index a5348c702a..50fb74e55c 100644 --- a/cms/djangoapps/contentstore/views/access.py +++ b/cms/djangoapps/contentstore/views/access.py @@ -1,7 +1,7 @@ """ Helper methods for determining user access permissions in Studio """ -from student.roles import CourseInstructorRole from student import auth +from student.roles import CourseInstructorRole def get_user_role(user, course_id): diff --git a/cms/djangoapps/contentstore/views/assets.py b/cms/djangoapps/contentstore/views/assets.py index 0d00d3129d..db72f0cdf0 100644 --- a/cms/djangoapps/contentstore/views/assets.py +++ b/cms/djangoapps/contentstore/views/assets.py @@ -1,8 +1,7 @@ -import logging -from functools import partial -import math import json -from pymongo import ASCENDING, DESCENDING +import logging +import math +from functools import partial from django.conf import settings from django.contrib.auth.decorators import login_required @@ -11,11 +10,12 @@ from django.http import HttpResponseBadRequest, HttpResponseNotFound from django.utils.translation import ugettext as _ from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.http import require_http_methods, require_POST +from opaque_keys.edx.keys import AssetKey, CourseKey +from pymongo import ASCENDING, DESCENDING -from edxmako.shortcuts import render_to_response from contentstore.utils import reverse_course_url from contentstore.views.exception import AssetNotFoundException -from opaque_keys.edx.keys import CourseKey, AssetKey +from edxmako.shortcuts import render_to_response from openedx.core.djangoapps.contentserver.caching import del_cached_content from student.auth import has_course_author_access from util.date_utils import get_default_time_display diff --git a/cms/djangoapps/contentstore/views/certificates.py b/cms/djangoapps/contentstore/views/certificates.py index 020f08e4c7..0350d4dc7e 100644 --- a/cms/djangoapps/contentstore/views/certificates.py +++ b/cms/djangoapps/contentstore/views/certificates.py @@ -26,27 +26,26 @@ import logging from django.conf import settings from django.contrib.auth.decorators import login_required -from django.views.decorators.csrf import ensure_csrf_cookie +from django.core.exceptions import PermissionDenied from django.http import HttpResponse from django.utils.translation import ugettext as _ +from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.http import require_http_methods - -from contentstore.utils import reverse_course_url -from edxmako.shortcuts import render_to_response -from opaque_keys.edx.keys import CourseKey, AssetKey from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import AssetKey, CourseKey + +from contentstore.utils import get_lms_link_for_certificate_web_view, reverse_course_url +from contentstore.views.assets import delete_asset +from contentstore.views.exception import AssetNotFoundException +from course_modes.models import CourseMode +from edxmako.shortcuts import render_to_response from eventtracking import tracker from student.auth import has_studio_write_access from student.roles import GlobalStaff -from util.db import generate_int_id, MYSQL_MAX_INT +from util.db import MYSQL_MAX_INT, generate_int_id from util.json_request import JsonResponse from xmodule.modulestore import EdxJSONEncoder from xmodule.modulestore.django import modulestore -from contentstore.views.assets import delete_asset -from contentstore.views.exception import AssetNotFoundException -from django.core.exceptions import PermissionDenied -from course_modes.models import CourseMode -from contentstore.utils import get_lms_link_for_certificate_web_view CERTIFICATE_SCHEMA_VERSION = 1 CERTIFICATE_MINIMUM_ID = 100 diff --git a/cms/djangoapps/contentstore/views/component.py b/cms/djangoapps/contentstore/views/component.py index 0afd654db2..48d5011593 100644 --- a/cms/djangoapps/contentstore/views/component.py +++ b/cms/djangoapps/contentstore/views/component.py @@ -2,36 +2,30 @@ from __future__ import absolute_import import logging -from django.http import HttpResponseBadRequest, Http404 -from django.contrib.auth.decorators import login_required -from django.views.decorators.http import require_GET -from django.core.exceptions import PermissionDenied from django.conf import settings +from django.contrib.auth.decorators import login_required +from django.core.exceptions import PermissionDenied +from django.http import Http404, HttpResponseBadRequest +from django.utils.translation import ugettext as _ +from django.views.decorators.http import require_GET from opaque_keys import InvalidKeyError from opaque_keys.edx.asides import AsideUsageKeyV1, AsideUsageKeyV2 -from xmodule.modulestore.exceptions import ItemNotFoundError -from edxmako.shortcuts import render_to_response - -from xmodule.modulestore.django import modulestore - +from opaque_keys.edx.keys import UsageKey from xblock.core import XBlock -from xblock.django.request import webob_to_django_response, django_to_webob_request +from xblock.django.request import django_to_webob_request, webob_to_django_response from xblock.exceptions import NoSuchHandlerError from xblock.plugin import PluginMissingError from xblock.runtime import Mixologist -from contentstore.utils import get_lms_link_for_item, reverse_course_url, get_xblock_aside_instance +from contentstore.utils import get_lms_link_for_item, get_xblock_aside_instance, reverse_course_url from contentstore.views.helpers import get_parent_xblock, is_unit, xblock_type_display_name -from contentstore.views.item import create_xblock_info, add_container_page_publishing_info, StudioEditModuleRuntime - -from opaque_keys.edx.keys import UsageKey - +from contentstore.views.item import StudioEditModuleRuntime, add_container_page_publishing_info, create_xblock_info +from edxmako.shortcuts import render_to_response from student.auth import has_course_author_access -from django.utils.translation import ugettext as _ - -from xblock_django.api import disabled_xblocks, authorable_xblocks +from xblock_django.api import authorable_xblocks, disabled_xblocks from xblock_django.models import XBlockStudioConfigurationFlag - +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.exceptions import ItemNotFoundError __all__ = [ 'container_handler', diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index 35d8ef367c..cd22160bec 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -7,75 +7,63 @@ import logging import random import string # pylint: disable=deprecated-module +import django.utils +import six +from ccx_keys.locator import CCXLocator from django.conf import settings from django.contrib.auth.decorators import login_required from django.core.exceptions import PermissionDenied from django.core.urlresolvers import reverse -from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotFound, Http404 +from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseNotFound from django.shortcuts import redirect -import django.utils from django.utils.translation import ugettext as _ -from django.views.decorators.http import require_http_methods, require_GET from django.views.decorators.csrf import ensure_csrf_cookie -import six - +from django.views.decorators.http import require_GET, require_http_methods from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locations import Location -from .component import ( - ADVANCED_COMPONENT_TYPES, -) -from .item import create_xblock_info -from .library import LIBRARIES_ENABLED, get_library_creator_status -from ccx_keys.locator import CCXLocator from contentstore.course_group_config import ( COHORT_SCHEME, ENROLLMENT_SCHEME, - GroupConfiguration, - GroupConfigurationsValidationError, RANDOM_SCHEME, + GroupConfiguration, + GroupConfigurationsValidationError ) -from contentstore.course_info_model import get_course_updates, update_course_updates, delete_course_update +from contentstore.course_info_model import delete_course_update, get_course_updates, update_course_updates from contentstore.courseware_index import CoursewareSearchIndexer, SearchIndexingError from contentstore.push_notification import push_notification_enabled from contentstore.tasks import rerun_course from contentstore.utils import ( add_instructor, - initialize_permissions, get_lms_link_for_item, + initialize_permissions, remove_all_instructors, reverse_course_url, reverse_library_url, - reverse_usage_url, reverse_url, + reverse_usage_url ) -from contentstore.views.entrance_exam import ( - create_entrance_exam, - delete_entrance_exam, - update_entrance_exam, -) +from contentstore.views.entrance_exam import create_entrance_exam, delete_entrance_exam, update_entrance_exam from course_action_state.managers import CourseActionStateItemNotFoundError from course_action_state.models import CourseRerunState, CourseRerunUIStateManager -from course_creators.views import get_course_creator_status, add_user_with_status_unrequested +from course_creators.views import add_user_with_status_unrequested, get_course_creator_status from edxmako.shortcuts import render_to_response from models.settings.course_grading import CourseGradingModel from models.settings.course_metadata import CourseMetadata from models.settings.encoder import CourseSettingsEncoder from openedx.core.djangoapps.content.course_structures.api.v0 import api, errors -from openedx.core.djangoapps.credit.api import is_credit_course, get_credit_requirements +from openedx.core.djangoapps.credit.api import get_credit_requirements, is_credit_course from openedx.core.djangoapps.credit.tasks import update_credit_course_requirements from openedx.core.djangoapps.models.course_details import CourseDetails from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.djangolib.js_utils import dump_js_escaped_json from openedx.core.lib.course_tabs import CourseTabPluginManager from openedx.core.lib.courses import course_image_url -from openedx.core.djangolib.js_utils import dump_js_escaped_json from student import auth -from student.auth import has_course_author_access, has_studio_write_access, has_studio_read_access -from student.roles import ( - CourseInstructorRole, CourseStaffRole, CourseCreatorRole, GlobalStaff, UserBasedRole -) +from student.auth import has_course_author_access, has_studio_read_access, has_studio_write_access +from student.roles import CourseCreatorRole, CourseInstructorRole, CourseStaffRole, GlobalStaff, UserBasedRole from util.course import get_link_for_about_page from util.date_utils import get_default_time_display from util.json_request import JsonResponse, JsonResponseBadRequest, expect_json @@ -83,24 +71,23 @@ from util.milestones_helpers import ( is_entrance_exams_enabled, is_prerequisite_courses_enabled, is_valid_course_key, - set_prerequisite_courses, -) -from util.organizations_helpers import ( - add_organization_course, - get_organization_by_short_name, - organizations_enabled, + set_prerequisite_courses ) +from util.organizations_helpers import add_organization_course, get_organization_by_short_name, organizations_enabled from util.string_utils import _has_non_ascii_characters from xblock_django.api import deprecated_xblocks from xmodule.contentstore.content import StaticContent -from xmodule.course_module import CourseFields -from xmodule.course_module import DEFAULT_START_DATE +from xmodule.course_module import DEFAULT_START_DATE, CourseFields from xmodule.error_module import ErrorDescriptor from xmodule.modulestore import EdxJSONEncoder from xmodule.modulestore.django import modulestore -from xmodule.modulestore.exceptions import ItemNotFoundError, DuplicateCourseError +from xmodule.modulestore.exceptions import DuplicateCourseError, ItemNotFoundError from xmodule.tabs import CourseTab, CourseTabList, InvalidTabsException +from .component import ADVANCED_COMPONENT_TYPES +from .item import create_xblock_info +from .library import LIBRARIES_ENABLED, get_library_creator_status + log = logging.getLogger(__name__) __all__ = ['course_info_handler', 'course_handler', 'course_listing', diff --git a/cms/djangoapps/contentstore/views/entrance_exam.py b/cms/djangoapps/contentstore/views/entrance_exam.py index 9dba4ae261..493c2126bc 100644 --- a/cms/djangoapps/contentstore/views/entrance_exam.py +++ b/cms/djangoapps/contentstore/views/entrance_exam.py @@ -2,25 +2,25 @@ Entrance Exams view module -- handles all requests related to entrance exam management via Studio Intended to be utilized as an AJAX callback handler, versus a proper view/screen """ -from functools import wraps import logging +from functools import wraps +from django.conf import settings from django.contrib.auth.decorators import login_required -from django.views.decorators.csrf import ensure_csrf_cookie from django.http import HttpResponse, HttpResponseBadRequest +from django.utils.translation import ugettext as _ +from django.views.decorators.csrf import ensure_csrf_cookie +from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey, UsageKey -from openedx.core.djangolib.js_utils import dump_js_escaped_json from contentstore.views.helpers import create_xblock, remove_entrance_exam_graders from contentstore.views.item import delete_item from models.settings.course_metadata import CourseMetadata -from opaque_keys.edx.keys import CourseKey, UsageKey -from opaque_keys import InvalidKeyError +from openedx.core.djangolib.js_utils import dump_js_escaped_json from student.auth import has_course_author_access from util import milestones_helpers from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError -from django.conf import settings -from django.utils.translation import ugettext as _ __all__ = ['entrance_exam', ] diff --git a/cms/djangoapps/contentstore/views/error.py b/cms/djangoapps/contentstore/views/error.py index 6f58ea296d..e1f1d6b21e 100644 --- a/cms/djangoapps/contentstore/views/error.py +++ b/cms/djangoapps/contentstore/views/error.py @@ -1,9 +1,10 @@ # pylint: disable=missing-docstring,unused-argument -from django.http import (HttpResponse, HttpResponseServerError, - HttpResponseNotFound) -from edxmako.shortcuts import render_to_string, render_to_response import functools + +from django.http import HttpResponse, HttpResponseNotFound, HttpResponseServerError + +from edxmako.shortcuts import render_to_response, render_to_string from openedx.core.djangolib.js_utils import dump_js_escaped_json __all__ = ['not_found', 'server_error', 'render_404', 'render_500'] diff --git a/cms/djangoapps/contentstore/views/export_git.py b/cms/djangoapps/contentstore/views/export_git.py index bb1f1d4c0e..f562640591 100644 --- a/cms/djangoapps/contentstore/views/export_git.py +++ b/cms/djangoapps/contentstore/views/export_git.py @@ -7,14 +7,14 @@ import logging from django.contrib.auth.decorators import login_required from django.core.exceptions import PermissionDenied -from django.views.decorators.csrf import ensure_csrf_cookie from django.utils.translation import ugettext as _ +from django.views.decorators.csrf import ensure_csrf_cookie +from opaque_keys.edx.keys import CourseKey -from student.auth import has_course_author_access import contentstore.git_export_utils as git_export_utils from edxmako.shortcuts import render_to_response +from student.auth import has_course_author_access from xmodule.modulestore.django import modulestore -from opaque_keys.edx.keys import CourseKey log = logging.getLogger(__name__) diff --git a/cms/djangoapps/contentstore/views/helpers.py b/cms/djangoapps/contentstore/views/helpers.py index 29e571c5b6..29e0f0bc6b 100644 --- a/cms/djangoapps/contentstore/views/helpers.py +++ b/cms/djangoapps/contentstore/views/helpers.py @@ -4,24 +4,23 @@ Helper methods for Studio views. from __future__ import absolute_import -from uuid import uuid4 import urllib +from uuid import uuid4 from django.conf import settings from django.http import HttpResponse from django.utils.translation import ugettext as _ - -from edxmako.shortcuts import render_to_string from opaque_keys.edx.keys import UsageKey from xblock.core import XBlock -import dogstats_wrapper as dog_stats_api -from xmodule.modulestore.django import modulestore -from xmodule.x_module import DEPRECATION_VSCOMPAT_EVENT -from xmodule.tabs import StaticTab +import dogstats_wrapper as dog_stats_api from contentstore.utils import reverse_course_url, reverse_library_url, reverse_usage_url +from edxmako.shortcuts import render_to_string from models.settings.course_grading import CourseGradingModel from util.milestones_helpers import is_entrance_exams_enabled +from xmodule.modulestore.django import modulestore +from xmodule.tabs import StaticTab +from xmodule.x_module import DEPRECATION_VSCOMPAT_EVENT __all__ = ['event'] diff --git a/cms/djangoapps/contentstore/views/import_export.py b/cms/djangoapps/contentstore/views/import_export.py index 9f7e212c3e..b5cd0f4552 100644 --- a/cms/djangoapps/contentstore/views/import_export.py +++ b/cms/djangoapps/contentstore/views/import_export.py @@ -8,9 +8,6 @@ import logging import os import re import shutil -from path import Path as path - -from six import text_type from django.conf import settings from django.contrib.auth.decorators import login_required @@ -18,28 +15,26 @@ from django.core.exceptions import PermissionDenied from django.core.files import File from django.core.servers.basehttp import FileWrapper from django.db import transaction -from django.http import HttpResponse, HttpResponseNotFound, Http404 +from django.http import Http404, HttpResponse, HttpResponseNotFound from django.utils.translation import ugettext as _ from django.views.decorators.csrf import ensure_csrf_cookie -from django.views.decorators.http import require_http_methods, require_GET - -from edxmako.shortcuts import render_to_response -from xmodule.exceptions import SerializationError -from xmodule.modulestore.django import modulestore +from django.views.decorators.http import require_GET, require_http_methods from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import LibraryLocator +from path import Path as path +from six import text_type from user_tasks.conf import settings as user_tasks_settings from user_tasks.models import UserTaskArtifact, UserTaskStatus -from student.auth import has_course_author_access - -from util.json_request import JsonResponse -from util.views import ensure_valid_course_key from contentstore.storage import course_import_export_storage from contentstore.tasks import CourseExportTask, CourseImportTask, create_export_tarball, export_olx, import_olx - from contentstore.utils import reverse_course_url, reverse_library_url - +from edxmako.shortcuts import render_to_response +from student.auth import has_course_author_access +from util.json_request import JsonResponse +from util.views import ensure_valid_course_key +from xmodule.exceptions import SerializationError +from xmodule.modulestore.django import modulestore __all__ = [ 'import_handler', 'import_status_handler', diff --git a/cms/djangoapps/contentstore/views/item.py b/cms/djangoapps/contentstore/views/item.py index e6510be15a..b4452f6f98 100644 --- a/cms/djangoapps/contentstore/views/item.py +++ b/cms/djangoapps/contentstore/views/item.py @@ -8,55 +8,62 @@ from datetime import datetime from functools import partial from uuid import uuid4 -import dogstats_wrapper as dog_stats_api from django.conf import settings from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from django.core.exceptions import PermissionDenied -from django.http import HttpResponseBadRequest, HttpResponse, Http404 +from django.http import Http404, HttpResponse, HttpResponseBadRequest from django.utils.translation import ugettext as _ from django.views.decorators.http import require_http_methods from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import LibraryUsageLocator from pytz import UTC - from xblock.core import XBlock from xblock.fields import Scope from xblock.fragment import Fragment -from xblock_config.models import CourseEditLTIFieldsEnabledFlag -from xblock_django.user_service import DjangoXBlockUserService - +import dogstats_wrapper as dog_stats_api from cms.lib.xblock.authoring_mixin import VISIBILITY_VIEW from contentstore.utils import ( - find_release_date_source, find_staff_lock_source, is_currently_visible_to_students, - ancestor_has_staff_lock, has_children_visible_to_specific_partition_groups, - get_user_partition_info, get_split_group_display_name, + ancestor_has_staff_lock, + find_release_date_source, + find_staff_lock_source, + get_split_group_display_name, + get_user_partition_info, + has_children_visible_to_specific_partition_groups, + is_currently_visible_to_students, + is_self_paced +) +from contentstore.views.helpers import ( + create_xblock, + get_parent_xblock, + is_unit, + usage_key_with_run, + xblock_primary_child_category, + xblock_studio_url, + xblock_type_display_name ) -from contentstore.views.helpers import is_unit, xblock_studio_url, xblock_primary_child_category, \ - xblock_type_display_name, get_parent_xblock, create_xblock, usage_key_with_run from contentstore.views.preview import get_preview_fragment -from contentstore.utils import is_self_paced - -from openedx.core.lib.gating import api as gating_api from edxmako.shortcuts import render_to_string from models.settings.course_grading import CourseGradingModel -from openedx.core.lib.xblock_utils import wrap_xblock, request_token +from openedx.core.lib.gating import api as gating_api +from openedx.core.lib.xblock_utils import request_token, wrap_xblock from static_replace import replace_static_urls -from student.auth import has_studio_write_access, has_studio_read_access +from student.auth import has_studio_read_access, has_studio_write_access from util.date_utils import get_default_time_display -from util.json_request import expect_json, JsonResponse +from util.json_request import JsonResponse, expect_json from util.milestones_helpers import is_entrance_exams_enabled +from xblock_config.models import CourseEditLTIFieldsEnabledFlag +from xblock_django.user_service import DjangoXBlockUserService from xmodule.course_module import DEFAULT_START_DATE -from xmodule.modulestore import ModuleStoreEnum, EdxJSONEncoder +from xmodule.modulestore import EdxJSONEncoder, ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.draft_and_published import DIRECT_ONLY_CATEGORIES -from xmodule.modulestore.exceptions import ItemNotFoundError, InvalidLocationError +from xmodule.modulestore.exceptions import InvalidLocationError, ItemNotFoundError from xmodule.modulestore.inheritance import own_metadata from xmodule.services import ConfigurationService, SettingsService from xmodule.tabs import CourseTabList -from xmodule.x_module import PREVIEW_VIEWS, STUDIO_VIEW, STUDENT_VIEW, DEPRECATION_VSCOMPAT_EVENT - +from xmodule.x_module import DEPRECATION_VSCOMPAT_EVENT, PREVIEW_VIEWS, STUDENT_VIEW, STUDIO_VIEW __all__ = [ 'orphan_handler', 'xblock_handler', 'xblock_view_handler', 'xblock_outline_handler', 'xblock_container_handler' diff --git a/cms/djangoapps/contentstore/views/library.py b/cms/djangoapps/contentstore/views/library.py index 7a642d474a..bce8079f62 100644 --- a/cms/djangoapps/contentstore/views/library.py +++ b/cms/djangoapps/contentstore/views/library.py @@ -7,31 +7,36 @@ from __future__ import absolute_import import logging -from contentstore.views.item import create_xblock_info -from contentstore.utils import reverse_library_url, add_instructor -from django.http import HttpResponseNotAllowed, Http404, HttpResponseForbidden +from django.conf import settings from django.contrib.auth.decorators import login_required from django.core.exceptions import PermissionDenied -from django.conf import settings +from django.http import Http404, HttpResponseForbidden, HttpResponseNotAllowed from django.utils.translation import ugettext as _ -from django.views.decorators.http import require_http_methods from django.views.decorators.csrf import ensure_csrf_cookie -from edxmako.shortcuts import render_to_response +from django.views.decorators.http import require_http_methods from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import LibraryLocator, LibraryUsageLocator -from xmodule.modulestore.exceptions import DuplicateCourseError -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.django import modulestore -from .user import user_with_role +from contentstore.utils import add_instructor, reverse_library_url +from contentstore.views.item import create_xblock_info from course_creators.views import get_course_creator_status -from .component import get_component_templates, CONTAINER_TEMPLATES +from edxmako.shortcuts import render_to_response from student.auth import ( - STUDIO_VIEW_USERS, STUDIO_EDIT_ROLES, get_user_permissions, has_studio_read_access, has_studio_write_access + STUDIO_EDIT_ROLES, + STUDIO_VIEW_USERS, + get_user_permissions, + has_studio_read_access, + has_studio_write_access ) from student.roles import CourseInstructorRole, CourseStaffRole, LibraryUserRole -from util.json_request import expect_json, JsonResponse, JsonResponseBadRequest +from util.json_request import JsonResponse, JsonResponseBadRequest, expect_json +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.exceptions import DuplicateCourseError + +from .component import CONTAINER_TEMPLATES, get_component_templates +from .user import user_with_role __all__ = ['library_handler', 'manage_library_users'] diff --git a/cms/djangoapps/contentstore/views/organization.py b/cms/djangoapps/contentstore/views/organization.py index 6c530dfe4f..253229963a 100644 --- a/cms/djangoapps/contentstore/views/organization.py +++ b/cms/djangoapps/contentstore/views/organization.py @@ -1,8 +1,8 @@ """Organizations views for use with Studio.""" from django.contrib.auth.decorators import login_required +from django.http import HttpResponse from django.utils.decorators import method_decorator from django.views.generic import View -from django.http import HttpResponse from openedx.core.djangolib.js_utils import dump_js_escaped_json from util.organizations_helpers import get_organizations diff --git a/cms/djangoapps/contentstore/views/preview.py b/cms/djangoapps/contentstore/views/preview.py index 1b8b08c225..351cd91636 100644 --- a/cms/djangoapps/contentstore/views/preview.py +++ b/cms/djangoapps/contentstore/views/preview.py @@ -4,44 +4,45 @@ import logging from functools import partial from django.conf import settings +from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse from django.http import Http404, HttpResponseBadRequest -from django.contrib.auth.decorators import login_required from django.utils.translation import ugettext as _ -from edxmako.shortcuts import render_to_string +from opaque_keys.edx.keys import UsageKey +from xblock.django.request import django_to_webob_request, webob_to_django_response +from xblock.exceptions import NoSuchHandlerError +from xblock.fragment import Fragment +from xblock.runtime import KvsFieldData +import static_replace +from cms.lib.xblock.field_data import CmsFieldData +from contentstore.utils import get_visibility_partition_info +from contentstore.views.access import get_user_role +from edxmako.shortcuts import render_to_string +from lms.djangoapps.lms_xblock.field_data import LmsFieldData +from openedx.core.lib.license import wrap_with_license from openedx.core.lib.xblock_utils import ( - replace_static_urls, wrap_xblock, wrap_fragment, wrap_xblock_aside, request_token, xblock_local_resource_url, + replace_static_urls, + request_token, + wrap_fragment, + wrap_xblock, + wrap_xblock_aside, + xblock_local_resource_url ) -from xmodule.x_module import PREVIEW_VIEWS, STUDENT_VIEW, AUTHOR_VIEW +from util.sandboxing import can_execute_unsafe_code, get_python_lib_zip +from xblock_config.models import StudioConfig +from xblock_django.user_service import DjangoXBlockUserService from xmodule.contentstore.django import contentstore from xmodule.error_module import ErrorDescriptor from xmodule.exceptions import NotFoundError, ProcessingError +from xmodule.modulestore.django import ModuleI18nService, modulestore from xmodule.partitions.partitions_service import PartitionService -from xmodule.studio_editable import has_author_view from xmodule.services import SettingsService -from xmodule.modulestore.django import modulestore, ModuleI18nService -from openedx.core.lib.license import wrap_with_license -from opaque_keys.edx.keys import UsageKey -from xmodule.x_module import ModuleSystem -from xblock.runtime import KvsFieldData -from xblock.django.request import webob_to_django_response, django_to_webob_request -from xblock.exceptions import NoSuchHandlerError -from xblock.fragment import Fragment -from xblock_django.user_service import DjangoXBlockUserService +from xmodule.studio_editable import has_author_view +from xmodule.x_module import AUTHOR_VIEW, PREVIEW_VIEWS, STUDENT_VIEW, ModuleSystem -from lms.djangoapps.lms_xblock.field_data import LmsFieldData -from cms.lib.xblock.field_data import CmsFieldData - -from util.sandboxing import can_execute_unsafe_code, get_python_lib_zip - -import static_replace -from .session_kv_store import SessionKeyValueStore from .helpers import render_from_lms - -from contentstore.utils import get_visibility_partition_info -from contentstore.views.access import get_user_role -from xblock_config.models import StudioConfig +from .session_kv_store import SessionKeyValueStore __all__ = ['preview_handler'] diff --git a/cms/djangoapps/contentstore/views/public.py b/cms/djangoapps/contentstore/views/public.py index 5aeb8c88bd..e423ecc3f7 100644 --- a/cms/djangoapps/contentstore/views/public.py +++ b/cms/djangoapps/contentstore/views/public.py @@ -1,20 +1,15 @@ """ Public views """ -from django.views.decorators.csrf import ensure_csrf_cookie -from django.views.decorators.clickjacking import xframe_options_deny +from django.conf import settings from django.core.context_processors import csrf from django.core.urlresolvers import reverse from django.shortcuts import redirect -from django.conf import settings +from django.views.decorators.clickjacking import xframe_options_deny +from django.views.decorators.csrf import ensure_csrf_cookie from edxmako.shortcuts import render_to_response - -from openedx.core.djangoapps.external_auth.views import ( - ssl_login_shortcut, - ssl_get_cert_from_request, - redirect_with_get, -) +from openedx.core.djangoapps.external_auth.views import redirect_with_get, ssl_get_cert_from_request, ssl_login_shortcut from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers __all__ = ['signup', 'login_page', 'howitworks'] diff --git a/cms/djangoapps/contentstore/views/tabs.py b/cms/djangoapps/contentstore/views/tabs.py index f79d4d0721..a05f4f79d1 100644 --- a/cms/djangoapps/contentstore/views/tabs.py +++ b/cms/djangoapps/contentstore/views/tabs.py @@ -1,20 +1,19 @@ """ Views related to course tabs """ -from student.auth import has_course_author_access -from util.json_request import expect_json, JsonResponse - -from django.http import HttpResponseNotFound from django.contrib.auth.decorators import login_required from django.core.exceptions import PermissionDenied +from django.http import HttpResponseNotFound from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.http import require_http_methods +from opaque_keys.edx.keys import CourseKey, UsageKey from edxmako.shortcuts import render_to_response -from xmodule.modulestore.django import modulestore +from student.auth import has_course_author_access +from util.json_request import JsonResponse, expect_json from xmodule.modulestore import ModuleStoreEnum -from xmodule.tabs import CourseTabList, CourseTab, InvalidTabsException, StaticTab -from opaque_keys.edx.keys import CourseKey, UsageKey +from xmodule.modulestore.django import modulestore +from xmodule.tabs import CourseTab, CourseTabList, InvalidTabsException, StaticTab from ..utils import get_lms_link_for_item diff --git a/cms/djangoapps/contentstore/views/tests/test_access.py b/cms/djangoapps/contentstore/views/tests/test_access.py index c38a292ba7..235193b980 100644 --- a/cms/djangoapps/contentstore/views/tests/test_access.py +++ b/cms/djangoapps/contentstore/views/tests/test_access.py @@ -1,14 +1,14 @@ """ Tests access.py """ -from django.test import TestCase from django.contrib.auth.models import User +from django.test import TestCase +from opaque_keys.edx.locations import SlashSeparatedCourseKey +from contentstore.views.access import get_user_role +from student.auth import add_users from student.roles import CourseInstructorRole, CourseStaffRole from student.tests.factories import AdminFactory -from student.auth import add_users -from contentstore.views.access import get_user_role -from opaque_keys.edx.locations import SlashSeparatedCourseKey class RolesTest(TestCase): diff --git a/cms/djangoapps/contentstore/views/tests/test_assets.py b/cms/djangoapps/contentstore/views/tests/test_assets.py index 7848f63335..57fe05d064 100644 --- a/cms/djangoapps/contentstore/views/tests/test_assets.py +++ b/cms/djangoapps/contentstore/views/tests/test_assets.py @@ -1,29 +1,29 @@ """ Unit tests for the asset upload endpoint. """ +import json from datetime import datetime from io import BytesIO -from pytz import UTC -from PIL import Image -import json -from mock import patch + +import mock +from ddt import data, ddt from django.conf import settings +from django.test.utils import override_settings +from mock import patch +from opaque_keys.edx.locations import AssetLocation, SlashSeparatedCourseKey +from PIL import Image +from pytz import UTC from contentstore.tests.utils import CourseTestCase -from contentstore.views import assets from contentstore.utils import reverse_course_url +from contentstore.views import assets +from static_replace import replace_static_urls from xmodule.assetstore import AssetMetadata from xmodule.contentstore.content import StaticContent from xmodule.contentstore.django import contentstore -from xmodule.modulestore.django import modulestore from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore from xmodule.modulestore.xml_importer import import_course_from_xml -from django.test.utils import override_settings -from opaque_keys.edx.locations import SlashSeparatedCourseKey, AssetLocation -from static_replace import replace_static_urls -import mock -from ddt import ddt -from ddt import data TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT diff --git a/cms/djangoapps/contentstore/views/tests/test_certificates.py b/cms/djangoapps/contentstore/views/tests/test_certificates.py index 3215aaaf26..26bbc9be18 100644 --- a/cms/djangoapps/contentstore/views/tests/test_certificates.py +++ b/cms/djangoapps/contentstore/views/tests/test_certificates.py @@ -5,28 +5,24 @@ Certificates Tests. """ import itertools import json -import mock -import ddt +import ddt +import mock from django.conf import settings from django.test.utils import override_settings - from opaque_keys.edx.keys import AssetKey -from contentstore.utils import reverse_course_url -from contentstore.views.certificates import CERTIFICATE_SCHEMA_VERSION from contentstore.tests.utils import CourseTestCase -from xmodule.contentstore.django import contentstore -from xmodule.contentstore.content import StaticContent -from xmodule.exceptions import NotFoundError +from contentstore.utils import get_lms_link_for_certificate_web_view, reverse_course_url +from contentstore.views.certificates import CERTIFICATE_SCHEMA_VERSION, CertificateManager +from course_modes.tests.factories import CourseModeFactory from student.models import CourseEnrollment from student.roles import CourseInstructorRole, CourseStaffRole from student.tests.factories import UserFactory -from course_modes.tests.factories import CourseModeFactory -from contentstore.views.certificates import CertificateManager -from django.test.utils import override_settings -from contentstore.utils import get_lms_link_for_certificate_web_view from util.testing import EventTestMixin, UrlResetMixin +from xmodule.contentstore.content import StaticContent +from xmodule.contentstore.django import contentstore +from xmodule.exceptions import NotFoundError FEATURES_WITH_CERTS_ENABLED = settings.FEATURES.copy() FEATURES_WITH_CERTS_ENABLED['CERTIFICATES_HTML_VIEW'] = True diff --git a/cms/djangoapps/contentstore/views/tests/test_container_page.py b/cms/djangoapps/contentstore/views/tests/test_container_page.py index 2b8caff475..76f0c186fa 100644 --- a/cms/djangoapps/contentstore/views/tests/test_container_page.py +++ b/cms/djangoapps/contentstore/views/tests/test_container_page.py @@ -1,18 +1,18 @@ """ Unit tests for the container page. """ -import re import datetime -from pytz import UTC -from mock import patch, Mock +import re from django.http import Http404 from django.test.client import RequestFactory from django.utils import http +from mock import Mock, patch +from pytz import UTC import contentstore.views.component as views -from contentstore.views.tests.utils import StudioPageTestCase from contentstore.tests.test_libraries import LibraryTestCase +from contentstore.views.tests.utils import StudioPageTestCase from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory diff --git a/cms/djangoapps/contentstore/views/tests/test_course_index.py b/cms/djangoapps/contentstore/views/tests/test_course_index.py index 43f20ce257..83636e0e6b 100644 --- a/cms/djangoapps/contentstore/views/tests/test_course_index.py +++ b/cms/djangoapps/contentstore/views/tests/test_course_index.py @@ -1,35 +1,37 @@ """ Unit tests for getting the list of courses and the course outline. """ -import ddt -import json -import lxml import datetime +import json + +import ddt +import lxml import mock import pytz - from django.conf import settings from django.core.exceptions import PermissionDenied from django.utils.translation import ugettext as _ +from opaque_keys.edx.locator import CourseLocator +from search.api import perform_search from contentstore.courseware_index import CoursewareSearchIndexer, SearchIndexingError from contentstore.tests.utils import CourseTestCase -from contentstore.utils import reverse_course_url, reverse_library_url, add_instructor, reverse_usage_url +from contentstore.utils import add_instructor, reverse_course_url, reverse_library_url, reverse_usage_url from contentstore.views.course import ( - course_outline_initial_state, reindex_course_and_check_access, _deprecated_blocks_info + _deprecated_blocks_info, + course_outline_initial_state, + reindex_course_and_check_access ) -from contentstore.views.item import create_xblock_info, VisibilityState +from contentstore.views.item import VisibilityState, create_xblock_info from course_action_state.managers import CourseRerunUIStateManager from course_action_state.models import CourseRerunState -from opaque_keys.edx.locator import CourseLocator -from search.api import perform_search from student.auth import has_course_author_access from student.roles import LibraryUserRole from student.tests.factories import UserFactory from util.date_utils import get_default_time_display from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.modulestore.django import modulestore +from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, LibraryFactory diff --git a/cms/djangoapps/contentstore/views/tests/test_course_updates.py b/cms/djangoapps/contentstore/views/tests/test_course_updates.py index 1687941a22..1a1069f003 100644 --- a/cms/djangoapps/contentstore/views/tests/test_course_updates.py +++ b/cms/djangoapps/contentstore/views/tests/test_course_updates.py @@ -2,13 +2,14 @@ unit tests for course_info views and models. """ import json -from mock import patch + from django.test.utils import override_settings +from mock import patch +from opaque_keys.edx.keys import UsageKey from contentstore.models import PushNotificationConfig from contentstore.tests.test_course_settings import CourseTestCase from contentstore.utils import reverse_course_url, reverse_usage_url -from opaque_keys.edx.keys import UsageKey from xmodule.modulestore.django import modulestore diff --git a/cms/djangoapps/contentstore/views/tests/test_credit_eligibility.py b/cms/djangoapps/contentstore/views/tests/test_credit_eligibility.py index f90fde577a..6f882a79d1 100644 --- a/cms/djangoapps/contentstore/views/tests/test_credit_eligibility.py +++ b/cms/djangoapps/contentstore/views/tests/test_credit_eligibility.py @@ -6,11 +6,10 @@ import mock from contentstore.tests.utils import CourseTestCase from contentstore.utils import reverse_course_url -from xmodule.modulestore.tests.factories import CourseFactory - from openedx.core.djangoapps.credit.api import get_credit_requirements from openedx.core.djangoapps.credit.models import CreditCourse from openedx.core.djangoapps.credit.signals import on_course_publish +from xmodule.modulestore.tests.factories import CourseFactory class CreditEligibilityTest(CourseTestCase): diff --git a/cms/djangoapps/contentstore/views/tests/test_entrance_exam.py b/cms/djangoapps/contentstore/views/tests/test_entrance_exam.py index fbf2d770bd..a20122aade 100644 --- a/cms/djangoapps/contentstore/views/tests/test_entrance_exam.py +++ b/cms/djangoapps/contentstore/views/tests/test_entrance_exam.py @@ -2,25 +2,29 @@ Test module for Entrance Exams AJAX callback handler workflows """ import json -from mock import patch from django.conf import settings from django.contrib.auth.models import User from django.test.client import RequestFactory +from milestones.tests.utils import MilestonesTestCaseMixin +from mock import patch +from opaque_keys.edx.keys import UsageKey from contentstore.tests.utils import AjaxEnabledTestClient, CourseTestCase from contentstore.utils import reverse_url -from contentstore.views.entrance_exam import create_entrance_exam, update_entrance_exam, delete_entrance_exam,\ - add_entrance_exam_milestone, remove_entrance_exam_milestone_reference -from contentstore.views.helpers import GRADER_TYPES +from contentstore.views.entrance_exam import ( + add_entrance_exam_milestone, + create_entrance_exam, + delete_entrance_exam, + remove_entrance_exam_milestone_reference, + update_entrance_exam +) +from contentstore.views.helpers import GRADER_TYPES, create_xblock from models.settings.course_grading import CourseGradingModel from models.settings.course_metadata import CourseMetadata -from opaque_keys.edx.keys import UsageKey from student.tests.factories import UserFactory from util import milestones_helpers from xmodule.modulestore.django import modulestore -from contentstore.views.helpers import create_xblock -from milestones.tests.utils import MilestonesTestCaseMixin @patch.dict(settings.FEATURES, {'ENTRANCE_EXAMS': True}) diff --git a/cms/djangoapps/contentstore/views/tests/test_gating.py b/cms/djangoapps/contentstore/views/tests/test_gating.py index 013271c8c1..ebbbf34440 100644 --- a/cms/djangoapps/contentstore/views/tests/test_gating.py +++ b/cms/djangoapps/contentstore/views/tests/test_gating.py @@ -4,12 +4,13 @@ Unit tests for the gating feature in Studio import json from mock import patch -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE -from xmodule.modulestore.tests.factories import ItemFactory + from contentstore.tests.utils import CourseTestCase from contentstore.utils import reverse_usage_url from contentstore.views.item import VisibilityState from openedx.core.lib.gating.api import GATING_NAMESPACE_QUALIFIER +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE +from xmodule.modulestore.tests.factories import ItemFactory class TestSubsectionGating(CourseTestCase): diff --git a/cms/djangoapps/contentstore/views/tests/test_helpers.py b/cms/djangoapps/contentstore/views/tests/test_helpers.py index 576ea38808..ace156d281 100644 --- a/cms/djangoapps/contentstore/views/tests/test_helpers.py +++ b/cms/djangoapps/contentstore/views/tests/test_helpers.py @@ -2,10 +2,11 @@ Unit tests for helpers.py. """ +from django.utils import http + from contentstore.tests.utils import CourseTestCase from contentstore.views.helpers import xblock_studio_url, xblock_type_display_name from xmodule.modulestore.tests.factories import ItemFactory, LibraryFactory -from django.utils import http class HelpersTestCase(CourseTestCase): diff --git a/cms/djangoapps/contentstore/views/tests/test_import_export.py b/cms/djangoapps/contentstore/views/tests/test_import_export.py index d320bac5b0..4ee34a1d0c 100644 --- a/cms/djangoapps/contentstore/views/tests/test_import_export.py +++ b/cms/djangoapps/contentstore/views/tests/test_import_export.py @@ -2,41 +2,37 @@ Unit tests for course import and export """ import copy -import ddt import json import logging -import lxml import os import shutil import tarfile import tempfile -from path import Path as path from uuid import uuid4 -from django.test.utils import override_settings +import ddt +import lxml from django.conf import settings +from django.test.utils import override_settings +from milestones.tests.utils import MilestonesTestCaseMixin +from opaque_keys.edx.locator import LibraryLocator +from path import Path as path from contentstore.tests.test_libraries import LibraryTestCase -from xmodule.contentstore.django import contentstore -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.xml_exporter import export_library_to_xml, export_course_to_xml -from xmodule.modulestore.xml_importer import import_library_from_xml, import_course_from_xml -from xmodule.modulestore import LIBRARY_ROOT, ModuleStoreEnum -from contentstore.utils import reverse_course_url from contentstore.tests.utils import CourseTestCase - -from xmodule.modulestore.tests.factories import ItemFactory, LibraryFactory, CourseFactory -from xmodule.modulestore.tests.utils import ( - MongoContentstoreBuilder, SPLIT_MODULESTORE_SETUP, TEST_DATA_DIR -) -from opaque_keys.edx.locator import LibraryLocator - +from contentstore.utils import reverse_course_url +from models.settings.course_metadata import CourseMetadata from openedx.core.lib.extract_tar import safetar_extractall from student import auth from student.roles import CourseInstructorRole, CourseStaffRole -from models.settings.course_metadata import CourseMetadata from util import milestones_helpers -from milestones.tests.utils import MilestonesTestCaseMixin +from xmodule.contentstore.django import contentstore +from xmodule.modulestore import LIBRARY_ROOT, ModuleStoreEnum +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, LibraryFactory +from xmodule.modulestore.tests.utils import SPLIT_MODULESTORE_SETUP, TEST_DATA_DIR, MongoContentstoreBuilder +from xmodule.modulestore.xml_exporter import export_course_to_xml, export_library_to_xml +from xmodule.modulestore.xml_importer import import_course_from_xml, import_library_from_xml TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex diff --git a/cms/djangoapps/contentstore/views/tests/test_library.py b/cms/djangoapps/contentstore/views/tests/test_library.py index ce13da354f..102d0778af 100644 --- a/cms/djangoapps/contentstore/views/tests/test_library.py +++ b/cms/djangoapps/contentstore/views/tests/test_library.py @@ -3,19 +3,19 @@ Unit tests for contentstore.views.library More important high-level tests are in contentstore/tests/test_libraries.py """ +import ddt +import mock from django.conf import settings -from contentstore.tests.utils import AjaxEnabledTestClient, parse_json +from mock import patch +from opaque_keys.edx.locator import CourseKey, LibraryLocator + +from contentstore.tests.utils import AjaxEnabledTestClient, CourseTestCase, parse_json from contentstore.utils import reverse_course_url, reverse_library_url -from contentstore.tests.utils import CourseTestCase from contentstore.views.component import get_component_templates from contentstore.views.library import get_library_creator_status from course_creators.views import add_user_with_status_granted as grant_course_creator_status -from xmodule.modulestore.tests.factories import LibraryFactory -from mock import patch -from opaque_keys.edx.locator import CourseKey, LibraryLocator -import ddt -import mock from student.roles import LibraryUserRole +from xmodule.modulestore.tests.factories import LibraryFactory LIBRARY_REST_URL = '/library/' # URL for GET/POST requests involving libraries diff --git a/cms/djangoapps/contentstore/views/tests/test_organizations.py b/cms/djangoapps/contentstore/views/tests/test_organizations.py index 3ba81f36b4..d8137a47d9 100644 --- a/cms/djangoapps/contentstore/views/tests/test_organizations.py +++ b/cms/djangoapps/contentstore/views/tests/test_organizations.py @@ -1,10 +1,12 @@ """Tests covering the Organizations listing on the Studio home.""" import json -from mock import patch + from django.core.urlresolvers import reverse from django.test import TestCase -from util.organizations_helpers import add_organization +from mock import patch + from student.tests.factories import UserFactory +from util.organizations_helpers import add_organization @patch.dict('django.conf.settings.FEATURES', {'ORGANIZATIONS_APP': True}) diff --git a/cms/djangoapps/contentstore/views/tests/test_preview.py b/cms/djangoapps/contentstore/views/tests/test_preview.py index b87d36b230..07d1a208ae 100644 --- a/cms/djangoapps/contentstore/views/tests/test_preview.py +++ b/cms/djangoapps/contentstore/views/tests/test_preview.py @@ -2,24 +2,21 @@ Tests for contentstore.views.preview.py """ import re + import ddt import mock -from xblock.core import XBlock - from django.test.client import Client, RequestFactory +from xblock.core import XBlock, XBlockAside -from xblock.core import XBlockAside -from student.tests.factories import UserFactory - -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase - -from contentstore.views.preview import get_preview_fragment, _preview_module_system from contentstore.utils import reverse_usage_url -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.tests.test_asides import AsideTestType +from contentstore.views.preview import _preview_module_system, get_preview_fragment +from student.tests.factories import UserFactory from xblock_config.models import StudioConfig +from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from xmodule.modulestore.tests.test_asides import AsideTestType @ddt.ddt diff --git a/cms/djangoapps/contentstore/views/tests/test_tabs.py b/cms/djangoapps/contentstore/views/tests/test_tabs.py index f440d44f91..166971c82c 100644 --- a/cms/djangoapps/contentstore/views/tests/test_tabs.py +++ b/cms/djangoapps/contentstore/views/tests/test_tabs.py @@ -2,14 +2,14 @@ import json -from contentstore.views import tabs from contentstore.tests.utils import CourseTestCase from contentstore.utils import reverse_course_url -from xmodule.x_module import STUDENT_VIEW -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.tabs import CourseTabList +from contentstore.views import tabs from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from xmodule.tabs import CourseTabList +from xmodule.x_module import STUDENT_VIEW class TabsPageTests(CourseTestCase): diff --git a/cms/djangoapps/contentstore/views/tests/test_textbooks.py b/cms/djangoapps/contentstore/views/tests/test_textbooks.py index 22219a9f21..cfbef2491a 100644 --- a/cms/djangoapps/contentstore/views/tests/test_textbooks.py +++ b/cms/djangoapps/contentstore/views/tests/test_textbooks.py @@ -1,10 +1,9 @@ import json from unittest import TestCase + from contentstore.tests.utils import CourseTestCase from contentstore.utils import reverse_course_url - -from contentstore.views.course import ( - validate_textbooks_json, validate_textbook_json, TextbookValidationError) +from contentstore.views.course import TextbookValidationError, validate_textbook_json, validate_textbooks_json class TextbookIndexTestCase(CourseTestCase): diff --git a/cms/djangoapps/contentstore/views/tests/test_transcripts.py b/cms/djangoapps/contentstore/views/tests/test_transcripts.py index fc120638b8..319f1f6b43 100644 --- a/cms/djangoapps/contentstore/views/tests/test_transcripts.py +++ b/cms/djangoapps/contentstore/views/tests/test_transcripts.py @@ -6,19 +6,19 @@ import os import tempfile import textwrap from uuid import uuid4 -from mock import patch +from django.conf import settings from django.core.urlresolvers import reverse from django.test.utils import override_settings -from django.conf import settings +from mock import patch +from opaque_keys.edx.keys import UsageKey from contentstore.tests.utils import CourseTestCase, mock_requests_get -from opaque_keys.edx.keys import UsageKey from openedx.core.djangoapps.contentserver.caching import del_cached_content -from xmodule.modulestore.django import modulestore -from xmodule.contentstore.django import contentstore from xmodule.contentstore.content import StaticContent +from xmodule.contentstore.django import contentstore from xmodule.exceptions import NotFoundError +from xmodule.modulestore.django import modulestore from xmodule.video_module import transcripts_utils TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) diff --git a/cms/djangoapps/contentstore/views/tests/test_user.py b/cms/djangoapps/contentstore/views/tests/test_user.py index 725858e44d..a2bd27b514 100644 --- a/cms/djangoapps/contentstore/views/tests/test_user.py +++ b/cms/djangoapps/contentstore/views/tests/test_user.py @@ -3,12 +3,13 @@ Tests for contentstore/views/user.py. """ import json +from django.contrib.auth.models import User + from contentstore.tests.utils import CourseTestCase from contentstore.utils import reverse_course_url -from django.contrib.auth.models import User -from student.models import CourseEnrollment -from student.roles import CourseStaffRole, CourseInstructorRole from student import auth +from student.models import CourseEnrollment +from student.roles import CourseInstructorRole, CourseStaffRole class UsersTestCase(CourseTestCase): diff --git a/cms/djangoapps/contentstore/views/tests/test_videos.py b/cms/djangoapps/contentstore/views/tests/test_videos.py index 5f9751e51f..6731bf6815 100644 --- a/cms/djangoapps/contentstore/views/tests/test_videos.py +++ b/cms/djangoapps/contentstore/views/tests/test_videos.py @@ -2,25 +2,24 @@ """ Unit tests for video-related REST APIs. """ -from datetime import datetime import csv -import ddt import json -import dateutil.parser import re +from datetime import datetime from StringIO import StringIO -import pytz +import dateutil.parser +import ddt +import pytz from django.conf import settings from django.test.utils import override_settings +from edxval.api import create_profile, create_video, get_video_info from mock import Mock, patch -from edxval.api import create_profile, create_video, get_video_info - from contentstore.models import VideoUploadConfig -from contentstore.views.videos import KEY_EXPIRATION_IN_SECONDS, StatusDisplayStrings, convert_video_status from contentstore.tests.utils import CourseTestCase from contentstore.utils import reverse_course_url +from contentstore.views.videos import KEY_EXPIRATION_IN_SECONDS, StatusDisplayStrings, convert_video_status from xmodule.modulestore.tests.factories import CourseFactory diff --git a/cms/djangoapps/contentstore/views/transcripts_ajax.py b/cms/djangoapps/contentstore/views/transcripts_ajax.py index 0eecd909a0..e32f27dbca 100644 --- a/cms/djangoapps/contentstore/views/transcripts_ajax.py +++ b/cms/djangoapps/contentstore/views/transcripts_ajax.py @@ -6,40 +6,38 @@ Module do not support rollback (pressing "Cancel" button in Studio) All user changes are saved immediately. """ import copy -import os -import logging import json +import logging +import os + import requests - -from django.http import HttpResponse, Http404 -from django.core.exceptions import PermissionDenied -from django.contrib.auth.decorators import login_required from django.conf import settings +from django.contrib.auth.decorators import login_required +from django.core.exceptions import PermissionDenied +from django.http import Http404, HttpResponse from django.utils.translation import ugettext as _ - from opaque_keys import InvalidKeyError - -from xmodule.contentstore.content import StaticContent -from xmodule.exceptions import NotFoundError -from xmodule.modulestore.django import modulestore from opaque_keys.edx.keys import UsageKey -from xmodule.contentstore.django import contentstore -from xmodule.modulestore.exceptions import ItemNotFoundError - -from util.json_request import JsonResponse - -from xmodule.video_module.transcripts_utils import ( - generate_subs_from_source, - generate_srt_from_sjson, remove_subs_from_store, - download_youtube_subs, get_transcripts_from_youtube, - copy_or_rename_transcript, - manage_video_subtitles_save, - GetTranscriptsFromYouTubeException, - TranscriptsRequestValidationException, - youtube_video_transcript_name, -) from student.auth import has_course_author_access +from util.json_request import JsonResponse +from xmodule.contentstore.content import StaticContent +from xmodule.contentstore.django import contentstore +from xmodule.exceptions import NotFoundError +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.exceptions import ItemNotFoundError +from xmodule.video_module.transcripts_utils import ( + GetTranscriptsFromYouTubeException, + TranscriptsRequestValidationException, + copy_or_rename_transcript, + download_youtube_subs, + generate_srt_from_sjson, + generate_subs_from_source, + get_transcripts_from_youtube, + manage_video_subtitles_save, + remove_subs_from_store, + youtube_video_transcript_name +) __all__ = [ 'upload_transcripts', diff --git a/cms/djangoapps/contentstore/views/user.py b/cms/djangoapps/contentstore/views/user.py index e74a7bac8f..07d82bf182 100644 --- a/cms/djangoapps/contentstore/views/user.py +++ b/cms/djangoapps/contentstore/views/user.py @@ -1,25 +1,21 @@ -from django.core.exceptions import PermissionDenied -from django.contrib.auth.models import User from django.contrib.auth.decorators import login_required -from django.views.decorators.http import require_http_methods +from django.contrib.auth.models import User +from django.core.exceptions import PermissionDenied +from django.http import HttpResponseNotFound from django.utils.translation import ugettext as _ -from django.views.decorators.http import require_POST from django.views.decorators.csrf import ensure_csrf_cookie -from edxmako.shortcuts import render_to_response - -from xmodule.modulestore.django import modulestore +from django.views.decorators.http import require_http_methods, require_POST from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import LibraryLocator -from util.json_request import JsonResponse, expect_json -from student.roles import CourseInstructorRole, CourseStaffRole, LibraryUserRole + from course_creators.views import user_requested_access - -from student.auth import STUDIO_EDIT_ROLES, STUDIO_VIEW_USERS, get_user_permissions - -from student.models import CourseEnrollment -from django.http import HttpResponseNotFound +from edxmako.shortcuts import render_to_response from student import auth - +from student.auth import STUDIO_EDIT_ROLES, STUDIO_VIEW_USERS, get_user_permissions +from student.models import CourseEnrollment +from student.roles import CourseInstructorRole, CourseStaffRole, LibraryUserRole +from util.json_request import JsonResponse, expect_json +from xmodule.modulestore.django import modulestore __all__ = ['request_course_creator', 'course_team_handler'] diff --git a/cms/djangoapps/contentstore/views/videos.py b/cms/djangoapps/contentstore/views/videos.py index b40ceae83c..f8ecbf152d 100644 --- a/cms/djangoapps/contentstore/views/videos.py +++ b/cms/djangoapps/contentstore/views/videos.py @@ -1,25 +1,24 @@ """ Views related to the video upload feature """ -from datetime import datetime, timedelta -import logging - -from boto import s3 import csv +import logging +from datetime import datetime, timedelta from uuid import uuid4 +import rfc6266 +from boto import s3 from django.conf import settings from django.contrib.auth.decorators import login_required from django.http import HttpResponse, HttpResponseNotFound -from django.utils.translation import ugettext as _, ugettext_noop +from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext_noop from django.views.decorators.http import require_GET, require_http_methods -import rfc6266 - from edxval.api import ( - create_video, - get_videos_for_course, SortDirection, VideoSortField, + create_video, + get_videos_for_course, remove_video_for_course, update_video_status ) @@ -28,11 +27,10 @@ from opaque_keys.edx.keys import CourseKey from contentstore.models import VideoUploadConfig from contentstore.utils import reverse_course_url from edxmako.shortcuts import render_to_response -from util.json_request import expect_json, JsonResponse +from util.json_request import JsonResponse, expect_json from .course import get_course_and_check_access - __all__ = ["videos_handler", "video_encodings_download"] LOGGER = logging.getLogger(__name__) diff --git a/cms/djangoapps/course_creators/admin.py b/cms/djangoapps/course_creators/admin.py index 5eaa8c4ac3..5a018ab049 100644 --- a/cms/djangoapps/course_creators/admin.py +++ b/cms/djangoapps/course_creators/admin.py @@ -2,17 +2,17 @@ django admin page for the course creators table """ -from course_creators.models import CourseCreator, update_creator_state, send_user_notification, send_admin_notification -from course_creators.views import update_course_creator_group - -from ratelimitbackend import admin -from django.conf import settings -from django.dispatch import receiver -from edxmako.shortcuts import render_to_string -from django.core.mail import send_mail +import logging from smtplib import SMTPException -import logging +from django.conf import settings +from django.core.mail import send_mail +from django.dispatch import receiver +from ratelimitbackend import admin + +from course_creators.models import CourseCreator, send_admin_notification, send_user_notification, update_creator_state +from course_creators.views import update_course_creator_group +from edxmako.shortcuts import render_to_string log = logging.getLogger("studio.coursecreatoradmin") diff --git a/cms/djangoapps/course_creators/migrations/0001_initial.py b/cms/djangoapps/course_creators/migrations/0001_initial.py index 14b68306c7..db668d83a8 100644 --- a/cms/djangoapps/course_creators/migrations/0001_initial.py +++ b/cms/djangoapps/course_creators/migrations/0001_initial.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import migrations, models from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/cms/djangoapps/course_creators/models.py b/cms/djangoapps/course_creators/models.py index 59d28b63e1..bec2da645e 100644 --- a/cms/djangoapps/course_creators/models.py +++ b/cms/djangoapps/course_creators/models.py @@ -1,11 +1,10 @@ """ Table for storing information about whether or not Studio users have course creation privileges. """ +from django.contrib.auth.models import User from django.db import models from django.db.models.signals import post_init, post_save -from django.dispatch import receiver, Signal -from django.contrib.auth.models import User - +from django.dispatch import Signal, receiver from django.utils import timezone from django.utils.translation import ugettext as _ diff --git a/cms/djangoapps/course_creators/tests/test_admin.py b/cms/djangoapps/course_creators/tests/test_admin.py index 45d84eed62..949fa45099 100644 --- a/cms/djangoapps/course_creators/tests/test_admin.py +++ b/cms/djangoapps/course_creators/tests/test_admin.py @@ -2,17 +2,17 @@ Tests course_creators.admin.py. """ -from django.test import TestCase -from django.contrib.auth.models import User -from django.contrib.admin.sites import AdminSite -from django.http import HttpRequest import mock +from django.contrib.admin.sites import AdminSite +from django.contrib.auth.models import User +from django.core import mail +from django.http import HttpRequest +from django.test import TestCase from course_creators.admin import CourseCreatorAdmin from course_creators.models import CourseCreator -from django.core import mail -from student.roles import CourseCreatorRole from student import auth +from student.roles import CourseCreatorRole def mock_render_to_string(template_name, context): diff --git a/cms/djangoapps/course_creators/tests/test_views.py b/cms/djangoapps/course_creators/tests/test_views.py index 9ece71c8a2..fa951643cd 100644 --- a/cms/djangoapps/course_creators/tests/test_views.py +++ b/cms/djangoapps/course_creators/tests/test_views.py @@ -2,16 +2,21 @@ Tests course_creators.views.py. """ +import mock from django.contrib.auth.models import User from django.core.exceptions import PermissionDenied -from django.test import TestCase from django.core.urlresolvers import reverse +from django.test import TestCase -from course_creators.views import add_user_with_status_unrequested, add_user_with_status_granted -from course_creators.views import get_course_creator_status, update_course_creator_group, user_requested_access -import mock -from student.roles import CourseCreatorRole +from course_creators.views import ( + add_user_with_status_granted, + add_user_with_status_unrequested, + get_course_creator_status, + update_course_creator_group, + user_requested_access +) from student import auth +from student.roles import CourseCreatorRole class CourseCreatorView(TestCase): diff --git a/cms/djangoapps/course_creators/views.py b/cms/djangoapps/course_creators/views.py index c0c1b4a452..f61c8450aa 100644 --- a/cms/djangoapps/course_creators/views.py +++ b/cms/djangoapps/course_creators/views.py @@ -2,8 +2,8 @@ Methods for interacting programmatically with the user creator table. """ from course_creators.models import CourseCreator -from student.roles import CourseCreatorRole from student import auth +from student.roles import CourseCreatorRole def add_user_with_status_unrequested(user): diff --git a/cms/djangoapps/maintenance/tests.py b/cms/djangoapps/maintenance/tests.py index 08a5c08859..ada6274050 100644 --- a/cms/djangoapps/maintenance/tests.py +++ b/cms/djangoapps/maintenance/tests.py @@ -1,24 +1,21 @@ """ Tests for the maintenance app views. """ -import ddt import json +import ddt from django.conf import settings from django.core.urlresolvers import reverse +from contentstore.management.commands.utils import get_course_versions +from student.tests.factories import AdminFactory, UserFactory from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory - -from contentstore.management.commands.utils import get_course_versions -from student.tests.factories import AdminFactory, UserFactory - from .views import COURSE_KEY_ERROR_MESSAGES, MAINTENANCE_VIEWS - # This list contains URLs of all maintenance app views. MAINTENANCE_URLS = [reverse(view['url']) for view in MAINTENANCE_VIEWS.values()] diff --git a/cms/djangoapps/maintenance/urls.py b/cms/djangoapps/maintenance/urls.py index 99ee2bc40d..5b780b29ec 100644 --- a/cms/djangoapps/maintenance/urls.py +++ b/cms/djangoapps/maintenance/urls.py @@ -3,8 +3,7 @@ URLs for the maintenance app. """ from django.conf.urls import patterns, url -from .views import MaintenanceIndexView, ForcePublishCourseView - +from .views import ForcePublishCourseView, MaintenanceIndexView urlpatterns = patterns( '', diff --git a/cms/djangoapps/maintenance/views.py b/cms/djangoapps/maintenance/views.py index b370d4bc5c..fe6555008e 100644 --- a/cms/djangoapps/maintenance/views.py +++ b/cms/djangoapps/maintenance/views.py @@ -2,24 +2,23 @@ Views for the maintenance app. """ import logging -from django.db import transaction + from django.core.validators import ValidationError +from django.db import transaction from django.utils.decorators import method_decorator from django.utils.translation import ugettext as _ from django.views.generic import View - -from edxmako.shortcuts import render_to_response from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey + +from contentstore.management.commands.utils import get_course_versions +from edxmako.shortcuts import render_to_response +from util.json_request import JsonResponse +from util.views import require_global_staff from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError -from contentstore.management.commands.utils import get_course_versions -from util.json_request import JsonResponse -from util.views import require_global_staff - - log = logging.getLogger(__name__) # This dict maintains all the views that will be used Maintenance app. diff --git a/cms/djangoapps/models/settings/course_metadata.py b/cms/djangoapps/models/settings/course_metadata.py index adc849405c..f581fee3e7 100644 --- a/cms/djangoapps/models/settings/course_metadata.py +++ b/cms/djangoapps/models/settings/course_metadata.py @@ -1,13 +1,13 @@ """ Django module for Course Metadata class -- manages advanced settings and related parameters """ +from django.conf import settings +from django.utils.translation import ugettext as _ from xblock.fields import Scope + from xblock_django.models import XBlockStudioConfigurationFlag from xmodule.modulestore.django import modulestore -from django.utils.translation import ugettext as _ -from django.conf import settings - class CourseMetadata(object): ''' diff --git a/cms/djangoapps/models/settings/encoder.py b/cms/djangoapps/models/settings/encoder.py index 36b6e1fb44..c276998322 100644 --- a/cms/djangoapps/models/settings/encoder.py +++ b/cms/djangoapps/models/settings/encoder.py @@ -6,6 +6,7 @@ import json from json.encoder import JSONEncoder from opaque_keys.edx.locations import Location + from openedx.core.djangoapps.models.course_details import CourseDetails from xmodule.fields import Date diff --git a/cms/djangoapps/pipeline_js/urls.py b/cms/djangoapps/pipeline_js/urls.py index 1fc732bcec..2f1e791300 100644 --- a/cms/djangoapps/pipeline_js/urls.py +++ b/cms/djangoapps/pipeline_js/urls.py @@ -1,7 +1,7 @@ """ URL patterns for Javascript files used to load all of the XModule JS in one wad. """ -from django.conf.urls import url, patterns +from django.conf.urls import patterns, url urlpatterns = patterns( 'pipeline_js.views', diff --git a/cms/djangoapps/pipeline_js/views.py b/cms/djangoapps/pipeline_js/views.py index 922fb6bac6..bfb05d1dd3 100644 --- a/cms/djangoapps/pipeline_js/views.py +++ b/cms/djangoapps/pipeline_js/views.py @@ -5,8 +5,8 @@ Views for returning XModule JS (used by requirejs) import json from django.conf import settings -from django.http import HttpResponse from django.contrib.staticfiles.storage import staticfiles_storage +from django.http import HttpResponse from edxmako.shortcuts import render_to_response diff --git a/cms/djangoapps/xblock_config/admin.py b/cms/djangoapps/xblock_config/admin.py index 9efd20799f..80b7b98e27 100644 --- a/cms/djangoapps/xblock_config/admin.py +++ b/cms/djangoapps/xblock_config/admin.py @@ -2,14 +2,11 @@ Django admin dashboard configuration for LMS XBlock infrastructure. """ -from django.contrib import admin from config_models.admin import ConfigurationModelAdmin, KeyedConfigurationModelAdmin +from django.contrib import admin from xblock_config.forms import CourseEditLTIFieldsEnabledAdminForm -from xblock_config.models import ( - CourseEditLTIFieldsEnabledFlag, - StudioConfig, -) +from xblock_config.models import CourseEditLTIFieldsEnabledFlag, StudioConfig class CourseEditLTIFieldsEnabledFlagAdmin(KeyedConfigurationModelAdmin): diff --git a/cms/djangoapps/xblock_config/forms.py b/cms/djangoapps/xblock_config/forms.py index f714b00e72..4ee49b1a60 100644 --- a/cms/djangoapps/xblock_config/forms.py +++ b/cms/djangoapps/xblock_config/forms.py @@ -6,9 +6,9 @@ import logging from django import forms from opaque_keys import InvalidKeyError from opaque_keys.edx.locator import CourseLocator -from xmodule.modulestore.django import modulestore from xblock_config.models import CourseEditLTIFieldsEnabledFlag +from xmodule.modulestore.django import modulestore log = logging.getLogger(__name__) diff --git a/cms/djangoapps/xblock_config/migrations/0001_initial.py b/cms/djangoapps/xblock_config/migrations/0001_initial.py index 8d3f9883cd..ee8de3c6b3 100644 --- a/cms/djangoapps/xblock_config/migrations/0001_initial.py +++ b/cms/djangoapps/xblock_config/migrations/0001_initial.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import migrations, models import django.db.models.deletion from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/cms/djangoapps/xblock_config/migrations/0002_courseeditltifieldsenabledflag.py b/cms/djangoapps/xblock_config/migrations/0002_courseeditltifieldsenabledflag.py index f6d165aed9..59b494ddcd 100644 --- a/cms/djangoapps/xblock_config/migrations/0002_courseeditltifieldsenabledflag.py +++ b/cms/djangoapps/xblock_config/migrations/0002_courseeditltifieldsenabledflag.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import migrations, models import django.db.models.deletion -import openedx.core.djangoapps.xmodule_django.models from django.conf import settings +from django.db import migrations, models + +import openedx.core.djangoapps.xmodule_django.models class Migration(migrations.Migration): diff --git a/cms/djangoapps/xblock_config/models.py b/cms/djangoapps/xblock_config/models.py index 3dacfd2692..b61f47f859 100644 --- a/cms/djangoapps/xblock_config/models.py +++ b/cms/djangoapps/xblock_config/models.py @@ -5,10 +5,10 @@ Includes: StudioConfig: A ConfigurationModel for managing Studio. """ -from django.db.models import BooleanField, TextField -from openedx.core.djangoapps.xmodule_django.models import CourseKeyField - from config_models.models import ConfigurationModel +from django.db.models import BooleanField, TextField + +from openedx.core.djangoapps.xmodule_django.models import CourseKeyField from request_cache.middleware import request_cached diff --git a/cms/djangoapps/xblock_config/tests/test_models.py b/cms/djangoapps/xblock_config/tests/test_models.py index 8239ef6d44..163e078599 100644 --- a/cms/djangoapps/xblock_config/tests/test_models.py +++ b/cms/djangoapps/xblock_config/tests/test_models.py @@ -1,12 +1,12 @@ """ Tests for the models that configures Edit LTI fields feature. """ -import ddt - from contextlib import contextmanager -from django.test import TestCase +import ddt +from django.test import TestCase from opaque_keys.edx.locator import CourseLocator + from request_cache.middleware import RequestCache from xblock_config.models import CourseEditLTIFieldsEnabledFlag diff --git a/cms/lib/xblock/authoring_mixin.py b/cms/lib/xblock/authoring_mixin.py index 3eb27c6f57..f9068fb8a4 100644 --- a/cms/lib/xblock/authoring_mixin.py +++ b/cms/lib/xblock/authoring_mixin.py @@ -5,7 +5,6 @@ Mixin class that provides authoring capabilities for XBlocks. import logging from django.conf import settings - from xblock.core import XBlock from xblock.fields import XBlockMixin from xblock.fragment import Fragment diff --git a/cms/lib/xblock/tagging/admin.py b/cms/lib/xblock/tagging/admin.py index 003a4f767b..47f7092b30 100644 --- a/cms/lib/xblock/tagging/admin.py +++ b/cms/lib/xblock/tagging/admin.py @@ -2,7 +2,8 @@ Admin registration for tags models """ from django.contrib import admin -from .models import TagCategories, TagAvailableValues + +from .models import TagAvailableValues, TagCategories class TagCategoriesAdmin(admin.ModelAdmin): diff --git a/cms/lib/xblock/tagging/tagging.py b/cms/lib/xblock/tagging/tagging.py index c6028f62b9..c7290b1b62 100644 --- a/cms/lib/xblock/tagging/tagging.py +++ b/cms/lib/xblock/tagging/tagging.py @@ -3,16 +3,17 @@ Structured Tagging based on XBlockAsides """ -from xblock.core import XBlockAside, XBlock -from xblock.fragment import Fragment -from xblock.fields import Scope, Dict -from xmodule.x_module import AUTHOR_VIEW -from xmodule.capa_module import CapaModule -from edxmako.shortcuts import render_to_string from django.conf import settings from webob import Response -from .models import TagCategories +from xblock.core import XBlock, XBlockAside +from xblock.fields import Dict, Scope +from xblock.fragment import Fragment +from edxmako.shortcuts import render_to_string +from xmodule.capa_module import CapaModule +from xmodule.x_module import AUTHOR_VIEW + +from .models import TagCategories _ = lambda text: text diff --git a/cms/lib/xblock/tagging/test.py b/cms/lib/xblock/tagging/test.py index f7ad46dcc7..173fa9b040 100644 --- a/cms/lib/xblock/tagging/test.py +++ b/cms/lib/xblock/tagging/test.py @@ -2,28 +2,30 @@ Tests for the Studio Tagging XBlockAside """ -import ddt import json +from datetime import datetime +from StringIO import StringIO + +import ddt +from django.test.client import RequestFactory +from lxml import etree +from opaque_keys.edx.asides import AsideUsageKeyV1, AsideUsageKeyV2 +from pytz import UTC +from xblock.fields import ScopeIds +from xblock.runtime import DictKeyValueStore, KvsFieldData +from xblock.test.tools import TestRuntime + +from cms.lib.xblock.tagging import StructuredTagsAside +from cms.lib.xblock.tagging.models import TagAvailableValues, TagCategories +from contentstore.tests.utils import AjaxEnabledTestClient +from contentstore.utils import reverse_usage_url +from contentstore.views.preview import get_preview_fragment +from student.tests.factories import UserFactory +from xblock_config.models import StudioConfig from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory -from xblock_config.models import StudioConfig -from xblock.fields import ScopeIds -from xblock.runtime import DictKeyValueStore, KvsFieldData -from xblock.test.tools import TestRuntime -from cms.lib.xblock.tagging import StructuredTagsAside -from cms.lib.xblock.tagging.models import TagCategories, TagAvailableValues -from contentstore.views.preview import get_preview_fragment -from contentstore.utils import reverse_usage_url -from contentstore.tests.utils import AjaxEnabledTestClient -from django.test.client import RequestFactory -from student.tests.factories import UserFactory -from opaque_keys.edx.asides import AsideUsageKeyV1, AsideUsageKeyV2 -from datetime import datetime -from pytz import UTC -from lxml import etree -from StringIO import StringIO @ddt.ddt diff --git a/cms/lib/xblock/test/test_runtime.py b/cms/lib/xblock/test/test_runtime.py index 6cfa798051..c126399e20 100644 --- a/cms/lib/xblock/test/test_runtime.py +++ b/cms/lib/xblock/test/test_runtime.py @@ -1,10 +1,11 @@ """ Tests of edX Studio runtime functionality """ +from unittest import TestCase from urlparse import urlparse from mock import Mock -from unittest import TestCase + from cms.lib.xblock.runtime import handler_url diff --git a/cms/startup.py b/cms/startup.py index 47aa0560f9..17ac47474e 100644 --- a/cms/startup.py +++ b/cms/startup.py @@ -2,25 +2,23 @@ Module with code executed during Studio startup """ +import django from django.conf import settings +import cms.lib.xblock.runtime +import xmodule.x_module +from openedx.core.djangoapps.monkey_patch import django_db_models_options +from openedx.core.djangoapps.theming.core import enable_theming +from openedx.core.djangoapps.theming.helpers import is_comprehensive_theming_enabled +from openedx.core.lib.django_startup import autostartup +from openedx.core.lib.xblock_utils import xblock_local_resource_url +from openedx.core.release import doc_version +from startup_configurations.validate_config import validate_cms_config + # Force settings to run so that the python path is modified settings.INSTALLED_APPS # pylint: disable=pointless-statement -from openedx.core.lib.django_startup import autostartup -import django -from openedx.core.djangoapps.monkey_patch import django_db_models_options -from openedx.core.lib.xblock_utils import xblock_local_resource_url -from openedx.core.release import doc_version - -import xmodule.x_module -import cms.lib.xblock.runtime - -from startup_configurations.validate_config import validate_cms_config -from openedx.core.djangoapps.theming.core import enable_theming -from openedx.core.djangoapps.theming.helpers import is_comprehensive_theming_enabled - def run(): """ diff --git a/cms/urls.py b/cms/urls.py index 1d4341ca6d..08636d7e67 100644 --- a/cms/urls.py +++ b/cms/urls.py @@ -1,5 +1,5 @@ from django.conf import settings -from django.conf.urls import patterns, include, url +from django.conf.urls import include, patterns, url # There is a course creators admin table. from ratelimitbackend import admin