diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index cb72885281..0000000000 --- a/.isort.cfg +++ /dev/null @@ -1,4 +0,0 @@ -[settings] -indent=' ' -line_length=120 -multi_line_output=3 diff --git a/lms/celery.py b/lms/celery.py index 23eb1aedba..89f35bde38 100644 --- a/lms/celery.py +++ b/lms/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/lms/djangoapps/badges/admin.py b/lms/djangoapps/badges/admin.py index cced329c07..552550821c 100644 --- a/lms/djangoapps/badges/admin.py +++ b/lms/djangoapps/badges/admin.py @@ -1,9 +1,10 @@ """ Admin registration for Badge Models """ -from django.contrib import admin -from badges.models import CourseCompleteImageConfiguration, CourseEventBadgesConfiguration, BadgeClass from config_models.admin import ConfigurationModelAdmin +from django.contrib import admin + +from badges.models import BadgeClass, CourseCompleteImageConfiguration, CourseEventBadgesConfiguration admin.site.register(CourseCompleteImageConfiguration) admin.site.register(BadgeClass) diff --git a/lms/djangoapps/badges/api/serializers.py b/lms/djangoapps/badges/api/serializers.py index 54e669e9ec..d1fcce25da 100644 --- a/lms/djangoapps/badges/api/serializers.py +++ b/lms/djangoapps/badges/api/serializers.py @@ -3,7 +3,7 @@ Serializers for Badges """ from rest_framework import serializers -from badges.models import BadgeClass, BadgeAssertion +from badges.models import BadgeAssertion, BadgeClass class BadgeClassSerializer(serializers.ModelSerializer): diff --git a/lms/djangoapps/badges/api/tests.py b/lms/djangoapps/badges/api/tests.py index 441c593eba..2078b50bec 100644 --- a/lms/djangoapps/badges/api/tests.py +++ b/lms/djangoapps/badges/api/tests.py @@ -1,7 +1,7 @@ """ Tests for the badges API views. """ -from ddt import ddt, data, unpack +from ddt import data, ddt, unpack from django.conf import settings from django.test.utils import override_settings from nose.plugins.attrib import attr diff --git a/lms/djangoapps/badges/api/views.py b/lms/djangoapps/badges/api/views.py index 3dd4a1de30..a9d1c8daf2 100644 --- a/lms/djangoapps/badges/api/views.py +++ b/lms/djangoapps/badges/api/views.py @@ -6,14 +6,14 @@ from opaque_keys.edx.keys import CourseKey from rest_framework import generics from rest_framework.exceptions import APIException +from badges.models import BadgeAssertion from openedx.core.djangoapps.user_api.permissions import is_field_shared_factory +from openedx.core.djangoapps.xmodule_django.models import CourseKeyField from openedx.core.lib.api.authentication import ( OAuth2AuthenticationAllowInactiveUser, SessionAuthenticationAllowInactiveUser ) -from openedx.core.djangoapps.xmodule_django.models import CourseKeyField -from badges.models import BadgeAssertion from .serializers import BadgeAssertionSerializer diff --git a/lms/djangoapps/badges/backends/badgr.py b/lms/djangoapps/badges/backends/badgr.py index d40efcf1c3..974534f397 100644 --- a/lms/djangoapps/badges/backends/badgr.py +++ b/lms/djangoapps/badges/backends/badgr.py @@ -12,9 +12,8 @@ from lazy import lazy from requests.packages.urllib3.exceptions import HTTPError from badges.backends.base import BadgeBackend -from eventtracking import tracker - from badges.models import BadgeAssertion +from eventtracking import tracker MAX_SLUG_LENGTH = 255 LOGGER = logging.getLogger(__name__) diff --git a/lms/djangoapps/badges/backends/tests/test_badgr_backend.py b/lms/djangoapps/badges/backends/tests/test_badgr_backend.py index ca79bf6c2b..13d5f857e4 100644 --- a/lms/djangoapps/badges/backends/tests/test_badgr_backend.py +++ b/lms/djangoapps/badges/backends/tests/test_badgr_backend.py @@ -7,13 +7,13 @@ import ddt from django.db.models.fields.files import ImageFieldFile from django.test.utils import override_settings from lazy.lazy import lazy -from mock import patch, Mock, call +from mock import Mock, call, patch from badges.backends.badgr import BadgrBackend from badges.models import BadgeAssertion from badges.tests.factories import BadgeClassFactory from openedx.core.lib.tests.assertions.events import assert_event_matches -from student.tests.factories import UserFactory, CourseEnrollmentFactory +from student.tests.factories import CourseEnrollmentFactory, UserFactory from track.tests import EventTrackingTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/lms/djangoapps/badges/events/course_complete.py b/lms/djangoapps/badges/events/course_complete.py index 6f531b2e64..24002771ae 100644 --- a/lms/djangoapps/badges/events/course_complete.py +++ b/lms/djangoapps/badges/events/course_complete.py @@ -8,8 +8,8 @@ from django.core.urlresolvers import reverse from django.template.defaultfilters import slugify from django.utils.translation import ugettext_lazy as _ -from badges.models import CourseCompleteImageConfiguration, BadgeClass, BadgeAssertion -from badges.utils import site_prefix, requires_badges_enabled +from badges.models import BadgeAssertion, BadgeClass, CourseCompleteImageConfiguration +from badges.utils import requires_badges_enabled, site_prefix from xmodule.modulestore.django import modulestore LOGGER = logging.getLogger(__name__) diff --git a/lms/djangoapps/badges/events/course_meta.py b/lms/djangoapps/badges/events/course_meta.py index e5bbb99c33..d300772ddc 100644 --- a/lms/djangoapps/badges/events/course_meta.py +++ b/lms/djangoapps/badges/events/course_meta.py @@ -3,7 +3,7 @@ Events which have to do with a user doing something with more than one course, s as enrolling in a certain number, completing a certain number, or completing a specific set of courses. """ -from badges.models import CourseEventBadgesConfiguration, BadgeClass +from badges.models import BadgeClass, CourseEventBadgesConfiguration from badges.utils import requires_badges_enabled diff --git a/lms/djangoapps/badges/events/tests/test_course_complete.py b/lms/djangoapps/badges/events/tests/test_course_complete.py index 0fb072ee80..bf6a8036c9 100644 --- a/lms/djangoapps/badges/events/tests/test_course_complete.py +++ b/lms/djangoapps/badges/events/tests/test_course_complete.py @@ -3,11 +3,10 @@ Tests for the course completion helper functions. """ from datetime import datetime -from student.tests.factories import UserFactory -from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase - from badges.events import course_complete +from student.tests.factories import UserFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class CourseCompleteTestCase(ModuleStoreTestCase): diff --git a/lms/djangoapps/badges/events/tests/test_course_meta.py b/lms/djangoapps/badges/events/tests/test_course_meta.py index 2183fd02c6..4b8eab2bdd 100644 --- a/lms/djangoapps/badges/events/tests/test_course_meta.py +++ b/lms/djangoapps/badges/events/tests/test_course_meta.py @@ -1,14 +1,13 @@ """ Tests the course meta badging events """ -from ddt import ddt, unpack, data +from ddt import data, ddt, unpack +from django.conf import settings from django.test.utils import override_settings from mock import patch -from django.conf import settings - -from badges.tests.factories import RandomBadgeClassFactory, CourseEventBadgesConfigurationFactory -from certificates.models import GeneratedCertificate, CertificateStatuses +from badges.tests.factories import CourseEventBadgesConfigurationFactory, RandomBadgeClassFactory +from certificates.models import CertificateStatuses, GeneratedCertificate from student.models import CourseEnrollment from student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase diff --git a/lms/djangoapps/badges/models.py b/lms/djangoapps/badges/models.py index 484e7cd110..19e763ba48 100644 --- a/lms/djangoapps/badges/models.py +++ b/lms/djangoapps/badges/models.py @@ -3,6 +3,7 @@ Database models for the badges app """ from importlib import import_module +from config_models.models import ConfigurationModel from django.conf import settings from django.contrib.auth.models import User from django.core.exceptions import ValidationError @@ -15,9 +16,8 @@ from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey from badges.utils import deserialize_count_specs -from config_models.models import ConfigurationModel -from xmodule.modulestore.django import modulestore from openedx.core.djangoapps.xmodule_django.models import CourseKeyField +from xmodule.modulestore.django import modulestore def validate_badge_image(image): diff --git a/lms/djangoapps/badges/tests/factories.py b/lms/djangoapps/badges/tests/factories.py index c625454a9b..0afb020b4f 100644 --- a/lms/djangoapps/badges/tests/factories.py +++ b/lms/djangoapps/badges/tests/factories.py @@ -8,7 +8,7 @@ from django.core.files.base import ContentFile from factory import DjangoModelFactory from factory.django import ImageField -from badges.models import BadgeAssertion, CourseCompleteImageConfiguration, BadgeClass, CourseEventBadgesConfiguration +from badges.models import BadgeAssertion, BadgeClass, CourseCompleteImageConfiguration, CourseEventBadgesConfiguration from student.tests.factories import UserFactory diff --git a/lms/djangoapps/badges/tests/test_models.py b/lms/djangoapps/badges/tests/test_models.py index fc56ab66b3..88e0a9bb6e 100644 --- a/lms/djangoapps/badges/tests/test_models.py +++ b/lms/djangoapps/badges/tests/test_models.py @@ -7,19 +7,21 @@ from django.core.files.storage import default_storage from django.db.utils import IntegrityError from django.test import TestCase from django.test.utils import override_settings -from mock import patch, Mock +from mock import Mock, patch from nose.plugins.attrib import attr -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase - -from xmodule.modulestore.tests.factories import CourseFactory from badges.models import ( - CourseCompleteImageConfiguration, validate_badge_image, BadgeClass, BadgeAssertion, - CourseBadgesDisabledError + BadgeAssertion, + BadgeClass, + CourseBadgesDisabledError, + CourseCompleteImageConfiguration, + validate_badge_image ) -from badges.tests.factories import BadgeClassFactory, BadgeAssertionFactory, RandomBadgeClassFactory +from badges.tests.factories import BadgeAssertionFactory, BadgeClassFactory, RandomBadgeClassFactory from certificates.tests.test_models import TEST_DATA_ROOT from student.tests.factories import UserFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory def get_image(name): diff --git a/lms/djangoapps/branding/admin.py b/lms/djangoapps/branding/admin.py index 4450174e16..851f57eca5 100644 --- a/lms/djangoapps/branding/admin.py +++ b/lms/djangoapps/branding/admin.py @@ -1,8 +1,8 @@ """Django admin pages for branding configuration. """ -from django.contrib import admin from config_models.admin import ConfigurationModelAdmin +from django.contrib import admin -from .models import BrandingInfoConfig, BrandingApiConfig +from .models import BrandingApiConfig, BrandingInfoConfig admin.site.register(BrandingInfoConfig, ConfigurationModelAdmin) admin.site.register(BrandingApiConfig, ConfigurationModelAdmin) diff --git a/lms/djangoapps/branding/api.py b/lms/djangoapps/branding/api.py index 88beae6b52..a3d5112c8e 100644 --- a/lms/djangoapps/branding/api.py +++ b/lms/djangoapps/branding/api.py @@ -16,14 +16,13 @@ import logging import urlparse from django.conf import settings -from django.utils.translation import ugettext as _ from django.contrib.staticfiles.storage import staticfiles_storage +from django.utils.translation import ugettext as _ -from edxmako.shortcuts import marketing_link from branding.models import BrandingApiConfig +from edxmako.shortcuts import marketing_link from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers - log = logging.getLogger("edx.footer") EMPTY_URL = '#' diff --git a/lms/djangoapps/branding/models.py b/lms/djangoapps/branding/models.py index 1dbed47bae..2626a55d04 100644 --- a/lms/djangoapps/branding/models.py +++ b/lms/djangoapps/branding/models.py @@ -6,9 +6,10 @@ Includes: use Branding. """ import json -from django.db.models import TextField -from django.core.exceptions import ValidationError + from config_models.models import ConfigurationModel +from django.core.exceptions import ValidationError +from django.db.models import TextField class BrandingInfoConfig(ConfigurationModel): diff --git a/lms/djangoapps/branding/tests/test_api.py b/lms/djangoapps/branding/tests/test_api.py index 5862bbbf1d..12e0ad47e3 100644 --- a/lms/djangoapps/branding/tests/test_api.py +++ b/lms/djangoapps/branding/tests/test_api.py @@ -2,12 +2,12 @@ """Tests of Branding API """ from __future__ import unicode_literals -from django.test import TestCase - import mock -from branding.api import get_logo_url, get_footer +from django.test import TestCase from django.test.utils import override_settings +from branding.api import get_footer, get_logo_url + class TestHeader(TestCase): """Test API end-point for retrieving the header. """ diff --git a/lms/djangoapps/branding/tests/test_models.py b/lms/djangoapps/branding/tests/test_models.py index a3d6c3fcae..1a00ab5241 100644 --- a/lms/djangoapps/branding/tests/test_models.py +++ b/lms/djangoapps/branding/tests/test_models.py @@ -1,8 +1,8 @@ """ Tests for the Video Branding configuration. """ -from django.test import TestCase from django.core.exceptions import ValidationError +from django.test import TestCase from nose.plugins.attrib import attr from branding.models import BrandingInfoConfig diff --git a/lms/djangoapps/branding/tests/test_page.py b/lms/djangoapps/branding/tests/test_page.py index 9db971d3b8..79f1b66b30 100644 --- a/lms/djangoapps/branding/tests/test_page.py +++ b/lms/djangoapps/branding/tests/test_page.py @@ -8,22 +8,21 @@ from django.conf import settings from django.contrib.auth.models import AnonymousUser from django.core.urlresolvers import reverse from django.http import HttpResponseRedirect -from django.test.utils import override_settings from django.test.client import RequestFactory -from mock import patch, Mock +from django.test.utils import override_settings +from milestones.tests.utils import MilestonesTestCaseMixin +from mock import Mock, patch from nose.plugins.attrib import attr from pytz import UTC -from edxmako.shortcuts import render_to_response from branding.views import index from courseware.tests.helpers import LoginEnrollmentTestCase -from milestones.tests.utils import MilestonesTestCaseMixin +from edxmako.shortcuts import render_to_response from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin from util.milestones_helpers import set_prerequisite_courses from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory - FEATURES_WITH_STARTDATE = settings.FEATURES.copy() FEATURES_WITH_STARTDATE['DISABLE_START_DATES'] = False FEATURES_WO_STARTDATE = settings.FEATURES.copy() diff --git a/lms/djangoapps/branding/tests/test_views.py b/lms/djangoapps/branding/tests/test_views.py index 0f123c2ad4..b08510c6be 100644 --- a/lms/djangoapps/branding/tests/test_views.py +++ b/lms/djangoapps/branding/tests/test_views.py @@ -2,14 +2,15 @@ """Tests of Branding API views. """ import json import urllib -from django.test import TestCase + +import ddt +import mock +from config_models.models import cache +from django.conf import settings from django.contrib.auth.models import User from django.core.urlresolvers import reverse -from django.conf import settings +from django.test import TestCase -import mock -import ddt -from config_models.models import cache from branding.models import BrandingApiConfig from openedx.core.djangoapps.dark_lang.models import DarkLangConfig from openedx.core.djangoapps.lang_pref.api import released_languages diff --git a/lms/djangoapps/branding/views.py b/lms/djangoapps/branding/views.py index c4f68cc53e..30fb3278aa 100644 --- a/lms/djangoapps/branding/views.py +++ b/lms/djangoapps/branding/views.py @@ -6,22 +6,21 @@ from django.conf import settings from django.contrib.staticfiles.storage import staticfiles_storage from django.core.cache import cache from django.core.urlresolvers import reverse -from django.http import HttpResponse, Http404 +from django.http import Http404, HttpResponse from django.shortcuts import redirect from django.utils import translation from django.utils.translation.trans_real import get_supported_language_variant from django.views.decorators.cache import cache_control from django.views.decorators.csrf import ensure_csrf_cookie -from edxmako.shortcuts import render_to_response -import student.views -import courseware.views.views -from edxmako.shortcuts import marketing_link -from util.cache import cache_if_anonymous -from util.json_request import JsonResponse import branding.api as branding_api +import courseware.views.views +import student.views +from edxmako.shortcuts import marketing_link, render_to_response from openedx.core.djangoapps.lang_pref.api import released_languages from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from util.cache import cache_if_anonymous +from util.json_request import JsonResponse log = logging.getLogger(__name__) diff --git a/lms/djangoapps/bulk_email/admin.py b/lms/djangoapps/bulk_email/admin.py index ac6937a7da..67043078ad 100644 --- a/lms/djangoapps/bulk_email/admin.py +++ b/lms/djangoapps/bulk_email/admin.py @@ -1,12 +1,11 @@ """ Django admin page for bulk email models """ +from config_models.admin import ConfigurationModelAdmin from django.contrib import admin -from config_models.admin import ConfigurationModelAdmin - -from bulk_email.models import CourseEmail, Optout, CourseEmailTemplate, CourseAuthorization, BulkEmailFlag -from bulk_email.forms import CourseEmailTemplateForm, CourseAuthorizationAdminForm +from bulk_email.forms import CourseAuthorizationAdminForm, CourseEmailTemplateForm +from bulk_email.models import BulkEmailFlag, CourseAuthorization, CourseEmail, CourseEmailTemplate, Optout class CourseEmailAdmin(admin.ModelAdmin): diff --git a/lms/djangoapps/bulk_email/forms.py b/lms/djangoapps/bulk_email/forms.py index 8b4ebb6c63..0b3097eebc 100644 --- a/lms/djangoapps/bulk_email/forms.py +++ b/lms/djangoapps/bulk_email/forms.py @@ -5,14 +5,13 @@ import logging from django import forms from django.core.exceptions import ValidationError - -from bulk_email.models import CourseEmailTemplate, COURSE_EMAIL_MESSAGE_BODY_TAG, CourseAuthorization - from opaque_keys import InvalidKeyError -from xmodule.modulestore.django import modulestore from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locations import SlashSeparatedCourseKey +from bulk_email.models import COURSE_EMAIL_MESSAGE_BODY_TAG, CourseAuthorization, CourseEmailTemplate +from xmodule.modulestore.django import modulestore + log = logging.getLogger(__name__) diff --git a/lms/djangoapps/bulk_email/models.py b/lms/djangoapps/bulk_email/models.py index 0f879735c5..5befaf9f44 100644 --- a/lms/djangoapps/bulk_email/models.py +++ b/lms/djangoapps/bulk_email/models.py @@ -2,24 +2,21 @@ Models for bulk email """ import logging -import markupsafe +import markupsafe +from config_models.models import ConfigurationModel from django.contrib.auth.models import User from django.db import models -from openedx.core.djangoapps.course_groups.models import CourseUserGroup -from openedx.core.djangoapps.course_groups.cohorts import get_cohort_by_name -from openedx.core.lib.html_to_text import html_to_text -from openedx.core.lib.mail_utils import wrap_message - -from config_models.models import ConfigurationModel from course_modes.models import CourseMode from enrollment.api import validate_course_mode from enrollment.errors import CourseModeNotFoundError -from student.roles import CourseStaffRole, CourseInstructorRole - +from openedx.core.djangoapps.course_groups.cohorts import get_cohort_by_name +from openedx.core.djangoapps.course_groups.models import CourseUserGroup from openedx.core.djangoapps.xmodule_django.models import CourseKeyField - +from openedx.core.lib.html_to_text import html_to_text +from openedx.core.lib.mail_utils import wrap_message +from student.roles import CourseInstructorRole, CourseStaffRole from util.keyword_substitution import substitute_keywords_with_data from util.query import use_read_replica_if_available diff --git a/lms/djangoapps/bulk_email/tasks.py b/lms/djangoapps/bulk_email/tasks.py index f64da3e29c..a5d99ca33c 100644 --- a/lms/djangoapps/bulk_email/tasks.py +++ b/lms/djangoapps/bulk_email/tasks.py @@ -3,52 +3,51 @@ This module contains celery task functions for handling the sending of bulk email to a course. """ -from collections import Counter import json import logging import random import re +from collections import Counter +from smtplib import SMTPConnectError, SMTPDataError, SMTPException, SMTPServerDisconnected from time import sleep -import dogstats_wrapper as dog_stats_api -from smtplib import SMTPServerDisconnected, SMTPDataError, SMTPConnectError, SMTPException -from boto.ses.exceptions import ( - SESAddressNotVerifiedError, - SESIdentityNotVerifiedError, - SESDomainNotConfirmedError, - SESAddressBlacklistedError, - SESDailyQuotaExceededError, - SESMaxSendingRateExceededError, - SESDomainEndsWithDotError, - SESLocalAddressCharacterError, - SESIllegalAddressError, -) from boto.exception import AWSConnectionError -from markupsafe import escape - -from celery import task, current_task # pylint: disable=no-name-in-module -from celery.states import SUCCESS, FAILURE, RETRY # pylint: disable=no-name-in-module, import-error +from boto.ses.exceptions import ( + SESAddressBlacklistedError, + SESAddressNotVerifiedError, + SESDailyQuotaExceededError, + SESDomainEndsWithDotError, + SESDomainNotConfirmedError, + SESIdentityNotVerifiedError, + SESIllegalAddressError, + SESLocalAddressCharacterError, + SESMaxSendingRateExceededError +) +from celery import current_task, task # pylint: disable=no-name-in-module from celery.exceptions import RetryTaskError # pylint: disable=no-name-in-module, import-error - +from celery.states import FAILURE, RETRY, SUCCESS # pylint: disable=no-name-in-module, import-error from django.conf import settings from django.contrib.auth.models import User from django.core.mail import EmailMultiAlternatives, get_connection from django.core.mail.message import forbid_multi_line_headers from django.core.urlresolvers import reverse -from django.utils.translation import override as override_language, ugettext as _ +from django.utils.translation import override as override_language +from django.utils.translation import ugettext as _ +from markupsafe import escape +import dogstats_wrapper as dog_stats_api from bulk_email.models import CourseEmail, Optout from courseware.courses import get_course -from openedx.core.lib.courses import course_image_url from lms.djangoapps.instructor_task.models import InstructorTask from lms.djangoapps.instructor_task.subtasks import ( SubtaskStatus, - queue_subtasks_for_query, check_subtask_is_valid, - update_subtask_status, + queue_subtasks_for_query, + update_subtask_status ) -from util.date_utils import get_default_time_display from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.lib.courses import course_image_url +from util.date_utils import get_default_time_display log = logging.getLogger('edx.celery.task') diff --git a/lms/djangoapps/bulk_email/tests/test_course_optout.py b/lms/djangoapps/bulk_email/tests/test_course_optout.py index d43d94d9e0..ae235c0cf5 100644 --- a/lms/djangoapps/bulk_email/tests/test_course_optout.py +++ b/lms/djangoapps/bulk_email/tests/test_course_optout.py @@ -3,18 +3,18 @@ Unit tests for student optouts from course email """ import json -from mock import patch, Mock -from nose.plugins.attrib import attr from django.core import mail from django.core.management import call_command from django.core.urlresolvers import reverse +from mock import Mock, patch +from nose.plugins.attrib import attr -from student.tests.factories import UserFactory, AdminFactory, CourseEnrollmentFactory +from bulk_email.models import BulkEmailFlag from student.models import CourseEnrollment +from student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from bulk_email.models import BulkEmailFlag @attr(shard=1) diff --git a/lms/djangoapps/bulk_email/tests/test_email.py b/lms/djangoapps/bulk_email/tests/test_email.py index ceb9e19b29..1b07e81b61 100644 --- a/lms/djangoapps/bulk_email/tests/test_email.py +++ b/lms/djangoapps/bulk_email/tests/test_email.py @@ -3,31 +3,31 @@ Unit tests for sending course email """ import json -from markupsafe import escape -from mock import patch, Mock -from nose.plugins.attrib import attr import os from unittest import skipIf -import ddt +import ddt from django.conf import settings from django.core import mail from django.core.mail.message import forbid_multi_line_headers -from django.core.urlresolvers import reverse from django.core.management import call_command +from django.core.urlresolvers import reverse from django.test.utils import override_settings from django.utils.translation import get_language +from markupsafe import escape +from mock import Mock, patch +from nose.plugins.attrib import attr -from bulk_email.models import Optout, BulkEmailFlag -from bulk_email.tasks import _get_source_address, _get_course_email_context -from openedx.core.djangoapps.course_groups.models import CourseCohort -from openedx.core.djangoapps.course_groups.cohorts import add_user_to_cohort +from bulk_email.models import BulkEmailFlag, Optout +from bulk_email.tasks import _get_course_email_context, _get_source_address from course_modes.models import CourseMode -from courseware.tests.factories import StaffFactory, InstructorFactory +from courseware.tests.factories import InstructorFactory, StaffFactory from enrollment.api import update_enrollment from lms.djangoapps.instructor_task.subtasks import update_subtask_status -from student.roles import CourseStaffRole +from openedx.core.djangoapps.course_groups.cohorts import add_user_to_cohort +from openedx.core.djangoapps.course_groups.models import CourseCohort from student.models import CourseEnrollment +from student.roles import CourseStaffRole from student.tests.factories import CourseEnrollmentFactory, UserFactory from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase diff --git a/lms/djangoapps/bulk_email/tests/test_err_handling.py b/lms/djangoapps/bulk_email/tests/test_err_handling.py index 5b277d24db..bad8c185d7 100644 --- a/lms/djangoapps/bulk_email/tests/test_err_handling.py +++ b/lms/djangoapps/bulk_email/tests/test_err_handling.py @@ -2,32 +2,32 @@ """ Unit tests for handling email sending errors """ +import json from itertools import cycle +from smtplib import SMTPConnectError, SMTPDataError, SMTPServerDisconnected -from celery.states import SUCCESS, RETRY # pylint: disable=no-name-in-module, import-error import ddt +from celery.states import RETRY, SUCCESS # pylint: disable=no-name-in-module, import-error from django.conf import settings from django.core.management import call_command from django.core.urlresolvers import reverse from django.db import DatabaseError -import json -from mock import patch, Mock +from mock import Mock, patch from nose.plugins.attrib import attr -from smtplib import SMTPDataError, SMTPServerDisconnected, SMTPConnectError +from opaque_keys.edx.locations import SlashSeparatedCourseKey -from bulk_email.models import CourseEmail, SEND_TO_MYSELF, BulkEmailFlag +from bulk_email.models import SEND_TO_MYSELF, BulkEmailFlag, CourseEmail from bulk_email.tasks import perform_delegate_email_batches, send_course_email from lms.djangoapps.instructor_task.exceptions import DuplicateTaskException from lms.djangoapps.instructor_task.models import InstructorTask from lms.djangoapps.instructor_task.subtasks import ( - initialize_subtask_info, + MAX_DATABASE_LOCK_RETRIES, SubtaskStatus, check_subtask_is_valid, - update_subtask_status, - MAX_DATABASE_LOCK_RETRIES, + initialize_subtask_info, + update_subtask_status ) -from opaque_keys.edx.locations import SlashSeparatedCourseKey -from student.tests.factories import UserFactory, AdminFactory, CourseEnrollmentFactory +from student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/lms/djangoapps/bulk_email/tests/test_forms.py b/lms/djangoapps/bulk_email/tests/test_forms.py index 7ea5771481..d36b93dacf 100644 --- a/lms/djangoapps/bulk_email/tests/test_forms.py +++ b/lms/djangoapps/bulk_email/tests/test_forms.py @@ -4,10 +4,10 @@ Unit tests for bulk-email-related forms. """ from nose.plugins.attrib import attr - -from bulk_email.models import CourseEmailTemplate, BulkEmailFlag -from bulk_email.forms import CourseAuthorizationAdminForm, CourseEmailTemplateForm from opaque_keys.edx.locations import SlashSeparatedCourseKey + +from bulk_email.forms import CourseAuthorizationAdminForm, CourseEmailTemplateForm +from bulk_email.models import BulkEmailFlag, CourseEmailTemplate from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/lms/djangoapps/bulk_email/tests/test_models.py b/lms/djangoapps/bulk_email/tests/test_models.py index 2886f58e86..89b51b511e 100644 --- a/lms/djangoapps/bulk_email/tests/test_models.py +++ b/lms/djangoapps/bulk_email/tests/test_models.py @@ -4,27 +4,27 @@ Unit tests for bulk-email-related models. import datetime import ddt -from bulk_email.models import ( - CourseEmail, - SEND_TO_COHORT, - SEND_TO_TRACK, - SEND_TO_STAFF, - CourseEmailTemplate, - CourseAuthorization, - BulkEmailFlag -) -from course_modes.models import CourseMode from django.core.management import call_command from django.test import TestCase -from mock import patch, Mock +from mock import Mock, patch from nose.plugins.attrib import attr from opaque_keys.edx.keys import CourseKey + +from bulk_email.models import ( + SEND_TO_COHORT, + SEND_TO_STAFF, + SEND_TO_TRACK, + BulkEmailFlag, + CourseAuthorization, + CourseEmail, + CourseEmailTemplate +) +from course_modes.models import CourseMode +from openedx.core.djangoapps.course_groups.models import CourseCohort from student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from openedx.core.djangoapps.course_groups.models import CourseCohort - @ddt.ddt @attr(shard=1) diff --git a/lms/djangoapps/bulk_email/tests/test_tasks.py b/lms/djangoapps/bulk_email/tests/test_tasks.py index f01d85eb33..b50796bd42 100644 --- a/lms/djangoapps/bulk_email/tests/test_tasks.py +++ b/lms/djangoapps/bulk_email/tests/test_tasks.py @@ -7,41 +7,38 @@ paths actually work. """ import json +from itertools import chain, cycle, repeat +from smtplib import SMTPAuthenticationError, SMTPConnectError, SMTPDataError, SMTPServerDisconnected from uuid import uuid4 -from itertools import cycle, chain, repeat -from mock import patch, Mock -from nose.plugins.attrib import attr -from smtplib import SMTPServerDisconnected, SMTPDataError, SMTPConnectError, SMTPAuthenticationError -from boto.ses.exceptions import ( - SESAddressNotVerifiedError, - SESIdentityNotVerifiedError, - SESDomainNotConfirmedError, - SESAddressBlacklistedError, - SESDailyQuotaExceededError, - SESMaxSendingRateExceededError, - SESDomainEndsWithDotError, - SESLocalAddressCharacterError, - SESIllegalAddressError, -) + from boto.exception import AWSConnectionError - -from celery.states import SUCCESS, FAILURE # pylint: disable=no-name-in-module, import-error - +from boto.ses.exceptions import ( + SESAddressBlacklistedError, + SESAddressNotVerifiedError, + SESDailyQuotaExceededError, + SESDomainEndsWithDotError, + SESDomainNotConfirmedError, + SESIdentityNotVerifiedError, + SESIllegalAddressError, + SESLocalAddressCharacterError, + SESMaxSendingRateExceededError +) +from celery.states import FAILURE, SUCCESS # pylint: disable=no-name-in-module, import-error from django.conf import settings from django.core.management import call_command - -from xmodule.modulestore.tests.factories import CourseFactory - -from bulk_email.models import CourseEmail, Optout, SEND_TO_MYSELF, SEND_TO_STAFF, SEND_TO_LEARNERS -from bulk_email.tasks import _get_course_email_context - -from lms.djangoapps.instructor_task.tasks import send_bulk_course_email -from lms.djangoapps.instructor_task.subtasks import update_subtask_status, SubtaskStatus -from lms.djangoapps.instructor_task.models import InstructorTask -from lms.djangoapps.instructor_task.tests.test_base import InstructorTaskCourseTestCase -from lms.djangoapps.instructor_task.tests.factories import InstructorTaskFactory +from mock import Mock, patch +from nose.plugins.attrib import attr from opaque_keys.edx.locations import SlashSeparatedCourseKey +from bulk_email.models import SEND_TO_LEARNERS, SEND_TO_MYSELF, SEND_TO_STAFF, CourseEmail, Optout +from bulk_email.tasks import _get_course_email_context +from lms.djangoapps.instructor_task.models import InstructorTask +from lms.djangoapps.instructor_task.subtasks import SubtaskStatus, update_subtask_status +from lms.djangoapps.instructor_task.tasks import send_bulk_course_email +from lms.djangoapps.instructor_task.tests.factories import InstructorTaskFactory +from lms.djangoapps.instructor_task.tests.test_base import InstructorTaskCourseTestCase +from xmodule.modulestore.tests.factories import CourseFactory + class TestTaskFailure(Exception): """Dummy exception used for unit tests.""" diff --git a/lms/djangoapps/ccx/api/urls.py b/lms/djangoapps/ccx/api/urls.py index 7a78eb0baf..ab19553bce 100644 --- a/lms/djangoapps/ccx/api/urls.py +++ b/lms/djangoapps/ccx/api/urls.py @@ -1,5 +1,5 @@ """ CCX API URLs. """ -from django.conf.urls import patterns, url, include +from django.conf.urls import include, patterns, url urlpatterns = patterns( '', diff --git a/lms/djangoapps/ccx/api/v0/serializers.py b/lms/djangoapps/ccx/api/v0/serializers.py index b376ef3fc6..f341d4d324 100644 --- a/lms/djangoapps/ccx/api/v0/serializers.py +++ b/lms/djangoapps/ccx/api/v0/serializers.py @@ -1,9 +1,9 @@ """ CCX API v0 Serializers. """ +from ccx_keys.locator import CCXLocator from rest_framework import serializers from lms.djangoapps.ccx.models import CustomCourseForEdX -from ccx_keys.locator import CCXLocator class CCXCourseSerializer(serializers.ModelSerializer): diff --git a/lms/djangoapps/ccx/api/v0/tests/test_views.py b/lms/djangoapps/ccx/api/v0/tests/test_views.py index 3060d8eb15..5aba864035 100644 --- a/lms/djangoapps/ccx/api/v0/tests/test_views.py +++ b/lms/djangoapps/ccx/api/v0/tests/test_views.py @@ -3,7 +3,6 @@ Tests for the CCX REST APIs. """ import json import math -import pytz import string import urllib import urlparse @@ -12,45 +11,31 @@ from itertools import izip import ddt import mock +import pytz +from ccx_keys.locator import CCXLocator from django.conf import settings from django.contrib.auth.models import User -from django.core.urlresolvers import ( - reverse, - resolve, - Resolver404 -) +from django.core.urlresolvers import Resolver404, resolve, reverse from nose.plugins.attrib import attr from oauth2_provider import models as dot_models +from opaque_keys.edx.keys import CourseKey from provider.constants import CONFIDENTIAL -from provider.oauth2.models import ( - Client, - Grant, -) +from provider.oauth2.models import Client, Grant from rest_framework import status from rest_framework.test import APITestCase from courseware import courses -from ccx_keys.locator import CCXLocator -from student.models import CourseEnrollment -from student.tests.factories import UserFactory -from lms.djangoapps.instructor.access import allow_access, list_with_level -from lms.djangoapps.instructor.enrollment import ( - enroll_email, - get_email_params, -) from lms.djangoapps.ccx.api.v0 import views from lms.djangoapps.ccx.models import CcxFieldOverride, CustomCourseForEdX from lms.djangoapps.ccx.overrides import override_field_for_ccx from lms.djangoapps.ccx.tests.utils import CcxTestCase -from lms.djangoapps.ccx.utils import get_course_chapters from lms.djangoapps.ccx.utils import ccx_course as ccx_course_cm -from opaque_keys.edx.keys import CourseKey -from student.roles import ( - CourseInstructorRole, - CourseCcxCoachRole, - CourseStaffRole, -) -from student.tests.factories import AdminFactory +from lms.djangoapps.ccx.utils import get_course_chapters +from lms.djangoapps.instructor.access import allow_access, list_with_level +from lms.djangoapps.instructor.enrollment import enroll_email, get_email_params +from student.models import CourseEnrollment +from student.roles import CourseCcxCoachRole, CourseInstructorRole, CourseStaffRole +from student.tests.factories import AdminFactory, UserFactory USER_PASSWORD = 'test' AUTH_ATTRS = ('auth', 'auth_header_oauth2_provider') diff --git a/lms/djangoapps/ccx/api/v0/urls.py b/lms/djangoapps/ccx/api/v0/urls.py index 92889c8955..8222601952 100644 --- a/lms/djangoapps/ccx/api/v0/urls.py +++ b/lms/djangoapps/ccx/api/v0/urls.py @@ -1,7 +1,7 @@ """ CCX API v0 URLs. """ from django.conf import settings -from django.conf.urls import patterns, url, include +from django.conf.urls import include, patterns, url from lms.djangoapps.ccx.api.v0 import views diff --git a/lms/djangoapps/ccx/api/v0/views.py b/lms/djangoapps/ccx/api/v0/views.py index 8b2c5cc93f..e543f4c75f 100644 --- a/lms/djangoapps/ccx/api/v0/views.py +++ b/lms/djangoapps/ccx/api/v0/views.py @@ -3,45 +3,36 @@ import datetime import json import logging -import pytz +import pytz +from ccx_keys.locator import CCXLocator from django.contrib.auth.models import User from django.db import transaction from django.http import Http404 +from edx_rest_framework_extensions.authentication import JwtAuthentication +from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey, UsageKey from rest_framework import status from rest_framework.generics import GenericAPIView from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response -from ccx_keys.locator import CCXLocator from courseware import courses -from xmodule.modulestore.django import SignalHandler -from edx_rest_framework_extensions.authentication import JwtAuthentication -from lms.djangoapps.instructor.enrollment import ( - enroll_email, - get_email_params, -) -from opaque_keys import InvalidKeyError -from opaque_keys.edx.keys import CourseKey, UsageKey -from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from openedx.core.lib.api import ( - authentication, - permissions, -) -from student.models import CourseEnrollment -from student.roles import CourseCcxCoachRole - - from lms.djangoapps.ccx.models import CcxFieldOverride, CustomCourseForEdX -from lms.djangoapps.ccx.overrides import ( - override_field_for_ccx, -) +from lms.djangoapps.ccx.overrides import override_field_for_ccx from lms.djangoapps.ccx.utils import ( add_master_course_staff_to_ccx, assign_staff_role_to_ccx, - is_email, get_course_chapters, + is_email ) +from lms.djangoapps.instructor.enrollment import enroll_email, get_email_params +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview +from openedx.core.lib.api import authentication, permissions +from student.models import CourseEnrollment +from student.roles import CourseCcxCoachRole +from xmodule.modulestore.django import SignalHandler + from .paginators import CCXAPIPagination from .serializers import CCXCourseSerializer diff --git a/lms/djangoapps/ccx/models.py b/lms/djangoapps/ccx/models.py index 8f8d596cbb..ce53399f43 100644 --- a/lms/djangoapps/ccx/models.py +++ b/lms/djangoapps/ccx/models.py @@ -2,21 +2,21 @@ Models for the custom course feature """ from __future__ import unicode_literals + import json import logging from datetime import datetime +from ccx_keys.locator import CCXLocator from django.contrib.auth.models import User from django.db import models -from pytz import utc from lazy import lazy +from pytz import utc -from ccx_keys.locator import CCXLocator from openedx.core.djangoapps.xmodule_django.models import CourseKeyField, LocationKeyField from xmodule.error_module import ErrorDescriptor from xmodule.modulestore.django import modulestore - log = logging.getLogger("edx.ccx") diff --git a/lms/djangoapps/ccx/modulestore.py b/lms/djangoapps/ccx/modulestore.py index 2b3b8cd627..85b2d4b9ad 100644 --- a/lms/djangoapps/ccx/modulestore.py +++ b/lms/djangoapps/ccx/modulestore.py @@ -11,8 +11,10 @@ version that was passed in. """ from contextlib import contextmanager from functools import partial -from ccx_keys.locator import CCXLocator, CCXBlockUsageLocator -from opaque_keys.edx.locator import CourseLocator, BlockUsageLocator + +from ccx_keys.locator import CCXBlockUsageLocator, CCXLocator +from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator + from xmodule.modulestore import XMODULE_FIELDS_WITH_USAGE_KEYS diff --git a/lms/djangoapps/ccx/overrides.py b/lms/djangoapps/ccx/overrides.py index 344135c9d8..9236418926 100644 --- a/lms/djangoapps/ccx/overrides.py +++ b/lms/djangoapps/ccx/overrides.py @@ -5,17 +5,14 @@ by the individual custom courses feature. import json import logging +from ccx_keys.locator import CCXBlockUsageLocator, CCXLocator from django.db import transaction +from opaque_keys.edx.keys import CourseKey, UsageKey import request_cache - from courseware.field_overrides import FieldOverrideProvider -from opaque_keys.edx.keys import CourseKey, UsageKey -from ccx_keys.locator import CCXLocator, CCXBlockUsageLocator - from lms.djangoapps.ccx.models import CcxFieldOverride, CustomCourseForEdX - log = logging.getLogger(__name__) diff --git a/lms/djangoapps/ccx/plugins.py b/lms/djangoapps/ccx/plugins.py index 44c42fb123..650c7bb7f2 100644 --- a/lms/djangoapps/ccx/plugins.py +++ b/lms/djangoapps/ccx/plugins.py @@ -5,9 +5,9 @@ Registers the CCX feature for the edX platform. from django.conf import settings from django.utils.translation import ugettext_noop -from xmodule.tabs import CourseTab -from student.roles import CourseCcxCoachRole from courseware.access import has_access +from student.roles import CourseCcxCoachRole +from xmodule.tabs import CourseTab class CcxCourseTab(CourseTab): diff --git a/lms/djangoapps/ccx/tasks.py b/lms/djangoapps/ccx/tasks.py index 2bb282125e..1f24d06d71 100644 --- a/lms/djangoapps/ccx/tasks.py +++ b/lms/djangoapps/ccx/tasks.py @@ -2,16 +2,16 @@ Asynchronous tasks for the CCX app. """ -from django.dispatch import receiver import logging +from ccx_keys.locator import CCXLocator +from django.dispatch import receiver from opaque_keys import InvalidKeyError from opaque_keys.edx.locator import CourseLocator -from ccx_keys.locator import CCXLocator -from xmodule.modulestore.django import SignalHandler -from lms import CELERY_APP +from lms import CELERY_APP from lms.djangoapps.ccx.models import CustomCourseForEdX +from xmodule.modulestore.django import SignalHandler log = logging.getLogger("edx.ccx") diff --git a/lms/djangoapps/ccx/tests/factories.py b/lms/djangoapps/ccx/tests/factories.py index df0039a120..07c05e793f 100644 --- a/lms/djangoapps/ccx/tests/factories.py +++ b/lms/djangoapps/ccx/tests/factories.py @@ -1,10 +1,11 @@ """ Dummy factories for tests """ -from factory import SubFactory, Sequence +from factory import Sequence, SubFactory from factory.django import DjangoModelFactory -from student.tests.factories import UserFactory + from lms.djangoapps.ccx.models import CustomCourseForEdX +from student.tests.factories import UserFactory class CcxFactory(DjangoModelFactory): # pylint: disable=missing-docstring diff --git a/lms/djangoapps/ccx/tests/test_ccx_modulestore.py b/lms/djangoapps/ccx/tests/test_ccx_modulestore.py index 81f1e0a154..c1c3f94d99 100644 --- a/lms/djangoapps/ccx/tests/test_ccx_modulestore.py +++ b/lms/djangoapps/ccx/tests/test_ccx_modulestore.py @@ -1,20 +1,17 @@ """ Test the CCXModulestoreWrapper """ -from collections import deque -from ccx_keys.locator import CCXLocator import datetime -from itertools import izip_longest, chain +from collections import deque +from itertools import chain, izip_longest + import pytz -from student.tests.factories import AdminFactory -from xmodule.modulestore.tests.django_utils import ( - SharedModuleStoreTestCase, - TEST_DATA_SPLIT_MODULESTORE -) -from student.tests.factories import UserFactory -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from ccx_keys.locator import CCXLocator from lms.djangoapps.ccx.models import CustomCourseForEdX +from student.tests.factories import AdminFactory, UserFactory +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory class TestCCXModulestoreWrapper(SharedModuleStoreTestCase): diff --git a/lms/djangoapps/ccx/tests/test_field_override_performance.py b/lms/djangoapps/ccx/tests/test_field_override_performance.py index 12bc086794..bc58cd7ebd 100644 --- a/lms/djangoapps/ccx/tests/test_field_override_performance.py +++ b/lms/djangoapps/ccx/tests/test_field_override_performance.py @@ -2,33 +2,37 @@ """ Performance tests for field overrides. """ -import ddt import itertools -import mock -from nose.plugins.skip import SkipTest - -from courseware.views.views import progress -from courseware.field_overrides import OverrideFieldData -from courseware.testutils import FieldOverrideTestMixin from datetime import datetime + +import ddt +import mock +from ccx_keys.locator import CCXLocator from django.conf import settings from django.core.cache import caches from django.test.client import RequestFactory from django.test.utils import override_settings from nose.plugins.attrib import attr +from nose.plugins.skip import SkipTest from opaque_keys.edx.keys import CourseKey from pytz import UTC +from xblock.core import XBlock + +from courseware.field_overrides import OverrideFieldData +from courseware.testutils import FieldOverrideTestMixin +from courseware.views.views import progress +from lms.djangoapps.ccx.tests.factories import CcxFactory +from openedx.core.djangoapps.content.block_structure.api import get_course_in_cache from request_cache.middleware import RequestCache from student.models import CourseEnrollment from student.tests.factories import UserFactory -from xblock.core import XBlock -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, \ - TEST_DATA_SPLIT_MODULESTORE, TEST_DATA_MONGO_MODULESTORE -from xmodule.modulestore.tests.factories import check_mongo_calls, CourseFactory, check_sum_of_calls +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_MONGO_MODULESTORE, + TEST_DATA_SPLIT_MODULESTORE, + ModuleStoreTestCase +) +from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls, check_sum_of_calls from xmodule.modulestore.tests.utils import ProceduralCourseTestMixin -from ccx_keys.locator import CCXLocator -from lms.djangoapps.ccx.tests.factories import CcxFactory -from openedx.core.djangoapps.content.block_structure.api import get_course_in_cache @attr(shard=3) diff --git a/lms/djangoapps/ccx/tests/test_models.py b/lms/djangoapps/ccx/tests/test_models.py index 5fdf7fed0e..d50d54cc2a 100644 --- a/lms/djangoapps/ccx/tests/test_models.py +++ b/lms/djangoapps/ccx/tests/test_models.py @@ -1,28 +1,20 @@ """ tests for the models """ -import ddt import json from datetime import datetime, timedelta + +import ddt from nose.plugins.attrib import attr from pytz import utc -from student.roles import CourseCcxCoachRole -from student.tests.factories import ( - AdminFactory, -) -from xmodule.modulestore.tests.django_utils import ( - ModuleStoreTestCase, - TEST_DATA_SPLIT_MODULESTORE -) -from xmodule.modulestore.tests.factories import ( - CourseFactory, - check_mongo_calls -) -from .factories import ( - CcxFactory, -) +from student.roles import CourseCcxCoachRole +from student.tests.factories import AdminFactory +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls + from ..overrides import override_field_for_ccx +from .factories import CcxFactory @ddt.ddt diff --git a/lms/djangoapps/ccx/tests/test_overrides.py b/lms/djangoapps/ccx/tests/test_overrides.py index 6110a74bf7..51ede06489 100644 --- a/lms/djangoapps/ccx/tests/test_overrides.py +++ b/lms/djangoapps/ccx/tests/test_overrides.py @@ -3,28 +3,25 @@ tests for overrides """ import datetime + import mock import pytz +from ccx_keys.locator import CCXLocator +from django.test.utils import override_settings from nose.plugins.attrib import attr -from ccx_keys.locator import CCXLocator from courseware.courses import get_course_by_id from courseware.field_overrides import OverrideFieldData from courseware.testutils import FieldOverrideTestMixin -from django.test.utils import override_settings +from lms.djangoapps.ccx.models import CustomCourseForEdX +from lms.djangoapps.ccx.overrides import override_field_for_ccx +from lms.djangoapps.ccx.tests.utils import flatten, iter_blocks from lms.djangoapps.courseware.tests.test_field_overrides import inject_field_overrides from request_cache.middleware import RequestCache from student.tests.factories import AdminFactory -from xmodule.modulestore.tests.django_utils import ( - SharedModuleStoreTestCase, - TEST_DATA_SPLIT_MODULESTORE) +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory -from lms.djangoapps.ccx.models import CustomCourseForEdX -from lms.djangoapps.ccx.overrides import override_field_for_ccx - -from lms.djangoapps.ccx.tests.utils import flatten, iter_blocks - @attr(shard=1) @override_settings( diff --git a/lms/djangoapps/ccx/tests/test_tasks.py b/lms/djangoapps/ccx/tests/test_tasks.py index 95e3030873..4bfe347fde 100644 --- a/lms/djangoapps/ccx/tests/test_tasks.py +++ b/lms/djangoapps/ccx/tests/test_tasks.py @@ -2,24 +2,18 @@ Tests for celery tasks defined in tasks module """ +from ccx_keys.locator import CCXLocator from mock_django import mock_signal_receiver -from lms.djangoapps.ccx.tests.factories import CcxFactory -from student.roles import CourseCcxCoachRole -from student.tests.factories import ( - AdminFactory, -) -from xmodule.modulestore.django import SignalHandler -from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.tests.django_utils import ( - ModuleStoreTestCase, - TEST_DATA_SPLIT_MODULESTORE) -from openedx.core.djangoapps.content.course_structures.models import CourseStructure -from openedx.core.djangoapps.content.course_overviews.models import CourseOverview - -from ccx_keys.locator import CCXLocator - from lms.djangoapps.ccx.tasks import send_ccx_course_published +from lms.djangoapps.ccx.tests.factories import CcxFactory +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview +from openedx.core.djangoapps.content.course_structures.models import CourseStructure +from student.roles import CourseCcxCoachRole +from student.tests.factories import AdminFactory +from xmodule.modulestore.django import SignalHandler +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class TestSendCCXCoursePublished(ModuleStoreTestCase): diff --git a/lms/djangoapps/ccx/tests/test_utils.py b/lms/djangoapps/ccx/tests/test_utils.py index 21ca542fea..2eef54c79d 100644 --- a/lms/djangoapps/ccx/tests/test_utils.py +++ b/lms/djangoapps/ccx/tests/test_utils.py @@ -1,40 +1,25 @@ """ test utils """ -import mock import uuid -from nose.plugins.attrib import attr from smtplib import SMTPException +import mock from ccx_keys.locator import CCXLocator -from student.roles import ( - CourseCcxCoachRole, - CourseInstructorRole, - CourseStaffRole, -) -from student.tests.factories import AdminFactory - -from student.models import CourseEnrollment, CourseEnrollmentException - -from xmodule.modulestore.tests.django_utils import ( - ModuleStoreTestCase, - TEST_DATA_SPLIT_MODULESTORE -) -from xmodule.modulestore.tests.factories import CourseFactory +from nose.plugins.attrib import attr from opaque_keys.edx.keys import CourseKey -from xmodule.modulestore.django import modulestore from lms.djangoapps.ccx import utils -from lms.djangoapps.instructor.access import ( - list_with_level, -) -from lms.djangoapps.ccx.utils import ( - add_master_course_staff_to_ccx, - ccx_course, - remove_master_course_staff_from_ccx -) from lms.djangoapps.ccx.tests.factories import CcxFactory from lms.djangoapps.ccx.tests.utils import CcxTestCase +from lms.djangoapps.ccx.utils import add_master_course_staff_to_ccx, ccx_course, remove_master_course_staff_from_ccx +from lms.djangoapps.instructor.access import list_with_level +from student.models import CourseEnrollment, CourseEnrollmentException +from student.roles import CourseCcxCoachRole, CourseInstructorRole, CourseStaffRole +from student.tests.factories import AdminFactory +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory @attr(shard=1) diff --git a/lms/djangoapps/ccx/tests/test_views.py b/lms/djangoapps/ccx/tests/test_views.py index 5ce7a24e24..b895a4294c 100644 --- a/lms/djangoapps/ccx/tests/test_views.py +++ b/lms/djangoapps/ccx/tests/test_views.py @@ -4,78 +4,52 @@ test views import datetime import json import re -import pytz -import ddt import urlparse + +import ddt +import pytz +from ccx_keys.locator import CCXLocator from dateutil.tz import tzutc -from mock import patch, MagicMock +from django.conf import settings +from django.core.urlresolvers import resolve, reverse +from django.test import RequestFactory +from django.test.utils import override_settings +from django.utils.timezone import UTC +from django.utils.translation import ugettext as _ +from mock import MagicMock, patch from nose.plugins.attrib import attr +from opaque_keys.edx.keys import CourseKey from capa.tests.response_xml_factory import StringResponseXMLFactory from courseware.courses import get_course_by_id +from courseware.tabs import get_course_tab_list from courseware.tests.factories import StudentModuleFactory from courseware.tests.helpers import LoginEnrollmentTestCase -from courseware.tabs import get_course_tab_list from courseware.testutils import FieldOverrideTestMixin from django_comment_client.utils import has_forum_access from django_comment_common.models import FORUM_ROLE_ADMINISTRATOR from django_comment_common.utils import are_permissions_roles_seeded -from lms.djangoapps.instructor.access import ( - allow_access, - list_with_level, -) - -from django.conf import settings -from django.core.urlresolvers import reverse, resolve -from django.utils.translation import ugettext as _ -from django.utils.timezone import UTC -from django.test.utils import override_settings -from django.test import RequestFactory from edxmako.shortcuts import render_to_response -from request_cache.middleware import RequestCache -from opaque_keys.edx.keys import CourseKey -from student.roles import ( - CourseCcxCoachRole, - CourseInstructorRole, - CourseStaffRole, -) -from student.models import ( - CourseEnrollment, - CourseEnrollmentAllowed, -) -from student.tests.factories import ( - AdminFactory, - CourseEnrollmentFactory, - UserFactory, -) - -from xmodule.x_module import XModuleMixin -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.tests.django_utils import ( - ModuleStoreTestCase, - SharedModuleStoreTestCase, - TEST_DATA_SPLIT_MODULESTORE) -from xmodule.modulestore.tests.factories import ( - CourseFactory, - ItemFactory, - SampleCourseFactory, -) -from ccx_keys.locator import CCXLocator - from lms.djangoapps.ccx.models import CustomCourseForEdX from lms.djangoapps.ccx.overrides import get_override_for_ccx, override_field_for_ccx from lms.djangoapps.ccx.tests.factories import CcxFactory -from lms.djangoapps.ccx.tests.utils import ( - CcxTestCase, - flatten, -) -from lms.djangoapps.ccx.utils import ( - ccx_course, - is_email, -) +from lms.djangoapps.ccx.tests.utils import CcxTestCase, flatten +from lms.djangoapps.ccx.utils import ccx_course, is_email from lms.djangoapps.ccx.views import get_date - +from lms.djangoapps.instructor.access import allow_access, list_with_level +from request_cache.middleware import RequestCache +from student.models import CourseEnrollment, CourseEnrollmentAllowed +from student.roles import CourseCcxCoachRole, CourseInstructorRole, CourseStaffRole +from student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory +from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_SPLIT_MODULESTORE, + ModuleStoreTestCase, + SharedModuleStoreTestCase +) +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, SampleCourseFactory +from xmodule.x_module import XModuleMixin def intercept_renderer(path, context): diff --git a/lms/djangoapps/ccx/tests/utils.py b/lms/djangoapps/ccx/tests/utils.py index 9a57400869..b0383fbf56 100644 --- a/lms/djangoapps/ccx/tests/utils.py +++ b/lms/djangoapps/ccx/tests/utils.py @@ -2,30 +2,17 @@ Test utils for CCX """ import datetime + import pytz - from django.conf import settings -from student.roles import ( - CourseCcxCoachRole, - CourseInstructorRole, - CourseStaffRole -) -from student.tests.factories import ( - UserFactory -) -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import ( - SharedModuleStoreTestCase, - TEST_DATA_SPLIT_MODULESTORE -) -from xmodule.modulestore.tests.factories import ( - CourseFactory, - ItemFactory, -) - from lms.djangoapps.ccx.overrides import override_field_for_ccx from lms.djangoapps.ccx.tests.factories import CcxFactory +from student.roles import CourseCcxCoachRole, CourseInstructorRole, CourseStaffRole +from student.tests.factories import UserFactory +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory class CcxTestCase(SharedModuleStoreTestCase): diff --git a/lms/djangoapps/ccx/urls.py b/lms/djangoapps/ccx/urls.py index f670749087..c3c19f13e5 100644 --- a/lms/djangoapps/ccx/urls.py +++ b/lms/djangoapps/ccx/urls.py @@ -3,7 +3,6 @@ URLs for the CCX Feature. """ from django.conf.urls import patterns, url - urlpatterns = patterns( '', url(r'^ccx_coach$', diff --git a/lms/djangoapps/ccx/utils.py b/lms/djangoapps/ccx/utils.py index 8aedb79653..279a6d54e9 100644 --- a/lms/djangoapps/ccx/utils.py +++ b/lms/djangoapps/ccx/utils.py @@ -5,40 +5,27 @@ Does not include any access control, be sure to check access before calling. """ import datetime import logging -import pytz from contextlib import contextmanager - -from django.contrib.auth.models import User -from django.core.exceptions import ValidationError -from django.utils.translation import ugettext as _ -from django.core.validators import validate_email -from django.core.urlresolvers import reverse from smtplib import SMTPException +import pytz +from django.contrib.auth.models import User +from django.core.exceptions import ValidationError +from django.core.urlresolvers import reverse +from django.core.validators import validate_email +from django.utils.translation import ugettext as _ + from courseware.courses import get_course_by_id -from lms.djangoapps.instructor.enrollment import ( - enroll_email, - get_email_params, - unenroll_email, -) -from lms.djangoapps.instructor.access import ( - allow_access, - list_with_level, - revoke_access, -) +from lms.djangoapps.ccx.custom_exception import CCXUserValidationException +from lms.djangoapps.ccx.models import CustomCourseForEdX +from lms.djangoapps.ccx.overrides import get_override_for_ccx +from lms.djangoapps.instructor.access import allow_access, list_with_level, revoke_access +from lms.djangoapps.instructor.enrollment import enroll_email, get_email_params, unenroll_email from lms.djangoapps.instructor.views.tools import get_student_from_identifier from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.content.course_structures.models import CourseStructure from student.models import CourseEnrollment, CourseEnrollmentException -from student.roles import ( - CourseCcxCoachRole, - CourseInstructorRole, - CourseStaffRole -) - -from lms.djangoapps.ccx.overrides import get_override_for_ccx -from lms.djangoapps.ccx.custom_exception import CCXUserValidationException -from lms.djangoapps.ccx.models import CustomCourseForEdX +from student.roles import CourseCcxCoachRole, CourseInstructorRole, CourseStaffRole log = logging.getLogger("edx.ccx") diff --git a/lms/djangoapps/ccx/views.py b/lms/djangoapps/ccx/views.py index 2a0d764457..80f9f96386 100644 --- a/lms/djangoapps/ccx/views.py +++ b/lms/djangoapps/ccx/views.py @@ -6,66 +6,55 @@ import datetime import functools import json import logging -import pytz - from copy import deepcopy from cStringIO import StringIO +import pytz +from ccx_keys.locator import CCXLocator from django.conf import settings -from django.core.urlresolvers import reverse -from django.http import ( - HttpResponse, - HttpResponseForbidden, -) from django.contrib import messages +from django.contrib.auth.models import User +from django.core.urlresolvers import reverse from django.db import transaction -from django.http import Http404 +from django.http import Http404, HttpResponse, HttpResponseForbidden from django.shortcuts import redirect from django.utils.translation import ugettext as _ from django.views.decorators.cache import cache_control from django.views.decorators.csrf import ensure_csrf_cookie -from django.contrib.auth.models import User +from opaque_keys.edx.keys import CourseKey from courseware.access import has_access from courseware.courses import get_course_by_id - from courseware.field_overrides import disable_overrides from django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, assign_role from django_comment_common.utils import seed_permissions_roles from edxmako.shortcuts import render_to_response -from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory -from opaque_keys.edx.keys import CourseKey -from ccx_keys.locator import CCXLocator -from student.roles import CourseCcxCoachRole -from student.models import CourseEnrollment -from xmodule.modulestore.django import SignalHandler - -from lms.djangoapps.instructor.views.api import _split_input_list -from lms.djangoapps.instructor.views.gradebook_api import get_grade_book_page -from lms.djangoapps.instructor.enrollment import ( - enroll_email, - get_email_params, -) - from lms.djangoapps.ccx.models import CustomCourseForEdX from lms.djangoapps.ccx.overrides import ( - get_override_for_ccx, - override_field_for_ccx, - clear_ccx_field_info_from_ccx_map, bulk_delete_ccx_override_fields, + clear_ccx_field_info_from_ccx_map, + get_override_for_ccx, + override_field_for_ccx ) from lms.djangoapps.ccx.utils import ( add_master_course_staff_to_ccx, assign_staff_role_to_ccx, ccx_course, ccx_students_enrolling_center, - get_ccx_for_coach, get_ccx_by_ccx_id, get_ccx_creation_dict, + get_ccx_for_coach, get_date, parse_date, - prep_course_for_grading, + prep_course_for_grading ) +from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory +from lms.djangoapps.instructor.enrollment import enroll_email, get_email_params +from lms.djangoapps.instructor.views.api import _split_input_list +from lms.djangoapps.instructor.views.gradebook_api import get_grade_book_page +from student.models import CourseEnrollment +from student.roles import CourseCcxCoachRole +from xmodule.modulestore.django import SignalHandler log = logging.getLogger(__name__) TODAY = datetime.datetime.today # for patching in tests diff --git a/lms/djangoapps/certificates/admin.py b/lms/djangoapps/certificates/admin.py index de71d0b6d1..076e28d39c 100644 --- a/lms/djangoapps/certificates/admin.py +++ b/lms/djangoapps/certificates/admin.py @@ -1,18 +1,19 @@ """ django admin pages for certificates models """ -from django.contrib import admin -from django import forms from config_models.admin import ConfigurationModelAdmin -from util.organizations_helpers import get_organizations +from django import forms +from django.contrib import admin + from certificates.models import ( CertificateGenerationConfiguration, CertificateGenerationCourseSetting, CertificateHtmlViewConfiguration, CertificateTemplate, CertificateTemplateAsset, - GeneratedCertificate, + GeneratedCertificate ) +from util.organizations_helpers import get_organizations class CertificateTemplateForm(forms.ModelForm): diff --git a/lms/djangoapps/certificates/api.py b/lms/djangoapps/certificates/api.py index 8a5d56f73b..8d0f1dc69f 100644 --- a/lms/djangoapps/certificates/api.py +++ b/lms/djangoapps/certificates/api.py @@ -8,16 +8,10 @@ import logging from django.conf import settings from django.core.urlresolvers import reverse -from eventtracking import tracker from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey from branding import api as branding_api -from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from xmodule.modulestore.django import modulestore -from openedx.core.djangoapps.xmodule_django.models import CourseKeyField -from util.organizations_helpers import get_course_organizations - from certificates.models import ( CertificateGenerationConfiguration, CertificateGenerationCourseSetting, @@ -27,10 +21,14 @@ from certificates.models import ( CertificateTemplateAsset, ExampleCertificateSet, GeneratedCertificate, - certificate_status_for_student, + certificate_status_for_student ) from certificates.queue import XQueueCertInterface - +from eventtracking import tracker +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview +from openedx.core.djangoapps.xmodule_django.models import CourseKeyField +from util.organizations_helpers import get_course_organizations +from xmodule.modulestore.django import modulestore log = logging.getLogger("edx.certificate") MODES = GeneratedCertificate.MODES diff --git a/lms/djangoapps/certificates/apis/urls.py b/lms/djangoapps/certificates/apis/urls.py index 2d45e3f712..1187761572 100644 --- a/lms/djangoapps/certificates/apis/urls.py +++ b/lms/djangoapps/certificates/apis/urls.py @@ -1,9 +1,5 @@ """ Certificates API URLs. """ -from django.conf.urls import ( - include, - patterns, - url, -) +from django.conf.urls import include, patterns, url urlpatterns = patterns( '', diff --git a/lms/djangoapps/certificates/apis/v0/urls.py b/lms/djangoapps/certificates/apis/v0/urls.py index f8ddd4cc17..66b28643b9 100644 --- a/lms/djangoapps/certificates/apis/v0/urls.py +++ b/lms/djangoapps/certificates/apis/v0/urls.py @@ -1,15 +1,10 @@ """ Certificates API v0 URLs. """ from django.conf import settings -from django.conf.urls import ( - include, - patterns, - url, -) +from django.conf.urls import include, patterns, url from lms.djangoapps.certificates.apis.v0 import views - CERTIFICATES_URLS = patterns( '', url( diff --git a/lms/djangoapps/certificates/apis/v0/views.py b/lms/djangoapps/certificates/apis/v0/views.py index 898112917c..ad57f093d5 100644 --- a/lms/djangoapps/certificates/apis/v0/views.py +++ b/lms/djangoapps/certificates/apis/v0/views.py @@ -1,6 +1,7 @@ """ API v0 views. """ import logging +from edx_rest_framework_extensions.authentication import JwtAuthentication from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey from rest_framework.generics import GenericAPIView @@ -8,11 +9,7 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from lms.djangoapps.certificates.api import get_certificate_for_user -from edx_rest_framework_extensions.authentication import JwtAuthentication -from openedx.core.lib.api import ( - authentication, - permissions, -) +from openedx.core.lib.api import authentication, permissions log = logging.getLogger(__name__) diff --git a/lms/djangoapps/certificates/management/commands/cert_whitelist.py b/lms/djangoapps/certificates/management/commands/cert_whitelist.py index ada927673d..8a668c5c37 100644 --- a/lms/djangoapps/certificates/management/commands/cert_whitelist.py +++ b/lms/djangoapps/certificates/management/commands/cert_whitelist.py @@ -3,13 +3,16 @@ Management command which sets or gets the certificate whitelist for a given user/course """ from __future__ import print_function -from django.core.management.base import BaseCommand, CommandError + from optparse import make_option + +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 opaque_keys.edx.locations import SlashSeparatedCourseKey + from certificates.models import CertificateWhitelist -from django.contrib.auth.models import User def get_user_from_identifier(identifier): diff --git a/lms/djangoapps/certificates/management/commands/create_fake_cert.py b/lms/djangoapps/certificates/management/commands/create_fake_cert.py index ed2c0a3c4f..b4c9514fef 100644 --- a/lms/djangoapps/certificates/management/commands/create_fake_cert.py +++ b/lms/djangoapps/certificates/management/commands/create_fake_cert.py @@ -10,12 +10,13 @@ Example usage: """ import logging -from django.core.management.base import BaseCommand, CommandError -from django.contrib.auth.models import User from optparse import make_option -from opaque_keys.edx.keys import CourseKey -from certificates.models import GeneratedCertificate, CertificateStatuses +from django.contrib.auth.models import User +from django.core.management.base import BaseCommand, CommandError +from opaque_keys.edx.keys import CourseKey + +from certificates.models import CertificateStatuses, GeneratedCertificate LOGGER = logging.getLogger(__name__) diff --git a/lms/djangoapps/certificates/management/commands/fix_ungraded_certs.py b/lms/djangoapps/certificates/management/commands/fix_ungraded_certs.py index a1c01e5df8..81dea83afa 100644 --- a/lms/djangoapps/certificates/management/commands/fix_ungraded_certs.py +++ b/lms/djangoapps/certificates/management/commands/fix_ungraded_certs.py @@ -1,15 +1,15 @@ """ Management command which fixes ungraded certificates for students """ -from django.core.management.base import BaseCommand import logging from optparse import make_option +from django.core.management.base import BaseCommand + from certificates.models import GeneratedCertificate from courseware import courses from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory - log = logging.getLogger(__name__) diff --git a/lms/djangoapps/certificates/management/commands/gen_cert_report.py b/lms/djangoapps/certificates/management/commands/gen_cert_report.py index 38f42876d8..6cc36ca1c4 100644 --- a/lms/djangoapps/certificates/management/commands/gen_cert_report.py +++ b/lms/djangoapps/certificates/management/commands/gen_cert_report.py @@ -2,14 +2,16 @@ Generate a report of certificate statuses """ -from django.core.management.base import BaseCommand, CommandError -from certificates.models import GeneratedCertificate -from django.contrib.auth.models import User from optparse import make_option + +from django.contrib.auth.models import User +from django.core.management.base import BaseCommand, CommandError +from django.db.models import Count from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locations import SlashSeparatedCourseKey -from django.db.models import Count + +from certificates.models import GeneratedCertificate class Command(BaseCommand): diff --git a/lms/djangoapps/certificates/management/commands/regenerate_user.py b/lms/djangoapps/certificates/management/commands/regenerate_user.py index 033aa9d4b2..ec3857ad30 100644 --- a/lms/djangoapps/certificates/management/commands/regenerate_user.py +++ b/lms/djangoapps/certificates/management/commands/regenerate_user.py @@ -1,8 +1,9 @@ """Django management command to force certificate regeneration for one user""" -import logging import copy +import logging from optparse import make_option + from django.contrib.auth.models import User from django.core.management.base import BaseCommand, CommandError from opaque_keys import InvalidKeyError @@ -10,8 +11,8 @@ from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locations import SlashSeparatedCourseKey from badges.events.course_complete import get_completion_badge -from xmodule.modulestore.django import modulestore from certificates.api import regenerate_user_certificates +from xmodule.modulestore.django import modulestore LOGGER = logging.getLogger(__name__) diff --git a/lms/djangoapps/certificates/management/commands/resubmit_error_certificates.py b/lms/djangoapps/certificates/management/commands/resubmit_error_certificates.py index 6a183effa7..efdbd146ea 100644 --- a/lms/djangoapps/certificates/management/commands/resubmit_error_certificates.py +++ b/lms/djangoapps/certificates/management/commands/resubmit_error_certificates.py @@ -18,14 +18,14 @@ Example usage: """ import logging from optparse import make_option -from django.core.management.base import BaseCommand, CommandError -from xmodule.modulestore.django import modulestore +from django.core.management.base import BaseCommand, CommandError from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey -from certificates import api as certs_api -from certificates.models import GeneratedCertificate, CertificateStatuses +from certificates import api as certs_api +from certificates.models import CertificateStatuses, GeneratedCertificate +from xmodule.modulestore.django import modulestore LOGGER = logging.getLogger(__name__) diff --git a/lms/djangoapps/certificates/management/commands/ungenerated_certs.py b/lms/djangoapps/certificates/management/commands/ungenerated_certs.py index 906bf85d84..b016848780 100644 --- a/lms/djangoapps/certificates/management/commands/ungenerated_certs.py +++ b/lms/djangoapps/certificates/management/commands/ungenerated_certs.py @@ -2,20 +2,20 @@ Management command to find all students that need certificates for courses that have finished, and put their cert requests on the queue. """ -import logging import datetime -from pytz import UTC -from django.core.management.base import BaseCommand, CommandError -from certificates.models import certificate_status_for_student -from certificates.api import generate_user_certificates -from django.contrib.auth.models import User +import logging from optparse import make_option + +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 opaque_keys.edx.locations import SlashSeparatedCourseKey -from xmodule.modulestore.django import modulestore -from certificates.models import CertificateStatuses +from pytz import UTC +from certificates.api import generate_user_certificates +from certificates.models import CertificateStatuses, certificate_status_for_student +from xmodule.modulestore.django import modulestore LOGGER = logging.getLogger(__name__) diff --git a/lms/djangoapps/certificates/models.py b/lms/djangoapps/certificates/models.py index 736a648959..3759456ee2 100644 --- a/lms/djangoapps/certificates/models.py +++ b/lms/djangoapps/certificates/models.py @@ -47,9 +47,10 @@ Eligibility: """ import json import logging +import os import uuid -import os +from config_models.models import ConfigurationModel from django.conf import settings from django.contrib.auth.models import User from django.core.exceptions import ValidationError @@ -60,15 +61,13 @@ from django.utils.translation import ugettext_lazy as _ from django_extensions.db.fields import CreationDateTimeField from model_utils import Choices from model_utils.models import TimeStampedModel -from openedx.core.djangoapps.signals.signals import COURSE_CERT_AWARDED - from badges.events.course_complete import course_badge_check from badges.events.course_meta import completion_check, course_group_check -from config_models.models import ConfigurationModel from lms.djangoapps.instructor_task.models import InstructorTask -from util.milestones_helpers import fulfill_course_milestone, is_prerequisite_courses_enabled +from openedx.core.djangoapps.signals.signals import COURSE_CERT_AWARDED from openedx.core.djangoapps.xmodule_django.models import CourseKeyField, NoneToEmptyManager +from util.milestones_helpers import fulfill_course_milestone, is_prerequisite_courses_enabled LOGGER = logging.getLogger(__name__) diff --git a/lms/djangoapps/certificates/queue.py b/lms/djangoapps/certificates/queue.py index 11b1452b7a..f168c93dba 100644 --- a/lms/djangoapps/certificates/queue.py +++ b/lms/djangoapps/certificates/queue.py @@ -1,33 +1,30 @@ """Interface for adding certificate generation tasks to the XQueue. """ import json -import random import logging -import lxml.html -from lxml.etree import XMLSyntaxError, ParserError +import random from uuid import uuid4 -from django.test.client import RequestFactory +import lxml.html from django.conf import settings from django.core.urlresolvers import reverse +from django.test.client import RequestFactory +from lxml.etree import ParserError, XMLSyntaxError from requests.auth import HTTPBasicAuth -from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory -from xmodule.modulestore.django import modulestore -from capa.xqueue_interface import XQueueInterface -from capa.xqueue_interface import make_xheader, make_hashkey -from course_modes.models import CourseMode -from student.models import UserProfile, CourseEnrollment -from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification - +from capa.xqueue_interface import XQueueInterface, make_hashkey, make_xheader +from certificates.models import CertificateStatuses as status from certificates.models import ( CertificateStatuses, - GeneratedCertificate, - certificate_status_for_student, - CertificateStatuses as status, CertificateWhitelist, - ExampleCertificate + ExampleCertificate, + GeneratedCertificate, + certificate_status_for_student ) - +from course_modes.models import CourseMode +from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory +from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification +from student.models import CourseEnrollment, UserProfile +from xmodule.modulestore.django import modulestore LOGGER = logging.getLogger(__name__) diff --git a/lms/djangoapps/certificates/signals.py b/lms/djangoapps/certificates/signals.py index 4cab739d5f..5334df7a36 100644 --- a/lms/djangoapps/certificates/signals.py +++ b/lms/djangoapps/certificates/signals.py @@ -3,9 +3,9 @@ for self-paced courses. """ from celery.task import task from django.dispatch.dispatcher import receiver +from opaque_keys.edx.keys import CourseKey from certificates.models import CertificateGenerationCourseSetting -from opaque_keys.edx.keys import CourseKey from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from xmodule.modulestore.django import SignalHandler diff --git a/lms/djangoapps/certificates/tests/factories.py b/lms/djangoapps/certificates/tests/factories.py index d0297ddff3..ab893b1fee 100644 --- a/lms/djangoapps/certificates/tests/factories.py +++ b/lms/djangoapps/certificates/tests/factories.py @@ -5,8 +5,11 @@ from uuid import uuid4 from factory.django import DjangoModelFactory from certificates.models import ( - GeneratedCertificate, CertificateStatuses, CertificateHtmlViewConfiguration, CertificateWhitelist, + CertificateHtmlViewConfiguration, CertificateInvalidation, + CertificateStatuses, + CertificateWhitelist, + GeneratedCertificate ) from student.models import LinkedInAddToProfileConfiguration diff --git a/lms/djangoapps/certificates/tests/test_api.py b/lms/djangoapps/certificates/tests/test_api.py index e5f0d145f7..82a86ae868 100644 --- a/lms/djangoapps/certificates/tests/test_api.py +++ b/lms/djangoapps/certificates/tests/test_api.py @@ -1,20 +1,30 @@ """Tests for the certificates Python API. """ -from contextlib import contextmanager -import ddt -from functools import wraps import uuid +from contextlib import contextmanager +from functools import wraps -from django.test import TestCase, RequestFactory -from django.test.utils import override_settings +import ddt +from config_models.models import cache from django.conf import settings from django.core.urlresolvers import reverse +from django.test import RequestFactory, TestCase +from django.test.utils import override_settings from django.utils import timezone from freezegun import freeze_time from mock import patch from nose.plugins.attrib import attr from opaque_keys.edx.locator import CourseLocator -from config_models.models import cache +from certificates import api as certs_api +from certificates.models import ( + CertificateGenerationConfiguration, + CertificateStatuses, + ExampleCertificate, + GeneratedCertificate, + certificate_status_for_student +) +from certificates.queue import XQueueAddToQueueError, XQueueCertInterface +from certificates.tests.factories import CertificateInvalidationFactory, GeneratedCertificateFactory from course_modes.models import CourseMode from course_modes.tests.factories import CourseModeFactory from courseware.tests.factories import GlobalStaffFactory @@ -23,26 +33,8 @@ from microsite_configuration import microsite from student.models import CourseEnrollment from student.tests.factories import UserFactory from util.testing import EventTestMixin +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.tests.django_utils import ( - ModuleStoreTestCase, - SharedModuleStoreTestCase, -) - -from certificates import api as certs_api -from certificates.models import ( - CertificateStatuses, - CertificateGenerationConfiguration, - ExampleCertificate, - GeneratedCertificate, - certificate_status_for_student, -) -from certificates.queue import XQueueCertInterface, XQueueAddToQueueError -from certificates.tests.factories import ( - CertificateInvalidationFactory, - GeneratedCertificateFactory -) - FEATURES_WITH_CERTS_ENABLED = settings.FEATURES.copy() FEATURES_WITH_CERTS_ENABLED['CERTIFICATES_HTML_VIEW'] = True diff --git a/lms/djangoapps/certificates/tests/test_cert_management.py b/lms/djangoapps/certificates/tests/test_cert_management.py index 3a8849d1ab..5ec7f56342 100644 --- a/lms/djangoapps/certificates/tests/test_cert_management.py +++ b/lms/djangoapps/certificates/tests/test_cert_management.py @@ -1,22 +1,21 @@ """Tests for the resubmit_error_certificates management command. """ import ddt from django.core.management.base import CommandError -from nose.plugins.attrib import attr from django.test.utils import override_settings from mock import patch - -from course_modes.models import CourseMode +from nose.plugins.attrib import attr from opaque_keys.edx.locator import CourseLocator from badges.events.course_complete import get_completion_badge from badges.models import BadgeAssertion from badges.tests.factories import BadgeAssertionFactory, CourseCompleteImageConfigurationFactory +from certificates.management.commands import regenerate_user, resubmit_error_certificates, ungenerated_certs +from certificates.models import CertificateStatuses, GeneratedCertificate +from course_modes.models import CourseMode from lms.djangoapps.grades.tests.utils import mock_passing_grade +from student.tests.factories import CourseEnrollmentFactory, UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls, ItemFactory -from student.tests.factories import UserFactory, CourseEnrollmentFactory -from certificates.management.commands import resubmit_error_certificates, regenerate_user, ungenerated_certs -from certificates.models import GeneratedCertificate, CertificateStatuses +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls class CertificateManagementTest(ModuleStoreTestCase): diff --git a/lms/djangoapps/certificates/tests/test_create_fake_cert.py b/lms/djangoapps/certificates/tests/test_create_fake_cert.py index 860447ff07..71b5da394b 100644 --- a/lms/djangoapps/certificates/tests/test_create_fake_cert.py +++ b/lms/djangoapps/certificates/tests/test_create_fake_cert.py @@ -1,12 +1,12 @@ """Tests for the create_fake_certs management command. """ -from django.test import TestCase from django.core.management.base import CommandError +from django.test import TestCase from nose.plugins.attrib import attr - from opaque_keys.edx.locator import CourseLocator -from student.tests.factories import UserFactory + from certificates.management.commands import create_fake_cert from certificates.models import GeneratedCertificate +from student.tests.factories import UserFactory @attr(shard=1) diff --git a/lms/djangoapps/certificates/tests/test_models.py b/lms/djangoapps/certificates/tests/test_models.py index 928b5086e1..74399de1db 100644 --- a/lms/djangoapps/certificates/tests/test_models.py +++ b/lms/djangoapps/certificates/tests/test_models.py @@ -1,31 +1,29 @@ """Tests for certificate Django models. """ +import json + import ddt from django.conf import settings from django.core.exceptions import ValidationError from django.core.files.uploadedfile import SimpleUploadedFile from django.test import TestCase from django.test.utils import override_settings -from nose.plugins.attrib import attr -import json from mock import Mock +from nose.plugins.attrib import attr +from opaque_keys.edx.locator import CourseLocator from path import Path as path from certificates.models import ( + CertificateGenerationHistory, + CertificateHtmlViewConfiguration, + CertificateInvalidation, + CertificateStatuses, + CertificateTemplateAsset, ExampleCertificate, ExampleCertificateSet, - CertificateHtmlViewConfiguration, - CertificateTemplateAsset, - CertificateInvalidation, - GeneratedCertificate, - CertificateStatuses, - CertificateGenerationHistory, -) -from certificates.tests.factories import ( - CertificateInvalidationFactory, - GeneratedCertificateFactory + GeneratedCertificate ) +from certificates.tests.factories import CertificateInvalidationFactory, GeneratedCertificateFactory from lms.djangoapps.instructor_task.tests.factories import InstructorTaskFactory -from opaque_keys.edx.locator import CourseLocator from student.tests.factories import AdminFactory, UserFactory from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/lms/djangoapps/certificates/tests/test_queue.py b/lms/djangoapps/certificates/tests/test_queue.py index 0b21f652cd..dbc84cf6a4 100644 --- a/lms/djangoapps/certificates/tests/test_queue.py +++ b/lms/djangoapps/certificates/tests/test_queue.py @@ -1,24 +1,17 @@ # -*- coding: utf-8 -*- """Tests for the XQueue certificates interface. """ +import json from contextlib import contextmanager from datetime import datetime, timedelta -import ddt -import json -from mock import patch, Mock -from nose.plugins.attrib import attr -from django.test import TestCase -from django.test.utils import override_settings +import ddt import freezegun import pytz - -from course_modes.models import CourseMode -from lms.djangoapps.grades.tests.utils import mock_passing_grade +from django.test import TestCase +from django.test.utils import override_settings +from mock import Mock, patch +from nose.plugins.attrib import attr from opaque_keys.edx.locator import CourseLocator -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from student.tests.factories import UserFactory, CourseEnrollmentFactory -from xmodule.modulestore.tests.factories import CourseFactory - # It is really unfortunate that we are using the XQueue client # code from the capa library. In the future, we should move this @@ -26,16 +19,15 @@ from xmodule.modulestore.tests.factories import CourseFactory # and verify that items are being correctly added to the queue # in our `XQueueCertInterface` implementation. from capa.xqueue_interface import XQueueInterface - -from certificates.models import ( - ExampleCertificateSet, - ExampleCertificate, - GeneratedCertificate, - CertificateStatuses, -) +from certificates.models import CertificateStatuses, ExampleCertificate, ExampleCertificateSet, GeneratedCertificate from certificates.queue import XQueueCertInterface from certificates.tests.factories import CertificateWhitelistFactory, GeneratedCertificateFactory +from course_modes.models import CourseMode +from lms.djangoapps.grades.tests.utils import mock_passing_grade from lms.djangoapps.verify_student.tests.factories import SoftwareSecurePhotoVerificationFactory +from student.tests.factories import CourseEnrollmentFactory, UserFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory @ddt.ddt diff --git a/lms/djangoapps/certificates/tests/test_signals.py b/lms/djangoapps/certificates/tests/test_signals.py index 7e27c496b0..2bfcaa81fe 100644 --- a/lms/djangoapps/certificates/tests/test_signals.py +++ b/lms/djangoapps/certificates/tests/test_signals.py @@ -5,8 +5,8 @@ from certificates import api as certs_api from certificates.models import CertificateGenerationConfiguration from certificates.signals import _listen_for_course_publish from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration -from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class SelfGeneratedCertsSignalTest(ModuleStoreTestCase): diff --git a/lms/djangoapps/certificates/tests/test_support_views.py b/lms/djangoapps/certificates/tests/test_support_views.py index ba68f7ad29..ae7831061c 100644 --- a/lms/djangoapps/certificates/tests/test_support_views.py +++ b/lms/djangoapps/certificates/tests/test_support_views.py @@ -8,17 +8,13 @@ import ddt from django.conf import settings from django.core.urlresolvers import reverse from django.test.utils import override_settings - -from certificates.models import ( - CertificateInvalidation, - CertificateStatuses, - GeneratedCertificate -) -from certificates.tests.factories import CertificateInvalidationFactory from opaque_keys.edx.keys import CourseKey -from student.tests.factories import UserFactory + +from certificates.models import CertificateInvalidation, CertificateStatuses, GeneratedCertificate +from certificates.tests.factories import CertificateInvalidationFactory from student.models import CourseEnrollment from student.roles import GlobalStaff, SupportStaffRole +from student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/lms/djangoapps/certificates/tests/test_views.py b/lms/djangoapps/certificates/tests/test_views.py index 6ccab264ae..3a9438a8ed 100644 --- a/lms/djangoapps/certificates/tests/test_views.py +++ b/lms/djangoapps/certificates/tests/test_views.py @@ -11,15 +11,15 @@ from django.test.client import Client from django.test.utils import override_settings from nose.plugins.attrib import attr from opaque_keys.edx.locator import CourseLocator -from openedx.core.djangolib.testing.utils import CacheIsolationTestCase from certificates.api import get_certificate_url from certificates.models import ( - ExampleCertificateSet, - ExampleCertificate, - GeneratedCertificate, CertificateHtmlViewConfiguration, + ExampleCertificate, + ExampleCertificateSet, + GeneratedCertificate ) +from openedx.core.djangolib.testing.utils import CacheIsolationTestCase from student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/lms/djangoapps/certificates/tests/test_webview_views.py b/lms/djangoapps/certificates/tests/test_webview_views.py index b6f6402af4..da8646fd28 100644 --- a/lms/djangoapps/certificates/tests/test_webview_views.py +++ b/lms/djangoapps/certificates/tests/test_webview_views.py @@ -2,49 +2,47 @@ """Tests for certificates views. """ import json -import ddt -from uuid import uuid4 -from nose.plugins.attrib import attr -from mock import patch -from urllib import urlencode from collections import OrderedDict +from urllib import urlencode +from uuid import uuid4 +import ddt from django.conf import settings from django.core.urlresolvers import reverse from django.test.client import Client, RequestFactory from django.test.utils import override_settings +from mock import patch +from nose.plugins.attrib import attr +from certificates.api import get_certificate_url +from certificates.models import ( + CertificateHtmlViewConfiguration, + CertificateSocialNetworks, + CertificateStatuses, + CertificateTemplate, + CertificateTemplateAsset, + GeneratedCertificate +) +from certificates.tests.factories import ( + CertificateHtmlViewConfigurationFactory, + GeneratedCertificateFactory, + LinkedInAddToProfileConfigurationFactory +) from course_modes.models import CourseMode from lms.djangoapps.badges.events.course_complete import get_completion_badge from lms.djangoapps.badges.tests.factories import ( BadgeAssertionFactory, - CourseCompleteImageConfigurationFactory, BadgeClassFactory, + CourseCompleteImageConfigurationFactory ) from lms.djangoapps.grades.tests.utils import mock_passing_grade from openedx.core.lib.tests.assertions.events import assert_event_matches -from student.tests.factories import UserFactory, CourseEnrollmentFactory from student.roles import CourseStaffRole +from student.tests.factories import CourseEnrollmentFactory, UserFactory from track.tests import EventTrackingTestCase from util import organizations_helpers as organizations_api -from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase - -from certificates.api import get_certificate_url -from certificates.models import ( - GeneratedCertificate, - CertificateStatuses, - CertificateSocialNetworks, - CertificateTemplate, - CertificateHtmlViewConfiguration, - CertificateTemplateAsset, -) - -from certificates.tests.factories import ( - CertificateHtmlViewConfigurationFactory, - LinkedInAddToProfileConfigurationFactory, - GeneratedCertificateFactory, -) +from xmodule.modulestore.tests.factories import CourseFactory FEATURES_WITH_CERTS_ENABLED = settings.FEATURES.copy() FEATURES_WITH_CERTS_ENABLED['CERTIFICATES_HTML_VIEW'] = True diff --git a/lms/djangoapps/certificates/tests/tests.py b/lms/djangoapps/certificates/tests/tests.py index fb82ce92c5..6b997d0ccc 100644 --- a/lms/djangoapps/certificates/tests/tests.py +++ b/lms/djangoapps/certificates/tests/tests.py @@ -1,29 +1,24 @@ """ Tests for the certificates models. """ -from ddt import ddt, data, unpack -from mock import patch +from ddt import data, ddt, unpack from django.conf import settings +from milestones.tests.utils import MilestonesTestCaseMixin +from mock import patch from nose.plugins.attrib import attr from badges.tests.factories import CourseCompleteImageConfigurationFactory -from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase - -from student.tests.factories import UserFactory, CourseEnrollmentFactory from certificates.models import ( CertificateStatuses, GeneratedCertificate, - certificate_status_for_student, - certificate_info_for_user + certificate_info_for_user, + certificate_status_for_student ) from certificates.tests.factories import GeneratedCertificateFactory - -from util.milestones_helpers import ( - set_prerequisite_courses, - milestones_achieved_by_user, -) -from milestones.tests.utils import MilestonesTestCaseMixin +from student.tests.factories import CourseEnrollmentFactory, UserFactory +from util.milestones_helpers import milestones_achieved_by_user, set_prerequisite_courses +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory @attr(shard=1) diff --git a/lms/djangoapps/certificates/urls.py b/lms/djangoapps/certificates/urls.py index b5c4687294..7889f0cefd 100644 --- a/lms/djangoapps/certificates/urls.py +++ b/lms/djangoapps/certificates/urls.py @@ -2,8 +2,8 @@ URLs for the certificates app. """ -from django.conf.urls import patterns, url from django.conf import settings +from django.conf.urls import patterns, url from certificates import views diff --git a/lms/djangoapps/certificates/views/support.py b/lms/djangoapps/certificates/views/support.py index dc879b10f2..e40c913deb 100644 --- a/lms/djangoapps/certificates/views/support.py +++ b/lms/djangoapps/certificates/views/support.py @@ -8,29 +8,23 @@ import logging import urllib from functools import wraps -from django.http import ( - HttpResponse, - HttpResponseBadRequest, - HttpResponseForbidden, - HttpResponseServerError -) -from django.views.decorators.http import require_GET, require_POST from django.db import transaction from django.db.models import Q +from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseServerError from django.utils.translation import ugettext as _ +from django.views.decorators.http import require_GET, require_POST +from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey from certificates import api from certificates.models import CertificateInvalidation from courseware.access import has_access from lms.djangoapps.instructor_task.api import generate_certificates_for_students -from opaque_keys import InvalidKeyError -from opaque_keys.edx.keys import CourseKey from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from student.models import User, CourseEnrollment +from student.models import CourseEnrollment, User from util.json_request import JsonResponse from xmodule.modulestore.django import modulestore - log = logging.getLogger(__name__) diff --git a/lms/djangoapps/certificates/views/webview.py b/lms/djangoapps/certificates/views/webview.py index 614df97320..2aaec8b799 100644 --- a/lms/djangoapps/certificates/views/webview.py +++ b/lms/djangoapps/certificates/views/webview.py @@ -2,49 +2,49 @@ """ Certificate HTML webview. """ -from datetime import datetime -from uuid import uuid4 import logging import urllib +from datetime import datetime +from uuid import uuid4 from django.conf import settings from django.contrib.auth.models import User -from django.http import HttpResponse, Http404 +from django.http import Http404, HttpResponse from django.template import RequestContext -from django.utils.translation import ugettext as _ from django.utils.encoding import smart_str +from django.utils.translation import ugettext as _ +from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey from badges.events.course_complete import get_completion_badge from badges.utils import badges_enabled +from certificates.api import ( + emit_certificate_event, + get_active_web_certificate, + get_certificate_footer_context, + get_certificate_header_context, + get_certificate_template, + get_certificate_url, + has_html_certificates_enabled +) +from certificates.models import ( + CertificateHtmlViewConfiguration, + CertificateSocialNetworks, + CertificateStatuses, + GeneratedCertificate +) from courseware.access import has_access from edxmako.shortcuts import render_to_response from edxmako.template import Template from eventtracking import tracker -from opaque_keys import InvalidKeyError -from opaque_keys.edx.keys import CourseKey -from openedx.core.lib.courses import course_image_url from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.lib.courses import course_image_url from student.models import LinkedInAddToProfileConfiguration from util import organizations_helpers as organization_api from util.views import handle_500 from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError -from certificates.api import ( - get_active_web_certificate, - get_certificate_url, - emit_certificate_event, - has_html_certificates_enabled, - get_certificate_template, - get_certificate_header_context, - get_certificate_footer_context, -) -from certificates.models import ( - GeneratedCertificate, - CertificateStatuses, - CertificateHtmlViewConfiguration, - CertificateSocialNetworks) - log = logging.getLogger(__name__) diff --git a/lms/djangoapps/certificates/views/xqueue.py b/lms/djangoapps/certificates/views/xqueue.py index 7bdeef6975..ce13ed5bf6 100644 --- a/lms/djangoapps/certificates/views/xqueue.py +++ b/lms/djangoapps/certificates/views/xqueue.py @@ -6,24 +6,23 @@ import logging from django.contrib.auth.models import User from django.db import transaction -from django.http import HttpResponse, Http404, HttpResponseForbidden +from django.http import Http404, HttpResponse, HttpResponseForbidden from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST -import dogstats_wrapper as dog_stats_api - -from capa.xqueue_interface import XQUEUE_METRIC_NAME -from xmodule.modulestore.django import modulestore from opaque_keys.edx.locations import SlashSeparatedCourseKey -from util.json_request import JsonResponse, JsonResponseBadRequest -from util.bad_request_rate_limiter import BadRequestRateLimiter + +import dogstats_wrapper as dog_stats_api +from capa.xqueue_interface import XQUEUE_METRIC_NAME from certificates.api import generate_user_certificates from certificates.models import ( - certificate_status_for_student, CertificateStatuses, - GeneratedCertificate, ExampleCertificate, + GeneratedCertificate, + certificate_status_for_student ) - +from util.bad_request_rate_limiter import BadRequestRateLimiter +from util.json_request import JsonResponse, JsonResponseBadRequest +from xmodule.modulestore.django import modulestore log = logging.getLogger(__name__) diff --git a/lms/djangoapps/class_dashboard/dashboard_data.py b/lms/djangoapps/class_dashboard/dashboard_data.py index 6d059ac135..f078258664 100644 --- a/lms/djangoapps/class_dashboard/dashboard_data.py +++ b/lms/djangoapps/class_dashboard/dashboard_data.py @@ -1,18 +1,17 @@ """ Computes the data to display on the Instructor Dashboard """ -from util.json_request import JsonResponse import json -from courseware import models from django.db.models import Count from django.utils.translation import ugettext as _ +from opaque_keys.edx.locations import Location +from courseware import models +from instructor_analytics.csvs import create_csv_response +from util.json_request import JsonResponse from xmodule.modulestore.django import modulestore from xmodule.modulestore.inheritance import own_metadata -from instructor_analytics.csvs import create_csv_response - -from opaque_keys.edx.locations import Location # Used to limit the length of list displayed to the screen. MAX_SCREEN_LIST_LENGTH = 250 diff --git a/lms/djangoapps/class_dashboard/tests/test_dashboard_data.py b/lms/djangoapps/class_dashboard/tests/test_dashboard_data.py index 616c4aa600..5aa1e91d59 100644 --- a/lms/djangoapps/class_dashboard/tests/test_dashboard_data.py +++ b/lms/djangoapps/class_dashboard/tests/test_dashboard_data.py @@ -10,19 +10,23 @@ from mock import patch from nose.plugins.attrib import attr from capa.tests.response_xml_factory import StringResponseXMLFactory -from courseware.tests.factories import StudentModuleFactory -from student.tests.factories import UserFactory, CourseEnrollmentFactory, AdminFactory -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase - from class_dashboard.dashboard_data import ( - get_problem_grade_distribution, get_sequential_open_distrib, - get_problem_set_grade_distrib, get_d3_problem_grade_distrib, - get_d3_sequential_open_distrib, get_d3_section_grade_distrib, - get_section_display_name, get_array_section_has_problem, - get_students_opened_subsection, get_students_problem_grades, + get_array_section_has_problem, + get_d3_problem_grade_distrib, + get_d3_section_grade_distrib, + get_d3_sequential_open_distrib, + get_problem_grade_distribution, + get_problem_set_grade_distrib, + get_section_display_name, + get_sequential_open_distrib, + get_students_opened_subsection, + get_students_problem_grades ) from class_dashboard.views import has_instructor_access_for_class +from courseware.tests.factories import StudentModuleFactory +from student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory USER_COUNT = 11 diff --git a/lms/djangoapps/class_dashboard/tests/test_views.py b/lms/djangoapps/class_dashboard/tests/test_views.py index adf5ff6b07..7976ec4a9d 100644 --- a/lms/djangoapps/class_dashboard/tests/test_views.py +++ b/lms/djangoapps/class_dashboard/tests/test_views.py @@ -6,11 +6,11 @@ import json from django.test.client import RequestFactory from mock import patch from nose.plugins.attrib import attr -from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from class_dashboard import views from student.tests.factories import AdminFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory @attr(shard=1) diff --git a/lms/djangoapps/class_dashboard/urls.py b/lms/djangoapps/class_dashboard/urls.py index ca78be6a30..8d103a2815 100644 --- a/lms/djangoapps/class_dashboard/urls.py +++ b/lms/djangoapps/class_dashboard/urls.py @@ -2,8 +2,9 @@ Class Dashboard API endpoint urls. """ -from django.conf.urls import patterns, url from django.conf import settings +from django.conf.urls import patterns, url + COURSE_ID_PATTERN = settings.COURSE_ID_PATTERN urlpatterns = patterns( diff --git a/lms/djangoapps/class_dashboard/views.py b/lms/djangoapps/class_dashboard/views.py index d5d67c793e..be090347a4 100644 --- a/lms/djangoapps/class_dashboard/views.py +++ b/lms/djangoapps/class_dashboard/views.py @@ -2,16 +2,15 @@ Handles requests for data, returning a json """ -import logging import json +import logging from django.http import HttpResponse from opaque_keys.edx.locations import SlashSeparatedCourseKey -from courseware.courses import get_course_overview_with_access -from courseware.access import has_access from class_dashboard import dashboard_data - +from courseware.access import has_access +from courseware.courses import get_course_overview_with_access log = logging.getLogger(__name__) diff --git a/lms/djangoapps/commerce/admin.py b/lms/djangoapps/commerce/admin.py index ad49323a13..c5c178183a 100644 --- a/lms/djangoapps/commerce/admin.py +++ b/lms/djangoapps/commerce/admin.py @@ -1,8 +1,8 @@ """ Admin site bindings for commerce app. """ +from config_models.admin import ConfigurationModelAdmin from django.contrib import admin from commerce.models import CommerceConfiguration -from config_models.admin import ConfigurationModelAdmin admin.site.register(CommerceConfiguration, ConfigurationModelAdmin) diff --git a/lms/djangoapps/commerce/api/urls.py b/lms/djangoapps/commerce/api/urls.py index 1129750f1c..c12a53ffc8 100644 --- a/lms/djangoapps/commerce/api/urls.py +++ b/lms/djangoapps/commerce/api/urls.py @@ -1,5 +1,5 @@ """ API URLs. """ -from django.conf.urls import patterns, url, include +from django.conf.urls import include, patterns, url urlpatterns = patterns( '', diff --git a/lms/djangoapps/commerce/api/v0/tests/test_views.py b/lms/djangoapps/commerce/api/v0/tests/test_views.py index b2dc7981ae..ea0f924a4f 100644 --- a/lms/djangoapps/commerce/api/v0/tests/test_views.py +++ b/lms/djangoapps/commerce/api/v0/tests/test_views.py @@ -1,35 +1,35 @@ """ Commerce API v0 view tests. """ -from datetime import datetime, timedelta -import json import itertools +import json +from datetime import datetime, timedelta from uuid import uuid4 -import httpretty import ddt +import httpretty +import mock +import pytz from django.conf import settings from django.core.urlresolvers import reverse from django.test import TestCase from django.test.utils import override_settings -import mock +from edx_rest_api_client import exceptions from nose.plugins.attrib import attr -import pytz -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory +from commerce.api.v0.views import SAILTHRU_CAMPAIGN_COOKIE from commerce.constants import Messages from commerce.tests import TEST_BASKET_ID, TEST_ORDER_NUMBER, TEST_PAYMENT_DATA from commerce.tests.mocks import mock_basket_order, mock_create_basket from commerce.tests.test_views import UserMixin from course_modes.models import CourseMode -from edx_rest_api_client import exceptions -from openedx.core.djangoapps.embargo.test_utils import restrict_course from enrollment.api import get_enrollment +from openedx.core.djangoapps.embargo.test_utils import restrict_course from openedx.core.lib.django_test_client_utils import get_absolute_url from student.models import CourseEnrollment from student.tests.factories import CourseModeFactory from student.tests.tests import EnrollmentEventTestMixin from xmodule.modulestore.django import modulestore -from commerce.api.v0.views import SAILTHRU_CAMPAIGN_COOKIE +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory UTM_COOKIE_NAME = 'edx.test.utm' UTM_COOKIE_CONTENTS = { diff --git a/lms/djangoapps/commerce/api/v0/urls.py b/lms/djangoapps/commerce/api/v0/urls.py index 8d0765085a..90fd9f1845 100644 --- a/lms/djangoapps/commerce/api/v0/urls.py +++ b/lms/djangoapps/commerce/api/v0/urls.py @@ -1,9 +1,8 @@ """ API v0 URLs. """ -from django.conf.urls import patterns, url, include +from django.conf.urls import include, patterns, url from commerce.api.v0 import views - BASKET_URLS = patterns( '', url(r'^$', views.BasketsView.as_view(), name='create'), diff --git a/lms/djangoapps/commerce/api/v0/views.py b/lms/djangoapps/commerce/api/v0/views.py index b427c89236..80bb149548 100644 --- a/lms/djangoapps/commerce/api/v0/views.py +++ b/lms/djangoapps/commerce/api/v0/views.py @@ -1,7 +1,7 @@ """ API v0 views. """ import logging -import requests +import requests from edx_rest_api_client import exceptions from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey @@ -15,17 +15,16 @@ from commerce.exceptions import InvalidResponseError from commerce.http import DetailResponse, InternalRequestErrorResponse from course_modes.models import CourseMode from courseware import courses -from openedx.core.djangoapps.embargo import api as embargo_api from enrollment.api import add_enrollment from enrollment.views import EnrollmentCrossDomainSessionAuth from openedx.core.djangoapps.commerce.utils import ecommerce_api_client +from openedx.core.djangoapps.embargo import api as embargo_api from openedx.core.djangoapps.user_api.preferences.api import update_email_opt_in from openedx.core.lib.api.authentication import OAuth2AuthenticationAllowInactiveUser from openedx.core.lib.log_utils import audit_log from student.models import CourseEnrollment, RegistrationCookieConfiguration from util.json_request import JsonResponse - log = logging.getLogger(__name__) SAILTHRU_CAMPAIGN_COOKIE = 'sailthru_bid' diff --git a/lms/djangoapps/commerce/api/v1/models.py b/lms/djangoapps/commerce/api/v1/models.py index 9d7c0f5ed7..356548faf7 100644 --- a/lms/djangoapps/commerce/api/v1/models.py +++ b/lms/djangoapps/commerce/api/v1/models.py @@ -1,13 +1,14 @@ """ API v1 models. """ +import logging from itertools import groupby -import logging from django.db import transaction from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey -from openedx.core.djangoapps.content.course_overviews.models import CourseOverview + from course_modes.models import CourseMode from lms.djangoapps.verify_student.models import VerificationDeadline +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview log = logging.getLogger(__name__) diff --git a/lms/djangoapps/commerce/api/v1/serializers.py b/lms/djangoapps/commerce/api/v1/serializers.py index a114160e3a..c1a4645c6c 100644 --- a/lms/djangoapps/commerce/api/v1/serializers.py +++ b/lms/djangoapps/commerce/api/v1/serializers.py @@ -3,14 +3,12 @@ from datetime import datetime import pytz from django.utils.translation import ugettext as _ - from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey from rest_framework import serializers from commerce.api.v1.models import Course from course_modes.models import CourseMode - from xmodule.modulestore.django import modulestore diff --git a/lms/djangoapps/commerce/api/v1/tests/test_views.py b/lms/djangoapps/commerce/api/v1/tests/test_views.py index 8af77d542a..7628cab782 100644 --- a/lms/djangoapps/commerce/api/v1/tests/test_views.py +++ b/lms/djangoapps/commerce/api/v1/tests/test_views.py @@ -1,9 +1,10 @@ """ Commerce API v1 view tests. """ -from datetime import datetime, timedelta import itertools import json +from datetime import datetime, timedelta import ddt +import pytz from django.conf import settings from django.contrib.auth.models import Permission from django.core.urlresolvers import reverse @@ -12,16 +13,15 @@ from django.test.utils import override_settings from edx_rest_api_client import exceptions from flaky import flaky from nose.plugins.attrib import attr -import pytz from rest_framework.utils.encoders import JSONEncoder -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from commerce.tests.mocks import mock_order_endpoint from commerce.tests.test_views import UserMixin from course_modes.models import CourseMode -from student.tests.factories import UserFactory from lms.djangoapps.verify_student.models import VerificationDeadline +from student.tests.factories import UserFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory PASSWORD = 'test' JSON_CONTENT_TYPE = 'application/json' diff --git a/lms/djangoapps/commerce/api/v1/urls.py b/lms/djangoapps/commerce/api/v1/urls.py index d4ed3a7def..90d149a5e2 100644 --- a/lms/djangoapps/commerce/api/v1/urls.py +++ b/lms/djangoapps/commerce/api/v1/urls.py @@ -1,6 +1,6 @@ """ API v1 URLs. """ from django.conf import settings -from django.conf.urls import patterns, url, include +from django.conf.urls import include, patterns, url from commerce.api.v1 import views diff --git a/lms/djangoapps/commerce/api/v1/views.py b/lms/djangoapps/commerce/api/v1/views.py index 8a862455a8..5c25d991c4 100644 --- a/lms/djangoapps/commerce/api/v1/views.py +++ b/lms/djangoapps/commerce/api/v1/views.py @@ -5,7 +5,7 @@ from django.http import Http404 from edx_rest_api_client import exceptions from edx_rest_framework_extensions.authentication import JwtAuthentication from rest_framework.authentication import SessionAuthentication -from rest_framework.generics import RetrieveUpdateAPIView, ListAPIView +from rest_framework.generics import ListAPIView, RetrieveUpdateAPIView from rest_framework.permissions import IsAuthenticated from rest_framework.views import APIView from rest_framework_oauth.authentication import OAuth2Authentication diff --git a/lms/djangoapps/commerce/http.py b/lms/djangoapps/commerce/http.py index 865d69045e..fea933330f 100644 --- a/lms/djangoapps/commerce/http.py +++ b/lms/djangoapps/commerce/http.py @@ -1,6 +1,6 @@ """ HTTP-related entities. """ -from rest_framework.status import HTTP_500_INTERNAL_SERVER_ERROR, HTTP_200_OK +from rest_framework.status import HTTP_200_OK, HTTP_500_INTERNAL_SERVER_ERROR from util.json_request import JsonResponse diff --git a/lms/djangoapps/commerce/management/commands/configure_commerce.py b/lms/djangoapps/commerce/management/commands/configure_commerce.py index 86b9310091..6b47a8814d 100644 --- a/lms/djangoapps/commerce/management/commands/configure_commerce.py +++ b/lms/djangoapps/commerce/management/commands/configure_commerce.py @@ -4,6 +4,7 @@ We can use this command to enable/disable commerce configuration or disable chec """ from __future__ import unicode_literals + import logging from django.core.management import BaseCommand diff --git a/lms/djangoapps/commerce/management/commands/tests/test_configure_commerce.py b/lms/djangoapps/commerce/management/commands/tests/test_configure_commerce.py index a3800314c4..1e7791e5d6 100644 --- a/lms/djangoapps/commerce/management/commands/tests/test_configure_commerce.py +++ b/lms/djangoapps/commerce/management/commands/tests/test_configure_commerce.py @@ -1,8 +1,8 @@ """ Tests for management command for enabling commerce configuration. """ -from django.test import TestCase from django.core.management import call_command +from django.test import TestCase from commerce.models import CommerceConfiguration diff --git a/lms/djangoapps/commerce/models.py b/lms/djangoapps/commerce/models.py index dba2258f8d..2363f137a0 100644 --- a/lms/djangoapps/commerce/models.py +++ b/lms/djangoapps/commerce/models.py @@ -1,11 +1,10 @@ """ Commerce-related models. """ +from config_models.models import ConfigurationModel from django.db import models from django.utils.translation import ugettext_lazy as _ -from config_models.models import ConfigurationModel - class CommerceConfiguration(ConfigurationModel): """ Commerce configuration """ diff --git a/lms/djangoapps/commerce/tests/test_signals.py b/lms/djangoapps/commerce/tests/test_signals.py index 7901fb4ce0..e90d45512d 100644 --- a/lms/djangoapps/commerce/tests/test_signals.py +++ b/lms/djangoapps/commerce/tests/test_signals.py @@ -19,12 +19,12 @@ from opaque_keys.edx.keys import CourseKey from requests import Timeout from commerce.models import CommerceConfiguration -from commerce.signals import send_refund_notification, generate_refund_notification_body, create_zendesk_ticket +from commerce.signals import create_zendesk_ticket, generate_refund_notification_body, send_refund_notification from commerce.tests import JSON from commerce.tests.mocks import mock_create_refund, mock_process_refund from course_modes.models import CourseMode from student.models import UNENROLL_DONE -from student.tests.factories import UserFactory, CourseEnrollmentFactory +from student.tests.factories import CourseEnrollmentFactory, UserFactory ZENDESK_URL = 'http://zendesk.example.com/' ZENDESK_USER = 'test@example.com' diff --git a/lms/djangoapps/commerce/tests/test_views.py b/lms/djangoapps/commerce/tests/test_views.py index b406c96c43..a2ec722840 100644 --- a/lms/djangoapps/commerce/tests/test_views.py +++ b/lms/djangoapps/commerce/tests/test_views.py @@ -1,18 +1,18 @@ """ Tests for commerce views. """ -from nose.plugins.attrib import attr +import json import ddt -import json -from django.core.urlresolvers import reverse import mock +from django.core.urlresolvers import reverse +from nose.plugins.attrib import attr -from student.tests.factories import UserFactory -from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme -from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from student.models import CourseEnrollment from course_modes.models import CourseMode +from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme +from student.models import CourseEnrollment +from student.tests.factories import UserFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class UserMixin(object): diff --git a/lms/djangoapps/commerce/urls.py b/lms/djangoapps/commerce/urls.py index 50399b82b5..665a7f8c0c 100644 --- a/lms/djangoapps/commerce/urls.py +++ b/lms/djangoapps/commerce/urls.py @@ -2,8 +2,8 @@ Defines the URL routes for this app. """ from django.conf.urls import patterns, url -from commerce import views +from commerce import views urlpatterns = patterns( '', diff --git a/lms/djangoapps/commerce/utils.py b/lms/djangoapps/commerce/utils.py index d0300bb394..644492e7bf 100644 --- a/lms/djangoapps/commerce/utils.py +++ b/lms/djangoapps/commerce/utils.py @@ -2,8 +2,8 @@ from urllib import urlencode from urlparse import urljoin -from django.conf import settings import waffle +from django.conf import settings from commerce.models import CommerceConfiguration from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers diff --git a/lms/djangoapps/commerce/views.py b/lms/djangoapps/commerce/views.py index 84f2108fe9..5f41736f07 100644 --- a/lms/djangoapps/commerce/views.py +++ b/lms/djangoapps/commerce/views.py @@ -4,21 +4,21 @@ import logging from django.conf import settings from django.contrib.auth.decorators import login_required from django.core.cache import cache +from django.http import HttpResponseBadRequest from django.utils.translation import ugettext as _ from django.views.decorators.csrf import csrf_exempt +from django.views.decorators.http import require_http_methods +from opaque_keys.edx.locator import CourseLocator from commerce.models import CommerceConfiguration +from course_modes.models import CourseMode from edxmako.shortcuts import render_to_response from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.theming.helpers import is_request_in_themed_site from shoppingcart.processors.CyberSource2 import is_user_payment_error -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers -from opaque_keys.edx.locator import CourseLocator from student.models import CourseEnrollment from util.json_request import JsonResponse -from django.views.decorators.http import require_http_methods -from course_modes.models import CourseMode -from django.http import HttpResponseBadRequest log = logging.getLogger(__name__) diff --git a/lms/djangoapps/course_api/api.py b/lms/djangoapps/course_api/api.py index 87c8e44ebe..79a3b38796 100644 --- a/lms/djangoapps/course_api/api.py +++ b/lms/djangoapps/course_api/api.py @@ -2,14 +2,15 @@ Course API """ -from django.contrib.auth.models import User, AnonymousUser +from django.contrib.auth.models import AnonymousUser, User from rest_framework.exceptions import PermissionDenied from lms.djangoapps.courseware.courses import ( - get_courses, get_course_overview_with_access, - get_permission_for_course_about, + get_courses, + get_permission_for_course_about ) + from .permissions import can_view_courses_for_username diff --git a/lms/djangoapps/course_api/blocks/api.py b/lms/djangoapps/course_api/blocks/api.py index e33c9252b9..233f618301 100644 --- a/lms/djangoapps/course_api/blocks/api.py +++ b/lms/djangoapps/course_api/blocks/api.py @@ -2,13 +2,13 @@ API function for retrieving course blocks data """ -from lms.djangoapps.course_blocks.api import get_course_blocks, COURSE_BLOCK_ACCESS_TRANSFORMERS +from lms.djangoapps.course_blocks.api import COURSE_BLOCK_ACCESS_TRANSFORMERS, get_course_blocks from lms.djangoapps.course_blocks.transformers.hidden_content import HiddenContentTransformer from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers +from .serializers import BlockDictSerializer, BlockSerializer from .transformers.blocks_api import BlocksAPITransformer from .transformers.milestones import MilestonesAndSpecialExamsTransformer -from .serializers import BlockSerializer, BlockDictSerializer def get_blocks( diff --git a/lms/djangoapps/course_api/blocks/forms.py b/lms/djangoapps/course_api/blocks/forms.py index 76363e6679..ca2cee5e97 100644 --- a/lms/djangoapps/course_api/blocks/forms.py +++ b/lms/djangoapps/course_api/blocks/forms.py @@ -3,12 +3,12 @@ Course API Forms """ from django.contrib.auth.models import User from django.core.exceptions import ValidationError -from django.forms import Form, CharField, ChoiceField, IntegerField +from django.forms import CharField, ChoiceField, Form, IntegerField from django.http import Http404 -from rest_framework.exceptions import PermissionDenied - from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import UsageKey +from rest_framework.exceptions import PermissionDenied + from openedx.core.djangoapps.util.forms import ExtendedNullBooleanField, MultiValueField from xmodule.modulestore.django import modulestore diff --git a/lms/djangoapps/course_api/blocks/tests/test_api.py b/lms/djangoapps/course_api/blocks/tests/test_api.py index af9dae0a05..3c3d3eef08 100644 --- a/lms/djangoapps/course_api/blocks/tests/test_api.py +++ b/lms/djangoapps/course_api/blocks/tests/test_api.py @@ -2,13 +2,13 @@ Tests for Blocks api.py """ +from itertools import product + import ddt from django.test.client import RequestFactory -from itertools import product from openedx.core.djangoapps.content.block_structure.api import clear_course_from_cache from openedx.core.djangoapps.content.block_structure.config import STORAGE_BACKING_FOR_CACHE, waffle - from student.tests.factories import UserFactory from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase diff --git a/lms/djangoapps/course_api/blocks/tests/test_forms.py b/lms/djangoapps/course_api/blocks/tests/test_forms.py index ac0bc93ac6..9ff5682053 100644 --- a/lms/djangoapps/course_api/blocks/tests/test_forms.py +++ b/lms/djangoapps/course_api/blocks/tests/test_forms.py @@ -1,15 +1,16 @@ """ Tests for Course Blocks forms """ +from urllib import urlencode + import ddt from django.http import Http404, QueryDict -from urllib import urlencode +from opaque_keys.edx.locator import CourseLocator from rest_framework.exceptions import PermissionDenied -from opaque_keys.edx.locator import CourseLocator from openedx.core.djangoapps.util.test_forms import FormTestMixin from student.models import CourseEnrollment -from student.tests.factories import UserFactory, CourseEnrollmentFactory +from student.tests.factories import CourseEnrollmentFactory, UserFactory from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/lms/djangoapps/course_api/blocks/tests/test_serializers.py b/lms/djangoapps/course_api/blocks/tests/test_serializers.py index d5a3be825f..943ec25096 100644 --- a/lms/djangoapps/course_api/blocks/tests/test_serializers.py +++ b/lms/djangoapps/course_api/blocks/tests/test_serializers.py @@ -3,16 +3,16 @@ Tests for Course Blocks serializers """ from mock import MagicMock +from lms.djangoapps.course_blocks.api import COURSE_BLOCK_ACCESS_TRANSFORMERS, get_course_blocks from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers +from student.roles import CourseStaffRole from student.tests.factories import UserFactory from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import ToyCourseFactory -from lms.djangoapps.course_blocks.api import get_course_blocks, COURSE_BLOCK_ACCESS_TRANSFORMERS -from student.roles import CourseStaffRole +from ..serializers import BlockDictSerializer, BlockSerializer from ..transformers.blocks_api import BlocksAPITransformer -from ..serializers import BlockSerializer, BlockDictSerializer from .helpers import deserialize_usage_key diff --git a/lms/djangoapps/course_api/blocks/tests/test_views.py b/lms/djangoapps/course_api/blocks/tests/test_views.py index f8d2e2bf16..5c518fa7e2 100644 --- a/lms/djangoapps/course_api/blocks/tests/test_views.py +++ b/lms/djangoapps/course_api/blocks/tests/test_views.py @@ -2,13 +2,13 @@ Tests for Blocks Views """ from datetime import datetime - -from django.core.urlresolvers import reverse from string import join from urllib import urlencode from urlparse import urlunparse +from django.core.urlresolvers import reverse from opaque_keys.edx.locator import CourseLocator + from student.models import CourseEnrollment from student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase diff --git a/lms/djangoapps/course_api/blocks/transformers/blocks_api.py b/lms/djangoapps/course_api/blocks/transformers/blocks_api.py index c4356b200d..376e78a13a 100644 --- a/lms/djangoapps/course_api/blocks/transformers/blocks_api.py +++ b/lms/djangoapps/course_api/blocks/transformers/blocks_api.py @@ -2,6 +2,7 @@ Blocks API Transformer """ from openedx.core.djangoapps.content.block_structure.transformer import BlockStructureTransformer + from .block_counts import BlockCountsTransformer from .block_depth import BlockDepthTransformer from .navigation import BlockNavigationTransformer diff --git a/lms/djangoapps/course_api/blocks/transformers/milestones.py b/lms/djangoapps/course_api/blocks/transformers/milestones.py index d0b33efe51..e039ec8432 100644 --- a/lms/djangoapps/course_api/blocks/transformers/milestones.py +++ b/lms/djangoapps/course_api/blocks/transformers/milestones.py @@ -3,14 +3,15 @@ Milestones Transformer """ import logging + from django.conf import settings +from edx_proctoring.api import get_attempt_status_summary +from edx_proctoring.exceptions import ProctoredExamNotFoundException from openedx.core.djangoapps.content.block_structure.transformer import ( BlockStructureTransformer, - FilteringTransformerMixin, + FilteringTransformerMixin ) -from edx_proctoring.exceptions import ProctoredExamNotFoundException -from edx_proctoring.api import get_attempt_status_summary from student.models import EntranceExamConfiguration from util import milestones_helpers diff --git a/lms/djangoapps/course_api/blocks/transformers/navigation.py b/lms/djangoapps/course_api/blocks/transformers/navigation.py index 4a9e2b9697..4a46d6afaa 100644 --- a/lms/djangoapps/course_api/blocks/transformers/navigation.py +++ b/lms/djangoapps/course_api/blocks/transformers/navigation.py @@ -2,6 +2,7 @@ TODO """ from openedx.core.djangoapps.content.block_structure.transformer import BlockStructureTransformer + from .block_depth import BlockDepthTransformer diff --git a/lms/djangoapps/course_api/blocks/transformers/tests/test_block_depth.py b/lms/djangoapps/course_api/blocks/transformers/tests/test_block_depth.py index 60ee26ae9a..b3e123b6b2 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_block_depth.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_block_depth.py @@ -4,11 +4,13 @@ Tests for BlockDepthTransformer. # pylint: disable=protected-access -import ddt from unittest import TestCase -from openedx.core.djangoapps.content.block_structure.tests.helpers import ChildrenMapTestMixin +import ddt + from openedx.core.djangoapps.content.block_structure.block_structure import BlockStructureModulestoreData +from openedx.core.djangoapps.content.block_structure.tests.helpers import ChildrenMapTestMixin + from ..block_depth import BlockDepthTransformer diff --git a/lms/djangoapps/course_api/blocks/transformers/tests/test_milestones.py b/lms/djangoapps/course_api/blocks/transformers/tests/test_milestones.py index 5652aae3f1..c566a0ab91 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_milestones.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_milestones.py @@ -1,19 +1,19 @@ """ Tests for ProctoredExamTransformer. """ -from mock import patch, Mock +import ddt +from milestones.tests.utils import MilestonesTestCaseMixin +from mock import Mock, patch from nose.plugins.attrib import attr -import ddt from gating import api as lms_gating_api from lms.djangoapps.course_blocks.transformers.tests.helpers import CourseStructureTestCase -from milestones.tests.utils import MilestonesTestCaseMixin -from openedx.core.lib.gating import api as gating_api from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers +from openedx.core.lib.gating import api as gating_api from student.tests.factories import CourseEnrollmentFactory -from ..milestones import MilestonesAndSpecialExamsTransformer from ...api import get_course_blocks +from ..milestones import MilestonesAndSpecialExamsTransformer @attr(shard=3) diff --git a/lms/djangoapps/course_api/blocks/transformers/tests/test_navigation.py b/lms/djangoapps/course_api/blocks/transformers/tests/test_navigation.py index 8cf73593cd..5db1fc9c2b 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_navigation.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_navigation.py @@ -2,17 +2,18 @@ """ Tests for BlockNavigationTransformer. """ -import ddt from unittest import TestCase +import ddt + from lms.djangoapps.course_api.blocks.transformers.block_depth import BlockDepthTransformer from lms.djangoapps.course_api.blocks.transformers.navigation import BlockNavigationTransformer -from openedx.core.djangoapps.content.block_structure.tests.helpers import ChildrenMapTestMixin from openedx.core.djangoapps.content.block_structure.block_structure import BlockStructureModulestoreData from openedx.core.djangoapps.content.block_structure.factory import BlockStructureFactory +from openedx.core.djangoapps.content.block_structure.tests.helpers import ChildrenMapTestMixin +from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import SampleCourseFactory -from xmodule.modulestore import ModuleStoreEnum @ddt.ddt diff --git a/lms/djangoapps/course_api/blocks/urls.py b/lms/djangoapps/course_api/blocks/urls.py index e40a7d7082..7cadd939b5 100644 --- a/lms/djangoapps/course_api/blocks/urls.py +++ b/lms/djangoapps/course_api/blocks/urls.py @@ -3,8 +3,8 @@ Course Block API URLs """ from django.conf import settings from django.conf.urls import patterns, url -from .views import BlocksView, BlocksInCourseView +from .views import BlocksInCourseView, BlocksView urlpatterns = patterns( '', diff --git a/lms/djangoapps/course_api/blocks/views.py b/lms/djangoapps/course_api/blocks/views.py index 7caefff9d0..2b9f939d4c 100644 --- a/lms/djangoapps/course_api/blocks/views.py +++ b/lms/djangoapps/course_api/blocks/views.py @@ -3,12 +3,12 @@ CourseBlocks API views """ from django.core.exceptions import ValidationError from django.http import Http404 +from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey from rest_framework.generics import ListAPIView from rest_framework.response import Response -from opaque_keys import InvalidKeyError -from opaque_keys.edx.keys import CourseKey -from openedx.core.lib.api.view_utils import view_auth_classes, DeveloperErrorViewMixin +from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError diff --git a/lms/djangoapps/course_api/forms.py b/lms/djangoapps/course_api/forms.py index 1767cc7422..85bfd4d896 100644 --- a/lms/djangoapps/course_api/forms.py +++ b/lms/djangoapps/course_api/forms.py @@ -3,11 +3,12 @@ Course API forms """ from collections import namedtuple -from django.core.exceptions import ValidationError -from django.forms import Form, CharField +from django.core.exceptions import ValidationError +from django.forms import CharField, Form from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey + from openedx.core.djangoapps.util.forms import ExtendedNullBooleanField diff --git a/lms/djangoapps/course_api/tests/mixins.py b/lms/djangoapps/course_api/tests/mixins.py index fa8b848802..11e6ae5943 100644 --- a/lms/djangoapps/course_api/tests/mixins.py +++ b/lms/djangoapps/course_api/tests/mixins.py @@ -7,7 +7,6 @@ from datetime import datetime from student.tests.factories import UserFactory from xmodule.modulestore.tests.factories import ToyCourseFactory - TEST_PASSWORD = u'edx' diff --git a/lms/djangoapps/course_api/tests/test_api.py b/lms/djangoapps/course_api/tests/test_api.py index b8b7afd559..0885611353 100644 --- a/lms/djangoapps/course_api/tests/test_api.py +++ b/lms/djangoapps/course_api/tests/test_api.py @@ -11,10 +11,11 @@ from rest_framework.request import Request from rest_framework.test import APIRequestFactory from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase, ModuleStoreTestCase +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import check_mongo_calls -from .mixins import CourseApiFactoryMixin + from ..api import course_detail, list_courses +from .mixins import CourseApiFactoryMixin class CourseApiTestMixin(CourseApiFactoryMixin): diff --git a/lms/djangoapps/course_api/tests/test_forms.py b/lms/djangoapps/course_api/tests/test_forms.py index 5ea6d2343a..5ebff7e571 100644 --- a/lms/djangoapps/course_api/tests/test_forms.py +++ b/lms/djangoapps/course_api/tests/test_forms.py @@ -2,11 +2,12 @@ Tests for Course API forms. """ +from itertools import product +from urllib import urlencode + import ddt from django.contrib.auth.models import AnonymousUser from django.http import QueryDict -from itertools import product -from urllib import urlencode from openedx.core.djangoapps.util.test_forms import FormTestMixin from student.tests.factories import UserFactory diff --git a/lms/djangoapps/course_api/tests/test_permissions.py b/lms/djangoapps/course_api/tests/test_permissions.py index fbfccd0a00..62efdbdfa7 100644 --- a/lms/djangoapps/course_api/tests/test_permissions.py +++ b/lms/djangoapps/course_api/tests/test_permissions.py @@ -5,9 +5,8 @@ Test authorization functions from django.contrib.auth.models import AnonymousUser from django.test import TestCase -from .mixins import CourseApiFactoryMixin - from ..permissions import can_view_courses_for_username +from .mixins import CourseApiFactoryMixin class ViewCoursesForUsernameTestCase(CourseApiFactoryMixin, TestCase): diff --git a/lms/djangoapps/course_api/tests/test_serializers.py b/lms/djangoapps/course_api/tests/test_serializers.py index b1d1e76bb6..3580599c51 100644 --- a/lms/djangoapps/course_api/tests/test_serializers.py +++ b/lms/djangoapps/course_api/tests/test_serializers.py @@ -3,21 +3,22 @@ Test data created by CourseSerializer and CourseDetailSerializer """ from __future__ import unicode_literals + from datetime import datetime import ddt from nose.plugins.attrib import attr -from openedx.core.djangoapps.models.course_details import CourseDetails -from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from rest_framework.test import APIRequestFactory from rest_framework.request import Request - +from rest_framework.test import APIRequestFactory from xblock.core import XBlock + +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview +from openedx.core.djangoapps.models.course_details import CourseDetails from xmodule.course_module import DEFAULT_START_DATE from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import check_mongo_calls -from ..serializers import CourseSerializer, CourseDetailSerializer +from ..serializers import CourseDetailSerializer, CourseSerializer from .mixins import CourseApiFactoryMixin diff --git a/lms/djangoapps/course_api/tests/test_views.py b/lms/djangoapps/course_api/tests/test_views.py index 6a357194ee..f2987b8496 100644 --- a/lms/djangoapps/course_api/tests/test_views.py +++ b/lms/djangoapps/course_api/tests/test_views.py @@ -7,9 +7,10 @@ from django.core.urlresolvers import reverse from django.test import RequestFactory from nose.plugins.attrib import attr -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase, ModuleStoreTestCase -from .mixins import CourseApiFactoryMixin, TEST_PASSWORD +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase + from ..views import CourseDetailView +from .mixins import TEST_PASSWORD, CourseApiFactoryMixin class CourseApiTestViewMixin(CourseApiFactoryMixin): diff --git a/lms/djangoapps/course_api/urls.py b/lms/djangoapps/course_api/urls.py index bf24e7ead4..294d03be32 100644 --- a/lms/djangoapps/course_api/urls.py +++ b/lms/djangoapps/course_api/urls.py @@ -2,11 +2,10 @@ Course API URLs """ from django.conf import settings -from django.conf.urls import patterns, url, include +from django.conf.urls import include, patterns, url from .views import CourseDetailView, CourseListView - urlpatterns = patterns( '', url(r'^v1/courses/$', CourseListView.as_view(), name="course-list"), diff --git a/lms/djangoapps/course_api/views.py b/lms/djangoapps/course_api/views.py index 33aea96e29..80e529c37f 100644 --- a/lms/djangoapps/course_api/views.py +++ b/lms/djangoapps/course_api/views.py @@ -6,10 +6,11 @@ from django.core.exceptions import ValidationError from rest_framework.generics import ListAPIView, RetrieveAPIView from openedx.core.lib.api.paginators import NamespacedPageNumberPagination -from openedx.core.lib.api.view_utils import view_auth_classes, DeveloperErrorViewMixin +from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes + from .api import course_detail, list_courses from .forms import CourseDetailGetForm, CourseListGetForm -from .serializers import CourseSerializer, CourseDetailSerializer +from .serializers import CourseDetailSerializer, CourseSerializer @view_auth_classes(is_authenticated=False) diff --git a/lms/djangoapps/course_blocks/api.py b/lms/djangoapps/course_blocks/api.py index 6c37624887..f48cdccbec 100644 --- a/lms/djangoapps/course_blocks/api.py +++ b/lms/djangoapps/course_blocks/api.py @@ -5,15 +5,9 @@ get_course_blocks function. from openedx.core.djangoapps.content.block_structure.api import get_block_structure_manager from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers -from .transformers import ( - library_content, - start_date, - user_partitions, - visibility, -) +from .transformers import library_content, start_date, user_partitions, visibility from .usage_info import CourseUsageInfo - # Default list of transformers for manipulating course block structures # based on the user's access to the course blocks. COURSE_BLOCK_ACCESS_TRANSFORMERS = [ diff --git a/lms/djangoapps/course_blocks/transformers/hidden_content.py b/lms/djangoapps/course_blocks/transformers/hidden_content.py index 0627390ef2..bea8706e10 100644 --- a/lms/djangoapps/course_blocks/transformers/hidden_content.py +++ b/lms/djangoapps/course_blocks/transformers/hidden_content.py @@ -2,15 +2,16 @@ Visibility Transformer implementation. """ from datetime import datetime + from pytz import utc from openedx.core.djangoapps.content.block_structure.transformer import ( BlockStructureTransformer, - FilteringTransformerMixin, + FilteringTransformerMixin ) from xmodule.seq_module import SequenceModule -from .utils import collect_merged_boolean_field, collect_merged_date_field +from .utils import collect_merged_boolean_field, collect_merged_date_field MAXIMUM_DATE = utc.localize(datetime.max) diff --git a/lms/djangoapps/course_blocks/transformers/library_content.py b/lms/djangoapps/course_blocks/transformers/library_content.py index 9743fc2460..1ab71ca32b 100644 --- a/lms/djangoapps/course_blocks/transformers/library_content.py +++ b/lms/djangoapps/course_blocks/transformers/library_content.py @@ -2,15 +2,16 @@ Content Library Transformer. """ import json + from courseware.models import StudentModule +from eventtracking import tracker from openedx.core.djangoapps.content.block_structure.transformer import ( BlockStructureTransformer, - FilteringTransformerMixin, + FilteringTransformerMixin ) +from track import contexts from xmodule.library_content_module import LibraryContentModule from xmodule.modulestore.django import modulestore -from eventtracking import tracker -from track import contexts from ..utils import get_student_module_as_dict diff --git a/lms/djangoapps/course_blocks/transformers/split_test.py b/lms/djangoapps/course_blocks/transformers/split_test.py index 4db261a6e1..98d1fd84f4 100644 --- a/lms/djangoapps/course_blocks/transformers/split_test.py +++ b/lms/djangoapps/course_blocks/transformers/split_test.py @@ -3,7 +3,7 @@ Split Test Block Transformer """ from openedx.core.djangoapps.content.block_structure.transformer import ( BlockStructureTransformer, - FilteringTransformerMixin, + FilteringTransformerMixin ) diff --git a/lms/djangoapps/course_blocks/transformers/start_date.py b/lms/djangoapps/course_blocks/transformers/start_date.py index 561d3c3153..c151cfdb21 100644 --- a/lms/djangoapps/course_blocks/transformers/start_date.py +++ b/lms/djangoapps/course_blocks/transformers/start_date.py @@ -1,11 +1,11 @@ """ Start Date Transformer implementation. """ +from lms.djangoapps.courseware.access_utils import check_start_date from openedx.core.djangoapps.content.block_structure.transformer import ( BlockStructureTransformer, - FilteringTransformerMixin, + FilteringTransformerMixin ) -from lms.djangoapps.courseware.access_utils import check_start_date from xmodule.course_metadata_utils import DEFAULT_START_DATE from .utils import collect_merged_date_field diff --git a/lms/djangoapps/course_blocks/transformers/tests/helpers.py b/lms/djangoapps/course_blocks/transformers/tests/helpers.py index 073dd08b5b..4216ed20cb 100644 --- a/lms/djangoapps/course_blocks/transformers/tests/helpers.py +++ b/lms/djangoapps/course_blocks/transformers/tests/helpers.py @@ -2,15 +2,16 @@ Test helpers for testing course block transformers. """ from mock import patch + from course_modes.models import CourseMode from lms.djangoapps.courseware.access import has_access -from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers from openedx.core.djangoapps.content.block_structure.tests.helpers import clear_registered_transformers_cache +from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers from student.tests.factories import CourseEnrollmentFactory, UserFactory from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from ...api import get_course_blocks diff --git a/lms/djangoapps/course_blocks/transformers/tests/test_hidden_content.py b/lms/djangoapps/course_blocks/transformers/tests/test_hidden_content.py index 4424133bca..86032ec368 100644 --- a/lms/djangoapps/course_blocks/transformers/tests/test_hidden_content.py +++ b/lms/djangoapps/course_blocks/transformers/tests/test_hidden_content.py @@ -2,6 +2,7 @@ Tests for HiddenContentTransformer. """ from datetime import timedelta + import ddt from django.utils.timezone import now from nose.plugins.attrib import attr diff --git a/lms/djangoapps/course_blocks/transformers/tests/test_library_content.py b/lms/djangoapps/course_blocks/transformers/tests/test_library_content.py index 2d36175832..e656b1ce25 100644 --- a/lms/djangoapps/course_blocks/transformers/tests/test_library_content.py +++ b/lms/djangoapps/course_blocks/transformers/tests/test_library_content.py @@ -2,10 +2,9 @@ Tests for ContentLibraryTransformer. """ -from student.tests.factories import CourseEnrollmentFactory - from openedx.core.djangoapps.content.block_structure.api import clear_course_from_cache from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers +from student.tests.factories import CourseEnrollmentFactory from ...api import get_course_blocks from ..library_content import ContentLibraryTransformer diff --git a/lms/djangoapps/course_blocks/transformers/tests/test_split_test.py b/lms/djangoapps/course_blocks/transformers/tests/test_split_test.py index f5110868f5..7cfe10f442 100644 --- a/lms/djangoapps/course_blocks/transformers/tests/test_split_test.py +++ b/lms/djangoapps/course_blocks/transformers/tests/test_split_test.py @@ -7,8 +7,8 @@ from nose.plugins.attrib import attr import openedx.core.djangoapps.user_api.course_tag.api as course_tag_api from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme from student.tests.factories import CourseEnrollmentFactory -from xmodule.partitions.partitions import Group, UserPartition from xmodule.modulestore.tests.factories import check_mongo_calls +from xmodule.partitions.partitions import Group, UserPartition from ...api import get_course_blocks from ..user_partitions import UserPartitionTransformer, _get_user_partition_groups diff --git a/lms/djangoapps/course_blocks/transformers/tests/test_start_date.py b/lms/djangoapps/course_blocks/transformers/tests/test_start_date.py index bbe4ae0725..a4cb0b5d3a 100644 --- a/lms/djangoapps/course_blocks/transformers/tests/test_start_date.py +++ b/lms/djangoapps/course_blocks/transformers/tests/test_start_date.py @@ -1,14 +1,16 @@ """ Tests for StartDateTransformer. """ -import ddt from datetime import timedelta + +import ddt from django.utils.timezone import now from mock import patch from nose.plugins.attrib import attr from courseware.tests.factories import BetaTesterFactory -from ..start_date import StartDateTransformer, DEFAULT_START_DATE + +from ..start_date import DEFAULT_START_DATE, StartDateTransformer from .helpers import BlockParentsMapTestCase, update_block diff --git a/lms/djangoapps/course_blocks/transformers/tests/test_user_partitions.py b/lms/djangoapps/course_blocks/transformers/tests/test_user_partitions.py index 2d51078a3b..8b97a55b9e 100644 --- a/lms/djangoapps/course_blocks/transformers/tests/test_user_partitions.py +++ b/lms/djangoapps/course_blocks/transformers/tests/test_user_partitions.py @@ -2,18 +2,19 @@ """ Tests for UserPartitionTransformer. """ +import string from collections import namedtuple + import ddt from nose.plugins.attrib import attr -import string +from openedx.core.djangoapps.course_groups.cohorts import add_user_to_cohort from openedx.core.djangoapps.course_groups.partition_scheme import CohortPartitionScheme from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory, config_course_cohorts -from openedx.core.djangoapps.course_groups.cohorts import add_user_to_cohort from openedx.core.djangoapps.course_groups.views import link_cohort_to_partition_group from student.tests.factories import CourseEnrollmentFactory -from xmodule.partitions.partitions import Group, UserPartition from xmodule.modulestore.tests.factories import CourseFactory +from xmodule.partitions.partitions import Group, UserPartition from ...api import get_course_blocks from ..user_partitions import UserPartitionTransformer, _MergedGroupAccess diff --git a/lms/djangoapps/course_blocks/transformers/user_partitions.py b/lms/djangoapps/course_blocks/transformers/user_partitions.py index a01cdf3b54..e8e26882e5 100644 --- a/lms/djangoapps/course_blocks/transformers/user_partitions.py +++ b/lms/djangoapps/course_blocks/transformers/user_partitions.py @@ -3,7 +3,7 @@ User Partitions Transformer """ from openedx.core.djangoapps.content.block_structure.transformer import ( BlockStructureTransformer, - FilteringTransformerMixin, + FilteringTransformerMixin ) from xmodule.partitions.partitions_service import get_all_partitions_for_course diff --git a/lms/djangoapps/course_blocks/transformers/visibility.py b/lms/djangoapps/course_blocks/transformers/visibility.py index bd87260428..2e2048c764 100644 --- a/lms/djangoapps/course_blocks/transformers/visibility.py +++ b/lms/djangoapps/course_blocks/transformers/visibility.py @@ -3,8 +3,9 @@ Visibility Transformer implementation. """ from openedx.core.djangoapps.content.block_structure.transformer import ( BlockStructureTransformer, - FilteringTransformerMixin, + FilteringTransformerMixin ) + from .utils import collect_merged_boolean_field diff --git a/lms/djangoapps/course_blocks/utils.py b/lms/djangoapps/course_blocks/utils.py index 33097b7e00..b2db403d0b 100644 --- a/lms/djangoapps/course_blocks/utils.py +++ b/lms/djangoapps/course_blocks/utils.py @@ -2,6 +2,7 @@ Common utilities for use along with the course blocks. """ import json + from courseware.models import StudentModule diff --git a/lms/djangoapps/course_structure_api/urls.py b/lms/djangoapps/course_structure_api/urls.py index f97dde0ee4..c5b6f37a50 100644 --- a/lms/djangoapps/course_structure_api/urls.py +++ b/lms/djangoapps/course_structure_api/urls.py @@ -3,7 +3,7 @@ Course Structure API URI specification. Patterns here should simply point to version-specific patterns. """ -from django.conf.urls import patterns, url, include +from django.conf.urls import include, patterns, url urlpatterns = patterns( '', diff --git a/lms/djangoapps/course_structure_api/v0/tests.py b/lms/djangoapps/course_structure_api/v0/tests.py index a83baaee27..82b8368625 100644 --- a/lms/djangoapps/course_structure_api/v0/tests.py +++ b/lms/djangoapps/course_structure_api/v0/tests.py @@ -4,13 +4,16 @@ Run these tests @ Devstack: """ # pylint: disable=missing-docstring,invalid-name,maybe-no-member,attribute-defined-outside-init from datetime import datetime -from mock import patch, Mock from django.core.urlresolvers import reverse +from edx_oauth2_provider.tests.factories import AccessTokenFactory, ClientFactory +from mock import Mock, patch +from opaque_keys.edx.locator import CourseLocator from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory -from edx_oauth2_provider.tests.factories import AccessTokenFactory, ClientFactory -from opaque_keys.edx.locator import CourseLocator +from courseware.tests.factories import GlobalStaffFactory, StaffFactory +from openedx.core.djangoapps.content.course_structures.models import CourseStructure +from openedx.core.djangoapps.content.course_structures.tasks import update_course_structure from xmodule.error_module import ErrorDescriptor from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase @@ -18,11 +21,6 @@ from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.xml import CourseLocationManager from xmodule.tests import get_test_system -from courseware.tests.factories import GlobalStaffFactory, StaffFactory -from openedx.core.djangoapps.content.course_structures.models import CourseStructure -from openedx.core.djangoapps.content.course_structures.tasks import update_course_structure - - TEST_SERVER_HOST = 'http://testserver' diff --git a/lms/djangoapps/course_structure_api/v0/urls.py b/lms/djangoapps/course_structure_api/v0/urls.py index 11ba6aef45..8bc0fb9a8f 100644 --- a/lms/djangoapps/course_structure_api/v0/urls.py +++ b/lms/djangoapps/course_structure_api/v0/urls.py @@ -6,7 +6,6 @@ from django.conf.urls import patterns, url from course_structure_api.v0 import views - COURSE_ID_PATTERN = settings.COURSE_ID_PATTERN urlpatterns = patterns( diff --git a/lms/djangoapps/course_wiki/editors.py b/lms/djangoapps/course_wiki/editors.py index eb20915b47..0f37e3fcc4 100644 --- a/lms/djangoapps/course_wiki/editors.py +++ b/lms/djangoapps/course_wiki/editors.py @@ -1,11 +1,9 @@ from django import forms from django.forms.utils import flatatt +from django.template.loader import render_to_string from django.utils.encoding import force_unicode from django.utils.html import conditional_escape from django.utils.safestring import mark_safe - -from django.template.loader import render_to_string - from wiki.editors.base import BaseEditor from wiki.editors.markitup import MarkItUpAdminWidget diff --git a/lms/djangoapps/course_wiki/middleware.py b/lms/djangoapps/course_wiki/middleware.py index a939408c48..434780099a 100644 --- a/lms/djangoapps/course_wiki/middleware.py +++ b/lms/djangoapps/course_wiki/middleware.py @@ -1,16 +1,17 @@ """Middleware for course_wiki""" from urlparse import urlparse + from django.conf import settings +from django.core.exceptions import PermissionDenied from django.http import Http404 from django.shortcuts import redirect -from django.core.exceptions import PermissionDenied from wiki.models import reverse -from courseware.courses import get_course_with_access, get_course_overview_with_access from courseware.access import has_access +from courseware.courses import get_course_overview_with_access, get_course_with_access +from openedx.features.enterprise_support.api import get_enterprise_consent_url from student.models import CourseEnrollment from util.request import course_id_from_url -from openedx.features.enterprise_support.api import get_enterprise_consent_url class WikiAccessMiddleware(object): diff --git a/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_mathjax.py b/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_mathjax.py index b14803744b..fd93c387d0 100644 --- a/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_mathjax.py +++ b/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_mathjax.py @@ -1,6 +1,7 @@ # Source: https://github.com/mayoff/python-markdown-mathjax import markdown + try: # Markdown 2.1.0 changed from 2.0.3. We try importing the new version first, # but import the 2.0.3 version if it fails diff --git a/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_video.py b/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_video.py index 37cf2d4033..00fbeb3cc9 100755 --- a/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_video.py +++ b/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_video.py @@ -129,6 +129,7 @@ u'

[0-9a-f-]+)/$', views.program_details, name='program_details_view'), diff --git a/lms/djangoapps/learner_dashboard/utils.py b/lms/djangoapps/learner_dashboard/utils.py index d214b03a51..4b34c10540 100644 --- a/lms/djangoapps/learner_dashboard/utils.py +++ b/lms/djangoapps/learner_dashboard/utils.py @@ -3,7 +3,6 @@ The utility methods and functions to help the djangoapp logic """ from opaque_keys.edx.keys import CourseKey - FAKE_COURSE_KEY = CourseKey.from_string('course-v1:fake+course+run') diff --git a/lms/djangoapps/learner_dashboard/views.py b/lms/djangoapps/learner_dashboard/views.py index f8411ca5df..e54ab41236 100644 --- a/lms/djangoapps/learner_dashboard/views.py +++ b/lms/djangoapps/learner_dashboard/views.py @@ -5,14 +5,14 @@ from django.http import Http404 from django.views.decorators.http import require_GET from edxmako.shortcuts import render_to_response -from lms.djangoapps.learner_dashboard.utils import strip_course_id, FAKE_COURSE_KEY +from lms.djangoapps.learner_dashboard.utils import FAKE_COURSE_KEY, strip_course_id from openedx.core.djangoapps.catalog.utils import get_programs from openedx.core.djangoapps.programs.models import ProgramsApiConfig from openedx.core.djangoapps.programs.utils import ( - get_program_marketing_url, - ProgramProgressMeter, ProgramDataExtender, + ProgramProgressMeter, get_certificates, + get_program_marketing_url ) from openedx.core.djangoapps.user_api.preferences.api import get_user_preferences diff --git a/lms/djangoapps/lms_migration/management/commands/create_groups.py b/lms/djangoapps/lms_migration/management/commands/create_groups.py index 75dc6975d9..1ec0ebf0a1 100644 --- a/lms/djangoapps/lms_migration/management/commands/create_groups.py +++ b/lms/djangoapps/lms_migration/management/commands/create_groups.py @@ -6,11 +6,11 @@ import os -from django.core.management.base import BaseCommand from django.conf import settings from django.contrib.auth.models import Group -from path import Path as path +from django.core.management.base import BaseCommand from lxml import etree +from path import Path as path def create_groups(): diff --git a/lms/djangoapps/lms_migration/management/commands/create_user.py b/lms/djangoapps/lms_migration/management/commands/create_user.py index 4f70c49b50..e3c6769479 100644 --- a/lms/djangoapps/lms_migration/management/commands/create_user.py +++ b/lms/djangoapps/lms_migration/management/commands/create_user.py @@ -4,21 +4,22 @@ # # Create user. Prompt for groups and ExternalAuthMap -import os -import sys -import string import datetime -from getpass import getpass import json -from random import choice +import os import readline +import string +import sys +from getpass import getpass +from random import choice +from django.contrib.auth.models import Group, User from django.core.management.base import BaseCommand -from student.models import UserProfile, Registration -from openedx.core.djangoapps.external_auth.models import ExternalAuthMap -from django.contrib.auth.models import User, Group from pytz import UTC +from openedx.core.djangoapps.external_auth.models import ExternalAuthMap +from student.models import Registration, UserProfile + class MyCompleter(object): # Custom completer diff --git a/lms/djangoapps/lms_migration/management/commands/manage_course_groups.py b/lms/djangoapps/lms_migration/management/commands/manage_course_groups.py index 3c87762624..0798790e80 100644 --- a/lms/djangoapps/lms_migration/management/commands/manage_course_groups.py +++ b/lms/djangoapps/lms_migration/management/commands/manage_course_groups.py @@ -6,8 +6,9 @@ import re +from django.contrib.auth.models import Group, User from django.core.management.base import BaseCommand -from django.contrib.auth.models import User, Group + #----------------------------------------------------------------------------- # get all staff groups diff --git a/lms/djangoapps/lms_migration/migrate.py b/lms/djangoapps/lms_migration/migrate.py index e3a6751b0d..4e9b794f7b 100644 --- a/lms/djangoapps/lms_migration/migrate.py +++ b/lms/djangoapps/lms_migration/migrate.py @@ -5,13 +5,14 @@ import json import logging import os + +from django.conf import settings +from django.http import HttpResponse + +import track.views import xmodule.modulestore.django as xmodule_django from xmodule.modulestore.django import modulestore -from django.http import HttpResponse -from django.conf import settings -import track.views - try: from django.views.decorators.csrf import csrf_exempt except ImportError: diff --git a/lms/djangoapps/lms_xblock/admin.py b/lms/djangoapps/lms_xblock/admin.py index 81ba9d67fc..61ccb4eefb 100644 --- a/lms/djangoapps/lms_xblock/admin.py +++ b/lms/djangoapps/lms_xblock/admin.py @@ -2,8 +2,9 @@ Django admin dashboard configuration for LMS XBlock infrastructure. """ -from django.contrib import admin from config_models.admin import ConfigurationModelAdmin +from django.contrib import admin + from lms.djangoapps.lms_xblock.models import XBlockAsidesConfig admin.site.register(XBlockAsidesConfig, ConfigurationModelAdmin) diff --git a/lms/djangoapps/lms_xblock/mixin.py b/lms/djangoapps/lms_xblock/mixin.py index 397e85306a..2e850088a6 100644 --- a/lms/djangoapps/lms_xblock/mixin.py +++ b/lms/djangoapps/lms_xblock/mixin.py @@ -4,10 +4,10 @@ Namespace that defines fields common to all blocks used in the LMS #from django.utils.translation import ugettext_noop as _ from lazy import lazy - from xblock.core import XBlock -from xblock.fields import Boolean, Scope, String, XBlockMixin, Dict +from xblock.fields import Boolean, Dict, Scope, String, XBlockMixin from xblock.validation import ValidationMessage + from xmodule.modulestore.inheritance import UserPartitionList from xmodule.partitions.partitions import NoSuchUserPartitionError, NoSuchUserPartitionGroupError diff --git a/lms/djangoapps/lms_xblock/models.py b/lms/djangoapps/lms_xblock/models.py index a67878be48..14129647ca 100644 --- a/lms/djangoapps/lms_xblock/models.py +++ b/lms/djangoapps/lms_xblock/models.py @@ -6,10 +6,8 @@ Includes: rendered in the LMS. """ -from django.db.models import TextField - from config_models.models import ConfigurationModel - +from django.db.models import TextField from xblock.core import XBlockAside diff --git a/lms/djangoapps/lms_xblock/runtime.py b/lms/djangoapps/lms_xblock/runtime.py index 58bf0f1f96..5b165bb186 100644 --- a/lms/djangoapps/lms_xblock/runtime.py +++ b/lms/djangoapps/lms_xblock/runtime.py @@ -1,24 +1,23 @@ """ Module implementing `xblock.runtime.Runtime` functionality for the LMS """ +import xblock.reference.plugins from django.conf import settings from django.core.urlresolvers import reverse from badges.service import BadgingService from badges.utils import badges_enabled +from lms.djangoapps.lms_xblock.models import XBlockAsidesConfig from openedx.core.djangoapps.user_api.course_tag import api as user_course_tag_api -from openedx.core.lib.xblock_utils import xblock_local_resource_url from openedx.core.lib.url_utils import quote_slashes +from openedx.core.lib.xblock_utils import xblock_local_resource_url from request_cache.middleware import RequestCache -import xblock.reference.plugins from xmodule.library_tools import LibraryToolsService -from xmodule.modulestore.django import modulestore, ModuleI18nService +from xmodule.modulestore.django import ModuleI18nService, modulestore from xmodule.partitions.partitions_service import PartitionService from xmodule.services import SettingsService from xmodule.x_module import ModuleSystem -from lms.djangoapps.lms_xblock.models import XBlockAsidesConfig - def handler_url(block, handler_name, suffix='', query='', thirdparty=False): """ diff --git a/lms/djangoapps/lms_xblock/test/test_runtime.py b/lms/djangoapps/lms_xblock/test/test_runtime.py index 0f37ea35ed..aa6331d969 100644 --- a/lms/djangoapps/lms_xblock/test/test_runtime.py +++ b/lms/djangoapps/lms_xblock/test/test_runtime.py @@ -2,24 +2,23 @@ Tests of the LMS XBlock Runtime and associated utilities """ -from django.conf import settings -from ddt import ddt, data -from django.test import TestCase -from mock import Mock, patch from urlparse import urlparse +from ddt import data, ddt +from django.conf import settings +from django.test import TestCase +from mock import Mock, patch from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locations import BlockUsageLocator, CourseLocator, SlashSeparatedCourseKey +from xblock.exceptions import NoSuchServiceError +from xblock.fields import ScopeIds from badges.tests.factories import BadgeClassFactory from badges.tests.test_models import get_image from lms.djangoapps.lms_xblock.runtime import LmsModuleSystem -from xblock.fields import ScopeIds +from student.tests.factories import UserFactory from xmodule.modulestore.django import ModuleI18nService from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xblock.exceptions import NoSuchServiceError - -from student.tests.factories import UserFactory from xmodule.modulestore.tests.factories import CourseFactory diff --git a/lms/djangoapps/lti_provider/management/commands/resend_lti_scores.py b/lms/djangoapps/lti_provider/management/commands/resend_lti_scores.py index 02a556c0a7..a6ef87c80f 100644 --- a/lms/djangoapps/lti_provider/management/commands/resend_lti_scores.py +++ b/lms/djangoapps/lti_provider/management/commands/resend_lti_scores.py @@ -5,11 +5,10 @@ Management command to resend all lti scores for the requested course. import textwrap from django.core.management import BaseCommand - from opaque_keys.edx.keys import CourseKey -from lti_provider.models import GradedAssignment from lti_provider import tasks +from lti_provider.models import GradedAssignment class Command(BaseCommand): diff --git a/lms/djangoapps/lti_provider/management/commands/tests/test_resend_lti_scores.py b/lms/djangoapps/lti_provider/management/commands/tests/test_resend_lti_scores.py index 77e09890dc..52f799d72b 100644 --- a/lms/djangoapps/lti_provider/management/commands/tests/test_resend_lti_scores.py +++ b/lms/djangoapps/lti_provider/management/commands/tests/test_resend_lti_scores.py @@ -5,16 +5,15 @@ Test lti_provider management commands. from django.test import TestCase from mock import patch -from opaque_keys.edx.keys import UsageKey, CourseKey +from opaque_keys.edx.keys import CourseKey, UsageKey +from lti_provider.management.commands import resend_lti_scores +from lti_provider.models import GradedAssignment, LtiConsumer, OutcomeService from student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.utils import TEST_DATA_DIR from xmodule.modulestore.xml_importer import import_course_from_xml -from lti_provider.management.commands import resend_lti_scores -from lti_provider.models import GradedAssignment, LtiConsumer, OutcomeService - class CommandArgsTestCase(TestCase): """ diff --git a/lms/djangoapps/lti_provider/models.py b/lms/djangoapps/lti_provider/models.py index 2dcc0cb61d..f55338c693 100644 --- a/lms/djangoapps/lti_provider/models.py +++ b/lms/djangoapps/lti_provider/models.py @@ -8,15 +8,15 @@ changes. To do that, 1. Go to the edx-platform dir 2. ./manage.py lms schemamigration lti_provider --auto "description" --settings=devstack """ +import logging + from django.contrib.auth.models import User from django.db import models -import logging +from provider.utils import short_token from openedx.core.djangoapps.xmodule_django.models import CourseKeyField, UsageKeyField from openedx.core.djangolib.fields import CharNullField -from provider.utils import short_token - log = logging.getLogger("edx.lti_provider") diff --git a/lms/djangoapps/lti_provider/outcomes.py b/lms/djangoapps/lti_provider/outcomes.py index 2d70b1c97d..a69fede350 100644 --- a/lms/djangoapps/lti_provider/outcomes.py +++ b/lms/djangoapps/lti_provider/outcomes.py @@ -6,11 +6,11 @@ in LTI v1.1. import logging import uuid +import requests +import requests_oauthlib from lxml import etree from lxml.builder import ElementMaker -import requests from requests.exceptions import RequestException -import requests_oauthlib from lti_provider.models import GradedAssignment, OutcomeService diff --git a/lms/djangoapps/lti_provider/signature_validator.py b/lms/djangoapps/lti_provider/signature_validator.py index 3353db18c1..d61276489d 100644 --- a/lms/djangoapps/lti_provider/signature_validator.py +++ b/lms/djangoapps/lti_provider/signature_validator.py @@ -2,8 +2,7 @@ Subclass of oauthlib's RequestValidator that checks an OAuth signature. """ -from oauthlib.oauth1 import SignatureOnlyEndpoint -from oauthlib.oauth1 import RequestValidator +from oauthlib.oauth1 import RequestValidator, SignatureOnlyEndpoint class SignatureValidator(RequestValidator): diff --git a/lms/djangoapps/lti_provider/startup.py b/lms/djangoapps/lti_provider/startup.py index ff27579134..24f5f6e505 100644 --- a/lms/djangoapps/lti_provider/startup.py +++ b/lms/djangoapps/lti_provider/startup.py @@ -1,4 +1,4 @@ """Code run at server start up to initialize the lti_provider app.""" # Import the tasks module to ensure that signal handlers are registered. -import lms.djangoapps.lti_provider.tasks # pylint: disable=unused-import +import lms.djangoapps.lti_provider.tasks # pylint: disable=unused-import diff --git a/lms/djangoapps/lti_provider/tasks.py b/lms/djangoapps/lti_provider/tasks.py index aa9fe79c25..4b57dc7fc0 100644 --- a/lms/djangoapps/lti_provider/tasks.py +++ b/lms/djangoapps/lti_provider/tasks.py @@ -2,18 +2,19 @@ Asynchronous tasks for the LTI provider app. """ +import logging + from django.conf import settings from django.contrib.auth.models import User from django.dispatch import receiver -import logging +from opaque_keys.edx.keys import CourseKey +import lti_provider.outcomes as outcomes +from lms import CELERY_APP from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory from lms.djangoapps.grades.signals.signals import PROBLEM_WEIGHTED_SCORE_CHANGED -from lms import CELERY_APP from lti_provider.models import GradedAssignment -import lti_provider.outcomes as outcomes from lti_provider.views import parse_course_and_usage_keys -from opaque_keys.edx.keys import CourseKey from xmodule.modulestore.django import modulestore log = logging.getLogger("edx.lti_provider") diff --git a/lms/djangoapps/lti_provider/tests/test_outcomes.py b/lms/djangoapps/lti_provider/tests/test_outcomes.py index e7a195554d..c37675a2ba 100644 --- a/lms/djangoapps/lti_provider/tests/test_outcomes.py +++ b/lms/djangoapps/lti_provider/tests/test_outcomes.py @@ -3,19 +3,18 @@ Tests for the LTI outcome service handlers, both in outcomes.py and in tasks.py """ import unittest +import requests +import requests_oauthlib from django.test import TestCase from lxml import etree -from mock import patch, MagicMock, ANY -import requests_oauthlib -import requests +from mock import ANY, MagicMock, patch +from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator -from opaque_keys.edx.locator import CourseLocator, BlockUsageLocator -from student.tests.factories import UserFactory - -from lti_provider.models import GradedAssignment, LtiConsumer, OutcomeService import lti_provider.outcomes as outcomes +from lti_provider.models import GradedAssignment, LtiConsumer, OutcomeService +from student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory, check_mongo_calls +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls class StoreOutcomeParametersTest(TestCase): diff --git a/lms/djangoapps/lti_provider/tests/test_tasks.py b/lms/djangoapps/lti_provider/tests/test_tasks.py index 193a6dac70..2f25af26fe 100644 --- a/lms/djangoapps/lti_provider/tests/test_tasks.py +++ b/lms/djangoapps/lti_provider/tests/test_tasks.py @@ -4,12 +4,12 @@ Tests for the LTI outcome service handlers, both in outcomes.py and in tasks.py import ddt from django.test import TestCase -from mock import patch, MagicMock -from student.tests.factories import UserFactory +from mock import MagicMock, patch +from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator -from lti_provider.models import GradedAssignment, LtiConsumer, OutcomeService import lti_provider.tasks as tasks -from opaque_keys.edx.locator import CourseLocator, BlockUsageLocator +from lti_provider.models import GradedAssignment, LtiConsumer, OutcomeService +from student.tests.factories import UserFactory class BaseOutcomeTest(TestCase): diff --git a/lms/djangoapps/lti_provider/tests/test_users.py b/lms/djangoapps/lti_provider/tests/test_users.py index ae535bb5ba..ca8f5364b4 100644 --- a/lms/djangoapps/lti_provider/tests/test_users.py +++ b/lms/djangoapps/lti_provider/tests/test_users.py @@ -8,9 +8,10 @@ from django.contrib.auth.models import User from django.core.exceptions import PermissionDenied from django.test import TestCase from django.test.client import RequestFactory -from mock import patch, MagicMock -from lti_provider.models import LtiConsumer, LtiUser +from mock import MagicMock, patch + import lti_provider.users as users +from lti_provider.models import LtiConsumer, LtiUser from student.tests.factories import UserFactory diff --git a/lms/djangoapps/lti_provider/tests/test_views.py b/lms/djangoapps/lti_provider/tests/test_views.py index 7c0440bc9f..8882a0ee09 100644 --- a/lms/djangoapps/lti_provider/tests/test_views.py +++ b/lms/djangoapps/lti_provider/tests/test_views.py @@ -5,16 +5,15 @@ Tests for the LTI provider views from django.core.urlresolvers import reverse from django.test import TestCase from django.test.client import RequestFactory -from mock import patch, MagicMock +from mock import MagicMock, patch from nose.plugins.attrib import attr +from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator from courseware.testutils import RenderXBlockTestMixin -from lti_provider import views, models -from opaque_keys.edx.locator import CourseLocator, BlockUsageLocator +from lti_provider import models, views from student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase - LTI_DEFAULT_PARAMS = { 'roles': u'Instructor,urn:lti:instrole:ims/lis/Administrator', 'context_id': u'lti_launch_context_id', diff --git a/lms/djangoapps/lti_provider/users.py b/lms/djangoapps/lti_provider/users.py index 41ec1c8eb9..ce625f35c1 100644 --- a/lms/djangoapps/lti_provider/users.py +++ b/lms/djangoapps/lti_provider/users.py @@ -3,8 +3,8 @@ LTI user management functionality. This module reconciles the two identities that an individual has in the campus LMS platform and on edX. """ -import string import random +import string import uuid from django.conf import settings @@ -12,6 +12,7 @@ from django.contrib.auth import authenticate, login from django.contrib.auth.models import User from django.core.exceptions import PermissionDenied from django.db import IntegrityError, transaction + from lti_provider.models import LtiUser from student.models import UserProfile diff --git a/lms/djangoapps/lti_provider/views.py b/lms/djangoapps/lti_provider/views.py index 5b948c518c..9f5cf18c0c 100644 --- a/lms/djangoapps/lti_provider/views.py +++ b/lms/djangoapps/lti_provider/views.py @@ -2,17 +2,18 @@ LTI Provider view functions """ -from django.conf import settings -from django.http import HttpResponseBadRequest, HttpResponseForbidden, Http404 -from django.views.decorators.csrf import csrf_exempt import logging -from lti_provider.outcomes import store_outcome_parameters +from django.conf import settings +from django.http import Http404, HttpResponseBadRequest, HttpResponseForbidden +from django.views.decorators.csrf import csrf_exempt +from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey, UsageKey + from lti_provider.models import LtiConsumer +from lti_provider.outcomes import store_outcome_parameters from lti_provider.signature_validator import SignatureValidator from lti_provider.users import authenticate_lti_user -from opaque_keys.edx.keys import CourseKey, UsageKey -from opaque_keys import InvalidKeyError from openedx.core.lib.url_utils import unquote_slashes from util.views import add_p3p_header diff --git a/lms/djangoapps/mailing/management/commands/mailchimp_id.py b/lms/djangoapps/mailing/management/commands/mailchimp_id.py index 922d10b80d..8b8f9fccea 100644 --- a/lms/djangoapps/mailing/management/commands/mailchimp_id.py +++ b/lms/djangoapps/mailing/management/commands/mailchimp_id.py @@ -6,7 +6,6 @@ import sys from optparse import make_option from django.core.management.base import BaseCommand, CommandError - from mailsnake import MailSnake diff --git a/lms/djangoapps/mailing/management/commands/mailchimp_sync_announcements.py b/lms/djangoapps/mailing/management/commands/mailchimp_sync_announcements.py index 718f25b34d..188cc54b30 100644 --- a/lms/djangoapps/mailing/management/commands/mailchimp_sync_announcements.py +++ b/lms/djangoapps/mailing/management/commands/mailchimp_sync_announcements.py @@ -4,15 +4,10 @@ Synchronizes the announcement list with all active students. import logging from optparse import make_option +from django.contrib.auth.models import User from django.core.management.base import BaseCommand, CommandError -from django.contrib.auth.models import User - -from .mailchimp_sync_course import ( - connect_mailchimp, get_cleaned, - get_subscribed, get_unsubscribed, - subscribe_with_data -) +from .mailchimp_sync_course import connect_mailchimp, get_cleaned, get_subscribed, get_unsubscribed, subscribe_with_data log = logging.getLogger('edx.mailchimp') diff --git a/lms/djangoapps/mailing/management/commands/mailchimp_sync_course.py b/lms/djangoapps/mailing/management/commands/mailchimp_sync_course.py index 3a1919fbbe..1abc9b4498 100644 --- a/lms/djangoapps/mailing/management/commands/mailchimp_sync_course.py +++ b/lms/djangoapps/mailing/management/commands/mailchimp_sync_course.py @@ -1,21 +1,19 @@ """ Synchronizes a mailchimp list with the students of a course. """ +import itertools import logging import math import random -import itertools +from collections import namedtuple from itertools import chain from optparse import make_option -from collections import namedtuple from django.core.management.base import BaseCommand, CommandError - from mailsnake import MailSnake - -from student.models import UserProfile, unique_id_for_user from opaque_keys.edx.keys import CourseKey +from student.models import UserProfile, unique_id_for_user BATCH_SIZE = 15000 # If you try to subscribe with too many users at once diff --git a/lms/djangoapps/mobile_api/admin.py b/lms/djangoapps/mobile_api/admin.py index 84ae1387a0..3a7c5f5862 100644 --- a/lms/djangoapps/mobile_api/admin.py +++ b/lms/djangoapps/mobile_api/admin.py @@ -2,13 +2,10 @@ Django admin dashboard configuration for LMS XBlock infrastructure. """ -from django.contrib import admin from config_models.admin import ConfigurationModelAdmin -from .models import ( - AppVersionConfig, - MobileApiConfig, - IgnoreMobileAvailableFlagConfig -) +from django.contrib import admin + +from .models import AppVersionConfig, IgnoreMobileAvailableFlagConfig, MobileApiConfig admin.site.register(MobileApiConfig, ConfigurationModelAdmin) admin.site.register(IgnoreMobileAvailableFlagConfig, ConfigurationModelAdmin) diff --git a/lms/djangoapps/mobile_api/course_info/urls.py b/lms/djangoapps/mobile_api/course_info/urls.py index 149ae62481..e1739df4af 100644 --- a/lms/djangoapps/mobile_api/course_info/urls.py +++ b/lms/djangoapps/mobile_api/course_info/urls.py @@ -1,10 +1,10 @@ """ URLs for course_info API """ -from django.conf.urls import patterns, url from django.conf import settings +from django.conf.urls import patterns, url -from .views import CourseUpdatesList, CourseHandoutsList +from .views import CourseHandoutsList, CourseUpdatesList urlpatterns = patterns( 'mobile_api.course_info.views', diff --git a/lms/djangoapps/mobile_api/course_info/views.py b/lms/djangoapps/mobile_api/course_info/views.py index 13557db83b..a4a31bfe11 100644 --- a/lms/djangoapps/mobile_api/course_info/views.py +++ b/lms/djangoapps/mobile_api/course_info/views.py @@ -6,8 +6,8 @@ from rest_framework import generics from rest_framework.response import Response from courseware.courses import get_course_info_section_module -from static_replace import make_static_urls_absolute from openedx.core.lib.xblock_utils import get_course_update_items +from static_replace import make_static_urls_absolute from ..decorators import mobile_course_access, mobile_view diff --git a/lms/djangoapps/mobile_api/decorators.py b/lms/djangoapps/mobile_api/decorators.py index abc04c6fcd..e8eb924562 100644 --- a/lms/djangoapps/mobile_api/decorators.py +++ b/lms/djangoapps/mobile_api/decorators.py @@ -2,18 +2,17 @@ Decorators for Mobile APIs. """ import functools -from rest_framework import status -from rest_framework.response import Response from django.http import Http404 +from opaque_keys.edx.keys import CourseKey +from rest_framework import status +from rest_framework.response import Response from lms.djangoapps.courseware.courses import get_course_with_access from lms.djangoapps.courseware.courseware_access_exception import CoursewareAccessException from lms.djangoapps.courseware.exceptions import CourseAccessRedirect -from opaque_keys.edx.keys import CourseKey -from xmodule.modulestore.django import modulestore - from openedx.core.lib.api.view_utils import view_auth_classes +from xmodule.modulestore.django import modulestore def mobile_course_access(depth=0): diff --git a/lms/djangoapps/mobile_api/middleware.py b/lms/djangoapps/mobile_api/middleware.py index 921cb2f8ab..65c6a3fe59 100644 --- a/lms/djangoapps/mobile_api/middleware.py +++ b/lms/djangoapps/mobile_api/middleware.py @@ -2,15 +2,17 @@ Middleware for Mobile APIs """ from datetime import datetime + from django.conf import settings from django.core.cache import cache from django.http import HttpResponse from pytz import UTC + +import request_cache from mobile_api.mobile_platform import MobilePlatform from mobile_api.models import AppVersionConfig from mobile_api.utils import parsed_version from openedx.core.lib.mobile_utils import is_request_from_mobile_app -import request_cache class AppVersionUpgrade(object): diff --git a/lms/djangoapps/mobile_api/models.py b/lms/djangoapps/mobile_api/models.py index 05744706d4..839a496c06 100644 --- a/lms/djangoapps/mobile_api/models.py +++ b/lms/djangoapps/mobile_api/models.py @@ -1,11 +1,11 @@ """ ConfigurationModel for the mobile_api djangoapp. """ +from config_models.models import ConfigurationModel from django.db import models -from config_models.models import ConfigurationModel -from .mobile_platform import PLATFORM_CLASSES from . import utils +from .mobile_platform import PLATFORM_CLASSES class MobileApiConfig(ConfigurationModel): diff --git a/lms/djangoapps/mobile_api/tests/test_middleware.py b/lms/djangoapps/mobile_api/tests/test_middleware.py index d2e26ed776..b2547f6fc0 100644 --- a/lms/djangoapps/mobile_api/tests/test_middleware.py +++ b/lms/djangoapps/mobile_api/tests/test_middleware.py @@ -2,11 +2,13 @@ Tests for Version Based App Upgrade Middleware """ from datetime import datetime + import ddt +import mock from django.core.cache import caches from django.http import HttpRequest, HttpResponse -import mock from pytz import UTC + from mobile_api.middleware import AppVersionUpgrade from mobile_api.models import AppVersionConfig from openedx.core.djangolib.testing.utils import CacheIsolationTestCase diff --git a/lms/djangoapps/mobile_api/tests/test_milestones.py b/lms/djangoapps/mobile_api/tests/test_milestones.py index bd200bb97d..3c7f22b4e2 100644 --- a/lms/djangoapps/mobile_api/tests/test_milestones.py +++ b/lms/djangoapps/mobile_api/tests/test_milestones.py @@ -5,12 +5,9 @@ from django.conf import settings from mock import patch from courseware.access_response import MilestoneError -from courseware.tests.test_entrance_exam import answer_entrance_exam_problem, add_entrance_exam_milestone +from courseware.tests.test_entrance_exam import add_entrance_exam_milestone, answer_entrance_exam_problem from openedx.core.djangolib.testing.utils import get_mock_request -from util.milestones_helpers import ( - add_prerequisite_course, - fulfill_course_milestone, -) +from util.milestones_helpers import add_prerequisite_course, fulfill_course_milestone from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory diff --git a/lms/djangoapps/mobile_api/tests/test_mobile_platform.py b/lms/djangoapps/mobile_api/tests/test_mobile_platform.py index 04ce53a7d0..0f021897e5 100644 --- a/lms/djangoapps/mobile_api/tests/test_mobile_platform.py +++ b/lms/djangoapps/mobile_api/tests/test_mobile_platform.py @@ -3,6 +3,7 @@ Tests for Platform against Mobile App Request """ import ddt from django.test import TestCase + from mobile_api.mobile_platform import MobilePlatform diff --git a/lms/djangoapps/mobile_api/tests/test_model.py b/lms/djangoapps/mobile_api/tests/test_model.py index 89832f92b7..15ffad9dde 100644 --- a/lms/djangoapps/mobile_api/tests/test_model.py +++ b/lms/djangoapps/mobile_api/tests/test_model.py @@ -2,9 +2,11 @@ Tests for Mobile API Configuration Models """ from datetime import datetime + import ddt from django.test import TestCase from pytz import UTC + from mobile_api.models import AppVersionConfig, MobileApiConfig diff --git a/lms/djangoapps/mobile_api/testutils.py b/lms/djangoapps/mobile_api/testutils.py index 35fc627cad..550d9523e1 100644 --- a/lms/djangoapps/mobile_api/testutils.py +++ b/lms/djangoapps/mobile_api/testutils.py @@ -11,27 +11,23 @@ Test utilities for mobile API tests: """ # pylint: disable=no-member from datetime import timedelta -from django.conf import settings -from django.utils import timezone import ddt -from mock import patch +from django.conf import settings from django.core.urlresolvers import reverse -from rest_framework.test import APITestCase +from django.utils import timezone +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 rest_framework.test import APITestCase -from courseware.access_response import ( - MobileAvailabilityError, - StartDateError, - VisibilityError -) +from courseware.access_response import MobileAvailabilityError, StartDateError, VisibilityError from courseware.tests.factories import UserFactory -from student import auth -from student.models import CourseEnrollment from mobile_api.models import IgnoreMobileAvailableFlagConfig from mobile_api.tests.test_milestones import MobileAPIMilestonesMixin +from student import auth +from student.models import CourseEnrollment +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class MobileAPITestCase(ModuleStoreTestCase, APITestCase): diff --git a/lms/djangoapps/mobile_api/urls.py b/lms/djangoapps/mobile_api/urls.py index 864fb9fdf3..e2ada74ccd 100644 --- a/lms/djangoapps/mobile_api/urls.py +++ b/lms/djangoapps/mobile_api/urls.py @@ -1,7 +1,7 @@ """ URLs for mobile API """ -from django.conf.urls import patterns, url, include +from django.conf.urls import include, patterns, url from .users.views import my_user_info diff --git a/lms/djangoapps/mobile_api/users/serializers.py b/lms/djangoapps/mobile_api/users/serializers.py index 6debf74a62..2decf2b449 100644 --- a/lms/djangoapps/mobile_api/users/serializers.py +++ b/lms/djangoapps/mobile_api/users/serializers.py @@ -8,7 +8,7 @@ from rest_framework.reverse import reverse from certificates.api import certificate_downloadable_status from courseware.access import has_access from student.models import CourseEnrollment, User -from util.course import get_link_for_about_page, get_encoded_course_sharing_utm_params +from util.course import get_encoded_course_sharing_utm_params, get_link_for_about_page class CourseOverviewField(serializers.RelatedField): diff --git a/lms/djangoapps/mobile_api/users/tests.py b/lms/djangoapps/mobile_api/users/tests.py index 2cb0e64263..a385dcd447 100644 --- a/lms/djangoapps/mobile_api/users/tests.py +++ b/lms/djangoapps/mobile_api/users/tests.py @@ -5,39 +5,35 @@ Tests for users API import datetime import ddt -from mock import patch -from nose.plugins.attrib import attr import pytz from django.conf import settings -from django.utils import timezone from django.template import defaultfilters from django.test import RequestFactory, override_settings +from django.utils import timezone from milestones.tests.utils import MilestonesTestCaseMixin -from xmodule.course_module import DEFAULT_START_DATE -from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory +from mock import patch +from nose.plugins.attrib import attr from certificates.api import generate_user_certificates from certificates.models import CertificateStatuses from certificates.tests.factories import GeneratedCertificateFactory -from courseware.access_response import ( - MilestoneError, - StartDateError, - VisibilityError, -) from course_modes.models import CourseMode +from courseware.access_response import MilestoneError, StartDateError, VisibilityError from lms.djangoapps.grades.tests.utils import mock_passing_grade -from openedx.core.lib.courses import course_image_url -from student.models import CourseEnrollment -from util.milestones_helpers import set_prerequisite_courses -from util.testing import UrlResetMixin -from .. import errors from mobile_api.testutils import ( MobileAPITestCase, MobileAuthTestMixin, MobileAuthUserTestMixin, - MobileCourseAccessTestMixin, + MobileCourseAccessTestMixin ) +from openedx.core.lib.courses import course_image_url +from student.models import CourseEnrollment +from util.milestones_helpers import set_prerequisite_courses +from util.testing import UrlResetMixin +from xmodule.course_module import DEFAULT_START_DATE +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from .. import errors from .serializers import CourseEnrollmentSerializer diff --git a/lms/djangoapps/mobile_api/users/urls.py b/lms/djangoapps/mobile_api/users/urls.py index 64f1ad4a55..91efbb0101 100644 --- a/lms/djangoapps/mobile_api/users/urls.py +++ b/lms/djangoapps/mobile_api/users/urls.py @@ -1,11 +1,10 @@ """ URLs for user API """ -from django.conf.urls import patterns, url from django.conf import settings +from django.conf.urls import patterns, url -from .views import UserDetail, UserCourseEnrollmentsList, UserCourseStatus - +from .views import UserCourseEnrollmentsList, UserCourseStatus, UserDetail urlpatterns = patterns( 'mobile_api.users.views', diff --git a/lms/djangoapps/mobile_api/users/views.py b/lms/djangoapps/mobile_api/users/views.py index 9ec9a071b6..6a5a8b9be1 100644 --- a/lms/djangoapps/mobile_api/users/views.py +++ b/lms/djangoapps/mobile_api/users/views.py @@ -4,13 +4,13 @@ Views for user API from django.shortcuts import redirect from django.utils import dateparse - +from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import UsageKey from rest_framework import generics, views from rest_framework.decorators import api_view from rest_framework.response import Response - -from opaque_keys.edx.keys import UsageKey -from opaque_keys import InvalidKeyError +from xblock.fields import Scope +from xblock.runtime import KeyValueStore from courseware.access import is_mobile_available_for_user from courseware.courses import get_current_child @@ -18,15 +18,12 @@ from courseware.model_data import FieldDataCache from courseware.module_render import get_module_for_descriptor from courseware.views.index import save_positions_recursively_up from student.models import CourseEnrollment, User - -from xblock.fields import Scope -from xblock.runtime import KeyValueStore from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError -from .serializers import CourseEnrollmentSerializer, UserSerializer from .. import errors from ..decorators import mobile_course_access, mobile_view +from .serializers import CourseEnrollmentSerializer, UserSerializer @mobile_view(is_user=True) diff --git a/lms/djangoapps/mobile_api/video_outlines/serializers.py b/lms/djangoapps/mobile_api/video_outlines/serializers.py index f1eb5a813b..5c0e08315a 100644 --- a/lms/djangoapps/mobile_api/video_outlines/serializers.py +++ b/lms/djangoapps/mobile_api/video_outlines/serializers.py @@ -1,19 +1,16 @@ """ Serializer for video outline """ +from edxval.api import ValInternalError, get_video_info_for_course_and_profiles from rest_framework.reverse import reverse -from xmodule.modulestore.mongo.base import BLOCK_TYPES_WITH_CHILDREN -from xmodule.modulestore.django import modulestore from courseware.access import has_access from courseware.courses import get_course_by_id from courseware.model_data import FieldDataCache from courseware.module_render import get_module_for_descriptor from util.module_utils import get_dynamic_descriptor_children - -from edxval.api import ( - get_video_info_for_course_and_profiles, ValInternalError -) +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.mongo.base import BLOCK_TYPES_WITH_CHILDREN class BlockOutline(object): diff --git a/lms/djangoapps/mobile_api/video_outlines/tests.py b/lms/djangoapps/mobile_api/video_outlines/tests.py index 877bb87b7c..144649729f 100644 --- a/lms/djangoapps/mobile_api/video_outlines/tests.py +++ b/lms/djangoapps/mobile_api/video_outlines/tests.py @@ -4,23 +4,23 @@ Tests for video outline API """ import itertools -from uuid import uuid4 from collections import namedtuple +from uuid import uuid4 import ddt -from nose.plugins.attrib import attr from edxval import api -from xmodule.modulestore.tests.factories import ItemFactory -from xmodule.video_module import transcripts_utils -from xmodule.modulestore.django import modulestore -from xmodule.partitions.partitions import Group, UserPartition from milestones.tests.utils import MilestonesTestCaseMixin +from nose.plugins.attrib import attr from mobile_api.models import MobileApiConfig -from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory -from openedx.core.djangoapps.course_groups.models import CourseUserGroupPartitionGroup -from openedx.core.djangoapps.course_groups.cohorts import add_user_to_cohort, remove_user_from_cohort from mobile_api.testutils import MobileAPITestCase, MobileAuthTestMixin, MobileCourseAccessTestMixin +from openedx.core.djangoapps.course_groups.cohorts import add_user_to_cohort, remove_user_from_cohort +from openedx.core.djangoapps.course_groups.models import CourseUserGroupPartitionGroup +from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.factories import ItemFactory +from xmodule.partitions.partitions import Group, UserPartition +from xmodule.video_module import transcripts_utils class TestVideoAPITestCase(MobileAPITestCase): diff --git a/lms/djangoapps/mobile_api/video_outlines/urls.py b/lms/djangoapps/mobile_api/video_outlines/urls.py index 3ce13378ad..01c05acb7e 100644 --- a/lms/djangoapps/mobile_api/video_outlines/urls.py +++ b/lms/djangoapps/mobile_api/video_outlines/urls.py @@ -1,8 +1,8 @@ """ URLs for video outline API """ -from django.conf.urls import patterns, url from django.conf import settings +from django.conf.urls import patterns, url from .views import VideoSummaryList, VideoTranscripts diff --git a/lms/djangoapps/mobile_api/video_outlines/views.py b/lms/djangoapps/mobile_api/video_outlines/views.py index d471d40b21..2160b02984 100644 --- a/lms/djangoapps/mobile_api/video_outlines/views.py +++ b/lms/djangoapps/mobile_api/video_outlines/views.py @@ -9,12 +9,11 @@ general XBlock representation in this rather specialized formatting. from functools import partial from django.http import Http404, HttpResponse -from mobile_api.models import MobileApiConfig - +from opaque_keys.edx.locator import BlockUsageLocator from rest_framework import generics from rest_framework.response import Response -from opaque_keys.edx.locator import BlockUsageLocator +from mobile_api.models import MobileApiConfig from xmodule.exceptions import NotFoundError from xmodule.modulestore.django import modulestore diff --git a/lms/djangoapps/notes/api.py b/lms/djangoapps/notes/api.py index 44abb99e20..a892bf05e5 100644 --- a/lms/djangoapps/notes/api.py +++ b/lms/djangoapps/notes/api.py @@ -1,15 +1,15 @@ -from opaque_keys.edx.locations import SlashSeparatedCourseKey -from django.contrib.auth.decorators import login_required -from django.http import HttpResponse, Http404 -from django.core.exceptions import ValidationError - -from notes.models import Note -from notes.utils import notes_enabled_for_course -from courseware.courses import get_course_with_access - +import collections import json import logging -import collections + +from django.contrib.auth.decorators import login_required +from django.core.exceptions import ValidationError +from django.http import Http404, HttpResponse +from opaque_keys.edx.locations import SlashSeparatedCourseKey + +from courseware.courses import get_course_with_access +from notes.models import Note +from notes.utils import notes_enabled_for_course log = logging.getLogger(__name__) diff --git a/lms/djangoapps/notes/models.py b/lms/djangoapps/notes/models.py index 4d9a5bdd6f..f7138c2c34 100644 --- a/lms/djangoapps/notes/models.py +++ b/lms/djangoapps/notes/models.py @@ -1,10 +1,11 @@ -from django.db import models -from django.contrib.auth.models import User -from django.core.urlresolvers import reverse -from django.core.exceptions import ValidationError -from django.utils.html import strip_tags import json +from django.contrib.auth.models import User +from django.core.exceptions import ValidationError +from django.core.urlresolvers import reverse +from django.db import models +from django.utils.html import strip_tags + from openedx.core.djangoapps.xmodule_django.models import CourseKeyField diff --git a/lms/djangoapps/notes/tests.py b/lms/djangoapps/notes/tests.py index 69a2593d6d..bf14fb8865 100644 --- a/lms/djangoapps/notes/tests.py +++ b/lms/djangoapps/notes/tests.py @@ -2,22 +2,21 @@ Unit tests for the notes app. """ -from mock import patch, Mock - -from opaque_keys.edx.locations import SlashSeparatedCourseKey -from django.test import TestCase, RequestFactory -from django.test.client import Client -from django.core.urlresolvers import reverse -from django.contrib.auth.models import User -from django.core.exceptions import ValidationError - import json +from django.contrib.auth.models import User +from django.core.exceptions import ValidationError +from django.core.urlresolvers import reverse +from django.test import RequestFactory, TestCase +from django.test.client import Client +from mock import Mock, patch +from opaque_keys.edx.locations import SlashSeparatedCourseKey + +from courseware.tabs import CourseTab, get_course_tab_list +from notes import api, models, utils +from student.tests.factories import CourseEnrollmentFactory, UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from courseware.tabs import get_course_tab_list, CourseTab -from student.tests.factories import UserFactory, CourseEnrollmentFactory -from notes import utils, api, models class UtilsTest(ModuleStoreTestCase): diff --git a/lms/djangoapps/notes/urls.py b/lms/djangoapps/notes/urls.py index 6abe92253a..c083507e78 100644 --- a/lms/djangoapps/notes/urls.py +++ b/lms/djangoapps/notes/urls.py @@ -1,6 +1,5 @@ from django.conf.urls import patterns, url - id_regex = r"(?P[0-9A-Fa-f]+)" urlpatterns = patterns('notes.api', url(r'^api$', 'api_request', {'resource': 'root'}, name='notes_api_root'), diff --git a/lms/djangoapps/notes/views.py b/lms/djangoapps/notes/views.py index 4b2ce51c02..47690c4e41 100644 --- a/lms/djangoapps/notes/views.py +++ b/lms/djangoapps/notes/views.py @@ -5,15 +5,15 @@ Views to support the edX Notes feature. from django.conf import settings from django.contrib.auth.decorators import login_required from django.http import Http404 - -from edxmako.shortcuts import render_to_response +from django.utils.translation import ugettext_noop from opaque_keys.edx.locations import SlashSeparatedCourseKey + from courseware.courses import get_course_with_access from courseware.tabs import EnrolledTab +from edxmako.shortcuts import render_to_response from notes.models import Note from notes.utils import notes_enabled_for_course from xmodule.annotator_token import retrieve_token -from django.utils.translation import ugettext_noop @login_required diff --git a/lms/djangoapps/notification_prefs/features/unsubscribe.py b/lms/djangoapps/notification_prefs/features/unsubscribe.py index 00221732ce..627816cb42 100644 --- a/lms/djangoapps/notification_prefs/features/unsubscribe.py +++ b/lms/djangoapps/notification_prefs/features/unsubscribe.py @@ -1,8 +1,8 @@ from django.contrib.auth.models import User from lettuce import step, world -from notification_prefs import NOTIFICATION_PREF_KEY -from openedx.core.djangoapps.user_api.preferences.api import set_user_preference, get_user_preference +from notification_prefs import NOTIFICATION_PREF_KEY +from openedx.core.djangoapps.user_api.preferences.api import get_user_preference, set_user_preference USERNAME = "robot" UNSUB_TOKEN = "av9E-14sAP1bVBRCPbrTHQ==" diff --git a/lms/djangoapps/notification_prefs/tests.py b/lms/djangoapps/notification_prefs/tests.py index e67d4e91ab..87854badfa 100644 --- a/lms/djangoapps/notification_prefs/tests.py +++ b/lms/djangoapps/notification_prefs/tests.py @@ -10,9 +10,9 @@ from django.test.utils import override_settings from mock import Mock, patch from notification_prefs import NOTIFICATION_PREF_KEY -from notification_prefs.views import ajax_enable, ajax_disable, ajax_status, set_subscription, UsernameCipher -from student.tests.factories import UserFactory +from notification_prefs.views import UsernameCipher, ajax_disable, ajax_enable, ajax_status, set_subscription from openedx.core.djangoapps.user_api.models import UserPreference +from student.tests.factories import UserFactory from util.testing import UrlResetMixin diff --git a/lms/djangoapps/notification_prefs/views.py b/lms/djangoapps/notification_prefs/views.py index c60d702e21..09e9bf64f7 100644 --- a/lms/djangoapps/notification_prefs/views.py +++ b/lms/djangoapps/notification_prefs/views.py @@ -1,9 +1,9 @@ -from base64 import urlsafe_b64encode, urlsafe_b64decode -from hashlib import sha256 import json +from base64 import urlsafe_b64decode, urlsafe_b64encode +from hashlib import sha256 -from Crypto.Cipher import AES from Crypto import Random +from Crypto.Cipher import AES from django.conf import settings from django.contrib.auth.models import User from django.core.exceptions import PermissionDenied diff --git a/lms/djangoapps/notifier_api/serializers.py b/lms/djangoapps/notifier_api/serializers.py index dc21bb48ef..e20796a3cf 100644 --- a/lms/djangoapps/notifier_api/serializers.py +++ b/lms/djangoapps/notifier_api/serializers.py @@ -2,11 +2,10 @@ from django.contrib.auth.models import User from django.http import Http404 from rest_framework import serializers +from lms.djangoapps.notification_prefs import NOTIFICATION_PREF_KEY from openedx.core.djangoapps.course_groups.cohorts import is_course_cohorted from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY -from lms.djangoapps.notification_prefs import NOTIFICATION_PREF_KEY - class NotifierUserSerializer(serializers.ModelSerializer): """ diff --git a/lms/djangoapps/notifier_api/tests.py b/lms/djangoapps/notifier_api/tests.py index e55857e752..ac3d9dba8a 100644 --- a/lms/djangoapps/notifier_api/tests.py +++ b/lms/djangoapps/notifier_api/tests.py @@ -4,17 +4,17 @@ import ddt from django.conf import settings from django.test.client import RequestFactory from django.test.utils import override_settings +from opaque_keys.edx.locator import CourseLocator -from django_comment_common.models import Role, Permission +from django_comment_common.models import Permission, Role from notification_prefs import NOTIFICATION_PREF_KEY from notifier_api.views import NotifierUsersViewSet -from opaque_keys.edx.locator import CourseLocator -from student.models import CourseEnrollment -from student.tests.factories import UserFactory, CourseEnrollmentFactory from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY from openedx.core.djangoapps.user_api.models import UserPreference from openedx.core.djangoapps.user_api.tests.factories import UserPreferenceFactory +from student.models import CourseEnrollment +from student.tests.factories import CourseEnrollmentFactory, UserFactory from util.testing import UrlResetMixin from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/lms/djangoapps/notifier_api/urls.py b/lms/djangoapps/notifier_api/urls.py index 4a1d65dd8b..f65260df50 100644 --- a/lms/djangoapps/notifier_api/urls.py +++ b/lms/djangoapps/notifier_api/urls.py @@ -3,7 +3,6 @@ from rest_framework import routers from notifier_api.views import NotifierUsersViewSet - notifier_api_router = routers.DefaultRouter() notifier_api_router.register(r'users', NotifierUsersViewSet, base_name="notifier_users") urlpatterns = patterns( diff --git a/lms/djangoapps/notifier_api/views.py b/lms/djangoapps/notifier_api/views.py index 44e1c78037..2786cfb96a 100644 --- a/lms/djangoapps/notifier_api/views.py +++ b/lms/djangoapps/notifier_api/views.py @@ -1,7 +1,7 @@ from django.contrib.auth.models import User -from rest_framework.viewsets import ReadOnlyModelViewSet -from rest_framework.response import Response from rest_framework import pagination +from rest_framework.response import Response +from rest_framework.viewsets import ReadOnlyModelViewSet from notification_prefs import NOTIFICATION_PREF_KEY from notifier_api.serializers import NotifierUserSerializer diff --git a/lms/djangoapps/oauth2_handler/handlers.py b/lms/djangoapps/oauth2_handler/handlers.py index 122ccd41ff..da7f44043d 100644 --- a/lms/djangoapps/oauth2_handler/handlers.py +++ b/lms/djangoapps/oauth2_handler/handlers.py @@ -7,9 +7,8 @@ from courseware.access import has_access from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY from openedx.core.djangoapps.user_api.models import UserPreference -from student.models import anonymous_id_for_user -from student.models import UserProfile -from student.roles import GlobalStaff, CourseStaffRole, CourseInstructorRole +from student.models import UserProfile, anonymous_id_for_user +from student.roles import CourseInstructorRole, CourseStaffRole, GlobalStaff class OpenIDHandler(object): diff --git a/lms/djangoapps/oauth2_handler/tests.py b/lms/djangoapps/oauth2_handler/tests.py index 878dadcb6a..e9316170db 100644 --- a/lms/djangoapps/oauth2_handler/tests.py +++ b/lms/djangoapps/oauth2_handler/tests.py @@ -1,20 +1,16 @@ # pylint: disable=missing-docstring from django.core.cache import cache from django.test.utils import override_settings +# Will also run default tests for IDTokens and UserInfo +from edx_oauth2_provider.tests import IDTokenTestCase, UserInfoTestCase from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY from openedx.core.djangoapps.user_api.preferences.api import set_user_preference -from student.models import anonymous_id_for_user -from student.models import UserProfile -from student.roles import (CourseInstructorRole, CourseStaffRole, GlobalStaff, - OrgInstructorRole, OrgStaffRole) +from student.models import UserProfile, anonymous_id_for_user +from student.roles import CourseInstructorRole, CourseStaffRole, GlobalStaff, OrgInstructorRole, OrgStaffRole from student.tests.factories import UserFactory, UserProfileFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import (check_mongo_calls, CourseFactory) - - -# Will also run default tests for IDTokens and UserInfo -from edx_oauth2_provider.tests import IDTokenTestCase, UserInfoTestCase +from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls class BaseTestMixin(ModuleStoreTestCase): diff --git a/lms/djangoapps/rss_proxy/admin.py b/lms/djangoapps/rss_proxy/admin.py index fa5af3753b..b0e7c0586a 100644 --- a/lms/djangoapps/rss_proxy/admin.py +++ b/lms/djangoapps/rss_proxy/admin.py @@ -2,6 +2,7 @@ Admin module for the rss_proxy djangoapp. """ from django.contrib import admin + from rss_proxy.models import WhitelistedRssUrl admin.site.register(WhitelistedRssUrl) diff --git a/lms/djangoapps/rss_proxy/tests/test_models.py b/lms/djangoapps/rss_proxy/tests/test_models.py index c880eee623..77bb599e55 100644 --- a/lms/djangoapps/rss_proxy/tests/test_models.py +++ b/lms/djangoapps/rss_proxy/tests/test_models.py @@ -2,6 +2,7 @@ Tests for the rss_proxy models """ from django.test import TestCase + from rss_proxy.models import WhitelistedRssUrl diff --git a/lms/djangoapps/rss_proxy/tests/test_views.py b/lms/djangoapps/rss_proxy/tests/test_views.py index 90a499e19a..1a40fa3c50 100644 --- a/lms/djangoapps/rss_proxy/tests/test_views.py +++ b/lms/djangoapps/rss_proxy/tests/test_views.py @@ -1,9 +1,10 @@ """ Tests for the rss_proxy views """ -from django.test import TestCase from django.core.urlresolvers import reverse -from mock import patch, Mock +from django.test import TestCase +from mock import Mock, patch + from rss_proxy.models import WhitelistedRssUrl diff --git a/lms/djangoapps/rss_proxy/urls.py b/lms/djangoapps/rss_proxy/urls.py index b61772c9e3..bacfe92e2d 100644 --- a/lms/djangoapps/rss_proxy/urls.py +++ b/lms/djangoapps/rss_proxy/urls.py @@ -3,7 +3,6 @@ URLs for the rss_proxy djangoapp. """ from django.conf.urls import url - urlpatterns = [ url(r"^$", "rss_proxy.views.proxy", name="proxy"), ] diff --git a/lms/djangoapps/rss_proxy/views.py b/lms/djangoapps/rss_proxy/views.py index 023d0529a6..15c86988ed 100644 --- a/lms/djangoapps/rss_proxy/views.py +++ b/lms/djangoapps/rss_proxy/views.py @@ -2,12 +2,11 @@ Views for the rss_proxy djangoapp. """ import requests - from django.conf import settings from django.core.cache import cache from django.http import HttpResponse, HttpResponseNotFound -from rss_proxy.models import WhitelistedRssUrl +from rss_proxy.models import WhitelistedRssUrl CACHE_KEY_RSS = "rss_proxy.{url}" diff --git a/lms/djangoapps/shoppingcart/admin.py b/lms/djangoapps/shoppingcart/admin.py index 9385eef334..e40646302d 100644 --- a/lms/djangoapps/shoppingcart/admin.py +++ b/lms/djangoapps/shoppingcart/admin.py @@ -1,12 +1,13 @@ """Django admin interface for the shopping cart models. """ from ratelimitbackend import admin + from shoppingcart.models import ( - PaidCourseRegistrationAnnotation, Coupon, + CourseRegistrationCodeInvoiceItem, DonationConfiguration, Invoice, - CourseRegistrationCodeInvoiceItem, - InvoiceTransaction + InvoiceTransaction, + PaidCourseRegistrationAnnotation ) diff --git a/lms/djangoapps/shoppingcart/api.py b/lms/djangoapps/shoppingcart/api.py index 65f2b95508..b8157cab37 100644 --- a/lms/djangoapps/shoppingcart/api.py +++ b/lms/djangoapps/shoppingcart/api.py @@ -2,8 +2,9 @@ API for for getting information about the user's shopping cart. """ from django.core.urlresolvers import reverse -from xmodule.modulestore.django import ModuleI18nService + from shoppingcart.models import OrderItem +from xmodule.modulestore.django import ModuleI18nService def order_history(user, **kwargs): diff --git a/lms/djangoapps/shoppingcart/context_processor.py b/lms/djangoapps/shoppingcart/context_processor.py index 95411944bb..eb3546eea4 100644 --- a/lms/djangoapps/shoppingcart/context_processor.py +++ b/lms/djangoapps/shoppingcart/context_processor.py @@ -6,7 +6,7 @@ navigation. We want to do this in the context_processor to 2) because navigation.html is "called" by being included in other templates, there's no "views.py" to put this. """ -from .models import Order, PaidCourseRegistration, CourseRegCodeItem +from .models import CourseRegCodeItem, Order, PaidCourseRegistration from .utils import is_shopping_cart_enabled diff --git a/lms/djangoapps/shoppingcart/decorators.py b/lms/djangoapps/shoppingcart/decorators.py index 9f4366f8bb..10f132bfc3 100644 --- a/lms/djangoapps/shoppingcart/decorators.py +++ b/lms/djangoapps/shoppingcart/decorators.py @@ -3,6 +3,7 @@ This file defines any decorators used by the shopping cart app """ from django.http import Http404 + from .utils import is_shopping_cart_enabled diff --git a/lms/djangoapps/shoppingcart/management/commands/retire_order.py b/lms/djangoapps/shoppingcart/management/commands/retire_order.py index e6539e2c13..a48925b28d 100644 --- a/lms/djangoapps/shoppingcart/management/commands/retire_order.py +++ b/lms/djangoapps/shoppingcart/management/commands/retire_order.py @@ -4,8 +4,9 @@ marked as "purchased" in the db """ from django.core.management.base import BaseCommand + +from shoppingcart.exceptions import InvalidStatusToRetire, UnexpectedOrderItemStatus from shoppingcart.models import Order -from shoppingcart.exceptions import UnexpectedOrderItemStatus, InvalidStatusToRetire class Command(BaseCommand): diff --git a/lms/djangoapps/shoppingcart/management/tests/test_retire_order.py b/lms/djangoapps/shoppingcart/management/tests/test_retire_order.py index 140cbd309a..c11f37dc0e 100644 --- a/lms/djangoapps/shoppingcart/management/tests/test_retire_order.py +++ b/lms/djangoapps/shoppingcart/management/tests/test_retire_order.py @@ -1,13 +1,14 @@ """Tests for the retire_order command""" from tempfile import NamedTemporaryFile + from django.core.management import call_command from course_modes.models import CourseMode +from shoppingcart.models import CertificateItem, Order +from student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from shoppingcart.models import Order, CertificateItem -from student.tests.factories import UserFactory class TestRetireOrder(ModuleStoreTestCase): diff --git a/lms/djangoapps/shoppingcart/models.py b/lms/djangoapps/shoppingcart/models.py index dc4de3e044..144df4bbed 100644 --- a/lms/djangoapps/shoppingcart/models.py +++ b/lms/djangoapps/shoppingcart/models.py @@ -1,59 +1,57 @@ # pylint: disable=arguments-differ """ Models for the shopping cart and assorted purchase types """ -from collections import namedtuple -from datetime import datetime -from datetime import timedelta -from decimal import Decimal +import csv import json -import analytics -from io import BytesIO -from django.db.models import Q, F -import pytz import logging import smtplib import StringIO -import csv +from collections import namedtuple +from datetime import datetime, timedelta +from decimal import Decimal +from io import BytesIO + +import analytics +import pytz from boto.exception import BotoServerError # this is a super-class of SESError and catches connection errors -from django.dispatch import receiver -from django.db import models +from config_models.models import ConfigurationModel from django.conf import settings +from django.contrib.auth.models import User from django.core.exceptions import ObjectDoesNotExist from django.core.mail import send_mail -from django.contrib.auth.models import User -from django.utils.translation import ugettext as _, ugettext_lazy -from django.db import transaction -from django.db.models import Sum, Count -from django.db.models.signals import post_save, post_delete - +from django.core.mail.message import EmailMessage from django.core.urlresolvers import reverse +from django.db import models, transaction +from django.db.models import Count, F, Q, Sum +from django.db.models.signals import post_delete, post_save +from django.dispatch import receiver +from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext_lazy from model_utils.managers import InheritanceManager from model_utils.models import TimeStampedModel -from django.core.mail.message import EmailMessage -from xmodule.modulestore.django import modulestore -from eventtracking import tracker -from courseware.courses import get_course_by_id -from config_models.models import ConfigurationModel from course_modes.models import CourseMode +from courseware.courses import get_course_by_id from edxmako.shortcuts import render_to_string -from student.models import CourseEnrollment, UNENROLL_DONE, EnrollStatusChange -from util.query import use_read_replica_if_available +from eventtracking import tracker +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.xmodule_django.models import CourseKeyField +from shoppingcart.pdf import PDFInvoice +from student.models import UNENROLL_DONE, CourseEnrollment, EnrollStatusChange +from util.query import use_read_replica_if_available +from xmodule.modulestore.django import modulestore + from .exceptions import ( - InvalidCartItem, - PurchasedCallbackException, - ItemAlreadyInCartException, AlreadyEnrolledInCourseException, CourseDoesNotExistException, - MultipleCouponsNotAllowedException, + InvalidCartItem, InvalidStatusToRetire, - UnexpectedOrderItemStatus, - ItemNotFoundInCartException + ItemAlreadyInCartException, + ItemNotFoundInCartException, + MultipleCouponsNotAllowedException, + PurchasedCallbackException, + UnexpectedOrderItemStatus ) -from shoppingcart.pdf import PDFInvoice -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers - log = logging.getLogger("shoppingcart") diff --git a/lms/djangoapps/shoppingcart/pdf.py b/lms/djangoapps/shoppingcart/pdf.py index 09f1504e30..c80fc3cbf5 100644 --- a/lms/djangoapps/shoppingcart/pdf.py +++ b/lms/djangoapps/shoppingcart/pdf.py @@ -1,19 +1,21 @@ """ Template for PDF Receipt/Invoice Generation """ -from PIL import Image import logging -from reportlab.lib import colors + from django.conf import settings from django.utils.translation import ugettext as _ -from reportlab.pdfgen.canvas import Canvas +from PIL import Image +from reportlab.lib import colors from reportlab.lib.pagesizes import letter -from reportlab.lib.units import mm from reportlab.lib.styles import getSampleStyleSheet +from reportlab.lib.units import mm +from reportlab.pdfgen.canvas import Canvas from reportlab.platypus import Paragraph from reportlab.platypus.tables import Table, TableStyle -from xmodule.modulestore.django import ModuleI18nService + from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from xmodule.modulestore.django import ModuleI18nService log = logging.getLogger("PDF Generation") diff --git a/lms/djangoapps/shoppingcart/processors/CyberSource.py b/lms/djangoapps/shoppingcart/processors/CyberSource.py index b5e84453c1..305d3ffd7c 100644 --- a/lms/djangoapps/shoppingcart/processors/CyberSource.py +++ b/lms/djangoapps/shoppingcart/processors/CyberSource.py @@ -18,22 +18,24 @@ To enable this implementation, add the following to Django settings: } """ -import time -import hmac import binascii -import re +import hmac import json +import re +import time from collections import OrderedDict, defaultdict from decimal import Decimal, InvalidOperation from hashlib import sha1 from textwrap import dedent + from django.conf import settings from django.utils.translation import ugettext as _ + from edxmako.shortcuts import render_to_string +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from shoppingcart.models import Order from shoppingcart.processors.exceptions import * from shoppingcart.processors.helpers import get_processor_config -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers def process_postpay_callback(params, **kwargs): diff --git a/lms/djangoapps/shoppingcart/processors/CyberSource2.py b/lms/djangoapps/shoppingcart/processors/CyberSource2.py index 6720c17f71..5a3aadd736 100644 --- a/lms/djangoapps/shoppingcart/processors/CyberSource2.py +++ b/lms/djangoapps/shoppingcart/processors/CyberSource2.py @@ -20,24 +20,27 @@ To enable this implementation, add the following Django settings: """ -import hmac import binascii -import re +import hmac import json -import uuid import logging -from textwrap import dedent -from datetime import datetime +import re +import uuid from collections import OrderedDict, defaultdict +from datetime import datetime from decimal import Decimal, InvalidOperation from hashlib import sha256 +from textwrap import dedent + from django.conf import settings -from django.utils.translation import ugettext as _, ugettext_noop +from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext_noop + from edxmako.shortcuts import render_to_string +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from shoppingcart.models import Order from shoppingcart.processors.exceptions import * from shoppingcart.processors.helpers import get_processor_config -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers log = logging.getLogger(__name__) diff --git a/lms/djangoapps/shoppingcart/processors/helpers.py b/lms/djangoapps/shoppingcart/processors/helpers.py index 953c0c5102..78c9e63308 100644 --- a/lms/djangoapps/shoppingcart/processors/helpers.py +++ b/lms/djangoapps/shoppingcart/processors/helpers.py @@ -4,6 +4,7 @@ These methods should be shared among all processor implementations, but should NOT be imported by modules outside this package. """ from django.conf import settings + from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers diff --git a/lms/djangoapps/shoppingcart/processors/tests/test_CyberSource.py b/lms/djangoapps/shoppingcart/processors/tests/test_CyberSource.py index 3d1117feb5..cbfd8b5453 100644 --- a/lms/djangoapps/shoppingcart/processors/tests/test_CyberSource.py +++ b/lms/djangoapps/shoppingcart/processors/tests/test_CyberSource.py @@ -2,32 +2,33 @@ Tests for the CyberSource processor handler """ from collections import OrderedDict + +from django.conf import settings from django.test import TestCase from django.test.utils import override_settings -from django.conf import settings -from student.tests.factories import UserFactory +from mock import Mock, patch + from shoppingcart.models import Order, OrderItem -from shoppingcart.processors.helpers import get_processor_config -from shoppingcart.processors.exceptions import ( - CCProcessorException, - CCProcessorSignatureException, - CCProcessorDataException, - CCProcessorWrongAmountException -) from shoppingcart.processors.CyberSource import ( - render_purchase_form_html, - process_postpay_callback, - processor_hash, - verify_signatures, - sign, REASONCODE_MAP, - record_purchase, get_processor_decline_html, get_processor_exception_html, payment_accepted, + process_postpay_callback, + processor_hash, + record_purchase, + render_purchase_form_html, + sign, + verify_signatures ) -from mock import patch, Mock - +from shoppingcart.processors.exceptions import ( + CCProcessorDataException, + CCProcessorException, + CCProcessorSignatureException, + CCProcessorWrongAmountException +) +from shoppingcart.processors.helpers import get_processor_config +from student.tests.factories import UserFactory TEST_CC_PROCESSOR_NAME = "CyberSource" TEST_CC_PROCESSOR = { diff --git a/lms/djangoapps/shoppingcart/processors/tests/test_CyberSource2.py b/lms/djangoapps/shoppingcart/processors/tests/test_CyberSource2.py index 62b7a1924a..323c12e237 100644 --- a/lms/djangoapps/shoppingcart/processors/tests/test_CyberSource2.py +++ b/lms/djangoapps/shoppingcart/processors/tests/test_CyberSource2.py @@ -2,25 +2,25 @@ """ Tests for the newer CyberSource API implementation. """ -from mock import patch -from django.test import TestCase -from django.conf import settings import ddt +from django.conf import settings +from django.test import TestCase +from mock import patch -from student.tests.factories import UserFactory from shoppingcart.models import Order, OrderItem from shoppingcart.processors.CyberSource2 import ( - processor_hash, - process_postpay_callback, - render_purchase_form_html, + _get_processor_exception_html, get_signed_purchase_params, - _get_processor_exception_html + process_postpay_callback, + processor_hash, + render_purchase_form_html ) from shoppingcart.processors.exceptions import ( - CCProcessorSignatureException, CCProcessorDataException, + CCProcessorSignatureException, CCProcessorWrongAmountException ) +from student.tests.factories import UserFactory @ddt.ddt diff --git a/lms/djangoapps/shoppingcart/reports.py b/lms/djangoapps/shoppingcart/reports.py index a7319ceff9..d9630d99cc 100644 --- a/lms/djangoapps/shoppingcart/reports.py +++ b/lms/djangoapps/shoppingcart/reports.py @@ -1,12 +1,12 @@ """ Objects and functions related to generating CSV reports """ from decimal import Decimal -import unicodecsv +import unicodecsv from django.utils.translation import ugettext as _ -from courseware.courses import get_course_by_id from course_modes.models import CourseMode +from courseware.courses import get_course_by_id from shoppingcart.models import CertificateItem, OrderItem from student.models import CourseEnrollment from util.query import use_read_replica_if_available diff --git a/lms/djangoapps/shoppingcart/tests/payment_fake.py b/lms/djangoapps/shoppingcart/tests/payment_fake.py index 71ef16a758..efb3df62f5 100644 --- a/lms/djangoapps/shoppingcart/tests/payment_fake.py +++ b/lms/djangoapps/shoppingcart/tests/payment_fake.py @@ -13,12 +13,11 @@ request to the view with param "success" set to "success" or "failure". The view defaults to payment success. """ -from django.views.generic.base import View -from django.views.decorators.csrf import csrf_exempt from django.http import HttpResponse, HttpResponseBadRequest +from django.views.decorators.csrf import csrf_exempt +from django.views.generic.base import View + from edxmako.shortcuts import render_to_response - - # We use the same hashing function as the software under test, # because it mainly uses standard libraries, and I want # to avoid duplicating that code. diff --git a/lms/djangoapps/shoppingcart/tests/test_configuration_overrides.py b/lms/djangoapps/shoppingcart/tests/test_configuration_overrides.py index da85df5b66..e70a75db45 100644 --- a/lms/djangoapps/shoppingcart/tests/test_configuration_overrides.py +++ b/lms/djangoapps/shoppingcart/tests/test_configuration_overrides.py @@ -3,17 +3,14 @@ Dashboard with Shopping Cart History tests with configuration overrides. """ from django.core.urlresolvers import reverse - from mock import patch -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory -from shoppingcart.models import ( - Order, PaidCourseRegistration, CertificateItem, Donation -) -from student.tests.factories import UserFactory from course_modes.models import CourseMode from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin +from shoppingcart.models import CertificateItem, Donation, Order, PaidCourseRegistration +from student.tests.factories import UserFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory @patch.dict('django.conf.settings.FEATURES', {'ENABLE_PAID_COURSE_REGISTRATION': True}) diff --git a/lms/djangoapps/shoppingcart/tests/test_context_processor.py b/lms/djangoapps/shoppingcart/tests/test_context_processor.py index 4a62667e3e..93d801a157 100644 --- a/lms/djangoapps/shoppingcart/tests/test_context_processor.py +++ b/lms/djangoapps/shoppingcart/tests/test_context_processor.py @@ -3,16 +3,15 @@ Unit tests for shoppingcart context_processor """ from django.conf import settings from django.contrib.auth.models import AnonymousUser -from mock import patch, Mock +from mock import Mock, patch from course_modes.tests.factories import CourseModeFactory +from shoppingcart.context_processor import user_has_cart_context_processor +from shoppingcart.models import Order, PaidCourseRegistration from student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from shoppingcart.models import Order, PaidCourseRegistration -from shoppingcart.context_processor import user_has_cart_context_processor - class UserCartContextProcessorUnitTest(ModuleStoreTestCase): """ diff --git a/lms/djangoapps/shoppingcart/tests/test_models.py b/lms/djangoapps/shoppingcart/tests/test_models.py index 08e8e27d09..94597e42b1 100644 --- a/lms/djangoapps/shoppingcart/tests/test_models.py +++ b/lms/djangoapps/shoppingcart/tests/test_models.py @@ -1,50 +1,59 @@ """ Tests for the Shopping Cart Models """ -from decimal import Decimal -import datetime -import sys -import json import copy - +import datetime +import json import smtplib -from boto.exception import BotoServerError # this is a super-class of SESError and catches connection errors +import sys +from decimal import Decimal -from mock import patch, MagicMock -from nose.plugins.attrib import attr -import pytz import ddt +import pytz +from boto.exception import BotoServerError # this is a super-class of SESError and catches connection errors +from django.conf import settings +from django.contrib.auth.models import AnonymousUser from django.core import mail from django.core.mail.message import EmailMessage -from django.conf import settings +from django.core.urlresolvers import reverse from django.db import DatabaseError from django.test import TestCase from django.test.utils import override_settings -from django.core.urlresolvers import reverse -from django.contrib.auth.models import AnonymousUser -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory +from mock import MagicMock, patch +from nose.plugins.attrib import attr +from opaque_keys.edx.locator import CourseLocator -from shoppingcart.models import ( - Order, OrderItem, CertificateItem, - InvalidCartItem, CourseRegistrationCode, PaidCourseRegistration, CourseRegCodeItem, - Donation, OrderItemSubclassPK, - Invoice, CourseRegistrationCodeInvoiceItem, InvoiceTransaction, InvoiceHistory, - RegistrationCodeRedemption, - Coupon, CouponRedemption) -from student.tests.factories import UserFactory -from student.models import CourseEnrollment from course_modes.models import CourseMode from shoppingcart.exceptions import ( - PurchasedCallbackException, - CourseDoesNotExistException, - ItemAlreadyInCartException, AlreadyEnrolledInCourseException, + CourseDoesNotExistException, InvalidStatusToRetire, - UnexpectedOrderItemStatus, + ItemAlreadyInCartException, + PurchasedCallbackException, + UnexpectedOrderItemStatus ) - -from opaque_keys.edx.locator import CourseLocator +from shoppingcart.models import ( + CertificateItem, + Coupon, + CouponRedemption, + CourseRegCodeItem, + CourseRegistrationCode, + CourseRegistrationCodeInvoiceItem, + Donation, + InvalidCartItem, + Invoice, + InvoiceHistory, + InvoiceTransaction, + Order, + OrderItem, + OrderItemSubclassPK, + PaidCourseRegistration, + RegistrationCodeRedemption +) +from student.models import CourseEnrollment +from student.tests.factories import UserFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory @attr(shard=3) diff --git a/lms/djangoapps/shoppingcart/tests/test_payment_fake.py b/lms/djangoapps/shoppingcart/tests/test_payment_fake.py index e28997a965..b45b82919a 100644 --- a/lms/djangoapps/shoppingcart/tests/test_payment_fake.py +++ b/lms/djangoapps/shoppingcart/tests/test_payment_fake.py @@ -2,11 +2,13 @@ Tests for the fake payment page used in acceptance tests. """ +from collections import OrderedDict + from django.test import TestCase + from shoppingcart.processors.CyberSource2 import sign, verify_signatures from shoppingcart.processors.exceptions import CCProcessorSignatureException from shoppingcart.tests.payment_fake import PaymentFakeView -from collections import OrderedDict class PaymentFakeViewTest(TestCase): diff --git a/lms/djangoapps/shoppingcart/tests/test_pdf.py b/lms/djangoapps/shoppingcart/tests/test_pdf.py index 635862ad65..c1e520d29a 100644 --- a/lms/djangoapps/shoppingcart/tests/test_pdf.py +++ b/lms/djangoapps/shoppingcart/tests/test_pdf.py @@ -1,11 +1,13 @@ """ Tests for Pdf file """ -from datetime import datetime -from django.test.utils import override_settings -from django.conf import settings import unittest +from datetime import datetime from io import BytesIO + +from django.conf import settings +from django.test.utils import override_settings + from shoppingcart.pdf import PDFInvoice from shoppingcart.utils import parse_pages diff --git a/lms/djangoapps/shoppingcart/tests/test_reports.py b/lms/djangoapps/shoppingcart/tests/test_reports.py index c362336be5..307bdb074d 100644 --- a/lms/djangoapps/shoppingcart/tests/test_reports.py +++ b/lms/djangoapps/shoppingcart/tests/test_reports.py @@ -4,19 +4,24 @@ Tests for the Shopping Cart Models """ import datetime -import pytz import StringIO from textwrap import dedent + +import pytz +from django.conf import settings from mock import patch -from django.conf import settings - from course_modes.models import CourseMode -from shoppingcart.models import (Order, CertificateItem, PaidCourseRegistration, PaidCourseRegistrationAnnotation, - CourseRegCodeItemAnnotation) +from shoppingcart.models import ( + CertificateItem, + CourseRegCodeItemAnnotation, + Order, + PaidCourseRegistration, + PaidCourseRegistrationAnnotation +) from shoppingcart.views import initialize_report -from student.tests.factories import UserFactory from student.models import CourseEnrollment +from student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/lms/djangoapps/shoppingcart/tests/test_views.py b/lms/djangoapps/shoppingcart/tests/test_views.py index dbe64eb158..35b439275b 100644 --- a/lms/djangoapps/shoppingcart/tests/test_views.py +++ b/lms/djangoapps/shoppingcart/tests/test_views.py @@ -1,54 +1,57 @@ """ Tests for Shopping Cart views """ -from collections import OrderedDict -import pytz -from urlparse import urlparse -from decimal import Decimal import json +from collections import OrderedDict +from datetime import datetime, timedelta +from decimal import Decimal +from urlparse import urlparse -from django.http import HttpRequest +import ddt +import pytz from django.conf import settings -from django.test import TestCase -from django.test.utils import override_settings -from django.core.urlresolvers import reverse from django.contrib.admin.sites import AdminSite from django.contrib.auth.models import Group, User from django.contrib.messages.storage.fallback import FallbackStorage from django.core import mail - from django.core.cache import cache -from pytz import UTC +from django.core.urlresolvers import reverse +from django.http import HttpRequest +from django.test import TestCase +from django.test.utils import override_settings from freezegun import freeze_time -from datetime import datetime, timedelta -from mock import patch, Mock +from mock import Mock, patch from nose.plugins.attrib import attr -import ddt +from pytz import UTC from common.test.utils import XssTestMixin -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase, ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory -from student.roles import CourseSalesAdminRole -from util.date_utils import get_default_time_display -from util.testing import UrlResetMixin - -from shoppingcart.views import _can_download_report, _get_date_from_str -from shoppingcart.models import ( - Order, CertificateItem, PaidCourseRegistration, CourseRegCodeItem, - Coupon, CourseRegistrationCode, RegistrationCodeRedemption, - DonationConfiguration, - CouponRedemption) -from student.tests.factories import UserFactory, AdminFactory, CourseModeFactory -from courseware.tests.factories import InstructorFactory -from student.models import CourseEnrollment from course_modes.models import CourseMode +from courseware.tests.factories import InstructorFactory from edxmako.shortcuts import render_to_response from openedx.core.djangoapps.embargo.test_utils import restrict_course -from shoppingcart.processors import render_purchase_form_html from shoppingcart.admin import SoftDeleteCouponAdmin -from shoppingcart.views import initialize_report -from shoppingcart.tests.payment_fake import PaymentFakeView +from shoppingcart.models import ( + CertificateItem, + Coupon, + CouponRedemption, + CourseRegCodeItem, + CourseRegistrationCode, + DonationConfiguration, + Order, + PaidCourseRegistration, + RegistrationCodeRedemption +) +from shoppingcart.processors import render_purchase_form_html from shoppingcart.processors.CyberSource2 import sign +from shoppingcart.tests.payment_fake import PaymentFakeView +from shoppingcart.views import _can_download_report, _get_date_from_str, initialize_report +from student.models import CourseEnrollment +from student.roles import CourseSalesAdminRole +from student.tests.factories import AdminFactory, CourseModeFactory, UserFactory +from util.date_utils import get_default_time_display +from util.testing import UrlResetMixin +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory def mock_render_purchase_form_html(*args, **kwargs): diff --git a/lms/djangoapps/shoppingcart/urls.py b/lms/djangoapps/shoppingcart/urls.py index 9363521ddc..a1cf21bffa 100644 --- a/lms/djangoapps/shoppingcart/urls.py +++ b/lms/djangoapps/shoppingcart/urls.py @@ -1,5 +1,5 @@ -from django.conf.urls import patterns, url from django.conf import settings +from django.conf.urls import patterns, url urlpatterns = patterns( 'shoppingcart.views', diff --git a/lms/djangoapps/shoppingcart/utils.py b/lms/djangoapps/shoppingcart/utils.py index 8eeb536db5..3777cc1e50 100644 --- a/lms/djangoapps/shoppingcart/utils.py +++ b/lms/djangoapps/shoppingcart/utils.py @@ -3,12 +3,13 @@ Utility methods for the Shopping Cart app """ from django.conf import settings -from pdfminer.pdfparser import PDFParser -from pdfminer.pdfdocument import PDFDocument -from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter from pdfminer.converter import PDFPageAggregator +from pdfminer.layout import LAParams, LTFigure, LTTextBox, LTTextLine +from pdfminer.pdfdocument import PDFDocument +from pdfminer.pdfinterp import PDFPageInterpreter, PDFResourceManager from pdfminer.pdfpage import PDFPage -from pdfminer.layout import LAParams, LTTextBox, LTTextLine, LTFigure +from pdfminer.pdfparser import PDFParser + from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers diff --git a/lms/djangoapps/shoppingcart/views.py b/lms/djangoapps/shoppingcart/views.py index d4e6c25762..2273851482 100644 --- a/lms/djangoapps/shoppingcart/views.py +++ b/lms/djangoapps/shoppingcart/views.py @@ -1,58 +1,80 @@ -import logging import datetime import decimal +import json +import logging + import pytz -from ipware.ip import get_ip -from django.db.models import Q +from config_models.decorators import require_config from django.conf import settings -from django.contrib.auth.models import Group -from django.shortcuts import redirect -from django.http import ( - HttpResponse, HttpResponseRedirect, HttpResponseNotFound, - HttpResponseBadRequest, HttpResponseForbidden, Http404 -) -from django.utils.translation import ugettext as _ -from course_modes.models import CourseMode -from util.json_request import JsonResponse -from django.views.decorators.http import require_POST, require_http_methods -from django.core.urlresolvers import reverse -from django.views.decorators.csrf import csrf_exempt -from util.bad_request_rate_limiter import BadRequestRateLimiter -from util.date_utils import get_default_time_display from django.contrib.auth.decorators import login_required -from edxmako.shortcuts import render_to_response +from django.contrib.auth.models import Group +from django.core.urlresolvers import reverse +from django.db.models import Q +from django.http import ( + Http404, + HttpResponse, + HttpResponseBadRequest, + HttpResponseForbidden, + HttpResponseNotFound, + HttpResponseRedirect +) +from django.shortcuts import redirect +from django.utils.translation import ugettext as _ +from django.views.decorators.csrf import csrf_exempt +from django.views.decorators.http import require_http_methods, require_POST +from ipware.ip import get_ip +from opaque_keys import InvalidKeyError from opaque_keys.edx.locations import SlashSeparatedCourseKey from opaque_keys.edx.locator import CourseLocator -from opaque_keys import InvalidKeyError + +from course_modes.models import CourseMode from courseware.courses import get_course_by_id -from config_models.decorators import require_config -from shoppingcart.reports import RefundReport, ItemizedPurchaseReport, UniversityRevenueShareReport, CertificateStatusReport -from student.models import CourseEnrollment, EnrollmentClosedError, CourseFullError, \ - AlreadyEnrolledError +from edxmako.shortcuts import render_to_response from openedx.core.djangoapps.embargo import api as embargo_api +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from shoppingcart.reports import ( + CertificateStatusReport, + ItemizedPurchaseReport, + RefundReport, + UniversityRevenueShareReport +) +from student.models import AlreadyEnrolledError, CourseEnrollment, CourseFullError, EnrollmentClosedError +from util.bad_request_rate_limiter import BadRequestRateLimiter +from util.date_utils import get_default_time_display +from util.json_request import JsonResponse + +from .decorators import enforce_shopping_cart_enabled from .exceptions import ( - ItemAlreadyInCartException, AlreadyEnrolledInCourseException, - CourseDoesNotExistException, ReportTypeDoesNotExistException, - MultipleCouponsNotAllowedException, InvalidCartItem, - ItemNotFoundInCartException, RedemptionCodeError + AlreadyEnrolledInCourseException, + CourseDoesNotExistException, + InvalidCartItem, + ItemAlreadyInCartException, + ItemNotFoundInCartException, + MultipleCouponsNotAllowedException, + RedemptionCodeError, + ReportTypeDoesNotExistException ) from .models import ( - Order, OrderTypes, - PaidCourseRegistration, OrderItem, Coupon, - CertificateItem, CouponRedemption, CourseRegistrationCode, - RegistrationCodeRedemption, CourseRegCodeItem, - Donation, DonationConfiguration + CertificateItem, + Coupon, + CouponRedemption, + CourseRegCodeItem, + CourseRegistrationCode, + Donation, + DonationConfiguration, + Order, + OrderItem, + OrderTypes, + PaidCourseRegistration, + RegistrationCodeRedemption ) from .processors import ( - process_postpay_callback, render_purchase_form_html, - get_signed_purchase_params, get_purchase_endpoint + get_purchase_endpoint, + get_signed_purchase_params, + process_postpay_callback, + render_purchase_form_html ) -import json -from .decorators import enforce_shopping_cart_enabled -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers - - log = logging.getLogger("shoppingcart") AUDIT_LOG = logging.getLogger("audit") diff --git a/lms/djangoapps/static_template_view/tests/test_views.py b/lms/djangoapps/static_template_view/tests/test_views.py index 45550f0896..e6c6b5c1d9 100644 --- a/lms/djangoapps/static_template_view/tests/test_views.py +++ b/lms/djangoapps/static_template_view/tests/test_views.py @@ -1,9 +1,9 @@ """ Tests for static templates """ -from django.test import TestCase from django.conf import settings from django.core.urlresolvers import reverse +from django.test import TestCase class MarketingSiteViewTests(TestCase): diff --git a/lms/djangoapps/static_template_view/views.py b/lms/djangoapps/static_template_view/views.py index 3a13f9a881..67bc790280 100644 --- a/lms/djangoapps/static_template_view/views.py +++ b/lms/djangoapps/static_template_view/views.py @@ -5,13 +5,13 @@ import mimetypes -from edxmako.shortcuts import render_to_response, render_to_string -from mako.exceptions import TopLevelLookupException -from django.shortcuts import redirect from django.conf import settings -from django.http import HttpResponseNotFound, HttpResponseServerError, Http404 +from django.http import Http404, HttpResponseNotFound, HttpResponseServerError +from django.shortcuts import redirect from django.views.decorators.csrf import ensure_csrf_cookie +from mako.exceptions import TopLevelLookupException +from edxmako.shortcuts import render_to_response, render_to_string from util.cache import cache_if_anonymous valid_templates = [] diff --git a/lms/djangoapps/staticbook/tests.py b/lms/djangoapps/staticbook/tests.py index b3b3e2e65a..a5cb1fcb64 100644 --- a/lms/djangoapps/staticbook/tests.py +++ b/lms/djangoapps/staticbook/tests.py @@ -6,13 +6,11 @@ import textwrap import mock import requests +from django.core.urlresolvers import NoReverseMatch, reverse -from django.core.urlresolvers import reverse, NoReverseMatch - -from student.tests.factories import UserFactory, CourseEnrollmentFactory -from xmodule.modulestore.tests.factories import CourseFactory +from student.tests.factories import CourseEnrollmentFactory, UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase - +from xmodule.modulestore.tests.factories import CourseFactory IMAGE_BOOK = ("An Image Textbook", "http://example.com/the_book/") diff --git a/lms/djangoapps/staticbook/views.py b/lms/djangoapps/staticbook/views.py index 7e904b582c..78f9bec0bc 100644 --- a/lms/djangoapps/staticbook/views.py +++ b/lms/djangoapps/staticbook/views.py @@ -4,15 +4,14 @@ Views for serving static textbooks. from django.contrib.auth.decorators import login_required from django.http import Http404 -from edxmako.shortcuts import render_to_response - from opaque_keys.edx.locations import SlashSeparatedCourseKey -from xmodule.annotator_token import retrieve_token from courseware.access import has_access from courseware.courses import get_course_with_access +from edxmako.shortcuts import render_to_response from notes.utils import notes_enabled_for_course from static_replace import replace_static_urls +from xmodule.annotator_token import retrieve_token @login_required diff --git a/lms/djangoapps/student_account/test/test_views.py b/lms/djangoapps/student_account/test/test_views.py index 49c367f3e5..10b5baa40d 100644 --- a/lms/djangoapps/student_account/test/test_views.py +++ b/lms/djangoapps/student_account/test/test_views.py @@ -6,29 +6,25 @@ import re from unittest import skipUnless from urllib import urlencode -import mock import ddt +import mock from django.conf import settings -from django.core import mail -from django.core.files.uploadedfile import SimpleUploadedFile -from django.core.urlresolvers import reverse from django.contrib import messages from django.contrib.auth import get_user_model from django.contrib.messages.middleware import MessageMiddleware +from django.core import mail +from django.core.files.uploadedfile import SimpleUploadedFile +from django.core.urlresolvers import reverse +from django.http import HttpRequest from django.test import TestCase from django.test.utils import override_settings -from django.http import HttpRequest -from edx_oauth2_provider.tests.factories import ClientFactory, AccessTokenFactory, RefreshTokenFactory +from edx_oauth2_provider.tests.factories import AccessTokenFactory, ClientFactory, RefreshTokenFactory from edx_rest_api_client import exceptions from nose.plugins.attrib import attr -from oauth2_provider.models import ( - AccessToken as dot_access_token, - RefreshToken as dot_refresh_token -) -from provider.oauth2.models import ( - AccessToken as dop_access_token, - RefreshToken as dop_refresh_token -) +from oauth2_provider.models import AccessToken as dot_access_token +from oauth2_provider.models import RefreshToken as dot_refresh_token +from provider.oauth2.models import AccessToken as dop_access_token +from provider.oauth2.models import RefreshToken as dop_refresh_token from testfixtures import LogCapture from commerce.models import CommerceConfiguration @@ -38,18 +34,17 @@ from course_modes.models import CourseMode from edxmako.shortcuts import render_to_response from openedx.core.djangoapps.oauth_dispatch.tests import factories as dot_factories from openedx.core.djangoapps.programs.tests.mixins import ProgramsApiConfigMixin -from openedx.core.djangoapps.user_api.accounts.api import activate_account, create_account -from openedx.core.djangoapps.user_api.accounts import EMAIL_MAX_LENGTH -from openedx.core.djangolib.js_utils import dump_js_escaped_json from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin +from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme_context +from openedx.core.djangoapps.user_api.accounts import EMAIL_MAX_LENGTH +from openedx.core.djangoapps.user_api.accounts.api import activate_account, create_account +from openedx.core.djangolib.js_utils import dump_js_escaped_json from openedx.core.djangolib.testing.utils import CacheIsolationTestCase from student.tests.factories import UserFactory from student_account.views import account_settings_context, get_user_orders -from third_party_auth.tests.testutil import simulate_running_pipeline, ThirdPartyAuthTestMixin +from third_party_auth.tests.testutil import ThirdPartyAuthTestMixin, simulate_running_pipeline from util.testing import UrlResetMixin from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme_context - LOGGER_NAME = 'audit' User = get_user_model() # pylint:disable=invalid-name diff --git a/lms/djangoapps/student_account/urls.py b/lms/djangoapps/student_account/urls.py index 9a7357d306..8d8657fbbb 100644 --- a/lms/djangoapps/student_account/urls.py +++ b/lms/djangoapps/student_account/urls.py @@ -1,5 +1,5 @@ -from django.conf.urls import patterns, url from django.conf import settings +from django.conf.urls import patterns, url urlpatterns = [] diff --git a/lms/djangoapps/student_account/views.py b/lms/djangoapps/student_account/views.py index 56223d7bd0..0a6da26076 100644 --- a/lms/djangoapps/student_account/views.py +++ b/lms/djangoapps/student_account/views.py @@ -1,49 +1,43 @@ """ Views for a student's account information. """ -import logging import json +import logging import urlparse from datetime import datetime +import pytz from django.conf import settings from django.contrib import messages -from django.contrib.auth.decorators import login_required from django.contrib.auth import get_user_model -from django.core.urlresolvers import reverse, resolve -from django.http import ( - HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, HttpRequest -) +from django.contrib.auth.decorators import login_required +from django.core.urlresolvers import resolve, reverse +from django.http import HttpRequest, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden from django.shortcuts import redirect 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 django_countries import countries -from edxmako.shortcuts import render_to_response, render_to_string -import pytz +import third_party_auth from commerce.models import CommerceConfiguration +from edxmako.shortcuts import render_to_response, render_to_string from lms.djangoapps.commerce.utils import EcommerceService -from openedx.core.djangoapps.external_auth.login_and_register import ( - login as external_auth_login, - register as external_auth_register -) from openedx.core.djangoapps.commerce.utils import ecommerce_api_client -from openedx.core.djangoapps.lang_pref.api import released_languages, all_languages +from openedx.core.djangoapps.external_auth.login_and_register import login as external_auth_login +from openedx.core.djangoapps.external_auth.login_and_register import register as external_auth_register +from openedx.core.djangoapps.lang_pref.api import all_languages, released_languages from openedx.core.djangoapps.programs.models import ProgramsApiConfig from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.theming.helpers import is_request_in_themed_site from openedx.core.djangoapps.user_api.accounts.api import request_password_change from openedx.core.djangoapps.user_api.errors import UserNotFound -from openedx.features.enterprise_support.api import enterprise_customer_for_request -from openedx.core.lib.time_zone_utils import TIME_ZONE_CHOICES from openedx.core.lib.edx_api_utils import get_edx_api_data +from openedx.core.lib.time_zone_utils import TIME_ZONE_CHOICES +from openedx.features.enterprise_support.api import enterprise_customer_for_request +from student.helpers import destroy_oauth_tokens, get_next_url_for_login_page from student.models import UserProfile -from student.views import ( - signin_user as old_login_view, - register_user as old_register_view -) -from student.helpers import get_next_url_for_login_page, destroy_oauth_tokens -import third_party_auth +from student.views import register_user as old_register_view +from student.views import signin_user as old_login_view from third_party_auth import pipeline from third_party_auth.decorators import xframe_allow_whitelisted from util.bad_request_rate_limiter import BadRequestRateLimiter diff --git a/lms/djangoapps/student_profile/test/test_views.py b/lms/djangoapps/student_profile/test/test_views.py index 5299b51308..25fd93513c 100644 --- a/lms/djangoapps/student_profile/test/test_views.py +++ b/lms/djangoapps/student_profile/test/test_views.py @@ -6,10 +6,9 @@ from django.core.urlresolvers import reverse from django.test import TestCase from django.test.client import RequestFactory -from util.testing import UrlResetMixin from student.tests.factories import UserFactory - from student_profile.views import learner_profile_context +from util.testing import UrlResetMixin class LearnerProfileViewTest(UrlResetMixin, TestCase): diff --git a/lms/djangoapps/student_profile/views.py b/lms/djangoapps/student_profile/views.py index 795a50ef06..51427b54cc 100644 --- a/lms/djangoapps/student_profile/views.py +++ b/lms/djangoapps/student_profile/views.py @@ -2,20 +2,20 @@ from django.conf import settings from django.contrib.auth.decorators import login_required +from django.contrib.staticfiles.storage import staticfiles_storage from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse from django.http import Http404 from django.views.decorators.http import require_http_methods from django_countries import countries -from django.contrib.staticfiles.storage import staticfiles_storage from badges.utils import badges_enabled -from edxmako.shortcuts import render_to_response, marketing_link +from edxmako.shortcuts import marketing_link, render_to_response +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.user_api.accounts.api import get_account_settings -from openedx.core.djangoapps.user_api.errors import UserNotFound, UserNotAuthorized +from openedx.core.djangoapps.user_api.errors import UserNotAuthorized, UserNotFound from openedx.core.djangoapps.user_api.preferences.api import get_user_preferences from student.models import User -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers @login_required diff --git a/lms/djangoapps/support/decorators.py b/lms/djangoapps/support/decorators.py index 090fb882b4..b7d0fc2968 100644 --- a/lms/djangoapps/support/decorators.py +++ b/lms/djangoapps/support/decorators.py @@ -3,8 +3,8 @@ Decorators used by the support app. """ from functools import wraps -from django.http import HttpResponseForbidden from django.contrib.auth.decorators import login_required +from django.http import HttpResponseForbidden from courseware.access import has_access diff --git a/lms/djangoapps/support/tests/test_refund.py b/lms/djangoapps/support/tests/test_refund.py index 3023d8cc9c..6008ed1170 100644 --- a/lms/djangoapps/support/tests/test_refund.py +++ b/lms/djangoapps/support/tests/test_refund.py @@ -8,18 +8,18 @@ to the E-Commerce service is complete. """ import datetime -import pytz -from mock import patch +import pytz from django.test.client import Client +from mock import patch from course_modes.models import CourseMode from shoppingcart.models import CertificateItem, Order from student.models import CourseEnrollment from student.roles import SupportStaffRole from student.tests.factories import UserFactory -from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class RefundTests(ModuleStoreTestCase): diff --git a/lms/djangoapps/support/tests/test_views.py b/lms/djangoapps/support/tests/test_views.py index d30c69363e..93d7f966e8 100644 --- a/lms/djangoapps/support/tests/test_views.py +++ b/lms/djangoapps/support/tests/test_views.py @@ -3,10 +3,10 @@ Tests for support views. """ -from datetime import datetime, timedelta import itertools import json import re +from datetime import datetime, timedelta import ddt from django.core.urlresolvers import reverse @@ -16,9 +16,9 @@ from pytz import UTC from course_modes.models import CourseMode from course_modes.tests.factories import CourseModeFactory from lms.djangoapps.verify_student.models import VerificationDeadline -from student.models import CourseEnrollment, ManualEnrollmentAudit, ENROLLED_TO_ENROLLED +from student.models import ENROLLED_TO_ENROLLED, CourseEnrollment, ManualEnrollmentAudit from student.roles import GlobalStaff, SupportStaffRole -from student.tests.factories import UserFactory, CourseEnrollmentFactory +from student.tests.factories import CourseEnrollmentFactory, UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/lms/djangoapps/support/views/certificate.py b/lms/djangoapps/support/views/certificate.py index b6f1a7e06d..246f528974 100644 --- a/lms/djangoapps/support/views/certificate.py +++ b/lms/djangoapps/support/views/certificate.py @@ -1,12 +1,13 @@ """ Certificate tool in the student support app. """ -from django.views.generic import View +import urllib + from django.utils.decorators import method_decorator +from django.views.generic import View from edxmako.shortcuts import render_to_response from support.decorators import require_support_permission -import urllib class CertificatesSupportView(View): diff --git a/lms/djangoapps/support/views/enrollments.py b/lms/djangoapps/support/views/enrollments.py index 1a2ef8dd32..5bed96e696 100644 --- a/lms/djangoapps/support/views/enrollments.py +++ b/lms/djangoapps/support/views/enrollments.py @@ -8,9 +8,9 @@ from django.db.models import Q from django.http import HttpResponseBadRequest from django.utils.decorators import method_decorator from django.views.generic import View -from rest_framework.generics import GenericAPIView from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey +from rest_framework.generics import GenericAPIView from course_modes.models import CourseMode from edxmako.shortcuts import render_to_response @@ -20,7 +20,7 @@ from enrollment.serializers import ModeSerializer from lms.djangoapps.support.decorators import require_support_permission from lms.djangoapps.support.serializers import ManualEnrollmentSerializer from lms.djangoapps.verify_student.models import VerificationDeadline -from student.models import CourseEnrollment, ManualEnrollmentAudit, ENROLLED_TO_ENROLLED +from student.models import ENROLLED_TO_ENROLLED, CourseEnrollment, ManualEnrollmentAudit from util.json_request import JsonResponse diff --git a/lms/djangoapps/support/views/index.py b/lms/djangoapps/support/views/index.py index df712f23ae..5085554d25 100644 --- a/lms/djangoapps/support/views/index.py +++ b/lms/djangoapps/support/views/index.py @@ -7,7 +7,6 @@ from django.utils.translation import ugettext_lazy as _ from edxmako.shortcuts import render_to_response from support.decorators import require_support_permission - SUPPORT_INDEX_URLS = [ { "url": reverse_lazy("support:certificates"), diff --git a/lms/djangoapps/support/views/refund.py b/lms/djangoapps/support/views/refund.py index bf922cb3ba..bc4104688b 100644 --- a/lms/djangoapps/support/views/refund.py +++ b/lms/djangoapps/support/views/refund.py @@ -12,18 +12,18 @@ transition is complete, we can remove this view. """ import logging -from django.contrib.auth.models import User -from django.views.generic.edit import FormView -from django.utils.translation import ugettext as _ -from django.http import HttpResponseRedirect -from django.contrib import messages from django import forms +from django.contrib import messages +from django.contrib.auth.models import User +from django.http import HttpResponseRedirect from django.utils.decorators import method_decorator +from django.utils.translation import ugettext as _ +from django.views.generic.edit import FormView +from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey +from opaque_keys.edx.locations import SlashSeparatedCourseKey from student.models import CourseEnrollment -from opaque_keys.edx.keys import CourseKey -from opaque_keys import InvalidKeyError -from opaque_keys.edx.locations import SlashSeparatedCourseKey from support.decorators import require_support_permission log = logging.getLogger(__name__) diff --git a/lms/djangoapps/survey/admin.py b/lms/djangoapps/survey/admin.py index b853a8445a..8c1e7368de 100644 --- a/lms/djangoapps/survey/admin.py +++ b/lms/djangoapps/survey/admin.py @@ -4,6 +4,7 @@ Provide accessors to these models via the Django Admin pages from django import forms from django.contrib import admin + from survey.models import SurveyForm diff --git a/lms/djangoapps/survey/models.py b/lms/djangoapps/survey/models.py index bf4dd451b4..ecc2342b0f 100644 --- a/lms/djangoapps/survey/models.py +++ b/lms/djangoapps/survey/models.py @@ -3,17 +3,16 @@ Models to support Course Surveys feature """ import logging -from lxml import etree from collections import OrderedDict -from django.db import models -from student.models import User -from django.core.exceptions import ValidationError +from django.core.exceptions import ValidationError +from django.db import models +from lxml import etree from model_utils.models import TimeStampedModel -from survey.exceptions import SurveyFormNameAlreadyExists, SurveyFormNotFound - from openedx.core.djangoapps.xmodule_django.models import CourseKeyField +from student.models import User +from survey.exceptions import SurveyFormNameAlreadyExists, SurveyFormNotFound log = logging.getLogger("edx.survey") diff --git a/lms/djangoapps/survey/tests/test_models.py b/lms/djangoapps/survey/tests/test_models.py index 881c087835..1c286e6055 100644 --- a/lms/djangoapps/survey/tests/test_models.py +++ b/lms/djangoapps/survey/tests/test_models.py @@ -2,16 +2,16 @@ Python tests for the Survey models """ -import ddt from collections import OrderedDict +import ddt +from django.contrib.auth.models import User +from django.core.exceptions import ValidationError from django.test import TestCase from django.test.client import Client -from django.contrib.auth.models import User -from survey.exceptions import SurveyFormNotFound, SurveyFormNameAlreadyExists -from django.core.exceptions import ValidationError -from survey.models import SurveyForm, SurveyAnswer +from survey.exceptions import SurveyFormNameAlreadyExists, SurveyFormNotFound +from survey.models import SurveyAnswer, SurveyForm @ddt.ddt diff --git a/lms/djangoapps/survey/tests/test_utils.py b/lms/djangoapps/survey/tests/test_utils.py index 00c1d3ea41..01da86079d 100644 --- a/lms/djangoapps/survey/tests/test_utils.py +++ b/lms/djangoapps/survey/tests/test_utils.py @@ -4,15 +4,13 @@ Python tests for the Survey models from collections import OrderedDict -from django.test.client import Client from django.contrib.auth.models import User +from django.test.client import Client from survey.models import SurveyForm - -from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase - from survey.utils import is_survey_required_for_course, must_answer_survey +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class SurveyModelsTests(ModuleStoreTestCase): diff --git a/lms/djangoapps/survey/tests/test_views.py b/lms/djangoapps/survey/tests/test_views.py index db52d06a3a..b324f29983 100644 --- a/lms/djangoapps/survey/tests/test_views.py +++ b/lms/djangoapps/survey/tests/test_views.py @@ -5,14 +5,13 @@ Python tests for the Survey views import json from collections import OrderedDict -from django.test.client import Client from django.core.urlresolvers import reverse - -from survey.models import SurveyForm, SurveyAnswer +from django.test.client import Client from student.tests.factories import UserFactory -from xmodule.modulestore.tests.factories import CourseFactory +from survey.models import SurveyAnswer, SurveyForm from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class SurveyViewsTests(ModuleStoreTestCase): diff --git a/lms/djangoapps/survey/urls.py b/lms/djangoapps/survey/urls.py index ad986159e4..c73e4eae7c 100644 --- a/lms/djangoapps/survey/urls.py +++ b/lms/djangoapps/survey/urls.py @@ -4,7 +4,6 @@ URL mappings for the Survey feature from django.conf.urls import patterns, url - urlpatterns = patterns( 'survey.views', diff --git a/lms/djangoapps/survey/utils.py b/lms/djangoapps/survey/utils.py index 39c03e58f9..1af29f2d40 100644 --- a/lms/djangoapps/survey/utils.py +++ b/lms/djangoapps/survey/utils.py @@ -2,8 +2,8 @@ Helper methods for Surveys """ -from survey.models import SurveyForm, SurveyAnswer from courseware.access import has_access +from survey.models import SurveyAnswer, SurveyForm def is_survey_required_for_course(course_descriptor): diff --git a/lms/djangoapps/survey/views.py b/lms/djangoapps/survey/views.py index 725bea8059..db54ddf891 100644 --- a/lms/djangoapps/survey/views.py +++ b/lms/djangoapps/survey/views.py @@ -2,23 +2,20 @@ View endpoints for Survey """ -import logging import json +import logging -from django.contrib.auth.decorators import login_required -from django.http import ( - HttpResponse, HttpResponseRedirect, HttpResponseNotFound -) -from django.core.urlresolvers import reverse -from django.views.decorators.http import require_POST from django.conf import settings +from django.contrib.auth.decorators import login_required +from django.core.urlresolvers import reverse +from django.http import HttpResponse, HttpResponseNotFound, HttpResponseRedirect from django.utils.html import escape - +from django.views.decorators.http import require_POST from opaque_keys.edx.keys import CourseKey from edxmako.shortcuts import render_to_response -from survey.models import SurveyForm from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from survey.models import SurveyForm log = logging.getLogger("edx.survey") diff --git a/lms/djangoapps/teams/api_urls.py b/lms/djangoapps/teams/api_urls.py index 0d71c78567..708057ed63 100644 --- a/lms/djangoapps/teams/api_urls.py +++ b/lms/djangoapps/teams/api_urls.py @@ -4,12 +4,12 @@ from django.conf import settings from django.conf.urls import patterns, url from .views import ( - TeamsListView, - TeamsDetailView, - TopicDetailView, - TopicListView, + MembershipDetailView, MembershipListView, - MembershipDetailView + TeamsDetailView, + TeamsListView, + TopicDetailView, + TopicListView ) TEAM_ID_PATTERN = r'(?P[a-z\d_-]+)' diff --git a/lms/djangoapps/teams/management/commands/reindex_course_team.py b/lms/djangoapps/teams/management/commands/reindex_course_team.py index 8061ee466f..cb5647e7e2 100644 --- a/lms/djangoapps/teams/management/commands/reindex_course_team.py +++ b/lms/djangoapps/teams/management/commands/reindex_course_team.py @@ -1,10 +1,11 @@ """ Management command to update course_teams' search index. """ -from django.core.management import BaseCommand, CommandError -from django.core.exceptions import ObjectDoesNotExist -from django.conf import settings from optparse import make_option from textwrap import dedent +from django.conf import settings +from django.core.exceptions import ObjectDoesNotExist +from django.core.management import BaseCommand, CommandError + from lms.djangoapps.teams.models import CourseTeam diff --git a/lms/djangoapps/teams/management/commands/tests/test_reindex_course_team.py b/lms/djangoapps/teams/management/commands/tests/test_reindex_course_team.py index 62e28a886c..f04a731c10 100644 --- a/lms/djangoapps/teams/management/commands/tests/test_reindex_course_team.py +++ b/lms/djangoapps/teams/management/commands/tests/test_reindex_course_team.py @@ -1,15 +1,16 @@ """ Tests for course_team reindex command """ import ddt - +from django.core.management import CommandError, call_command from mock import patch -from django.core.management import call_command, CommandError -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from opaque_keys.edx.keys import CourseKey -from ....tests.factories import CourseTeamFactory -from ....search_indexes import CourseTeamIndexer from search.search_engine_base import SearchEngine +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase + +from ....search_indexes import CourseTeamIndexer +from ....tests.factories import CourseTeamFactory + COURSE_KEY1 = CourseKey.from_string('edx/history/1') diff --git a/lms/djangoapps/teams/models.py b/lms/djangoapps/teams/models.py index 21967f2127..154f424acd 100644 --- a/lms/djangoapps/teams/models.py +++ b/lms/djangoapps/teams/models.py @@ -2,33 +2,34 @@ from datetime import datetime from uuid import uuid4 -import pytz -from model_utils import FieldTracker -from django.core.exceptions import ObjectDoesNotExist +import pytz from django.contrib.auth.models import User +from django.core.exceptions import ObjectDoesNotExist from django.db import models from django.dispatch import receiver from django.utils.translation import ugettext_lazy from django_countries.fields import CountryField +from model_utils import FieldTracker from django_comment_common.signals import ( - thread_created, - thread_edited, - thread_deleted, - thread_voted, comment_created, - comment_edited, comment_deleted, + comment_edited, + comment_endorsed, comment_voted, - comment_endorsed + thread_created, + thread_deleted, + thread_edited, + thread_voted ) -from openedx.core.djangoapps.xmodule_django.models import CourseKeyField -from util.model_utils import slugify -from student.models import LanguageField, CourseEnrollment -from .errors import AlreadyOnTeamInCourse, NotEnrolledInCourseForTeam, ImmutableMembershipFieldException -from lms.djangoapps.teams.utils import emit_team_event from lms.djangoapps.teams import TEAM_DISCUSSION_CONTEXT +from lms.djangoapps.teams.utils import emit_team_event +from openedx.core.djangoapps.xmodule_django.models import CourseKeyField +from student.models import CourseEnrollment, LanguageField +from util.model_utils import slugify + +from .errors import AlreadyOnTeamInCourse, ImmutableMembershipFieldException, NotEnrolledInCourseForTeam @receiver(thread_voted) diff --git a/lms/djangoapps/teams/plugins.py b/lms/djangoapps/teams/plugins.py index 9a167da5ce..e0cc852277 100644 --- a/lms/djangoapps/teams/plugins.py +++ b/lms/djangoapps/teams/plugins.py @@ -2,7 +2,9 @@ Definition of the course team feature. """ from django.utils.translation import ugettext_noop + from courseware.tabs import EnrolledTab + from . import is_feature_enabled diff --git a/lms/djangoapps/teams/search_indexes.py b/lms/djangoapps/teams/search_indexes.py index 9fcba08d0e..69ea9d1121 100644 --- a/lms/djangoapps/teams/search_indexes.py +++ b/lms/djangoapps/teams/search_indexes.py @@ -1,19 +1,19 @@ """ Search index used to load data into elasticsearch""" import logging -from elasticsearch.exceptions import ConnectionError +from functools import wraps from django.conf import settings from django.db.models.signals import post_delete, post_save from django.dispatch import receiver from django.utils import translation -from functools import wraps - +from elasticsearch.exceptions import ConnectionError from search.search_engine_base import SearchEngine + +from lms.djangoapps.teams.models import CourseTeam from request_cache import get_request_or_stub from .errors import ElasticSearchConnectionError -from lms.djangoapps.teams.models import CourseTeam from .serializers import CourseTeamSerializer diff --git a/lms/djangoapps/teams/serializers.py b/lms/djangoapps/teams/serializers.py index 8444765640..d63591a75f 100644 --- a/lms/djangoapps/teams/serializers.py +++ b/lms/djangoapps/teams/serializers.py @@ -1,17 +1,16 @@ """Defines serializers used by the Team API.""" from copy import deepcopy + +from django.conf import settings from django.contrib.auth.models import User from django.db.models import Count -from django.conf import settings - from django_countries import countries from rest_framework import serializers -from openedx.core.lib.api.serializers import CollapsedReferenceSerializer -from openedx.core.lib.api.fields import ExpandableField -from openedx.core.djangoapps.user_api.accounts.serializers import UserReadOnlySerializer - from lms.djangoapps.teams.models import CourseTeam, CourseTeamMembership +from openedx.core.djangoapps.user_api.accounts.serializers import UserReadOnlySerializer +from openedx.core.lib.api.fields import ExpandableField +from openedx.core.lib.api.serializers import CollapsedReferenceSerializer class CountryField(serializers.Field): diff --git a/lms/djangoapps/teams/tests/factories.py b/lms/djangoapps/teams/tests/factories.py index 25375a76cb..a4991df4c2 100644 --- a/lms/djangoapps/teams/tests/factories.py +++ b/lms/djangoapps/teams/tests/factories.py @@ -1,15 +1,14 @@ """Factories for testing the Teams API.""" -import pytz from datetime import datetime from uuid import uuid4 import factory +import pytz from factory.django import DjangoModelFactory from lms.djangoapps.teams.models import CourseTeam, CourseTeamMembership - LAST_ACTIVITY_AT = datetime(2015, 8, 15, 0, 0, 0, tzinfo=pytz.utc) diff --git a/lms/djangoapps/teams/tests/test_models.py b/lms/djangoapps/teams/tests/test_models.py index ea820329c2..7bcd29d144 100644 --- a/lms/djangoapps/teams/tests/test_models.py +++ b/lms/djangoapps/teams/tests/test_models.py @@ -1,33 +1,32 @@ # -*- coding: utf-8 -*- # pylint: disable=no-member """Tests for the teams API at the HTTP request level.""" +import itertools from contextlib import contextmanager from datetime import datetime + import ddt -import itertools -from mock import Mock import pytz +from mock import Mock +from opaque_keys.edx.keys import CourseKey from django_comment_common.signals import ( - thread_created, - thread_edited, - thread_deleted, - thread_voted, comment_created, - comment_edited, comment_deleted, + comment_edited, + comment_endorsed, comment_voted, - comment_endorsed + thread_created, + thread_deleted, + thread_edited, + thread_voted ) -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from opaque_keys.edx.keys import CourseKey -from student.tests.factories import CourseEnrollmentFactory, UserFactory - -from lms.djangoapps.teams.tests.factories import CourseTeamFactory, CourseTeamMembershipFactory -from lms.djangoapps.teams.models import CourseTeam, CourseTeamMembership from lms.djangoapps.teams import TEAM_DISCUSSION_CONTEXT +from lms.djangoapps.teams.models import CourseTeam, CourseTeamMembership +from lms.djangoapps.teams.tests.factories import CourseTeamFactory, CourseTeamMembershipFactory +from student.tests.factories import CourseEnrollmentFactory, UserFactory from util.testing import EventTestMixin - +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase COURSE_KEY1 = CourseKey.from_string('edx/history/1') COURSE_KEY2 = CourseKey.from_string('edx/history/2') diff --git a/lms/djangoapps/teams/tests/test_serializers.py b/lms/djangoapps/teams/tests/test_serializers.py index 189b8fa349..b5a243fc47 100644 --- a/lms/djangoapps/teams/tests/test_serializers.py +++ b/lms/djangoapps/teams/tests/test_serializers.py @@ -5,17 +5,12 @@ Tests for custom Teams Serializers. from django.core.paginator import Paginator from django.test.client import RequestFactory +from lms.djangoapps.teams.serializers import BulkTeamCountTopicSerializer, MembershipSerializer, TopicSerializer +from lms.djangoapps.teams.tests.factories import CourseTeamFactory, CourseTeamMembershipFactory from student.tests.factories import CourseEnrollmentFactory, UserFactory from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from lms.djangoapps.teams.tests.factories import CourseTeamFactory, CourseTeamMembershipFactory -from lms.djangoapps.teams.serializers import ( - BulkTeamCountTopicSerializer, - TopicSerializer, - MembershipSerializer, -) - class SerializerTestCase(SharedModuleStoreTestCase): """ diff --git a/lms/djangoapps/teams/tests/test_views.py b/lms/djangoapps/teams/tests/test_views.py index 1492722197..0bd970565b 100644 --- a/lms/djangoapps/teams/tests/test_views.py +++ b/lms/djangoapps/teams/tests/test_views.py @@ -1,34 +1,35 @@ # -*- coding: utf-8 -*- """Tests for the teams API at the HTTP request level.""" import json +import unittest from datetime import datetime +import ddt import pytz from dateutil import parser -import ddt -from elasticsearch.exceptions import ConnectionError -from mock import patch -from search.search_engine_base import SearchEngine -from django.core.urlresolvers import reverse from django.conf import settings +from django.core.urlresolvers import reverse from django.db.models.signals import post_save from django.utils import translation +from elasticsearch.exceptions import ConnectionError +from mock import patch from nose.plugins.attrib import attr -import unittest -from rest_framework.test import APITestCase, APIClient +from rest_framework.test import APIClient, APITestCase +from search.search_engine_base import SearchEngine + +from common.test.utils import skip_signal +from courseware.tests.factories import StaffFactory +from django_comment_common.models import FORUM_ROLE_COMMUNITY_TA, Role +from django_comment_common.utils import seed_permissions_roles +from student.models import CourseEnrollment +from student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory +from util.testing import EventTestMixin from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from courseware.tests.factories import StaffFactory -from common.test.utils import skip_signal -from student.tests.factories import UserFactory, AdminFactory, CourseEnrollmentFactory -from student.models import CourseEnrollment -from util.testing import EventTestMixin -from .factories import CourseTeamFactory, LAST_ACTIVITY_AT from ..models import CourseTeamMembership -from ..search_indexes import CourseTeamIndexer, CourseTeam, course_team_post_save_callback -from django_comment_common.models import Role, FORUM_ROLE_COMMUNITY_TA -from django_comment_common.utils import seed_permissions_roles +from ..search_indexes import CourseTeam, CourseTeamIndexer, course_team_post_save_callback +from .factories import LAST_ACTIVITY_AT, CourseTeamFactory @attr(shard=1) diff --git a/lms/djangoapps/teams/views.py b/lms/djangoapps/teams/views.py index 4ed307c494..03881a6b79 100644 --- a/lms/djangoapps/teams/views.py +++ b/lms/djangoapps/teams/views.py @@ -2,53 +2,53 @@ import logging -from django.shortcuts import get_object_or_404, render_to_response -from django.http import Http404 from django.conf import settings +from django.contrib.auth.models import User +from django.db.models.signals import post_save +from django.dispatch import receiver +from django.http import Http404 +from django.shortcuts import get_object_or_404, render_to_response +from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext_noop +from django_countries import countries +from opaque_keys import InvalidKeyError +from opaque_keys.edx.keys import CourseKey +from rest_framework import permissions, status +from rest_framework.authentication import SessionAuthentication from rest_framework.generics import GenericAPIView from rest_framework.response import Response from rest_framework.reverse import reverse from rest_framework.views import APIView -from rest_framework.authentication import SessionAuthentication from rest_framework_oauth.authentication import OAuth2Authentication -from rest_framework import status -from rest_framework import permissions -from django.db.models.signals import post_save -from django.dispatch import receiver -from django.contrib.auth.models import User -from django_countries import countries -from django.utils.translation import ugettext as _ -from django.utils.translation import ugettext_noop + +from courseware.courses import get_course_with_access, has_access +from django_comment_client.utils import has_discussion_privileges +from lms.djangoapps.teams.models import CourseTeam, CourseTeamMembership +from openedx.core.lib.api.paginators import DefaultPagination, paginate_search_results from openedx.core.lib.api.parsers import MergePatchParser from openedx.core.lib.api.permissions import IsStaffOrReadOnly from openedx.core.lib.api.view_utils import ( + ExpandableFieldViewMixin, RetrievePatchAPIView, add_serializer_errors, - build_api_error, - ExpandableFieldViewMixin + build_api_error ) -from openedx.core.lib.api.paginators import paginate_search_results, DefaultPagination -from xmodule.modulestore.django import modulestore -from opaque_keys import InvalidKeyError -from opaque_keys.edx.keys import CourseKey - -from courseware.courses import get_course_with_access, has_access -from student.models import CourseEnrollment, CourseAccessRole +from student.models import CourseAccessRole, CourseEnrollment from student.roles import CourseStaffRole -from django_comment_client.utils import has_discussion_privileges from util.model_utils import truncate_fields +from xmodule.modulestore.django import modulestore + from . import is_feature_enabled -from lms.djangoapps.teams.models import CourseTeam, CourseTeamMembership +from .errors import AlreadyOnTeamInCourse, ElasticSearchConnectionError, NotEnrolledInCourseForTeam +from .search_indexes import CourseTeamIndexer from .serializers import ( - CourseTeamSerializer, - CourseTeamCreationSerializer, - TopicSerializer, BulkTeamCountTopicSerializer, + CourseTeamCreationSerializer, + CourseTeamSerializer, MembershipSerializer, + TopicSerializer, add_team_count ) -from .search_indexes import CourseTeamIndexer -from .errors import AlreadyOnTeamInCourse, ElasticSearchConnectionError, NotEnrolledInCourseForTeam from .utils import emit_team_event TEAM_MEMBERSHIPS_PER_PAGE = 2 diff --git a/lms/djangoapps/verify_student/image.py b/lms/djangoapps/verify_student/image.py index a440e5b673..a733da6ca6 100644 --- a/lms/djangoapps/verify_student/image.py +++ b/lms/djangoapps/verify_student/image.py @@ -3,7 +3,6 @@ Image encoding helpers for the verification app. """ import logging - log = logging.getLogger(__name__) diff --git a/lms/djangoapps/verify_student/management/commands/retry_failed_photo_verifications.py b/lms/djangoapps/verify_student/management/commands/retry_failed_photo_verifications.py index 2efdeadbde..c28c4e327d 100644 --- a/lms/djangoapps/verify_student/management/commands/retry_failed_photo_verifications.py +++ b/lms/djangoapps/verify_student/management/commands/retry_failed_photo_verifications.py @@ -2,9 +2,10 @@ Django admin commands related to verify_student """ -from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification from django.core.management.base import BaseCommand +from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification + class Command(BaseCommand): """ diff --git a/lms/djangoapps/verify_student/management/commands/set_software_secure_status.py b/lms/djangoapps/verify_student/management/commands/set_software_secure_status.py index 0be17a842d..0e56c0d102 100644 --- a/lms/djangoapps/verify_student/management/commands/set_software_secure_status.py +++ b/lms/djangoapps/verify_student/management/commands/set_software_secure_status.py @@ -5,8 +5,11 @@ Manually set Software Secure verification status. import sys from django.core.management.base import BaseCommand + from lms.djangoapps.verify_student.models import ( - SoftwareSecurePhotoVerification, VerificationCheckpoint, VerificationStatus + SoftwareSecurePhotoVerification, + VerificationCheckpoint, + VerificationStatus ) diff --git a/lms/djangoapps/verify_student/management/commands/tests/test_verify_student.py b/lms/djangoapps/verify_student/management/commands/tests/test_verify_student.py index 04682ec699..87d8aa45ec 100644 --- a/lms/djangoapps/verify_student/management/commands/tests/test_verify_student.py +++ b/lms/djangoapps/verify_student/management/commands/tests/test_verify_student.py @@ -4,19 +4,20 @@ Tests for django admin commands in the verify_student module Lots of imports from verify_student's model tests, since they cover similar ground """ import boto -from nose.tools import assert_equals -from mock import patch - -from django.test import TestCase from django.conf import settings +from django.core.management import call_command +from django.test import TestCase +from mock import patch +from nose.tools import assert_equals from common.test.utils import MockS3Mixin -from student.tests.factories import UserFactory from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification -from django.core.management import call_command from lms.djangoapps.verify_student.tests.test_models import ( - mock_software_secure_post, mock_software_secure_post_error, FAKE_SETTINGS, + FAKE_SETTINGS, + mock_software_secure_post, + mock_software_secure_post_error ) +from student.tests.factories import UserFactory # Lots of patching to stub in our own settings, and HTTP posting diff --git a/lms/djangoapps/verify_student/models.py b/lms/djangoapps/verify_student/models.py index 3d46b47c5d..57557d6d46 100644 --- a/lms/djangoapps/verify_student/models.py +++ b/lms/djangoapps/verify_student/models.py @@ -12,36 +12,38 @@ import functools import json import logging import os.path +import uuid from datetime import datetime, timedelta from email.utils import formatdate import pytz import requests -import uuid - +from config_models.models import ConfigurationModel from django.conf import settings from django.contrib.auth.models import User -from django.core.urlresolvers import reverse from django.core.cache import cache from django.core.files.base import ContentFile -from django.dispatch import receiver +from django.core.urlresolvers import reverse from django.db import models +from django.dispatch import receiver from django.utils.functional import cached_property -from django.utils.translation import ugettext as _, ugettext_lazy - -from openedx.core.storage import get_storage -from simple_history.models import HistoricalRecords -from config_models.models import ConfigurationModel -from course_modes.models import CourseMode -from model_utils.models import StatusModel, TimeStampedModel +from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext_lazy from model_utils import Choices +from model_utils.models import StatusModel, TimeStampedModel +from simple_history.models import HistoricalRecords + +from course_modes.models import CourseMode from lms.djangoapps.verify_student.ssencrypt import ( - random_aes_key, encrypt_and_encode, - generate_signed_message, rsa_encrypt + encrypt_and_encode, + generate_signed_message, + random_aes_key, + rsa_encrypt ) -from openedx.core.djangoapps.xmodule_django.models import CourseKeyField from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.djangoapps.xmodule_django.models import CourseKeyField from openedx.core.djangolib.model_mixins import DeprecatedModelMixin +from openedx.core.storage import get_storage log = logging.getLogger(__name__) diff --git a/lms/djangoapps/verify_student/services.py b/lms/djangoapps/verify_student/services.py index 680ab4f8a4..33be53050c 100644 --- a/lms/djangoapps/verify_student/services.py +++ b/lms/djangoapps/verify_student/services.py @@ -7,10 +7,9 @@ import logging from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse from django.db import IntegrityError - from opaque_keys.edx.keys import CourseKey -from student.models import User, CourseEnrollment +from student.models import CourseEnrollment, User from .models import SoftwareSecurePhotoVerification diff --git a/lms/djangoapps/verify_student/signals.py b/lms/djangoapps/verify_student/signals.py index 474ff2a3e5..b332a184f6 100644 --- a/lms/djangoapps/verify_student/signals.py +++ b/lms/djangoapps/verify_student/signals.py @@ -3,6 +3,7 @@ Signal handler for setting default course verification dates """ from django.core.exceptions import ObjectDoesNotExist from django.dispatch.dispatcher import receiver + from xmodule.modulestore.django import SignalHandler, modulestore from .models import VerificationDeadline diff --git a/lms/djangoapps/verify_student/ssencrypt.py b/lms/djangoapps/verify_student/ssencrypt.py index a83b6f644f..ceb301e27b 100644 --- a/lms/djangoapps/verify_student/ssencrypt.py +++ b/lms/djangoapps/verify_student/ssencrypt.py @@ -22,11 +22,11 @@ In case of PEM encoding, the private key can be encrypted with DES or 3TDES according to a certain pass phrase. Only OpenSSL-compatible pass phrases are supported. """ -from hashlib import md5, sha256 import base64 import binascii import hmac import logging +from hashlib import md5, sha256 from Crypto import Random from Crypto.Cipher import AES, PKCS1_OAEP diff --git a/lms/djangoapps/verify_student/tests/factories.py b/lms/djangoapps/verify_student/tests/factories.py index 9abe2be505..295e632b46 100644 --- a/lms/djangoapps/verify_student/tests/factories.py +++ b/lms/djangoapps/verify_student/tests/factories.py @@ -3,6 +3,7 @@ Factories related to student verification. """ from factory.django import DjangoModelFactory + from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification diff --git a/lms/djangoapps/verify_student/tests/test_fake_software_secure.py b/lms/djangoapps/verify_student/tests/test_fake_software_secure.py index a9c2b4b8dc..fd72054035 100644 --- a/lms/djangoapps/verify_student/tests/test_fake_software_secure.py +++ b/lms/djangoapps/verify_student/tests/test_fake_software_secure.py @@ -3,11 +3,11 @@ Tests for the fake software secure response. """ from django.test import TestCase - from mock import patch + +from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification from student.tests.factories import UserFactory from util.testing import UrlResetMixin -from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification class SoftwareSecureFakeViewTest(UrlResetMixin, TestCase): diff --git a/lms/djangoapps/verify_student/tests/test_integration.py b/lms/djangoapps/verify_student/tests/test_integration.py index c45c9cd350..fa8d278b35 100644 --- a/lms/djangoapps/verify_student/tests/test_integration.py +++ b/lms/djangoapps/verify_student/tests/test_integration.py @@ -4,11 +4,11 @@ Integration tests of the payment flow, including course mode selection. from django.core.urlresolvers import reverse -from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from student.tests.factories import UserFactory -from student.models import CourseEnrollment from course_modes.tests.factories import CourseModeFactory +from student.models import CourseEnrollment +from student.tests.factories import UserFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class TestProfEdVerification(ModuleStoreTestCase): diff --git a/lms/djangoapps/verify_student/tests/test_models.py b/lms/djangoapps/verify_student/tests/test_models.py index b49e31f8f6..35efe8b57c 100644 --- a/lms/djangoapps/verify_student/tests/test_models.py +++ b/lms/djangoapps/verify_student/tests/test_models.py @@ -1,32 +1,36 @@ # -*- coding: utf-8 -*- -from datetime import timedelta, datetime import json +from datetime import datetime, timedelta import boto import ddt -from django.conf import settings -from freezegun import freeze_time import mock -from mock import patch -from nose.tools import assert_is_none, assert_equals, assert_raises, assert_true, assert_false # pylint: disable=no-name-in-module import pytz import requests.exceptions +from django.conf import settings +from freezegun import freeze_time +from mock import patch +from nose.tools import ( # pylint: disable=no-name-in-module + assert_equals, + assert_false, + assert_is_none, + assert_raises, + assert_true +) +from opaque_keys.edx.keys import CourseKey from testfixtures import LogCapture from common.test.utils import MockS3Mixin +from lms.djangoapps.verify_student.models import ( + SoftwareSecurePhotoVerification, + VerificationDeadline, + VerificationException +) +from openedx.core.djangolib.testing.utils import CacheIsolationTestCase from student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from opaque_keys.edx.keys import CourseKey -from openedx.core.djangolib.testing.utils import CacheIsolationTestCase - -from lms.djangoapps.verify_student.models import ( - SoftwareSecurePhotoVerification, - VerificationException, VerificationDeadline -) - - FAKE_SETTINGS = { "SOFTWARE_SECURE": { "FACE_IMAGE_AES_KEY": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", diff --git a/lms/djangoapps/verify_student/tests/test_signals.py b/lms/djangoapps/verify_student/tests/test_signals.py index c7baece697..5b0cdc29e9 100644 --- a/lms/djangoapps/verify_student/tests/test_signals.py +++ b/lms/djangoapps/verify_student/tests/test_signals.py @@ -5,11 +5,11 @@ Unit tests for the VerificationDeadline signals from datetime import datetime, timedelta from pytz import UTC -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from lms.djangoapps.verify_student.models import VerificationDeadline from lms.djangoapps.verify_student.signals import _listen_for_course_publish +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class VerificationDeadlineSignalTest(ModuleStoreTestCase): diff --git a/lms/djangoapps/verify_student/tests/test_ssencrypt.py b/lms/djangoapps/verify_student/tests/test_ssencrypt.py index 7a3b83ba5d..a77923c796 100644 --- a/lms/djangoapps/verify_student/tests/test_ssencrypt.py +++ b/lms/djangoapps/verify_student/tests/test_ssencrypt.py @@ -1,9 +1,14 @@ import base64 + from nose.tools import assert_equals from lms.djangoapps.verify_student.ssencrypt import ( - aes_decrypt, aes_encrypt, encrypt_and_encode, decode_and_decrypt, - rsa_decrypt, rsa_encrypt + aes_decrypt, + aes_encrypt, + decode_and_decrypt, + encrypt_and_encode, + rsa_decrypt, + rsa_encrypt ) diff --git a/lms/djangoapps/verify_student/tests/test_views.py b/lms/djangoapps/verify_student/tests/test_views.py index 03bed48f58..0a2253a11e 100644 --- a/lms/djangoapps/verify_student/tests/test_views.py +++ b/lms/djangoapps/verify_student/tests/test_views.py @@ -5,55 +5,47 @@ Tests of verify_student views. import json import urllib -from datetime import timedelta, datetime +from datetime import datetime, timedelta from uuid import uuid4 +import boto import ddt import httpretty import mock -from nose.plugins.attrib import attr -import boto import moto import pytz -from bs4 import BeautifulSoup -from mock import patch, Mock import requests -from waffle.testutils import override_switch - +from bs4 import BeautifulSoup from django.conf import settings -from django.core.urlresolvers import reverse from django.core import mail +from django.core.urlresolvers import reverse from django.test import TestCase from django.test.client import Client, RequestFactory from django.test.utils import override_settings - +from mock import Mock, patch +from nose.plugins.attrib import attr from opaque_keys.edx.locations import SlashSeparatedCourseKey from opaque_keys.edx.locator import CourseLocator +from waffle.testutils import override_switch +from commerce.models import CommerceConfiguration +from commerce.tests import TEST_API_URL, TEST_PAYMENT_DATA, TEST_PUBLIC_URL_ROOT +from common.test.utils import XssTestMixin from course_modes.models import CourseMode from course_modes.tests.factories import CourseModeFactory -from common.test.utils import XssTestMixin -from commerce.models import CommerceConfiguration -from commerce.tests import TEST_PAYMENT_DATA, TEST_API_URL, TEST_PUBLIC_URL_ROOT +from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification, VerificationDeadline +from lms.djangoapps.verify_student.views import PayAndVerifyView, checkout_with_ecommerce_service, render_to_response from openedx.core.djangoapps.embargo.test_utils import restrict_course -from openedx.core.djangoapps.user_api.accounts.api import get_account_settings from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme -from shoppingcart.models import Order, CertificateItem -from student.tests.factories import UserFactory, CourseEnrollmentFactory +from openedx.core.djangoapps.user_api.accounts.api import get_account_settings +from shoppingcart.models import CertificateItem, Order from student.models import CourseEnrollment +from student.tests.factories import CourseEnrollmentFactory, UserFactory from util.testing import UrlResetMixin +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.django import modulestore -from xmodule.modulestore import ModuleStoreEnum - - -from lms.djangoapps.verify_student.models import ( - VerificationDeadline, SoftwareSecurePhotoVerification, -) -from lms.djangoapps.verify_student.views import ( - checkout_with_ecommerce_service, render_to_response, PayAndVerifyView, -) def mock_render_to_response(*args, **kwargs): diff --git a/lms/djangoapps/verify_student/urls.py b/lms/djangoapps/verify_student/urls.py index bee7f25573..c75e783e07 100644 --- a/lms/djangoapps/verify_student/urls.py +++ b/lms/djangoapps/verify_student/urls.py @@ -5,7 +5,6 @@ from django.conf.urls import patterns, url from lms.djangoapps.verify_student import views - urlpatterns = patterns( '', diff --git a/lms/djangoapps/verify_student/views.py b/lms/djangoapps/verify_student/views.py index 861264d82f..38dafa9268 100644 --- a/lms/djangoapps/verify_student/views.py +++ b/lms/djangoapps/verify_student/views.py @@ -6,53 +6,48 @@ import datetime import decimal import json import logging -from pytz import UTC -from ipware.ip import get_ip +import analytics +import waffle from django.conf import settings from django.contrib.auth.decorators import login_required from django.contrib.staticfiles.storage import staticfiles_storage from django.core.mail import send_mail from django.core.urlresolvers import reverse from django.db import transaction -from django.http import HttpResponse, HttpResponseBadRequest, Http404 +from django.http import Http404, HttpResponse, HttpResponseBadRequest from django.shortcuts import redirect from django.utils.decorators import method_decorator -from django.utils.translation import ugettext as _, ugettext_lazy +from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext_lazy from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST from django.views.generic.base import View - -import analytics -from eventtracking import tracker +from edx_rest_api_client.exceptions import SlumberBaseException +from ipware.ip import get_ip from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey -import waffle +from pytz import UTC from commerce.utils import EcommerceService, is_account_activation_requirement_disabled from course_modes.models import CourseMode -from edx_rest_api_client.exceptions import SlumberBaseException from edxmako.shortcuts import render_to_response, render_to_string -from openedx.core.djangoapps.embargo import api as embargo_api +from eventtracking import tracker +from lms.djangoapps.verify_student.image import InvalidImageData, decode_image_data +from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification, VerificationDeadline +from lms.djangoapps.verify_student.ssencrypt import has_valid_signature from openedx.core.djangoapps.commerce.utils import ecommerce_api_client +from openedx.core.djangoapps.embargo import api as embargo_api +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.user_api.accounts import NAME_MIN_LENGTH from openedx.core.djangoapps.user_api.accounts.api import update_account_settings -from openedx.core.djangoapps.user_api.errors import UserNotFound, AccountValidationError -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.djangoapps.user_api.errors import AccountValidationError, UserNotFound from openedx.core.lib.log_utils import audit_log +from shoppingcart.models import CertificateItem, Order +from shoppingcart.processors import get_purchase_endpoint, get_signed_purchase_params from student.models import CourseEnrollment -from shoppingcart.models import Order, CertificateItem -from shoppingcart.processors import ( - get_signed_purchase_params, get_purchase_endpoint -) -from lms.djangoapps.verify_student.ssencrypt import has_valid_signature -from lms.djangoapps.verify_student.models import ( - VerificationDeadline, - SoftwareSecurePhotoVerification, -) -from lms.djangoapps.verify_student.image import decode_image_data, InvalidImageData -from util.json_request import JsonResponse from util.db import outer_atomic +from util.json_request import JsonResponse from xmodule.modulestore.django import modulestore log = logging.getLogger(__name__) diff --git a/lms/lib/comment_client/comment.py b/lms/lib/comment_client/comment.py index 76f200f9f4..d0b23eadc4 100644 --- a/lms/lib/comment_client/comment.py +++ b/lms/lib/comment_client/comment.py @@ -1,8 +1,7 @@ -from .utils import CommentClientRequestError, perform_request +from lms.lib.comment_client import models, settings from .thread import Thread, _url_for_flag_abuse_thread, _url_for_unflag_abuse_thread -from lms.lib.comment_client import models -from lms.lib.comment_client import settings +from .utils import CommentClientRequestError, perform_request class Comment(models.Model): diff --git a/lms/lib/comment_client/comment_client.py b/lms/lib/comment_client/comment_client.py index 0562c9ada1..bfd7b687f4 100644 --- a/lms/lib/comment_client/comment_client.py +++ b/lms/lib/comment_client/comment_client.py @@ -1,6 +1,6 @@ """Import other classes here so they can be imported from here.""" # pylint: disable=unused-import from .comment import Comment +from .commentable import Commentable from .thread import Thread from .user import User -from .commentable import Commentable diff --git a/lms/lib/comment_client/commentable.py b/lms/lib/comment_client/commentable.py index 93a2c28022..5a5a1f9113 100644 --- a/lms/lib/comment_client/commentable.py +++ b/lms/lib/comment_client/commentable.py @@ -1,6 +1,5 @@ """Provides base Commentable model class""" -from lms.lib.comment_client import models -from lms.lib.comment_client import settings +from lms.lib.comment_client import models, settings class Commentable(models.Model): diff --git a/lms/lib/comment_client/models.py b/lms/lib/comment_client/models.py index ed7f5c292b..cbf5cd257a 100644 --- a/lms/lib/comment_client/models.py +++ b/lms/lib/comment_client/models.py @@ -1,7 +1,6 @@ import logging -from .utils import extract, perform_request, CommentClientRequestError - +from .utils import CommentClientRequestError, extract, perform_request log = logging.getLogger(__name__) diff --git a/lms/lib/comment_client/thread.py b/lms/lib/comment_client/thread.py index b50a3dd2bf..07ab6d3c39 100644 --- a/lms/lib/comment_client/thread.py +++ b/lms/lib/comment_client/thread.py @@ -1,11 +1,20 @@ import logging -from eventtracking import tracker -from .utils import merge_dict, strip_blank, strip_none, extract, perform_request, CommentClientPaginatedResult -from .utils import CommentClientRequestError -import models import settings +import models +from eventtracking import tracker + +from .utils import ( + CommentClientPaginatedResult, + CommentClientRequestError, + extract, + merge_dict, + perform_request, + strip_blank, + strip_none +) + log = logging.getLogger(__name__) diff --git a/lms/lib/comment_client/user.py b/lms/lib/comment_client/user.py index d43f563b57..22106504c2 100644 --- a/lms/lib/comment_client/user.py +++ b/lms/lib/comment_client/user.py @@ -1,8 +1,9 @@ """ User model wrapper for comment service""" -from .utils import merge_dict, perform_request, CommentClientRequestError, CommentClientPaginatedResult +import settings import models -import settings + +from .utils import CommentClientPaginatedResult, CommentClientRequestError, merge_dict, perform_request class User(models.Model): diff --git a/lms/lib/comment_client/utils.py b/lms/lib/comment_client/utils.py index 0531574b40..33793107c6 100644 --- a/lms/lib/comment_client/utils.py +++ b/lms/lib/comment_client/utils.py @@ -1,13 +1,15 @@ """" Common utilities for comment client wrapper """ -from contextlib import contextmanager -import dogstats_wrapper as dog_stats_api import logging -import requests -from django.conf import settings +from contextlib import contextmanager from time import time from uuid import uuid4 + +import requests +from django.conf import settings from django.utils.translation import get_language +import dogstats_wrapper as dog_stats_api + log = logging.getLogger(__name__) diff --git a/lms/lib/courseware_search/lms_filter_generator.py b/lms/lib/courseware_search/lms_filter_generator.py index 1af0713696..c2e33ab18b 100644 --- a/lms/lib/courseware_search/lms_filter_generator.py +++ b/lms/lib/courseware_search/lms_filter_generator.py @@ -3,11 +3,12 @@ This file contains implementation override of SearchFilterGenerator which will a * Filter by all courses in which the user is enrolled in """ -from student.models import CourseEnrollment from search.filter_generator import SearchFilterGenerator -from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme + from openedx.core.djangoapps.course_groups.partition_scheme import CohortPartitionScheme from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme +from student.models import CourseEnrollment INCLUDE_SCHEMES = [CohortPartitionScheme, RandomUserPartitionScheme, ] SCHEME_SUPPORTS_ASSIGNMENT = [RandomUserPartitionScheme, ] diff --git a/lms/lib/courseware_search/lms_result_processor.py b/lms/lib/courseware_search/lms_result_processor.py index 73d6df73da..50ae2ad4a6 100644 --- a/lms/lib/courseware_search/lms_result_processor.py +++ b/lms/lib/courseware_search/lms_result_processor.py @@ -4,12 +4,12 @@ This file contains implementation override of SearchResultProcessor which will a * Confirms user access to object """ from django.core.urlresolvers import reverse - from opaque_keys.edx.locations import SlashSeparatedCourseKey from search.result_processor import SearchResultProcessor -from xmodule.modulestore.django import modulestore + from lms.djangoapps.course_blocks.api import get_course_blocks from lms.djangoapps.courseware.access import has_access +from xmodule.modulestore.django import modulestore class LmsSearchResultProcessor(SearchResultProcessor): diff --git a/lms/lib/courseware_search/lms_search_initializer.py b/lms/lib/courseware_search/lms_search_initializer.py index eec36e1a57..0c62d05c3f 100644 --- a/lms/lib/courseware_search/lms_search_initializer.py +++ b/lms/lib/courseware_search/lms_search_initializer.py @@ -6,10 +6,10 @@ This file contains implementation override of SearchInitializer which will allow from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locations import SlashSeparatedCourseKey - from search.initializer import SearchInitializer -from courseware.masquerade import setup_masquerade + from courseware.access import has_access +from courseware.masquerade import setup_masquerade class LmsSearchInitializer(SearchInitializer): diff --git a/lms/lib/courseware_search/test/test_lms_filter_generator.py b/lms/lib/courseware_search/test/test_lms_filter_generator.py index 3f062c87d8..2f88a8bbd4 100644 --- a/lms/lib/courseware_search/test/test_lms_filter_generator.py +++ b/lms/lib/courseware_search/test/test_lms_filter_generator.py @@ -1,13 +1,13 @@ """ Tests for the lms_filter_generator """ -from mock import patch, Mock +from mock import Mock, patch -from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from student.tests.factories import UserFactory -from student.models import CourseEnrollment from lms.lib.courseware_search.lms_filter_generator import LmsSearchFilterGenerator +from student.models import CourseEnrollment +from student.tests.factories import UserFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory class LmsSearchFilterGeneratorTestCase(ModuleStoreTestCase): diff --git a/lms/lib/courseware_search/test/test_lms_result_processor.py b/lms/lib/courseware_search/test/test_lms_result_processor.py index ef85771b72..e37cebe82e 100644 --- a/lms/lib/courseware_search/test/test_lms_result_processor.py +++ b/lms/lib/courseware_search/test/test_lms_result_processor.py @@ -1,12 +1,10 @@ """ Tests for the lms_result_processor """ -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase - from courseware.tests.factories import UserFactory - from lms.lib.courseware_search.lms_result_processor import LmsSearchResultProcessor +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory class LmsSearchResultProcessorTestCase(ModuleStoreTestCase): diff --git a/lms/tests.py b/lms/tests.py index c70d482bd0..cddcc181d9 100644 --- a/lms/tests.py +++ b/lms/tests.py @@ -1,16 +1,16 @@ """Tests for the lms module itself.""" import mimetypes + +from django.core.urlresolvers import reverse +from django.test import TestCase from mock import patch -from django.test import TestCase -from django.core.urlresolvers import reverse - -from edxmako import add_lookup, LOOKUP +from edxmako import LOOKUP, add_lookup from lms import startup from openedx.features.course_experience import course_home_url_name -from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class LmsModuleTests(TestCase): diff --git a/lms/urls.py b/lms/urls.py index 8e9b64774d..b0cf9b295f 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -2,15 +2,15 @@ URLs for LMS """ +from config_models.views import ConfigurationModelCurrentAPIView from django.conf import settings -from django.conf.urls import patterns, include, url +from django.conf.urls import include, patterns, url +from django.conf.urls.static import static from django.views.generic.base import RedirectView from ratelimitbackend import admin -from django.conf.urls.static import static -from courseware.views.views import CourseTabView, EnrollStaffView, StaticCourseTabView -from config_models.views import ConfigurationModelCurrentAPIView from courseware.views.index import CoursewareIndex +from courseware.views.views import CourseTabView, EnrollStaffView, StaticCourseTabView from django_comment_common.models import ForumsConfig from openedx.core.djangoapps.auth_exchange.views import LoginWithAccessTokenView from openedx.core.djangoapps.catalog.models import CatalogIntegration diff --git a/setup.cfg b/setup.cfg index 3bf713d337..673bf03b01 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,3 +29,9 @@ process-timeout=300 # this rule. ignore=E501,E265,W602 exclude=migrations,.git,.pycharm_helpers,test_root/staticfiles,node_modules + +[isort] +indent=' ' +line_length=120 +multi_line_output=3 +skip=envs,migrations