diff --git a/.isort.cfg b/.isort.cfg
deleted file mode 100644
index cb7288528128e60a059bb49035a1e615e6fd6001..0000000000000000000000000000000000000000
--- 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 23eb1aedbaeee85f13601fe0201ea8843dae30d8..89f35bde38a31331de755c5e663533cfb3d7fea1 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 cced329c0771fdbb2b39dda6be27e29208ccd65c..552550821c2ca5d19ddbfc9262b225e47c6eb42d 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 54e669e9ec272386e3cba43ac23e444a3b31ceed..d1fcce25da05f91988444968f724686b6584b90a 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 441c593eba3d186f1444005f7efd4f848adb1631..2078b50bec0d3e24ae8c76fbbb7ec38d6333bacb 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 3dd4a1de300744694daae2c9a5185733699adcd3..a9d1c8daf2ea4a3d70de2825c687e7fdddf1a7ec 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 d40efcf1c34015e15d850a47f475cf5a94265da4..974534f397313fc1ca97f4595bf9fe9bf6b537f4 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 ca79bf6c2b73ae5654c33ded492be604770a03ba..13d5f857e48fc173d2db6c7903e5f6d90a1f5a88 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 6f531b2e646173609e751b1dd0daad7f8bc0f648..24002771ae7538949cb8f621ffafab96a20703e1 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 e5bbb99c338dbb786ae614577aec2311e8d63358..d300772ddcf3cd8cfc1b7b51e5e16172188d9d5c 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 0fb072ee804fa54642f1f62ba89336e864ed81ee..bf6a8036c90e527ac2c92b2ccada42108f625733 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 badges.events import course_complete
 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 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 2183fd02c69d1cec52ba896d8d64c2033249e971..4b8eab2bddc6b97c6af921a4545093d601a1cb01 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 484e7cd11064810f9112b857780ae8a2b0cd69bf..19e763ba48fe546ecf5af135e43d9fccf73a13c8 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 c625454a9b4a8c91819fb823871f935c87ff95cd..0afb020b4fd02ae446568f242d6c354441b37df4 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 fc56ab66b35287b0ed6be9af92a86867eff9e4ed..88e0a9bb6e332501b7f1b3490b1b56f23f8f05c1 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 4450174e16f08e956b9db20471f196d19a53cf19..851f57eca5ffba98365d44d0241330afa417abc2 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 88beae6b525c6895a66d17c0e790d36447762b70..a3d5112c8e700aff53690c148e9e7bfa19b36f49 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 1dbed47baeea1a9c45bf70de63bcd82aead59c37..2626a55d0416f42846985fd6d4dfc61bd21b0d48 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 5862bbbf1d5e34d562a64b8d7d3c13898275b85a..12e0ad47e38087d0bcaa5ffb781bc2cce501449b 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 a3d6c3fcae62f5a8bec2e69c9a5b8b1dd7462a02..1a00ab52412fdbdfadc09c4aa7e4c839f8dae02d 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 9db971d3b8137326e98f83b8bf083d7c84484ed0..79f1b66b30b59695ea8724c414b70db9bbae22b2 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 0f123c2ad4496898f1a9bb575285a4cc9efe986d..b08510c6bef56d1262ec14b869f8cb9358d69b78 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
-from django.contrib.auth.models import User
-from django.core.urlresolvers import reverse
-from django.conf import settings
 
-import mock
 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.test import TestCase
+
 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 c4f68cc53e3df0db91fcee33ac97d6853defee81..30fb3278aa7e439895f8dfe65c7d591c7e8b244c 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 ac6937a7da067922f6c579e06a2b2cd70e016cc9..67043078ad9abf412f97b50c8a2a2cf1dcd07104 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 django.contrib import admin
-
 from config_models.admin import ConfigurationModelAdmin
+from django.contrib import admin
 
-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 8b4ebb6c63cf6befe642219b70dd036d322a6357..0b3097eebc7496a33ba3c113f841c7654d8d092c 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 0f879735c5ec8bd761134a01693c26ce7a20426c..5befaf9f442f2e95aeea9e8a8f508f108fdce57f 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 f64da3e29cb91ada302ac883766ebce624486b0e..a5d99ca33c9f992d70fe086d4ef05a3798e0dea5 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.exception import AWSConnectionError
 from boto.ses.exceptions import (
-    SESAddressNotVerifiedError,
-    SESIdentityNotVerifiedError,
-    SESDomainNotConfirmedError,
     SESAddressBlacklistedError,
+    SESAddressNotVerifiedError,
     SESDailyQuotaExceededError,
-    SESMaxSendingRateExceededError,
     SESDomainEndsWithDotError,
-    SESLocalAddressCharacterError,
+    SESDomainNotConfirmedError,
+    SESIdentityNotVerifiedError,
     SESIllegalAddressError,
+    SESLocalAddressCharacterError,
+    SESMaxSendingRateExceededError
 )
-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 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 d43d94d9e0f310b3bb24caeae35715b7bcfecff3..ae235c0cf5b5cbb1c20babd5a66e7718b2bf4662 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 ceb9e19b2903d1b7cc86cfc26e0651521e2271c0..1b07e81b61ea6c068d707f52b079256f8ada7292 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 5b277d24dba198954fe17ff92d6f098dbad3826e..bad8c185d7dbdcd27314616a104a2b2994bdff2b 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 7ea5771481b19c8029b4846e8634cfbbe59a15a1..d36b93dacf3064ed0208e2fb4f7f06b73e8253e4 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 opaque_keys.edx.locations import SlashSeparatedCourseKey
 
-from bulk_email.models import CourseEmailTemplate, BulkEmailFlag
 from bulk_email.forms import CourseAuthorizationAdminForm, CourseEmailTemplateForm
-from opaque_keys.edx.locations import SlashSeparatedCourseKey
+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 2886f58e8617eda1ab2888779bdd503301847b92..89b51b511e7c4e80068ba345ebfc1e69ea08c823 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 django.core.management import call_command
+from django.test import TestCase
+from mock import Mock, patch
+from nose.plugins.attrib import attr
+from opaque_keys.edx.keys import CourseKey
+
 from bulk_email.models import (
-    CourseEmail,
     SEND_TO_COHORT,
-    SEND_TO_TRACK,
     SEND_TO_STAFF,
-    CourseEmailTemplate,
+    SEND_TO_TRACK,
+    BulkEmailFlag,
     CourseAuthorization,
-    BulkEmailFlag
+    CourseEmail,
+    CourseEmailTemplate
 )
 from course_modes.models import CourseMode
-from django.core.management import call_command
-from django.test import TestCase
-from mock import patch, Mock
-from nose.plugins.attrib import attr
-from opaque_keys.edx.keys import CourseKey
+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 f01d85eb33e85eb2539a5b5ef8da5777822a7e6c..b50796bd42748dee02960c91b7b6e99bf479de34 100644
--- a/lms/djangoapps/bulk_email/tests/test_tasks.py
+++ b/lms/djangoapps/bulk_email/tests/test_tasks.py
@@ -7,40 +7,37 @@ 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.exception import AWSConnectionError
 from boto.ses.exceptions import (
-    SESAddressNotVerifiedError,
-    SESIdentityNotVerifiedError,
-    SESDomainNotConfirmedError,
     SESAddressBlacklistedError,
+    SESAddressNotVerifiedError,
     SESDailyQuotaExceededError,
-    SESMaxSendingRateExceededError,
     SESDomainEndsWithDotError,
-    SESLocalAddressCharacterError,
+    SESDomainNotConfirmedError,
+    SESIdentityNotVerifiedError,
     SESIllegalAddressError,
+    SESLocalAddressCharacterError,
+    SESMaxSendingRateExceededError
 )
-from boto.exception import AWSConnectionError
-
-from celery.states import SUCCESS, FAILURE  # pylint: disable=no-name-in-module, import-error
-
+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 mock import Mock, patch
+from nose.plugins.attrib import attr
+from opaque_keys.edx.locations import SlashSeparatedCourseKey
 
-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.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.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.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 opaque_keys.edx.locations import SlashSeparatedCourseKey
+from lms.djangoapps.instructor_task.tests.test_base import InstructorTaskCourseTestCase
+from xmodule.modulestore.tests.factories import CourseFactory
 
 
 class TestTaskFailure(Exception):
diff --git a/lms/djangoapps/ccx/api/urls.py b/lms/djangoapps/ccx/api/urls.py
index 7a78eb0bafc861d0f5d94e369e6772e0be6a44ef..ab19553bce4e804c2d22f14f0cfc29f1d86dce7f 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 b376ef3fc6d6dbe2faa3e13decc80a6060993c2b..f341d4d3240884a2b34403e418707047293b6db5 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 3060d8eb15f0af4205188ddccaf435731ed5560f..5aba8640351b8ca9c88805daa43ef940faeaa263 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 92889c8955258ed660143ee9e50b0bfe964e3699..8222601952637b1932c4a35cb80248942dd29378 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 8b2c5cc93f788c30c1318322e4d4f5b4eb49dc72..e543f4c75fba7f2638aa6b5cd65d08f210b1b87a 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 8f8d596cbb6f30ba4a1b078f8d3f18d4d454fbad..ce53399f439e9ca48945aea05d0ee5745e837857 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 2b3b8cd627b29abae2b45be69f487cae59e9d81f..85b2d4b9ad4ead2e582e57cc4603904fa27509a3 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 344135c9d8f06b5e83d6f86759a65dd08b725ac5..923641892663efaf1dda2538333f7735aaf5d2f8 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 44c42fb123f6d89166b852c8320212175fb634d2..650c7bb7f2b70ed8a1205a0a96711db4d382dfa4 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 2bb282125e15344dea3898dd8fd4442705cfb4d4..1f24d06d71b1f44a1bb8d505a4d76b28fdbebda9 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 df0039a12042cdd6e9a1bd7352c76e4380a4fdd1..07c05e793f37f1524adcf7c5ce4758a73f15e029 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 81f1e0a154453f1071c2e556257137e36d0f2424..c1c3f94d990c2ffa6838aa03d8505597e8e24676 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 12bc086794b4a250c63873da58a3189cc09b2968..bc58cd7ebdf6a4d5eca669ddf045f1ec304a1771 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 5fdf7fed0eac5609450c047438797c311d11b192..d50d54cc2a9cd366d57e921e7c8b509f38466ee2 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.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 6110a74bf7a9f17d8ce3e99ce2684b9c2a88a3a3..51ede06489c9a5d9b63463f6ecc6df605507d0ad 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 95e3030873f7076c2fbb5901ce6e436e3113ec21..4bfe347fde75a29cf9327f0d1046c5ecae9c174f 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.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 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
-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
 
 
 class TestSendCCXCoursePublished(ModuleStoreTestCase):
diff --git a/lms/djangoapps/ccx/tests/test_utils.py b/lms/djangoapps/ccx/tests/test_utils.py
index 21ca542feae35b6a8a8116eb5e191f8ac54532b0..2eef54c79d6ed499a69281255902b93ce09d8d2f 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 5ce7a24e24329656c6dde982dc80ba586a00a7e2..b895a4294c643a7814f8c2aa8d84f21454bf62e0 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 9a5740086955f584afd040bfd7a53ac3d2bd72b1..b0383fbf563b4f058ae3387c11efaeb511ed7233 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
 
+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 f6707490872114b2796886c100d84d56515d088e..c3c19f13e56f8cfbffadc8caeb0c3b738f1be90d 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 8aedb796539b1bbb24d61a79103e07094e16da79..279a6d54e9d01129da53faa409a948e3d5d22c5b 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 smtplib import SMTPException
 
+import pytz
 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
+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 2a0d7644574cb35da78b4478586732f999954141..80f9f96386bb6c4ec1e71a964c5691fb05858995 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 de71d0b6d163b5e692061acd0b3cdeee3560d5ad..076e28d39c15ab46e10d236d87011808ac28fb1c 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 8a5d56f73bc785934b14d8e63fb8554ad942f82e..8d0f1dc69f80c3543297192a007456a5dac6a0ea 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 2d45e3f712d2f5f3c2afb59abefd034f1a6e9207..11877615725d082cc630eba24c197b2710451e70 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 f8ddd4cc1709acee070754199ccb68e45b2c8a35..66b28643b9cced681d657bfd91c6d489f59b4486 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 898112917cd9d9d0a1d3fa32e92b9ed43da10ab0..ad57f093d542ce4b56b2488bcaa902125125d667 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 ada927673dd2db093a51461d24e7ea6f553b39d6..8a668c5c37b0b2e25f95be379e7ae6f347ce5964 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 ed2c0a3c4f840d31a2afd3371eef255804b97cc6..b4c9514fef67e43ad568ea9d30b158511d8354e1 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 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 GeneratedCertificate, CertificateStatuses
 
+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 a1c01e5df84045df442ed823b600d7d5b355f461..81dea83afa45aa64a30db717126b4133634c8d52 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 38f42876d84ff453a83c9813737e18a4e9089d31..6cc36ca1c4c485442da21e55041d12b32498871e 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 033aa9d4b2b0e9d4e983a679e44841a1f9d2c2bd..ec3857ad30b06e7c4d634fb023b0a99d62b780cb 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 6a183effa7e53fa7998f241a5c56180a0fa1bbf6..efdbd146ea02655d1c244dc38b7885065c9ca5fe 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 906bf85d845f65f7fb35c26ea879c1109a9b76cc..b0168487801bd47f508f6c8dc16f519b614e674d 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 736a6489598f3f85844372181e9611ffa3c0ee82..3759456ee2edd4409bcd232f5a9d37e3759c43ec 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 11b1452b7af7a1b2ac764fe7a61bf7199ddfd554..f168c93dba6d7cecf88f10434976ff1b15da6cc3 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 4cab739d5fe337092901f7a5233a6240b33e409c..5334df7a364405c5ccb0d3d57ee84eb865fa8740 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 d0297ddff309abc8489f5cc75b5162a4d7ec4fe5..ab893b1fee149150de1f9afd55d7f1638bc41729 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 e5f0d145f7817455ca959fb945e3d951023feecc..82a86ae868a525b2982238582f6a5d9e6d2f3d45 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. """
+import uuid
 from contextlib import contextmanager
-import ddt
 from functools import wraps
-import uuid
 
-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 3a8849d1ab46681078722a1125b129028f3ebbb6..5ec7f56342636807a9cf42dd9e0fc685848a5470 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 860447ff07550e9bdf08e5fcaa4dd7cbcf0ee103..71b5da394bdb07838571c65f5682b35fa7f03089 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 928b5086e13f302b500903bbd6c011c1a547dee1..74399de1db2c8f24ceb96b42e3444f6f0771ed84 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 (
-    ExampleCertificate,
-    ExampleCertificateSet,
+    CertificateGenerationHistory,
     CertificateHtmlViewConfiguration,
-    CertificateTemplateAsset,
     CertificateInvalidation,
-    GeneratedCertificate,
     CertificateStatuses,
-    CertificateGenerationHistory,
-)
-from certificates.tests.factories import (
-    CertificateInvalidationFactory,
-    GeneratedCertificateFactory
+    CertificateTemplateAsset,
+    ExampleCertificate,
+    ExampleCertificateSet,
+    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 0b21f652cd1939af1ee235c4d1e58676b285a0c8..dbc84cf6a4d2f883a2f75a4b9a4d95fa504e7ac3 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 7e27c496b04be6c8031c5887d58452209725f055..2bfcaa81fe994d0284deb87cb22f827daa96623f 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 ba68f7ad29e08a832c37692229622fa320a79935..ae7831061c4b3e7466874cc08609f7fd38be6090 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 opaque_keys.edx.keys import CourseKey
 
-from certificates.models import (
-    CertificateInvalidation,
-    CertificateStatuses,
-    GeneratedCertificate
-)
+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 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 6ccab264ae2171c396969fd43557b07bfc7396dc..3a9438a8ed812b69842827b26454bab12138e6ba 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 b6f6402af465b5bb2da06acba511ef78d1d4a942..da8646fd2822e779b5f5967de9e2b8fec0fe9ed3 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 fb82ce92c5c73e328ca53108c3ddb70b42d86f56..6b997d0ccc78c4298245b036d2c4d6c628c08343 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 b5c468729416e133c14b5ba2d6c27bf537a346bc..7889f0cefdf69a0b8dc499a5c179380dcea86f0b 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 dc879b10f2442f6f5cba964b85edebf6ee345ff3..e40c913debd7def2789ff0049317cfe13a4fc48c 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 614df9732004bec433b1d53f1429cbee841a8a41..2aaec8b7991fd3770b318b0de168025a5f546478 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 7bdeef697524fb29db041c6d98e129f686dde399..ce13ed5bf65e066340fc23b98b64a8c581fd1eaa 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 opaque_keys.edx.locations import SlashSeparatedCourseKey
 
+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
 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 6d059ac135df0840a3515c29cb74ab47365dd650..f0782586642bd56f21d120cdeff25d25044646c5 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 616c4aa600c83ac004fb2f920f09f7589d27a235..5aa1e91d59231b87ef44fab3d5777f73341201af 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 adf5ff6b077b7dcf765f5b7c4d7a15cc69663d80..7976ec4a9d5cfd7a3ed3a4cc24fe582d6cc7c54d 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 ca78be6a3069ceced4c6d98e5406334f580c9adc..8d103a28150726a975ccb938d9b1784da09c3324 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 d5d67c793e350af3665ae0215120f8ec529dbe85..be090347a484aa395ec635d7398365c26bf42ff9 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 ad49323a1399586856acdf4b58057f7ed12bc326..c5c178183aec91769fad102263663b7bdf4cf59e 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 1129750f1c44b8cfb965362c39d22099a2007f39..c12a53ffc8382f066b15af12d162f0854527c87b 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 b2dc7981ae47193c39330911ff20aae909e3916c..ea0f924a4f4714ba47cb61dd3b909eef22758943 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 8d0765085a884ab177b97732f23c13bb8c94a943..90fd9f18457e1176da2f197b403575d18ac818ed 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 b427c89236f6171bf412d9ff77c26b54461a8b73..80bb14954814cefd6bfc2925c5577c9bbe0c933b 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 9d7c0f5ed7b6795822b8e6da06847188eeca2073..356548faf7f5403560f07fdb94a0b9ea248b9a23 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 a114160e3a757600eaa1304fa23cf51bddc3a538..c1a4645c6c993dc34e62f1b39a336989dbe488c6 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 8af77d542a40ee23ab089933943b87f8b5ad0136..7628cab78285bc961687750417aff531cb0d7a36 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 d4ed3a7defab7391055aed0861a0a11f5eb2ab5b..90d149a5e2913b2a7372195f1d5c20d749394691 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 8a862455a8864dad5b27eacc1253d796b66ea192..5c25d991c4a7419dd376a5664933b844fe11c616 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 865d69045ee83add491b5370aaf16df99d795556..fea933330fe7c0d59bd7acd94850e0299f2b3c8c 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 86b931009125e8088ef1932b829ac28ceb6de932..6b47a8814d1ba5f8417fe5fa4ae41f9a04ef463c 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 a3800314c40a78e58d8f38bfdc1de703418dcc07..1e7791e5d65cd4ae48a58191623aab2d63919993 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 dba2258f8dc95f5a8faeb526dfc655fd04515a65..2363f137a09f51ae5d85c0f2a1e74da4b94649e1 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 7901fb4ce02fbcd586c53c3dda8214078ddbdc34..e90d45512d6b16629db38f4e2e0348435167c2d4 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 b406c96c43899e740624ef24cbeaa3283702bf0a..a2ec722840214c65b7b8c3011c4c98589f852370 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 course_modes.models import CourseMode
 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 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 50399b82b51bc2f5fe4da5b34f89ed841407d9a5..665a7f8c0cadb9dcc212d669269f32de7c72fbca 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 d0300bb3943d7f4c8caadd5022e7564f6df23ad8..644492e7bf5884347c1baa975260a22579b00f6b 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 84f2108fe996921d6308e4d41210f1cc6df5b02c..5f41736f07824b095847e38c329c8a30aa5fb476 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 87c8e44ebec4e604dd8204d85c5e8ffb378d2e8c..79a3b387963a7b9159cf7f6dc28f48573dddbe56 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 e33c9252b9b1633c3aa91893e2f44aed4e2a473d..233f618301edf582432fb2ebfaf15e1091a3a407 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 76363e667965543048642a452fdae7fac3a8b1c2..ca2cee5e971dc40f229281a60961e4cf9f00d7d6 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 af9dae0a05059d8672c946ed35d91f152bbc6f8f..3c3d3eef080c1dea199e7e3652a802f763c29fd1 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 ac0bc93ac667a9cb4c5be4d8d175fd52912341ec..9ff56820538f96a1f4f2ffd8c10e996be4a5d02e 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 d5a3be825f72857f01d4444410661e21a3af4929..943ec25096ed9865dbafccc41434926f9b62c8ab 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 f8d2e2bf1610f39c0a461cdb914d6027b2a72710..5c518fa7e27a23c30318ea68a7b1c790cdaef1a4 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 c4356b200d43d924d310e2e7cff6ebd2bae76884..376e78a13ab0d71749fd191756c8344a70e0d23f 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 d0b33efe51474a510396ddde3c6a3aa26d11f7be..e039ec8432dbad438d3a487da2fd49adc6c8cd64 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 4a9e2b969787e08809dc726744450c7697e42320..4a46d6afaab27522641685563b02d6cbfa98fb8b 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 60ee26ae9ac3bb6ec53d41a457b5993b7edbeb4a..b3e123b6b2bc4c37731119582a355150a1b606cd 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 5652aae3f127120364a0f02e9ebf323bba2b2d2e..c566a0ab912edff8dc42f53d3da93731fa33ec6b 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 8cf73593cd14074da4fe9e49eee60aec5ef2dd97..5db1fc9c2b14aeeffef79dfb2dc40b7299cf8151 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 e40a7d708263a79a131b190b59f39e66989c25dc..7cadd939b5787bc0560c96f1f2ae3d178fbb59b6 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 7caefff9d05ea6e131783d120ab5fbf1fec4253d..2b9f939d4c7f8d5153696ae4bff4f34837cbef2d 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 1767cc7422cdb96d109e218b4c296e36412dac2f..85bfd4d896e405d4cf595ac519c1b9cb53c536f8 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 fa8b8488025bd2d4e49de2b72c3ad50cbe8928d0..11e6ae594330ed6c45487c77a1dbb175d3fa7f19 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 b8b7afd559300eb903437ebdbafaef7bfdc420a6..0885611353d40cee352a4ac0c9998be599adc847 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 5ea6d2343a16cfae75f384f3d93dbc202f20ab0b..5ebff7e5712644a28f92d18fa6434b2df85b37c5 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 fbfccd0a00444f5224d80c5a3ed899415d3f3884..62efdbdfa7551b457107f54d79aca095360de896 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 b1d1e76bb6a81f563fb109cae64cde4a1950eb85..3580599c517bead375f37a23296d98f5e3e43511 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 6a357194ee0a9db523caba2a70e9cf9741c5a86f..f2987b849676adf9ba4fe3af13ec0b7e54e3f73e 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 bf24e7ead4643c82bbe226e8f2017d36c809a1ca..294d03be32425d204b0f512ffd10314ef7542096 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 33aea96e29b5e5a19a40f22955f3ddea9d483f44..80e529c37f53e45313c983b0b2962076afc44f06 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 6c37624887cbb285cd4d879c39060088985e3c2c..f48cdccbec0e33aaeef4f23caf959d208d5cbc60 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 0627390ef226d03f6eda2647463670e34cfcdb14..bea8706e1084d8c6766bc61502447c38a4891563 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 9743fc2460214ed03b09cce4e30ce8c0c83f6f16..1ab71ca32b7159bc058cec85201dcb898f45f1f9 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 4db261a6e19b49094d732d08b1c6524b72f2064e..98d1fd84f4120f296f9b7e0014104f25968c86a0 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 561d3c315320263496ac0f8ab5304318de94a38d..c151cfdb21cf052442a3a3950ac384cbe0a055f8 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 073dd08b5b7bc8c96f93ef6de86eb9ca20db1aef..4216ed20cb661c3aa71a557541b5d626f8c9c80d 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 4424133bcae9a22eab58e1dea8e31ff080602054..86032ec36845f48b95b4447801144e72e24a3258 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 2d361758324dd7ea318e8c1d981c14d590f82c8c..e656b1ce259c90268fc5166e04602423a91e7185 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 f5110868f5ac3fbb4c262cda5eccdd9eaf51f1a5..7cfe10f44246fea7e45cf0a9475e44cb435fb80c 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 bbe4ae0725e85f772152cab219597fe159689b8f..a4cb0b5d3ab785dc9f0bfd64336248f3a1f0ecf7 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 2d51078a3b2c767eeba0eb5fe2536742fe2a4c8a..8b97a55b9e687ac77bf294bc563d4e3edb3d28b1 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 a01cdf3b54a9ab7d1e71e556c8f82ba39ca49d83..e8e26882e516fe2750e261966bf5c9bed40a22a8 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 bd872604283c5f9f44b4f36558285eb2ae8a3290..2e2048c764bb3545cd011247a8902d3bb98a5a33 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 33097b7e00303a814dc00b8ee248ecbc54835604..b2db403d0b6cd87b37f451e7ab518bc34953602a 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 f97dde0ee4116fe8ca873e6c95b542732a74222d..c5b6f37a50ff2d9e0e09846669b35afc4226d5ae 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 a83baaee27ee892a121d4ee75be6f67bc6c54ffb..82b8368625f1134ea8c48f34d2df64c357b1d330 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 capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory
 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 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 11ba6aef453c9e7d1a009b988cd9bde7892b068f..8bc0fb9a8f20c830f97bf3f3a23320d2ec48c053 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 eb20915b47a91555843c12916dffe95ff02c8ac5..0f37e3fcc4be0c0d87f43737ede4bd028070b0d0 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 a939408c48dff16db3758a10d3aa5328ec2afe56..434780099af6738527cc02fd07cda9089b54757b 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 b14803744b7068b1afac37e1dd0298a9728561c2..fd93c387d04af98963f64916ef729c991e9951c6 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 37cf2d4033c40b1ce88ff0a82bb6b3469179b272..00fbeb3cc91c00808d72d94139c4e74979ef3c12 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'<p><object data="http://www.gametrailers.com/remote_wrap.php?mid=58079" height
 """
 
 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/wiki_plugin.py b/lms/djangoapps/course_wiki/plugins/markdownedx/wiki_plugin.py
index 407aa77c750deee970bce4708ae4de1348f2d62b..557c91722fa941e8a8a7e69c45c6c6940c72bd21 100644
--- a/lms/djangoapps/course_wiki/plugins/markdownedx/wiki_plugin.py
+++ b/lms/djangoapps/course_wiki/plugins/markdownedx/wiki_plugin.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
-from wiki.core.plugins.base import BasePlugin
 from wiki.core.plugins import registry as plugin_registry
+from wiki.core.plugins.base import BasePlugin
 
 from course_wiki.plugins.markdownedx import mdx_mathjax, mdx_video
 
diff --git a/lms/djangoapps/course_wiki/tests/test_access.py b/lms/djangoapps/course_wiki/tests/test_access.py
index 7c0be1bf3680a8ccdb2db45ede4752715dcda5fc..c5746486410d76db152da56ba75a558541e9eea1 100644
--- a/lms/djangoapps/course_wiki/tests/test_access.py
+++ b/lms/djangoapps/course_wiki/tests/test_access.py
@@ -4,16 +4,15 @@ Tests for wiki permissions
 
 from django.contrib.auth.models import Group
 from nose.plugins.attrib import attr
-from student.tests.factories import UserFactory
-from xmodule.modulestore.tests.factories import CourseFactory
-from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
-
-from courseware.tests.factories import InstructorFactory, StaffFactory
-
 from wiki.models import URLPath
-from course_wiki.views import get_or_create_root
-from course_wiki.utils import user_is_article_course_staff, course_wiki_slug
+
 from course_wiki import settings
+from course_wiki.utils import course_wiki_slug, user_is_article_course_staff
+from course_wiki.views import get_or_create_root
+from courseware.tests.factories import InstructorFactory, StaffFactory
+from student.tests.factories import UserFactory
+from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory
 
 
 class TestWikiAccessBase(ModuleStoreTestCase):
diff --git a/lms/djangoapps/course_wiki/tests/test_comprehensive_theming.py b/lms/djangoapps/course_wiki/tests/test_comprehensive_theming.py
index ecd677b8053a3ad09d02579f19f8312f18320b80..149bdfdb040c1cd39fe0511024b6e77ab9486a7e 100644
--- a/lms/djangoapps/course_wiki/tests/test_comprehensive_theming.py
+++ b/lms/djangoapps/course_wiki/tests/test_comprehensive_theming.py
@@ -1,17 +1,17 @@
 """
 Tests for wiki middleware.
 """
+from unittest import skip
+
 from django.test.client import Client
 from nose.plugins.attrib import attr
-from unittest import skip
 from wiki.models import URLPath
 
+from course_wiki.views import get_or_create_root
+from courseware.tests.factories import InstructorFactory
+from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme
 from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
 from xmodule.modulestore.tests.factories import CourseFactory
-from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme
-
-from courseware.tests.factories import InstructorFactory
-from course_wiki.views import get_or_create_root
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/course_wiki/tests/test_middleware.py b/lms/djangoapps/course_wiki/tests/test_middleware.py
index 23fd4e830ff26e7336a7600d7bad9908d8c0528d..4ad9a36b00615cc2f6260796d8b32013ee69c26f 100644
--- a/lms/djangoapps/course_wiki/tests/test_middleware.py
+++ b/lms/djangoapps/course_wiki/tests/test_middleware.py
@@ -6,12 +6,11 @@ from django.test.client import Client
 from nose.plugins.attrib import attr
 from wiki.models import URLPath
 
+from course_wiki.views import get_or_create_root
+from courseware.tests.factories import InstructorFactory
 from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
 from xmodule.modulestore.tests.factories import CourseFactory
 
-from courseware.tests.factories import InstructorFactory
-from course_wiki.views import get_or_create_root
-
 
 @attr(shard=1)
 class TestWikiAccessMiddleware(ModuleStoreTestCase):
diff --git a/lms/djangoapps/course_wiki/tests/tests.py b/lms/djangoapps/course_wiki/tests/tests.py
index 2ea09a0edf0b94c011bd57529b5307008c0d0d6a..66fcacc493294de35bed2161cdab21f70e6c8a0c 100644
--- a/lms/djangoapps/course_wiki/tests/tests.py
+++ b/lms/djangoapps/course_wiki/tests/tests.py
@@ -1,4 +1,5 @@
 from django.core.urlresolvers import reverse
+from mock import patch
 from nose.plugins.attrib import attr
 
 from courseware.tests.tests import LoginEnrollmentTestCase
@@ -6,8 +7,6 @@ from openedx.features.enterprise_support.tests.mixins.enterprise import Enterpri
 from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
 from xmodule.modulestore.tests.factories import CourseFactory
 
-from mock import patch
-
 
 @attr(shard=1)
 class WikiRedirectTestCase(EnterpriseTestConsentRequired, LoginEnrollmentTestCase, ModuleStoreTestCase):
diff --git a/lms/djangoapps/course_wiki/utils.py b/lms/djangoapps/course_wiki/utils.py
index 6054558c052d2e720849d85269a4ee9db26db54b..3740d952252d03194d742e44c353576155370674 100644
--- a/lms/djangoapps/course_wiki/utils.py
+++ b/lms/djangoapps/course_wiki/utils.py
@@ -3,8 +3,9 @@ Utility functions for course_wiki.
 """
 
 from django.core.exceptions import ObjectDoesNotExist
-from xmodule import modulestore
+
 import courseware
+from xmodule import modulestore
 
 
 def user_is_article_course_staff(user, article):
diff --git a/lms/djangoapps/course_wiki/views.py b/lms/djangoapps/course_wiki/views.py
index 89bb3d1c0f3de96a26ac0eda682a4c344cd17d97..7dde56383803997f463ba0093d8fcde221bec7ee 100644
--- a/lms/djangoapps/course_wiki/views.py
+++ b/lms/djangoapps/course_wiki/views.py
@@ -1,20 +1,19 @@
 """
 This file contains view functions for wrapping the django-wiki.
 """
+import cgi
 import logging
 import re
-import cgi
 
 from django.conf import settings
 from django.shortcuts import redirect
 from django.utils.translation import ugettext as _
-
+from opaque_keys.edx.locations import SlashSeparatedCourseKey
 from wiki.core.exceptions import NoRootURL
-from wiki.models import URLPath, Article
+from wiki.models import Article, URLPath
 
-from courseware.courses import get_course_by_id
 from course_wiki.utils import course_wiki_slug
-from opaque_keys.edx.locations import SlashSeparatedCourseKey
+from courseware.courses import get_course_by_id
 from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
 from openedx.features.enterprise_support.api import data_sharing_consent_required
 
diff --git a/lms/djangoapps/courseware/access.py b/lms/djangoapps/courseware/access.py
index c60368fe1daa03477ce7667ee3204abf01281c36..69a154b46f0310e4f13cd3b9c2dc7df0110d1970 100644
--- a/lms/djangoapps/courseware/access.py
+++ b/lms/djangoapps/courseware/access.py
@@ -10,33 +10,18 @@ Note: The access control logic in this file does NOT check for enrollment in
   If enrollment is to be checked, use get_course_with_access in courseware.courses.
   It is a wrapper around has_access that additionally checks for enrollment.
 """
-from datetime import datetime
 import logging
-import pytz
+from datetime import datetime
 
+import pytz
+from ccx_keys.locator import CCXLocator
 from django.conf import settings
 from django.contrib.auth.models import AnonymousUser
 from django.utils.timezone import UTC
-
 from opaque_keys.edx.keys import CourseKey, UsageKey
-
-from util import milestones_helpers as milestones_helpers
 from xblock.core import XBlock
 
-from xmodule.course_module import (
-    CourseDescriptor,
-    CATALOG_VISIBILITY_CATALOG_AND_ABOUT,
-    CATALOG_VISIBILITY_ABOUT,
-)
-from xmodule.error_module import ErrorDescriptor
-from xmodule.x_module import XModule
-from xmodule.partitions.partitions import NoSuchUserPartitionError, NoSuchUserPartitionGroupError
-
-from courseware.access_response import (
-    MilestoneError,
-    MobileAvailabilityError,
-    VisibilityError,
-)
+from courseware.access_response import MilestoneError, MobileAvailabilityError, VisibilityError
 from courseware.access_utils import (
     ACCESS_DENIED,
     ACCESS_GRANTED,
@@ -59,16 +44,20 @@ from student.roles import (
     CourseInstructorRole,
     CourseStaffRole,
     GlobalStaff,
-    SupportStaffRole,
     OrgInstructorRole,
     OrgStaffRole,
+    SupportStaffRole
 )
+from util import milestones_helpers as milestones_helpers
 from util.milestones_helpers import (
-    get_pre_requisite_courses_not_completed,
     any_unfulfilled_milestones,
-    is_prerequisite_courses_enabled,
+    get_pre_requisite_courses_not_completed,
+    is_prerequisite_courses_enabled
 )
-from ccx_keys.locator import CCXLocator
+from xmodule.course_module import CATALOG_VISIBILITY_ABOUT, CATALOG_VISIBILITY_CATALOG_AND_ABOUT, CourseDescriptor
+from xmodule.error_module import ErrorDescriptor
+from xmodule.partitions.partitions import NoSuchUserPartitionError, NoSuchUserPartitionGroupError
+from xmodule.x_module import XModule
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/courseware/access_response.py b/lms/djangoapps/courseware/access_response.py
index 976571cf2411e43940872047301fcb4f4ab6e61b..f9b4b6f703ee9c7ac1c7f85b404c968c64c2611d 100644
--- a/lms/djangoapps/courseware/access_response.py
+++ b/lms/djangoapps/courseware/access_response.py
@@ -3,6 +3,7 @@ This file contains all the classes used by has_access for error handling
 """
 
 from django.utils.translation import ugettext as _
+
 from xmodule.course_metadata_utils import DEFAULT_START_DATE
 
 
diff --git a/lms/djangoapps/courseware/access_utils.py b/lms/djangoapps/courseware/access_utils.py
index 094a6928b258f7b02f2497ae20cdbf1d794648e9..77cc9cbc1db3b2bf9d3652a033a73fcca140205d 100644
--- a/lms/djangoapps/courseware/access_utils.py
+++ b/lms/djangoapps/courseware/access_utils.py
@@ -4,15 +4,16 @@ It allows us to share code between access.py and block transformers.
 """
 
 from datetime import datetime, timedelta
+from logging import getLogger
+
 from django.conf import settings
 from django.utils.timezone import UTC
-from logging import getLogger
-from student.roles import CourseBetaTesterRole
-from courseware.masquerade import is_masquerading_as_student
+
 from courseware.access_response import AccessResponse, StartDateError
+from courseware.masquerade import is_masquerading_as_student
+from student.roles import CourseBetaTesterRole
 from xmodule.util.django import get_current_request_hostname
 
-
 DEBUG_ACCESS = False
 log = getLogger(__name__)
 
diff --git a/lms/djangoapps/courseware/admin.py b/lms/djangoapps/courseware/admin.py
index 78c9fc826fab152fc466036c4af962ee621f938c..3b704565a8df3560266fd7ec54543321268baec6 100644
--- a/lms/djangoapps/courseware/admin.py
+++ b/lms/djangoapps/courseware/admin.py
@@ -2,9 +2,10 @@
 django admin pages for courseware model
 '''
 
-from courseware.models import StudentModule, OfflineComputedGrade, OfflineComputedGradeLog
 from ratelimitbackend import admin
 
+from courseware.models import OfflineComputedGrade, OfflineComputedGradeLog, StudentModule
+
 admin.site.register(StudentModule)
 
 admin.site.register(OfflineComputedGrade)
diff --git a/lms/djangoapps/courseware/context_processor.py b/lms/djangoapps/courseware/context_processor.py
index 07f98191a0941397f77ff7f62113ca9920769936..ecc1efbd3af44e2e047c350436100d96cfc8a35e 100644
--- a/lms/djangoapps/courseware/context_processor.py
+++ b/lms/djangoapps/courseware/context_processor.py
@@ -5,9 +5,9 @@ This is meant to simplify the process of sending user preferences (espec. time_z
 to the templates without having to append every view file.
 
 """
-from openedx.core.djangoapps.user_api.errors import UserNotFound, UserAPIInternalError
-from openedx.core.djangoapps.user_api.preferences.api import get_user_preferences
 import request_cache
+from openedx.core.djangoapps.user_api.errors import UserAPIInternalError, UserNotFound
+from openedx.core.djangoapps.user_api.preferences.api import get_user_preferences
 
 RETRIEVABLE_PREFERENCES = {
     'user_timezone': 'time_zone',
diff --git a/lms/djangoapps/courseware/courses.py b/lms/djangoapps/courseware/courses.py
index c4c1fb29f0937b830b1662c6847a635692162fc8..08f7fdfbefbfbdb383da127dab12695220ac381e 100644
--- a/lms/djangoapps/courseware/courses.py
+++ b/lms/djangoapps/courseware/courses.py
@@ -2,41 +2,39 @@
 Functions for accessing and displaying courses within the
 courseware.
 """
-from datetime import datetime
-from collections import defaultdict
-from fs.errors import ResourceNotFoundError
 import logging
-from path import Path as path
-import pytz
+from collections import defaultdict
+from datetime import datetime
 
-from django.http import Http404
+import pytz
 from django.conf import settings
 from django.core.urlresolvers import reverse
+from django.http import Http404
+from fs.errors import ResourceNotFoundError
+from opaque_keys.edx.keys import UsageKey
+from path import Path as path
 
-from edxmako.shortcuts import render_to_string
-from xmodule.modulestore.django import modulestore
-from xmodule.modulestore.exceptions import ItemNotFoundError
-from static_replace import replace_static_urls
-from xmodule.x_module import STUDENT_VIEW
-
+import branding
 from courseware.access import has_access
 from courseware.date_summary import (
     CourseEndDate,
     CourseStartDate,
     TodaysDate,
     VerificationDeadlineDate,
-    VerifiedUpgradeDeadlineDate,
+    VerifiedUpgradeDeadlineDate
 )
 from courseware.model_data import FieldDataCache
 from courseware.module_render import get_module, get_module_for_descriptor
+from edxmako.shortcuts import render_to_string
 from lms.djangoapps.courseware.courseware_access_exception import CoursewareAccessException
 from lms.djangoapps.courseware.exceptions import CourseAccessRedirect
-from student.models import CourseEnrollment
-import branding
-
-from opaque_keys.edx.keys import UsageKey
 from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
 from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
+from static_replace import replace_static_urls
+from student.models import CourseEnrollment
+from xmodule.modulestore.django import modulestore
+from xmodule.modulestore.exceptions import ItemNotFoundError
+from xmodule.x_module import STUDENT_VIEW
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/courseware/date_summary.py b/lms/djangoapps/courseware/date_summary.py
index c0fa0c6eda439677761051300881a9e2c44229d8..2e0b2dc007229296a638cfcf2b30d84b3d527bb4 100644
--- a/lms/djangoapps/courseware/date_summary.py
+++ b/lms/djangoapps/courseware/date_summary.py
@@ -4,18 +4,17 @@ page. Each block gives information about a particular
 course-run-specific date which will be displayed to the user.
 """
 from datetime import datetime
-from pytz import timezone, utc
 
 from babel.dates import format_timedelta
 from django.core.urlresolvers import reverse
 from django.utils.translation import ugettext as _
-from django.utils.translation import ugettext_lazy
-from django.utils.translation import to_locale, get_language
+from django.utils.translation import get_language, to_locale, ugettext_lazy
 from lazy import lazy
+from pytz import timezone, utc
 
 from course_modes.models import CourseMode
 from lms.djangoapps.commerce.utils import EcommerceService
-from lms.djangoapps.verify_student.models import VerificationDeadline, SoftwareSecurePhotoVerification
+from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification, VerificationDeadline
 from student.models import CourseEnrollment
 
 
diff --git a/lms/djangoapps/courseware/features/common.py b/lms/djangoapps/courseware/features/common.py
index 79df764fdd87b1dfad96ae3ec9de96ad5b45774b..c351db7061e07b40a9755f278efc442cc9f9d620 100644
--- a/lms/djangoapps/courseware/features/common.py
+++ b/lms/djangoapps/courseware/features/common.py
@@ -4,17 +4,19 @@
 from __future__ import absolute_import
 
 import time
+from logging import getLogger
 
-from lettuce import world, step, before
-from lettuce.django import django_url
 from django.contrib.auth.models import User
 from django.core.urlresolvers import reverse
-from student.models import CourseEnrollment
-from xmodule.modulestore.django import modulestore
-from xmodule.course_module import CourseDescriptor
+from lettuce import before, step, world
+from lettuce.django import django_url
+
 from courseware.courses import get_course_by_id
+from student.models import CourseEnrollment
 from xmodule import seq_module, vertical_block
-from logging import getLogger
+from xmodule.course_module import CourseDescriptor
+from xmodule.modulestore.django import modulestore
+
 logger = getLogger(__name__)
 
 
diff --git a/lms/djangoapps/courseware/features/courseware.py b/lms/djangoapps/courseware/features/courseware.py
index 91de6ffe709e7cab556e1abc2348f85d8d9f56f0..db19fd1970832b1b4b7ce7bdb5b5b3d4adda7821 100644
--- a/lms/djangoapps/courseware/features/courseware.py
+++ b/lms/djangoapps/courseware/features/courseware.py
@@ -1,7 +1,7 @@
 # pylint: disable=missing-docstring
 # pylint: disable=redefined-outer-name
 
-from lettuce import world, step
+from lettuce import step, world
 from lettuce.django import django_url
 
 
diff --git a/lms/djangoapps/courseware/features/courseware_common.py b/lms/djangoapps/courseware/features/courseware_common.py
index 8814d45a476c5a900f6144eb5e6f55886a25d71d..ba2f2193a775b56edf356ff406499f7d479733ed 100644
--- a/lms/djangoapps/courseware/features/courseware_common.py
+++ b/lms/djangoapps/courseware/features/courseware_common.py
@@ -2,7 +2,7 @@
 # pylint: disable=redefined-outer-name
 # pylint: disable=unused-argument
 
-from lettuce import world, step
+from lettuce import step, world
 
 
 @step('I click on View Courseware')
diff --git a/lms/djangoapps/courseware/features/events.py b/lms/djangoapps/courseware/features/events.py
index eefd0e1b92c2e5f1f7440cf4d2875889ae80f5aa..c2528cec0e46629f1be05967671967f1076266b5 100644
--- a/lms/djangoapps/courseware/features/events.py
+++ b/lms/djangoapps/courseware/features/events.py
@@ -1,11 +1,8 @@
 # pylint: disable=missing-docstring
 
-from lettuce import step
-from lettuce import world
-from lettuce import before
+from lettuce import before, step, world
+from nose.tools import assert_equals, assert_in
 from pymongo import MongoClient
-from nose.tools import assert_equals
-from nose.tools import assert_in
 
 REQUIRED_EVENT_FIELDS = [
     'agent',
diff --git a/lms/djangoapps/courseware/features/lti.py b/lms/djangoapps/courseware/features/lti.py
index 6da318c7a6f87871d3f3cd62ddca882e4d982f16..b4f29972f3b47d178d82b45e3be8020933044c70 100644
--- a/lms/djangoapps/courseware/features/lti.py
+++ b/lms/djangoapps/courseware/features/lti.py
@@ -1,21 +1,21 @@
 # pylint: disable=missing-docstring
 import datetime
 import os
+
 import pytz
 from django.conf import settings
+from lettuce import step, world
 from mock import patch
+from nose.tools import assert_equal, assert_in, assert_is_none, assert_true
 from pytz import UTC
-from splinter.exceptions import ElementDoesNotExist
 from selenium.common.exceptions import NoAlertPresentException
-from nose.tools import assert_true, assert_equal, assert_in, assert_is_none
-from lettuce import world, step
+from splinter.exceptions import ElementDoesNotExist
 
-from courseware.tests.factories import InstructorFactory, BetaTesterFactory
+from common import visit_scenario_item
 from courseware.access import has_access
+from courseware.tests.factories import BetaTesterFactory, InstructorFactory
 from student.tests.factories import UserFactory
 
-from common import visit_scenario_item
-
 TEST_COURSE_NAME = "test_course_a"
 
 
diff --git a/lms/djangoapps/courseware/features/problems.py b/lms/djangoapps/courseware/features/problems.py
index 93460849728da8e278b6255ae426e67b4ff45e63..808d34c807526da39dc68cd798c2047f2e6257fc 100644
--- a/lms/djangoapps/courseware/features/problems.py
+++ b/lms/djangoapps/courseware/features/problems.py
@@ -5,9 +5,10 @@ Steps for problem.feature lettuce tests
 # pylint: disable=missing-docstring
 # pylint: disable=redefined-outer-name
 
-from lettuce import world, step
+from lettuce import step, world
+
 from common import i_am_registered_for_the_course, visit_scenario_item
-from problems_setup import PROBLEM_DICT, answer_problem, problem_has_answer, add_problem_to_course
+from problems_setup import PROBLEM_DICT, add_problem_to_course, answer_problem, problem_has_answer
 
 
 def _view_problem(step, problem_type, problem_settings=None):
diff --git a/lms/djangoapps/courseware/features/problems_setup.py b/lms/djangoapps/courseware/features/problems_setup.py
index bbfa911dcec819273ab9949af4292ce759161316..3f92945551f088e9c433fe3f69abde840e507d5c 100644
--- a/lms/djangoapps/courseware/features/problems_setup.py
+++ b/lms/djangoapps/courseware/features/problems_setup.py
@@ -9,10 +9,11 @@
 # -A way to answer the problem correctly and incorrectly
 # -A way to check the problem was answered correctly, incorrectly and blank
 
-from lettuce import world
 import random
 import textwrap
-from common import section_location
+
+from lettuce import world
+
 from capa.tests.response_xml_factory import (
     ChoiceResponseXMLFactory,
     ChoiceTextResponseXMLFactory,
@@ -23,9 +24,9 @@ from capa.tests.response_xml_factory import (
     MultipleChoiceResponseXMLFactory,
     NumericalResponseXMLFactory,
     OptionResponseXMLFactory,
-    StringResponseXMLFactory,
+    StringResponseXMLFactory
 )
-
+from common import section_location
 
 # Factories from capa.tests.response_xml_factory that we will use
 # to generate the problem XML, with the keyword args used to configure
diff --git a/lms/djangoapps/courseware/features/registration.py b/lms/djangoapps/courseware/features/registration.py
index 8542a88bf5a47c8cefe9edc3583d2fcfd5b8bcfc..b83ed5dd6f0de55f9f47027b5dc9f659c330bd4f 100644
--- a/lms/djangoapps/courseware/features/registration.py
+++ b/lms/djangoapps/courseware/features/registration.py
@@ -1,9 +1,10 @@
 # pylint: disable=missing-docstring
 
-from lettuce import world, step
-from lettuce.django import django_url
 import time
 
+from lettuce import step, world
+from lettuce.django import django_url
+
 
 @step('I register for the course "([^"]*)"$')
 def i_register_for_the_course(_step, course):
diff --git a/lms/djangoapps/courseware/features/word_cloud.py b/lms/djangoapps/courseware/features/word_cloud.py
index e14a0a53075a94622a796e8b450a926d0ccd0a3c..1c2c5ff902a54eaa6c639cd68865824855981eb1 100644
--- a/lms/djangoapps/courseware/features/word_cloud.py
+++ b/lms/djangoapps/courseware/features/word_cloud.py
@@ -1,6 +1,7 @@
 # pylint: disable=missing-docstring
 
-from lettuce import world, step
+from lettuce import step, world
+
 from common import i_am_registered_for_the_course, section_location, visit_scenario_item
 
 
diff --git a/lms/djangoapps/courseware/field_overrides.py b/lms/djangoapps/courseware/field_overrides.py
index 02417d951575032e7762d3a9ff0e20724ba69c54..a14ad18fce6645aa78456d47843321d1627e7ef6 100644
--- a/lms/djangoapps/courseware/field_overrides.py
+++ b/lms/djangoapps/courseware/field_overrides.py
@@ -14,9 +14,9 @@ package and is used to wrap the `authored_data` when constructing an
 `LmsFieldData`.  This means overrides will be in effect for all scopes covered
 by `authored_data`, e.g. course content and settings stored in Mongo.
 """
+import threading
 from abc import ABCMeta, abstractmethod
 from contextlib import contextmanager
-import threading
 
 from django.conf import settings
 from xblock.field_data import FieldData
@@ -24,7 +24,6 @@ from xblock.field_data import FieldData
 from request_cache.middleware import RequestCache
 from xmodule.modulestore.inheritance import InheritanceMixin
 
-
 NOTSET = object()
 ENABLED_OVERRIDE_PROVIDERS_KEY = u'courseware.field_overrides.enabled_providers.{course_id}'
 ENABLED_MODULESTORE_OVERRIDE_PROVIDERS_KEY = u'courseware.modulestore_field_overrides.enabled_providers.{course_id}'
diff --git a/lms/djangoapps/courseware/management/commands/clean_xml.py b/lms/djangoapps/courseware/management/commands/clean_xml.py
index f3ca26d29030e70843dbc4c1828b7c67a6a190b0..53e98384750af9ad23c81e416bbb3a629ce238de 100644
--- a/lms/djangoapps/courseware/management/commands/clean_xml.py
+++ b/lms/djangoapps/courseware/management/commands/clean_xml.py
@@ -1,13 +1,12 @@
-import lxml.etree
 import os
 import sys
 import traceback
 
+import lxml.etree
+from django.core.management.base import BaseCommand
 from fs.osfs import OSFS
 from path import Path as path
 
-from django.core.management.base import BaseCommand
-
 from xmodule.modulestore.xml import XMLModuleStore
 
 
diff --git a/lms/djangoapps/courseware/management/commands/dump_course_structure.py b/lms/djangoapps/courseware/management/commands/dump_course_structure.py
index 874133a074c1a91554790b6c8c5289d00abf9559..f1b58a85da5572a2fb065ac5e1a63ec00fd14c90 100644
--- a/lms/djangoapps/courseware/management/commands/dump_course_structure.py
+++ b/lms/djangoapps/courseware/management/commands/dump_course_structure.py
@@ -21,14 +21,13 @@ from optparse import make_option
 from textwrap import dedent
 
 from django.core.management.base import BaseCommand, CommandError
-
-from xmodule.modulestore.django import modulestore
-from xmodule.modulestore.inheritance import own_metadata, compute_inherited_metadata
-
-from xblock_discussion import DiscussionXBlock
-from xblock.fields import Scope
 from opaque_keys import InvalidKeyError
 from opaque_keys.edx.keys import CourseKey
+from xblock.fields import Scope
+
+from xblock_discussion import DiscussionXBlock
+from xmodule.modulestore.django import modulestore
+from xmodule.modulestore.inheritance import compute_inherited_metadata, own_metadata
 
 FILTER_LIST = ['xml_attributes']
 INHERITED_FILTER_LIST = ['children', 'xml_attributes']
diff --git a/lms/djangoapps/courseware/management/commands/export_course.py b/lms/djangoapps/courseware/management/commands/export_course.py
index 27a6c4497e42cf350cb76d9ec3ee1cd6c3744837..0f6d748faba080a85732fcc26a7ba44862acd6db 100644
--- a/lms/djangoapps/courseware/management/commands/export_course.py
+++ b/lms/djangoapps/courseware/management/commands/export_course.py
@@ -17,17 +17,16 @@ import os
 import re
 import shutil
 import tarfile
-from tempfile import mktemp, mkdtemp
+from tempfile import mkdtemp, mktemp
 from textwrap import dedent
 
-from path import Path as path
-
 from django.core.management.base import BaseCommand, CommandError
+from opaque_keys import InvalidKeyError
+from opaque_keys.edx.keys import CourseKey
+from path import Path as path
 
 from xmodule.modulestore.django import modulestore
 from xmodule.modulestore.xml_exporter import export_course_to_xml
-from opaque_keys import InvalidKeyError
-from opaque_keys.edx.keys import CourseKey
 
 
 class Command(BaseCommand):
diff --git a/lms/djangoapps/courseware/management/commands/fix_student_module_newlines.py b/lms/djangoapps/courseware/management/commands/fix_student_module_newlines.py
index f165e37b93058a688157fdcc7595b8f014dfec46..d195afec2e53e027257aac3dd9385a3898465ae4 100644
--- a/lms/djangoapps/courseware/management/commands/fix_student_module_newlines.py
+++ b/lms/djangoapps/courseware/management/commands/fix_student_module_newlines.py
@@ -6,15 +6,14 @@ Due to a bug, many rows in courseware_studentmodule were written with a
 course_id that had a trailing newline. This command tries to fix that, and to
 merge that data with data that might have been written to the correct course_id.
 """
+import json
+import logging
 from collections import namedtuple
 from optparse import make_option
 from textwrap import dedent
-import json
-import logging
 
-from django.db import DatabaseError
-from django.db import transaction
 from django.core.management.base import BaseCommand, CommandError
+from django.db import DatabaseError, transaction
 
 from courseware.models import StudentModule
 from util.query import use_read_replica_if_available
diff --git a/lms/djangoapps/courseware/management/commands/regrade_partial.py b/lms/djangoapps/courseware/management/commands/regrade_partial.py
index 9ef99cf8e03769dcd29d6624bd25b69223ede1c9..656fb71e2db10c7c12ded983b73f24dc9c907135 100644
--- a/lms/djangoapps/courseware/management/commands/regrade_partial.py
+++ b/lms/djangoapps/courseware/management/commands/regrade_partial.py
@@ -10,8 +10,8 @@ from optparse import make_option
 
 from django.core.management.base import BaseCommand
 
-from courseware.models import StudentModule
 from capa.correctmap import CorrectMap
+from courseware.models import StudentModule
 
 LOG = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py b/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py
index aee2febcec63df7afd067a0c76a4572b510c41ca..01812093a6e12789903f6a5f57a90eba6b75bf11 100644
--- a/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py
+++ b/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py
@@ -3,22 +3,23 @@
 """Tests for Django management commands"""
 
 import json
-from nose.plugins.attrib import attr
-from path import Path as path
 import shutil
-from StringIO import StringIO
 import tarfile
+from StringIO import StringIO
 from tempfile import mkdtemp
-import factory
 
+import factory
 from django.conf import settings
 from django.core.management import call_command
+from nose.plugins.attrib import attr
+from path import Path as path
 
 from xmodule.modulestore import ModuleStoreEnum
 from xmodule.modulestore.django import modulestore
-from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
 from xmodule.modulestore.tests.django_utils import (
-    TEST_DATA_MONGO_MODULESTORE, TEST_DATA_SPLIT_MODULESTORE
+    TEST_DATA_MONGO_MODULESTORE,
+    TEST_DATA_SPLIT_MODULESTORE,
+    SharedModuleStoreTestCase
 )
 from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
 from xmodule.modulestore.xml_importer import import_course_from_xml
diff --git a/lms/djangoapps/courseware/masquerade.py b/lms/djangoapps/courseware/masquerade.py
index 5cfeac5c109f8969f1bc430d02feedbb2dfd1504..bc29de1d89755614a8f40e15f67ad64d5067aae3 100644
--- a/lms/djangoapps/courseware/masquerade.py
+++ b/lms/djangoapps/courseware/masquerade.py
@@ -11,14 +11,13 @@ from django.contrib.auth.decorators import login_required
 from django.contrib.auth.models import User
 from django.utils.translation import ugettext as _
 from django.views.decorators.http import require_POST
-from student.models import CourseEnrollment
-from util.json_request import expect_json, JsonResponse
-
 from opaque_keys.edx.keys import CourseKey
 from xblock.fragment import Fragment
 from xblock.runtime import KeyValueStore
-from xmodule.partitions.partitions import NoSuchUserPartitionGroupError
 
+from student.models import CourseEnrollment
+from util.json_request import JsonResponse, expect_json
+from xmodule.partitions.partitions import NoSuchUserPartitionGroupError
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/courseware/model_data.py b/lms/djangoapps/courseware/model_data.py
index 2b32e834403c695895cc5043c3f242c4e9dd69b1..ae780a519a51c0831a272752c516719a3e92e8fa 100644
--- a/lms/djangoapps/courseware/model_data.py
+++ b/lms/djangoapps/courseware/model_data.py
@@ -22,29 +22,24 @@ DjangoOrmFieldCache: A base-class for single-row-per-field caches.
 """
 
 import json
-from abc import abstractmethod, ABCMeta
-from collections import defaultdict, namedtuple
-from .models import (
-    StudentModule,
-    XModuleUserStateSummaryField,
-    XModuleStudentPrefsField,
-    XModuleStudentInfoField
-)
 import logging
-from opaque_keys.edx.keys import CourseKey, UsageKey
-from opaque_keys.edx.block_types import BlockTypeKeyV1
-from opaque_keys.edx.asides import AsideUsageKeyV1, AsideUsageKeyV2
-from contracts import contract, new_contract
+from abc import ABCMeta, abstractmethod
+from collections import defaultdict, namedtuple
 
+from contracts import contract, new_contract
 from django.db import DatabaseError
-
-from xblock.runtime import KeyValueStore
-from xblock.exceptions import KeyValueMultiSaveError, InvalidScopeError
-from xblock.fields import Scope, UserScope
-from xmodule.modulestore.django import modulestore
+from opaque_keys.edx.asides import AsideUsageKeyV1, AsideUsageKeyV2
+from opaque_keys.edx.block_types import BlockTypeKeyV1
+from opaque_keys.edx.keys import CourseKey, UsageKey
 from xblock.core import XBlockAside
+from xblock.exceptions import InvalidScopeError, KeyValueMultiSaveError
+from xblock.fields import Scope, UserScope
+from xblock.runtime import KeyValueStore
+
 from courseware.user_state_client import DjangoXBlockUserStateClient
+from xmodule.modulestore.django import modulestore
 
+from .models import StudentModule, XModuleStudentInfoField, XModuleStudentPrefsField, XModuleUserStateSummaryField
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/courseware/models.py b/lms/djangoapps/courseware/models.py
index db2cb7279c5e0dfbf9df6f6bc95019411f7371ee..7e0c5fc5a87e24224694594e70ea9b6c8567838a 100644
--- a/lms/djangoapps/courseware/models.py
+++ b/lms/djangoapps/courseware/models.py
@@ -12,20 +12,17 @@ file and check it in at the same time as your model changes. To do that,
 ASSUMPTIONS: modules have unique IDs, even across different module_types
 
 """
-import logging
 import itertools
+import logging
 
-from django.contrib.auth.models import User
 from django.conf import settings
+from django.contrib.auth.models import User
 from django.db import models
 from django.db.models.signals import post_save
-
 from model_utils.models import TimeStampedModel
-import coursewarehistoryextended
 
-from openedx.core.djangoapps.xmodule_django.models import (
-    CourseKeyField, LocationKeyField, BlockTypeKeyField
-)
+import coursewarehistoryextended
+from openedx.core.djangoapps.xmodule_django.models import BlockTypeKeyField, CourseKeyField, LocationKeyField
 
 log = logging.getLogger("edx.courseware")
 
diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py
index 6c97d46ee2681904a5c8807701b5893eb4c70dde..3aa22050a65d2225da0687edf574f00abd2c9c5f 100644
--- a/lms/djangoapps/courseware/module_render.py
+++ b/lms/djangoapps/courseware/module_render.py
@@ -8,6 +8,25 @@ import logging
 from collections import OrderedDict
 from functools import partial
 
+from django.conf import settings
+from django.contrib.auth.models import User
+from django.core.cache import cache
+from django.core.context_processors import csrf
+from django.core.exceptions import PermissionDenied
+from django.core.urlresolvers import reverse
+from django.http import Http404, HttpResponse
+from django.views.decorators.csrf import csrf_exempt
+from edx_proctoring.services import ProctoringService
+from opaque_keys import InvalidKeyError
+from opaque_keys.edx.keys import CourseKey, UsageKey
+from opaque_keys.edx.locations import SlashSeparatedCourseKey
+from requests.auth import HTTPBasicAuth
+from xblock.core import XBlock
+from xblock.django.request import django_to_webob_request, webob_to_django_response
+from xblock.exceptions import NoSuchHandlerError, NoSuchViewError
+from xblock.reference.plugins import FSService
+from xblock.runtime import KvsFieldData
+
 import static_replace
 from capa.xqueue_interface import XQueueInterface
 from courseware.access import get_user_role, has_access
@@ -19,15 +38,6 @@ from courseware.masquerade import (
     setup_masquerade
 )
 from courseware.model_data import DjangoKeyValueStore, FieldDataCache
-from django.conf import settings
-from django.contrib.auth.models import User
-from django.core.cache import cache
-from django.core.context_processors import csrf
-from django.core.exceptions import PermissionDenied
-from django.core.urlresolvers import reverse
-from django.http import Http404, HttpResponse
-from django.views.decorators.csrf import csrf_exempt
-from edx_proctoring.services import ProctoringService
 from edxmako.shortcuts import render_to_string
 from eventtracking import tracker
 from lms.djangoapps.grades.signals.signals import SCORE_PUBLISHED
@@ -35,9 +45,6 @@ from lms.djangoapps.lms_xblock.field_data import LmsFieldData
 from lms.djangoapps.lms_xblock.models import XBlockAsidesConfig
 from lms.djangoapps.lms_xblock.runtime import LmsModuleSystem
 from lms.djangoapps.verify_student.services import VerificationService
-from opaque_keys import InvalidKeyError
-from opaque_keys.edx.keys import CourseKey, UsageKey
-from opaque_keys.edx.locations import SlashSeparatedCourseKey
 from openedx.core.djangoapps.bookmarks.services import BookmarksService
 from openedx.core.djangoapps.crawlers.models import CrawlersConfig
 from openedx.core.djangoapps.credit.services import CreditService
@@ -53,7 +60,6 @@ from openedx.core.lib.xblock_utils import (
     replace_static_urls,
     wrap_xblock
 )
-from requests.auth import HTTPBasicAuth
 from student.models import anonymous_id_for_user, user_by_anonymous_id
 from student.roles import CourseBetaTesterRole
 from track import contexts
@@ -61,11 +67,6 @@ from util import milestones_helpers
 from util.json_request import JsonResponse
 from util.model_utils import slugify
 from util.sandboxing import can_execute_unsafe_code, get_python_lib_zip
-from xblock.core import XBlock
-from xblock.django.request import django_to_webob_request, webob_to_django_response
-from xblock.exceptions import NoSuchHandlerError, NoSuchViewError
-from xblock.reference.plugins import FSService
-from xblock.runtime import KvsFieldData
 from xblock_django.user_service import DjangoXBlockUserService
 from xmodule.contentstore.django import contentstore
 from xmodule.error_module import ErrorDescriptor, NonStaffErrorDescriptor
diff --git a/lms/djangoapps/courseware/self_paced_overrides.py b/lms/djangoapps/courseware/self_paced_overrides.py
index 9ca19d6810f50c38a0f5af833ab3af607e45569d..2c8e7b4cac856ba433ea66047688815865476f96 100644
--- a/lms/djangoapps/courseware/self_paced_overrides.py
+++ b/lms/djangoapps/courseware/self_paced_overrides.py
@@ -3,9 +3,10 @@ Field overrides for self-paced courses. This allows overriding due
 dates for each block in the course.
 """
 
-from .field_overrides import FieldOverrideProvider
 from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
 
+from .field_overrides import FieldOverrideProvider
+
 
 class SelfPacedDateOverrideProvider(FieldOverrideProvider):
     """
diff --git a/lms/djangoapps/courseware/tabs.py b/lms/djangoapps/courseware/tabs.py
index 049d6a0aa685d4d506cb72fc4c318a07ec7c08f4..2a6974c52aedee2b934f86bee2c92a462abaf690 100644
--- a/lms/djangoapps/courseware/tabs.py
+++ b/lms/djangoapps/courseware/tabs.py
@@ -3,13 +3,13 @@ This module is essentially a broker to xmodule/tabs.py -- it was originally intr
 perform some LMS-specific tab display gymnastics for the Entrance Exams feature
 """
 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 courseware.access import has_access
 from courseware.entrance_exams import user_can_skip_entrance_exam
 from openedx.core.lib.course_tabs import CourseTabPluginManager
-from openedx.features.course_experience import default_course_url_name
-from openedx.features.course_experience import UNIFIED_COURSE_TAB_FLAG
+from openedx.features.course_experience import UNIFIED_COURSE_TAB_FLAG, default_course_url_name
 from request_cache.middleware import RequestCache
 from student.models import CourseEnrollment
 from xmodule.tabs import CourseTab, CourseTabList, key_checker, link_reverse_func
diff --git a/lms/djangoapps/courseware/tests/factories.py b/lms/djangoapps/courseware/tests/factories.py
index 67bacec960068d6e362e9645c753f37bd67faccd..3a0974e924c15dc95bb40f95b7bc38cd5eb1c7cf 100644
--- a/lms/djangoapps/courseware/tests/factories.py
+++ b/lms/djangoapps/courseware/tests/factories.py
@@ -2,26 +2,28 @@
 # pylint: disable=missing-docstring
 import json
 from functools import partial
+
 import factory
 from factory.django import DjangoModelFactory
+from opaque_keys.edx.locations import SlashSeparatedCourseKey
 
-# Imported to re-export
-from student.tests.factories import UserFactory  # Imported to re-export
-
-from student.tests.factories import UserProfileFactory as StudentUserProfileFactory
-from courseware.models import StudentModule, XModuleUserStateSummaryField
-from courseware.models import XModuleStudentInfoField, XModuleStudentPrefsField
+from courseware.models import (
+    StudentModule,
+    XModuleStudentInfoField,
+    XModuleStudentPrefsField,
+    XModuleUserStateSummaryField
+)
 from student.roles import (
+    CourseBetaTesterRole,
     CourseInstructorRole,
     CourseStaffRole,
-    CourseBetaTesterRole,
     GlobalStaff,
-    OrgStaffRole,
     OrgInstructorRole,
+    OrgStaffRole
 )
-
-from opaque_keys.edx.locations import SlashSeparatedCourseKey
-
+from student.tests.factories import UserProfileFactory as StudentUserProfileFactory
+# Imported to re-export
+from student.tests.factories import UserFactory  # Imported to re-export
 
 # TODO fix this (course_id and location are invalid names as constants, and course_id should really be COURSE_KEY)
 # pylint: disable=invalid-name
diff --git a/lms/djangoapps/courseware/tests/helpers.py b/lms/djangoapps/courseware/tests/helpers.py
index 4c15c6d39b59edb66f0ff8d69e9c4a3a9f3f88aa..a3a968f34f178b25d8639d5f33c9c0f16d34d24b 100644
--- a/lms/djangoapps/courseware/tests/helpers.py
+++ b/lms/djangoapps/courseware/tests/helpers.py
@@ -10,10 +10,7 @@ from django.test import TestCase
 from django.test.client import RequestFactory
 
 from courseware.access import has_access
-from courseware.masquerade import (
-    handle_ajax,
-    setup_masquerade
-)
+from courseware.masquerade import handle_ajax, setup_masquerade
 from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
 from student.models import Registration
 
diff --git a/lms/djangoapps/courseware/tests/test_about.py b/lms/djangoapps/courseware/tests/test_about.py
index 6c33d3a3d4a7f268879b3544547e27ae16ad6901..95e3943e72d517db9cd4f496a14531e63a9f8fd2 100644
--- a/lms/djangoapps/courseware/tests/test_about.py
+++ b/lms/djangoapps/courseware/tests/test_about.py
@@ -2,38 +2,34 @@
 Test the about xblock
 """
 import datetime
-import pytz
 
+import pytz
 from ccx_keys.locator import CCXLocator
 from django.conf import settings
 from django.core.urlresolvers import reverse
 from django.test.utils import override_settings
+from milestones.tests.utils import MilestonesTestCaseMixin
 from mock import patch
 from nose.plugins.attrib import attr
 
 from course_modes.models import CourseMode
-from track.tests import EventTrackingTestCase
-from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_MODULESTORE
-from xmodule.modulestore.tests.utils import TEST_DATA_DIR
-from xmodule.modulestore.xml_importer import import_course_from_xml
-
+from lms.djangoapps.ccx.tests.factories import CcxFactory
+from shoppingcart.models import Order, PaidCourseRegistration
 from student.models import CourseEnrollment
 from student.tests.factories import AdminFactory, CourseEnrollmentAllowedFactory, UserFactory
-from shoppingcart.models import Order, PaidCourseRegistration
+from track.tests import EventTrackingTestCase
+from util.milestones_helpers import get_prerequisite_courses_display, set_prerequisite_courses
 from xmodule.course_module import CATALOG_VISIBILITY_ABOUT, CATALOG_VISIBILITY_NONE
 from xmodule.modulestore.tests.django_utils import (
+    TEST_DATA_MIXED_MODULESTORE,
+    TEST_DATA_SPLIT_MODULESTORE,
     ModuleStoreTestCase,
-    SharedModuleStoreTestCase,
-    TEST_DATA_SPLIT_MODULESTORE
+    SharedModuleStoreTestCase
 )
 from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
-from util.milestones_helpers import (
-    set_prerequisite_courses,
-    get_prerequisite_courses_display,
-)
-from milestones.tests.utils import MilestonesTestCaseMixin
+from xmodule.modulestore.tests.utils import TEST_DATA_DIR
+from xmodule.modulestore.xml_importer import import_course_from_xml
 
-from lms.djangoapps.ccx.tests.factories import CcxFactory
 from .helpers import LoginEnrollmentTestCase
 
 # HTML for registration button
diff --git a/lms/djangoapps/courseware/tests/test_access.py b/lms/djangoapps/courseware/tests/test_access.py
index f509c9f6febc2a35654a9a132696a34b955adf1e..a98d229fbe139901d2412f2a90b0700e36157746 100644
--- a/lms/djangoapps/courseware/tests/test_access.py
+++ b/lms/djangoapps/courseware/tests/test_access.py
@@ -3,31 +3,33 @@
 Test the access control framework
 """
 import datetime
-import ddt
 import itertools
-import pytz
 
-from django.contrib.auth.models import User
+import ddt
+import pytz
 from ccx_keys.locator import CCXLocator
-from django.test.client import RequestFactory
+from django.contrib.auth.models import User
 from django.core.urlresolvers import reverse
 from django.test import TestCase
+from django.test.client import RequestFactory
+from milestones.tests.utils import MilestonesTestCaseMixin
 from mock import Mock, patch
 from nose.plugins.attrib import attr
 from opaque_keys.edx.locations import SlashSeparatedCourseKey
 
-from ccx.tests.factories import CcxFactory
 import courseware.access as access
 import courseware.access_response as access_response
+from ccx.tests.factories import CcxFactory
 from courseware.masquerade import CourseMasquerade
 from courseware.tests.factories import (
     BetaTesterFactory,
     GlobalStaffFactory,
     InstructorFactory,
     StaffFactory,
-    UserFactory,
+    UserFactory
 )
 from courseware.tests.helpers import LoginEnrollmentTestCase, masquerade_as_group_member
+from lms.djangoapps.ccx.models import CustomCourseForEdX
 from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
 from student.models import CourseEnrollment
 from student.roles import CourseCcxCoachRole, CourseStaffRole
@@ -35,34 +37,27 @@ from student.tests.factories import (
     AdminFactory,
     AnonymousUserFactory,
     CourseEnrollmentAllowedFactory,
-    CourseEnrollmentFactory,
+    CourseEnrollmentFactory
 )
-
+from util.milestones_helpers import fulfill_course_milestone, set_prerequisite_courses
 from xmodule.course_module import (
-    CATALOG_VISIBILITY_CATALOG_AND_ABOUT,
     CATALOG_VISIBILITY_ABOUT,
-    CATALOG_VISIBILITY_NONE,
+    CATALOG_VISIBILITY_CATALOG_AND_ABOUT,
+    CATALOG_VISIBILITY_NONE
 )
 from xmodule.error_module import ErrorDescriptor
-from xmodule.partitions.partitions import Group, UserPartition, MINIMUM_STATIC_PARTITION_ID
 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 (
+    TEST_DATA_SPLIT_MODULESTORE,
     ModuleStoreTestCase,
-    SharedModuleStoreTestCase,
-    TEST_DATA_SPLIT_MODULESTORE
+    SharedModuleStoreTestCase
 )
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
 from xmodule.modulestore.xml import CourseLocationManager
+from xmodule.partitions.partitions import MINIMUM_STATIC_PARTITION_ID, Group, UserPartition
 from xmodule.tests import get_test_system
 
-from util.milestones_helpers import (
-    set_prerequisite_courses,
-    fulfill_course_milestone,
-)
-from milestones.tests.utils import MilestonesTestCaseMixin
-
-from lms.djangoapps.ccx.models import CustomCourseForEdX
 
 # pylint: disable=protected-access
 
diff --git a/lms/djangoapps/courseware/tests/test_comprehensive_theming.py b/lms/djangoapps/courseware/tests/test_comprehensive_theming.py
index 475bc337627bcdbd1e6795760a3e5221bd82bc66..f2e4e8137c2324576ce8d9d4fe5023c266e5d3cc 100644
--- a/lms/djangoapps/courseware/tests/test_comprehensive_theming.py
+++ b/lms/djangoapps/courseware/tests/test_comprehensive_theming.py
@@ -1,14 +1,13 @@
 """Tests of comprehensive theming."""
 
 from django.conf import settings
-from django.test import TestCase
-
-from path import path           # pylint: disable=no-name-in-module
 from django.contrib import staticfiles
+from django.test import TestCase
+from path import path  # pylint: disable=no-name-in-module
 
 import edxmako
 from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme
-from openedx.core.lib.tempdir import mkdtemp_clean, create_symlink, delete_symlink
+from openedx.core.lib.tempdir import create_symlink, delete_symlink, mkdtemp_clean
 
 
 class TestComprehensiveTheming(TestCase):
diff --git a/lms/djangoapps/courseware/tests/test_context_processor.py b/lms/djangoapps/courseware/tests/test_context_processor.py
index 73b86a36f7c29227aac1c2a8778562a6dcfd055d..198e89e420593a15a65c358797d13318b498958d 100644
--- a/lms/djangoapps/courseware/tests/test_context_processor.py
+++ b/lms/djangoapps/courseware/tests/test_context_processor.py
@@ -4,11 +4,10 @@ Unit tests for courseware context_processor
 from django.contrib.auth.models import AnonymousUser
 from mock import Mock
 
+from courseware.context_processor import user_timezone_locale_prefs
+from openedx.core.djangoapps.user_api.preferences.api import set_user_preference
 from student.tests.factories import UserFactory
 from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
-from openedx.core.djangoapps.user_api.preferences.api import set_user_preference
-
-from courseware.context_processor import user_timezone_locale_prefs
 
 
 class UserPrefContextProcessorUnitTest(ModuleStoreTestCase):
diff --git a/lms/djangoapps/courseware/tests/test_course_info.py b/lms/djangoapps/courseware/tests/test_course_info.py
index 0bc1bd59b225b258dccb0795b9550952ec6cdadd..4267b785301ba56b849d8e413425bc0c466f5951 100644
--- a/lms/djangoapps/courseware/tests/test_course_info.py
+++ b/lms/djangoapps/courseware/tests/test_course_info.py
@@ -3,33 +3,31 @@
 Test the course_info xblock
 """
 import mock
-from nose.plugins.attrib import attr
-from pyquery import PyQuery as pq
-
 from ccx_keys.locator import CCXLocator
 from django.conf import settings
 from django.core.urlresolvers import reverse
 from django.http import QueryDict
 from django.test.utils import override_settings
+from nose.plugins.attrib import attr
+from pyquery import PyQuery as pq
 
+from lms.djangoapps.ccx.tests.factories import CcxFactory
 from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
+from student.models import CourseEnrollment
+from student.tests.factories import AdminFactory
 from util.date_utils import strftime_localized
 from xmodule.modulestore.tests.django_utils import (
-    ModuleStoreTestCase,
-    SharedModuleStoreTestCase,
+    TEST_DATA_MIXED_MODULESTORE,
     TEST_DATA_SPLIT_MODULESTORE,
-    TEST_DATA_MIXED_MODULESTORE
+    ModuleStoreTestCase,
+    SharedModuleStoreTestCase
 )
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls
 from xmodule.modulestore.tests.utils import TEST_DATA_DIR
 from xmodule.modulestore.xml_importer import import_course_from_xml
-from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls
-from student.models import CourseEnrollment
-from student.tests.factories import AdminFactory
 
 from .helpers import LoginEnrollmentTestCase
 
-from lms.djangoapps.ccx.tests.factories import CcxFactory
-
 
 @attr(shard=1)
 class CourseInfoTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase):
diff --git a/lms/djangoapps/courseware/tests/test_course_survey.py b/lms/djangoapps/courseware/tests/test_course_survey.py
index 6fa02c7d3091970d874de41f032a1097805f5851..7d827b917ecef50b76c436923261cd06d31d53ea 100644
--- a/lms/djangoapps/courseware/tests/test_course_survey.py
+++ b/lms/djangoapps/courseware/tests/test_course_survey.py
@@ -3,18 +3,17 @@ Python tests for the Survey workflows
 """
 
 from collections import OrderedDict
-from nose.plugins.attrib import attr
 from copy import deepcopy
 
-from django.core.urlresolvers import reverse
 from django.contrib.auth.models import User
-
-from survey.models import SurveyForm, SurveyAnswer
+from django.core.urlresolvers import reverse
+from nose.plugins.attrib import attr
 
 from common.test.utils import XssTestMixin
-from xmodule.modulestore.tests.factories import CourseFactory
-from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
 from courseware.tests.helpers import LoginEnrollmentTestCase
+from survey.models import SurveyAnswer, SurveyForm
+from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/courseware/tests/test_courses.py b/lms/djangoapps/courseware/tests/test_courses.py
index ba6f85a9efa68d735ee1c42ea911c4a7be84d32b..a8ccccc8c44ab9184be61c105a6bb5e8606ad056 100644
--- a/lms/djangoapps/courseware/tests/test_courses.py
+++ b/lms/djangoapps/courseware/tests/test_courses.py
@@ -5,41 +5,38 @@ Tests for course access
 import itertools
 
 import ddt
+import mock
 from django.conf import settings
-from django.test.utils import override_settings
 from django.core.urlresolvers import reverse
 from django.test.client import RequestFactory
-import mock
+from django.test.utils import override_settings
 from nose.plugins.attrib import attr
 
 from courseware.courses import (
     get_cms_block_link,
     get_cms_course_link,
-    get_courses,
     get_course_about_section,
     get_course_by_id,
     get_course_info_section,
     get_course_overview_with_access,
     get_course_with_access,
-    get_current_child,
+    get_courses,
+    get_current_child
 )
-from courseware.module_render import get_module_for_descriptor
 from courseware.model_data import FieldDataCache
+from courseware.module_render import get_module_for_descriptor
 from lms.djangoapps.courseware.courseware_access_exception import CoursewareAccessException
 from openedx.core.djangolib.testing.utils import get_mock_request
 from openedx.core.lib.courses import course_image_url
 from student.tests.factories import UserFactory
-from xmodule.modulestore.django import _get_modulestore_branch_setting, modulestore
 from xmodule.modulestore import ModuleStoreEnum
-from xmodule.modulestore.xml_importer import import_course_from_xml
+from xmodule.modulestore.django import _get_modulestore_branch_setting, modulestore
 from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
-from xmodule.modulestore.tests.factories import (
-    CourseFactory, ItemFactory, check_mongo_calls
-)
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls
+from xmodule.modulestore.xml_importer import import_course_from_xml
 from xmodule.tests.xml import factories as xml
 from xmodule.tests.xml import XModuleXmlImportTest
 
-
 CMS_BASE_TEST = 'testcms'
 TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
 
diff --git a/lms/djangoapps/courseware/tests/test_credit_requirements.py b/lms/djangoapps/courseware/tests/test_credit_requirements.py
index 399cb5ab259d0f42cb8b730aa8ba4ef6fc0da983..8d3630a7073d637b0d41f6875c21b4b29dfd2d39 100644
--- a/lms/djangoapps/courseware/tests/test_credit_requirements.py
+++ b/lms/djangoapps/courseware/tests/test_credit_requirements.py
@@ -3,18 +3,16 @@ Tests for credit requirement display on the progress page.
 """
 
 import ddt
-from mock import patch
-
 from django.conf import settings
 from django.core.urlresolvers import reverse
-
-from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
-from xmodule.modulestore.tests.factories import CourseFactory
-from student.tests.factories import UserFactory, CourseEnrollmentFactory
+from mock import patch
 
 from course_modes.models import CourseMode
 from openedx.core.djangoapps.credit import api as credit_api
 from openedx.core.djangoapps.credit.models import CreditCourse
+from student.tests.factories import CourseEnrollmentFactory, UserFactory
+from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory
 
 
 @patch.dict(settings.FEATURES, {"ENABLE_CREDIT_ELIGIBILITY": True})
diff --git a/lms/djangoapps/courseware/tests/test_date_summary.py b/lms/djangoapps/courseware/tests/test_date_summary.py
index f1a6adb48bcbbe22387b762c492ec27dd26566d4..3c4cf314f20b92964966b231245257f604318c04 100644
--- a/lms/djangoapps/courseware/tests/test_date_summary.py
+++ b/lms/djangoapps/courseware/tests/test_date_summary.py
@@ -9,8 +9,8 @@ from nose.plugins.attrib import attr
 from pytz import utc
 
 from commerce.models import CommerceConfiguration
-from course_modes.tests.factories import CourseModeFactory
 from course_modes.models import CourseMode
+from course_modes.tests.factories import CourseModeFactory
 from courseware.courses import get_course_date_blocks
 from courseware.date_summary import (
     CourseEndDate,
@@ -18,15 +18,15 @@ from courseware.date_summary import (
     DateSummary,
     TodaysDate,
     VerificationDeadlineDate,
-    VerifiedUpgradeDeadlineDate,
+    VerifiedUpgradeDeadlineDate
 )
+from lms.djangoapps.verify_student.models import VerificationDeadline
+from lms.djangoapps.verify_student.tests.factories import SoftwareSecurePhotoVerificationFactory
 from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
 from openedx.core.djangoapps.user_api.preferences.api import set_user_preference
 from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag
 from openedx.features.course_experience import UNIFIED_COURSE_TAB_FLAG
 from student.tests.factories import CourseEnrollmentFactory, UserFactory
-from lms.djangoapps.verify_student.models import VerificationDeadline
-from lms.djangoapps.verify_student.tests.factories import SoftwareSecurePhotoVerificationFactory
 from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
 from xmodule.modulestore.tests.factories import CourseFactory
 
diff --git a/lms/djangoapps/courseware/tests/test_discussion_xblock.py b/lms/djangoapps/courseware/tests/test_discussion_xblock.py
index 496affd2637da52b6a327eecdc07515537bd4736..fe31ee655c85a61dd9778918e0cd1b3e1b7d8dc0 100644
--- a/lms/djangoapps/courseware/tests/test_discussion_xblock.py
+++ b/lms/djangoapps/courseware/tests/test_discussion_xblock.py
@@ -6,24 +6,23 @@ tests for functionalities that require django API, and lms specific
 functionalities.
 """
 
+import json
 import uuid
 
 import ddt
-import json
 import mock
-
 from django.core.urlresolvers import reverse
-from course_api.blocks.tests.helpers import deserialize_usage_key
-from courseware.module_render import get_module_for_descriptor_internal
-from student.tests.factories import UserFactory, CourseEnrollmentFactory
 from xblock.field_data import DictFieldData
 from xblock.fragment import Fragment
-from xmodule.modulestore import ModuleStoreEnum
-from xmodule.modulestore.tests.factories import ToyCourseFactory, ItemFactory
-from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
-from lms.djangoapps.courseware.tests import XModuleRenderingTestBase
 
+from course_api.blocks.tests.helpers import deserialize_usage_key
+from courseware.module_render import get_module_for_descriptor_internal
+from lms.djangoapps.courseware.tests import XModuleRenderingTestBase
+from student.tests.factories import CourseEnrollmentFactory, UserFactory
 from xblock_discussion import DiscussionXBlock, loader
+from xmodule.modulestore import ModuleStoreEnum
+from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
+from xmodule.modulestore.tests.factories import ItemFactory, ToyCourseFactory
 
 
 @ddt.ddt
diff --git a/lms/djangoapps/courseware/tests/test_draft_modulestore.py b/lms/djangoapps/courseware/tests/test_draft_modulestore.py
index c5217333e7415bc614aba7e80e029e2e171e26eb..c2985e4057ab8c4689255b283110a333fed9a146 100644
--- a/lms/djangoapps/courseware/tests/test_draft_modulestore.py
+++ b/lms/djangoapps/courseware/tests/test_draft_modulestore.py
@@ -1,8 +1,8 @@
 from django.test import TestCase
 from nose.plugins.attrib import attr
+from opaque_keys.edx.locations import SlashSeparatedCourseKey
 
 from xmodule.modulestore.django import modulestore
-from opaque_keys.edx.locations import SlashSeparatedCourseKey
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/courseware/tests/test_entrance_exam.py b/lms/djangoapps/courseware/tests/test_entrance_exam.py
index bac392115b6fd69b1500db1243cf3cf4885a5d6b..023733db24721de270528212683f5bcfa54ff05c 100644
--- a/lms/djangoapps/courseware/tests/test_entrance_exam.py
+++ b/lms/djangoapps/courseware/tests/test_entrance_exam.py
@@ -1,37 +1,34 @@
 """
 Tests use cases related to LMS Entrance Exam behavior, such as gated content access (TOC)
 """
-from mock import patch, Mock
-
 from django.core.urlresolvers import reverse
 from django.test.client import RequestFactory
+from milestones.tests.utils import MilestonesTestCaseMixin
+from mock import Mock, patch
 from nose.plugins.attrib import attr
 
 from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory
-from courseware.model_data import FieldDataCache
-from courseware.module_render import toc_for_course, get_module, handle_xblock_callback
-from courseware.tests.factories import UserFactory, InstructorFactory, StaffFactory
-from courseware.tests.helpers import (
-    LoginEnrollmentTestCase,
-)
 from courseware.entrance_exams import (
     course_has_entrance_exam,
     get_entrance_exam_content,
     user_can_skip_entrance_exam,
-    user_has_passed_entrance_exam,
+    user_has_passed_entrance_exam
 )
+from courseware.model_data import FieldDataCache
+from courseware.module_render import get_module, handle_xblock_callback, toc_for_course
+from courseware.tests.factories import InstructorFactory, StaffFactory, UserFactory
+from courseware.tests.helpers import LoginEnrollmentTestCase
 from openedx.core.djangolib.testing.utils import get_mock_request
 from student.models import CourseEnrollment
-from student.tests.factories import CourseEnrollmentFactory, AnonymousUserFactory
+from student.tests.factories import AnonymousUserFactory, CourseEnrollmentFactory
 from util.milestones_helpers import (
-    add_milestone,
+    add_course_content_milestone,
     add_course_milestone,
-    get_namespace_choices,
+    add_milestone,
     generate_milestone_namespace,
-    add_course_content_milestone,
     get_milestone_relationship_types,
+    get_namespace_choices
 )
-from milestones.tests.utils import MilestonesTestCaseMixin
 from xmodule.modulestore.django import modulestore
 from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
 from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
diff --git a/lms/djangoapps/courseware/tests/test_favicon.py b/lms/djangoapps/courseware/tests/test_favicon.py
index 7f61acf04e7bdebc8ad4e71c39c25a0ab1da72ca..5152bce4efa12ba7b59516cc92375776723ec4f4 100644
--- a/lms/djangoapps/courseware/tests/test_favicon.py
+++ b/lms/djangoapps/courseware/tests/test_favicon.py
@@ -1,6 +1,5 @@
 from django.test import TestCase
 from django.test.utils import override_settings
-
 from nose.plugins.attrib import attr
 
 from util.testing import UrlResetMixin
diff --git a/lms/djangoapps/courseware/tests/test_field_overrides.py b/lms/djangoapps/courseware/tests/test_field_overrides.py
index 142ed5a4b05db3559714d66dd6e511e5ab0576f1..deb522e01a8b2b2e77f160523e6388c01b47faae 100644
--- a/lms/djangoapps/courseware/tests/test_field_overrides.py
+++ b/lms/djangoapps/courseware/tests/test_field_overrides.py
@@ -3,23 +3,23 @@ Tests for `field_overrides` module.
 """
 # pylint: disable=missing-docstring
 import unittest
-from nose.plugins.attrib import attr
 
 from django.test.utils import override_settings
+from nose.plugins.attrib import attr
 from xblock.field_data import DictFieldData
-from xmodule.modulestore.tests.factories import CourseFactory
+
 from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory
 
 from ..field_overrides import (
-    resolve_dotted,
-    disable_overrides,
     FieldOverrideProvider,
     OverrideFieldData,
     OverrideModulestoreFieldData,
+    disable_overrides,
+    resolve_dotted
 )
 from ..testutils import FieldOverrideTestMixin
 
-
 TESTUSER = "testuser"
 
 
diff --git a/lms/djangoapps/courseware/tests/test_footer.py b/lms/djangoapps/courseware/tests/test_footer.py
index eb9f97f1d75fbd7240763cf05faab2779aa1caff..c655afe8e211b411725dd27575fd1d6857e6182f 100644
--- a/lms/djangoapps/courseware/tests/test_footer.py
+++ b/lms/djangoapps/courseware/tests/test_footer.py
@@ -4,11 +4,11 @@ edx.org uses an edx footer but other instances use an Open edX footer.
 """
 
 import unittest
-from nose.plugins.attrib import attr
 
 from django.conf import settings
 from django.test import TestCase
 from django.test.utils import override_settings
+from nose.plugins.attrib import attr
 
 from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme
 
diff --git a/lms/djangoapps/courseware/tests/test_group_access.py b/lms/djangoapps/courseware/tests/test_group_access.py
index a762e4d88bb581eff129c5658e4f602aa1388d45..725be86703d70bd9830e954158f1819ee1b40d23 100644
--- a/lms/djangoapps/courseware/tests/test_group_access.py
+++ b/lms/djangoapps/courseware/tests/test_group_access.py
@@ -7,13 +7,12 @@ import ddt
 from nose.plugins.attrib import attr
 from stevedore.extension import Extension, ExtensionManager
 
-from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
-from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
-from xmodule.partitions.partitions import Group, UserPartition, USER_PARTITION_SCHEME_NAMESPACE
-from xmodule.modulestore.django import modulestore
-
 import courseware.access as access
 from courseware.tests.factories import StaffFactory, UserFactory
+from xmodule.modulestore.django import modulestore
+from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
+from xmodule.partitions.partitions import USER_PARTITION_SCHEME_NAMESPACE, Group, UserPartition
 
 
 class MemoryUserPartitionScheme(object):
diff --git a/lms/djangoapps/courseware/tests/test_lti_integration.py b/lms/djangoapps/courseware/tests/test_lti_integration.py
index 20c69e0f8a4789eb1a123d04fdd24b8ef53ee425..5e1a6537c611b5ba9a0682ef088f42c89573583a 100644
--- a/lms/djangoapps/courseware/tests/test_lti_integration.py
+++ b/lms/djangoapps/courseware/tests/test_lti_integration.py
@@ -1,14 +1,14 @@
 """LTI integration tests"""
 
-from collections import OrderedDict
 import json
-import mock
-from nose.plugins.attrib import attr
-import oauthlib
 import urllib
+from collections import OrderedDict
 
+import mock
+import oauthlib
 from django.conf import settings
 from django.core.urlresolvers import reverse
+from nose.plugins.attrib import attr
 
 from courseware.tests import BaseTestXmodule
 from courseware.views.views import get_course_lti_endpoints
diff --git a/lms/djangoapps/courseware/tests/test_masquerade.py b/lms/djangoapps/courseware/tests/test_masquerade.py
index 64f175cf0d216d43ffb20c6b28046ba136663edb..9928614a3e355ed355d2dad1404bfe20ee8587a3 100644
--- a/lms/djangoapps/courseware/tests/test_masquerade.py
+++ b/lms/djangoapps/courseware/tests/test_masquerade.py
@@ -3,32 +3,32 @@ Unit tests for masquerade.
 """
 import json
 import pickle
-from mock import patch
-from nose.plugins.attrib import attr
 from datetime import datetime
 
 from django.core.urlresolvers import reverse
 from django.test import TestCase
 from django.utils.timezone import UTC
+from mock import patch
+from nose.plugins.attrib import attr
+from xblock.runtime import DictKeyValueStore
 
 from capa.tests.response_xml_factory import OptionResponseXMLFactory
 from courseware.masquerade import (
     CourseMasquerade,
     MasqueradingKeyValueStore,
+    get_masquerading_user_group,
     handle_ajax,
-    setup_masquerade,
-    get_masquerading_user_group
+    setup_masquerade
 )
 from courseware.tests.factories import StaffFactory
 from courseware.tests.helpers import LoginEnrollmentTestCase, masquerade_as_group_member
 from courseware.tests.test_submitting_problems import ProblemSubmissionTestMixin
+from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
 from student.tests.factories import UserFactory
-from xblock.runtime import DictKeyValueStore
 from xmodule.modulestore.django import modulestore
 from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
-from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
 from xmodule.partitions.partitions import Group, UserPartition
-from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
 
 
 class MasqueradeTestCase(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
diff --git a/lms/djangoapps/courseware/tests/test_microsites.py b/lms/djangoapps/courseware/tests/test_microsites.py
index a9d73aa5abf836b3f846a3302e861f2464362b45..e58acda3cb07f1f38d16e664a957ef714f301997 100644
--- a/lms/djangoapps/courseware/tests/test_microsites.py
+++ b/lms/djangoapps/courseware/tests/test_microsites.py
@@ -6,12 +6,11 @@ from django.core.urlresolvers import reverse
 from django.test.utils import override_settings
 from nose.plugins.attrib import attr
 
-from courseware.tests.helpers import LoginEnrollmentTestCase
 from course_modes.models import CourseMode
-from xmodule.course_module import (
-    CATALOG_VISIBILITY_CATALOG_AND_ABOUT, CATALOG_VISIBILITY_NONE)
-from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
+from courseware.tests.helpers import LoginEnrollmentTestCase
+from xmodule.course_module import CATALOG_VISIBILITY_CATALOG_AND_ABOUT, CATALOG_VISIBILITY_NONE
 from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/courseware/tests/test_middleware.py b/lms/djangoapps/courseware/tests/test_middleware.py
index 78f1c3c97ae0261a526820d41e532687612c1486..addfeb9f3b991b56d7d01bed609c66d1c05b3aea 100644
--- a/lms/djangoapps/courseware/tests/test_middleware.py
+++ b/lms/djangoapps/courseware/tests/test_middleware.py
@@ -2,15 +2,14 @@
 Tests for courseware middleware
 """
 
-from django.test.client import RequestFactory
 from django.http import Http404
+from django.test.client import RequestFactory
 from nose.plugins.attrib import attr
 
-from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
-from xmodule.modulestore.tests.factories import CourseFactory
-
 from lms.djangoapps.courseware.exceptions import Redirect
 from lms.djangoapps.courseware.middleware import RedirectMiddleware
+from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/courseware/tests/test_model_data.py b/lms/djangoapps/courseware/tests/test_model_data.py
index da06e8574942232b5b7dc9dbb9b0b95c47b0580e..14320d95aa026dfbbc565effd530cd7f70ba67b8 100644
--- a/lms/djangoapps/courseware/tests/test_model_data.py
+++ b/lms/djangoapps/courseware/tests/test_model_data.py
@@ -2,24 +2,32 @@
 Test for lms courseware app, module data (runtime data storage for XBlocks)
 """
 import json
+from functools import partial
+
+from django.db import DatabaseError
+from django.test import TestCase
 from mock import Mock, patch
 from nose.plugins.attrib import attr
-from functools import partial
+from xblock.core import XBlock
+from xblock.exceptions import KeyValueMultiSaveError
+from xblock.fields import BlockScope, Scope, ScopeIds
 
 from courseware.model_data import DjangoKeyValueStore, FieldDataCache, InvalidScopeError
-from courseware.models import StudentModule, XModuleUserStateSummaryField
-from courseware.models import XModuleStudentInfoField, XModuleStudentPrefsField
-
+from courseware.models import (
+    StudentModule,
+    XModuleStudentInfoField,
+    XModuleStudentPrefsField,
+    XModuleUserStateSummaryField
+)
+from courseware.tests.factories import StudentModuleFactory as cmfStudentModuleFactory
+from courseware.tests.factories import (
+    StudentInfoFactory,
+    StudentPrefsFactory,
+    UserStateSummaryFactory,
+    course_id,
+    location
+)
 from student.tests.factories import UserFactory
-from courseware.tests.factories import StudentModuleFactory as cmfStudentModuleFactory, location, course_id
-from courseware.tests.factories import UserStateSummaryFactory
-from courseware.tests.factories import StudentPrefsFactory, StudentInfoFactory
-
-from xblock.fields import Scope, BlockScope, ScopeIds
-from xblock.exceptions import KeyValueMultiSaveError
-from xblock.core import XBlock
-from django.test import TestCase
-from django.db import DatabaseError
 
 
 def mock_field(scope, name):
diff --git a/lms/djangoapps/courseware/tests/test_module_render.py b/lms/djangoapps/courseware/tests/test_module_render.py
index 8a75fedf5ba6074f108fd773a99ef513b1bc9f14..e37ef2a3ace26accada818d43240ae8749e322f8 100644
--- a/lms/djangoapps/courseware/tests/test_module_render.py
+++ b/lms/djangoapps/courseware/tests/test_module_render.py
@@ -2,78 +2,67 @@
 """
 Test for lms courseware app, module render unit
 """
-from datetime import datetime
-import ddt
 import itertools
 import json
-from nose.plugins.attrib import attr
+from datetime import datetime
 from functools import partial
 
+import ddt
+import pytz
 from bson import ObjectId
-from django.http import Http404, HttpResponse
-from django.core.urlresolvers import reverse
 from django.conf import settings
+from django.contrib.auth.models import AnonymousUser
+from django.core.urlresolvers import reverse
+from django.http import Http404, HttpResponse
 from django.test.client import RequestFactory
 from django.test.utils import override_settings
-from django.contrib.auth.models import AnonymousUser
+from edx_proctoring.api import create_exam, create_exam_attempt, update_attempt_status
+from edx_proctoring.runtime import set_runtime_service
+from edx_proctoring.tests.test_services import MockCreditService
 from freezegun import freeze_time
-from mock import MagicMock, patch, Mock
-from opaque_keys.edx.keys import UsageKey, CourseKey
+from milestones.tests.utils import MilestonesTestCaseMixin
+from mock import MagicMock, Mock, patch
+from nose.plugins.attrib import attr
+from opaque_keys.edx.keys import CourseKey, UsageKey
 from opaque_keys.edx.locations import SlashSeparatedCourseKey
 from pyquery import PyQuery
-import pytz
+from xblock.core import XBlock, XBlockAside
 from xblock.field_data import FieldData
-from xblock.runtime import Runtime
 from xblock.fields import ScopeIds
-from xblock.core import XBlock, XBlockAside
 from xblock.fragment import Fragment
+from xblock.runtime import Runtime
 
 from capa.tests.response_xml_factory import OptionResponseXMLFactory
 from course_modes.models import CourseMode
 from courseware import module_render as render
-from courseware.courses import get_course_with_access, get_course_info_section
+from courseware.courses import get_course_info_section, get_course_with_access
 from courseware.field_overrides import OverrideFieldData
 from courseware.model_data import FieldDataCache
-from courseware.module_render import hash_resource, get_module_for_descriptor
 from courseware.models import StudentModule
-from courseware.tests.factories import StudentModuleFactory, UserFactory, GlobalStaffFactory
-from courseware.tests.tests import LoginEnrollmentTestCase
+from courseware.module_render import get_module_for_descriptor, hash_resource
+from courseware.tests.factories import GlobalStaffFactory, StudentModuleFactory, UserFactory
 from courseware.tests.test_submitting_problems import TestSubmittingProblems
+from courseware.tests.tests import LoginEnrollmentTestCase
 from lms.djangoapps.lms_xblock.field_data import LmsFieldData
+from openedx.core.djangoapps.credit.api import set_credit_requirement_status, set_credit_requirements
+from openedx.core.djangoapps.credit.models import CreditCourse
 from openedx.core.lib.courses import course_image_url
 from openedx.core.lib.gating import api as gating_api
 from openedx.core.lib.url_utils import quote_slashes
 from student.models import anonymous_id_for_user
-from xmodule.modulestore.tests.django_utils import (
-    ModuleStoreTestCase,
-    SharedModuleStoreTestCase,
-    TEST_DATA_MIXED_MODULESTORE
-)
+from verify_student.tests.factories import SoftwareSecurePhotoVerificationFactory
+from xblock_django.models import XBlockConfiguration
 from xmodule.lti_module import LTIDescriptor
 from xmodule.modulestore import ModuleStoreEnum
 from xmodule.modulestore.django import modulestore
-from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory, ToyCourseFactory, check_mongo_calls
-from xmodule.modulestore.tests.test_asides import AsideTestType
-from xmodule.x_module import XModuleDescriptor, XModule, STUDENT_VIEW, CombinedSystem
-
-from openedx.core.djangoapps.credit.models import CreditCourse
-from openedx.core.djangoapps.credit.api import (
-    set_credit_requirements,
-    set_credit_requirement_status
-)
-from xblock_django.models import XBlockConfiguration
-
-from edx_proctoring.api import (
-    create_exam,
-    create_exam_attempt,
-    update_attempt_status
+from xmodule.modulestore.tests.django_utils import (
+    TEST_DATA_MIXED_MODULESTORE,
+    ModuleStoreTestCase,
+    SharedModuleStoreTestCase
 )
-from edx_proctoring.runtime import set_runtime_service
-from edx_proctoring.tests.test_services import MockCreditService
-from verify_student.tests.factories import SoftwareSecurePhotoVerificationFactory
-
-from milestones.tests.utils import MilestonesTestCaseMixin
-
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, ToyCourseFactory, check_mongo_calls
+from xmodule.modulestore.tests.test_asides import AsideTestType
+from xmodule.x_module import STUDENT_VIEW, CombinedSystem, XModule, XModuleDescriptor
 
 TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
 
diff --git a/lms/djangoapps/courseware/tests/test_navigation.py b/lms/djangoapps/courseware/tests/test_navigation.py
index 4be076b55d20144071b4bad81d351ce952104918..dd087a53c79d55b806efaae29135008eec1f1cf2 100644
--- a/lms/djangoapps/courseware/tests/test_navigation.py
+++ b/lms/djangoapps/courseware/tests/test_navigation.py
@@ -2,19 +2,19 @@
 This test file will run through some LMS test scenarios regarding access and navigation of the LMS
 """
 import time
-from mock import patch
-from nose.plugins.attrib import attr
 
 from django.conf import settings
 from django.core.urlresolvers import reverse
 from django.test.utils import override_settings
+from mock import patch
+from nose.plugins.attrib import attr
 
-from courseware.tests.helpers import LoginEnrollmentTestCase
 from courseware.tests.factories import GlobalStaffFactory
+from courseware.tests.helpers import LoginEnrollmentTestCase
 from student.tests.factories import UserFactory
+from xmodule.modulestore.django import modulestore
 from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
 from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
-from xmodule.modulestore.django import modulestore
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/courseware/tests/test_password_history.py b/lms/djangoapps/courseware/tests/test_password_history.py
index 0f9a26eb77bcffef5717ef899c72e907df523653..af8379ae59a814993e2b681941f805125b197797 100644
--- a/lms/djangoapps/courseware/tests/test_password_history.py
+++ b/lms/djangoapps/courseware/tests/test_password_history.py
@@ -2,24 +2,22 @@
 This file will test through the LMS some of the PasswordHistory features
 """
 import json
-import ddt
-from mock import patch
+from datetime import timedelta
 from uuid import uuid4
-from nose.plugins.attrib import attr
 
+import ddt
 from django.contrib.auth.models import User
-from django.utils import timezone
-from datetime import timedelta
-from django.test.utils import override_settings
-
-from django.core.urlresolvers import reverse
 from django.contrib.auth.tokens import default_token_generator
+from django.core.urlresolvers import reverse
+from django.test.utils import override_settings
+from django.utils import timezone
 from django.utils.http import int_to_base36
-
 from freezegun import freeze_time
+from mock import patch
+from nose.plugins.attrib import attr
 
-from student.models import PasswordHistory
 from courseware.tests.helpers import LoginEnrollmentTestCase
+from student.models import PasswordHistory
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/courseware/tests/test_self_paced_overrides.py b/lms/djangoapps/courseware/tests/test_self_paced_overrides.py
index b2e166fb3d1db6328237f5e2bb02271e9db02c34..47490b9c61f2607b9f2714203689c8d33ef5c411 100644
--- a/lms/djangoapps/courseware/tests/test_self_paced_overrides.py
+++ b/lms/djangoapps/courseware/tests/test_self_paced_overrides.py
@@ -1,16 +1,16 @@
 """Tests for self-paced course due date overrides."""
 # pylint: disable=missing-docstring
 import datetime
-import pytz
 
+import pytz
 from django.test.utils import override_settings
 from mock import patch
 
-from courseware.tests.factories import BetaTesterFactory
 from courseware.access import has_access
+from courseware.tests.factories import BetaTesterFactory
 from lms.djangoapps.ccx.tests.test_overrides import inject_field_overrides
-from lms.djangoapps.django_comment_client.utils import get_accessible_discussion_xblocks
 from lms.djangoapps.courseware.field_overrides import OverrideFieldData, OverrideModulestoreFieldData
+from lms.djangoapps.django_comment_client.utils import get_accessible_discussion_xblocks
 from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
 from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
 from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
diff --git a/lms/djangoapps/courseware/tests/test_split_module.py b/lms/djangoapps/courseware/tests/test_split_module.py
index c7aa323170dbb9b905650949a231a8c6c500d2d4..3413ddd3f97bd9fac050ab0711db19c60ddb6b03 100644
--- a/lms/djangoapps/courseware/tests/test_split_module.py
+++ b/lms/djangoapps/courseware/tests/test_split_module.py
@@ -5,13 +5,13 @@ from django.core.urlresolvers import reverse
 from mock import MagicMock
 from nose.plugins.attrib import attr
 
-from courseware.module_render import get_module_for_descriptor
 from courseware.model_data import FieldDataCache
-from student.tests.factories import UserFactory, CourseEnrollmentFactory
-from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory
+from courseware.module_render import get_module_for_descriptor
+from openedx.core.djangoapps.user_api.tests.factories import UserCourseTagFactory
+from student.tests.factories import CourseEnrollmentFactory, UserFactory
 from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
 from xmodule.partitions.partitions import Group, UserPartition
-from openedx.core.djangoapps.user_api.tests.factories import UserCourseTagFactory
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/courseware/tests/test_submitting_problems.py b/lms/djangoapps/courseware/tests/test_submitting_problems.py
index 2532e67d5515d2c4202a91fd34f31af6b9a44675..db3ab50bf2fe8632f4bd8dd9d4535fd6cd0879bc 100644
--- a/lms/djangoapps/courseware/tests/test_submitting_problems.py
+++ b/lms/djangoapps/courseware/tests/test_submitting_problems.py
@@ -20,20 +20,20 @@ from mock import patch
 from nose.plugins.attrib import attr
 
 from capa.tests.response_xml_factory import (
-    OptionResponseXMLFactory, CustomResponseXMLFactory, SchematicResponseXMLFactory,
     CodeResponseXMLFactory,
+    CustomResponseXMLFactory,
+    OptionResponseXMLFactory,
+    SchematicResponseXMLFactory
 )
 from course_modes.models import CourseMode
-from courseware.models import StudentModule, BaseStudentModuleHistory
+from courseware.models import BaseStudentModuleHistory, StudentModule
 from courseware.tests.helpers import LoginEnrollmentTestCase
 from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory
-from openedx.core.djangoapps.credit.api import (
-    set_credit_requirements, get_credit_requirement_status
-)
+from openedx.core.djangoapps.credit.api import get_credit_requirement_status, set_credit_requirements
 from openedx.core.djangoapps.credit.models import CreditCourse, CreditProvider
 from openedx.core.djangoapps.user_api.tests.factories import UserCourseTagFactory
 from openedx.core.lib.url_utils import quote_slashes
-from student.models import anonymous_id_for_user, CourseEnrollment
+from student.models import CourseEnrollment, anonymous_id_for_user
 from submissions import api as submissions_api
 from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
 from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
diff --git a/lms/djangoapps/courseware/tests/test_tabs.py b/lms/djangoapps/courseware/tests/test_tabs.py
index 28a33222f51de6c919fd72c4eb1da4e6556ba819..fced69faa4764071d08e7209ad17540d86303e86 100644
--- a/lms/djangoapps/courseware/tests/test_tabs.py
+++ b/lms/djangoapps/courseware/tests/test_tabs.py
@@ -4,34 +4,39 @@ Test cases for tabs.
 
 from django.core.urlresolvers import reverse
 from django.http import Http404
+from milestones.tests.utils import MilestonesTestCaseMixin
 from mock import MagicMock, Mock, patch
 from nose.plugins.attrib import attr
+from waffle.testutils import override_flag
 
 from courseware.courses import get_course_by_id
 from courseware.tabs import (
-    get_course_tab_list, CoursewareTab, CourseInfoTab, ProgressTab,
-    ExternalDiscussionCourseTab, ExternalLinkCourseTab
+    CourseInfoTab,
+    CoursewareTab,
+    ExternalDiscussionCourseTab,
+    ExternalLinkCourseTab,
+    ProgressTab,
+    get_course_tab_list
 )
-from courseware.tests.helpers import LoginEnrollmentTestCase
 from courseware.tests.factories import InstructorFactory, StaffFactory
-from courseware.views.views import get_static_tab_fragment, StaticCourseTabView
-from openedx.core.djangolib.testing.utils import get_mock_request
+from courseware.tests.helpers import LoginEnrollmentTestCase
+from courseware.views.views import StaticCourseTabView, get_static_tab_fragment
 from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag
+from openedx.core.djangolib.testing.utils import get_mock_request
 from openedx.features.course_experience import UNIFIED_COURSE_TAB_FLAG
 from student.models import CourseEnrollment
 from student.tests.factories import UserFactory
 from util.milestones_helpers import (
-    get_milestone_relationship_types,
-    add_milestone,
+    add_course_content_milestone,
     add_course_milestone,
-    add_course_content_milestone
+    add_milestone,
+    get_milestone_relationship_types
 )
-from milestones.tests.utils import MilestonesTestCaseMixin
 from xmodule import tabs as xmodule_tabs
 from xmodule.modulestore.tests.django_utils import (
+    TEST_DATA_MIXED_MODULESTORE,
     ModuleStoreTestCase,
-    SharedModuleStoreTestCase,
-    TEST_DATA_MIXED_MODULESTORE
+    SharedModuleStoreTestCase
 )
 from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
 from xmodule.modulestore.tests.utils import TEST_DATA_DIR
diff --git a/lms/djangoapps/courseware/tests/test_user_state_client.py b/lms/djangoapps/courseware/tests/test_user_state_client.py
index 143bd7f644c477388f2e6181b72885bbfa152614..4891840a138eee0a5c0cafa63f8aee654051b490 100644
--- a/lms/djangoapps/courseware/tests/test_user_state_client.py
+++ b/lms/djangoapps/courseware/tests/test_user_state_client.py
@@ -7,10 +7,10 @@ from collections import defaultdict
 from unittest import skip
 
 from django.test import TestCase
-
 from edx_user_state_client.tests import UserStateClientTestBase
-from courseware.user_state_client import DjangoXBlockUserStateClient
+
 from courseware.tests.factories import UserFactory
+from courseware.user_state_client import DjangoXBlockUserStateClient
 
 
 class TestDjangoUserStateClient(UserStateClientTestBase, TestCase):
diff --git a/lms/djangoapps/courseware/tests/test_video_handlers.py b/lms/djangoapps/courseware/tests/test_video_handlers.py
index 63eb6ab23c078699455b089fd141b22a41f1d5ee..df37776e55c40db354020ce593967ec1cefd0218 100644
--- a/lms/djangoapps/courseware/tests/test_video_handlers.py
+++ b/lms/djangoapps/courseware/tests/test_video_handlers.py
@@ -1,14 +1,14 @@
 # -*- coding: utf-8 -*-
 """Video xmodule tests in mongo."""
 
+import json
 import os
-import freezegun
 import tempfile
 import textwrap
-import json
-import ddt
+from datetime import datetime, timedelta
 
-from datetime import timedelta, datetime
+import ddt
+import freezegun
 from mock import MagicMock, Mock, patch
 from nose.plugins.attrib import attr
 from webob import Request
@@ -16,14 +16,11 @@ from webob import Request
 from openedx.core.djangoapps.contentserver.caching import del_cached_content
 from xmodule.contentstore.content import StaticContent
 from xmodule.contentstore.django import contentstore
-from xmodule.modulestore.django import modulestore
+from xmodule.exceptions import NotFoundError
 from xmodule.modulestore import ModuleStoreEnum
+from xmodule.modulestore.django import modulestore
+from xmodule.video_module.transcripts_utils import TranscriptException, TranscriptsGenerationException
 from xmodule.x_module import STUDENT_VIEW
-from xmodule.exceptions import NotFoundError
-from xmodule.video_module.transcripts_utils import (
-    TranscriptException,
-    TranscriptsGenerationException,
-)
 
 from . import BaseTestXmodule
 from .test_video_xml import SOURCE_XML
diff --git a/lms/djangoapps/courseware/tests/test_video_mongo.py b/lms/djangoapps/courseware/tests/test_video_mongo.py
index a56278deefaa35d294ade693de8d2ca30761fcd0..0cbc036bf6a7c1e83b9696024154c81e66da9bd5 100644
--- a/lms/djangoapps/courseware/tests/test_video_mongo.py
+++ b/lms/djangoapps/courseware/tests/test_video_mongo.py
@@ -1,38 +1,33 @@
 # -*- coding: utf-8 -*-
 """Video xmodule tests in mongo."""
 
-import ddt
 import json
 from collections import OrderedDict
-from path import Path as path
-
-from lxml import etree
-from mock import patch, MagicMock, Mock
-from nose.plugins.attrib import attr
 from uuid import uuid4
 
+import ddt
 from django.conf import settings
 from django.test import TestCase
 from django.test.utils import override_settings
+from edxval.api import ValCannotCreateError, ValVideoNotFoundError, create_profile, create_video, get_video_info
+from lxml import etree
+from mock import MagicMock, Mock, patch
+from nose.plugins.attrib import attr
+from path import Path as path
 
-from xmodule.video_module import VideoDescriptor, bumper_utils, video_utils, rewrite_video_url
-from xmodule.x_module import STUDENT_VIEW
-from xmodule.tests.test_video import VideoDescriptorTestBase, instantiate_descriptor
-from xmodule.tests.test_import import DummySystem
-from xmodule.video_module.transcripts_utils import save_to_store, Transcript
-from xmodule.modulestore.inheritance import own_metadata
 from xmodule.contentstore.content import StaticContent
 from xmodule.exceptions import NotFoundError
-from xmodule.modulestore.tests.django_utils import (
-    TEST_DATA_MONGO_MODULESTORE, TEST_DATA_SPLIT_MODULESTORE
-)
-from edxval.api import (
-    create_profile, create_video, get_video_info, ValCannotCreateError, ValVideoNotFoundError
-)
+from xmodule.modulestore.inheritance import own_metadata
+from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_MODULESTORE, TEST_DATA_SPLIT_MODULESTORE
+from xmodule.tests.test_import import DummySystem
+from xmodule.tests.test_video import VideoDescriptorTestBase, instantiate_descriptor
+from xmodule.video_module import VideoDescriptor, bumper_utils, rewrite_video_url, video_utils
+from xmodule.video_module.transcripts_utils import Transcript, save_to_store
+from xmodule.x_module import STUDENT_VIEW
 
 from . import BaseTestXmodule
-from .test_video_xml import SOURCE_XML
 from .test_video_handlers import TestVideo
+from .test_video_xml import SOURCE_XML
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/courseware/tests/test_video_xml.py b/lms/djangoapps/courseware/tests/test_video_xml.py
index bc65d5935e6bbc1eadbdf76985bbdeadb50afeb8..6c789f8672773430c3f0108dd0998e25271ceead 100644
--- a/lms/djangoapps/courseware/tests/test_video_xml.py
+++ b/lms/djangoapps/courseware/tests/test_video_xml.py
@@ -16,8 +16,8 @@ course, section, subsection, unit, etc.
 """
 from nose.plugins.attrib import attr
 
-from xmodule.video_module import VideoDescriptor
 from xmodule.tests import LogicTest
+from xmodule.video_module import VideoDescriptor
 
 
 SOURCE_XML = """
diff --git a/lms/djangoapps/courseware/tests/test_view_authentication.py b/lms/djangoapps/courseware/tests/test_view_authentication.py
index 0b3d644b63b976c867ffbd58cc5b891abf176d54..7fffc8bd68448efeabe0bde776dcb84c74c33be0 100644
--- a/lms/djangoapps/courseware/tests/test_view_authentication.py
+++ b/lms/djangoapps/courseware/tests/test_view_authentication.py
@@ -1,24 +1,24 @@
 import datetime
-import pytz
 
+import pytz
 from django.core.urlresolvers import reverse
 from mock import patch
 from nose.plugins.attrib import attr
 
 from courseware.access import has_access
-from courseware.tests.helpers import CourseAccessTestMixin, LoginEnrollmentTestCase
 from courseware.tests.factories import (
     BetaTesterFactory,
-    StaffFactory,
     GlobalStaffFactory,
     InstructorFactory,
-    OrgStaffFactory,
     OrgInstructorFactory,
+    OrgStaffFactory,
+    StaffFactory
 )
+from courseware.tests.helpers import CourseAccessTestMixin, LoginEnrollmentTestCase
+from student.tests.factories import CourseEnrollmentFactory, UserFactory
 from xmodule.modulestore.django import modulestore
 from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
 from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
-from student.tests.factories import UserFactory, CourseEnrollmentFactory
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py
index 1f9b1e7f358dde6ed6898d0efe627b5eddfcaa6d..f186277f7148dcb1cfa4453df1092f2bfecb1d42 100644
--- a/lms/djangoapps/courseware/tests/test_views.py
+++ b/lms/djangoapps/courseware/tests/test_views.py
@@ -10,8 +10,26 @@ from HTMLParser import HTMLParser
 from urllib import quote, urlencode
 from uuid import uuid4
 
-import courseware.views.views as views
 import ddt
+from django.conf import settings
+from django.contrib.auth.models import AnonymousUser
+from django.core.urlresolvers import reverse
+from django.http import Http404, HttpResponseBadRequest
+from django.test import TestCase
+from django.test.client import Client, RequestFactory
+from django.test.utils import override_settings
+from freezegun import freeze_time
+from milestones.tests.utils import MilestonesTestCaseMixin
+from mock import MagicMock, PropertyMock, create_autospec, patch
+from nose.plugins.attrib import attr
+from opaque_keys.edx.locations import Location, SlashSeparatedCourseKey
+from pytz import UTC
+from waffle.testutils import override_flag
+from xblock.core import XBlock
+from xblock.fields import Scope, String
+from xblock.fragment import Fragment
+
+import courseware.views.views as views
 import shoppingcart
 from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory
 from certificates import api as certs_api
@@ -27,21 +45,9 @@ from courseware.tests.factories import GlobalStaffFactory, StudentModuleFactory
 from courseware.testutils import RenderXBlockTestMixin
 from courseware.url_helpers import get_redirect_url
 from courseware.user_state_client import DjangoXBlockUserStateClient
-from django.conf import settings
-from django.contrib.auth.models import AnonymousUser
-from django.core.urlresolvers import reverse
-from django.http import Http404, HttpResponseBadRequest
-from django.test import TestCase
-from django.test.client import Client, RequestFactory
-from django.test.utils import override_settings
-from freezegun import freeze_time
 from lms.djangoapps.commerce.utils import EcommerceService  # pylint: disable=import-error
 from lms.djangoapps.grades.config.waffle import waffle as grades_waffle
 from lms.djangoapps.grades.config.waffle import ASSUME_ZERO_GRADE_IF_ABSENT
-from milestones.tests.utils import MilestonesTestCaseMixin
-from mock import MagicMock, PropertyMock, create_autospec, patch
-from nose.plugins.attrib import attr
-from opaque_keys.edx.locations import Location, SlashSeparatedCourseKey
 from openedx.core.djangoapps.catalog.tests.factories import CourseFactory as CatalogCourseFactory
 from openedx.core.djangoapps.catalog.tests.factories import CourseRunFactory, ProgramFactory
 from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
@@ -52,16 +58,11 @@ from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
 from openedx.core.djangolib.testing.utils import get_mock_request
 from openedx.core.lib.gating import api as gating_api
 from openedx.features.enterprise_support.tests.mixins.enterprise import EnterpriseTestConsentRequired
-from pytz import UTC
 from student.models import CourseEnrollment
 from student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory
 from util.tests.test_date_utils import fake_pgettext, fake_ugettext
 from util.url import reload_django_url_config
 from util.views import ensure_valid_course_key
-from waffle.testutils import override_flag
-from xblock.core import XBlock
-from xblock.fields import Scope, String
-from xblock.fragment import Fragment
 from xmodule.graders import ShowCorrectness
 from xmodule.modulestore import ModuleStoreEnum
 from xmodule.modulestore.django import modulestore
diff --git a/lms/djangoapps/courseware/tests/test_word_cloud.py b/lms/djangoapps/courseware/tests/test_word_cloud.py
index 690a8d010ccbba1cd40f1131ce8c946f540b017e..7f799c817f2bab287c63e7015186bba0361c6e2b 100644
--- a/lms/djangoapps/courseware/tests/test_word_cloud.py
+++ b/lms/djangoapps/courseware/tests/test_word_cloud.py
@@ -3,11 +3,13 @@
 
 import json
 from operator import itemgetter
+
 from nose.plugins.attrib import attr
 
-from . import BaseTestXmodule
 from xmodule.x_module import STUDENT_VIEW
 
+from . import BaseTestXmodule
+
 
 @attr(shard=1)
 class TestWordCloud(BaseTestXmodule):
diff --git a/lms/djangoapps/courseware/tests/tests.py b/lms/djangoapps/courseware/tests/tests.py
index 6d7727decb5a9ee7f5711dd2274b626ee31af429..cd964dab147aa237d2335c94c598755a1de51405 100644
--- a/lms/djangoapps/courseware/tests/tests.py
+++ b/lms/djangoapps/courseware/tests/tests.py
@@ -4,8 +4,8 @@ Test for LMS courseware app.
 from textwrap import dedent
 from unittest import TestCase
 
-from django.core.urlresolvers import reverse
 import mock
+from django.core.urlresolvers import reverse
 from nose.plugins.attrib import attr
 from opaque_keys.edx.locations import SlashSeparatedCourseKey
 
@@ -13,9 +13,7 @@ from courseware.tests.helpers import LoginEnrollmentTestCase
 from lms.djangoapps.lms_xblock.field_data import LmsFieldData
 from xmodule.error_module import ErrorDescriptor
 from xmodule.modulestore.django import modulestore
-from xmodule.modulestore.tests.django_utils import (
-    ModuleStoreTestCase, TEST_DATA_MIXED_MODULESTORE
-)
+from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_MODULESTORE, ModuleStoreTestCase
 from xmodule.modulestore.tests.factories import ToyCourseFactory
 
 
diff --git a/lms/djangoapps/courseware/testutils.py b/lms/djangoapps/courseware/testutils.py
index 5ae9047ffa33f7db910733f211ab76116534408c..91ba8d813a8505fd736734c0a56bced8e0d2cb32 100644
--- a/lms/djangoapps/courseware/testutils.py
+++ b/lms/djangoapps/courseware/testutils.py
@@ -5,13 +5,14 @@ Common test utilities for courseware functionality
 
 from abc import ABCMeta, abstractmethod
 from datetime import datetime, timedelta
+from urllib import urlencode
+
 import ddt
 from mock import patch
-from urllib import urlencode
 
 from lms.djangoapps.courseware.field_overrides import OverrideModulestoreFieldData
 from lms.djangoapps.courseware.url_helpers import get_redirect_url
-from student.tests.factories import AdminFactory, UserFactory, CourseEnrollmentFactory
+from student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory
 from xmodule.modulestore import ModuleStoreEnum
 from xmodule.modulestore.django import modulestore
 from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls
diff --git a/lms/djangoapps/courseware/url_helpers.py b/lms/djangoapps/courseware/url_helpers.py
index b4da0a59de64ee2ae632d530a29e99b2252fd7e9..25ac8e49153430ed1ece6ac6e55e198bebf1da41 100644
--- a/lms/djangoapps/courseware/url_helpers.py
+++ b/lms/djangoapps/courseware/url_helpers.py
@@ -5,8 +5,8 @@ from urllib import urlencode
 
 from django.core.urlresolvers import reverse
 
-from xmodule.modulestore.search import path_to_location, navigation_index
 from xmodule.modulestore.django import modulestore
+from xmodule.modulestore.search import navigation_index, path_to_location
 
 
 def get_redirect_url(course_key, usage_key):
diff --git a/lms/djangoapps/courseware/user_state_client.py b/lms/djangoapps/courseware/user_state_client.py
index ac316b876f872ea43fccb00bf32547677355f0a5..02316fec3445dfbb772e0c9e0fe12f0ff8974131 100644
--- a/lms/djangoapps/courseware/user_state_client.py
+++ b/lms/djangoapps/courseware/user_state_client.py
@@ -4,23 +4,26 @@ data in a Django ORM model.
 """
 
 import itertools
+import logging
 from operator import attrgetter
 from time import time
-import logging
-try:
-    import simplejson as json
-except ImportError:
-    import json
 
-import dogstats_wrapper as dog_stats_api
 from django.contrib.auth.models import User
 from django.db import transaction
 from django.db.utils import IntegrityError
+from edx_user_state_client.interface import XBlockUserState, XBlockUserStateClient
 from xblock.fields import Scope
-from courseware.models import StudentModule, BaseStudentModuleHistory
-from edx_user_state_client.interface import XBlockUserStateClient, XBlockUserState
+
+import dogstats_wrapper as dog_stats_api
+from courseware.models import BaseStudentModuleHistory, StudentModule
 from openedx.core.djangoapps import monitoring_utils
 
+try:
+    import simplejson as json
+except ImportError:
+    import json
+
+
 log = logging.getLogger(__name__)
 
 
diff --git a/lms/djangoapps/courseware/views/index.py b/lms/djangoapps/courseware/views/index.py
index 46878cf66ed9e658e07f72452ad9289e225e29e7..caf52a57f24984b5bbebfc205245fa3b63739aa7 100644
--- a/lms/djangoapps/courseware/views/index.py
+++ b/lms/djangoapps/courseware/views/index.py
@@ -1,65 +1,65 @@
 """
 View for Courseware Index
 """
+import logging
+import urllib
 # pylint: disable=attribute-defined-outside-init
 from datetime import datetime
+
+import waffle
 from django.conf import settings
 from django.contrib.auth.decorators import login_required
 from django.contrib.auth.models import User
 from django.core.context_processors import csrf
 from django.core.urlresolvers import reverse
 from django.http import Http404
+from django.shortcuts import redirect
 from django.utils.decorators import method_decorator
 from django.utils.timezone import UTC
 from django.views.decorators.cache import cache_control
 from django.views.decorators.csrf import ensure_csrf_cookie
 from django.views.generic import View
-from django.shortcuts import redirect
+from opaque_keys.edx.keys import CourseKey
+from web_fragments.fragment import Fragment
 
 from edxmako.shortcuts import render_to_response, render_to_string
-import logging
-
-log = logging.getLogger("edx.courseware.views.index")
-
-import urllib
-import waffle
-
 from lms.djangoapps.courseware.exceptions import CourseAccessRedirect
 from lms.djangoapps.gating.api import get_entrance_exam_score_ratio, get_entrance_exam_usage_key
 from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory
-from opaque_keys.edx.keys import CourseKey
-from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY
-from openedx.core.djangoapps.user_api.preferences.api import get_user_preference
 from openedx.core.djangoapps.crawlers.models import CrawlersConfig
+from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY
 from openedx.core.djangoapps.monitoring_utils import set_custom_metrics_for_course_key
+from openedx.core.djangoapps.user_api.preferences.api import get_user_preference
 from openedx.core.djangoapps.waffle_utils import WaffleSwitchNamespace
-from openedx.features.enterprise_support.api import data_sharing_consent_required
 from openedx.features.course_experience import UNIFIED_COURSE_VIEW_FLAG, default_course_url_name
+from openedx.features.enterprise_support.api import data_sharing_consent_required
 from request_cache.middleware import RequestCache
 from shoppingcart.models import CourseRegistrationCode
 from student.views import is_course_blocked
 from util.views import ensure_valid_course_key
 from xmodule.modulestore.django import modulestore
 from xmodule.x_module import STUDENT_VIEW
-from web_fragments.fragment import Fragment
 
 from ..access import has_access
 from ..access_utils import in_preview_mode, is_course_open_for_learner
-from ..courses import get_current_child, get_studio_url, get_course_with_access
+from ..courses import get_course_with_access, get_current_child, get_studio_url
 from ..entrance_exams import (
     course_has_entrance_exam,
     get_entrance_exam_content,
-    user_has_passed_entrance_exam,
     user_can_skip_entrance_exam,
+    user_has_passed_entrance_exam
 )
 from ..masquerade import setup_masquerade
 from ..model_data import FieldDataCache
-from ..module_render import toc_for_course, get_module_for_descriptor
+from ..module_render import get_module_for_descriptor, toc_for_course
 from .views import (
-    CourseTabView, check_access_to_course, check_and_get_upgrade_link,
+    CourseTabView,
+    check_access_to_course,
+    check_and_get_upgrade_link,
     get_cosmetic_verified_display_price
 )
 
+log = logging.getLogger("edx.courseware.views.index")
 
 TEMPLATE_IMPORTS = {'urllib': urllib}
 CONTENT_DEPTH = 2
diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py
index 784bec22b3b20dddf745e773d36630d1a8283cfd..4903b2b4f3ac61adacc0ce169f62c3989b2e1af8 100644
--- a/lms/djangoapps/courseware/views/views.py
+++ b/lms/djangoapps/courseware/views/views.py
@@ -85,11 +85,7 @@ from openedx.core.djangoapps.plugin_api.views import EdxFragmentView
 from openedx.core.djangoapps.programs.utils import ProgramMarketingDataExtender
 from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
 from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
-from openedx.features.course_experience import (
-    UNIFIED_COURSE_TAB_FLAG,
-    UNIFIED_COURSE_VIEW_FLAG,
-    course_home_url_name,
-)
+from openedx.features.course_experience import UNIFIED_COURSE_TAB_FLAG, UNIFIED_COURSE_VIEW_FLAG, course_home_url_name
 from openedx.features.course_experience.views.course_dates import CourseDatesFragmentView
 from openedx.features.enterprise_support.api import data_sharing_consent_required
 from shoppingcart.utils import is_shopping_cart_enabled
diff --git a/lms/djangoapps/coursewarehistoryextended/models.py b/lms/djangoapps/coursewarehistoryextended/models.py
index dc99c1f533256a90b2ebc8f20d09290a91808afb..2d6b2c04966c87d81dde51f45567b690fcc9029d 100644
--- a/lms/djangoapps/coursewarehistoryextended/models.py
+++ b/lms/djangoapps/coursewarehistoryextended/models.py
@@ -13,11 +13,11 @@ ASSUMPTIONS: modules have unique IDs, even across different module_types
 
 """
 from django.db import models
-from django.db.models.signals import post_save, post_delete
+from django.db.models.signals import post_delete, post_save
 from django.dispatch import receiver
 
+from courseware.models import BaseStudentModuleHistory, StudentModule
 from coursewarehistoryextended.fields import UnsignedBigIntAutoField
-from courseware.models import StudentModule, BaseStudentModuleHistory
 
 
 class StudentModuleHistoryExtended(BaseStudentModuleHistory):
diff --git a/lms/djangoapps/coursewarehistoryextended/tests.py b/lms/djangoapps/coursewarehistoryextended/tests.py
index 114c23794f21c4a3ed08bf49734c1eebacd87940..93b8e88de5de5d89785b6a40d4a7902e6b80e6a2 100644
--- a/lms/djangoapps/coursewarehistoryextended/tests.py
+++ b/lms/djangoapps/coursewarehistoryextended/tests.py
@@ -6,15 +6,15 @@ backend tables.
 """
 
 import json
-from mock import patch
-from django.test import TestCase
-from django.conf import settings
 from unittest import skipUnless
-from nose.plugins.attrib import attr
 
-from courseware.models import BaseStudentModuleHistory, StudentModuleHistory, StudentModule
+from django.conf import settings
+from django.test import TestCase
+from mock import patch
+from nose.plugins.attrib import attr
 
-from courseware.tests.factories import StudentModuleFactory, location, course_id
+from courseware.models import BaseStudentModuleHistory, StudentModule, StudentModuleHistory
+from courseware.tests.factories import StudentModuleFactory, course_id, location
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/dashboard/git_import.py b/lms/djangoapps/dashboard/git_import.py
index 38226af5dac3b1fe5ad3765efb26ed7f464283ae..283f40821a60a5f02b92e24dac7c1c8b897ee1ea 100644
--- a/lms/djangoapps/dashboard/git_import.py
+++ b/lms/djangoapps/dashboard/git_import.py
@@ -3,24 +3,24 @@ Provides a function for importing a git repository into the lms
 instance when using a mongo modulestore
 """
 
+import logging
 import os
 import re
 import StringIO
 import subprocess
-import logging
 
+import mongoengine
 from django.conf import settings
 from django.core import management
 from django.core.management.base import CommandError
 from django.utils import timezone
 from django.utils.translation import ugettext_lazy as _
-import mongoengine
-
-from dashboard.models import CourseImportLog
 from opaque_keys import InvalidKeyError
 from opaque_keys.edx.keys import CourseKey
 from opaque_keys.edx.locations import SlashSeparatedCourseKey
 
+from dashboard.models import CourseImportLog
+
 log = logging.getLogger(__name__)
 
 DEFAULT_GIT_REPO_DIR = '/edx/var/app/edxapp/course_repos'
diff --git a/lms/djangoapps/dashboard/management/commands/tests/test_git_add_course.py b/lms/djangoapps/dashboard/management/commands/tests/test_git_add_course.py
index 1d87418d5c253f5d0da9a31a9126ad89e3794b02..f45e1d94e7642b0be676c9b71a1a697e35038a95 100644
--- a/lms/djangoapps/dashboard/management/commands/tests/test_git_add_course.py
+++ b/lms/djangoapps/dashboard/management/commands/tests/test_git_add_course.py
@@ -8,28 +8,27 @@ import StringIO
 import subprocess
 import unittest
 from uuid import uuid4
-from nose.plugins.attrib import attr
 
 from django.conf import settings
 from django.core.management import call_command
 from django.core.management.base import CommandError
 from django.test.utils import override_settings
+from nose.plugins.attrib import attr
 from opaque_keys.edx.locations import SlashSeparatedCourseKey
 
 import dashboard.git_import as git_import
 from dashboard.git_import import (
     GitImportError,
-    GitImportErrorNoDir,
-    GitImportErrorUrlBad,
-    GitImportErrorCannotPull,
     GitImportErrorBadRepo,
+    GitImportErrorCannotPull,
+    GitImportErrorNoDir,
     GitImportErrorRemoteBranchMissing,
+    GitImportErrorUrlBad
 )
 from xmodule.modulestore import ModuleStoreEnum
 from xmodule.modulestore.django import modulestore
 from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
-from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST
-
+from xmodule.modulestore.tests.mongo_connection import MONGO_HOST, MONGO_PORT_NUM
 
 TEST_MONGODB_LOG = {
     'host': MONGO_HOST,
diff --git a/lms/djangoapps/dashboard/models.py b/lms/djangoapps/dashboard/models.py
index a92a41887197a4847a2051787c61b08185ee0402..d7ef149f36ee252e9bb6107be250f8db1bb4a6f4 100644
--- a/lms/djangoapps/dashboard/models.py
+++ b/lms/djangoapps/dashboard/models.py
@@ -1,6 +1,7 @@
 """Models for dashboard application"""
 
 import mongoengine
+
 from xmodule.modulestore.mongoengine_fields import CourseKeyField
 
 
diff --git a/lms/djangoapps/dashboard/sysadmin.py b/lms/djangoapps/dashboard/sysadmin.py
index dd6e320a32927a9e9aa1d175dfb83bb1e70d9810..60f63c5c87626d02521df2bfebe97d691cc9e2c0 100644
--- a/lms/djangoapps/dashboard/sysadmin.py
+++ b/lms/djangoapps/dashboard/sysadmin.py
@@ -6,41 +6,40 @@ import csv
 import json
 import logging
 import os
-import subprocess
 import StringIO
+import subprocess
 
+import mongoengine
 from django.conf import settings
 from django.contrib.auth import authenticate
 from django.contrib.auth.decorators import login_required
 from django.contrib.auth.models import User
 from django.core.exceptions import PermissionDenied
-from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
+from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
 from django.db import IntegrityError
-from django.http import HttpResponse, Http404
+from django.http import Http404, HttpResponse
+from django.utils import timezone
 from django.utils.decorators import method_decorator
 from django.utils.html import escape
-from django.utils import timezone
 from django.utils.translation import ugettext as _
 from django.views.decorators.cache import cache_control
-from django.views.generic.base import TemplateView
-from django.views.decorators.http import condition
 from django.views.decorators.csrf import ensure_csrf_cookie
-from edxmako.shortcuts import render_to_response
-import mongoengine
+from django.views.decorators.http import condition
+from django.views.generic.base import TemplateView
+from opaque_keys.edx.locations import SlashSeparatedCourseKey
 from path import Path as path
 
-from courseware.courses import get_course_by_id
 import dashboard.git_import as git_import
+import track.views
+from courseware.courses import get_course_by_id
 from dashboard.git_import import GitImportError
-from student.roles import CourseStaffRole, CourseInstructorRole
 from dashboard.models import CourseImportLog
+from edxmako.shortcuts import render_to_response
 from openedx.core.djangoapps.external_auth.models import ExternalAuthMap
 from openedx.core.djangoapps.external_auth.views import generate_password
-from student.models import CourseEnrollment, UserProfile, Registration
-import track.views
+from student.models import CourseEnrollment, Registration, UserProfile
+from student.roles import CourseInstructorRole, CourseStaffRole
 from xmodule.modulestore.django import modulestore
-from opaque_keys.edx.locations import SlashSeparatedCourseKey
-
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/dashboard/tests/test_sysadmin.py b/lms/djangoapps/dashboard/tests/test_sysadmin.py
index c05f38add6e08fece48ac0d6ee8563abc69843c4..0d3322edfe45a0d47e4ff959781c82f0e6737304 100644
--- a/lms/djangoapps/dashboard/tests/test_sysadmin.py
+++ b/lms/djangoapps/dashboard/tests/test_sysadmin.py
@@ -6,27 +6,26 @@ import os
 import re
 import shutil
 import unittest
+from datetime import datetime
 from uuid import uuid4
-from util.date_utils import get_time_display, DEFAULT_DATE_TIME_FORMAT
-from nose.plugins.attrib import attr
 
+import mongoengine
 from django.conf import settings
 from django.core.urlresolvers import reverse
 from django.test.client import Client
 from django.test.utils import override_settings
 from django.utils.timezone import utc as UTC
-import mongoengine
+from nose.plugins.attrib import attr
 from opaque_keys.edx.locations import SlashSeparatedCourseKey
 
-from dashboard.models import CourseImportLog
 from dashboard.git_import import GitImportErrorNoDir
-from datetime import datetime
+from dashboard.models import CourseImportLog
 from student.roles import CourseStaffRole, GlobalStaff
 from student.tests.factories import UserFactory
+from util.date_utils import DEFAULT_DATE_TIME_FORMAT, get_time_display
 from xmodule.modulestore.django import modulestore
 from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
-from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST
-
+from xmodule.modulestore.tests.mongo_connection import MONGO_HOST, MONGO_PORT_NUM
 
 TEST_MONGODB_LOG = {
     'host': MONGO_HOST,
diff --git a/lms/djangoapps/debug/management/commands/dump_xml_courses.py b/lms/djangoapps/debug/management/commands/dump_xml_courses.py
index 136281bcb363372dd6be0c3578de1f18e225537c..9f4d3e388e5c1946690d2f37fd8d166d15330740 100644
--- a/lms/djangoapps/debug/management/commands/dump_xml_courses.py
+++ b/lms/djangoapps/debug/management/commands/dump_xml_courses.py
@@ -10,10 +10,10 @@ of each of its fields (including those fields that are set as default values).
 from __future__ import print_function
 
 import json
-from path import Path as path
 
-from django.core.management.base import BaseCommand, CommandError
 from django.conf import settings
+from django.core.management.base import BaseCommand, CommandError
+from path import Path as path
 
 from xmodule.modulestore.xml import XMLModuleStore
 
diff --git a/lms/djangoapps/debug/views.py b/lms/djangoapps/debug/views.py
index c8036b34e6413cdae380c19744ab8838e30261f4..2fb32a38d4d531c20b703db4730e15515022d039 100644
--- a/lms/djangoapps/debug/views.py
+++ b/lms/djangoapps/debug/views.py
@@ -3,14 +3,13 @@
 import pprint
 import traceback
 
-from django.http import Http404, HttpResponse
 from django.contrib.auth.decorators import login_required
+from django.http import Http404, HttpResponse
 from django.utils.html import escape
-
 from django.views.decorators.csrf import ensure_csrf_cookie
-from edxmako.shortcuts import render_to_response
 
 from codejail.safe_exec import safe_exec
+from edxmako.shortcuts import render_to_response
 
 
 @login_required
diff --git a/lms/djangoapps/discussion/plugins.py b/lms/djangoapps/discussion/plugins.py
index f0096f3f5bfd25c6308619957413e21d906e05cc..77037d41a216ca19b5f400f7d38389b61e6f916d 100644
--- a/lms/djangoapps/discussion/plugins.py
+++ b/lms/djangoapps/discussion/plugins.py
@@ -5,8 +5,8 @@ Views handling read (GET) requests for the Discussion tab and inline discussions
 from django.conf import settings
 from django.utils.translation import ugettext_noop
 
-from courseware.tabs import EnrolledTab
 import django_comment_client.utils as utils
+from courseware.tabs import EnrolledTab
 from xmodule.tabs import TabFragmentViewMixin
 
 
diff --git a/lms/djangoapps/discussion/tests/test_views.py b/lms/djangoapps/discussion/tests/test_views.py
index 0bdb26c49cd0ae9ccaa9c8ea041f36797162631c..e25ef1120dd71f36e8b58d1cd11234359ba09b55 100644
--- a/lms/djangoapps/discussion/tests/test_views.py
+++ b/lms/djangoapps/discussion/tests/test_views.py
@@ -3,16 +3,16 @@ import logging
 from datetime import datetime
 
 import ddt
-from mock import ANY, Mock, call, patch
-from nose.tools import assert_true
-
-from course_modes.models import CourseMode
-from course_modes.tests.factories import CourseModeFactory
 from django.core.urlresolvers import reverse
 from django.http import Http404
 from django.test.client import Client, RequestFactory
 from django.test.utils import override_settings
 from django.utils import translation
+from mock import ANY, Mock, call, patch
+from nose.tools import assert_true
+
+from course_modes.models import CourseMode
+from course_modes.tests.factories import CourseModeFactory
 from django_comment_client.constants import TYPE_ENTRY, TYPE_SUBCATEGORY
 from django_comment_client.permissions import get_team
 from django_comment_client.tests.group_id import (
diff --git a/lms/djangoapps/discussion/urls.py b/lms/djangoapps/discussion/urls.py
index 4295d3a253c25e554bd9e8df8253cb50c4a24301..e1fa4de8f7ddac87db84e329235789a8019a63b4 100644
--- a/lms/djangoapps/discussion/urls.py
+++ b/lms/djangoapps/discussion/urls.py
@@ -1,7 +1,7 @@
 """
 Forum urls for the django_comment_client.
 """
-from django.conf.urls import url, patterns
+from django.conf.urls import patterns, url
 
 from .views import DiscussionBoardFragmentView
 
diff --git a/lms/djangoapps/discussion/views.py b/lms/djangoapps/discussion/views.py
index ee67d9e196ec07d76f45f90c6b039478b34eadfb..8929203517854f2a9017b522f6d4d40a812d36fd 100644
--- a/lms/djangoapps/discussion/views.py
+++ b/lms/djangoapps/discussion/views.py
@@ -7,11 +7,6 @@ from contextlib import contextmanager
 from functools import wraps
 from sets import Set
 
-import django_comment_client.utils as utils
-import lms.lib.comment_client as cc
-from courseware.access import has_access
-from courseware.courses import get_course_with_access
-from courseware.views.views import CourseTabView
 from django.conf import settings
 from django.contrib.auth.decorators import login_required
 from django.contrib.auth.models import User
@@ -24,6 +19,15 @@ from django.template.loader import render_to_string
 from django.utils.translation import get_language_bidi
 from django.views.decorators.csrf import ensure_csrf_cookie
 from django.views.decorators.http import require_GET, require_http_methods
+from opaque_keys.edx.keys import CourseKey
+from rest_framework import status
+from web_fragments.fragment import Fragment
+
+import django_comment_client.utils as utils
+import lms.lib.comment_client as cc
+from courseware.access import has_access
+from courseware.courses import get_course_with_access
+from courseware.views.views import CourseTabView
 from django_comment_client.constants import TYPE_ENTRY
 from django_comment_client.permissions import get_team, has_permission
 from django_comment_client.utils import (
@@ -40,13 +44,9 @@ from django_comment_client.utils import (
 )
 from django_comment_common.utils import ThreadContext, get_course_discussion_settings, set_course_discussion_settings
 from lms.djangoapps.courseware.views.views import check_and_get_upgrade_link, get_cosmetic_verified_display_price
-
-from opaque_keys.edx.keys import CourseKey
 from openedx.core.djangoapps.plugin_api.views import EdxFragmentView
-from rest_framework import status
 from student.models import CourseEnrollment
 from util.json_request import JsonResponse, expect_json
-from web_fragments.fragment import Fragment
 from xmodule.modulestore.django import modulestore
 
 log = logging.getLogger("edx.discussions")
diff --git a/lms/djangoapps/discussion_api/api.py b/lms/djangoapps/discussion_api/api.py
index 0e7979b4542197ea2f2c76316d9571a4138410ac..eeb30fc271c4ca973f76ba0ad2682795d17581c7 100644
--- a/lms/djangoapps/discussion_api/api.py
+++ b/lms/djangoapps/discussion_api/api.py
@@ -3,10 +3,17 @@ Discussion API internal interface
 """
 import itertools
 from collections import defaultdict
-from enum import Enum
 from urllib import urlencode
 from urlparse import urlunparse
 
+from django.core.exceptions import ValidationError
+from django.core.urlresolvers import reverse
+from django.http import Http404
+from enum import Enum
+from opaque_keys import InvalidKeyError
+from opaque_keys.edx.locator import CourseKey
+from rest_framework.exceptions import PermissionDenied
+
 from courseware.courses import get_course_with_access
 from discussion_api.exceptions import CommentNotFoundError, DiscussionDisabledError, ThreadNotFoundError
 from discussion_api.forms import CommentActionsForm, ThreadActionsForm
@@ -17,9 +24,6 @@ from discussion_api.permissions import (
     get_initializable_thread_fields
 )
 from discussion_api.serializers import CommentSerializer, DiscussionTopicSerializer, ThreadSerializer, get_context
-from django.core.exceptions import ValidationError
-from django.core.urlresolvers import reverse
-from django.http import Http404
 from django_comment_client.base.views import track_comment_created_event, track_thread_created_event, track_voted_event
 from django_comment_client.utils import get_accessible_discussion_xblocks, get_group_id_for_user, is_commentable_divided
 from django_comment_common.signals import (
@@ -38,11 +42,8 @@ from lms.djangoapps.discussion_api.pagination import DiscussionAPIPagination
 from lms.lib.comment_client.comment import Comment
 from lms.lib.comment_client.thread import Thread
 from lms.lib.comment_client.utils import CommentClientRequestError
-from opaque_keys import InvalidKeyError
-from opaque_keys.edx.locator import CourseKey
 from openedx.core.djangoapps.user_api.accounts.views import AccountViewSet
 from openedx.core.lib.exceptions import CourseNotFoundError, DiscussionNotFoundError, PageNotFoundError
-from rest_framework.exceptions import PermissionDenied
 
 
 class DiscussionTopic(object):
diff --git a/lms/djangoapps/discussion_api/forms.py b/lms/djangoapps/discussion_api/forms.py
index 2d5ac81c9f95a129746e9fc19ac3c0bca08e45dc..16edfc9c9717d3833650d8c25b4a5eac06446d24 100644
--- a/lms/djangoapps/discussion_api/forms.py
+++ b/lms/djangoapps/discussion_api/forms.py
@@ -2,17 +2,11 @@
 Discussion API forms
 """
 from django.core.exceptions import ValidationError
-from django.forms import (
-    BooleanField,
-    CharField,
-    ChoiceField,
-    Form,
-    IntegerField,
-)
-
+from django.forms import BooleanField, CharField, ChoiceField, Form, IntegerField
 from opaque_keys import InvalidKeyError
 from opaque_keys.edx.locator import CourseLocator
-from openedx.core.djangoapps.util.forms import MultiValueField, ExtendedNullBooleanField
+
+from openedx.core.djangoapps.util.forms import ExtendedNullBooleanField, MultiValueField
 
 
 class _PaginationForm(Form):
diff --git a/lms/djangoapps/discussion_api/pagination.py b/lms/djangoapps/discussion_api/pagination.py
index 099459510f74d0f50fc605e3b0dbfdf0a6ad0abe..bf4c25ac5afccd4baf7050ce7c192b0d15a45904 100644
--- a/lms/djangoapps/discussion_api/pagination.py
+++ b/lms/djangoapps/discussion_api/pagination.py
@@ -2,6 +2,7 @@
 Discussion API pagination support
 """
 from rest_framework.utils.urls import replace_query_param
+
 from openedx.core.lib.api.paginators import NamespacedPageNumberPagination
 
 
diff --git a/lms/djangoapps/discussion_api/serializers.py b/lms/djangoapps/discussion_api/serializers.py
index a11ff95ae6724b411f3f59cf4b96f6dffaa7470b..4f7c1d14ff58ef5596e58d4822240888400a7ceb 100644
--- a/lms/djangoapps/discussion_api/serializers.py
+++ b/lms/djangoapps/discussion_api/serializers.py
@@ -4,11 +4,13 @@ Discussion API serializers
 from urllib import urlencode
 from urlparse import urlunparse
 
-from discussion_api.permissions import NON_UPDATABLE_COMMENT_FIELDS, NON_UPDATABLE_THREAD_FIELDS, get_editable_fields
-from discussion_api.render import render_body
 from django.contrib.auth.models import User as DjangoUser
 from django.core.exceptions import ValidationError
 from django.core.urlresolvers import reverse
+from rest_framework import serializers
+
+from discussion_api.permissions import NON_UPDATABLE_COMMENT_FIELDS, NON_UPDATABLE_THREAD_FIELDS, get_editable_fields
+from discussion_api.render import render_body
 from django_comment_client.utils import is_comment_too_deep
 from django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_MODERATOR, Role
 from django_comment_common.utils import get_course_discussion_settings
@@ -17,7 +19,6 @@ from lms.lib.comment_client.comment import Comment
 from lms.lib.comment_client.thread import Thread
 from lms.lib.comment_client.user import User as CommentClientUser
 from lms.lib.comment_client.utils import CommentClientRequestError
-from rest_framework import serializers
 
 
 def get_context(course, request, thread=None):
diff --git a/lms/djangoapps/discussion_api/tests/test_api.py b/lms/djangoapps/discussion_api/tests/test_api.py
index 11cc6f33f99345500d2e0492a394b52f9e99dc05..b8274ed0f1d0ac4ab61584e5c4df37a6ae7d11f3 100644
--- a/lms/djangoapps/discussion_api/tests/test_api.py
+++ b/lms/djangoapps/discussion_api/tests/test_api.py
@@ -7,10 +7,15 @@ from urllib import urlencode
 from urlparse import parse_qs, urlparse, urlunparse
 
 import ddt
+import httpretty
 import mock
+from django.core.exceptions import ValidationError
+from django.test.client import RequestFactory
 from nose.plugins.attrib import attr
+from opaque_keys.edx.locator import CourseLocator
+from pytz import UTC
+from rest_framework.exceptions import PermissionDenied
 
-import httpretty
 from common.test.utils import MockSignalHandlerMixin, disable_signal
 from courseware.tests.factories import BetaTesterFactory, StaffFactory
 from discussion_api import api
@@ -34,8 +39,6 @@ from discussion_api.tests.utils import (
     make_minimal_cs_thread,
     make_paginated_api_response
 )
-from django.core.exceptions import ValidationError
-from django.test.client import RequestFactory
 from django_comment_client.tests.utils import ForumsEnableMixin
 from django_comment_common.models import (
     FORUM_ROLE_ADMINISTRATOR,
@@ -44,12 +47,9 @@ from django_comment_common.models import (
     FORUM_ROLE_STUDENT,
     Role
 )
-from opaque_keys.edx.locator import CourseLocator
 from openedx.core.djangoapps.course_groups.models import CourseUserGroupPartitionGroup
 from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory
 from openedx.core.lib.exceptions import CourseNotFoundError, PageNotFoundError
-from pytz import UTC
-from rest_framework.exceptions import PermissionDenied
 from student.tests.factories import CourseEnrollmentFactory, UserFactory
 from util.testing import UrlResetMixin
 from xmodule.modulestore import ModuleStoreEnum
diff --git a/lms/djangoapps/discussion_api/tests/test_forms.py b/lms/djangoapps/discussion_api/tests/test_forms.py
index 48b32d4fc9915ebc038eb911d732150c60a374cb..b507ae4c26313933d0cafadd743498a5b8934142 100644
--- a/lms/djangoapps/discussion_api/tests/test_forms.py
+++ b/lms/djangoapps/discussion_api/tests/test_forms.py
@@ -6,12 +6,11 @@ from unittest import TestCase
 from urllib import urlencode
 
 import ddt
-
 from django.http import QueryDict
-
 from opaque_keys.edx.locator import CourseLocator
-from openedx.core.djangoapps.util.test_forms import FormTestMixin
+
 from discussion_api.forms import CommentListGetForm, ThreadListGetForm
+from openedx.core.djangoapps.util.test_forms import FormTestMixin
 
 
 class PaginationTestMixin(object):
diff --git a/lms/djangoapps/discussion_api/tests/test_permissions.py b/lms/djangoapps/discussion_api/tests/test_permissions.py
index 392628d45079380447a506a5fca6ad5671c526fd..cdac23f5b5f44420e8aecffe3717d44c2529f9d3 100644
--- a/lms/djangoapps/discussion_api/tests/test_permissions.py
+++ b/lms/djangoapps/discussion_api/tests/test_permissions.py
@@ -10,7 +10,7 @@ from discussion_api.permissions import (
     can_delete,
     get_editable_fields,
     get_initializable_comment_fields,
-    get_initializable_thread_fields,
+    get_initializable_thread_fields
 )
 from lms.lib.comment_client.comment import Comment
 from lms.lib.comment_client.thread import Thread
diff --git a/lms/djangoapps/discussion_api/tests/test_serializers.py b/lms/djangoapps/discussion_api/tests/test_serializers.py
index 413a5b4a5986f40f8a39ae52f3fe2e416ce1c2be..4ceeaa5486ac4b91563321bbe4655ad300ca2250 100644
--- a/lms/djangoapps/discussion_api/tests/test_serializers.py
+++ b/lms/djangoapps/discussion_api/tests/test_serializers.py
@@ -5,13 +5,13 @@ import itertools
 from urlparse import urlparse
 
 import ddt
+import httpretty
 import mock
+from django.test.client import RequestFactory
 from nose.plugins.attrib import attr
 
-import httpretty
 from discussion_api.serializers import CommentSerializer, ThreadSerializer, get_context
 from discussion_api.tests.utils import CommentsServiceMockMixin, make_minimal_cs_comment, make_minimal_cs_thread
-from django.test.client import RequestFactory
 from django_comment_client.tests.utils import ForumsEnableMixin
 from django_comment_common.models import (
     FORUM_ROLE_ADMINISTRATOR,
diff --git a/lms/djangoapps/discussion_api/tests/test_views.py b/lms/djangoapps/discussion_api/tests/test_views.py
index cba01d4fad032968d55dd31d4d2914c8a232dca7..559b094ce86af9be8b6167fac913b82c80dfebcf 100644
--- a/lms/djangoapps/discussion_api/tests/test_views.py
+++ b/lms/djangoapps/discussion_api/tests/test_views.py
@@ -1,37 +1,36 @@
 """
 Tests for Discussion API views
 """
-from datetime import datetime
 import json
+from datetime import datetime
 from urlparse import urlparse
 
 import ddt
 import httpretty
 import mock
+from django.core.urlresolvers import reverse
 from nose.plugins.attrib import attr
-from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_image_storage
 from pytz import UTC
-
-from django.core.urlresolvers import reverse
 from rest_framework.parsers import JSONParser
-
 from rest_framework.test import APIClient
-from xmodule.modulestore import ModuleStoreEnum
-from xmodule.modulestore.django import modulestore
 
 from common.test.utils import disable_signal
 from discussion_api import api
 from discussion_api.tests.utils import (
     CommentsServiceMockMixin,
+    ProfileImageTestMixin,
     make_minimal_cs_comment,
     make_minimal_cs_thread,
-    make_paginated_api_response,
-    ProfileImageTestMixin)
+    make_paginated_api_response
+)
 from django_comment_client.tests.utils import ForumsEnableMixin
+from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_image_storage
 from student.tests.factories import CourseEnrollmentFactory, UserFactory
-from util.testing import UrlResetMixin, PatchMediaTypeMixin
+from util.testing import PatchMediaTypeMixin, 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, check_mongo_calls, ItemFactory
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls
 
 
 class DiscussionAPIViewTestMixin(ForumsEnableMixin, CommentsServiceMockMixin, UrlResetMixin):
diff --git a/lms/djangoapps/discussion_api/tests/utils.py b/lms/djangoapps/discussion_api/tests/utils.py
index dde68bd93830c5f1efa648cf97ad618b4c491f15..5f7a864e5e14b82a0c99dca88579ed0ebefe1d22 100644
--- a/lms/djangoapps/discussion_api/tests/utils.py
+++ b/lms/djangoapps/discussion_api/tests/utils.py
@@ -1,15 +1,15 @@
 """
 Discussion API test utilities
 """
-from contextlib import closing
-from datetime import datetime
+import hashlib
 import json
 import re
+from contextlib import closing
+from datetime import datetime
 
-import hashlib
 import httpretty
-from pytz import UTC
 from PIL import Image
+from pytz import UTC
 
 from openedx.core.djangoapps.profile_images.images import create_profile_images
 from openedx.core.djangoapps.profile_images.tests.helpers import make_image_file
diff --git a/lms/djangoapps/discussion_api/urls.py b/lms/djangoapps/discussion_api/urls.py
index ed150b6a8db9b3c30a916288d13320012b47afc9..6edf3eab9fd54365b9eb8df888a27cbd840b6f2d 100644
--- a/lms/djangoapps/discussion_api/urls.py
+++ b/lms/djangoapps/discussion_api/urls.py
@@ -3,12 +3,10 @@ Discussion API URLs
 """
 from django.conf import settings
 from django.conf.urls import include, patterns, url
-
 from rest_framework.routers import SimpleRouter
 
 from discussion_api.views import CommentViewSet, CourseTopicsView, CourseView, ThreadViewSet
 
-
 ROUTER = SimpleRouter()
 ROUTER.register("threads", ThreadViewSet, base_name="thread")
 ROUTER.register("comments", CommentViewSet, base_name="comment")
diff --git a/lms/djangoapps/discussion_api/views.py b/lms/djangoapps/discussion_api/views.py
index 4f3fd6340dcc02addeadb92eb2ea32aa37377bba..fcf89087d720cb08e8f0067876375c3498b00be9 100644
--- a/lms/djangoapps/discussion_api/views.py
+++ b/lms/djangoapps/discussion_api/views.py
@@ -2,33 +2,31 @@
 Discussion API views
 """
 from django.core.exceptions import ValidationError
+from opaque_keys.edx.keys import CourseKey
 from rest_framework.exceptions import UnsupportedMediaType
 from rest_framework.parsers import JSONParser
-
 from rest_framework.response import Response
 from rest_framework.views import APIView
 from rest_framework.viewsets import ViewSet
 
-from opaque_keys.edx.keys import CourseKey
-from xmodule.modulestore.django import modulestore
-
 from discussion_api.api import (
     create_comment,
     create_thread,
-    delete_thread,
     delete_comment,
+    delete_thread,
     get_comment_list,
-    get_response_comments,
     get_course,
     get_course_topics,
+    get_response_comments,
     get_thread,
     get_thread_list,
     update_comment,
-    update_thread,
+    update_thread
 )
-from discussion_api.forms import CommentListGetForm, ThreadListGetForm, CommentGetForm
+from discussion_api.forms import CommentGetForm, CommentListGetForm, ThreadListGetForm
 from openedx.core.lib.api.parsers import MergePatchParser
 from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes
+from xmodule.modulestore.django import modulestore
 
 
 @view_auth_classes()
diff --git a/lms/djangoapps/django_comment_client/base/tests.py b/lms/djangoapps/django_comment_client/base/tests.py
index 7288ecd3c90a7c051e5fdebe773ea15ee52e1745..bcdd19e934a579a1eea02736588abf577f14bcdb 100644
--- a/lms/djangoapps/django_comment_client/base/tests.py
+++ b/lms/djangoapps/django_comment_client/base/tests.py
@@ -1,37 +1,38 @@
 # -*- coding: utf-8 -*-
 """Tests for django comment client views."""
-from contextlib import contextmanager
-import logging
 import json
-import ddt
+import logging
+from contextlib import contextmanager
 
-from django.test.client import RequestFactory
+import ddt
 from django.contrib.auth.models import User
 from django.core.management import call_command
 from django.core.urlresolvers import reverse
-from mock import patch, ANY, Mock
-from nose.tools import assert_true, assert_equal
+from django.test.client import RequestFactory
+from mock import ANY, Mock, patch
 from nose.plugins.attrib import attr
+from nose.tools import assert_equal, assert_true
 from opaque_keys.edx.keys import CourseKey
-from lms.lib.comment_client import Thread
 
 from common.test.utils import MockSignalHandlerMixin, disable_signal
 from django_comment_client.base import views
-from django_comment_client.tests.group_id import CohortedTopicGroupIdTestMixin, NonCohortedTopicGroupIdTestMixin, GroupIdAssertionMixin
-from django_comment_client.tests.utils import CohortedTestCase, ForumsEnableMixin
+from django_comment_client.tests.group_id import (
+    CohortedTopicGroupIdTestMixin,
+    GroupIdAssertionMixin,
+    NonCohortedTopicGroupIdTestMixin
+)
 from django_comment_client.tests.unicode import UnicodeTestMixin
+from django_comment_client.tests.utils import CohortedTestCase, ForumsEnableMixin
 from django_comment_common.models import Role
-from django_comment_common.utils import seed_permissions_roles, ThreadContext
-
+from django_comment_common.utils import ThreadContext, seed_permissions_roles
 from lms.djangoapps.teams.tests.factories import CourseTeamFactory, CourseTeamMembershipFactory
-from student.tests.factories import CourseEnrollmentFactory, UserFactory, CourseAccessRoleFactory
+from lms.lib.comment_client import Thread
+from student.tests.factories import CourseAccessRoleFactory, CourseEnrollmentFactory, UserFactory
 from util.testing import UrlResetMixin
-from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
-from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase
-from xmodule.modulestore.tests.factories import check_mongo_calls
-from xmodule.modulestore.django import modulestore
 from xmodule.modulestore import ModuleStoreEnum
-
+from xmodule.modulestore.django import modulestore
+from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/django_comment_client/base/urls.py b/lms/djangoapps/django_comment_client/base/urls.py
index f3a2f9244a8cbd70d9efb5bd2a7b3a74c0a8547a..0e26310c7575183cce169915aa6ab360733dfd11 100644
--- a/lms/djangoapps/django_comment_client/base/urls.py
+++ b/lms/djangoapps/django_comment_client/base/urls.py
@@ -1,7 +1,7 @@
 """
 Base urls for the django_comment_client.
 """
-from django.conf.urls import url, patterns
+from django.conf.urls import patterns, url
 
 urlpatterns = patterns(
     'django_comment_client.base.views',
diff --git a/lms/djangoapps/django_comment_client/base/views.py b/lms/djangoapps/django_comment_client/base/views.py
index 2a5e1d09d1af6ed4aae652d3a2f531bfeb374886..5a8b457baf01905beb55c6708deea2dc849c0c80 100644
--- a/lms/djangoapps/django_comment_client/base/views.py
+++ b/lms/djangoapps/django_comment_client/base/views.py
@@ -1,6 +1,6 @@
 import functools
-import logging
 import json
+import logging
 import random
 import time
 import urlparse
@@ -14,39 +14,38 @@ from django.views.decorators import csrf
 from django.views.decorators.http import require_GET, require_POST
 from opaque_keys.edx.keys import CourseKey
 
-from courseware.access import has_access
-from util.file import store_uploaded_file
-from courseware.courses import get_course_with_access, get_course_overview_with_access, get_course_by_id
-from lms.djangoapps.courseware.exceptions import CourseAccessRedirect
-
 import django_comment_client.settings as cc_settings
-from django_comment_common.signals import (
-    thread_created,
-    thread_edited,
-    thread_voted,
-    thread_deleted,
-    comment_created,
-    comment_edited,
-    comment_voted,
-    comment_deleted,
-    comment_endorsed,
-)
-from django_comment_common.utils import ThreadContext
+import lms.lib.comment_client as cc
+from courseware.access import has_access
+from courseware.courses import get_course_by_id, get_course_overview_with_access, get_course_with_access
+from django_comment_client.permissions import check_permissions_by_view, get_team, has_permission
 from django_comment_client.utils import (
-    add_courseware_context,
-    get_annotated_content_info,
-    get_ability,
-    is_comment_too_deep,
     JsonError,
     JsonResponse,
-    prepare_content,
-    get_group_id_for_comments_service,
+    add_courseware_context,
     discussion_category_id_access,
+    get_ability,
+    get_annotated_content_info,
     get_cached_discussion_id_map,
+    get_group_id_for_comments_service,
+    is_comment_too_deep,
+    prepare_content
 )
-from django_comment_client.permissions import check_permissions_by_view, has_permission, get_team
+from django_comment_common.signals import (
+    comment_created,
+    comment_deleted,
+    comment_edited,
+    comment_endorsed,
+    comment_voted,
+    thread_created,
+    thread_deleted,
+    thread_edited,
+    thread_voted
+)
+from django_comment_common.utils import ThreadContext
 from eventtracking import tracker
-import lms.lib.comment_client as cc
+from lms.djangoapps.courseware.exceptions import CourseAccessRedirect
+from util.file import store_uploaded_file
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/django_comment_client/management/commands/assign_role.py b/lms/djangoapps/django_comment_client/management/commands/assign_role.py
index 4e9321410c20129734df9c0322cc9e41b6f316e6..2c3452e54b14a29ecf160ac58d8174b1c0d0ea39 100644
--- a/lms/djangoapps/django_comment_client/management/commands/assign_role.py
+++ b/lms/djangoapps/django_comment_client/management/commands/assign_role.py
@@ -1,8 +1,9 @@
 from optparse import make_option
 
+from django.contrib.auth.models import User
 from django.core.management.base import BaseCommand, CommandError
+
 from django_comment_common.models import Role
-from django.contrib.auth.models import User
 
 
 class Command(BaseCommand):
diff --git a/lms/djangoapps/django_comment_client/management/commands/assign_roles_for_course.py b/lms/djangoapps/django_comment_client/management/commands/assign_roles_for_course.py
index 4701774a2eb21ed2c46c78a06db55a8f1555511f..cb0f7afc5b6eb3e3d6e57f444fbf4990d4716feb 100644
--- a/lms/djangoapps/django_comment_client/management/commands/assign_roles_for_course.py
+++ b/lms/djangoapps/django_comment_client/management/commands/assign_roles_for_course.py
@@ -6,8 +6,8 @@ Enrollments.
 """
 from django.core.management.base import BaseCommand, CommandError
 
-from student.models import CourseEnrollment
 from django_comment_common.models import assign_default_role_on_enrollment
+from student.models import CourseEnrollment
 
 
 class Command(BaseCommand):
diff --git a/lms/djangoapps/django_comment_client/management/commands/create_roles_for_existing.py b/lms/djangoapps/django_comment_client/management/commands/create_roles_for_existing.py
index 575d9666e1a07ef607f3ff387531286c73fb3fab..c14359af21491f8373f739435054f2f3890a287b 100644
--- a/lms/djangoapps/django_comment_client/management/commands/create_roles_for_existing.py
+++ b/lms/djangoapps/django_comment_client/management/commands/create_roles_for_existing.py
@@ -6,8 +6,8 @@ Enrollments.
 """
 from django.core.management.base import BaseCommand, CommandError
 
-from student.models import CourseEnrollment
 from django_comment_common.models import assign_default_role_on_enrollment
+from student.models import CourseEnrollment
 
 
 class Command(BaseCommand):
diff --git a/lms/djangoapps/django_comment_client/management/commands/reload_forum_users.py b/lms/djangoapps/django_comment_client/management/commands/reload_forum_users.py
index 53c6aaf2b2d792b6ca8564bdbf792911fecaed31..a7ea40f4fde2c81bbb59116e558d6e10b5e19d07 100644
--- a/lms/djangoapps/django_comment_client/management/commands/reload_forum_users.py
+++ b/lms/djangoapps/django_comment_client/management/commands/reload_forum_users.py
@@ -1,9 +1,9 @@
 """
 Reload forum (comment client) users from existing users.
 """
+from django.contrib.auth.models import User
 from django.core.management.base import BaseCommand
 
-from django.contrib.auth.models import User
 import lms.lib.comment_client as cc
 
 
diff --git a/lms/djangoapps/django_comment_client/management/commands/seed_permissions_roles.py b/lms/djangoapps/django_comment_client/management/commands/seed_permissions_roles.py
index 64976656b21f596632d243bff4c3c15855ffab49..c3afb7f6e38a5929fff013337e8da35825b6f1dc 100644
--- a/lms/djangoapps/django_comment_client/management/commands/seed_permissions_roles.py
+++ b/lms/djangoapps/django_comment_client/management/commands/seed_permissions_roles.py
@@ -2,9 +2,10 @@
 Management command to seed default permissions and roles.
 """
 from django.core.management.base import BaseCommand, CommandError
-from django_comment_common.utils import seed_permissions_roles
 from opaque_keys.edx.keys import CourseKey
 
+from django_comment_common.utils import seed_permissions_roles
+
 
 class Command(BaseCommand):
     args = 'course_id'
diff --git a/lms/djangoapps/django_comment_client/management/commands/show_permissions.py b/lms/djangoapps/django_comment_client/management/commands/show_permissions.py
index f24f1831930d5a77618b1bd7c6117b3125aae601..abe90cf644167c26f9c6487062f3040df13a0f4c 100644
--- a/lms/djangoapps/django_comment_client/management/commands/show_permissions.py
+++ b/lms/djangoapps/django_comment_client/management/commands/show_permissions.py
@@ -1,5 +1,5 @@
-from django.core.management.base import BaseCommand, CommandError
 from django.contrib.auth.models import User
+from django.core.management.base import BaseCommand, CommandError
 
 
 class Command(BaseCommand):
diff --git a/lms/djangoapps/django_comment_client/management/commands/sync_user_info.py b/lms/djangoapps/django_comment_client/management/commands/sync_user_info.py
index 06428cbe59ca50a1de97f5b278eb8a5d2fdd8e9a..044e3832a1f1cf309a493de41882883bd21ad6f8 100644
--- a/lms/djangoapps/django_comment_client/management/commands/sync_user_info.py
+++ b/lms/djangoapps/django_comment_client/management/commands/sync_user_info.py
@@ -3,8 +3,9 @@ One-off script to sync all user information to the
 discussion service (later info will be synced automatically)
 """
 
-from django.core.management.base import BaseCommand
 from django.contrib.auth.models import User
+from django.core.management.base import BaseCommand
+
 import lms.lib.comment_client as cc
 
 
diff --git a/lms/djangoapps/django_comment_client/middleware.py b/lms/djangoapps/django_comment_client/middleware.py
index 7e2daab8ac24010802a65e4992c5dac3e06fc681..9dce7bc0127564f168ea0dc0022f1fffd4541591 100644
--- a/lms/djangoapps/django_comment_client/middleware.py
+++ b/lms/djangoapps/django_comment_client/middleware.py
@@ -1,8 +1,9 @@
-from lms.lib.comment_client import CommentClientRequestError
-from django_comment_client.utils import JsonError
 import json
 import logging
 
+from django_comment_client.utils import JsonError
+from lms.lib.comment_client import CommentClientRequestError
+
 log = logging.getLogger(__name__)
 
 
diff --git a/lms/djangoapps/django_comment_client/permissions.py b/lms/djangoapps/django_comment_client/permissions.py
index 36e4b2b35e92f09becd290bdb1db43462f73b0b6..a9250256bd818ada24d1bc301c5d9433ec866232 100644
--- a/lms/djangoapps/django_comment_client/permissions.py
+++ b/lms/djangoapps/django_comment_client/permissions.py
@@ -5,12 +5,12 @@ Module for checking permissions with the comment_client backend
 import logging
 from types import NoneType
 
-from request_cache.middleware import RequestCache, request_cached
-from lms.lib.comment_client import Thread
 from opaque_keys.edx.keys import CourseKey
 
 from django_comment_common.models import all_permissions_for_user_in_course
 from lms.djangoapps.teams.models import CourseTeam
+from lms.lib.comment_client import Thread
+from request_cache.middleware import RequestCache, request_cached
 
 
 def has_permission(user, permission, course_id=None):
diff --git a/lms/djangoapps/django_comment_client/tests/factories.py b/lms/djangoapps/django_comment_client/tests/factories.py
index c68339458847067b0100bb83e4d4dc0690bf7ba6..5a22db6be24fe9d4e0061a86af853afbc325e71e 100644
--- a/lms/djangoapps/django_comment_client/tests/factories.py
+++ b/lms/djangoapps/django_comment_client/tests/factories.py
@@ -1,5 +1,6 @@
 from factory.django import DjangoModelFactory
-from django_comment_common.models import Role, Permission
+
+from django_comment_common.models import Permission, Role
 
 
 class RoleFactory(DjangoModelFactory):
diff --git a/lms/djangoapps/django_comment_client/tests/mock_cs_server/mock_cs_server.py b/lms/djangoapps/django_comment_client/tests/mock_cs_server/mock_cs_server.py
index 55ea73455efc71237ed8f56298cdcf07059d0824..cdacca539bb36d4682b96d490392b0461e488bb6 100644
--- a/lms/djangoapps/django_comment_client/tests/mock_cs_server/mock_cs_server.py
+++ b/lms/djangoapps/django_comment_client/tests/mock_cs_server/mock_cs_server.py
@@ -1,6 +1,7 @@
-from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
 import json
+from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
 from logging import getLogger
+
 logger = getLogger(__name__)
 
 
diff --git a/lms/djangoapps/django_comment_client/tests/mock_cs_server/test_mock_cs_server.py b/lms/djangoapps/django_comment_client/tests/mock_cs_server/test_mock_cs_server.py
index 1aea66832998f4cf72267138e2d5391ae6f93678..ca9ba868767bf83b93b808957ebc45bbead3eb43 100644
--- a/lms/djangoapps/django_comment_client/tests/mock_cs_server/test_mock_cs_server.py
+++ b/lms/djangoapps/django_comment_client/tests/mock_cs_server/test_mock_cs_server.py
@@ -1,10 +1,12 @@
-import unittest
-import threading
 import json
+import threading
+import unittest
 import urllib2
-from django_comment_client.tests.mock_cs_server.mock_cs_server import MockCommentServiceServer
+
 from nose.plugins.skip import SkipTest
 
+from django_comment_client.tests.mock_cs_server.mock_cs_server import MockCommentServiceServer
+
 
 class MockCommentServiceServerTest(unittest.TestCase):
     '''
diff --git a/lms/djangoapps/django_comment_client/tests/test_middleware.py b/lms/djangoapps/django_comment_client/tests/test_middleware.py
index 8b223eaa1b4ac1b5af8cb8979836d6f5f53ac0de..4849cfa3d0258a520f15a9102fea95e47062904b 100644
--- a/lms/djangoapps/django_comment_client/tests/test_middleware.py
+++ b/lms/djangoapps/django_comment_client/tests/test_middleware.py
@@ -1,10 +1,11 @@
+import json
+
 import django.http
 from django.test import TestCase
 from nose.plugins.attrib import attr
-import json
 
-import lms.lib.comment_client
 import django_comment_client.middleware as middleware
+import lms.lib.comment_client
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/django_comment_client/tests/test_models.py b/lms/djangoapps/django_comment_client/tests/test_models.py
index bb59e6a7c7f435e93fc5f9ce37f23738d40e37d0..019d267b750fdcf1918427d9c7787484499236bd 100644
--- a/lms/djangoapps/django_comment_client/tests/test_models.py
+++ b/lms/djangoapps/django_comment_client/tests/test_models.py
@@ -6,9 +6,7 @@ from nose.plugins.attrib import attr
 from opaque_keys.edx.keys import CourseKey
 
 import django_comment_common.models as models
-from xmodule.modulestore.tests.django_utils import (
-    TEST_DATA_MIXED_MODULESTORE, ModuleStoreTestCase
-)
+from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_MODULESTORE, ModuleStoreTestCase
 from xmodule.modulestore.tests.factories import ToyCourseFactory
 
 
diff --git a/lms/djangoapps/django_comment_client/tests/test_utils.py b/lms/djangoapps/django_comment_client/tests/test_utils.py
index c273ed88b369fce2a88da3ca779e13751534422c..ab48975294154b6a6eedd315d3eedee084f9b2e1 100644
--- a/lms/djangoapps/django_comment_client/tests/test_utils.py
+++ b/lms/djangoapps/django_comment_client/tests/test_utils.py
@@ -4,17 +4,18 @@ import json
 
 import ddt
 import mock
+from django.core.urlresolvers import reverse
+from django.test import RequestFactory, TestCase
+from django.utils.timezone import UTC as django_utc
 from mock import Mock, patch
 from nose.plugins.attrib import attr
+from pytz import UTC
 
 import django_comment_client.utils as utils
 from course_modes.models import CourseMode
 from course_modes.tests.factories import CourseModeFactory
 from courseware.tabs import get_course_tab_list
 from courseware.tests.factories import InstructorFactory
-from django.core.urlresolvers import reverse
-from django.test import RequestFactory, TestCase
-from django.utils.timezone import UTC as django_utc
 from django_comment_client.constants import TYPE_ENTRY, TYPE_SUBCATEGORY
 from django_comment_client.tests.factories import RoleFactory
 from django_comment_client.tests.unicode import UnicodeTestMixin
@@ -29,7 +30,6 @@ from openedx.core.djangoapps.course_groups import cohorts
 from openedx.core.djangoapps.course_groups.cohorts import set_course_cohorted
 from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory, config_course_cohorts
 from openedx.core.djangoapps.util.testing import ContentGroupTestCase
-from pytz import UTC
 from student.roles import CourseStaffRole
 from student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory
 from xmodule.modulestore import ModuleStoreEnum
diff --git a/lms/djangoapps/django_comment_client/urls.py b/lms/djangoapps/django_comment_client/urls.py
index d2972b4c79c9f5b4809a5ffbcdc282c5a81ac4a1..ddebe62260aa22ddbf22f804bdb886296324cefb 100644
--- a/lms/djangoapps/django_comment_client/urls.py
+++ b/lms/djangoapps/django_comment_client/urls.py
@@ -1,7 +1,7 @@
 """
 Urls for the django_comment_client.
 """
-from django.conf.urls import url, patterns, include
+from django.conf.urls import include, patterns, url
 
 urlpatterns = patterns(
     '',
diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py
index 483fe2e917bd328d57f1b9867733b1368d8eae2f..8f6804193165b9d60d41025730d3cb332496a346 100644
--- a/lms/djangoapps/django_comment_client/utils.py
+++ b/lms/djangoapps/django_comment_client/utils.py
@@ -3,24 +3,25 @@ import logging
 from collections import defaultdict
 from datetime import datetime
 
-import pystache_custom as pystache
 import pytz
-from courseware import courses
-from courseware.access import has_access
 from django.conf import settings
 from django.contrib.auth.models import User
 from django.core.urlresolvers import reverse
 from django.db import connection
 from django.http import HttpResponse
 from django.utils.timezone import UTC
+from opaque_keys.edx.keys import CourseKey
+from opaque_keys.edx.locations import i4xEncoder
+
+import pystache_custom as pystache
+from courseware import courses
+from courseware.access import has_access
 from django_comment_client.constants import TYPE_ENTRY, TYPE_SUBCATEGORY
 from django_comment_client.permissions import check_permissions_by_view, get_team, has_permission
 from django_comment_client.settings import MAX_COMMENT_DEPTH
 from django_comment_common.models import FORUM_ROLE_STUDENT, CourseDiscussionSettings, Role
 from django_comment_common.utils import get_course_discussion_settings
 from edxmako import lookup_template
-from opaque_keys.edx.keys import CourseKey
-from opaque_keys.edx.locations import i4xEncoder
 from openedx.core.djangoapps.content.course_structures.models import CourseStructure
 from openedx.core.djangoapps.course_groups.cohorts import get_cohort_id, get_cohort_names, is_course_cohorted
 from request_cache.middleware import request_cached
diff --git a/lms/djangoapps/edxnotes/decorators.py b/lms/djangoapps/edxnotes/decorators.py
index 232afa08dab572470c2954395451027d81373a2c..42857d7845527ae551f5939f4241cc4e0a355412 100644
--- a/lms/djangoapps/edxnotes/decorators.py
+++ b/lms/djangoapps/edxnotes/decorators.py
@@ -6,14 +6,8 @@ import json
 
 from django.conf import settings
 
-from edxnotes.helpers import (
-    get_edxnotes_id_token,
-    get_public_endpoint,
-    get_token_url,
-    generate_uid,
-    is_feature_enabled,
-)
 from edxmako.shortcuts import render_to_string
+from edxnotes.helpers import generate_uid, get_edxnotes_id_token, get_public_endpoint, get_token_url, is_feature_enabled
 
 
 def edxnotes(cls):
diff --git a/lms/djangoapps/edxnotes/helpers.py b/lms/djangoapps/edxnotes/helpers.py
index 62598d9a3027ac3862f8e26c5360cd38673bfd4b..7374cc2fb395be68c15ecc29eae85535863c8ab9 100644
--- a/lms/djangoapps/edxnotes/helpers.py
+++ b/lms/djangoapps/edxnotes/helpers.py
@@ -3,34 +3,32 @@ Helper methods related to EdxNotes.
 """
 import json
 import logging
-from json import JSONEncoder
-from uuid import uuid4
 import urlparse
+from datetime import datetime
+from json import JSONEncoder
 from urllib import urlencode
+from uuid import uuid4
 
 import requests
-from datetime import datetime
 from dateutil.parser import parse as dateutil_parse
-from opaque_keys.edx.keys import UsageKey
-from requests.exceptions import RequestException
-
 from django.conf import settings
 from django.core.exceptions import ImproperlyConfigured
 from django.core.urlresolvers import reverse
 from django.utils.translation import ugettext as _
+from opaque_keys.edx.keys import UsageKey
 from provider.oauth2.models import Client
+from requests.exceptions import RequestException
 
-from edxnotes.exceptions import EdxNotesParseError, EdxNotesServiceUnavailable
-from edxnotes.plugins import EdxNotesTab
 from courseware.access import has_access
 from courseware.courses import get_current_child
+from edxnotes.exceptions import EdxNotesParseError, EdxNotesServiceUnavailable
+from edxnotes.plugins import EdxNotesTab
 from openedx.core.lib.token_utils import JwtBuilder
 from student.models import anonymous_id_for_user
 from util.date_utils import get_default_time_display
 from xmodule.modulestore.django import modulestore
 from xmodule.modulestore.exceptions import ItemNotFoundError
 
-
 log = logging.getLogger(__name__)
 # OAuth2 Client name for edxnotes
 CLIENT_NAME = "edx-notes"
diff --git a/lms/djangoapps/edxnotes/plugins.py b/lms/djangoapps/edxnotes/plugins.py
index 68519fe5495ae5918523b49994e6a00596d2d07d..1303324a8af86f733bc612e301bfb1fe4c4c6086 100644
--- a/lms/djangoapps/edxnotes/plugins.py
+++ b/lms/djangoapps/edxnotes/plugins.py
@@ -3,6 +3,7 @@ Registers the "edX Notes" feature for the edX platform.
 """
 from django.conf import settings
 from django.utils.translation import ugettext_noop
+
 from courseware.tabs import EnrolledTab
 
 
diff --git a/lms/djangoapps/edxnotes/tests.py b/lms/djangoapps/edxnotes/tests.py
index 24943615c267bce3954d46ef7c2dbb9c200dc82a..fe713c042176829de8fba407facd3893ce53844e 100644
--- a/lms/djangoapps/edxnotes/tests.py
+++ b/lms/djangoapps/edxnotes/tests.py
@@ -1,38 +1,38 @@
 """
 Tests for the EdxNotes app.
 """
+import json
+import urlparse
 from contextlib import contextmanager
+from datetime import datetime
+from unittest import skipUnless
+
 import ddt
-import json
 import jwt
-from mock import patch, MagicMock
+from django.conf import settings
+from django.core.exceptions import ImproperlyConfigured
+from django.core.urlresolvers import reverse
+from django.test.client import RequestFactory
+from django.test.utils import override_settings
+from edx_oauth2_provider.tests.factories import ClientFactory
+from mock import MagicMock, patch
 from nose.plugins.attrib import attr
-from unittest import skipUnless
-from datetime import datetime
-import urlparse
+from provider.oauth2.models import Client
 
+from courseware.model_data import FieldDataCache
+from courseware.module_render import get_module_for_descriptor
+from courseware.tabs import get_course_tab_list
 from edxmako.shortcuts import render_to_string
 from edxnotes import helpers
 from edxnotes.decorators import edxnotes
 from edxnotes.exceptions import EdxNotesParseError, EdxNotesServiceUnavailable
 from edxnotes.plugins import EdxNotesTab
-from django.conf import settings
-from django.core.urlresolvers import reverse
-from django.core.exceptions import ImproperlyConfigured
-from django.test.client import RequestFactory
-from django.test.utils import override_settings
-from edx_oauth2_provider.tests.factories import ClientFactory
-from provider.oauth2.models import Client
-from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
-from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
+from student.tests.factories import CourseEnrollmentFactory, UserFactory
 from xmodule.modulestore import ModuleStoreEnum
 from xmodule.modulestore.django import modulestore
+from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
 from xmodule.tabs import CourseTab
-from courseware.model_data import FieldDataCache
-from courseware.module_render import get_module_for_descriptor
-from courseware.tabs import get_course_tab_list
-from student.tests.factories import UserFactory, CourseEnrollmentFactory
-
 
 FEATURES = settings.FEATURES.copy()
 
diff --git a/lms/djangoapps/edxnotes/views.py b/lms/djangoapps/edxnotes/views.py
index ad696ddc693915e425e9bd21c85147884c8fab8c..96a582976b33c169d072339eb1d72c118c8a6aa7 100644
--- a/lms/djangoapps/edxnotes/views.py
+++ b/lms/djangoapps/edxnotes/views.py
@@ -3,28 +3,29 @@ Views related to EdxNotes.
 """
 import json
 import logging
-from django.contrib.auth.decorators import login_required
-from django.http import HttpResponse, Http404
+
 from django.conf import settings
+from django.contrib.auth.decorators import login_required
 from django.core.urlresolvers import reverse
+from django.http import Http404, HttpResponse
 from django.views.decorators.http import require_GET
-from edxmako.shortcuts import render_to_response
 from opaque_keys.edx.keys import CourseKey
+
 from courseware.courses import get_course_with_access
 from courseware.model_data import FieldDataCache
 from courseware.module_render import get_module_for_descriptor
-from util.json_request import JsonResponse, JsonResponseBadRequest
+from edxmako.shortcuts import render_to_response
 from edxnotes.exceptions import EdxNotesParseError, EdxNotesServiceUnavailable
 from edxnotes.helpers import (
-    get_edxnotes_id_token,
-    get_notes,
-    is_feature_enabled,
-    get_course_position,
     DEFAULT_PAGE,
     DEFAULT_PAGE_SIZE,
     NoteJSONEncoder,
+    get_course_position,
+    get_edxnotes_id_token,
+    get_notes,
+    is_feature_enabled
 )
-
+from util.json_request import JsonResponse, JsonResponseBadRequest
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/email_marketing/admin.py b/lms/djangoapps/email_marketing/admin.py
index 6ec36bd3833ee403bee529f1251e8a0c48680401..ce338c19741275406eece87f6a8ccbfcca97c290 100644
--- a/lms/djangoapps/email_marketing/admin.py
+++ b/lms/djangoapps/email_marketing/admin.py
@@ -1,8 +1,8 @@
 """ Admin site bindings for email marketing """
 
+from config_models.admin import ConfigurationModelAdmin
 from django.contrib import admin
 
 from email_marketing.models import EmailMarketingConfiguration
-from config_models.admin import ConfigurationModelAdmin
 
 admin.site.register(EmailMarketingConfiguration, ConfigurationModelAdmin)
diff --git a/lms/djangoapps/email_marketing/models.py b/lms/djangoapps/email_marketing/models.py
index d16146e4c5881e860c23b5690e8f296ad6258dfc..7e81095865d9570902c667873caf4d1d73e4cb55 100644
--- a/lms/djangoapps/email_marketing/models.py
+++ b/lms/djangoapps/email_marketing/models.py
@@ -1,11 +1,10 @@
 """
 Email-marketing-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 EmailMarketingConfiguration(ConfigurationModel):
     """ Email marketing configuration """
diff --git a/lms/djangoapps/email_marketing/signals.py b/lms/djangoapps/email_marketing/signals.py
index a8723ea92dd1902f66c94f2e71b18e969271ade3..e83f57eccb2d41d20cfb09627c1af3c3c818abe2 100644
--- a/lms/djangoapps/email_marketing/signals.py
+++ b/lms/djangoapps/email_marketing/signals.py
@@ -1,23 +1,20 @@
 """
 This module contains signals needed for email integration
 """
-import crum
 import datetime
 import logging
 
+import crum
 from django.conf import settings
 from django.dispatch import receiver
+from sailthru.sailthru_client import SailthruClient
+from sailthru.sailthru_error import SailthruClientError
 
+from email_marketing.models import EmailMarketingConfiguration
+from lms.djangoapps.email_marketing.tasks import update_user, update_user_email
 from student.cookies import CREATE_LOGON_COOKIE
 from student.views import REGISTER_USER
-from email_marketing.models import EmailMarketingConfiguration
 from util.model_utils import USER_FIELD_CHANGED
-from lms.djangoapps.email_marketing.tasks import (
-    update_user, update_user_email
-)
-
-from sailthru.sailthru_client import SailthruClient
-from sailthru.sailthru_error import SailthruClientError
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/email_marketing/tasks.py b/lms/djangoapps/email_marketing/tasks.py
index ab29d598756171810e2ee9aeb117f42a6b4dce9c..95955475e25a7b7906bfb476dfc41e57ea98ddc2 100644
--- a/lms/djangoapps/email_marketing/tasks.py
+++ b/lms/djangoapps/email_marketing/tasks.py
@@ -6,13 +6,13 @@ import time
 from datetime import datetime, timedelta
 
 from celery import task
-from django.core.cache import cache
 from django.conf import settings
-
-from email_marketing.models import EmailMarketingConfiguration
+from django.core.cache import cache
 from sailthru.sailthru_client import SailthruClient
 from sailthru.sailthru_error import SailthruClientError
 
+from email_marketing.models import EmailMarketingConfiguration
+
 log = logging.getLogger(__name__)
 SAILTHRU_LIST_CACHE_KEY = "email.marketing.cache"
 
diff --git a/lms/djangoapps/email_marketing/tests/test_signals.py b/lms/djangoapps/email_marketing/tests/test_signals.py
index 764fbc9c7911d0e3f68c2ce34e7656e8cd11fddb..1d12ac0aa7ce0f8416be212f91bdb52421e3cbd6 100644
--- a/lms/djangoapps/email_marketing/tests/test_signals.py
+++ b/lms/djangoapps/email_marketing/tests/test_signals.py
@@ -1,31 +1,34 @@
 """Tests of email marketing signal handlers."""
-import ddt
-import logging
 import datetime
+import logging
 
-from django.test import TestCase
+import ddt
 from django.contrib.auth.models import AnonymousUser
 from django.contrib.sites.models import Site
-from mock import patch, ANY
-from util.json_request import JsonResponse
-from testfixtures import LogCapture
+from django.test import TestCase
+from django.test.client import RequestFactory
 from freezegun import freeze_time
+from mock import ANY, patch
+from opaque_keys.edx.keys import CourseKey
+from sailthru.sailthru_error import SailthruClientError
+from sailthru.sailthru_response import SailthruResponse
+from testfixtures import LogCapture
 
-from email_marketing.signals import email_marketing_register_user, \
-    email_marketing_user_field_changed, \
-    add_email_marketing_cookies
+from email_marketing.models import EmailMarketingConfiguration
+from email_marketing.signals import (
+    add_email_marketing_cookies,
+    email_marketing_register_user,
+    email_marketing_user_field_changed
+)
 from email_marketing.tasks import (
-    update_user, update_user_email, _get_or_create_user_list,
-    _get_list_from_email_marketing_provider, _create_user_list
+    _create_user_list,
+    _get_list_from_email_marketing_provider,
+    _get_or_create_user_list,
+    update_user,
+    update_user_email
 )
-
-from email_marketing.models import EmailMarketingConfiguration
-from django.test.client import RequestFactory
 from student.tests.factories import UserFactory, UserProfileFactory
-from opaque_keys.edx.keys import CourseKey
-
-from sailthru.sailthru_response import SailthruResponse
-from sailthru.sailthru_error import SailthruClientError
+from util.json_request import JsonResponse
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/gating/api.py b/lms/djangoapps/gating/api.py
index cc9287fde4f2309cf2a6e36c33a3848d3d452c77..b8f45b617e36d4bd084f929e4367e7b75c440bd6 100644
--- a/lms/djangoapps/gating/api.py
+++ b/lms/djangoapps/gating/api.py
@@ -1,16 +1,16 @@
 """
 API for the gating djangoapp
 """
-from collections import defaultdict
 import json
 import logging
+from collections import defaultdict
+
+from opaque_keys.edx.keys import UsageKey
 
 from lms.djangoapps.courseware.entrance_exams import get_entrance_exam_content
 from openedx.core.lib.gating import api as gating_api
-from opaque_keys.edx.keys import UsageKey
 from util import milestones_helpers
 
-
 log = logging.getLogger(__name__)
 
 
diff --git a/lms/djangoapps/gating/tests/test_api.py b/lms/djangoapps/gating/tests/test_api.py
index 805eb969408097758fb408f35c542adb48a4bf42..6a5ddec153431b0be6ec3a1ec6b93b66764e0f02 100644
--- a/lms/djangoapps/gating/tests/test_api.py
+++ b/lms/djangoapps/gating/tests/test_api.py
@@ -1,17 +1,17 @@
 """
 Unit tests for gating.signals module
 """
-from mock import patch, Mock
-from nose.plugins.attrib import attr
-from ddt import ddt, data, unpack
-from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
-from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
-from courseware.tests.helpers import LoginEnrollmentTestCase
-
+from ddt import data, ddt, unpack
 from milestones import api as milestones_api
 from milestones.tests.utils import MilestonesTestCaseMixin
-from openedx.core.lib.gating import api as gating_api
+from mock import Mock, patch
+from nose.plugins.attrib import attr
+
+from courseware.tests.helpers import LoginEnrollmentTestCase
 from gating.api import evaluate_prerequisite
+from openedx.core.lib.gating import api as gating_api
+from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
 
 
 class GatingTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
diff --git a/lms/djangoapps/gating/tests/test_integration.py b/lms/djangoapps/gating/tests/test_integration.py
index 8c00bb7565c6323f36bf89a63fc423f70d136b24..f4b60dca3e56f8050e98440e45047c5cd7f890e7 100644
--- a/lms/djangoapps/gating/tests/test_integration.py
+++ b/lms/djangoapps/gating/tests/test_integration.py
@@ -2,20 +2,20 @@
 Integration tests for gated content.
 """
 import ddt
+from milestones import api as milestones_api
+from milestones.tests.utils import MilestonesTestCaseMixin
 from nose.plugins.attrib import attr
-from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
 
 from lms.djangoapps.courseware.access import has_access
-from lms.djangoapps.grades.tests.utils import answer_problem
 from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory
-from milestones import api as milestones_api
-from milestones.tests.utils import MilestonesTestCaseMixin
+from lms.djangoapps.grades.tests.utils import answer_problem
 from openedx.core.djangolib.testing.utils import get_mock_request
 from openedx.core.lib.gating import api as gating_api
 from request_cache.middleware import RequestCache
 from student.tests.factories import UserFactory
 from xmodule.modulestore.django import modulestore
 from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
 
 
 @attr(shard=3)
diff --git a/lms/djangoapps/gating/tests/test_signals.py b/lms/djangoapps/gating/tests/test_signals.py
index f88dbf15ae8342e4c17d9ef8bc7ad6562f95601f..6b564764877a823b32ad15c8afec61afde5123dc 100644
--- a/lms/djangoapps/gating/tests/test_signals.py
+++ b/lms/djangoapps/gating/tests/test_signals.py
@@ -1,14 +1,13 @@
 """
 Unit tests for gating.signals module
 """
-from mock import patch, Mock
+from mock import Mock, patch
 
+from gating.signals import evaluate_subsection_gated_milestones
 from student.tests.factories import UserFactory
+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 gating.signals import evaluate_subsection_gated_milestones
 
 
 class TestHandleScoreChanged(ModuleStoreTestCase):
diff --git a/lms/djangoapps/grades/admin.py b/lms/djangoapps/grades/admin.py
index aaecba7295542d447c8350102a933350a41b3911..0527c20b355261a8e7ab4132a471c66432dd70ff 100644
--- a/lms/djangoapps/grades/admin.py
+++ b/lms/djangoapps/grades/admin.py
@@ -1,16 +1,15 @@
 """
 Django admin page for grades models
 """
-from django.contrib import admin
-
 from config_models.admin import ConfigurationModelAdmin, KeyedConfigurationModelAdmin
+from django.contrib import admin
 
+from lms.djangoapps.grades.config.forms import CoursePersistentGradesAdminForm
 from lms.djangoapps.grades.config.models import (
-    CoursePersistentGradesFlag,
-    PersistentGradesEnabledFlag,
     ComputeGradesSetting,
+    CoursePersistentGradesFlag,
+    PersistentGradesEnabledFlag
 )
-from lms.djangoapps.grades.config.forms import CoursePersistentGradesAdminForm
 
 
 class CoursePersistentGradesAdmin(KeyedConfigurationModelAdmin):
diff --git a/lms/djangoapps/grades/api/serializers.py b/lms/djangoapps/grades/api/serializers.py
index be50412fcedcec67565633aa87684a94c4e27801..6ecc58f8ed195b36bdd82e6fc0ba7a1881860479 100644
--- a/lms/djangoapps/grades/api/serializers.py
+++ b/lms/djangoapps/grades/api/serializers.py
@@ -2,6 +2,7 @@
 API Serializers
 """
 from collections import defaultdict
+
 from rest_framework import serializers
 
 
diff --git a/lms/djangoapps/grades/api/tests/test_views.py b/lms/djangoapps/grades/api/tests/test_views.py
index ffa4a4238f29a2c0b4d598d6ab1a612dd44d3163..2aa6f8502b341c064214d63b4784bb10b676bdd6 100644
--- a/lms/djangoapps/grades/api/tests/test_views.py
+++ b/lms/djangoapps/grades/api/tests/test_views.py
@@ -2,23 +2,24 @@
 Tests for the views
 """
 from datetime import datetime
+from urllib import urlencode
+
 import ddt
 from django.core.urlresolvers import reverse
+from edx_oauth2_provider.tests.factories import AccessTokenFactory, ClientFactory
 from mock import patch
 from opaque_keys import InvalidKeyError
 from pytz import UTC
 from rest_framework import status
 from rest_framework.test import APITestCase
-from urllib import urlencode
 
 from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory
-from edx_oauth2_provider.tests.factories import AccessTokenFactory, ClientFactory
 from lms.djangoapps.courseware.tests.factories import GlobalStaffFactory, StaffFactory
 from lms.djangoapps.grades.tests.utils import mock_get_score
 from student.tests.factories import CourseEnrollmentFactory, UserFactory
 from xmodule.modulestore import ModuleStoreEnum
+from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase
 from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls
-from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase, TEST_DATA_SPLIT_MODULESTORE
 
 
 @ddt.ddt
diff --git a/lms/djangoapps/grades/api/urls.py b/lms/djangoapps/grades/api/urls.py
index 1ffb446af649b0ff4a4afd15321980b85dc1041b..c4ee1b0c097f199fdd0fc1620e5ad129adba323e 100644
--- a/lms/djangoapps/grades/api/urls.py
+++ b/lms/djangoapps/grades/api/urls.py
@@ -1,9 +1,6 @@
 """ Grades API URLs. """
 from django.conf import settings
-from django.conf.urls import (
-    patterns,
-    url,
-)
+from django.conf.urls import patterns, url
 
 from lms.djangoapps.grades.api import views
 
diff --git a/lms/djangoapps/grades/config/forms.py b/lms/djangoapps/grades/config/forms.py
index 5db1d6a29d230be5d73717c49fa87adf01dbd9ed..d1561c46d0c7f0302ce169b02f6b15186d14c26e 100644
--- a/lms/djangoapps/grades/config/forms.py
+++ b/lms/djangoapps/grades/config/forms.py
@@ -4,12 +4,11 @@ Defines a form for providing validation of subsection grade templates.
 import logging
 
 from django import forms
+from opaque_keys import InvalidKeyError
+from opaque_keys.edx.locator import CourseLocator
 
 from lms.djangoapps.grades.config.models import CoursePersistentGradesFlag
-
-from opaque_keys import InvalidKeyError
 from xmodule.modulestore.django import modulestore
-from opaque_keys.edx.locator import CourseLocator
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/grades/config/models.py b/lms/djangoapps/grades/config/models.py
index e0e745ca76d6e07f519afea8ef1cffe6bc3a1b69..647ce303882497c34bb5eaeb082e9c9b39734d4c 100644
--- a/lms/djangoapps/grades/config/models.py
+++ b/lms/djangoapps/grades/config/models.py
@@ -5,6 +5,7 @@ controlling persistent grades.
 from config_models.models import ConfigurationModel
 from django.conf import settings
 from django.db.models import BooleanField, IntegerField, TextField
+
 from openedx.core.djangoapps.xmodule_django.models import CourseKeyField
 from request_cache.middleware import request_cached
 
diff --git a/lms/djangoapps/grades/config/tests/test_models.py b/lms/djangoapps/grades/config/tests/test_models.py
index d8eef844402ff69a4bb1d878afa31baa284f7cfa..b14fde2405b91a0865cd982ba601ae05e71f2f54 100644
--- a/lms/djangoapps/grades/config/tests/test_models.py
+++ b/lms/djangoapps/grades/config/tests/test_models.py
@@ -2,13 +2,14 @@
 Tests for the models that control the
 persistent grading feature.
 """
-import ddt
-from django.conf import settings
 import itertools
-from mock import patch
 
+import ddt
+from django.conf import settings
 from django.test import TestCase
+from mock import patch
 from opaque_keys.edx.locator import CourseLocator
+
 from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag
 from lms.djangoapps.grades.config.tests.utils import persistent_grades_feature_flags
 
diff --git a/lms/djangoapps/grades/config/tests/utils.py b/lms/djangoapps/grades/config/tests/utils.py
index f01e3d920b27d3bc190f6e14e37da6521495070b..a948a8329e45fcbd91f3941504cacbb2f89c6993 100644
--- a/lms/djangoapps/grades/config/tests/utils.py
+++ b/lms/djangoapps/grades/config/tests/utils.py
@@ -3,7 +3,8 @@ Provides helper functions for tests that want
 to configure flags related to persistent grading.
 """
 from contextlib import contextmanager
-from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag, CoursePersistentGradesFlag
+
+from lms.djangoapps.grades.config.models import CoursePersistentGradesFlag, PersistentGradesEnabledFlag
 from request_cache.middleware import RequestCache
 
 
diff --git a/lms/djangoapps/grades/config/waffle.py b/lms/djangoapps/grades/config/waffle.py
index 54c9b5b3b87bb9611f606718f13ed351cf67bbab..c5705ac49112fe7b7c77ff744ac9f44838c95c23 100644
--- a/lms/djangoapps/grades/config/waffle.py
+++ b/lms/djangoapps/grades/config/waffle.py
@@ -4,7 +4,6 @@ waffle switches for the Grades app.
 """
 from openedx.core.djangoapps.waffle_utils import WaffleSwitchNamespace
 
-
 # Namespace
 WAFFLE_NAMESPACE = u'grades'
 
diff --git a/lms/djangoapps/grades/context.py b/lms/djangoapps/grades/context.py
index cb9c88a2c4b9626f6819423489100a257185f990..3b643a6133d398233af299950a0e154f1e86835d 100644
--- a/lms/djangoapps/grades/context.py
+++ b/lms/djangoapps/grades/context.py
@@ -2,6 +2,7 @@
 Grading Context
 """
 from collections import OrderedDict
+
 from openedx.core.djangoapps.content.block_structure.api import get_course_in_cache
 
 from .scores import possibly_scored
diff --git a/lms/djangoapps/grades/management/commands/compute_grades.py b/lms/djangoapps/grades/management/commands/compute_grades.py
index 185671b77a6623d4e19ef33ce9d9bdb2a273be32..9b10d4d7b295c5cfa2415d898053a1238a916771 100644
--- a/lms/djangoapps/grades/management/commands/compute_grades.py
+++ b/lms/djangoapps/grades/management/commands/compute_grades.py
@@ -7,20 +7,16 @@ from __future__ import absolute_import, division, print_function, unicode_litera
 import hashlib
 import logging
 
-from django.core.management.base import BaseCommand
 import six
+from django.core.management.base import BaseCommand
 
-from openedx.core.lib.command_utils import (
-    get_mutually_exclusive_required_option,
-    parse_course_keys,
-)
 from lms.djangoapps.grades.config.models import ComputeGradesSetting
+from openedx.core.lib.command_utils import get_mutually_exclusive_required_option, parse_course_keys
 from student.models import CourseEnrollment
 from xmodule.modulestore.django import modulestore
 
 from ... import tasks
 
-
 log = logging.getLogger(__name__)
 
 
diff --git a/lms/djangoapps/grades/management/commands/get_grades.py b/lms/djangoapps/grades/management/commands/get_grades.py
index fcdff39e21f4c02d19172422335073cf777396e0..93f072488a56282e05484aff35a80c2cdc3b34af 100644
--- a/lms/djangoapps/grades/management/commands/get_grades.py
+++ b/lms/djangoapps/grades/management/commands/get_grades.py
@@ -2,20 +2,22 @@
 Management command to generate a list of grades for
 all students that are enrolled in a course.
 """
-from django.test.client import RequestFactory
-from django.core.management.base import BaseCommand, CommandError
+import csv
+import datetime
 import os
-from lms.djangoapps.courseware import courses
-from lms.djangoapps.certificates.models import GeneratedCertificate
-from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory
+from optparse import make_option
+
+from django.contrib.auth.models import User
+from django.core.handlers.base import BaseHandler
+from django.core.management.base import BaseCommand, CommandError
+from django.test.client import RequestFactory
 from opaque_keys import InvalidKeyError
 from opaque_keys.edx.keys import CourseKey
 from opaque_keys.edx.locations import SlashSeparatedCourseKey
-from django.contrib.auth.models import User
-from optparse import make_option
-import datetime
-from django.core.handlers.base import BaseHandler
-import csv
+
+from lms.djangoapps.certificates.models import GeneratedCertificate
+from lms.djangoapps.courseware import courses
+from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory
 
 
 class RequestMock(RequestFactory):
diff --git a/lms/djangoapps/grades/management/commands/recalculate_subsection_grades.py b/lms/djangoapps/grades/management/commands/recalculate_subsection_grades.py
index 9384a3066b8b725109b8d2a85b18c48733d8a3b0..9cd4ffeccc4966484cb21c96553fdc462b3e9570 100644
--- a/lms/djangoapps/grades/management/commands/recalculate_subsection_grades.py
+++ b/lms/djangoapps/grades/management/commands/recalculate_subsection_grades.py
@@ -5,15 +5,16 @@ in the specified time range.
 
 from __future__ import absolute_import, division, print_function, unicode_literals
 
-from datetime import datetime
 import logging
-from pytz import utc
+from datetime import datetime
 
 from django.core.management.base import BaseCommand, CommandError
+from pytz import utc
+
+from courseware.models import StudentModule
 from lms.djangoapps.grades.constants import ScoreDatabaseTableEnum
 from lms.djangoapps.grades.signals.handlers import PROBLEM_SUBMITTED_EVENT_TYPE
 from lms.djangoapps.grades.tasks import recalculate_subsection_grade_v3
-from courseware.models import StudentModule
 from student.models import user_by_anonymous_id
 from submissions.models import Submission
 from track.event_transaction_utils import create_new_event_transaction_id, set_event_transaction_type
diff --git a/lms/djangoapps/grades/management/commands/reset_grades.py b/lms/djangoapps/grades/management/commands/reset_grades.py
index 811ffbda8e3dbe604fe67b1fb4913d51ab43ecb4..b22a100c1f2d894a8b805bc689a8d087362d1b58 100644
--- a/lms/djangoapps/grades/management/commands/reset_grades.py
+++ b/lms/djangoapps/grades/management/commands/reset_grades.py
@@ -1,17 +1,16 @@
 """
 Reset persistent grades for learners.
 """
-from datetime import datetime
 import logging
-from pytz import utc
+from datetime import datetime
 from textwrap import dedent
 
 from django.core.management.base import BaseCommand, CommandError
 from django.db.models import Count
+from pytz import utc
 
+from lms.djangoapps.grades.models import PersistentCourseGrade, PersistentSubsectionGrade
 from openedx.core.lib.command_utils import get_mutually_exclusive_required_option, parse_course_keys
-from lms.djangoapps.grades.models import PersistentSubsectionGrade, PersistentCourseGrade
-
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/grades/management/commands/tests/test_compute_grades.py b/lms/djangoapps/grades/management/commands/tests/test_compute_grades.py
index 0c210ff0f91907d4d62961f39e4e3b647d5d9ad6..ee772997182a905805cf3ec532cd28202e689c3c 100644
--- a/lms/djangoapps/grades/management/commands/tests/test_compute_grades.py
+++ b/lms/djangoapps/grades/management/commands/tests/test_compute_grades.py
@@ -7,18 +7,17 @@ Tests for compute_grades management command.
 from __future__ import absolute_import, division, print_function, unicode_literals
 
 import ddt
+import six
 from django.contrib.auth import get_user_model
 from django.core.management import CommandError, call_command
 from mock import ANY, patch
-import six
 
+from lms.djangoapps.grades.config.models import ComputeGradesSetting
+from lms.djangoapps.grades.management.commands import compute_grades
 from student.models import CourseEnrollment
 from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
 from xmodule.modulestore.tests.factories import CourseFactory
 
-from lms.djangoapps.grades.config.models import ComputeGradesSetting
-from lms.djangoapps.grades.management.commands import compute_grades
-
 
 def _sorted_by_batch(calls):
     """
diff --git a/lms/djangoapps/grades/management/commands/tests/test_recalculate_subsection_grades.py b/lms/djangoapps/grades/management/commands/tests/test_recalculate_subsection_grades.py
index 2e57da10efa025e7d4b0d8573e6baf6d5e068b00..ec349e02d66096b366ff56bc1cd2c08116a65aae 100644
--- a/lms/djangoapps/grades/management/commands/tests/test_recalculate_subsection_grades.py
+++ b/lms/djangoapps/grades/management/commands/tests/test_recalculate_subsection_grades.py
@@ -2,14 +2,15 @@
 Tests for reset_grades management command.
 """
 
-import ddt
 from datetime import datetime
+
+import ddt
 from django.conf import settings
-from mock import patch, MagicMock
+from mock import MagicMock, patch
 from pytz import utc
 
-from lms.djangoapps.grades.management.commands import recalculate_subsection_grades
 from lms.djangoapps.grades.constants import ScoreDatabaseTableEnum
+from lms.djangoapps.grades.management.commands import recalculate_subsection_grades
 from lms.djangoapps.grades.tests.test_tasks import HasCourseWithProblemsMixin
 from track.event_transaction_utils import get_event_transaction_id
 from util.date_utils import to_timestamp
diff --git a/lms/djangoapps/grades/management/commands/tests/test_reset_grades.py b/lms/djangoapps/grades/management/commands/tests/test_reset_grades.py
index 3cfbbaf5e855e324f1fcbcb5f2b6a1bcf1152de3..be57882af6e660278f29948e5527315674a47a96 100644
--- a/lms/djangoapps/grades/management/commands/tests/test_reset_grades.py
+++ b/lms/djangoapps/grades/management/commands/tests/test_reset_grades.py
@@ -2,15 +2,16 @@
 Tests for reset_grades management command.
 """
 from datetime import datetime, timedelta
+
 import ddt
 from django.core.management.base import CommandError
 from django.test import TestCase
 from freezegun import freeze_time
-from mock import patch, MagicMock
+from mock import MagicMock, patch
+from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator
 
 from lms.djangoapps.grades.management.commands import reset_grades
-from lms.djangoapps.grades.models import PersistentSubsectionGrade, PersistentCourseGrade
-from opaque_keys.edx.locator import CourseLocator, BlockUsageLocator
+from lms.djangoapps.grades.models import PersistentCourseGrade, PersistentSubsectionGrade
 
 
 @ddt.ddt
diff --git a/lms/djangoapps/grades/models.py b/lms/djangoapps/grades/models.py
index 716f330db5c0983ba835bc27fd4cd0eacc5a9658..b4d0c2c01e893b0bc984ff1bbd1fba5e7831c98e 100644
--- a/lms/djangoapps/grades/models.py
+++ b/lms/djangoapps/grades/models.py
@@ -8,24 +8,24 @@ a student's score or the course grading policy changes. As they are
 persisted, course grades are also immune to changes in course content.
 """
 
+import json
+import logging
 from base64 import b64encode
 from collections import namedtuple
 from hashlib import sha1
-import json
-from lazy import lazy
-import logging
 
 from django.db import models
 from django.utils.timezone import now
-from eventtracking import tracker
+from lazy import lazy
 from model_utils.models import TimeStampedModel
-from track import contexts
-from track.event_transaction_utils import get_event_transaction_id, get_event_transaction_type
+from opaque_keys.edx.keys import CourseKey, UsageKey
 
 from coursewarehistoryextended.fields import UnsignedBigIntAutoField
-from opaque_keys.edx.keys import CourseKey, UsageKey
+from eventtracking import tracker
 from openedx.core.djangoapps.xmodule_django.models import CourseKeyField, UsageKeyField
 from request_cache import get_cache
+from track import contexts
+from track.event_transaction_utils import get_event_transaction_id, get_event_transaction_type
 
 from .config import waffle
 
diff --git a/lms/djangoapps/grades/new/course_data.py b/lms/djangoapps/grades/new/course_data.py
index c1a03d5fc393943c089fd5da49074e3f1e5b8af3..4ceb86dc2a7a6902d53456740f4672c5127a274b 100644
--- a/lms/djangoapps/grades/new/course_data.py
+++ b/lms/djangoapps/grades/new/course_data.py
@@ -1,6 +1,7 @@
 from lms.djangoapps.course_blocks.api import get_course_blocks
 from openedx.core.djangoapps.content.block_structure.api import get_block_structure_manager
 from xmodule.modulestore.django import modulestore
+
 from ..transformer import GradesTransformer
 
 
diff --git a/lms/djangoapps/grades/new/course_grade.py b/lms/djangoapps/grades/new/course_grade.py
index 7dc18bfae2e7d26886a0a606ca9ddbd4cda4f3cc..1783db8ef7693113f6cdbae3eda69e403da58e02 100644
--- a/lms/djangoapps/grades/new/course_grade.py
+++ b/lms/djangoapps/grades/new/course_grade.py
@@ -2,13 +2,15 @@
 CourseGrade Class
 """
 from abc import abstractmethod
-from collections import defaultdict, OrderedDict
+from collections import OrderedDict, defaultdict
+
 from django.conf import settings
 from lazy import lazy
 
 from xmodule import block_metadata_utils
-from .subsection_grade_factory import SubsectionGradeFactory
+
 from .subsection_grade import ZeroSubsectionGrade
+from .subsection_grade_factory import SubsectionGradeFactory
 
 
 class CourseGradeBase(object):
diff --git a/lms/djangoapps/grades/new/course_grade_factory.py b/lms/djangoapps/grades/new/course_grade_factory.py
index 716cf13c77e683a71af2062f31debbe2c5835a9d..56b4eca040164f75925249a8c43b63060a238372 100644
--- a/lms/djangoapps/grades/new/course_grade_factory.py
+++ b/lms/djangoapps/grades/new/course_grade_factory.py
@@ -1,16 +1,15 @@
 from collections import namedtuple
-import dogstats_wrapper as dog_stats_api
 from logging import getLogger
 
+import dogstats_wrapper as dog_stats_api
 from openedx.core.djangoapps.signals.signals import COURSE_GRADE_CHANGED
 
 from ..config import assume_zero_if_absent, should_persist_grades
-from ..config.waffle import waffle, WRITE_ONLY_IF_ENGAGED
+from ..config.waffle import WRITE_ONLY_IF_ENGAGED, waffle
 from ..models import PersistentCourseGrade
 from .course_data import CourseData
 from .course_grade import CourseGrade, ZeroCourseGrade
 
-
 log = getLogger(__name__)
 
 
diff --git a/lms/djangoapps/grades/new/subsection_grade.py b/lms/djangoapps/grades/new/subsection_grade.py
index 2595f062951428037b7c3b828bf503a4ab39e8ef..407e9582ce7d8969bdd5d3bc429e8a71066d5482 100644
--- a/lms/djangoapps/grades/new/subsection_grade.py
+++ b/lms/djangoapps/grades/new/subsection_grade.py
@@ -2,15 +2,16 @@
 SubsectionGrade Class
 """
 from collections import OrderedDict
-from lazy import lazy
 from logging import getLogger
-from lms.djangoapps.grades.scores import get_score, possibly_scored
+
+from lazy import lazy
+
 from lms.djangoapps.grades.models import BlockRecord, PersistentSubsectionGrade
+from lms.djangoapps.grades.scores import get_score, possibly_scored
 from xmodule import block_metadata_utils, graders
 from xmodule.graders import AggregatedScore, ShowCorrectness
 
-from ..config.waffle import waffle, WRITE_ONLY_IF_ENGAGED
-
+from ..config.waffle import WRITE_ONLY_IF_ENGAGED, waffle
 
 log = getLogger(__name__)
 
diff --git a/lms/djangoapps/grades/new/subsection_grade_factory.py b/lms/djangoapps/grades/new/subsection_grade_factory.py
index 2960b5d626a075e49b924fa3d2f7ef2a8d9f71df..6a97b31705d94b184ab0856a177fc4c1e75484d9 100644
--- a/lms/djangoapps/grades/new/subsection_grade_factory.py
+++ b/lms/djangoapps/grades/new/subsection_grade_factory.py
@@ -1,18 +1,18 @@
-from lazy import lazy
 from logging import getLogger
 
+from lazy import lazy
+
 from courseware.model_data import ScoresClient
+from lms.djangoapps.grades.config import assume_zero_if_absent, should_persist_grades
+from lms.djangoapps.grades.models import PersistentSubsectionGrade
+from lms.djangoapps.grades.scores import possibly_scored
 from openedx.core.lib.grade_utils import is_score_higher_or_equal
 from student.models import anonymous_id_for_user
 from submissions import api as submissions_api
 
-from lms.djangoapps.grades.config import should_persist_grades, assume_zero_if_absent
-from lms.djangoapps.grades.models import PersistentSubsectionGrade
-from lms.djangoapps.grades.scores import possibly_scored
 from .course_data import CourseData
 from .subsection_grade import SubsectionGrade, ZeroSubsectionGrade
 
-
 log = getLogger(__name__)
 
 
diff --git a/lms/djangoapps/grades/scores.py b/lms/djangoapps/grades/scores.py
index 459f576be95976fab877f85f57b22405f3d290d2..34345771732d76aaeb16c69a3052a4d838136dba 100644
--- a/lms/djangoapps/grades/scores.py
+++ b/lms/djangoapps/grades/scores.py
@@ -3,11 +3,12 @@ Functionality for problem scores.
 """
 from logging import getLogger
 
-from openedx.core.lib.cache_utils import memoized
 from xblock.core import XBlock
+
+from openedx.core.lib.cache_utils import memoized
 from xmodule.graders import ProblemScore
-from .transformer import GradesTransformer
 
+from .transformer import GradesTransformer
 
 log = getLogger(__name__)
 
diff --git a/lms/djangoapps/grades/signals/handlers.py b/lms/djangoapps/grades/signals/handlers.py
index 4bddf058295902256d4d3c318c235ba3d936bf77..4b5e15e08a0159becaa0bfe6c65456009f40af08 100644
--- a/lms/djangoapps/grades/signals/handlers.py
+++ b/lms/djangoapps/grades/signals/handlers.py
@@ -2,34 +2,35 @@
 Grades related signals.
 """
 from contextlib import contextmanager
-from crum import get_current_user
 from logging import getLogger
 
+from crum import get_current_user
 from django.dispatch import receiver
-from submissions.models import score_set, score_reset
 from xblock.scorable import ScorableXBlockMixin, Score
 
 from courseware.model_data import get_score, set_score
 from eventtracking import tracker
 from openedx.core.lib.grade_utils import is_score_higher_or_equal
 from student.models import user_by_anonymous_id
-from util.date_utils import to_timestamp
+from submissions.models import score_reset, score_set
 from track.event_transaction_utils import (
-    get_event_transaction_type,
+    create_new_event_transaction_id,
     get_event_transaction_id,
-    set_event_transaction_type,
-    create_new_event_transaction_id
+    get_event_transaction_type,
+    set_event_transaction_type
 )
+from util.date_utils import to_timestamp
+
+from ..constants import ScoreDatabaseTableEnum
+from ..new.course_grade_factory import CourseGradeFactory
+from ..scores import weighted_score
+from ..tasks import RECALCULATE_GRADE_DELAY, recalculate_subsection_grade_v3
 from .signals import (
     PROBLEM_RAW_SCORE_CHANGED,
     PROBLEM_WEIGHTED_SCORE_CHANGED,
-    SUBSECTION_SCORE_CHANGED,
     SCORE_PUBLISHED,
+    SUBSECTION_SCORE_CHANGED
 )
-from ..constants import ScoreDatabaseTableEnum
-from ..new.course_grade_factory import CourseGradeFactory
-from ..scores import weighted_score
-from ..tasks import recalculate_subsection_grade_v3, RECALCULATE_GRADE_DELAY
 
 log = getLogger(__name__)
 
diff --git a/lms/djangoapps/grades/signals/signals.py b/lms/djangoapps/grades/signals/signals.py
index 0cf2976db4a9f3d6e2ccb575c95ea2d2391397ea..b1c4c4f32f194d1769c15f66749e6ff80db607d4 100644
--- a/lms/djangoapps/grades/signals/signals.py
+++ b/lms/djangoapps/grades/signals/signals.py
@@ -3,6 +3,9 @@ Grades related signals.
 """
 from django.dispatch import Signal
 
+# Signal that indicates that a user's grade for a course has been updated.
+# This is a downstream signal of SUBSECTION_SCORE_CHANGED.
+from openedx.core.djangoapps.signals.signals import COURSE_GRADE_CHANGED
 
 # Signal that indicates that a user's raw score for a problem has been updated.
 # This signal is generated when a scoring event occurs within the core
@@ -78,8 +81,3 @@ SUBSECTION_SCORE_CHANGED = Signal(
         'subsection_grade',  # SubsectionGrade object
     ]
 )
-
-
-# Signal that indicates that a user's grade for a course has been updated.
-# This is a downstream signal of SUBSECTION_SCORE_CHANGED.
-from openedx.core.djangoapps.signals.signals import COURSE_GRADE_CHANGED
diff --git a/lms/djangoapps/grades/tasks.py b/lms/djangoapps/grades/tasks.py
index cda788cb6b05d6d34fc547b656ac4264716af658..e03b4076418b3da331434e05399afe4ec721e8c0 100644
--- a/lms/djangoapps/grades/tasks.py
+++ b/lms/djangoapps/grades/tasks.py
@@ -2,44 +2,39 @@
 This module contains tasks for asynchronous execution of grade updates.
 """
 
+from logging import getLogger
+
+import six
 from celery import task
+from celery_utils.logged_task import LoggedTask
+from celery_utils.persist_on_failure import PersistOnFailureTask
 from django.conf import settings
 from django.contrib.auth.models import User
 from django.core.exceptions import ValidationError
 from django.db.utils import DatabaseError
-from logging import getLogger
-
-log = getLogger(__name__)
-import six
+from opaque_keys.edx.keys import CourseKey, UsageKey
+from opaque_keys.edx.locator import CourseLocator
 
-from celery_utils.logged_task import LoggedTask
-from celery_utils.persist_on_failure import PersistOnFailureTask
 from courseware.model_data import get_score
 from lms.djangoapps.course_blocks.api import get_course_blocks
 from lms.djangoapps.courseware import courses
 from lms.djangoapps.grades.config.models import ComputeGradesSetting
-from opaque_keys.edx.keys import CourseKey, UsageKey
-from opaque_keys.edx.locator import CourseLocator
-from openedx.core.djangoapps.monitoring_utils import (
-    set_custom_metrics_for_course_key, set_custom_metric
-)
+from openedx.core.djangoapps.monitoring_utils import set_custom_metric, set_custom_metrics_for_course_key
 from student.models import CourseEnrollment
 from submissions import api as sub_api
-from track.event_transaction_utils import (
-    set_event_transaction_type,
-    set_event_transaction_id,
-)
+from track.event_transaction_utils import set_event_transaction_id, set_event_transaction_type
 from util.date_utils import from_timestamp
 from xmodule.modulestore.django import modulestore
 
-from .config.waffle import waffle, ESTIMATE_FIRST_ATTEMPTED
+from .config.waffle import ESTIMATE_FIRST_ATTEMPTED, waffle
 from .constants import ScoreDatabaseTableEnum
 from .exceptions import DatabaseNotReadyError
-from .new.subsection_grade_factory import SubsectionGradeFactory
 from .new.course_grade_factory import CourseGradeFactory
+from .new.subsection_grade_factory import SubsectionGradeFactory
 from .signals.signals import SUBSECTION_SCORE_CHANGED
 from .transformer import GradesTransformer
 
+log = getLogger(__name__)
 
 KNOWN_RETRY_ERRORS = (  # Errors we expect occasionally, should be resolved on retry
     DatabaseError,
diff --git a/lms/djangoapps/grades/tests/integration/test_access.py b/lms/djangoapps/grades/tests/integration/test_access.py
index cdc97638f578e1e21bb409952273cf329bed2a4b..99f95b467520cb85ffafac4a2ad727d4194e3e3c 100644
--- a/lms/djangoapps/grades/tests/integration/test_access.py
+++ b/lms/djangoapps/grades/tests/integration/test_access.py
@@ -4,16 +4,15 @@ Test grading with access changes.
 # pylint: disable=protected-access
 
 from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory
+from courseware.tests.test_submitting_problems import ProblemSubmissionTestMixin
 from lms.djangoapps.course_blocks.api import get_course_blocks
 from openedx.core.djangolib.testing.utils import get_mock_request
-from xmodule.modulestore.django import modulestore
-from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
-from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
-
-from courseware.tests.test_submitting_problems import ProblemSubmissionTestMixin
 from student.models import CourseEnrollment
 from student.tests.factories import UserFactory
 from xmodule.modulestore import ModuleStoreEnum
+from xmodule.modulestore.django import modulestore
+from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
 
 from ...new.subsection_grade_factory import SubsectionGradeFactory
 
diff --git a/lms/djangoapps/grades/tests/integration/test_events.py b/lms/djangoapps/grades/tests/integration/test_events.py
index bd062841c7c7527b9a1ff231bf64ccf5a55be5e7..6950775a3f960560146f7ce3d664e99856573b78 100644
--- a/lms/djangoapps/grades/tests/integration/test_events.py
+++ b/lms/djangoapps/grades/tests/integration/test_events.py
@@ -3,18 +3,18 @@ Test grading events across apps.
 """
 # pylint: disable=protected-access
 
+from mock import patch
+
 from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory
+from courseware.tests.test_submitting_problems import ProblemSubmissionTestMixin
 from lms.djangoapps.instructor.enrollment import reset_student_attempts
 from lms.djangoapps.instructor_task.api import submit_rescore_problem_for_student
-from mock import patch
 from openedx.core.djangolib.testing.utils import get_mock_request
-from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
-from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
-
-from courseware.tests.test_submitting_problems import ProblemSubmissionTestMixin
 from student.models import CourseEnrollment
 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 CourseFactory, ItemFactory
 
 STATE_DELETED_TYPE = 'edx.grades.problem.state_deleted'
 RESCORE_TYPE = 'edx.grades.problem.rescored'
diff --git a/lms/djangoapps/grades/tests/test_course_data.py b/lms/djangoapps/grades/tests/test_course_data.py
index 6705ec803772493841c869cdd49f0a3d5d2016a8..05ead22b3ebb504bb81c57e24c301c6905a5e2b8 100644
--- a/lms/djangoapps/grades/tests/test_course_data.py
+++ b/lms/djangoapps/grades/tests/test_course_data.py
@@ -9,6 +9,7 @@ from student.tests.factories import UserFactory
 from xmodule.modulestore import ModuleStoreEnum
 from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
 from xmodule.modulestore.tests.factories import CourseFactory
+
 from ..new.course_data import CourseData
 
 
diff --git a/lms/djangoapps/grades/tests/test_grades.py b/lms/djangoapps/grades/tests/test_grades.py
index f7d6684ce0c5ac900d75d8895d165f2766dc184a..371062adffe6f7729b139a227d9f79d4d15e958e 100644
--- a/lms/djangoapps/grades/tests/test_grades.py
+++ b/lms/djangoapps/grades/tests/test_grades.py
@@ -13,16 +13,16 @@ from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory
 from lms.djangoapps.course_blocks.api import get_course_blocks
 from openedx.core.djangoapps.content.block_structure.factory import BlockStructureFactory
 from openedx.core.djangolib.testing.utils import get_mock_request
-from student.tests.factories import UserFactory
 from student.models import CourseEnrollment
+from student.tests.factories import UserFactory
 from xmodule.graders import ProblemScore
 from xmodule.modulestore import ModuleStoreEnum
-from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
 from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
 
-from .utils import answer_problem
 from ..new.course_grade_factory import CourseGradeFactory
 from ..new.subsection_grade_factory import SubsectionGradeFactory
+from .utils import answer_problem
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/grades/tests/test_models.py b/lms/djangoapps/grades/tests/test_models.py
index b7a70dd6b743924c8819a488bac58498cf22b025..5ea10805db0b305f4f044c4d55b2fa55c4e03ae5 100644
--- a/lms/djangoapps/grades/tests/test_models.py
+++ b/lms/djangoapps/grades/tests/test_models.py
@@ -1,31 +1,31 @@
 """
 Unit tests for grades models.
 """
+import json
 from base64 import b64encode
 from collections import OrderedDict
 from datetime import datetime
-import ddt
 from hashlib import sha1
-import json
-from mock import patch
 
+import ddt
+import pytz
 from django.db.utils import IntegrityError
 from django.test import TestCase
 from django.utils.timezone import now
 from freezegun import freeze_time
-from opaque_keys.edx.locator import CourseLocator, BlockUsageLocator
-import pytz
-from track.event_transaction_utils import get_event_transaction_id, get_event_transaction_type
+from mock import patch
+from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator
 
 from lms.djangoapps.grades.config import waffle
 from lms.djangoapps.grades.models import (
+    BLOCK_RECORD_LIST_VERSION,
     BlockRecord,
     BlockRecordList,
-    BLOCK_RECORD_LIST_VERSION,
     PersistentCourseGrade,
     PersistentSubsectionGrade,
     VisibleBlocks
 )
+from track.event_transaction_utils import get_event_transaction_id, get_event_transaction_type
 
 
 class BlockRecordListTestCase(TestCase):
diff --git a/lms/djangoapps/grades/tests/test_new.py b/lms/djangoapps/grades/tests/test_new.py
index 99549856d66b2fc14a31f3585ac6f07fbeecbeee..172658806f124331847bb1371cc22d4c9db8eeaf 100644
--- a/lms/djangoapps/grades/tests/test_new.py
+++ b/lms/djangoapps/grades/tests/test_new.py
@@ -4,13 +4,12 @@ Test saved subsection grade functionality.
 # pylint: disable=protected-access
 
 import datetime
+import itertools
 
 import ddt
+import pytz
 from django.conf import settings
-import itertools
-
 from mock import patch
-import pytz
 
 from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory
 from courseware.access import has_access
@@ -25,13 +24,13 @@ from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
 from xmodule.modulestore.tests.utils import TEST_DATA_DIR
 from xmodule.modulestore.xml_importer import import_course_from_xml
 
-from ..config.waffle import waffle, ASSUME_ZERO_GRADE_IF_ABSENT, WRITE_ONLY_IF_ENGAGED
+from ..config.waffle import ASSUME_ZERO_GRADE_IF_ABSENT, WRITE_ONLY_IF_ENGAGED, waffle
 from ..models import PersistentSubsectionGrade
 from ..new.course_data import CourseData
+from ..new.course_grade import CourseGrade, ZeroCourseGrade
 from ..new.course_grade_factory import CourseGradeFactory
-from ..new.course_grade import ZeroCourseGrade, CourseGrade
+from ..new.subsection_grade import SubsectionGrade, ZeroSubsectionGrade
 from ..new.subsection_grade_factory import SubsectionGradeFactory
-from ..new.subsection_grade import ZeroSubsectionGrade, SubsectionGrade
 from .utils import mock_get_score, mock_get_submissions_score
 
 
diff --git a/lms/djangoapps/grades/tests/test_scores.py b/lms/djangoapps/grades/tests/test_scores.py
index 1bf8c42fec6f461ab14f8072bcbb1853081ef75c..286e3a3cad97cebde962b169259d6ac9e3c607a4 100644
--- a/lms/djangoapps/grades/tests/test_scores.py
+++ b/lms/djangoapps/grades/tests/test_scores.py
@@ -1,21 +1,21 @@
 """
 Tests for grades.scores module.
 """
+import itertools
 # pylint: disable=protected-access
 from collections import namedtuple
+
 import ddt
 from django.test import TestCase
 from django.utils.timezone import now
-import itertools
+from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator
 
-from lms.djangoapps.grades.models import BlockRecord
 import lms.djangoapps.grades.scores as scores
+from lms.djangoapps.grades.models import BlockRecord
 from lms.djangoapps.grades.transformer import GradesTransformer
-from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator
 from openedx.core.djangoapps.content.block_structure.block_structure import BlockData
 from xmodule.graders import ProblemScore
 
-
 NOW = now()
 
 
diff --git a/lms/djangoapps/grades/tests/test_signals.py b/lms/djangoapps/grades/tests/test_signals.py
index a6b8f5c9dd3eb5f3414534e0e170927b57d71d20..dfaca5dd4c5e3ce6e7c6e26578a77eba84b1d22e 100644
--- a/lms/djangoapps/grades/tests/test_signals.py
+++ b/lms/djangoapps/grades/tests/test_signals.py
@@ -3,22 +3,23 @@ Tests for the score change signals defined in the courseware models module.
 """
 
 import re
-
 from datetime import datetime
+
 import ddt
-from django.test import TestCase
-from mock import patch, MagicMock
 import pytz
-from submissions.models import score_set, score_reset
+from django.test import TestCase
+from mock import MagicMock, patch
+
+from submissions.models import score_reset, score_set
 from util.date_utils import to_timestamp
 
 from ..constants import ScoreDatabaseTableEnum
 from ..signals.handlers import (
-    enqueue_subsection_update,
-    submissions_score_set_handler,
-    submissions_score_reset_handler,
     disconnect_submissions_signal_receiver,
+    enqueue_subsection_update,
     problem_raw_score_changed_handler,
+    submissions_score_reset_handler,
+    submissions_score_set_handler
 )
 from ..signals.signals import PROBLEM_RAW_SCORE_CHANGED
 
diff --git a/lms/djangoapps/grades/tests/test_tasks.py b/lms/djangoapps/grades/tests/test_tasks.py
index 6b0e7e010afd4dfed05ff3007632536d90565a7b..5a60c2c69d00588af1288f2af86aa28900b439d8 100644
--- a/lms/djangoapps/grades/tests/test_tasks.py
+++ b/lms/djangoapps/grades/tests/test_tasks.py
@@ -2,41 +2,38 @@
 Tests for the functionality and infrastructure of grades tasks.
 """
 
+import itertools
 from collections import OrderedDict
 from contextlib import contextmanager
 from datetime import datetime, timedelta
+
 import ddt
-from django.conf import settings
-from django.db.utils import IntegrityError
-import itertools
-from mock import patch, MagicMock
 import pytz
 import six
-from util.date_utils import to_timestamp
-
-from openedx.core.djangoapps.content.block_structure.exceptions import BlockStructureNotFound
-from student.models import CourseEnrollment, anonymous_id_for_user
-from student.tests.factories import UserFactory
-from track.event_transaction_utils import (
-    create_new_event_transaction_id,
-    get_event_transaction_id,
-)
-from xmodule.modulestore.django import modulestore
-from xmodule.modulestore import ModuleStoreEnum
-from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
-from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls
+from django.conf import settings
+from django.db.utils import IntegrityError
+from mock import MagicMock, patch
 
 from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag
 from lms.djangoapps.grades.constants import ScoreDatabaseTableEnum
 from lms.djangoapps.grades.models import PersistentCourseGrade, PersistentSubsectionGrade
 from lms.djangoapps.grades.signals.signals import PROBLEM_WEIGHTED_SCORE_CHANGED
 from lms.djangoapps.grades.tasks import (
+    RECALCULATE_GRADE_DELAY,
+    _course_task_args,
     compute_all_grades_for_course,
     compute_grades_for_course_v2,
-    recalculate_subsection_grade_v3,
-    RECALCULATE_GRADE_DELAY,
-    _course_task_args
+    recalculate_subsection_grade_v3
 )
+from openedx.core.djangoapps.content.block_structure.exceptions import BlockStructureNotFound
+from student.models import CourseEnrollment, anonymous_id_for_user
+from student.tests.factories import UserFactory
+from track.event_transaction_utils import create_new_event_transaction_id, get_event_transaction_id
+from util.date_utils import to_timestamp
+from xmodule.modulestore import ModuleStoreEnum
+from xmodule.modulestore.django import modulestore
+from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls
 
 
 class HasCourseWithProblemsMixin(object):
diff --git a/lms/djangoapps/grades/tests/test_transformer.py b/lms/djangoapps/grades/tests/test_transformer.py
index 2863a64f138db327aa606871c56fc4967dd42167..086fc48b7ae01f9d01d01d330a7c6a18f60d0bfd 100644
--- a/lms/djangoapps/grades/tests/test_transformer.py
+++ b/lms/djangoapps/grades/tests/test_transformer.py
@@ -3,21 +3,21 @@ Test the behavior of the GradesTransformer
 """
 
 import datetime
-import pytz
 import random
+from copy import deepcopy
 
 import ddt
-from copy import deepcopy
+import pytz
 
+from lms.djangoapps.course_blocks.api import get_course_blocks
+from lms.djangoapps.course_blocks.transformers.tests.helpers import CourseStructureTestCase
+from openedx.core.djangoapps.content.block_structure.api import clear_course_from_cache
 from student.tests.factories import UserFactory
 from xmodule.modulestore import ModuleStoreEnum
 from xmodule.modulestore.django import modulestore
 from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
 from xmodule.modulestore.tests.factories import check_mongo_calls
 
-from lms.djangoapps.course_blocks.api import get_course_blocks
-from lms.djangoapps.course_blocks.transformers.tests.helpers import CourseStructureTestCase
-from openedx.core.djangoapps.content.block_structure.api import clear_course_from_cache
 from ..transformer import GradesTransformer
 
 
diff --git a/lms/djangoapps/grades/tests/utils.py b/lms/djangoapps/grades/tests/utils.py
index fc78bfc87673a8c745480f798c15ddde5167c9ff..637f374f1e915bacd6d85664fb6502e1405223f2 100644
--- a/lms/djangoapps/grades/tests/utils.py
+++ b/lms/djangoapps/grades/tests/utils.py
@@ -3,9 +3,11 @@ Utilities for grades related tests
 """
 from contextlib import contextmanager
 from datetime import datetime
+
 from mock import patch
-from courseware.module_render import get_module
+
 from courseware.model_data import FieldDataCache
+from courseware.module_render import get_module
 from xmodule.graders import ProblemScore
 
 
diff --git a/lms/djangoapps/grades/transformer.py b/lms/djangoapps/grades/transformer.py
index afe298402b037eb2aa4beff6f92553102c9666fb..e12c6861b1a2b394b7618b59999d5e333b99af74 100644
--- a/lms/djangoapps/grades/transformer.py
+++ b/lms/djangoapps/grades/transformer.py
@@ -10,7 +10,6 @@ from logging import getLogger
 from lms.djangoapps.course_blocks.transformers.utils import collect_unioned_set_field, get_field_on_block
 from openedx.core.djangoapps.content.block_structure.transformer import BlockStructureTransformer
 
-
 log = getLogger(__name__)
 
 
diff --git a/lms/djangoapps/instructor/access.py b/lms/djangoapps/instructor/access.py
index 5ea8d3f576af4d1dccf4c78fa501718862d5ebce..f20a89ae204595d461492913b6b6537e159d4155 100644
--- a/lms/djangoapps/instructor/access.py
+++ b/lms/djangoapps/instructor/access.py
@@ -10,19 +10,10 @@ TO DO sync instructor and staff flags
 """
 
 import logging
-from django_comment_common.models import Role
 
-from student.roles import (
-    CourseBetaTesterRole,
-    CourseInstructorRole,
-    CourseCcxCoachRole,
-    CourseStaffRole,
-)
-
-from lms.djangoapps.instructor.enrollment import (
-    enroll_email,
-    get_email_params,
-)
+from django_comment_common.models import Role
+from lms.djangoapps.instructor.enrollment import enroll_email, get_email_params
+from student.roles import CourseBetaTesterRole, CourseCcxCoachRole, CourseInstructorRole, CourseStaffRole
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/instructor/enrollment.py b/lms/djangoapps/instructor/enrollment.py
index 07b75efa201b3d5190fe76d45db63c3db8116626..45e9b33b06e24f4552dfe7163cab96511bf60d93 100644
--- a/lms/djangoapps/instructor/enrollment.py
+++ b/lms/djangoapps/instructor/enrollment.py
@@ -6,36 +6,35 @@ Does not include any access control, be sure to check access before calling.
 
 import json
 import logging
-
 from datetime import datetime
-from django.contrib.auth.models import User
+
+import pytz
 from django.conf import settings
+from django.contrib.auth.models import User
 from django.core.mail import send_mail
 from django.core.urlresolvers import reverse
 from django.utils.translation import override as override_language
-from eventtracking import tracker
-import pytz
 
+from course_modes.models import CourseMode
+from courseware.models import StudentModule
+from edxmako.shortcuts import render_to_string
+from eventtracking import tracker
+from lms.djangoapps.grades.constants import ScoreDatabaseTableEnum
 from lms.djangoapps.grades.signals.handlers import disconnect_submissions_signal_receiver
 from lms.djangoapps.grades.signals.signals import PROBLEM_RAW_SCORE_CHANGED
-from lms.djangoapps.grades.constants import ScoreDatabaseTableEnum
 from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY
 from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
 from openedx.core.djangoapps.user_api.models import UserPreference
+from student.models import CourseEnrollment, CourseEnrollmentAllowed, anonymous_id_for_user
 from submissions import api as sub_api  # installed from the edx-submissions repository
 from submissions.models import score_set
-from xmodule.modulestore.django import modulestore
-from xmodule.modulestore.exceptions import ItemNotFoundError
-
-from course_modes.models import CourseMode
-from courseware.models import StudentModule
-from edxmako.shortcuts import render_to_string
-from student.models import CourseEnrollment, CourseEnrollmentAllowed, anonymous_id_for_user
 from track.event_transaction_utils import (
     create_new_event_transaction_id,
-    set_event_transaction_type,
-    get_event_transaction_id
+    get_event_transaction_id,
+    set_event_transaction_type
 )
+from xmodule.modulestore.django import modulestore
+from xmodule.modulestore.exceptions import ItemNotFoundError
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/instructor/enrollment_report.py b/lms/djangoapps/instructor/enrollment_report.py
index 2ddbd8dbe98945d14d149a03a9fdcc14146d041e..76c78306e55dbe5eb1362b03a17d9c1aa6245cd9 100644
--- a/lms/djangoapps/instructor/enrollment_report.py
+++ b/lms/djangoapps/instructor/enrollment_report.py
@@ -2,11 +2,13 @@
 Defines abstract class for the Enrollment Reports.
 """
 
-from django.contrib.auth.models import User
-from student.models import UserProfile
+import abc
 import collections
 import json
-import abc
+
+from django.contrib.auth.models import User
+
+from student.models import UserProfile
 
 
 class AbstractEnrollmentReportProvider(object):
diff --git a/lms/djangoapps/instructor/features/common.py b/lms/djangoapps/instructor/features/common.py
index 8c1b7280968ba7ebfa2b00f6a6e27358e311afd4..4342398f816bf4810fcf0799c43df32f7741ddd4 100644
--- a/lms/djangoapps/instructor/features/common.py
+++ b/lms/djangoapps/instructor/features/common.py
@@ -7,11 +7,11 @@ Define common steps for instructor dashboard acceptance tests.
 
 from __future__ import absolute_import
 
-from lettuce import world, step
+from lettuce import step, world
 from mock import patch
 from nose.tools import assert_in
 
-from courseware.tests.factories import StaffFactory, InstructorFactory
+from courseware.tests.factories import InstructorFactory, StaffFactory
 
 
 @step(u'Given I am "([^"]*)" for a very large course')
diff --git a/lms/djangoapps/instructor/features/data_download.py b/lms/djangoapps/instructor/features/data_download.py
index 1a628e8bde5e696a9ef8b94c0de5d49c94aedba0..5a050867b74ac65ce62c0bcb214e88ea6c971558 100644
--- a/lms/djangoapps/instructor/features/data_download.py
+++ b/lms/djangoapps/instructor/features/data_download.py
@@ -6,10 +6,11 @@ acceptance tests.
 # pylint: disable=missing-docstring
 # pylint: disable=redefined-outer-name
 
-from lettuce import world, step
+from django.utils import http
+from lettuce import step, world
 from nose.tools import assert_in, assert_regexp_matches
+
 from terrain.steps import reload_the_page
-from django.utils import http
 
 
 @step(u'I see a table of student profiles')
diff --git a/lms/djangoapps/instructor/paidcourse_enrollment_report.py b/lms/djangoapps/instructor/paidcourse_enrollment_report.py
index cd1096eb3f9ad2f486be04727ea477e3282c557d..d9fae3ce15c95e3951392b370bc3beebbd259348 100644
--- a/lms/djangoapps/instructor/paidcourse_enrollment_report.py
+++ b/lms/djangoapps/instructor/paidcourse_enrollment_report.py
@@ -2,16 +2,23 @@
 Defines concrete class for cybersource  Enrollment Report.
 
 """
-from courseware.access import has_access
 import collections
+
 from django.conf import settings
 from django.utils.translation import ugettext as _
+
+from courseware.access import has_access
 from courseware.courses import get_course_by_id
 from lms.djangoapps.instructor.enrollment_report import BaseAbstractEnrollmentReportProvider
-from shoppingcart.models import RegistrationCodeRedemption, PaidCourseRegistration, CouponRedemption, OrderItem, \
-    InvoiceTransaction
-from student.models import CourseEnrollment, ManualEnrollmentAudit
 from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
+from shoppingcart.models import (
+    CouponRedemption,
+    InvoiceTransaction,
+    OrderItem,
+    PaidCourseRegistration,
+    RegistrationCodeRedemption
+)
+from student.models import CourseEnrollment, ManualEnrollmentAudit
 
 
 class PaidCourseEnrollmentReportProvider(BaseAbstractEnrollmentReportProvider):
diff --git a/lms/djangoapps/instructor/services.py b/lms/djangoapps/instructor/services.py
index 87c9a920003e8df7cf68e0ae548b9298594c2c9d..5e7e4fadf6fcc606233fbd44494fcb7df979a8d5 100644
--- a/lms/djangoapps/instructor/services.py
+++ b/lms/djangoapps/instructor/services.py
@@ -4,22 +4,18 @@ Implementation of "Instructor" service
 
 import logging
 
+from django.core.exceptions import ObjectDoesNotExist
+from django.utils.translation import ugettext as _
 from opaque_keys import InvalidKeyError
 from opaque_keys.edx.keys import CourseKey, UsageKey
+
+import lms.djangoapps.instructor.enrollment as enrollment
 from commerce.signals import create_zendesk_ticket
 from courseware.models import StudentModule
 from lms.djangoapps.instructor.views.tools import get_student_from_identifier
-from django.core.exceptions import ObjectDoesNotExist
-import lms.djangoapps.instructor.enrollment as enrollment
-from django.utils.translation import ugettext as _
-
-
-from xmodule.modulestore.django import modulestore
-
-from student.roles import CourseStaffRole
-
 from student import auth
-
+from student.roles import CourseStaffRole
+from xmodule.modulestore.django import modulestore
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/instructor/tests/test_access.py b/lms/djangoapps/instructor/tests/test_access.py
index fb971bc61b7c9c8473fe5140486b1a971f7348c6..c203392b48052573a24ab6de1d1abf33f1970b30 100644
--- a/lms/djangoapps/instructor/tests/test_access.py
+++ b/lms/djangoapps/instructor/tests/test_access.py
@@ -2,17 +2,15 @@
 Test instructor.access
 """
 
-from nose.tools import raises
 from nose.plugins.attrib import attr
+from nose.tools import raises
+
+from django_comment_common.models import FORUM_ROLE_MODERATOR, Role
+from lms.djangoapps.instructor.access import allow_access, list_with_level, revoke_access, update_forum_role
+from student.roles import CourseBetaTesterRole, CourseCcxCoachRole, CourseStaffRole
 from student.tests.factories import UserFactory
-from xmodule.modulestore.tests.factories import CourseFactory
 from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
-
-from student.roles import CourseBetaTesterRole, CourseStaffRole, CourseCcxCoachRole
-
-from django_comment_common.models import (Role,
-                                          FORUM_ROLE_MODERATOR)
-from lms.djangoapps.instructor.access import (allow_access, revoke_access, list_with_level, update_forum_role)
+from xmodule.modulestore.tests.factories import CourseFactory
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/instructor/tests/test_api.py b/lms/djangoapps/instructor/tests/test_api.py
index 74d6c96fbd11ede20ba9d3b4304f592dbc0718e8..ba07cbade03e3f845eaf167968dd01214afde0a7 100644
--- a/lms/djangoapps/instructor/tests/test_api.py
+++ b/lms/djangoapps/instructor/tests/test_api.py
@@ -3,15 +3,15 @@
 Unit tests for instructor.api methods.
 """
 import datetime
-import ddt
 import functools
-import random
-import pytz
 import io
 import json
+import random
 import shutil
 import tempfile
 
+import ddt
+import pytz
 from django.conf import settings
 from django.contrib.auth.models import User
 from django.core import mail
@@ -22,55 +22,72 @@ from django.test import RequestFactory, TestCase
 from django.test.utils import override_settings
 from django.utils.timezone import utc
 from django.utils.translation import ugettext as _
-
 from mock import Mock, patch
-from nose.tools import raises
 from nose.plugins.attrib import attr
+from nose.tools import raises
 from opaque_keys.edx.locations import SlashSeparatedCourseKey
 from opaque_keys.edx.locator import UsageKey
-from xmodule.modulestore import ModuleStoreEnum
 
+import lms.djangoapps.instructor.views.api
+import lms.djangoapps.instructor_task.api
 from bulk_email.models import BulkEmailFlag, CourseEmail, CourseEmailTemplate
+from certificates.models import CertificateStatuses
+from certificates.tests.factories import GeneratedCertificateFactory
 from course_modes.models import CourseMode
-from courseware.models import StudentModule
+from courseware.models import StudentFieldOverride, StudentModule
 from courseware.tests.factories import (
-    BetaTesterFactory, GlobalStaffFactory, InstructorFactory, StaffFactory, UserProfileFactory
+    BetaTesterFactory,
+    GlobalStaffFactory,
+    InstructorFactory,
+    StaffFactory,
+    UserProfileFactory
 )
 from courseware.tests.helpers import LoginEnrollmentTestCase
 from django_comment_common.models import FORUM_ROLE_COMMUNITY_TA
 from django_comment_common.utils import seed_permissions_roles
-from shoppingcart.models import (
-    RegistrationCodeRedemption, Order, CouponRedemption,
-    PaidCourseRegistration, Coupon, Invoice, CourseRegistrationCode, CourseRegistrationCodeInvoiceItem,
-    InvoiceTransaction)
-from shoppingcart.pdf import PDFInvoice
-from student.models import (
-    CourseEnrollment, CourseEnrollmentAllowed, NonExistentCourseError,
-    ManualEnrollmentAudit, UNENROLLED_TO_ENROLLED, ENROLLED_TO_UNENROLLED,
-    ALLOWEDTOENROLL_TO_UNENROLLED, ENROLLED_TO_ENROLLED, UNENROLLED_TO_ALLOWEDTOENROLL,
-    UNENROLLED_TO_UNENROLLED, ALLOWEDTOENROLL_TO_ENROLLED
-)
-from student.tests.factories import UserFactory, CourseModeFactory, AdminFactory
-from student.roles import CourseBetaTesterRole, CourseSalesAdminRole, CourseFinanceAdminRole, CourseInstructorRole
-from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase, ModuleStoreTestCase
-from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
-from xmodule.fields import Date
-
-from courseware.models import StudentFieldOverride
-
-import lms.djangoapps.instructor_task.api
-import lms.djangoapps.instructor.views.api
-from lms.djangoapps.instructor.views.api import require_finance_admin
 from lms.djangoapps.instructor.tests.utils import FakeContentTask, FakeEmail, FakeEmailInfo
-from lms.djangoapps.instructor.views.api import _split_input_list, common_exceptions_400, generate_unique_password
+from lms.djangoapps.instructor.views.api import (
+    _split_input_list,
+    common_exceptions_400,
+    generate_unique_password,
+    require_finance_admin
+)
 from lms.djangoapps.instructor_task.api_helper import AlreadyRunningError
-from certificates.tests.factories import GeneratedCertificateFactory
-from certificates.models import CertificateStatuses
-
 from openedx.core.djangoapps.course_groups.cohorts import set_course_cohorted
-from openedx.core.lib.xblock_utils import grade_histogram
 from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
 from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin
+from openedx.core.lib.xblock_utils import grade_histogram
+from shoppingcart.models import (
+    Coupon,
+    CouponRedemption,
+    CourseRegistrationCode,
+    CourseRegistrationCodeInvoiceItem,
+    Invoice,
+    InvoiceTransaction,
+    Order,
+    PaidCourseRegistration,
+    RegistrationCodeRedemption
+)
+from shoppingcart.pdf import PDFInvoice
+from student.models import (
+    ALLOWEDTOENROLL_TO_ENROLLED,
+    ALLOWEDTOENROLL_TO_UNENROLLED,
+    ENROLLED_TO_ENROLLED,
+    ENROLLED_TO_UNENROLLED,
+    UNENROLLED_TO_ALLOWEDTOENROLL,
+    UNENROLLED_TO_ENROLLED,
+    UNENROLLED_TO_UNENROLLED,
+    CourseEnrollment,
+    CourseEnrollmentAllowed,
+    ManualEnrollmentAudit,
+    NonExistentCourseError
+)
+from student.roles import CourseBetaTesterRole, CourseFinanceAdminRole, CourseInstructorRole, CourseSalesAdminRole
+from student.tests.factories import AdminFactory, CourseModeFactory, UserFactory
+from xmodule.fields import Date
+from xmodule.modulestore import ModuleStoreEnum
+from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
 
 from .test_tools import msk_from_problem_urlname
 
diff --git a/lms/djangoapps/instructor/tests/test_api_email_localization.py b/lms/djangoapps/instructor/tests/test_api_email_localization.py
index 9bf0f3d70efb8cb6fa31e53691af731bddeba837..7ab9ab5e081a34c50a7d1c1539b26f04230a52f6 100644
--- a/lms/djangoapps/instructor/tests/test_api_email_localization.py
+++ b/lms/djangoapps/instructor/tests/test_api_email_localization.py
@@ -10,11 +10,11 @@ from nose.plugins.attrib import attr
 
 from courseware.tests.factories import InstructorFactory
 from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY
-from openedx.core.djangoapps.user_api.preferences.api import set_user_preference, delete_user_preference
+from openedx.core.djangoapps.user_api.preferences.api import delete_user_preference, set_user_preference
 from student.models import CourseEnrollment
 from student.tests.factories import UserFactory
-from xmodule.modulestore.tests.factories import CourseFactory
 from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/instructor/tests/test_certificates.py b/lms/djangoapps/instructor/tests/test_certificates.py
index 14e404af84bebda66e83506bb3d5aebce74848ee..929f22b571ab7ebfd902c1978a5a765ffeaf8f01 100644
--- a/lms/djangoapps/instructor/tests/test_certificates.py
+++ b/lms/djangoapps/instructor/tests/test_certificates.py
@@ -1,35 +1,42 @@
 """Tests for the certificates panel of the instructor dash. """
 import contextlib
-import ddt
-import mock
+import io
 import json
-import pytz
-
 from datetime import datetime, timedelta
 
-from nose.plugins.attrib import attr
-from django.core.urlresolvers import reverse
+import ddt
+import mock
+import pytz
+from config_models.models import cache
+from django.conf import settings
 from django.core.exceptions import ObjectDoesNotExist
+from django.core.files.uploadedfile import SimpleUploadedFile
+from django.core.urlresolvers import reverse
 from django.test.utils import override_settings
-from django.conf import settings
+from nose.plugins.attrib import attr
 
-from course_modes.models import CourseMode
 from capa.xqueue_interface import XQueueInterface
+from certificates import api as certs_api
+from certificates.models import (
+    CertificateGenerationConfiguration,
+    CertificateInvalidation,
+    CertificateStatuses,
+    CertificateWhitelist,
+    GeneratedCertificate
+)
+from certificates.tests.factories import (
+    CertificateInvalidationFactory,
+    CertificateWhitelistFactory,
+    GeneratedCertificateFactory
+)
+from course_modes.models import CourseMode
+from courseware.tests.factories import GlobalStaffFactory, InstructorFactory, UserFactory
 from lms.djangoapps.grades.tests.utils import mock_passing_grade
-from lms.djangoapps.verify_student.tests.factories import SoftwareSecurePhotoVerificationFactory
 from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification
+from lms.djangoapps.verify_student.tests.factories import SoftwareSecurePhotoVerificationFactory
+from student.models import CourseEnrollment
 from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
 from xmodule.modulestore.tests.factories import CourseFactory
-from config_models.models import cache
-from courseware.tests.factories import GlobalStaffFactory, InstructorFactory, UserFactory
-from certificates.tests.factories import GeneratedCertificateFactory, CertificateWhitelistFactory, \
-    CertificateInvalidationFactory
-from certificates.models import CertificateGenerationConfiguration, CertificateStatuses, CertificateWhitelist, \
-    GeneratedCertificate, CertificateInvalidation
-from certificates import api as certs_api
-from student.models import CourseEnrollment
-from django.core.files.uploadedfile import SimpleUploadedFile
-import io
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/instructor/tests/test_ecommerce.py b/lms/djangoapps/instructor/tests/test_ecommerce.py
index 1d05e480710270c1edaa340dec7bbdce14cf0b72..86c28c38f537944f2d88655c2da375d41b0cf917 100644
--- a/lms/djangoapps/instructor/tests/test_ecommerce.py
+++ b/lms/djangoapps/instructor/tests/test_ecommerce.py
@@ -5,17 +5,16 @@ Unit tests for Ecommerce feature flag in new instructor dashboard.
 import datetime
 
 import pytz
-
 from django.core.urlresolvers import reverse
 from nose.plugins.attrib import attr
 
 from course_modes.models import CourseMode
-from student.roles import CourseFinanceAdminRole
+from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin
 from shoppingcart.models import Coupon, CourseRegistrationCode
+from student.roles import CourseFinanceAdminRole
 from student.tests.factories import AdminFactory
 from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
 from xmodule.modulestore.tests.factories import CourseFactory
-from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/instructor/tests/test_email.py b/lms/djangoapps/instructor/tests/test_email.py
index 728142b055311dfd866ef90de499e3db6458b90c..fb18334b0d1877b6b265a03b647cdecb8065d2e8 100644
--- a/lms/djangoapps/instructor/tests/test_email.py
+++ b/lms/djangoapps/instructor/tests/test_email.py
@@ -9,11 +9,9 @@ from django.core.urlresolvers import reverse
 from nose.plugins.attrib import attr
 from opaque_keys.edx.locations import SlashSeparatedCourseKey
 
-from bulk_email.models import CourseAuthorization, BulkEmailFlag
-from xmodule.modulestore.tests.django_utils import (
-    TEST_DATA_MIXED_MODULESTORE, SharedModuleStoreTestCase
-)
+from bulk_email.models import BulkEmailFlag, CourseAuthorization
 from student.tests.factories import AdminFactory
+from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_MODULESTORE, SharedModuleStoreTestCase
 from xmodule.modulestore.tests.factories import CourseFactory
 
 
diff --git a/lms/djangoapps/instructor/tests/test_enrollment.py b/lms/djangoapps/instructor/tests/test_enrollment.py
index 42c5d015e45cb583d51577b6688d45de68648e5f..af8a5604ab534a06be0c6689784aee577ea84804 100644
--- a/lms/djangoapps/instructor/tests/test_enrollment.py
+++ b/lms/djangoapps/instructor/tests/test_enrollment.py
@@ -3,19 +3,19 @@
 Unit tests for instructor.enrollment methods.
 """
 
-from abc import ABCMeta
 import json
+from abc import ABCMeta
 
+import mock
+from ccx_keys.locator import CCXLocator
 from django.conf import settings
-from django.utils.translation import get_language
 from django.utils.translation import override as override_language
-import mock
+from django.utils.translation import get_language
 from mock import patch
 from nose.plugins.attrib import attr
 from opaque_keys.edx.locations import SlashSeparatedCourseKey
 
 from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory
-from ccx_keys.locator import CCXLocator
 from courseware.models import StudentModule
 from grades.new.subsection_grade_factory import SubsectionGradeFactory
 from grades.tests.utils import answer_problem
@@ -25,18 +25,17 @@ from lms.djangoapps.instructor.enrollment import (
     EmailEnrollmentState,
     enroll_email,
     get_email_params,
+    render_message_to_string,
     reset_student_attempts,
     send_beta_role_email,
-    unenroll_email,
-    render_message_to_string,
+    unenroll_email
 )
 from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, get_mock_request
-from student.models import CourseEnrollment, CourseEnrollmentAllowed
+from student.models import CourseEnrollment, CourseEnrollmentAllowed, anonymous_id_for_user
 from student.roles import CourseCcxCoachRole
 from student.tests.factories import AdminFactory, UserFactory
 from submissions import api as sub_api
-from student.models import anonymous_id_for_user
-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
 
 
diff --git a/lms/djangoapps/instructor/tests/test_enrollment_store_provider.py b/lms/djangoapps/instructor/tests/test_enrollment_store_provider.py
index a8f753290a45ef7e551e71ade90a97be20f189eb..1277d09244f878c620294915adbd01c0c3e41e88 100644
--- a/lms/djangoapps/instructor/tests/test_enrollment_store_provider.py
+++ b/lms/djangoapps/instructor/tests/test_enrollment_store_provider.py
@@ -3,6 +3,7 @@ Exercises tests on the base_store_provider file
 """
 
 from django.test import TestCase
+
 from lms.djangoapps.instructor.enrollment_report import AbstractEnrollmentReportProvider
 from lms.djangoapps.instructor.paidcourse_enrollment_report import PaidCourseEnrollmentReportProvider
 
diff --git a/lms/djangoapps/instructor/tests/test_proctoring.py b/lms/djangoapps/instructor/tests/test_proctoring.py
index 841e87082d3f56c25d422e6852d5f5c89983ec2f..986c09891e267c887761a0070fc9eafccc1b53d5 100644
--- a/lms/djangoapps/instructor/tests/test_proctoring.py
+++ b/lms/djangoapps/instructor/tests/test_proctoring.py
@@ -2,10 +2,9 @@
 Unit tests for Edx Proctoring feature flag in new instructor dashboard.
 """
 
-from mock import patch
-
 from django.conf import settings
 from django.core.urlresolvers import reverse
+from mock import patch
 from nose.plugins.attrib import attr
 
 from student.roles import CourseFinanceAdminRole
diff --git a/lms/djangoapps/instructor/tests/test_registration_codes.py b/lms/djangoapps/instructor/tests/test_registration_codes.py
index 497f1966ff3ce7936d176499ab737e47b726f224..9cc4c6d7332c7f36e2823650399bbba7236db191 100644
--- a/lms/djangoapps/instructor/tests/test_registration_codes.py
+++ b/lms/djangoapps/instructor/tests/test_registration_codes.py
@@ -1,22 +1,28 @@
 """
 Test for the registration code status information.
 """
+import json
+
+from django.core.urlresolvers import reverse
+from django.test.utils import override_settings
+from django.utils.translation import ugettext as _
+from nose.plugins.attrib import attr
+
 from course_modes.models import CourseMode
 from courseware.tests.factories import InstructorFactory
-from xmodule.modulestore.tests.factories import CourseFactory
-from django.utils.translation import ugettext as _
 from shoppingcart.models import (
-    Invoice, CourseRegistrationCodeInvoiceItem, CourseRegistrationCode,
-    CourseRegCodeItem, Order, RegistrationCodeRedemption
+    CourseRegCodeItem,
+    CourseRegistrationCode,
+    CourseRegistrationCodeInvoiceItem,
+    Invoice,
+    Order,
+    RegistrationCodeRedemption
 )
 from student.models import CourseEnrollment
 from student.roles import CourseSalesAdminRole
-from nose.plugins.attrib import attr
-import json
-from student.tests.factories import UserFactory, CourseModeFactory
-from django.core.urlresolvers import reverse
-from django.test.utils import override_settings
+from student.tests.factories import CourseModeFactory, UserFactory
 from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/instructor/tests/test_services.py b/lms/djangoapps/instructor/tests/test_services.py
index 09f824a154994fb39ed77b4c976bd68bdd50cdcd..b46b7f831a8e2efb4c5f7ae375fdcafe943c17b6 100644
--- a/lms/djangoapps/instructor/tests/test_services.py
+++ b/lms/djangoapps/instructor/tests/test_services.py
@@ -3,16 +3,18 @@ Tests for the InstructorService
 """
 
 import json
-from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
-from xmodule.modulestore.tests.factories import CourseFactory
+
+import mock
+from nose.plugins.attrib import attr
+
 from courseware.models import StudentModule
 from lms.djangoapps.instructor.access import allow_access
 from lms.djangoapps.instructor.services import InstructorService
 from lms.djangoapps.instructor.tests.test_tools import msk_from_problem_urlname
-from nose.plugins.attrib import attr
 from student.models import CourseEnrollment
 from student.tests.factories import UserFactory
-import mock
+from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/instructor/tests/test_spoc_gradebook.py b/lms/djangoapps/instructor/tests/test_spoc_gradebook.py
index 07fe049924f971ff3ec55675e96a5de4cc6112ab..ade14980ae1065d1522cf14f08beb3fa7c4378e4 100644
--- a/lms/djangoapps/instructor/tests/test_spoc_gradebook.py
+++ b/lms/djangoapps/instructor/tests/test_spoc_gradebook.py
@@ -4,12 +4,12 @@ Tests of the instructor dashboard spoc gradebook
 
 from django.core.urlresolvers import reverse
 from nose.plugins.attrib import attr
-from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
-from student.tests.factories import UserFactory, CourseEnrollmentFactory, AdminFactory
-from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
+
 from capa.tests.response_xml_factory import StringResponseXMLFactory
 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/instructor/tests/test_tools.py b/lms/djangoapps/instructor/tests/test_tools.py
index da8fe04d483fa997a16a90cf0b4f41e3f1ad1df2..5eecf44359c05866bb14172b4f23287107876c4d 100644
--- a/lms/djangoapps/instructor/tests/test_tools.py
+++ b/lms/djangoapps/instructor/tests/test_tools.py
@@ -3,13 +3,14 @@ Tests for views/tools.py.
 """
 
 import datetime
-import mock
 import json
 import unittest
 
-from django.utils.timezone import utc
+import mock
 from django.test.utils import override_settings
+from django.utils.timezone import utc
 from nose.plugins.attrib import attr
+from opaque_keys.edx.keys import CourseKey
 
 from courseware.field_overrides import OverrideFieldData
 from lms.djangoapps.ccx.tests.test_overrides import inject_field_overrides
@@ -17,7 +18,6 @@ from student.tests.factories import UserFactory
 from xmodule.fields import Date
 from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase
 from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
-from opaque_keys.edx.keys import CourseKey
 
 from ..views import tools
 
diff --git a/lms/djangoapps/instructor/tests/utils.py b/lms/djangoapps/instructor/tests/utils.py
index f3816cbde144c67d15b0cf01a74c022c2d4c3049..8c1308ebb34f2500c85e6b34656345227960f656 100644
--- a/lms/djangoapps/instructor/tests/utils.py
+++ b/lms/djangoapps/instructor/tests/utils.py
@@ -4,7 +4,9 @@ Utilities for instructor unit tests
 import datetime
 import json
 import random
+
 from django.utils.timezone import utc
+
 from util.date_utils import get_default_time_display
 
 
diff --git a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py
index e57109c2c15bdf32921e181cca7591068121a92f..1c970e11ddb0b0a2de462eb9638b3d90a0337235 100644
--- a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py
+++ b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py
@@ -1,32 +1,31 @@
 """
 Unit tests for instructor_dashboard.py.
 """
-import ddt
 import datetime
-from mock import patch
-from nose.plugins.attrib import attr
-from pytz import UTC
 
+import ddt
 from django.conf import settings
 from django.core.urlresolvers import reverse
 from django.test.client import RequestFactory
 from django.test.utils import override_settings
-from edxmako.shortcuts import render_to_response
+from mock import patch
+from nose.plugins.attrib import attr
+from pytz import UTC
 
+from common.test.utils import XssTestMixin
+from course_modes.models import CourseMode
 from courseware.tabs import get_course_tab_list
-from courseware.tests.factories import UserFactory, StudentModuleFactory, StaffFactory
+from courseware.tests.factories import StaffFactory, StudentModuleFactory, UserFactory
 from courseware.tests.helpers import LoginEnrollmentTestCase
+from edxmako.shortcuts import render_to_response
 from lms.djangoapps.instructor.views.gradebook_api import calculate_page_info
-
-from common.test.utils import XssTestMixin
+from shoppingcart.models import CourseRegCodeItem, Order, PaidCourseRegistration
+from student.models import CourseEnrollment
+from student.roles import CourseFinanceAdminRole
 from student.tests.factories import AdminFactory, CourseEnrollmentFactory
 from xmodule.modulestore import ModuleStoreEnum
-from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, TEST_DATA_SPLIT_MODULESTORE
+from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase
 from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls
-from shoppingcart.models import PaidCourseRegistration, Order, CourseRegCodeItem
-from course_modes.models import CourseMode
-from student.roles import CourseFinanceAdminRole
-from student.models import CourseEnrollment
 
 
 def intercept_renderer(path, context):
diff --git a/lms/djangoapps/instructor/utils.py b/lms/djangoapps/instructor/utils.py
index dcfa45ac9388a25da2583b19b90881eedb5debb3..1a150de9cbfea73891ec61c8f7eccb62b214142f 100644
--- a/lms/djangoapps/instructor/utils.py
+++ b/lms/djangoapps/instructor/utils.py
@@ -2,10 +2,9 @@
 Helpers for instructor app.
 """
 
-from xmodule.modulestore.django import modulestore
-
 from courseware.model_data import FieldDataCache
 from courseware.module_render import get_module
+from xmodule.modulestore.django import modulestore
 
 
 class DummyRequest(object):
diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py
index 9877119864c3ef6bdbcc5fa4eca0d1037daabce4..4d6b24b8782f2210a3a59e7aadf68b5a6eb990e0 100644
--- a/lms/djangoapps/instructor/views/api.py
+++ b/lms/djangoapps/instructor/views/api.py
@@ -5,112 +5,116 @@ JSON views which the instructor dashboard requests.
 
 Many of these GETs may become PUTs in the future.
 """
-import StringIO
+import csv
+import decimal
 import json
 import logging
+import random
 import re
+import string
+import StringIO
 import time
+
+import unicodecsv
 from django.conf import settings
-from django.views.decorators.csrf import ensure_csrf_cookie
-from django.views.decorators.http import require_POST, require_http_methods
-from django.views.decorators.cache import cache_control
-from django.core.exceptions import ValidationError, PermissionDenied
+from django.contrib.auth.models import User
+from django.core.exceptions import ObjectDoesNotExist, PermissionDenied, ValidationError
 from django.core.mail.message import EmailMessage
-from django.core.exceptions import ObjectDoesNotExist
-from django.db import IntegrityError, transaction
 from django.core.urlresolvers import reverse
 from django.core.validators import validate_email
-from django.utils.translation import ugettext as _
+from django.db import IntegrityError, transaction
 from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseNotFound
-from django.utils.html import strip_tags
 from django.shortcuts import redirect
-import string
-import random
-import unicodecsv
-import decimal
-from student import auth
-from student.roles import CourseSalesAdminRole, CourseFinanceAdminRole
-from util.file import (
-    store_uploaded_file, course_and_time_based_filename_generator,
-    FileValidationException, UniversalNewlineIterator
-)
-from util.json_request import JsonResponse, JsonResponseBadRequest
-from util.views import require_global_staff
-from lms.djangoapps.instructor.views.instructor_task_helpers import extract_email_features, extract_task_features
+from django.utils.html import strip_tags
+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.views.decorators.http import require_http_methods, require_POST
+from opaque_keys import InvalidKeyError
+from opaque_keys.edx.keys import CourseKey, UsageKey
+from opaque_keys.edx.locations import SlashSeparatedCourseKey
 
+import instructor_analytics.basic
+import instructor_analytics.csvs
+import instructor_analytics.distributions
+import lms.djangoapps.instructor.enrollment as enrollment
+import lms.djangoapps.instructor_task.api
+from bulk_email.models import BulkEmailFlag, CourseEmail
+from certificates import api as certs_api
+from certificates.models import CertificateInvalidation, CertificateStatuses, CertificateWhitelist, GeneratedCertificate
 from courseware.access import has_access
-from courseware.courses import get_course_with_access, get_course_by_id
-from django.contrib.auth.models import User
+from courseware.courses import get_course_by_id, get_course_with_access
+from courseware.models import StudentModule
 from django_comment_client.utils import has_forum_access
-from django_comment_common.models import (
-    Role,
-    FORUM_ROLE_ADMINISTRATOR,
-    FORUM_ROLE_MODERATOR,
-    FORUM_ROLE_COMMUNITY_TA,
-)
+from django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_MODERATOR, Role
 from edxmako.shortcuts import render_to_string
-from courseware.models import StudentModule
-from shoppingcart.models import (
-    Coupon,
-    CourseRegistrationCode,
-    RegistrationCodeRedemption,
-    Invoice,
-    CourseMode,
-    CourseRegistrationCodeInvoiceItem,
-)
-from student.models import (
-    CourseEnrollment, unique_id_for_user, anonymous_id_for_user,
-    UserProfile, Registration, EntranceExamConfiguration,
-    ManualEnrollmentAudit, UNENROLLED_TO_ALLOWEDTOENROLL, ALLOWEDTOENROLL_TO_ENROLLED,
-    ENROLLED_TO_ENROLLED, ENROLLED_TO_UNENROLLED, UNENROLLED_TO_ENROLLED,
-    UNENROLLED_TO_UNENROLLED, ALLOWEDTOENROLL_TO_UNENROLLED, DEFAULT_TRANSITION_STATE
-)
-import lms.djangoapps.instructor_task.api
-from lms.djangoapps.instructor_task.api_helper import AlreadyRunningError
-from lms.djangoapps.instructor_task.models import ReportStore
-import lms.djangoapps.instructor.enrollment as enrollment
+from lms.djangoapps.instructor.access import ROLES, allow_access, list_with_level, revoke_access, update_forum_role
 from lms.djangoapps.instructor.enrollment import (
-    get_user_email_language,
     enroll_email,
-    send_mail_to_student,
     get_email_params,
+    get_user_email_language,
     send_beta_role_email,
-    unenroll_email,
+    send_mail_to_student,
+    unenroll_email
 )
-from lms.djangoapps.instructor.access import list_with_level, allow_access, revoke_access, ROLES, update_forum_role
-import instructor_analytics.basic
-import instructor_analytics.distributions
-import instructor_analytics.csvs
-import csv
+from lms.djangoapps.instructor.views import INVOICE_KEY
+from lms.djangoapps.instructor.views.instructor_task_helpers import extract_email_features, extract_task_features
+from lms.djangoapps.instructor_task.api_helper import AlreadyRunningError
+from lms.djangoapps.instructor_task.models import ReportStore
+from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
+from openedx.core.djangoapps.course_groups.cohorts import is_course_cohorted
+from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
 from openedx.core.djangoapps.user_api.preferences.api import get_user_preference, set_user_preference
 from openedx.core.djangolib.markup import HTML, Text
-from lms.djangoapps.instructor.views import INVOICE_KEY
-
+from shoppingcart.models import (
+    Coupon,
+    CourseMode,
+    CourseRegistrationCode,
+    CourseRegistrationCodeInvoiceItem,
+    Invoice,
+    RegistrationCodeRedemption
+)
+from student import auth
+from student.models import (
+    ALLOWEDTOENROLL_TO_ENROLLED,
+    ALLOWEDTOENROLL_TO_UNENROLLED,
+    DEFAULT_TRANSITION_STATE,
+    ENROLLED_TO_ENROLLED,
+    ENROLLED_TO_UNENROLLED,
+    UNENROLLED_TO_ALLOWEDTOENROLL,
+    UNENROLLED_TO_ENROLLED,
+    UNENROLLED_TO_UNENROLLED,
+    CourseEnrollment,
+    EntranceExamConfiguration,
+    ManualEnrollmentAudit,
+    Registration,
+    UserProfile,
+    anonymous_id_for_user,
+    get_user_by_username_or_email,
+    unique_id_for_user
+)
+from student.roles import CourseFinanceAdminRole, CourseSalesAdminRole
 from submissions import api as sub_api  # installed from the edx-submissions repository
-
-from certificates import api as certs_api
-from certificates.models import CertificateWhitelist, GeneratedCertificate, CertificateStatuses, CertificateInvalidation
-
-from bulk_email.models import CourseEmail, BulkEmailFlag
-from student.models import get_user_by_username_or_email
+from util.file import (
+    FileValidationException,
+    UniversalNewlineIterator,
+    course_and_time_based_filename_generator,
+    store_uploaded_file
+)
+from util.json_request import JsonResponse, JsonResponseBadRequest
+from util.views import require_global_staff
 
 from .tools import (
-    dump_student_extensions,
     dump_module_extensions,
+    dump_student_extensions,
     find_unit,
     get_student_from_identifier,
-    require_student_from_identifier,
     handle_dashboard_error,
     parse_datetime,
+    require_student_from_identifier,
     set_due_date_extension,
-    strip_if_string,
+    strip_if_string
 )
-from opaque_keys.edx.keys import CourseKey, UsageKey
-from opaque_keys.edx.locations import SlashSeparatedCourseKey
-from opaque_keys import InvalidKeyError
-from openedx.core.djangoapps.course_groups.cohorts import is_course_cohorted
-from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
-from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/instructor/views/coupons.py b/lms/djangoapps/instructor/views/coupons.py
index 59d8ee7f42c08e0cc9590f9cf6479cd2dbdf55e3..1b3e8bd921c7271e3019b4ad619e0689d719fb76 100644
--- a/lms/djangoapps/instructor/views/coupons.py
+++ b/lms/djangoapps/instructor/views/coupons.py
@@ -1,16 +1,18 @@
 """
 E-commerce Tab Instructor Dashboard Coupons Operations views
 """
+import datetime
+import logging
+
+import pytz
 from django.contrib.auth.decorators import login_required
 from django.core.exceptions import ObjectDoesNotExist
-from django.views.decorators.http import require_POST
 from django.utils.translation import ugettext as _
-from util.json_request import JsonResponse
-from shoppingcart.models import Coupon, CourseRegistrationCode
+from django.views.decorators.http import require_POST
 from opaque_keys.edx.locations import SlashSeparatedCourseKey
-import datetime
-import pytz
-import logging
+
+from shoppingcart.models import Coupon, CourseRegistrationCode
+from util.json_request import JsonResponse
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/instructor/views/gradebook_api.py b/lms/djangoapps/instructor/views/gradebook_api.py
index 291601b00a727a01416982880e785d388a4824fe..5bce65dbe2283f1138ee0b8219ebc75f4e5b8340 100644
--- a/lms/djangoapps/instructor/views/gradebook_api.py
+++ b/lms/djangoapps/instructor/views/gradebook_api.py
@@ -8,16 +8,14 @@ from django.contrib.auth.models import User
 from django.core.urlresolvers import reverse
 from django.db import transaction
 from django.views.decorators.cache import cache_control
-
 from opaque_keys.edx.keys import CourseKey
 
-from edxmako.shortcuts import render_to_response
 from courseware.courses import get_course_with_access
-from lms.djangoapps.instructor.views.api import require_level
+from edxmako.shortcuts import render_to_response
 from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory
+from lms.djangoapps.instructor.views.api import require_level
 from xmodule.modulestore.django import modulestore
 
-
 # Grade book: max students per page
 MAX_STUDENTS_PER_PAGE_GRADE_BOOK = 20
 
diff --git a/lms/djangoapps/instructor/views/instructor_dashboard.py b/lms/djangoapps/instructor/views/instructor_dashboard.py
index 25572167d2186be407ddb9947a426467a09bb06a..a5ffbb7eeb4d0d02312ed6cd0af520dd8060b2de 100644
--- a/lms/djangoapps/instructor/views/instructor_dashboard.py
+++ b/lms/djangoapps/instructor/views/instructor_dashboard.py
@@ -6,9 +6,24 @@ import datetime
 import logging
 import uuid
 
+import pytz
+from django.conf import settings
+from django.contrib.auth.decorators import login_required
+from django.core.urlresolvers import reverse
+from django.http import Http404, HttpResponseServerError
+from django.utils.html import escape
+from django.utils.translation import ugettext as _
+from django.utils.translation import ugettext_noop
+from django.views.decorators.cache import cache_control
+from django.views.decorators.csrf import ensure_csrf_cookie
+from django.views.decorators.http import require_POST
 from mock import patch
+from opaque_keys import InvalidKeyError
+from opaque_keys.edx.keys import CourseKey
+from opaque_keys.edx.locations import SlashSeparatedCourseKey
+from xblock.field_data import DictFieldData
+from xblock.fields import ScopeIds
 
-import pytz
 from bulk_email.models import BulkEmailFlag
 from certificates import api as certs_api
 from certificates.models import (
@@ -23,23 +38,10 @@ from class_dashboard.dashboard_data import get_array_section_has_problem, get_se
 from course_modes.models import CourseMode, CourseModesArchive
 from courseware.access import has_access
 from courseware.courses import get_course_by_id, get_studio_url
-from django.conf import settings
-from django.contrib.auth.decorators import login_required
-from django.core.urlresolvers import reverse
-from django.http import Http404, HttpResponseServerError
-from django.utils.html import escape
-from django.utils.translation import ugettext as _
-from django.utils.translation import ugettext_noop
-from django.views.decorators.cache import cache_control
-from django.views.decorators.csrf import ensure_csrf_cookie
-from django.views.decorators.http import require_POST
 from django_comment_client.utils import available_division_schemes, has_forum_access
 from django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, CourseDiscussionSettings
 from edxmako.shortcuts import render_to_response
 from lms.djangoapps.courseware.module_render import get_module_by_usage_id
-from opaque_keys import InvalidKeyError
-from opaque_keys.edx.keys import CourseKey
-from opaque_keys.edx.locations import SlashSeparatedCourseKey
 from openedx.core.djangoapps.course_groups.cohorts import DEFAULT_COHORT_NAME, get_course_cohorts, is_course_cohorted
 from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
 from openedx.core.djangoapps.verified_track_content.models import VerifiedTrackCohortedCourse
@@ -50,8 +52,6 @@ from shoppingcart.models import Coupon, CourseRegCodeItem, PaidCourseRegistratio
 from student.models import CourseEnrollment
 from student.roles import CourseFinanceAdminRole, CourseSalesAdminRole
 from util.json_request import JsonResponse
-from xblock.field_data import DictFieldData
-from xblock.fields import ScopeIds
 from xmodule.html_module import HtmlDescriptor
 from xmodule.modulestore.django import modulestore
 from xmodule.tabs import CourseTab
diff --git a/lms/djangoapps/instructor/views/instructor_task_helpers.py b/lms/djangoapps/instructor/views/instructor_task_helpers.py
index 15b53c7e5cd6531d07c77ebf08f2f4a9e5d72e4f..df5935f3210afa5efcfe47052c0bb82898245966 100644
--- a/lms/djangoapps/instructor/views/instructor_task_helpers.py
+++ b/lms/djangoapps/instructor/views/instructor_task_helpers.py
@@ -4,11 +4,13 @@ tasks.
 """
 import json
 import logging
-from util.date_utils import get_default_time_display
-from bulk_email.models import CourseEmail
+
 from django.utils.translation import ugettext as _
 from django.utils.translation import ungettext
+
+from bulk_email.models import CourseEmail
 from lms.djangoapps.instructor_task.views import get_task_completion_info
+from util.date_utils import get_default_time_display
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/instructor/views/registration_codes.py b/lms/djangoapps/instructor/views/registration_codes.py
index 3775f6769de10dc049dfc33628cbcd0f42aa34ba..7e72566c2aae765df26c0d868f2e2b09aadcfac4 100644
--- a/lms/djangoapps/instructor/views/registration_codes.py
+++ b/lms/djangoapps/instructor/views/registration_codes.py
@@ -1,18 +1,20 @@
 """
 E-commerce Tab Instructor Dashboard Query Registration Code Status.
 """
+import logging
+
 from django.core.urlresolvers import reverse
-from django.views.decorators.http import require_GET, require_POST
-from lms.djangoapps.instructor.enrollment import get_email_params, send_mail_to_student
 from django.utils.translation import ugettext as _
+from django.views.decorators.cache import cache_control
+from django.views.decorators.http import require_GET, require_POST
+from opaque_keys.edx.locations import SlashSeparatedCourseKey
+
 from courseware.courses import get_course_by_id
+from lms.djangoapps.instructor.enrollment import get_email_params, send_mail_to_student
 from lms.djangoapps.instructor.views.api import require_level
+from shoppingcart.models import CourseRegistrationCode, RegistrationCodeRedemption
 from student.models import CourseEnrollment
 from util.json_request import JsonResponse
-from shoppingcart.models import CourseRegistrationCode, RegistrationCodeRedemption
-from opaque_keys.edx.locations import SlashSeparatedCourseKey
-from django.views.decorators.cache import cache_control
-import logging
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/instructor/views/tools.py b/lms/djangoapps/instructor/views/tools.py
index 9d6daa511d6b52629e309bac4d72196cbb1d31a4..3e70b2168d441527ed7f62605b1ecd2dc02ceef9 100644
--- a/lms/djangoapps/instructor/views/tools.py
+++ b/lms/djangoapps/instructor/views/tools.py
@@ -1,23 +1,19 @@
 """
 Tools for the instructor dashboard
 """
-import dateutil
 import json
 
+import dateutil
 from django.contrib.auth.models import User
 from django.http import HttpResponseBadRequest
 from django.utils.timezone import utc
 from django.utils.translation import ugettext as _
+from opaque_keys.edx.keys import UsageKey
 
-from courseware.models import StudentFieldOverride
 from courseware.field_overrides import disable_overrides
-from courseware.student_field_overrides import (
-    clear_override_for_user,
-    get_override_for_user,
-    override_field_for_user,
-)
+from courseware.models import StudentFieldOverride
+from courseware.student_field_overrides import clear_override_for_user, get_override_for_user, override_field_for_user
 from xmodule.fields import Date
-from opaque_keys.edx.keys import UsageKey
 
 DATE_FIELD = Date()
 
diff --git a/lms/djangoapps/instructor_analytics/basic.py b/lms/djangoapps/instructor_analytics/basic.py
index f3625e1de23c3fbbfe3546f28ccaf63c7ca4c445..3393e19530629d01059cba608a91e787e807538f 100644
--- a/lms/djangoapps/instructor_analytics/basic.py
+++ b/lms/djangoapps/instructor_analytics/basic.py
@@ -3,30 +3,32 @@ Student and course analytics.
 
 Serve miscellaneous course and student data
 """
-import json
 import datetime
-from shoppingcart.models import (
-    PaidCourseRegistration, CouponRedemption, CourseRegCodeItem,
-    RegistrationCodeRedemption, CourseRegistrationCodeInvoiceItem
-)
-from django.db.models import Q
+import json
+
 from django.conf import settings
 from django.contrib.auth.models import User
 from django.core.exceptions import ObjectDoesNotExist
 from django.core.serializers.json import DjangoJSONEncoder
 from django.core.urlresolvers import reverse
+from django.db.models import Count, Q
+from edx_proctoring.api import get_all_exam_attempts
 from opaque_keys.edx.keys import UsageKey
+
 import xmodule.graders as xmgraders
-from student.models import CourseEnrollmentAllowed, CourseEnrollment
-from edx_proctoring.api import get_all_exam_attempts
+from certificates.models import CertificateStatuses, GeneratedCertificate
 from courseware.models import StudentModule
-from certificates.models import GeneratedCertificate
-from django.db.models import Count
-from certificates.models import CertificateStatuses
 from lms.djangoapps.grades.context import grading_context_for_course
 from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification
 from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
-
+from shoppingcart.models import (
+    CouponRedemption,
+    CourseRegCodeItem,
+    CourseRegistrationCodeInvoiceItem,
+    PaidCourseRegistration,
+    RegistrationCodeRedemption
+)
+from student.models import CourseEnrollment, CourseEnrollmentAllowed
 
 STUDENT_FEATURES = ('id', 'username', 'first_name', 'last_name', 'is_staff', 'email')
 PROFILE_FEATURES = ('name', 'language', 'location', 'year_of_birth', 'gender',
diff --git a/lms/djangoapps/instructor_analytics/csvs.py b/lms/djangoapps/instructor_analytics/csvs.py
index 2b8da615f048801c24f57a7cea7d5533f7545d1f..77fda1d07c85bc9f70d2a68ea430cf21b92ee749 100644
--- a/lms/djangoapps/instructor_analytics/csvs.py
+++ b/lms/djangoapps/instructor_analytics/csvs.py
@@ -5,6 +5,7 @@ Format and create csv responses
 """
 
 import csv
+
 from django.http import HttpResponse
 
 
diff --git a/lms/djangoapps/instructor_analytics/distributions.py b/lms/djangoapps/instructor_analytics/distributions.py
index 423db91b93eaa29bab3f1caf600afad028c6983f..fe2394625a651559ccf705e4c0d07f3b5d37930d 100644
--- a/lms/djangoapps/instructor_analytics/distributions.py
+++ b/lms/djangoapps/instructor_analytics/distributions.py
@@ -22,6 +22,7 @@ The distribution in a course for gender might look like:
 """
 
 from django.db.models import Count
+
 from student.models import CourseEnrollment, UserProfile
 
 # choices with a restricted domain, e.g. level_of_education
diff --git a/lms/djangoapps/instructor_analytics/tests/test_basic.py b/lms/djangoapps/instructor_analytics/tests/test_basic.py
index 8ae477f506d193489fda3bec88367097a4186e3f..ceb738800cb3ad9c20f4eb76452d00d26ef4bd1a 100644
--- a/lms/djangoapps/instructor_analytics/tests/test_basic.py
+++ b/lms/djangoapps/instructor_analytics/tests/test_basic.py
@@ -4,32 +4,48 @@ Tests for instructor.basic
 
 import datetime
 import json
+
 import pytz
-from mock import MagicMock, Mock, patch
-from nose.plugins.attrib import attr
 from django.core.urlresolvers import reverse
 from django.db.models import Q
+from edx_proctoring.api import create_exam
+from edx_proctoring.models import ProctoredExamStudentAttempt
+from mock import MagicMock, Mock, patch
+from nose.plugins.attrib import attr
+from opaque_keys.edx.locator import UsageKey
 
 from course_modes.models import CourseMode
 from courseware.tests.factories import InstructorFactory
 from instructor_analytics.basic import (
-    StudentModule, sale_record_features, sale_order_record_features, enrolled_students_features,
-    course_registration_features, coupon_codes_features, get_proctored_exam_results, list_may_enroll,
-    list_problem_responses, AVAILABLE_FEATURES, STUDENT_FEATURES, PROFILE_FEATURES
+    AVAILABLE_FEATURES,
+    PROFILE_FEATURES,
+    STUDENT_FEATURES,
+    StudentModule,
+    coupon_codes_features,
+    course_registration_features,
+    enrolled_students_features,
+    get_proctored_exam_results,
+    list_may_enroll,
+    list_problem_responses,
+    sale_order_record_features,
+    sale_record_features
 )
-from opaque_keys.edx.locator import UsageKey
 from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory
-from student.models import CourseEnrollment, CourseEnrollmentAllowed
-from student.roles import CourseSalesAdminRole
-from student.tests.factories import UserFactory, CourseModeFactory
 from shoppingcart.models import (
-    CourseRegistrationCode, RegistrationCodeRedemption, Order,
-    Invoice, Coupon, CourseRegCodeItem, CouponRedemption, CourseRegistrationCodeInvoiceItem
+    Coupon,
+    CouponRedemption,
+    CourseRegCodeItem,
+    CourseRegistrationCode,
+    CourseRegistrationCodeInvoiceItem,
+    Invoice,
+    Order,
+    RegistrationCodeRedemption
 )
+from student.models import CourseEnrollment, CourseEnrollmentAllowed
+from student.roles import CourseSalesAdminRole
+from student.tests.factories import CourseModeFactory, UserFactory
 from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
 from xmodule.modulestore.tests.factories import CourseFactory
-from edx_proctoring.api import create_exam
-from edx_proctoring.models import ProctoredExamStudentAttempt
 
 
 @attr(shard=3)
diff --git a/lms/djangoapps/instructor_analytics/tests/test_distributions.py b/lms/djangoapps/instructor_analytics/tests/test_distributions.py
index 6a8e8ba1b214ef768eae3d46859c91ccb33610c7..0a91a04ba1d236f478810be2b2f7e5bdfb66a81c 100644
--- a/lms/djangoapps/instructor_analytics/tests/test_distributions.py
+++ b/lms/djangoapps/instructor_analytics/tests/test_distributions.py
@@ -2,11 +2,11 @@
 
 from django.test import TestCase
 from nose.tools import raises
-from student.models import CourseEnrollment
-from student.tests.factories import UserFactory
 from opaque_keys.edx.locations import SlashSeparatedCourseKey
 
-from instructor_analytics.distributions import profile_distribution, AVAILABLE_PROFILE_FEATURES
+from instructor_analytics.distributions import AVAILABLE_PROFILE_FEATURES, profile_distribution
+from student.models import CourseEnrollment
+from student.tests.factories import UserFactory
 
 
 class TestAnalyticsDistributions(TestCase):
diff --git a/lms/djangoapps/instructor_task/admin.py b/lms/djangoapps/instructor_task/admin.py
index 02d488513004afc17d8fe3f27e842c9caae886f5..977596ec17fc5222095cdcd251969e7d0b0d0374 100644
--- a/lms/djangoapps/instructor_task/admin.py
+++ b/lms/djangoapps/instructor_task/admin.py
@@ -7,8 +7,9 @@ a task.
 """
 from config_models.admin import ConfigurationModelAdmin
 from django.contrib import admin
-from .models import InstructorTask
+
 from .config.models import GradeReportSetting
+from .models import InstructorTask
 
 
 class InstructorTaskAdmin(admin.ModelAdmin):
diff --git a/lms/djangoapps/instructor_task/api.py b/lms/djangoapps/instructor_task/api.py
index 8bce85597c348b0000ed3653f317cf8460c24062..9b7101e8e71e690c281eb924d618ffbd909853fc 100644
--- a/lms/djangoapps/instructor_task/api.py
+++ b/lms/djangoapps/instructor_task/api.py
@@ -6,44 +6,41 @@ already been submitted, filtered either by running state or input
 arguments.
 
 """
-from collections import Counter
 import hashlib
+from collections import Counter
 
 from celery.states import READY_STATES
 
-from xmodule.modulestore.django import modulestore
-
+from bulk_email.models import CourseEmail
+from certificates.models import CertificateGenerationHistory
+from lms.djangoapps.instructor_task.api_helper import (
+    check_arguments_for_rescoring,
+    check_entrance_exam_problems_for_rescoring,
+    encode_entrance_exam_and_student_input,
+    encode_problem_and_student_input,
+    submit_task
+)
 from lms.djangoapps.instructor_task.models import InstructorTask
 from lms.djangoapps.instructor_task.tasks import (
-    rescore_problem,
-    reset_problem_attempts,
-    delete_problem_state,
-    send_bulk_course_email,
-    calculate_problem_responses_csv,
     calculate_grades_csv,
+    calculate_may_enroll_csv,
     calculate_problem_grade_report,
+    calculate_problem_responses_csv,
     calculate_students_features_csv,
     cohort_students,
+    course_survey_report_csv,
+    delete_problem_state,
     enrollment_report_features_csv,
-    calculate_may_enroll_csv,
     exec_summary_report_csv,
-    course_survey_report_csv,
+    export_ora2_data,
     generate_certificates,
     proctored_exam_results_csv,
-    export_ora2_data,
-)
-
-from certificates.models import CertificateGenerationHistory
-
-from lms.djangoapps.instructor_task.api_helper import (
-    check_arguments_for_rescoring,
-    encode_problem_and_student_input,
-    encode_entrance_exam_and_student_input,
-    check_entrance_exam_problems_for_rescoring,
-    submit_task,
+    rescore_problem,
+    reset_problem_attempts,
+    send_bulk_course_email
 )
-from bulk_email.models import CourseEmail
 from util import milestones_helpers
+from xmodule.modulestore.django import modulestore
 
 
 class SpecificStudentIdMissingError(Exception):
diff --git a/lms/djangoapps/instructor_task/api_helper.py b/lms/djangoapps/instructor_task/api_helper.py
index 3a8a1a66c506284c824741286ebb955141be597f..20c3308a5eea28c41e3716862eb431e2720b6c1b 100644
--- a/lms/djangoapps/instructor_task/api_helper.py
+++ b/lms/djangoapps/instructor_task/api_helper.py
@@ -8,19 +8,16 @@ import hashlib
 import json
 import logging
 
-from django.utils.translation import ugettext as _
-from util.db import outer_atomic
-
 from celery.result import AsyncResult
-from celery.states import READY_STATES, SUCCESS, FAILURE, REVOKED
+from celery.states import FAILURE, READY_STATES, REVOKED, SUCCESS
+from django.utils.translation import ugettext as _
+from opaque_keys.edx.keys import UsageKey
 
-from courseware.module_render import get_xqueue_callback_url_prefix
 from courseware.courses import get_problems_in_section
-
+from courseware.module_render import get_xqueue_callback_url_prefix
+from lms.djangoapps.instructor_task.models import PROGRESS, InstructorTask
+from util.db import outer_atomic
 from xmodule.modulestore.django import modulestore
-from opaque_keys.edx.keys import UsageKey
-from lms.djangoapps.instructor_task.models import InstructorTask, PROGRESS
-
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/instructor_task/management/commands/fail_old_tasks.py b/lms/djangoapps/instructor_task/management/commands/fail_old_tasks.py
index f3251e1aa5216632c0411392b90817daa5c45ff8..46ed086dd311ba373004c180c39569b130ba3310 100644
--- a/lms/djangoapps/instructor_task/management/commands/fail_old_tasks.py
+++ b/lms/djangoapps/instructor_task/management/commands/fail_old_tasks.py
@@ -1,4 +1,4 @@
-from __future__ import unicode_literals, print_function
+from __future__ import print_function, unicode_literals
 
 from datetime import datetime
 
@@ -6,7 +6,7 @@ from celery.states import FAILURE
 from django.core.management.base import BaseCommand, CommandError
 from pytz import utc
 
-from lms.djangoapps.instructor_task.models import InstructorTask, QUEUING, PROGRESS
+from lms.djangoapps.instructor_task.models import PROGRESS, QUEUING, InstructorTask
 
 
 class Command(BaseCommand):
diff --git a/lms/djangoapps/instructor_task/management/commands/tests/test_fail_old_tasks.py b/lms/djangoapps/instructor_task/management/commands/tests/test_fail_old_tasks.py
index eed2a04ef6c001f40996b849eed5b444601225de..70eb50175febbc1cae70f0437c55039f377845f5 100644
--- a/lms/djangoapps/instructor_task/management/commands/tests/test_fail_old_tasks.py
+++ b/lms/djangoapps/instructor_task/management/commands/tests/test_fail_old_tasks.py
@@ -5,7 +5,7 @@ from celery.states import FAILURE
 from django.core.management import call_command
 from django.core.management.base import CommandError
 
-from lms.djangoapps.instructor_task.models import InstructorTask, PROGRESS, QUEUING
+from lms.djangoapps.instructor_task.models import PROGRESS, QUEUING, InstructorTask
 from lms.djangoapps.instructor_task.tests.factories import InstructorTaskFactory
 from lms.djangoapps.instructor_task.tests.test_base import InstructorTaskTestCase
 
diff --git a/lms/djangoapps/instructor_task/models.py b/lms/djangoapps/instructor_task/models.py
index 8179a6c320d2f5454fba780274a978d5d9c98a78..f990a499390e2f921a2a6b13c9aa15e3672ff5a7 100644
--- a/lms/djangoapps/instructor_task/models.py
+++ b/lms/djangoapps/instructor_task/models.py
@@ -12,20 +12,19 @@ file and check it in at the same time as your model changes. To do that,
 ASSUMPTIONS: modules have unique IDs, even across different module_types
 
 """
-from uuid import uuid4
 import csv
-import json
 import hashlib
+import json
 import os.path
+from uuid import uuid4
 
 from django.conf import settings
 from django.contrib.auth.models import User
 from django.core.files.base import ContentFile
 from django.db import models, transaction
 
-from openedx.core.storage import get_storage
 from openedx.core.djangoapps.xmodule_django.models import CourseKeyField
-
+from openedx.core.storage import get_storage
 
 # define custom states used by InstructorTask
 QUEUING = 'QUEUING'
diff --git a/lms/djangoapps/instructor_task/subtasks.py b/lms/djangoapps/instructor_task/subtasks.py
index 5dd14ede3db7884d6b92c5652daf2434c52308f9..c1da60663ebbf890f960bead8f13c97e11c7ad11 100644
--- a/lms/djangoapps/instructor_task/subtasks.py
+++ b/lms/djangoapps/instructor_task/subtasks.py
@@ -1,24 +1,22 @@
 """
 This module contains celery task functions for handling the management of subtasks.
 """
-from time import time
 import json
-from uuid import uuid4
-import psutil
-from contextlib import contextmanager
 import logging
+from contextlib import contextmanager
+from time import time
+from uuid import uuid4
 
-from celery.states import SUCCESS, READY_STATES, RETRY
-import dogstats_wrapper as dog_stats_api
-
-from django.db import transaction, DatabaseError
+import psutil
+from celery.states import READY_STATES, RETRY, SUCCESS
 from django.core.cache import cache
+from django.db import DatabaseError, transaction
 
+import dogstats_wrapper as dog_stats_api
 from util.db import outer_atomic
 
 from .exceptions import DuplicateTaskException
-from .models import InstructorTask, PROGRESS, QUEUING
-
+from .models import PROGRESS, QUEUING, InstructorTask
 
 TASK_LOG = logging.getLogger('edx.celery.task')
 
diff --git a/lms/djangoapps/instructor_task/tasks.py b/lms/djangoapps/instructor_task/tasks.py
index e0bd28ef114c8e01eb27d74ce6ae1be7781c923d..a2ed72d57dfab8d2d95be8c8e7df283c0b8815ee 100644
--- a/lms/djangoapps/instructor_task/tasks.py
+++ b/lms/djangoapps/instructor_task/tasks.py
@@ -22,40 +22,33 @@ of the query for traversing StudentModule objects.
 import logging
 from functools import partial
 
+from celery import task
 from django.conf import settings
 from django.utils.translation import ugettext_noop
 
-from celery import task
 from bulk_email.tasks import perform_delegate_email_batches
 from lms.djangoapps.instructor_task.tasks_base import BaseInstructorTask
-from lms.djangoapps.instructor_task.tasks_helper.runner import run_main_task
-from lms.djangoapps.instructor_task.tasks_helper.certs import (
-    generate_students_certificates,
-)
+from lms.djangoapps.instructor_task.tasks_helper.certs import generate_students_certificates
 from lms.djangoapps.instructor_task.tasks_helper.enrollments import (
     upload_enrollment_report,
-    upload_may_enroll_csv,
     upload_exec_summary_report,
-    upload_students_csv,
-)
-from lms.djangoapps.instructor_task.tasks_helper.grades import (
-    CourseGradeReport,
-    ProblemGradeReport,
-    ProblemResponses,
+    upload_may_enroll_csv,
+    upload_students_csv
 )
+from lms.djangoapps.instructor_task.tasks_helper.grades import CourseGradeReport, ProblemGradeReport, ProblemResponses
 from lms.djangoapps.instructor_task.tasks_helper.misc import (
     cohort_students_and_upload,
     upload_course_survey_report,
-    upload_proctored_exam_results_report,
     upload_ora2_data,
+    upload_proctored_exam_results_report
 )
 from lms.djangoapps.instructor_task.tasks_helper.module_state import (
+    delete_problem_module_state,
     perform_module_state_update,
     rescore_problem_module_state,
-    reset_attempts_module_state,
-    delete_problem_module_state,
+    reset_attempts_module_state
 )
-
+from lms.djangoapps.instructor_task.tasks_helper.runner import run_main_task
 
 TASK_LOG = logging.getLogger('edx.celery.task')
 
diff --git a/lms/djangoapps/instructor_task/tasks_base.py b/lms/djangoapps/instructor_task/tasks_base.py
index 41f199b39954303994ed959d8b9961b7c8b67405..1b7419feaad991d3883fc92f6f285c67696068d9 100644
--- a/lms/djangoapps/instructor_task/tasks_base.py
+++ b/lms/djangoapps/instructor_task/tasks_base.py
@@ -1,11 +1,12 @@
 """
 Base class for Instructor celery tasks.
 """
-from celery import Task
-from celery.states import SUCCESS, FAILURE
 import logging
-from lms.djangoapps.instructor_task.models import InstructorTask
 
+from celery import Task
+from celery.states import FAILURE, SUCCESS
+
+from lms.djangoapps.instructor_task.models import InstructorTask
 
 # define different loggers for use within tasks and on client side
 TASK_LOG = logging.getLogger('edx.celery.task')
diff --git a/lms/djangoapps/instructor_task/tasks_helper/certs.py b/lms/djangoapps/instructor_task/tasks_helper/certs.py
index 4569288f838bf084e8165b20263b482178afc648..99f5663ecd168e4f0230669b92e89c1aa63041d7 100644
--- a/lms/djangoapps/instructor_task/tasks_helper/certs.py
+++ b/lms/djangoapps/instructor_task/tasks_helper/certs.py
@@ -1,14 +1,16 @@
 """
 Instructor tasks related to certificates.
 """
+from time import time
+
 from django.contrib.auth.models import User
 from django.db.models import Q
-from time import time
 
 from certificates.api import generate_user_certificates
 from certificates.models import CertificateStatuses, GeneratedCertificate
 from student.models import CourseEnrollment
 from xmodule.modulestore.django import modulestore
+
 from .runner import TaskProgress
 
 
diff --git a/lms/djangoapps/instructor_task/tasks_helper/enrollments.py b/lms/djangoapps/instructor_task/tasks_helper/enrollments.py
index 65f2714689a58678ee0775b9745139f8c76242e3..fe23b22db84e99f52d29c971f2b9b363d096b656 100644
--- a/lms/djangoapps/instructor_task/tasks_helper/enrollments.py
+++ b/lms/djangoapps/instructor_task/tasks_helper/enrollments.py
@@ -1,31 +1,36 @@
 """
 Instructor tasks related to enrollments.
 """
+import logging
 from datetime import datetime
+from StringIO import StringIO
+from time import time
+
 from django.conf import settings
 from django.utils.translation import ugettext as _
-import logging
 from pytz import UTC
-from StringIO import StringIO
-from time import time
 
-from edxmako.shortcuts import render_to_string
 from courseware.courses import get_course_by_id
-from lms.djangoapps.instructor.paidcourse_enrollment_report import PaidCourseEnrollmentReportProvider
-from lms.djangoapps.instructor_task.models import ReportStore
+from edxmako.shortcuts import render_to_string
 from instructor_analytics.basic import enrolled_students_features, list_may_enroll
 from instructor_analytics.csvs import format_dictlist
+from lms.djangoapps.instructor.paidcourse_enrollment_report import PaidCourseEnrollmentReportProvider
+from lms.djangoapps.instructor_task.models import ReportStore
 from shoppingcart.models import (
-    PaidCourseRegistration, CourseRegCodeItem, InvoiceTransaction,
-    Invoice, CouponRedemption, RegistrationCodeRedemption, CourseRegistrationCode
+    CouponRedemption,
+    CourseRegCodeItem,
+    CourseRegistrationCode,
+    Invoice,
+    InvoiceTransaction,
+    PaidCourseRegistration,
+    RegistrationCodeRedemption
 )
-from student.models import CourseEnrollment, CourseAccessRole
+from student.models import CourseAccessRole, CourseEnrollment
 from util.file import course_filename_prefix_generator
 
 from .runner import TaskProgress
 from .utils import tracker_emit, upload_csv_to_report_store
 
-
 TASK_LOG = logging.getLogger('edx.celery.task')
 FILTERED_OUT_ROLES = ['staff', 'instructor', 'finance_admin', 'sales_admin']
 
diff --git a/lms/djangoapps/instructor_task/tasks_helper/grades.py b/lms/djangoapps/instructor_task/tasks_helper/grades.py
index bfc47a0712479190e41efc94d26832f3567cd4c2..650d4a99b883568adcd0f8ac80f945fabfac4c03 100644
--- a/lms/djangoapps/instructor_task/tasks_helper/grades.py
+++ b/lms/djangoapps/instructor_task/tasks_helper/grades.py
@@ -1,26 +1,27 @@
 """
 Functionality for generating grade reports.
 """
+import logging
+import re
 from collections import OrderedDict
 from datetime import datetime
-from itertools import chain, izip_longest, izip
+from itertools import chain, izip, izip_longest
+from time import time
+
 from lazy import lazy
-import logging
 from pytz import UTC
-import re
-from time import time
 
+from certificates.models import CertificateWhitelist, GeneratedCertificate, certificate_info_for_user
+from courseware.courses import get_course_by_id
 from instructor_analytics.basic import list_problem_responses
 from instructor_analytics.csvs import format_dictlist
-from certificates.models import CertificateWhitelist, certificate_info_for_user, GeneratedCertificate
-from courseware.courses import get_course_by_id
-from lms.djangoapps.grades.context import grading_context_for_course, grading_context
-from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory
+from lms.djangoapps.grades.context import grading_context, grading_context_for_course
 from lms.djangoapps.grades.models import PersistentCourseGrade
+from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory
 from lms.djangoapps.teams.models import CourseTeamMembership
 from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification
 from openedx.core.djangoapps.content.block_structure.api import get_course_in_cache
-from openedx.core.djangoapps.course_groups.cohorts import get_cohort, is_course_cohorted, bulk_cache_cohorts
+from openedx.core.djangoapps.course_groups.cohorts import bulk_cache_cohorts, get_cohort, is_course_cohorted
 from openedx.core.djangoapps.user_api.course_tag.api import BulkCourseTags
 from student.models import CourseEnrollment
 from student.roles import BulkRoleCache
@@ -31,7 +32,6 @@ from xmodule.split_test_module import get_split_user_partitions
 from .runner import TaskProgress
 from .utils import upload_csv_to_report_store
 
-
 TASK_LOG = logging.getLogger('edx.celery.task')
 
 ENROLLED_IN_COURSE = 'enrolled'
diff --git a/lms/djangoapps/instructor_task/tasks_helper/misc.py b/lms/djangoapps/instructor_task/tasks_helper/misc.py
index 043486e3effd7c3ea5773ebfca0a1c6aea04707a..cdb23149e02ce5c210d4d7e4e364a8fd8851e35c 100644
--- a/lms/djangoapps/instructor_task/tasks_helper/misc.py
+++ b/lms/djangoapps/instructor_task/tasks_helper/misc.py
@@ -3,27 +3,26 @@ This file contains tasks that are designed to perform background operations on t
 running state of a course.
 
 """
+import logging
 from collections import OrderedDict
 from datetime import datetime
-import logging
-from pytz import UTC
 from time import time
-import unicodecsv
 
+import unicodecsv
 from django.contrib.auth.models import User
 from django.core.files.storage import DefaultStorage
+from openassessment.data import OraAggregateData
+from pytz import UTC
 
 from instructor_analytics.basic import get_proctored_exam_results
 from instructor_analytics.csvs import format_dictlist
-from openassessment.data import OraAggregateData
-from openedx.core.djangoapps.course_groups.models import CourseUserGroup
 from openedx.core.djangoapps.course_groups.cohorts import add_user_to_cohort
+from openedx.core.djangoapps.course_groups.models import CourseUserGroup
 from survey.models import SurveyAnswer
-from util.file import course_filename_prefix_generator, UniversalNewlineIterator
+from util.file import UniversalNewlineIterator, course_filename_prefix_generator
 
 from .runner import TaskProgress
-from .utils import upload_csv_to_report_store, UPDATE_STATUS_SUCCEEDED, UPDATE_STATUS_FAILED
-
+from .utils import UPDATE_STATUS_FAILED, UPDATE_STATUS_SUCCEEDED, upload_csv_to_report_store
 
 # define different loggers for use within tasks and on client side
 TASK_LOG = logging.getLogger('edx.celery.task')
diff --git a/lms/djangoapps/instructor_task/tasks_helper/module_state.py b/lms/djangoapps/instructor_task/tasks_helper/module_state.py
index a5775d1a046bfaf63c65baaf2b61e3bac9892d7b..4078305e1383bce13614a6158f0a9aab863f747e 100644
--- a/lms/djangoapps/instructor_task/tasks_helper/module_state.py
+++ b/lms/djangoapps/instructor_task/tasks_helper/module_state.py
@@ -1,31 +1,31 @@
 """
 Instructor Tasks related to module state.
 """
-from django.contrib.auth.models import User
-import dogstats_wrapper as dog_stats_api
 import json
 import logging
 from time import time
 
-from eventtracking import tracker
+from django.contrib.auth.models import User
 from opaque_keys.edx.keys import UsageKey
-from xmodule.modulestore.django import modulestore
-from capa.responsetypes import StudentInputError, ResponseError, LoncapaProblemError
+from xblock.runtime import KvsFieldData
+
+import dogstats_wrapper as dog_stats_api
+from capa.responsetypes import LoncapaProblemError, ResponseError, StudentInputError
 from courseware.courses import get_course_by_id, get_problems_in_section
-from courseware.models import StudentModule
 from courseware.model_data import DjangoKeyValueStore, FieldDataCache
+from courseware.models import StudentModule
 from courseware.module_render import get_module_for_descriptor_internal
+from eventtracking import tracker
 from lms.djangoapps.grades.scores import weighted_score
 from track.contexts import course_context_from_course_id
-from track.event_transaction_utils import set_event_transaction_type, create_new_event_transaction_id
+from track.event_transaction_utils import create_new_event_transaction_id, set_event_transaction_type
 from track.views import task_track
 from util.db import outer_atomic
-from xblock.runtime import KvsFieldData
+from xmodule.modulestore.django import modulestore
 
 from ..exceptions import UpdateProblemModuleStateError
 from .runner import TaskProgress
-from .utils import UPDATE_STATUS_SUCCEEDED, UPDATE_STATUS_FAILED, UPDATE_STATUS_SKIPPED, UNKNOWN_TASK_ID
-
+from .utils import UNKNOWN_TASK_ID, UPDATE_STATUS_FAILED, UPDATE_STATUS_SKIPPED, UPDATE_STATUS_SUCCEEDED
 
 TASK_LOG = logging.getLogger('edx.celery.task')
 
diff --git a/lms/djangoapps/instructor_task/tasks_helper/runner.py b/lms/djangoapps/instructor_task/tasks_helper/runner.py
index 71cd9fb8b43752efce8867d14341eacbc2c1196f..e276720564c4080ecc81911bb4a653231a2e3103 100644
--- a/lms/djangoapps/instructor_task/tasks_helper/runner.py
+++ b/lms/djangoapps/instructor_task/tasks_helper/runner.py
@@ -1,13 +1,13 @@
-from django.db import reset_queries
-from celery import Task, current_task
-import dogstats_wrapper as dog_stats_api
 import json
 import logging
-from util.db import outer_atomic
 from time import time
 
-from lms.djangoapps.instructor_task.models import InstructorTask, PROGRESS
+from celery import Task, current_task
+from django.db import reset_queries
 
+import dogstats_wrapper as dog_stats_api
+from lms.djangoapps.instructor_task.models import PROGRESS, InstructorTask
+from util.db import outer_atomic
 
 TASK_LOG = logging.getLogger('edx.celery.task')
 
diff --git a/lms/djangoapps/instructor_task/tasks_helper/utils.py b/lms/djangoapps/instructor_task/tasks_helper/utils.py
index 2c30b34c3e140c6fc56cb00db14419736c37e337..a02ef645a93119b902588f6f74e164af562b0b2a 100644
--- a/lms/djangoapps/instructor_task/tasks_helper/utils.py
+++ b/lms/djangoapps/instructor_task/tasks_helper/utils.py
@@ -2,7 +2,6 @@ from eventtracking import tracker
 from lms.djangoapps.instructor_task.models import ReportStore
 from util.file import course_filename_prefix_generator
 
-
 REPORT_REQUESTED_EVENT_NAME = u'edx.instructor.report.requested'
 
 # define value to use when no task_id is provided:
diff --git a/lms/djangoapps/instructor_task/tests/factories.py b/lms/djangoapps/instructor_task/tests/factories.py
index e08b6ea25d429a075ab85ae52aa47d445c2b738a..9be5423dce8821e80ebfb79b5626941313b6f0cc 100644
--- a/lms/djangoapps/instructor_task/tests/factories.py
+++ b/lms/djangoapps/instructor_task/tests/factories.py
@@ -1,12 +1,13 @@
 import json
 
 import factory
-from factory.django import DjangoModelFactory
-from student.tests.factories import UserFactory as StudentUserFactory
-from lms.djangoapps.instructor_task.models import InstructorTask
 from celery.states import PENDING
+from factory.django import DjangoModelFactory
 from opaque_keys.edx.locations import SlashSeparatedCourseKey
 
+from lms.djangoapps.instructor_task.models import InstructorTask
+from student.tests.factories import UserFactory as StudentUserFactory
+
 
 class InstructorTaskFactory(DjangoModelFactory):
     class Meta(object):
diff --git a/lms/djangoapps/instructor_task/tests/test_api.py b/lms/djangoapps/instructor_task/tests/test_api.py
index edcd1fc81b3444e185b9cd92406353e11419459b..b5b4b40d681c093ae6c4f1d219eed84cb469f46a 100644
--- a/lms/djangoapps/instructor_task/tests/test_api.py
+++ b/lms/djangoapps/instructor_task/tests/test_api.py
@@ -2,47 +2,46 @@
 Test for LMS instructor background task queue management
 """
 import ddt
-from mock import patch, Mock, MagicMock
+from mock import MagicMock, Mock, patch
 from nose.plugins.attrib import attr
-from bulk_email.models import CourseEmail, SEND_TO_MYSELF, SEND_TO_STAFF, SEND_TO_LEARNERS
-from courseware.tests.factories import UserFactory
-from xmodule.modulestore.exceptions import ItemNotFoundError
 
+from bulk_email.models import SEND_TO_LEARNERS, SEND_TO_MYSELF, SEND_TO_STAFF, CourseEmail
+from certificates.models import CertificateGenerationHistory, CertificateStatuses
+from courseware.tests.factories import UserFactory
 from lms.djangoapps.instructor_task.api import (
-    get_running_instructor_tasks,
+    SpecificStudentIdMissingError,
+    generate_certificates_for_students,
     get_instructor_task_history,
-    submit_rescore_problem_for_all_students,
-    submit_rescore_problem_for_student,
-    submit_rescore_entrance_exam_for_student,
-    submit_reset_problem_attempts_for_all_students,
-    submit_reset_problem_attempts_in_entrance_exam,
-    submit_delete_problem_state_for_all_students,
-    submit_delete_entrance_exam_state_for_student,
+    get_running_instructor_tasks,
+    regenerate_certificates,
     submit_bulk_course_email,
+    submit_calculate_may_enroll_csv,
     submit_calculate_problem_responses_csv,
     submit_calculate_students_features_csv,
     submit_cohort_students,
+    submit_course_survey_report,
+    submit_delete_entrance_exam_state_for_student,
+    submit_delete_problem_state_for_all_students,
     submit_detailed_enrollment_features_csv,
-    submit_calculate_may_enroll_csv,
     submit_executive_summary_report,
-    submit_course_survey_report,
-    generate_certificates_for_students,
-    regenerate_certificates,
     submit_export_ora2_data,
-    SpecificStudentIdMissingError,
+    submit_rescore_entrance_exam_for_student,
+    submit_rescore_problem_for_all_students,
+    submit_rescore_problem_for_student,
+    submit_reset_problem_attempts_for_all_students,
+    submit_reset_problem_attempts_in_entrance_exam
 )
-
 from lms.djangoapps.instructor_task.api_helper import AlreadyRunningError
-from lms.djangoapps.instructor_task.models import InstructorTask, PROGRESS
+from lms.djangoapps.instructor_task.models import PROGRESS, InstructorTask
 from lms.djangoapps.instructor_task.tasks import export_ora2_data
 from lms.djangoapps.instructor_task.tests.test_base import (
-    InstructorTaskTestCase,
+    TEST_COURSE_KEY,
     InstructorTaskCourseTestCase,
     InstructorTaskModuleTestCase,
-    TestReportMixin,
-    TEST_COURSE_KEY,
+    InstructorTaskTestCase,
+    TestReportMixin
 )
-from certificates.models import CertificateStatuses, CertificateGenerationHistory
+from xmodule.modulestore.exceptions import ItemNotFoundError
 
 
 class InstructorTaskReportTest(InstructorTaskTestCase):
diff --git a/lms/djangoapps/instructor_task/tests/test_base.py b/lms/djangoapps/instructor_task/tests/test_base.py
index 949f6e64d82d52f1cd2ea3afbf063e213c8f27a3..d9be20925a4d5e0d2a6f08cdb67e4c271204171d 100644
--- a/lms/djangoapps/instructor_task/tests/test_base.py
+++ b/lms/djangoapps/instructor_task/tests/test_base.py
@@ -2,36 +2,34 @@
 Base test classes for LMS instructor-initiated background tasks
 
 """
+import json
 # pylint: disable=attribute-defined-outside-init
 import os
-import json
-from mock import Mock, patch
 import shutil
 from tempfile import mkdtemp
-import unicodecsv
 from uuid import uuid4
 
-from celery.states import SUCCESS, FAILURE
-from django.core.urlresolvers import reverse
+import unicodecsv
+from celery.states import FAILURE, SUCCESS
 from django.contrib.auth.models import User
+from django.core.urlresolvers import reverse
+from mock import Mock, patch
+from opaque_keys.edx.locations import Location, SlashSeparatedCourseKey
 
 from capa.tests.response_xml_factory import OptionResponseXMLFactory
 from courseware.model_data import StudentModule
 from courseware.tests.tests import LoginEnrollmentTestCase
-from opaque_keys.edx.locations import Location, SlashSeparatedCourseKey
+from lms.djangoapps.instructor_task.api_helper import encode_problem_and_student_input
+from lms.djangoapps.instructor_task.models import PROGRESS, QUEUING, ReportStore
+from lms.djangoapps.instructor_task.tests.factories import InstructorTaskFactory
+from lms.djangoapps.instructor_task.views import instructor_task_status
 from openedx.core.djangolib.testing.utils import CacheIsolationTestCase
 from openedx.core.lib.url_utils import quote_slashes
 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 lms.djangoapps.instructor_task.api_helper import encode_problem_and_student_input
-from lms.djangoapps.instructor_task.models import PROGRESS, QUEUING, ReportStore
-from lms.djangoapps.instructor_task.tests.factories import InstructorTaskFactory
-from lms.djangoapps.instructor_task.views import instructor_task_status
-
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
 
 TEST_COURSE_ORG = 'edx'
 TEST_COURSE_NAME = 'test_course'
diff --git a/lms/djangoapps/instructor_task/tests/test_integration.py b/lms/djangoapps/instructor_task/tests/test_integration.py
index 96bbf1f8d9ebeef60cb5d930d24506dddf9fd1a6..ccec9ae4cea03004c83a089dc81712b8b3dd1405 100644
--- a/lms/djangoapps/instructor_task/tests/test_integration.py
+++ b/lms/djangoapps/instructor_task/tests/test_integration.py
@@ -5,45 +5,41 @@ Runs tasks on answers to course problems to validate that code
 paths actually work.
 
 """
-from collections import namedtuple
-import ddt
 import json
 import logging
-from mock import patch
-from nose.plugins.attrib import attr
 import textwrap
+from collections import namedtuple
 
-from celery.states import SUCCESS, FAILURE
+import ddt
+from celery.states import FAILURE, SUCCESS
 from django.contrib.auth.models import User
 from django.core.urlresolvers import reverse
+from mock import patch
+from nose.plugins.attrib import attr
 
-from openedx.core.djangoapps.util.testing import TestConditionalContent
-from openedx.core.djangolib.testing.utils import get_mock_request
-from capa.tests.response_xml_factory import (CodeResponseXMLFactory,
-                                             CustomResponseXMLFactory)
-from xmodule.modulestore.tests.factories import ItemFactory
-from xmodule.modulestore import ModuleStoreEnum
-
+from capa.responsetypes import StudentInputError
+from capa.tests.response_xml_factory import CodeResponseXMLFactory, CustomResponseXMLFactory
 from courseware.model_data import StudentModule
-
+from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory
 from lms.djangoapps.instructor_task.api import (
+    submit_delete_problem_state_for_all_students,
     submit_rescore_problem_for_all_students,
     submit_rescore_problem_for_student,
-    submit_reset_problem_attempts_for_all_students,
-    submit_delete_problem_state_for_all_students
+    submit_reset_problem_attempts_for_all_students
 )
 from lms.djangoapps.instructor_task.models import InstructorTask
 from lms.djangoapps.instructor_task.tasks_helper.grades import CourseGradeReport
 from lms.djangoapps.instructor_task.tests.test_base import (
-    InstructorTaskModuleTestCase,
-    TestReportMixin,
     OPTION_1,
     OPTION_2,
+    InstructorTaskModuleTestCase,
+    TestReportMixin
 )
-from capa.responsetypes import StudentInputError
-from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory
+from openedx.core.djangoapps.util.testing import TestConditionalContent
+from openedx.core.djangolib.testing.utils import get_mock_request
 from openedx.core.lib.url_utils import quote_slashes
-
+from xmodule.modulestore import ModuleStoreEnum
+from xmodule.modulestore.tests.factories import ItemFactory
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/instructor_task/tests/test_models.py b/lms/djangoapps/instructor_task/tests/test_models.py
index 5e0a0544ba9f41e16218574e490699f902e157c5..24d39e28b977a6747fae9417c215d5f4662cdd83 100644
--- a/lms/djangoapps/instructor_task/tests/test_models.py
+++ b/lms/djangoapps/instructor_task/tests/test_models.py
@@ -2,18 +2,18 @@
 Tests for instructor_task/models.py.
 """
 import copy
-from cStringIO import StringIO
 import time
+from cStringIO import StringIO
 
 import boto
 from django.conf import settings
-from django.test import SimpleTestCase, override_settings, TestCase
+from django.test import SimpleTestCase, TestCase, override_settings
 from mock import patch
+from opaque_keys.edx.locator import CourseLocator
 
 from common.test.utils import MockS3Mixin
 from lms.djangoapps.instructor_task.models import ReportStore
 from lms.djangoapps.instructor_task.tests.test_base import TestReportMixin
-from opaque_keys.edx.locator import CourseLocator
 
 
 class ReportStoreTestMixin(object):
diff --git a/lms/djangoapps/instructor_task/tests/test_subtasks.py b/lms/djangoapps/instructor_task/tests/test_subtasks.py
index 0c9d49626840d3fba037016e4dbde7323ea7ba13..12007862ef5429c0f33725c42f6743a0ee9c8c27 100644
--- a/lms/djangoapps/instructor_task/tests/test_subtasks.py
+++ b/lms/djangoapps/instructor_task/tests/test_subtasks.py
@@ -5,11 +5,10 @@ from uuid import uuid4
 
 from mock import Mock, patch
 
-from student.models import CourseEnrollment
-
 from lms.djangoapps.instructor_task.subtasks import queue_subtasks_for_query
 from lms.djangoapps.instructor_task.tests.factories import InstructorTaskFactory
 from lms.djangoapps.instructor_task.tests.test_base import InstructorTaskCourseTestCase
+from student.models import CourseEnrollment
 
 
 class TestSubtasks(InstructorTaskCourseTestCase):
diff --git a/lms/djangoapps/instructor_task/tests/test_tasks.py b/lms/djangoapps/instructor_task/tests/test_tasks.py
index 84f119e8c904ad8b86ebf10cfbb1c975a79617e6..6ab2e6b2a8bc7ec9902459396a65fd309107fbed 100644
--- a/lms/djangoapps/instructor_task/tests/test_tasks.py
+++ b/lms/djangoapps/instructor_task/tests/test_tasks.py
@@ -5,36 +5,33 @@ Runs tasks on answers to course problems to validate that code
 paths actually work.
 """
 
-from functools import partial
 import json
+from functools import partial
 from uuid import uuid4
 
-from celery.states import SUCCESS, FAILURE
 import ddt
+from celery.states import FAILURE, SUCCESS
 from django.utils.translation import ugettext_noop
-from mock import Mock, MagicMock, patch
+from mock import MagicMock, Mock, patch
 from nose.plugins.attrib import attr
-
 from opaque_keys.edx.locations import i4xEncoder
 
 from courseware.models import StudentModule
 from courseware.tests.factories import StudentModuleFactory
-from student.tests.factories import UserFactory, CourseEnrollmentFactory
-from xmodule.modulestore.exceptions import ItemNotFoundError
-
 from lms.djangoapps.instructor_task.exceptions import UpdateProblemModuleStateError
 from lms.djangoapps.instructor_task.models import InstructorTask
-from lms.djangoapps.instructor_task.tests.test_base import InstructorTaskModuleTestCase
-from lms.djangoapps.instructor_task.tests.factories import InstructorTaskFactory
 from lms.djangoapps.instructor_task.tasks import (
-    rescore_problem,
-    reset_problem_attempts,
     delete_problem_state,
-    generate_certificates,
     export_ora2_data,
+    generate_certificates,
+    rescore_problem,
+    reset_problem_attempts
 )
 from lms.djangoapps.instructor_task.tasks_helper.misc import upload_ora2_data
-
+from lms.djangoapps.instructor_task.tests.factories import InstructorTaskFactory
+from lms.djangoapps.instructor_task.tests.test_base import InstructorTaskModuleTestCase
+from student.tests.factories import CourseEnrollmentFactory, UserFactory
+from xmodule.modulestore.exceptions import ItemNotFoundError
 
 PROBLEM_URL_NAME = "test_urlname"
 
diff --git a/lms/djangoapps/instructor_task/tests/test_tasks_helper.py b/lms/djangoapps/instructor_task/tests/test_tasks_helper.py
index 69bcf22a4c22d629087756d88907f20dda5bd9bf..67dcaff60801db449640e05781a058349684b854 100644
--- a/lms/djangoapps/instructor_task/tests/test_tasks_helper.py
+++ b/lms/djangoapps/instructor_task/tests/test_tasks_helper.py
@@ -10,81 +10,80 @@ Unit tests for LMS instructor-initiated background tasks helper functions.
 
 import os
 import shutil
-from datetime import datetime
+import tempfile
 import urllib
+from datetime import datetime
 
+import ddt
+import unicodecsv
 from django.conf import settings
 from django.core.urlresolvers import reverse
 from django.test.utils import override_settings
-import ddt
 from freezegun import freeze_time
-from mock import Mock, patch, MagicMock
+from mock import MagicMock, Mock, patch
 from nose.plugins.attrib import attr
 from pytz import UTC
-import tempfile
-import unicodecsv
 
+import openedx.core.djangoapps.user_api.course_tag.api as course_tag_api
 from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory
 from certificates.models import CertificateStatuses, GeneratedCertificate
-from certificates.tests.factories import GeneratedCertificateFactory, CertificateWhitelistFactory
+from certificates.tests.factories import CertificateWhitelistFactory, GeneratedCertificateFactory
 from course_modes.models import CourseMode
 from courseware.tests.factories import InstructorFactory
 from instructor_analytics.basic import UNAVAILABLE
 from lms.djangoapps.grades.models import PersistentCourseGrade
 from lms.djangoapps.grades.transformer import GradesTransformer
-from lms.djangoapps.teams.tests.factories import CourseTeamFactory, CourseTeamMembershipFactory
-from lms.djangoapps.verify_student.tests.factories import SoftwareSecurePhotoVerificationFactory
-from openedx.core.djangoapps.course_groups.models import CourseUserGroupPartitionGroup, CohortMembership
-from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory
-from openedx.core.djangoapps.credit.tests.factories import CreditCourseFactory
-import openedx.core.djangoapps.user_api.course_tag.api as course_tag_api
-from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme
-from openedx.core.djangoapps.util.testing import ContentGroupTestCase, TestConditionalContent
-from request_cache.middleware import RequestCache
-from shoppingcart.models import (
-    Order, PaidCourseRegistration, CourseRegistrationCode, Invoice,
-    CourseRegistrationCodeInvoiceItem, InvoiceTransaction, Coupon
-)
-from student.models import CourseEnrollment, CourseEnrollmentAllowed, ManualEnrollmentAudit, ALLOWEDTOENROLL_TO_ENROLLED
-from student.tests.factories import CourseEnrollmentFactory, CourseModeFactory, UserFactory
-from survey.models import SurveyForm, SurveyAnswer
-from xmodule.modulestore import ModuleStoreEnum
-from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
-from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls
-from xmodule.partitions.partitions import Group, UserPartition
-
-from ..models import ReportStore
-from lms.djangoapps.instructor_task.tasks_helper.certs import (
-    generate_students_certificates,
-)
+from lms.djangoapps.instructor_task.tasks_helper.certs import generate_students_certificates
 from lms.djangoapps.instructor_task.tasks_helper.enrollments import (
     upload_enrollment_report,
-    upload_may_enroll_csv,
     upload_exec_summary_report,
-    upload_students_csv,
+    upload_may_enroll_csv,
+    upload_students_csv
 )
 from lms.djangoapps.instructor_task.tasks_helper.grades import (
     ENROLLED_IN_COURSE,
     NOT_ENROLLED_IN_COURSE,
     CourseGradeReport,
     ProblemGradeReport,
-    ProblemResponses,
+    ProblemResponses
 )
 from lms.djangoapps.instructor_task.tasks_helper.misc import (
     cohort_students_and_upload,
     upload_course_survey_report,
-    upload_ora2_data,
-)
-from ..tasks_helper.utils import (
-    UPDATE_STATUS_FAILED,
-    UPDATE_STATUS_SUCCEEDED,
+    upload_ora2_data
 )
-
 from lms.djangoapps.instructor_task.tests.test_base import (
     InstructorTaskCourseTestCase,
-    TestReportMixin,
-    InstructorTaskModuleTestCase
+    InstructorTaskModuleTestCase,
+    TestReportMixin
 )
+from lms.djangoapps.teams.tests.factories import CourseTeamFactory, CourseTeamMembershipFactory
+from lms.djangoapps.verify_student.tests.factories import SoftwareSecurePhotoVerificationFactory
+from openedx.core.djangoapps.course_groups.models import CohortMembership, CourseUserGroupPartitionGroup
+from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory
+from openedx.core.djangoapps.credit.tests.factories import CreditCourseFactory
+from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme
+from openedx.core.djangoapps.util.testing import ContentGroupTestCase, TestConditionalContent
+from request_cache.middleware import RequestCache
+from shoppingcart.models import (
+    Coupon,
+    CourseRegistrationCode,
+    CourseRegistrationCodeInvoiceItem,
+    Invoice,
+    InvoiceTransaction,
+    Order,
+    PaidCourseRegistration
+)
+from student.models import ALLOWEDTOENROLL_TO_ENROLLED, CourseEnrollment, CourseEnrollmentAllowed, ManualEnrollmentAudit
+from student.tests.factories import CourseEnrollmentFactory, CourseModeFactory, UserFactory
+from survey.models import SurveyAnswer, SurveyForm
+from xmodule.modulestore import ModuleStoreEnum
+from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls
+from xmodule.partitions.partitions import Group, UserPartition
+
+from ..models import ReportStore
+from ..tasks_helper.utils import UPDATE_STATUS_FAILED, UPDATE_STATUS_SUCCEEDED
 
 
 class InstructorGradeReportTestCase(TestReportMixin, InstructorTaskCourseTestCase):
diff --git a/lms/djangoapps/instructor_task/tests/test_views.py b/lms/djangoapps/instructor_task/tests/test_views.py
index 39bd8217a0c1a3df9c3742d7436598734863566d..80b1c51f7bcf1db3e52685d3e814ba2667469798 100644
--- a/lms/djangoapps/instructor_task/tests/test_views.py
+++ b/lms/djangoapps/instructor_task/tests/test_views.py
@@ -3,19 +3,18 @@
 Test for LMS instructor background task views.
 """
 import json
-from celery.states import SUCCESS, FAILURE, REVOKED, PENDING
-
-from mock import Mock, patch
 
+from celery.states import FAILURE, PENDING, REVOKED, SUCCESS
 from django.http import QueryDict
+from mock import Mock, patch
 
 from lms.djangoapps.instructor_task.models import PROGRESS
 from lms.djangoapps.instructor_task.tests.test_base import (
-    InstructorTaskTestCase,
+    TEST_FAILURE_EXCEPTION,
     TEST_FAILURE_MESSAGE,
-    TEST_FAILURE_EXCEPTION
+    InstructorTaskTestCase
 )
-from lms.djangoapps.instructor_task.views import instructor_task_status, get_task_completion_info
+from lms.djangoapps.instructor_task.views import get_task_completion_info, instructor_task_status
 
 
 class InstructorTaskReportTest(InstructorTaskTestCase):
diff --git a/lms/djangoapps/instructor_task/views.py b/lms/djangoapps/instructor_task/views.py
index a1f6a1882407c394e5b173d188d08eded438c0b2..07f11372cb4fe10baeab341570f8d1c46d27b0f8 100644
--- a/lms/djangoapps/instructor_task/views.py
+++ b/lms/djangoapps/instructor_task/views.py
@@ -2,15 +2,13 @@
 import json
 import logging
 
+from celery.states import FAILURE, READY_STATES, REVOKED
 from django.http import HttpResponse
 from django.utils.translation import ugettext as _
 
-from celery.states import FAILURE, REVOKED, READY_STATES
-
-from lms.djangoapps.instructor_task.api_helper import (get_status_from_instructor_task, get_updated_instructor_task)
+from lms.djangoapps.instructor_task.api_helper import get_status_from_instructor_task, get_updated_instructor_task
 from lms.djangoapps.instructor_task.models import PROGRESS
 
-
 log = logging.getLogger(__name__)
 
 # return status for completed tasks and tasks in progress
diff --git a/lms/djangoapps/learner_dashboard/tests/test_programs.py b/lms/djangoapps/learner_dashboard/tests/test_programs.py
index 27c3ad024ecda0886bcc6273187d4936413009b4..43c9625cc7e704e5ee68fabf509db3309fd2b35b 100644
--- a/lms/djangoapps/learner_dashboard/tests/test_programs.py
+++ b/lms/djangoapps/learner_dashboard/tests/test_programs.py
@@ -7,21 +7,20 @@ import re
 from urlparse import urljoin
 from uuid import uuid4
 
+import mock
 from bs4 import BeautifulSoup
 from django.conf import settings
 from django.core.urlresolvers import reverse
 from django.test import override_settings
-import mock
 
-from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory, CourseFactory, CourseRunFactory
+from openedx.core.djangoapps.catalog.tests.factories import CourseFactory, CourseRunFactory, ProgramFactory
 from openedx.core.djangoapps.catalog.tests.mixins import CatalogIntegrationMixin
 from openedx.core.djangoapps.programs.tests.mixins import ProgramsApiConfigMixin
 from openedx.core.djangolib.testing.utils import skip_unless_lms
-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 as ModuleStoreCourseFactory
 
-
 PROGRAMS_UTILS_MODULE = 'openedx.core.djangoapps.programs.utils'
 
 
diff --git a/lms/djangoapps/learner_dashboard/urls.py b/lms/djangoapps/learner_dashboard/urls.py
index 27e5e83ecd551b60732df936c64bda5251da407e..1f2f053cdde68f5d8164a8971f009035cf143df1 100644
--- a/lms/djangoapps/learner_dashboard/urls.py
+++ b/lms/djangoapps/learner_dashboard/urls.py
@@ -3,7 +3,6 @@ from django.conf.urls import url
 
 from . import views
 
-
 urlpatterns = [
     url(r'^programs/$', views.program_listing, name='program_listing_view'),
     url(r'^programs/(?P<program_uuid>[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 d214b03a51850c158bec89ca51ce300eee936d1b..4b34c10540dd0de966f53a44324bc7f76bf5e9db 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 f8411ca5df39e24d92e8e90538edc3f0523ac37e..e54ab412362c45ffa2819dd16a073bd8be2d50d2 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 75dc6975d9f8b84adfe51bc2adeb587965b11996..1ec0ebf0a1591cdf6c62e8a7df4a64cf4b9c1c4e 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 4f70c49b50d248a9118849ac887bea9655785d12..e3c6769479addcc5aa3021c89fcdb7e648e08e53 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 datetime
+import json
 import os
-import sys
+import readline
 import string
-import datetime
+import sys
 from getpass import getpass
-import json
 from random import choice
-import readline
 
+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 3c877626249f303a99ccd26ce8a9ff3a9aa0bb2d..0798790e8020d64a2be0fd335e0e7125d92471ea 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 e3a6751b0d780549fb7748b5519f881205e6db95..4e9b794f7be8b13955658e92e27a66e03d79ba43 100644
--- a/lms/djangoapps/lms_migration/migrate.py
+++ b/lms/djangoapps/lms_migration/migrate.py
@@ -5,12 +5,13 @@
 import json
 import logging
 import os
-import xmodule.modulestore.django as xmodule_django
-from xmodule.modulestore.django import modulestore
 
-from django.http import HttpResponse
 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
 
 try:
     from django.views.decorators.csrf import csrf_exempt
diff --git a/lms/djangoapps/lms_xblock/admin.py b/lms/djangoapps/lms_xblock/admin.py
index 81ba9d67fcca56786613d438c93ae48a4155094d..61ccb4eefb3538351ab8202ba8948922f58c9837 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 397e85306a775e16e4c916c5f582cd3dea33fa3e..2e850088a60e90b9dbc40d4cedb842448b5fecdc 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 a67878be48cd57110dfdca21c8f8d43854cfdeb8..14129647cac25640d29264805984a36d8d8e2be8 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 58bf0f1f96c35fd826089d002ecc32b9027b7edb..5b165bb1860e200dd420d4f08301a2767e2522ab 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 0f37ea35eded0d7a36172a3c1435220bbc9b2d83..aa6331d969587bc747b76bb608223b2ffe320b88 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 urlparse import urlparse
+
+from ddt import data, ddt
 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 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 02a556c0a71e7d2580e43318a97d8ea18d1c4769..a6ef87c80fce42351309c93819fc4c262cf4e76c 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 77e09890dcceb9f18d320589dc41a9db38c5c006..52f799d72b9672fc5d0ea9d280facc712b314235 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 2dcc0cb61deed3a2a77dc7e293d4a2752b34a7d9..f55338c693d12200a79e2d838b2c5d0a96953934 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 2d70b1c97d07ed4753774a9e084a7dea5ba93503..a69fede350b8cebe8b2e568aea75f6ee3be70bc6 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 3353db18c1413bbf08ea37e213faa7de3d34f010..d61276489d39d2ed5aea06b584de59c31c91344a 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 ff27579134c895ea662bdad262d68c17575525f6..24f5f6e505e6627428a437547712bc16b0255950 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 aa9fe79c25c81776919e81dad981d262c99d2885..4b57dc7fc08245c9f5e424cbd6a452bb9310dbdd 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 e7a195554d7551c00b0f2a6fd7b0213a522ef969..c37675a2bae25149153d08ce5f0c9165dfb7167d 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 193a6dac70aa7de45e8ba7d246108991d01b9248..2f25af26febdf4e1b7c97c037438a897ba54513c 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 ae535bb5ba29ac4919c70d6329dee3830af3d7b0..ca8f5364b4362da6c3c0c119be7da92ea6c63c56 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 7c0440bc9f25fc13c253e5219c65979781802ba9..8882a0ee098c1526ef57dc41983b2c23b63a6554 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 41ec1c8eb920e255d46126d6edcd206f2ff6ca3c..ce625f35c1006b33eb9175cfa8179510628af0e1 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 5b948c518c1c0a29d7feb52d719398666ec6ce7f..9f5cf18c0cc6dbbc78b350e7f885ef49b42ac1f4 100644
--- a/lms/djangoapps/lti_provider/views.py
+++ b/lms/djangoapps/lti_provider/views.py
@@ -2,17 +2,18 @@
 LTI Provider view functions
 """
 
+import logging
+
 from django.conf import settings
-from django.http import HttpResponseBadRequest, HttpResponseForbidden, Http404
+from django.http import Http404, HttpResponseBadRequest, HttpResponseForbidden
 from django.views.decorators.csrf import csrf_exempt
-import logging
+from opaque_keys import InvalidKeyError
+from opaque_keys.edx.keys import CourseKey, UsageKey
 
-from lti_provider.outcomes import store_outcome_parameters
 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 922d10b80d9b0bf7764876334d4c4b70c23957a6..8b8f9fccea3ddca257356cdf6416e7940fea34cf 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 718f25b34d8386abd1d29e6d59838cf458618071..188cc54b30fef11a598a034d4bfc6b6c17cf2b7d 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.core.management.base import BaseCommand, CommandError
-
 from django.contrib.auth.models import User
+from django.core.management.base import BaseCommand, CommandError
 
-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 3a1919fbbecc0f3f6dbb92ccaefa9f96054f9b5f..1abc9b4498b34cbcddc2e129d68408730463ec04 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 84ae1387a01456a5a4da92407e9e6e43f68f994f..3a7c5f5862616ef2d37ed4fca9d542d1e8fa7c84 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 149ae624815b5968e804ddac0915a4625f81af91..e1739df4afc50652e629a9ea1b3aef8b31b95db9 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 13557db83bcde93c193ea630d1aab0129f9d5ca0..a4a31bfe11f2835d6abae3d742b3f6a7a9f01bb2 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 abc04c6fcdc147b08025c4ca173f5293fbec515e..e8eb92456221ac25d110be9a609cbe456ada740f 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 921cb2f8abf606ca116b1071dcb6a585b9273400..65c6a3fe594dcab8a877d56fbf4dca531bceb536 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 05744706d4cf09bccb6bc167af899a86b5485353..839a496c06db400f9ce73b207bc0c1503cd86f17 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 d2e26ed77698444c26fe3ef352be63c0188469ef..b2547f6fc085080c3c1f9ae6c17c1b70e96fcf76 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 bd200bb97d277d490a1f49c2080853405c27ba0a..3c7f22b4e22f01fa5b0b92eb11554545f9a49d45 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 04ce53a7d0846111fd55094d5c1367318748217e..0f021897e5d829d9f9695444a9ecfd2a4eb173ab 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 89832f92b70503e87cb9d0697c898f30c61e134f..15ffad9dde95cfa9db02752629438074aa9d0605 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 35fc627cad39dc9b349dfdadf65142b407e56ffe..550d9523e15712023f1042be2f08878a0668345a 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 864fb9fdf33af89afdc7ad451a8e1a3265ac91fd..e2ada74ccd6d859bec17fed929af0759438f322b 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 6debf74a6294b219da684a9058d7b43020c2e74d..2decf2b4497a1b4b112563b8d171e3f416cf9822 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 2cb0e642634090a623dd49f38fcc04eb054044d2..a385dcd44790efc1d0498355f10790c1cfbcacd4 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 64f1ad4a55330690cdced3114dac69fd0f78531c..91efbb0101f7d1af05bde7243000d181fc34d6d9 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 9ec9a071b6254869183e94bcdd2f3a2b98842072..6a5a8b9be190339cdea1712126eef1d31b0fd847 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 f1eb5a813b04234eae8b1d3f65aa4f58c1aba1ec..5c0e08315a88a9b0b7f17f33790ddf89c51f5831 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 877bb87b7ccdd659a4ce1628ad5dd32b6f669b5a..144649729f9df3534c6ebaf949faab5c40d6b022 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 3ce13378ad0b8d8a89ec232d585690901a21386e..01c05acb7e8171109c51cbec793bf74d5548aa34 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 d471d40b214b09dac9b3344c9c2e020bfc2fc448..2160b02984fda8827be2ddb07b2368b886ad59e6 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 44abb99e203957f821c92e9911efb84d9bb2d199..a892bf05e52ff173d15fdd5d579c42fa32651795 100644
--- a/lms/djangoapps/notes/api.py
+++ b/lms/djangoapps/notes/api.py
@@ -1,15 +1,15 @@
-from opaque_keys.edx.locations import SlashSeparatedCourseKey
+import collections
+import json
+import logging
+
 from django.contrib.auth.decorators import login_required
-from django.http import HttpResponse, Http404
 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
-from courseware.courses import get_course_with_access
-
-import json
-import logging
-import collections
 
 log = logging.getLogger(__name__)
 
diff --git a/lms/djangoapps/notes/models.py b/lms/djangoapps/notes/models.py
index 4d9a5bdd6f098e10964f41c534f46aeaa3d476a8..f7138c2c34f4de326151109102aa89603b93ec81 100644
--- a/lms/djangoapps/notes/models.py
+++ b/lms/djangoapps/notes/models.py
@@ -1,9 +1,10 @@
-from django.db import models
+import json
+
 from django.contrib.auth.models import User
-from django.core.urlresolvers import reverse
 from django.core.exceptions import ValidationError
+from django.core.urlresolvers import reverse
+from django.db import models
 from django.utils.html import strip_tags
-import json
 
 from openedx.core.djangoapps.xmodule_django.models import CourseKeyField
 
diff --git a/lms/djangoapps/notes/tests.py b/lms/djangoapps/notes/tests.py
index 69a2593d6dd746c9a1e6f3fff03b5e9af983884d..bf14fb88657d0b9bbeade1256a013aeded9ad9b6 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
+import json
 
-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
+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
 
-import json
-
+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 6abe92253a02552817925a7e26dbbd8f8c229f4c..c083507e78a597907f0b4d6b350dbabcb1a3b29d 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<note_id>[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 4b2ce51c028f875f83327060ce50f79e66842c04..47690c4e41a4ead58692da246a0a782dccbd49b1 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 00221732cec72f326d12ab69233a0eb15f9df3ce..627816cb4207925b91278dc7e578a6191eb82c71 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 e67d4e91abb3af14b83d564672c8be0ffe684d50..87854badfacae9b171c68f7e3ae3adf4902513a6 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 c60d702e21d8d0d87aa84045ee7ef917cd2a2818..09e9bf64f76dd9d93334b2b31bb00671ce00d845 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 dc21bb48ef15928f24f2810cb8064cc7ba196b1e..e20796a3cf50ae2daf1e11c3d1d0bffda775bdd8 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 e55857e752110dad3c40f9b80cf85200222d59c9..ac3d9dba8ae7a636dca4c2119b08e4de5419d38f 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 4a1d65dd8ba6355f306629bfe75ecf04dd37a783..f65260df5016e607490751abc13b9f98beea0804 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 44e1c78037ec0116900f7bb4235bf87f933cc958..2786cfb96a4ece1eefcfba0df93b093b2557e1f5 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 122ccd41ffb699bda6f5fea3e7996b5f5ac9412f..da7f44043daf7a22b882a28fc51a457746a9ea33 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 878dadcb6ae70b1841ada08bc861a3d0c5ef8ac7..e9316170dbc141826a91308a92671df6e409d6d8 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 fa5af3753bfd85d3be8d881c4ee2a1b945340041..b0e7c0586ab189f1299b2b630f7a9946daf0a151 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 c880eee623463f651dcb80e91a0d3e859cf289dc..77bb599e5557a052cd3a8385948bd8d3b7048fce 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 90a499e19aa27fa55124cc57d11028206ad83f1b..1a40fa3c50c74925ad4d0e1c9d514ca320e289af 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 b61772c9e365a271efa01ade886cea3d2e32a6df..bacfe92e2d8ce690e14b6ba543210fa75076417f 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 023d0529a685db0a627f7a33eb8079f42cd62438..15c86988ed5a99292c50284ee9d70686e54e80b4 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 9385eef3347fa37c81d46ce804d0afd6c936e03d..e40646302d0509ff228817bb80b247047a48f0d9 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 65f2b95508d4bd01cc6303ac511556fad8ac55ca..b8157cab37e6e81e5e86a7213f9ebb6a0e898b6f 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 95411944bb81d7ec90e61989e5c9bbd965c4c0a3..eb3546eea477ac30dbfe3a27bf0ba8c5e917ce7b 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 9f4366f8bb30577c601e4e760418f73b7bd7011e..10f132bfc392f75f6feaf89f08b79e8f23cb8a72 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 e6539e2c13aa80735a9f89ac32b8e06ed71be9ee..a48925b28d8a8b87fdde88cdb98a7a244479193f 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 140cbd309a3a566833139fc4b6f486de34fdbc7c..c11f37dc0e127d9183f43f2dada4c00b3b09b600 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 dc4de3e0449a73d09ea0f2926e3d51e0495385cc..144df4bbed9d48b0ee9d9e56d783aea4124f04fb 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 09f1504e30e4d8546b7e4c08ac261206b6aa4eae..c80fc3cbf5a5997459ad5d09132d9fdb95d9a3b5 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 b5e84453c1f2463a37959ece0490d727db30093d..305d3ffd7c70143ecae46fa3952fb6ea311fd75d 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 6720c17f7176754a162c7f47b7827176d277e249..5a3aadd73622206339d44b8ac809f6dad405640a 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 953c0c5102ec8e9d70099e935e6745416e6fd642..78c9e633083d7a00e8ab6ee7900fd6b55e7bd73e 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 3d1117feb5c57c8041187e124bb8a21d9cb42f60..cbfd8b54537fdad577f42d444e91ee227b30c8ac 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 62b7a1924af305173824a56e1cb5e990c21788f6..323c12e2379f17f701f5b573032c29c3c829c2cc 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 a7319ceff97d18e87dddb4d67df88792458186ba..d9630d99cc8427c1476156741c426821dd67cd1b 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 71ef16a7588505bc5e292ab2a0adf219c05f35e2..efb3df62f5f6940a9e70f14f8679c14def68749d 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 edxmako.shortcuts import render_to_response
-
+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 da85df5b66a064d76b8e751435bff9acb2a803af..e70a75db45054aefdfb07cf5fbb56c20d6d75441 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 4a62667e3efa9de5a3e467be37a71a06b89d378b..93d801a1571782f35f7596c76fc8f234692d943e 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 08e8e27d0927942df890e908a964778c08ccd853..94597e42b1c086677d0aaf559661f12e660b00a2 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 copy
 import datetime
-import sys
 import json
-import copy
-
 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 e28997a9650b1a35419dc8184540fdf0c7c11828..b45b82919a86d0df917712af93b2e2270f1ef0aa 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 635862ad65422ca6cdf1ee699f9cb8f3c3f2e256..c1e520d29a6c3697f6fe141b5e8845bd95769e3c 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 c362336be55a60354877d09670c657e11edc0699..307bdb074d56f8f6a80eacd3e37d0c7a79cf5d93 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
-from mock import patch
 
+import pytz
 from django.conf import settings
+from mock import patch
 
 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 dbe64eb1588ef654741e41d275b48e52f8492b8f..35b439275b6af50eff05b638cfd4449685ce4a3e 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
 """
+import json
 from collections import OrderedDict
-import pytz
-from urlparse import urlparse
+from datetime import datetime, timedelta
 from decimal import Decimal
-import json
+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 9363521ddc825d37ba7c453524faf94fa4440ea0..a1cf21bffa888e7b2f193d0286b3306aec4f28fa 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 8eeb536db516c1163a48445430cfe646a32ac33a..3777cc1e50e12623e44ab2eaac6365b7ec8f7b08 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 d4e6c257623e7c8fc44dd35baa6ea2aa1e2ee8fd..227385148299722835b23de5007c7a1ec08cfaab 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.decorators import login_required
 from django.contrib.auth.models import Group
-from django.shortcuts import redirect
+from django.core.urlresolvers import reverse
+from django.db.models import Q
 from django.http import (
-    HttpResponse, HttpResponseRedirect, HttpResponseNotFound,
-    HttpResponseBadRequest, HttpResponseForbidden, Http404
+    Http404,
+    HttpResponse,
+    HttpResponseBadRequest,
+    HttpResponseForbidden,
+    HttpResponseNotFound,
+    HttpResponseRedirect
 )
+from django.shortcuts import redirect
 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.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 45550f0896972da61ace1d11b7678e68e77dc019..e6c6b5c1d9931c0abafce6f00ad46c447d98977f 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 3a13f9a88113be08e46d2df64df8a5c421f5deeb..67bc79028047f62d9b573d01f8c017d479141779 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 b3b3e2e65a21fe7b1a02c1366e8e199aa74467b1..a5cb1fcb64095f38df2dec7ad67f132885b5ea85 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 7e904b582cd61648086e2552565d6bb828cfe867..78f9bec0bc5b837373d48e6e1a95646044dd0c17 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 49c367f3e57a66cc6ed91385b310b787e1135824..10b5baa40dff4c5fafeae0b7fc4f47ea7e748d0b 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.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.djangoapps.site_configuration.tests.mixins import SiteMixin
 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 9a7357d3063455b28b1ef7aaab45bc09ba667f9a..8d8657fbbb88f56d962a1d4abe8f1a8757668cb5 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 56223d7bd0ac8a8559f6a50e88bb49e497d96919..0a6da2607643f776d72e23f0ca3d682401fffa11 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 5299b513089d1566851fc763ade08657b1668669..25fd93513c07477eff61b690c1cc53e4e9922642 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 795a50ef063b4bc294a8a32d649f366cc2e3b66d..51427b54cc97774cf87ef734b39baf2f6ecfa56c 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 090fb882b421d3670de18c4b4a54405b26accc26..b7d0fc296827b128c3059c3f7a87cb7a8495bec7 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 3023d8cc9c0221127ed760d2c73d4328c5311001..6008ed11700c1a555408447e1d975c53ff818b64 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 d30c69363e31940eb48a01da5f19f9aeeb41c7c6..93d7f966e89d6dd751feb80b93b4a551b42baf00 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 b6f1a7e06dab689f089f7bf540eed578c04e2072..246f528974ac532c929fb9abc6deb732f5e4a58d 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 1a2ef8dd320d0562f40f264c06e09ca699d48a30..5bed96e69651bd91285c89afa0be0b8737ec1626 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 df712f23ae34f65cea79c0a458e2941e985e3259..5085554d25e6af358b13bd5ad459c8bc42a395ce 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 bf922cb3ba417db7e4e7a9a7068d495b9a3f8679..bc4104688bf313ebefcc6f7158ad427fbcddf323 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 import forms
+from django.contrib import messages
 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.utils.decorators import method_decorator
-
-from student.models import CourseEnrollment
-from opaque_keys.edx.keys import CourseKey
+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 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 b853a8445af28d136bc64bb2733a77218765dac5..8c1e7368debf8d1b7648a43be91c51e46b9a58b6 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 bf4dd451b4e6a1439a339234209d27612d41e4be..ecc2342b0fcd80478071243cb59ab5fad6b50ee7 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 881c0878356f49f3402781e456d43363e1a598cf..1c286e60551e3892046ca5d5c77b3398eb70674d 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 00c1d3ea41ebd7e6e5c72684a6c7fa9425d4388f..01da86079de342578535c228e90308d8044f0309 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 db52d06a3a02c0a4df058c4d42e0e776659817d5..b324f29983d3c2d1ab0cf5985c355778386008ac 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 ad986159e4142c5af93479fbf4e5eb650a6f2d91..c73e4eae7c8714d1bac35772961529b9c459a5b7 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 39c03e58f990e4658531d4ffa791f768ca38e1ff..1af29f2d4055c1050190494d060484a9f943e5d5 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 725bea80599a061b33d44aa79fe56f443087a685..db54ddf8917234a8e30904a376f6933d480fdcc2 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.conf import settings
 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.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 0d71c7856705abf6c552df1449b2715329de3ee4..708057ed63ee24f1dc3308dcacb2c912d14acbde 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,
+    MembershipDetailView,
+    MembershipListView,
     TeamsDetailView,
+    TeamsListView,
     TopicDetailView,
-    TopicListView,
-    MembershipListView,
-    MembershipDetailView
+    TopicListView
 )
 
 TEAM_ID_PATTERN = r'(?P<team_id>[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 8061ee466f41e93e069cfdcc53cdb840f33da9c2..cb5647e7e22733d8b46fed35c3df64ce2a2bd716 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 62e28a886c96b3e0da0fb53ede8300bf690d3eeb..f04a731c103d2b20e7411168928ffde514d00ec2 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 21967f2127d4b14ecb01f47d79dcfb3dd40c0373..154f424acd9a77247425078e9a6448bb649c7462 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 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 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 .errors import AlreadyOnTeamInCourse, ImmutableMembershipFieldException, NotEnrolledInCourseForTeam
 
 
 @receiver(thread_voted)
diff --git a/lms/djangoapps/teams/plugins.py b/lms/djangoapps/teams/plugins.py
index 9a167da5cee90e346429ba132bc8c56d53922f2f..e0cc852277be11a80376e96251a4359b00002d60 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 9fcba08d0ee6c89f799c6cda572d2f4844add1ad..69ea9d112186adb7d937d23745f2d6a92106948e 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 84447656400f5165bf72ee830360510d54d38c46..d63591a75f12e5e0b837a374c8d186784c105df6 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 25375a76cb85c6835d721387a1564f9ba5544c7a..a4991df4c251b3d055e5874d0e32d6a5298e4ead 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 ea820329c272627f3d59d42ea89827974eac5f52..7bcd29d1445fa781ad37e6afbbdc9442c4f19926 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 189b8fa3494728ef483ff0f20f449efad53c5d16..b5a243fc47da7200d7ba0ef1f5aa98b0e90ae9fe 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 149272219709e43eb31ecc99ef9131aeaed3d00c..0bd970565bcc73dba339017fe65f654aeb71f732 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 xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
-from xmodule.modulestore.tests.factories import CourseFactory
+from rest_framework.test import APIClient, APITestCase
+from search.search_engine_base import SearchEngine
 
-from courseware.tests.factories import StaffFactory
 from common.test.utils import skip_signal
-from student.tests.factories import UserFactory, AdminFactory, CourseEnrollmentFactory
+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 .factories import CourseTeamFactory, LAST_ACTIVITY_AT
+from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
+from xmodule.modulestore.tests.factories import CourseFactory
+
 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 4ed307c494b99610c6cfc1f680afcf3c6c1f8aef..03881a6b79f3e2653b9567d34b7b50c74b0f88e0 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 a440e5b67399a01afff81b8ccddd237603ca92b2..a733da6ca687c8983b42d453f1661034e3627e51 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 2efdeadbde702c27a892ffec16cd97bd5d61c97b..c28c4e327dabdfb30ab105e4984b7baff148d8df 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 0be17a842ddd52ba367ec376317b26920016eb70..0e56c0d102bca01490d87f3289b2c7682d247ec8 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 04682ec699201907df4a2a8d6dd3d64bf4b0436d..87d8aa45ec8c493c6fb1caf0a6f4ac50e229d856 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 3d46b47c5d2258151143624906244332de5a504d..57557d6d4657a6a638605f0732c47b1f913c526b 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 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 config_models.models import ConfigurationModel
+
 from course_modes.models import CourseMode
-from model_utils.models import StatusModel, TimeStampedModel
-from model_utils import Choices
 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 680ab4f8a497ee9adc87ca19da1b250e79ddf360..33be53050c8aa39ce45e18b38770f9388ff8eaac 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 474ff2a3e58872a0bec257045cda2d1ede975a49..b332a184f656e5e90e361c246afc2ad54fe7d3a7 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 a83b6f644fea144b6fe38f8407c40c5ea80dad14..ceb301e27b19aff5ec0c73d2d88ca3314dc29638 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 9abe2be505741a275813f380a0dfc00757b42346..295e632b46189324f84dc8b656e878b0656118f6 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 a9c2b4b8dcafeba5054e2727704df25f9f7f63e6..fd72054035e944e04656f03b10bfd4442c085fa5 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 c45c9cd350bb50b433bb26ed2765a0f34410f97b..fa8d278b3553a7785ad28e36b43e84b08cd326b7 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 b49e31f8f67aee3b44755d6ea05c110d1e3868f9..35efe8b57ccda4bf160d8470b95551b5c375f4ef 100644
--- a/lms/djangoapps/verify_student/tests/test_models.py
+++ b/lms/djangoapps/verify_student/tests/test_models.py
@@ -1,31 +1,35 @@
 # -*- 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 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
+    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
 
 FAKE_SETTINGS = {
     "SOFTWARE_SECURE": {
diff --git a/lms/djangoapps/verify_student/tests/test_signals.py b/lms/djangoapps/verify_student/tests/test_signals.py
index c7baece697282802f45290b05290fcd6c3d6c7e2..5b0cdc29e9b70e4d1561721dee9ea33e367aaba4 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 7a3b83ba5dc06a82ae0c166fab4fbfd7ee7a6c57..a77923c7961ac7ff58ac3c5cf864ba6abb98a06e 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 03bed48f582c0a82870127707b3b22341ebf5764..0a2253a11e51c5bc082d7e79378af47a9b5c7a06 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 bee7f2557330717ab708afb59728edeec5193278..c75e783e079e67ac28ff783da2c1c179c1552cde 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 861264d82f49ec25afb034f53fd94b4f67396a5e..38dafa9268530f9ee52c1e56416f7c64b942f98c 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 76f200f9f47401d2df91298ea7f972403c99c354..d0b23eadc4ebadc3caeba9dd3cd272439e1e9bc0 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 0562c9ada10b606ff3ae80c3c137c83b8619586d..bfd7b687f45f01ab302465adada1013bf25d7768 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 93a2c280223ea2417348b2f698b06d7e2c3cb204..5a5a1f9113093a212538ae81013a4b32aa7cce77 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 ed7f5c292b246b0c9181901b0233f9060a40a17a..cbf5cd257a66e22d0ddb14974d9b5dcedc1c132a 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 b50a3dd2bfc028bbc46b41adb4d1ca3b3bd1577c..07ab6d3c3929e44b71c1e94d8c9a8fc7f6c0b7bd 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 d43f563b57afb5ee452ebbe6c3c8c1479ae8468c..22106504c29bc0faea06001ad7c1e0266ffc1b30 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 0531574b408a1df6938457267f06d7dc0ff55846..33793107c6936a6b5979e06f3c6b7cde7344dffd 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 1af0713696b8bdf2697601c9dff5783507c6f942..c2e33ab18b60cbd8db2e27bb50a811ce0bf0ea47 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 73d6df73daf9f69afde04e4f085beae867004fcc..50ae2ad4a6c29f34cb924063c8dfb3a90501986d 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 eec36e1a57df78571ac22f998253f7da6ae3bc8a..0c62d05c3f9ce5626bae1b46abf998c82acf427e 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 3f062c87d873bbaf0f886a5542c29312ae94b2b5..2f88a8bbd4b36a2126a19c62de0f9016fd0685c4 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 ef85771b72061a2b2cb4ecf2ffe8e9807a746b2d..e37cebe82ec13d5f5adc32d8a877de3aaeb0a808 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 c70d482bd0bfa9d3dd5036cb1cca7447a7431edb..cddcc181d95c553b98b9bb55010b74b81e5dcf63 100644
--- a/lms/tests.py
+++ b/lms/tests.py
@@ -1,16 +1,16 @@
 """Tests for the lms module itself."""
 
 import mimetypes
-from mock import patch
 
-from django.test import TestCase
 from django.core.urlresolvers import reverse
+from django.test import TestCase
+from mock import patch
 
-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 8e9b64774d5cb89886f9140730ae2a488f015eb5..b0cf9b295fa6d62952aa6818732bc8df215d6012 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 3bf713d337e02f2ddfd9f396b4322d70b2f1570f..673bf03b017eacfb82302ab3ccafde56dd5fdad6 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