From 79acb5c5be9ad5cc439484792de0737535e6ec92 Mon Sep 17 00:00:00 2001
From: Andy Armstrong <andya@edx.org>
Date: Tue, 30 May 2017 09:42:18 -0400
Subject: [PATCH] Reorder LMS imports using isort

---
 .isort.cfg                                    |   4 -
 lms/celery.py                                 |   3 +
 lms/djangoapps/badges/admin.py                |   5 +-
 lms/djangoapps/badges/api/serializers.py      |   2 +-
 lms/djangoapps/badges/api/tests.py            |   2 +-
 lms/djangoapps/badges/api/views.py            |   4 +-
 lms/djangoapps/badges/backends/badgr.py       |   3 +-
 .../backends/tests/test_badgr_backend.py      |   4 +-
 .../badges/events/course_complete.py          |   4 +-
 lms/djangoapps/badges/events/course_meta.py   |   2 +-
 .../events/tests/test_course_complete.py      |   5 +-
 .../badges/events/tests/test_course_meta.py   |   9 +-
 lms/djangoapps/badges/models.py               |   4 +-
 lms/djangoapps/badges/tests/factories.py      |   2 +-
 lms/djangoapps/badges/tests/test_models.py    |  16 +-
 lms/djangoapps/branding/admin.py              |   4 +-
 lms/djangoapps/branding/api.py                |   5 +-
 lms/djangoapps/branding/models.py             |   5 +-
 lms/djangoapps/branding/tests/test_api.py     |   6 +-
 lms/djangoapps/branding/tests/test_models.py  |   2 +-
 lms/djangoapps/branding/tests/test_page.py    |   9 +-
 lms/djangoapps/branding/tests/test_views.py   |  11 +-
 lms/djangoapps/branding/views.py              |  13 +-
 lms/djangoapps/bulk_email/admin.py            |   7 +-
 lms/djangoapps/bulk_email/forms.py            |   7 +-
 lms/djangoapps/bulk_email/models.py           |  17 +-
 lms/djangoapps/bulk_email/tasks.py            |  37 ++---
 .../bulk_email/tests/test_course_optout.py    |   8 +-
 lms/djangoapps/bulk_email/tests/test_email.py |  22 +--
 .../bulk_email/tests/test_err_handling.py     |  20 +--
 lms/djangoapps/bulk_email/tests/test_forms.py |   4 +-
 .../bulk_email/tests/test_models.py           |  22 +--
 lms/djangoapps/bulk_email/tests/test_tasks.py |  39 ++---
 lms/djangoapps/ccx/api/urls.py                |   2 +-
 lms/djangoapps/ccx/api/v0/serializers.py      |   2 +-
 lms/djangoapps/ccx/api/v0/tests/test_views.py |  37 ++---
 lms/djangoapps/ccx/api/v0/urls.py             |   2 +-
 lms/djangoapps/ccx/api/v0/views.py            |  37 ++---
 lms/djangoapps/ccx/models.py                  |   6 +-
 lms/djangoapps/ccx/modulestore.py             |   6 +-
 lms/djangoapps/ccx/overrides.py               |   7 +-
 lms/djangoapps/ccx/plugins.py                 |   4 +-
 lms/djangoapps/ccx/tasks.py                   |   8 +-
 lms/djangoapps/ccx/tests/factories.py         |   5 +-
 .../ccx/tests/test_ccx_modulestore.py         |  17 +-
 .../tests/test_field_override_performance.py  |  32 ++--
 lms/djangoapps/ccx/tests/test_models.py       |  24 +--
 lms/djangoapps/ccx/tests/test_overrides.py    |  17 +-
 lms/djangoapps/ccx/tests/test_tasks.py        |  18 +-
 lms/djangoapps/ccx/tests/test_utils.py        |  35 ++--
 lms/djangoapps/ccx/tests/test_views.py        |  82 ++++------
 lms/djangoapps/ccx/tests/utils.py             |  25 +--
 lms/djangoapps/ccx/urls.py                    |   1 -
 lms/djangoapps/ccx/utils.py                   |  33 ++--
 lms/djangoapps/ccx/views.py                   |  47 ++----
 lms/djangoapps/certificates/admin.py          |   9 +-
 lms/djangoapps/certificates/api.py            |  14 +-
 lms/djangoapps/certificates/apis/urls.py      |   6 +-
 lms/djangoapps/certificates/apis/v0/urls.py   |   7 +-
 lms/djangoapps/certificates/apis/v0/views.py  |   7 +-
 .../management/commands/cert_whitelist.py     |   7 +-
 .../management/commands/create_fake_cert.py   |   7 +-
 .../management/commands/fix_ungraded_certs.py |   4 +-
 .../management/commands/gen_cert_report.py    |  10 +-
 .../management/commands/regenerate_user.py    |   5 +-
 .../commands/resubmit_error_certificates.py   |   8 +-
 .../management/commands/ungenerated_certs.py  |  16 +-
 lms/djangoapps/certificates/models.py         |   9 +-
 lms/djangoapps/certificates/queue.py          |  31 ++--
 lms/djangoapps/certificates/signals.py        |   2 +-
 .../certificates/tests/factories.py           |   5 +-
 lms/djangoapps/certificates/tests/test_api.py |  40 ++---
 .../tests/test_cert_management.py             |  13 +-
 .../tests/test_create_fake_cert.py            |   6 +-
 .../certificates/tests/test_models.py         |  22 ++-
 .../certificates/tests/test_queue.py          |  32 ++--
 .../certificates/tests/test_signals.py        |   2 +-
 .../certificates/tests/test_support_views.py  |  10 +-
 .../certificates/tests/test_views.py          |   8 +-
 .../certificates/tests/test_webview_views.py  |  46 +++---
 lms/djangoapps/certificates/tests/tests.py    |  23 +--
 lms/djangoapps/certificates/urls.py           |   2 +-
 lms/djangoapps/certificates/views/support.py  |  16 +-
 lms/djangoapps/certificates/views/webview.py  |  44 ++---
 lms/djangoapps/certificates/views/xqueue.py   |  17 +-
 .../class_dashboard/dashboard_data.py         |   9 +-
 .../tests/test_dashboard_data.py              |  24 +--
 .../class_dashboard/tests/test_views.py       |   4 +-
 lms/djangoapps/class_dashboard/urls.py        |   3 +-
 lms/djangoapps/class_dashboard/views.py       |   7 +-
 lms/djangoapps/commerce/admin.py              |   2 +-
 lms/djangoapps/commerce/api/urls.py           |   2 +-
 .../commerce/api/v0/tests/test_views.py       |  20 +--
 lms/djangoapps/commerce/api/v0/urls.py        |   3 +-
 lms/djangoapps/commerce/api/v0/views.py       |   5 +-
 lms/djangoapps/commerce/api/v1/models.py      |   5 +-
 lms/djangoapps/commerce/api/v1/serializers.py |   2 -
 .../commerce/api/v1/tests/test_views.py       |  10 +-
 lms/djangoapps/commerce/api/v1/urls.py        |   2 +-
 lms/djangoapps/commerce/api/v1/views.py       |   2 +-
 lms/djangoapps/commerce/http.py               |   2 +-
 .../management/commands/configure_commerce.py |   1 +
 .../commands/tests/test_configure_commerce.py |   2 +-
 lms/djangoapps/commerce/models.py             |   3 +-
 lms/djangoapps/commerce/tests/test_signals.py |   4 +-
 lms/djangoapps/commerce/tests/test_views.py   |  14 +-
 lms/djangoapps/commerce/urls.py               |   2 +-
 lms/djangoapps/commerce/utils.py              |   2 +-
 lms/djangoapps/commerce/views.py              |  10 +-
 lms/djangoapps/course_api/api.py              |   7 +-
 lms/djangoapps/course_api/blocks/api.py       |   4 +-
 lms/djangoapps/course_api/blocks/forms.py     |   6 +-
 .../course_api/blocks/tests/test_api.py       |   4 +-
 .../course_api/blocks/tests/test_forms.py     |   7 +-
 .../blocks/tests/test_serializers.py          |   6 +-
 .../course_api/blocks/tests/test_views.py     |   4 +-
 .../blocks/transformers/blocks_api.py         |   1 +
 .../blocks/transformers/milestones.py         |   7 +-
 .../blocks/transformers/navigation.py         |   1 +
 .../transformers/tests/test_block_depth.py    |   6 +-
 .../transformers/tests/test_milestones.py     |  10 +-
 .../transformers/tests/test_navigation.py     |   7 +-
 lms/djangoapps/course_api/blocks/urls.py      |   2 +-
 lms/djangoapps/course_api/blocks/views.py     |   6 +-
 lms/djangoapps/course_api/forms.py            |   5 +-
 lms/djangoapps/course_api/tests/mixins.py     |   1 -
 lms/djangoapps/course_api/tests/test_api.py   |   5 +-
 lms/djangoapps/course_api/tests/test_forms.py |   5 +-
 .../course_api/tests/test_permissions.py      |   3 +-
 .../course_api/tests/test_serializers.py      |  11 +-
 lms/djangoapps/course_api/tests/test_views.py |   5 +-
 lms/djangoapps/course_api/urls.py             |   3 +-
 lms/djangoapps/course_api/views.py            |   5 +-
 lms/djangoapps/course_blocks/api.py           |   8 +-
 .../transformers/hidden_content.py            |   5 +-
 .../transformers/library_content.py           |   7 +-
 .../course_blocks/transformers/split_test.py  |   2 +-
 .../course_blocks/transformers/start_date.py  |   4 +-
 .../transformers/tests/helpers.py             |   5 +-
 .../transformers/tests/test_hidden_content.py |   1 +
 .../tests/test_library_content.py             |   3 +-
 .../transformers/tests/test_split_test.py     |   2 +-
 .../transformers/tests/test_start_date.py     |   6 +-
 .../tests/test_user_partitions.py             |   7 +-
 .../transformers/user_partitions.py           |   2 +-
 .../course_blocks/transformers/visibility.py  |   3 +-
 lms/djangoapps/course_blocks/utils.py         |   1 +
 lms/djangoapps/course_structure_api/urls.py   |   2 +-
 .../course_structure_api/v0/tests.py          |  14 +-
 .../course_structure_api/v0/urls.py           |   1 -
 lms/djangoapps/course_wiki/editors.py         |   4 +-
 lms/djangoapps/course_wiki/middleware.py      |   7 +-
 .../plugins/markdownedx/mdx_mathjax.py        |   1 +
 .../plugins/markdownedx/mdx_video.py          |   1 +
 .../plugins/markdownedx/wiki_plugin.py        |   2 +-
 .../course_wiki/tests/test_access.py          |  15 +-
 .../tests/test_comprehensive_theming.py       |  10 +-
 .../course_wiki/tests/test_middleware.py      |   5 +-
 lms/djangoapps/course_wiki/tests/tests.py     |   3 +-
 lms/djangoapps/course_wiki/utils.py           |   3 +-
 lms/djangoapps/course_wiki/views.py           |   9 +-
 lms/djangoapps/courseware/access.py           |  35 ++--
 lms/djangoapps/courseware/access_response.py  |   1 +
 lms/djangoapps/courseware/access_utils.py     |   9 +-
 lms/djangoapps/courseware/admin.py            |   3 +-
 .../courseware/context_processor.py           |   4 +-
 lms/djangoapps/courseware/courses.py          |  32 ++--
 lms/djangoapps/courseware/date_summary.py     |   7 +-
 lms/djangoapps/courseware/features/common.py  |  14 +-
 .../courseware/features/courseware.py         |   2 +-
 .../courseware/features/courseware_common.py  |   2 +-
 lms/djangoapps/courseware/features/events.py  |   7 +-
 lms/djangoapps/courseware/features/lti.py     |  12 +-
 .../courseware/features/problems.py           |   5 +-
 .../courseware/features/problems_setup.py     |   9 +-
 .../courseware/features/registration.py       |   5 +-
 .../courseware/features/word_cloud.py         |   3 +-
 lms/djangoapps/courseware/field_overrides.py  |   3 +-
 .../management/commands/clean_xml.py          |   5 +-
 .../commands/dump_course_structure.py         |  11 +-
 .../management/commands/export_course.py      |   9 +-
 .../commands/fix_student_module_newlines.py   |   7 +-
 .../management/commands/regrade_partial.py    |   2 +-
 .../commands/tests/test_dump_course.py        |  13 +-
 lms/djangoapps/courseware/masquerade.py       |   7 +-
 lms/djangoapps/courseware/model_data.py       |  29 ++--
 lms/djangoapps/courseware/models.py           |  11 +-
 lms/djangoapps/courseware/module_render.py    |  37 +++--
 .../courseware/self_paced_overrides.py        |   3 +-
 lms/djangoapps/courseware/tabs.py             |   6 +-
 lms/djangoapps/courseware/tests/factories.py  |  24 +--
 lms/djangoapps/courseware/tests/helpers.py    |   5 +-
 lms/djangoapps/courseware/tests/test_about.py |  26 ++-
 .../courseware/tests/test_access.py           |  37 ++---
 .../tests/test_comprehensive_theming.py       |   7 +-
 .../tests/test_context_processor.py           |   5 +-
 .../courseware/tests/test_course_info.py      |  20 +--
 .../courseware/tests/test_course_survey.py    |  11 +-
 .../courseware/tests/test_courses.py          |  19 +--
 .../tests/test_credit_requirements.py         |  10 +-
 .../courseware/tests/test_date_summary.py     |   8 +-
 .../tests/test_discussion_xblock.py           |  17 +-
 .../tests/test_draft_modulestore.py           |   2 +-
 .../courseware/tests/test_entrance_exam.py    |  25 ++-
 .../courseware/tests/test_favicon.py          |   1 -
 .../courseware/tests/test_field_overrides.py  |  10 +-
 .../courseware/tests/test_footer.py           |   2 +-
 .../courseware/tests/test_group_access.py     |   9 +-
 .../courseware/tests/test_lti_integration.py  |   8 +-
 .../courseware/tests/test_masquerade.py       |  14 +-
 .../courseware/tests/test_microsites.py       |   7 +-
 .../courseware/tests/test_middleware.py       |   7 +-
 .../courseware/tests/test_model_data.py       |  34 ++--
 .../courseware/tests/test_module_render.py    |  71 ++++----
 .../courseware/tests/test_navigation.py       |   8 +-
 .../courseware/tests/test_password_history.py |  18 +-
 .../tests/test_self_paced_overrides.py        |   6 +-
 .../courseware/tests/test_split_module.py     |   8 +-
 .../tests/test_submitting_problems.py         |  12 +-
 lms/djangoapps/courseware/tests/test_tabs.py  |  27 +--
 .../tests/test_user_state_client.py           |   4 +-
 .../courseware/tests/test_video_handlers.py   |  17 +-
 .../courseware/tests/test_video_mongo.py      |  33 ++--
 .../courseware/tests/test_video_xml.py        |   2 +-
 .../tests/test_view_authentication.py         |  10 +-
 lms/djangoapps/courseware/tests/test_views.py |  37 +++--
 .../courseware/tests/test_word_cloud.py       |   4 +-
 lms/djangoapps/courseware/tests/tests.py      |   6 +-
 lms/djangoapps/courseware/testutils.py        |   5 +-
 lms/djangoapps/courseware/url_helpers.py      |   2 +-
 .../courseware/user_state_client.py           |  19 ++-
 lms/djangoapps/courseware/views/index.py      |  34 ++--
 lms/djangoapps/courseware/views/views.py      |   6 +-
 .../coursewarehistoryextended/models.py       |   4 +-
 .../coursewarehistoryextended/tests.py        |  12 +-
 lms/djangoapps/dashboard/git_import.py        |   8 +-
 .../commands/tests/test_git_add_course.py     |  11 +-
 lms/djangoapps/dashboard/models.py            |   1 +
 lms/djangoapps/dashboard/sysadmin.py          |  27 ++-
 .../dashboard/tests/test_sysadmin.py          |  13 +-
 .../management/commands/dump_xml_courses.py   |   4 +-
 lms/djangoapps/debug/views.py                 |   5 +-
 lms/djangoapps/discussion/plugins.py          |   2 +-
 lms/djangoapps/discussion/tests/test_views.py |  10 +-
 lms/djangoapps/discussion/urls.py             |   2 +-
 lms/djangoapps/discussion/views.py            |  18 +-
 lms/djangoapps/discussion_api/api.py          |  15 +-
 lms/djangoapps/discussion_api/forms.py        |  12 +-
 lms/djangoapps/discussion_api/pagination.py   |   1 +
 lms/djangoapps/discussion_api/serializers.py  |   7 +-
 .../discussion_api/tests/test_api.py          |  12 +-
 .../discussion_api/tests/test_forms.py        |   5 +-
 .../discussion_api/tests/test_permissions.py  |   2 +-
 .../discussion_api/tests/test_serializers.py  |   4 +-
 .../discussion_api/tests/test_views.py        |  21 ++-
 lms/djangoapps/discussion_api/tests/utils.py  |   8 +-
 lms/djangoapps/discussion_api/urls.py         |   2 -
 lms/djangoapps/discussion_api/views.py        |  14 +-
 .../django_comment_client/base/tests.py       |  35 ++--
 .../django_comment_client/base/urls.py        |   2 +-
 .../django_comment_client/base/views.py       |  51 +++---
 .../management/commands/assign_role.py        |   3 +-
 .../commands/assign_roles_for_course.py       |   2 +-
 .../commands/create_roles_for_existing.py     |   2 +-
 .../management/commands/reload_forum_users.py |   2 +-
 .../commands/seed_permissions_roles.py        |   3 +-
 .../management/commands/show_permissions.py   |   2 +-
 .../management/commands/sync_user_info.py     |   3 +-
 .../django_comment_client/middleware.py       |   5 +-
 .../django_comment_client/permissions.py      |   4 +-
 .../django_comment_client/tests/factories.py  |   3 +-
 .../tests/mock_cs_server/mock_cs_server.py    |   3 +-
 .../mock_cs_server/test_mock_cs_server.py     |   8 +-
 .../tests/test_middleware.py                  |   5 +-
 .../tests/test_models.py                      |   4 +-
 .../django_comment_client/tests/test_utils.py |   8 +-
 lms/djangoapps/django_comment_client/urls.py  |   2 +-
 lms/djangoapps/django_comment_client/utils.py |  11 +-
 lms/djangoapps/edxnotes/decorators.py         |   8 +-
 lms/djangoapps/edxnotes/helpers.py            |  16 +-
 lms/djangoapps/edxnotes/plugins.py            |   1 +
 lms/djangoapps/edxnotes/tests.py              |  38 ++---
 lms/djangoapps/edxnotes/views.py              |  19 ++-
 lms/djangoapps/email_marketing/admin.py       |   2 +-
 lms/djangoapps/email_marketing/models.py      |   3 +-
 lms/djangoapps/email_marketing/signals.py     |  13 +-
 lms/djangoapps/email_marketing/tasks.py       |   6 +-
 .../email_marketing/tests/test_signals.py     |  39 +++--
 lms/djangoapps/gating/api.py                  |   6 +-
 lms/djangoapps/gating/tests/test_api.py       |  16 +-
 .../gating/tests/test_integration.py          |   8 +-
 lms/djangoapps/gating/tests/test_signals.py   |   7 +-
 lms/djangoapps/grades/admin.py                |   9 +-
 lms/djangoapps/grades/api/serializers.py      |   1 +
 lms/djangoapps/grades/api/tests/test_views.py |   7 +-
 lms/djangoapps/grades/api/urls.py             |   5 +-
 lms/djangoapps/grades/config/forms.py         |   5 +-
 lms/djangoapps/grades/config/models.py        |   1 +
 .../grades/config/tests/test_models.py        |   7 +-
 lms/djangoapps/grades/config/tests/utils.py   |   3 +-
 lms/djangoapps/grades/config/waffle.py        |   1 -
 lms/djangoapps/grades/context.py              |   1 +
 .../management/commands/compute_grades.py     |   8 +-
 .../grades/management/commands/get_grades.py  |  22 +--
 .../commands/recalculate_subsection_grades.py |   7 +-
 .../management/commands/reset_grades.py       |   7 +-
 .../commands/tests/test_compute_grades.py     |   7 +-
 .../test_recalculate_subsection_grades.py     |   7 +-
 .../commands/tests/test_reset_grades.py       |   7 +-
 lms/djangoapps/grades/models.py               |  14 +-
 lms/djangoapps/grades/new/course_data.py      |   1 +
 lms/djangoapps/grades/new/course_grade.py     |   6 +-
 .../grades/new/course_grade_factory.py        |   5 +-
 lms/djangoapps/grades/new/subsection_grade.py |   9 +-
 .../grades/new/subsection_grade_factory.py    |  10 +-
 lms/djangoapps/grades/scores.py               |   5 +-
 lms/djangoapps/grades/signals/handlers.py     |  23 +--
 lms/djangoapps/grades/signals/signals.py      |   8 +-
 lms/djangoapps/grades/tasks.py                |  29 ++--
 .../grades/tests/integration/test_access.py   |   9 +-
 .../grades/tests/integration/test_events.py   |  10 +-
 .../grades/tests/test_course_data.py          |   1 +
 lms/djangoapps/grades/tests/test_grades.py    |   6 +-
 lms/djangoapps/grades/tests/test_models.py    |  14 +-
 lms/djangoapps/grades/tests/test_new.py       |  11 +-
 lms/djangoapps/grades/tests/test_scores.py    |   8 +-
 lms/djangoapps/grades/tests/test_signals.py   |  15 +-
 lms/djangoapps/grades/tests/test_tasks.py     |  37 ++---
 .../grades/tests/test_transformer.py          |  10 +-
 lms/djangoapps/grades/tests/utils.py          |   4 +-
 lms/djangoapps/grades/transformer.py          |   1 -
 lms/djangoapps/instructor/access.py           |  15 +-
 lms/djangoapps/instructor/enrollment.py       |  27 ++-
 .../instructor/enrollment_report.py           |   8 +-
 lms/djangoapps/instructor/features/common.py  |   4 +-
 .../instructor/features/data_download.py      |   5 +-
 .../paidcourse_enrollment_report.py           |  15 +-
 lms/djangoapps/instructor/services.py         |  16 +-
 .../instructor/tests/test_access.py           |  14 +-
 lms/djangoapps/instructor/tests/test_api.py   |  87 ++++++----
 .../tests/test_api_email_localization.py      |   4 +-
 .../instructor/tests/test_certificates.py     |  45 ++---
 .../instructor/tests/test_ecommerce.py        |   5 +-
 lms/djangoapps/instructor/tests/test_email.py |   6 +-
 .../instructor/tests/test_enrollment.py       |  17 +-
 .../tests/test_enrollment_store_provider.py   |   1 +
 .../instructor/tests/test_proctoring.py       |   3 +-
 .../tests/test_registration_codes.py          |  24 ++-
 .../instructor/tests/test_services.py         |  10 +-
 .../instructor/tests/test_spoc_gradebook.py   |   8 +-
 lms/djangoapps/instructor/tests/test_tools.py |   6 +-
 lms/djangoapps/instructor/tests/utils.py      |   2 +
 .../tests/views/test_instructor_dashboard.py  |  25 ++-
 lms/djangoapps/instructor/utils.py            |   3 +-
 lms/djangoapps/instructor/views/api.py        | 154 +++++++++---------
 lms/djangoapps/instructor/views/coupons.py    |  14 +-
 .../instructor/views/gradebook_api.py         |   6 +-
 .../instructor/views/instructor_dashboard.py  |  32 ++--
 .../views/instructor_task_helpers.py          |   6 +-
 .../instructor/views/registration_codes.py    |  14 +-
 lms/djangoapps/instructor/views/tools.py      |  12 +-
 lms/djangoapps/instructor_analytics/basic.py  |  26 +--
 lms/djangoapps/instructor_analytics/csvs.py   |   1 +
 .../instructor_analytics/distributions.py     |   1 +
 .../instructor_analytics/tests/test_basic.py  |  42 +++--
 .../tests/test_distributions.py               |   6 +-
 lms/djangoapps/instructor_task/admin.py       |   3 +-
 lms/djangoapps/instructor_task/api.py         |  41 +++--
 lms/djangoapps/instructor_task/api_helper.py  |  15 +-
 .../management/commands/fail_old_tasks.py     |   4 +-
 .../commands/tests/test_fail_old_tasks.py     |   2 +-
 lms/djangoapps/instructor_task/models.py      |   7 +-
 lms/djangoapps/instructor_task/subtasks.py    |  18 +-
 lms/djangoapps/instructor_task/tasks.py       |  25 +--
 lms/djangoapps/instructor_task/tasks_base.py  |   7 +-
 .../instructor_task/tasks_helper/certs.py     |   4 +-
 .../tasks_helper/enrollments.py               |  25 +--
 .../instructor_task/tasks_helper/grades.py    |  20 +--
 .../instructor_task/tasks_helper/misc.py      |  15 +-
 .../tasks_helper/module_state.py              |  20 +--
 .../instructor_task/tasks_helper/runner.py    |  10 +-
 .../instructor_task/tasks_helper/utils.py     |   1 -
 .../instructor_task/tests/factories.py        |   7 +-
 .../instructor_task/tests/test_api.py         |  45 +++--
 .../instructor_task/tests/test_base.py        |  24 ++-
 .../instructor_task/tests/test_integration.py |  36 ++--
 .../instructor_task/tests/test_models.py      |   6 +-
 .../instructor_task/tests/test_subtasks.py    |   3 +-
 .../instructor_task/tests/test_tasks.py       |  23 ++-
 .../tests/test_tasks_helper.py                |  83 +++++-----
 .../instructor_task/tests/test_views.py       |  11 +-
 lms/djangoapps/instructor_task/views.py       |   6 +-
 .../learner_dashboard/tests/test_programs.py  |   7 +-
 lms/djangoapps/learner_dashboard/urls.py      |   1 -
 lms/djangoapps/learner_dashboard/utils.py     |   1 -
 lms/djangoapps/learner_dashboard/views.py     |   6 +-
 .../management/commands/create_groups.py      |   4 +-
 .../management/commands/create_user.py        |  15 +-
 .../commands/manage_course_groups.py          |   3 +-
 lms/djangoapps/lms_migration/migrate.py       |   7 +-
 lms/djangoapps/lms_xblock/admin.py            |   3 +-
 lms/djangoapps/lms_xblock/mixin.py            |   4 +-
 lms/djangoapps/lms_xblock/models.py           |   4 +-
 lms/djangoapps/lms_xblock/runtime.py          |   9 +-
 .../lms_xblock/test/test_runtime.py           |  13 +-
 .../management/commands/resend_lti_scores.py  |   3 +-
 .../commands/tests/test_resend_lti_scores.py  |   7 +-
 lms/djangoapps/lti_provider/models.py         |   6 +-
 lms/djangoapps/lti_provider/outcomes.py       |   4 +-
 .../lti_provider/signature_validator.py       |   3 +-
 lms/djangoapps/lti_provider/startup.py        |   2 +-
 lms/djangoapps/lti_provider/tasks.py          |   9 +-
 .../lti_provider/tests/test_outcomes.py       |  15 +-
 .../lti_provider/tests/test_tasks.py          |   8 +-
 .../lti_provider/tests/test_users.py          |   5 +-
 .../lti_provider/tests/test_views.py          |   7 +-
 lms/djangoapps/lti_provider/users.py          |   3 +-
 lms/djangoapps/lti_provider/views.py          |  11 +-
 .../management/commands/mailchimp_id.py       |   1 -
 .../commands/mailchimp_sync_announcements.py  |   9 +-
 .../commands/mailchimp_sync_course.py         |   8 +-
 lms/djangoapps/mobile_api/admin.py            |   9 +-
 lms/djangoapps/mobile_api/course_info/urls.py |   4 +-
 .../mobile_api/course_info/views.py           |   2 +-
 lms/djangoapps/mobile_api/decorators.py       |   9 +-
 lms/djangoapps/mobile_api/middleware.py       |   4 +-
 lms/djangoapps/mobile_api/models.py           |   4 +-
 .../mobile_api/tests/test_middleware.py       |   4 +-
 .../mobile_api/tests/test_milestones.py       |   7 +-
 .../mobile_api/tests/test_mobile_platform.py  |   1 +
 lms/djangoapps/mobile_api/tests/test_model.py |   2 +
 lms/djangoapps/mobile_api/testutils.py        |  22 +--
 lms/djangoapps/mobile_api/urls.py             |   2 +-
 .../mobile_api/users/serializers.py           |   2 +-
 lms/djangoapps/mobile_api/users/tests.py      |  28 ++--
 lms/djangoapps/mobile_api/users/urls.py       |   5 +-
 lms/djangoapps/mobile_api/users/views.py      |  13 +-
 .../mobile_api/video_outlines/serializers.py  |   9 +-
 .../mobile_api/video_outlines/tests.py        |  18 +-
 .../mobile_api/video_outlines/urls.py         |   2 +-
 .../mobile_api/video_outlines/views.py        |   5 +-
 lms/djangoapps/notes/api.py                   |  14 +-
 lms/djangoapps/notes/models.py                |   7 +-
 lms/djangoapps/notes/tests.py                 |  19 +--
 lms/djangoapps/notes/urls.py                  |   1 -
 lms/djangoapps/notes/views.py                 |   6 +-
 .../features/unsubscribe.py                   |   4 +-
 lms/djangoapps/notification_prefs/tests.py    |   4 +-
 lms/djangoapps/notification_prefs/views.py    |   6 +-
 lms/djangoapps/notifier_api/serializers.py    |   3 +-
 lms/djangoapps/notifier_api/tests.py          |   8 +-
 lms/djangoapps/notifier_api/urls.py           |   1 -
 lms/djangoapps/notifier_api/views.py          |   4 +-
 lms/djangoapps/oauth2_handler/handlers.py     |   5 +-
 lms/djangoapps/oauth2_handler/tests.py        |  14 +-
 lms/djangoapps/rss_proxy/admin.py             |   1 +
 lms/djangoapps/rss_proxy/tests/test_models.py |   1 +
 lms/djangoapps/rss_proxy/tests/test_views.py  |   5 +-
 lms/djangoapps/rss_proxy/urls.py              |   1 -
 lms/djangoapps/rss_proxy/views.py             |   3 +-
 lms/djangoapps/shoppingcart/admin.py          |   7 +-
 lms/djangoapps/shoppingcart/api.py            |   3 +-
 .../shoppingcart/context_processor.py         |   2 +-
 lms/djangoapps/shoppingcart/decorators.py     |   1 +
 .../management/commands/retire_order.py       |   3 +-
 .../management/tests/test_retire_order.py     |   5 +-
 lms/djangoapps/shoppingcart/models.py         |  64 ++++----
 lms/djangoapps/shoppingcart/pdf.py            |  12 +-
 .../shoppingcart/processors/CyberSource.py    |  10 +-
 .../shoppingcart/processors/CyberSource2.py   |  17 +-
 .../shoppingcart/processors/helpers.py        |   1 +
 .../processors/tests/test_CyberSource.py      |  35 ++--
 .../processors/tests/test_CyberSource2.py     |  18 +-
 lms/djangoapps/shoppingcart/reports.py        |   4 +-
 .../shoppingcart/tests/payment_fake.py        |   7 +-
 .../tests/test_configuration_overrides.py     |  11 +-
 .../tests/test_context_processor.py           |   7 +-
 .../shoppingcart/tests/test_models.py         |  65 ++++----
 .../shoppingcart/tests/test_payment_fake.py   |   4 +-
 lms/djangoapps/shoppingcart/tests/test_pdf.py |   8 +-
 .../shoppingcart/tests/test_reports.py        |  15 +-
 .../shoppingcart/tests/test_views.py          |  63 +++----
 lms/djangoapps/shoppingcart/urls.py           |   2 +-
 lms/djangoapps/shoppingcart/utils.py          |   9 +-
 lms/djangoapps/shoppingcart/views.py          |  92 +++++++----
 .../static_template_view/tests/test_views.py  |   2 +-
 lms/djangoapps/static_template_view/views.py  |   8 +-
 lms/djangoapps/staticbook/tests.py            |   8 +-
 lms/djangoapps/staticbook/views.py            |   5 +-
 .../student_account/test/test_views.py        |  33 ++--
 lms/djangoapps/student_account/urls.py        |   2 +-
 lms/djangoapps/student_account/views.py       |  36 ++--
 .../student_profile/test/test_views.py        |   3 +-
 lms/djangoapps/student_profile/views.py       |   8 +-
 lms/djangoapps/support/decorators.py          |   2 +-
 lms/djangoapps/support/tests/test_refund.py   |   6 +-
 lms/djangoapps/support/tests/test_views.py    |   6 +-
 lms/djangoapps/support/views/certificate.py   |   5 +-
 lms/djangoapps/support/views/enrollments.py   |   4 +-
 lms/djangoapps/support/views/index.py         |   1 -
 lms/djangoapps/support/views/refund.py        |  14 +-
 lms/djangoapps/survey/admin.py                |   1 +
 lms/djangoapps/survey/models.py               |  11 +-
 lms/djangoapps/survey/tests/test_models.py    |  10 +-
 lms/djangoapps/survey/tests/test_utils.py     |   8 +-
 lms/djangoapps/survey/tests/test_views.py     |   7 +-
 lms/djangoapps/survey/urls.py                 |   1 -
 lms/djangoapps/survey/utils.py                |   2 +-
 lms/djangoapps/survey/views.py                |  13 +-
 lms/djangoapps/teams/api_urls.py              |   8 +-
 .../commands/reindex_course_team.py           |   7 +-
 .../tests/test_reindex_course_team.py         |  11 +-
 lms/djangoapps/teams/models.py                |  27 +--
 lms/djangoapps/teams/plugins.py               |   2 +
 lms/djangoapps/teams/search_indexes.py        |   8 +-
 lms/djangoapps/teams/serializers.py           |  11 +-
 lms/djangoapps/teams/tests/factories.py       |   3 +-
 lms/djangoapps/teams/tests/test_models.py     |  29 ++--
 .../teams/tests/test_serializers.py           |   9 +-
 lms/djangoapps/teams/tests/test_views.py      |  31 ++--
 lms/djangoapps/teams/views.py                 |  54 +++---
 lms/djangoapps/verify_student/image.py        |   1 -
 .../retry_failed_photo_verifications.py       |   3 +-
 .../commands/set_software_secure_status.py    |   5 +-
 .../commands/tests/test_verify_student.py     |  15 +-
 lms/djangoapps/verify_student/models.py       |  28 ++--
 lms/djangoapps/verify_student/services.py     |   3 +-
 lms/djangoapps/verify_student/signals.py      |   1 +
 lms/djangoapps/verify_student/ssencrypt.py    |   2 +-
 .../verify_student/tests/factories.py         |   1 +
 .../tests/test_fake_software_secure.py        |   4 +-
 .../verify_student/tests/test_integration.py  |   8 +-
 .../verify_student/tests/test_models.py       |  32 ++--
 .../verify_student/tests/test_signals.py      |   4 +-
 .../verify_student/tests/test_ssencrypt.py    |   9 +-
 .../verify_student/tests/test_views.py        |  42 ++---
 lms/djangoapps/verify_student/urls.py         |   1 -
 lms/djangoapps/verify_student/views.py        |  41 ++---
 lms/lib/comment_client/comment.py             |   5 +-
 lms/lib/comment_client/comment_client.py      |   2 +-
 lms/lib/comment_client/commentable.py         |   3 +-
 lms/lib/comment_client/models.py              |   3 +-
 lms/lib/comment_client/thread.py              |  17 +-
 lms/lib/comment_client/user.py                |   5 +-
 lms/lib/comment_client/utils.py               |  10 +-
 .../courseware_search/lms_filter_generator.py |   5 +-
 .../courseware_search/lms_result_processor.py |   4 +-
 .../lms_search_initializer.py                 |   4 +-
 .../test/test_lms_filter_generator.py         |  10 +-
 .../test/test_lms_result_processor.py         |   6 +-
 lms/tests.py                                  |   8 +-
 lms/urls.py                                   |   8 +-
 setup.cfg                                     |   6 +
 553 files changed, 2960 insertions(+), 3166 deletions(-)
 delete mode 100644 .isort.cfg

diff --git a/.isort.cfg b/.isort.cfg
deleted file mode 100644
index cb728852812..00000000000
--- 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 23eb1aedbae..89f35bde38a 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 cced329c077..552550821c2 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 54e669e9ec2..d1fcce25da0 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 441c593eba3..2078b50bec0 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 3dd4a1de300..a9d1c8daf2e 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 d40efcf1c34..974534f3973 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 ca79bf6c2b7..13d5f857e48 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 6f531b2e646..24002771ae7 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 e5bbb99c338..d300772ddcf 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 0fb072ee804..bf6a8036c90 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 2183fd02c69..4b8eab2bddc 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 484e7cd1106..19e763ba48f 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 c625454a9b4..0afb020b4fd 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 fc56ab66b35..88e0a9bb6e3 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 4450174e16f..851f57eca5f 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 88beae6b525..a3d5112c8e7 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 1dbed47baee..2626a55d041 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 5862bbbf1d5..12e0ad47e38 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 a3d6c3fcae6..1a00ab52412 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 9db971d3b81..79f1b66b30b 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 0f123c2ad44..b08510c6bef 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 c4f68cc53e3..30fb3278aa7 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 ac6937a7da0..67043078ad9 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 8b4ebb6c63c..0b3097eebc7 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 0f879735c5e..5befaf9f442 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 f64da3e29cb..a5d99ca33c9 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 d43d94d9e0f..ae235c0cf5b 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 ceb9e19b290..1b07e81b61e 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 5b277d24dba..bad8c185d7d 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 7ea5771481b..d36b93dacf3 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 2886f58e861..89b51b511e7 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 f01d85eb33e..b50796bd427 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 7a78eb0bafc..ab19553bce4 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 b376ef3fc6d..f341d4d3240 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 3060d8eb15f..5aba8640351 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 92889c89552..82226019526 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 8b2c5cc93f7..e543f4c75fb 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 8f8d596cbb6..ce53399f439 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 2b3b8cd627b..85b2d4b9ad4 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 344135c9d8f..92364189266 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 44c42fb123f..650c7bb7f2b 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 2bb282125e1..1f24d06d71b 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 df0039a1204..07c05e793f3 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 81f1e0a1544..c1c3f94d990 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 12bc086794b..bc58cd7ebdf 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 5fdf7fed0ea..d50d54cc2a9 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 6110a74bf7a..51ede06489c 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 95e3030873f..4bfe347fde7 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 21ca542feae..2eef54c79d6 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 5ce7a24e243..b895a4294c6 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 9a574008695..b0383fbf563 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 f6707490872..c3c19f13e56 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 8aedb796539..279a6d54e9d 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 2a0d7644574..80f9f96386b 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 de71d0b6d16..076e28d39c1 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 8a5d56f73bc..8d0f1dc69f8 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 2d45e3f712d..11877615725 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 f8ddd4cc170..66b28643b9c 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 898112917cd..ad57f093d54 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 ada927673dd..8a668c5c37b 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 ed2c0a3c4f8..b4c9514fef6 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 a1c01e5df84..81dea83afa4 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 38f42876d84..6cc36ca1c4c 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 033aa9d4b2b..ec3857ad30b 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 6a183effa7e..efdbd146ea0 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 906bf85d845..b0168487801 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 736a6489598..3759456ee2e 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 11b1452b7af..f168c93dba6 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 4cab739d5fe..5334df7a364 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 d0297ddff30..ab893b1fee1 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 e5f0d145f78..82a86ae868a 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 3a8849d1ab4..5ec7f563426 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 860447ff075..71b5da394bd 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 928b5086e13..74399de1db2 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 0b21f652cd1..dbc84cf6a4d 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 7e27c496b04..2bfcaa81fe9 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 ba68f7ad29e..ae7831061c4 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 6ccab264ae2..3a9438a8ed8 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 b6f6402af46..da8646fd282 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 fb82ce92c5c..6b997d0ccc7 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 b5c46872941..7889f0cefdf 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 dc879b10f24..e40c913debd 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 614df973200..2aaec8b7991 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 7bdeef69752..ce13ed5bf65 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 6d059ac135d..f0782586642 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 616c4aa600c..5aa1e91d592 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 adf5ff6b077..7976ec4a9d5 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 ca78be6a306..8d103a28150 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 d5d67c793e3..be090347a48 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 ad49323a139..c5c178183ae 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 1129750f1c4..c12a53ffc83 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 b2dc7981ae4..ea0f924a4f4 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 8d0765085a8..90fd9f18457 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 b427c89236f..80bb1495481 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 9d7c0f5ed7b..356548faf7f 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 a114160e3a7..c1a4645c6c9 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 8af77d542a4..7628cab7828 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 d4ed3a7defa..90d149a5e29 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 8a862455a88..5c25d991c4a 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 865d69045ee..fea933330fe 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 86b93100912..6b47a8814d1 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 a3800314c40..1e7791e5d65 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 dba2258f8dc..2363f137a09 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 7901fb4ce02..e90d45512d6 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 b406c96c438..a2ec7228402 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 50399b82b51..665a7f8c0ca 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 d0300bb3943..644492e7bf5 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 84f2108fe99..5f41736f078 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 87c8e44ebec..79a3b387963 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 e33c9252b9b..233f618301e 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 76363e66796..ca2cee5e971 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 af9dae0a050..3c3d3eef080 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 ac0bc93ac66..9ff56820538 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 d5a3be825f7..943ec25096e 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 f8d2e2bf161..5c518fa7e27 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 c4356b200d4..376e78a13ab 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 d0b33efe514..e039ec8432d 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 4a9e2b96978..4a46d6afaab 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 60ee26ae9ac..b3e123b6b2b 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 5652aae3f12..c566a0ab912 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 8cf73593cd1..5db1fc9c2b1 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 e40a7d70826..7cadd939b57 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 7caefff9d05..2b9f939d4c7 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 1767cc7422c..85bfd4d896e 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 fa8b8488025..11e6ae59433 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 b8b7afd5593..0885611353d 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 5ea6d2343a1..5ebff7e5712 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 fbfccd0a004..62efdbdfa75 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 b1d1e76bb6a..3580599c517 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 6a357194ee0..f2987b84967 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 bf24e7ead46..294d03be324 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 33aea96e29b..80e529c37f5 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 6c37624887c..f48cdccbec0 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 0627390ef22..bea8706e108 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 9743fc24602..1ab71ca32b7 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 4db261a6e19..98d1fd84f41 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 561d3c31532..c151cfdb21c 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 073dd08b5b7..4216ed20cb6 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 4424133bcae..86032ec3684 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 2d361758324..e656b1ce259 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 f5110868f5a..7cfe10f4424 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 bbe4ae0725e..a4cb0b5d3ab 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 2d51078a3b2..8b97a55b9e6 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 a01cdf3b54a..e8e26882e51 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 bd872604283..2e2048c764b 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 33097b7e003..b2db403d0b6 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 f97dde0ee41..c5b6f37a50f 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 a83baaee27e..82b8368625f 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 11ba6aef453..8bc0fb9a8f2 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 eb20915b47a..0f37e3fcc4b 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 a939408c48d..434780099af 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 b14803744b7..fd93c387d04 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 37cf2d4033c..00fbeb3cc91 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 407aa77c750..557c91722fa 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 7c0be1bf368..c5746486410 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 ecd677b8053..149bdfdb040 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 23fd4e830ff..4ad9a36b006 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 2ea09a0edf0..66fcacc4932 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 6054558c052..3740d952252 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 89bb3d1c0f3..7dde5638380 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 c60368fe1da..69a154b46f0 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 976571cf241..f9b4b6f703e 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 094a6928b25..77cc9cbc1db 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 78c9fc826fa..3b704565a8d 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 07f98191a09..ecc1efbd3af 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 c4c1fb29f09..08f7fdfbefb 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 c0fa0c6eda4..2e0b2dc0072 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 79df764fdd8..c351db7061e 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 91de6ffe709..db19fd19708 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 8814d45a476..ba2f2193a77 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 eefd0e1b92c..c2528cec0e4 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 6da318c7a6f..b4f29972f3b 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 93460849728..808d34c8075 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 bbfa911dcec..3f92945551f 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 8542a88bf5a..b83ed5dd6f0 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 e14a0a53075..1c2c5ff902a 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 02417d95157..a14ad18fce6 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 f3ca26d2903..53e98384750 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 874133a074c..f1b58a85da5 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 27a6c4497e4..0f6d748faba 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 f165e37b930..d195afec2e5 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 9ef99cf8e03..656fb71e2db 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 aee2febcec6..01812093a6e 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 5cfeac5c109..bc29de1d897 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 2b32e834403..ae780a519a5 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 db2cb7279c5..7e0c5fc5a87 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 6c97d46ee26..3aa22050a65 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 9ca19d6810f..2c8e7b4cac8 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 049d6a0aa68..2a6974c52ae 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 67bacec9600..3a0974e924c 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 4c15c6d39b5..a3a968f34f1 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 6c33d3a3d4a..95e3943e72d 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 f509c9f6feb..a98d229fbe1 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 475bc337627..f2e4e8137c2 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 73b86a36f7c..198e89e4205 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 0bc1bd59b22..4267b785301 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 6fa02c7d309..7d827b917ec 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 ba6f85a9efa..a8ccccc8c44 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 399cb5ab259..8d3630a7073 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 f1a6adb48bc..3c4cf314f20 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 496affd2637..fe31ee655c8 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 c5217333e74..c2985e4057a 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 bac392115b6..023733db247 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 7f61acf04e7..5152bce4efa 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 142ed5a4b05..deb522e01a8 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 eb9f97f1d75..c655afe8e21 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 a762e4d88bb..725be86703d 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 20c69e0f8a4..5e1a6537c61 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 64f175cf0d2..9928614a3e3 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 a9d73aa5abf..e58acda3cb0 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 78f1c3c97ae..addfeb9f3b9 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 da06e857494..14320d95aa0 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 8a75fedf5ba..e37ef2a3ace 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 4be076b55d2..dd087a53c79 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 0f9a26eb77b..af8379ae59a 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 b2e166fb3d1..47490b9c61f 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 c7aa323170d..3413ddd3f97 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 2532e67d551..db3ab50bf2f 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 28a33222f51..fced69faa47 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 143bd7f644c..4891840a138 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 63eb6ab23c0..df37776e55c 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 a56278deefa..0cbc036bf6a 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 bc65d5935e6..6c789f86727 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 0b3d644b63b..7fffc8bd684 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 1f9b1e7f358..f186277f714 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 690a8d010cc..7f799c817f2 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 6d7727decb5..cd964dab147 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 5ae9047ffa3..91ba8d813a8 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 b4da0a59de6..25ac8e49153 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 ac316b876f8..02316fec344 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 46878cf66ed..caf52a57f24 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 784bec22b3b..4903b2b4f3a 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 dc99c1f5332..2d6b2c04966 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 114c23794f2..93b8e88de5d 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 38226af5dac..283f40821a6 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 1d87418d5c2..f45e1d94e76 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 a92a4188719..d7ef149f36e 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 dd6e320a329..60f63c5c876 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 c05f38add6e..0d3322edfe4 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 136281bcb36..9f4d3e388e5 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 c8036b34e64..2fb32a38d4d 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 f0096f3f5bf..77037d41a21 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 0bdb26c49cd..e25ef1120dd 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 4295d3a253c..e1fa4de8f7d 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 ee67d9e196e..89292035178 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 0e7979b4542..eeb30fc271c 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 2d5ac81c9f9..16edfc9c971 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 099459510f7..bf4c25ac5af 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 a11ff95ae67..4f7c1d14ff5 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 11cc6f33f99..b8274ed0f1d 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 48b32d4fc99..b507ae4c263 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 392628d4507..cdac23f5b5f 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 413a5b4a598..4ceeaa5486a 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 cba01d4fad0..559b094ce86 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 dde68bd9383..5f7a864e5e1 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 ed150b6a8db..6edf3eab9fd 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 4f3fd6340dc..fcf89087d72 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 7288ecd3c90..bcdd19e934a 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 f3a2f9244a8..0e26310c757 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 2a5e1d09d1a..5a8b457baf0 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 4e9321410c2..2c3452e54b1 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 4701774a2eb..cb0f7afc5b6 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 575d9666e1a..c14359af214 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 53c6aaf2b2d..a7ea40f4fde 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 64976656b21..c3afb7f6e38 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 f24f1831930..abe90cf6441 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 06428cbe59c..044e3832a1f 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 7e2daab8ac2..9dce7bc0127 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 36e4b2b35e9..a9250256bd8 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 c6833945884..5a22db6be24 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 55ea73455ef..cdacca539bb 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 1aea6683299..ca9ba868767 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 8b223eaa1b4..4849cfa3d02 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 bb59e6a7c7f..019d267b750 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 c273ed88b36..ab489752941 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 d2972b4c79c..ddebe62260a 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 483fe2e917b..8f680419316 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 232afa08dab..42857d78455 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 62598d9a302..7374cc2fb39 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 68519fe5495..1303324a8af 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 24943615c26..fe713c04217 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 ad696ddc693..96a582976b3 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 6ec36bd3833..ce338c19741 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 d16146e4c58..7e81095865d 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 a8723ea92dd..e83f57eccb2 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 ab29d598756..95955475e25 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 764fbc9c791..1d12ac0aa7c 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 cc9287fde4f..b8f45b617e3 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 805eb969408..6a5ddec1534 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 8c00bb7565c..f4b60dca3e5 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 f88dbf15ae8..6b564764877 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 aaecba72955..0527c20b355 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 be50412fced..6ecc58f8ed1 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 ffa4a4238f2..2aa6f8502b3 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 1ffb446af64..c4ee1b0c097 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 5db1d6a29d2..d1561c46d0c 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 e0e745ca76d..647ce303882 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 d8eef844402..b14fde2405b 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 f01e3d920b2..a948a8329e4 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 54c9b5b3b87..c5705ac4911 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 cb9c88a2c4b..3b643a6133d 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 185671b77a6..9b10d4d7b29 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 fcdff39e21f..93f072488a5 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 9384a3066b8..9cd4ffeccc4 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 811ffbda8e3..b22a100c1f2 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 0c210ff0f91..ee772997182 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 2e57da10efa..ec349e02d66 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 3cfbbaf5e85..be57882af6e 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 716f330db5c..b4d0c2c01e8 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 c1a03d5fc39..4ceb86dc2a7 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 7dc18bfae2e..1783db8ef76 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 716cf13c77e..56b4eca0401 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 2595f062951..407e9582ce7 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 2960b5d626a..6a97b31705d 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 459f576be95..34345771732 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 4bddf058295..4b5e15e08a0 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 0cf2976db4a..b1c4c4f32f1 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 cda788cb6b0..e03b4076418 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 cdc97638f57..99f95b46752 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 bd062841c7c..6950775a3f9 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 6705ec80377..05ead22b3eb 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 f7d6684ce0c..371062adffe 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 b7a70dd6b74..5ea10805db0 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 99549856d66..172658806f1 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 1bf8c42fec6..286e3a3cad9 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 a6b8f5c9dd3..dfaca5dd4c5 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 6b0e7e010af..5a60c2c69d0 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 2863a64f138..086fc48b7ae 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 fc78bfc8767..637f374f1e9 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 afe298402b0..e12c6861b1a 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 5ea8d3f576a..f20a89ae204 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 07b75efa201..45e9b33b06e 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 2ddbd8dbe98..76c78306e55 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 8c1b7280968..4342398f816 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 1a628e8bde5..5a050867b74 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 cd1096eb3f9..d9fae3ce15c 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 87c9a920003..5e7e4fadf6f 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 fb971bc61b7..c203392b480 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 74d6c96fbd1..ba07cbade03 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 9bf0f3d70ef..7ab9ab5e081 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 14e404af84b..929f22b571a 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 1d05e480710..86c28c38f53 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 728142b0553..fb18334b0d1 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 42c5d015e45..af8a5604ab5 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 a8f753290a4..1277d09244f 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 841e87082d3..986c09891e2 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 497f1966ff3..9cc4c6d7332 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 09f824a1549..b46b7f831a8 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 07fe049924f..ade14980ae1 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 da8fe04d483..5eecf44359c 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 f3816cbde14..8c1308ebb34 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 e57109c2c15..1c970e11ddb 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 dcfa45ac938..1a150de9cbf 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 9877119864c..4d6b24b8782 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 59d8ee7f42c..1b3e8bd921c 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 291601b00a7..5bce65dbe22 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 25572167d21..a5ffbb7eeb4 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 15b53c7e5cd..df5935f3210 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 3775f6769de..7e72566c2aa 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 9d6daa511d6..3e70b2168d4 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 f3625e1de23..3393e195306 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 2b8da615f04..77fda1d07c8 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 423db91b93e..fe2394625a6 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 8ae477f506d..ceb738800cb 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 6a8e8ba1b21..0a91a04ba1d 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 02d48851300..977596ec17f 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 8bce85597c3..9b7101e8e71 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 3a8a1a66c50..20c3308a5ee 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 f3251e1aa52..46ed086dd31 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 eed2a04ef6c..70eb50175fe 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 8179a6c320d..f990a499390 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 5dd14ede3db..c1da60663eb 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 e0bd28ef114..a2ed72d57df 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 41f199b3995..1b7419feaad 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 4569288f838..99f5663ecd1 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 65f2714689a..fe23b22db84 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 bfc47a07124..650d4a99b88 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 043486e3eff..cdb23149e02 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 a5775d1a046..4078305e138 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 71cd9fb8b43..e276720564c 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 2c30b34c3e1..a02ef645a93 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 e08b6ea25d4..9be5423dce8 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 edcd1fc81b3..b5b4b40d681 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 949f6e64d82..d9be20925a4 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 96bbf1f8d9e..ccec9ae4cea 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 5e0a0544ba9..24d39e28b97 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 0c9d4962684..12007862ef5 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 84f119e8c90..6ab2e6b2a8b 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 69bcf22a4c2..67dcaff6080 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 39bd8217a0c..80b1c51f7bc 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 a1f6a188240..07f11372cb4 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 27c3ad024ec..43c9625cc7e 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 27e5e83ecd5..1f2f053cdde 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 d214b03a518..4b34c10540d 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 f8411ca5df3..e54ab412362 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 75dc6975d9f..1ec0ebf0a15 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 4f70c49b50d..e3c6769479a 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 3c877626249..0798790e802 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 e3a6751b0d7..4e9b794f7be 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 81ba9d67fcc..61ccb4eefb3 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 397e85306a7..2e850088a60 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 a67878be48c..14129647cac 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 58bf0f1f96c..5b165bb1860 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 0f37ea35ede..aa6331d9695 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 02a556c0a71..a6ef87c80fc 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 77e09890dcc..52f799d72b9 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 2dcc0cb61de..f55338c693d 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 2d70b1c97d0..a69fede350b 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 3353db18c14..d61276489d3 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 ff27579134c..24f5f6e505e 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 aa9fe79c25c..4b57dc7fc08 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 e7a195554d7..c37675a2bae 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 193a6dac70a..2f25af26feb 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 ae535bb5ba2..ca8f5364b43 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 7c0440bc9f2..8882a0ee098 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 41ec1c8eb92..ce625f35c10 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 5b948c518c1..9f5cf18c0cc 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 922d10b80d9..8b8f9fccea3 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 718f25b34d8..188cc54b30f 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 3a1919fbbec..1abc9b4498b 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 84ae1387a01..3a7c5f58626 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 149ae624815..e1739df4afc 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 13557db83bc..a4a31bfe11f 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 abc04c6fcdc..e8eb9245622 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 921cb2f8abf..65c6a3fe594 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 05744706d4c..839a496c06d 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 d2e26ed7769..b2547f6fc08 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 bd200bb97d2..3c7f22b4e22 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 04ce53a7d08..0f021897e5d 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 89832f92b70..15ffad9dde9 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 35fc627cad3..550d9523e15 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 864fb9fdf33..e2ada74ccd6 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 6debf74a629..2decf2b4497 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 2cb0e642634..a385dcd4479 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 64f1ad4a553..91efbb0101f 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 9ec9a071b62..6a5a8b9be19 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 f1eb5a813b0..5c0e08315a8 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 877bb87b7cc..144649729f9 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 3ce13378ad0..01c05acb7e8 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 d471d40b214..2160b02984f 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 44abb99e203..a892bf05e52 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 4d9a5bdd6f0..f7138c2c34f 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 69a2593d6dd..bf14fb88657 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 6abe92253a0..c083507e78a 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 4b2ce51c028..47690c4e41a 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 00221732cec..627816cb420 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 e67d4e91abb..87854badfac 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 c60d702e21d..09e9bf64f76 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 dc21bb48ef1..e20796a3cf5 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 e55857e7521..ac3d9dba8ae 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 4a1d65dd8ba..f65260df501 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 44e1c78037e..2786cfb96a4 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 122ccd41ffb..da7f44043da 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 878dadcb6ae..e9316170dbc 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 fa5af3753bf..b0e7c0586ab 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 c880eee6234..77bb599e555 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 90a499e19aa..1a40fa3c50c 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 b61772c9e36..bacfe92e2d8 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 023d0529a68..15c86988ed5 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 9385eef3347..e40646302d0 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 65f2b95508d..b8157cab37e 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 95411944bb8..eb3546eea47 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 9f4366f8bb3..10f132bfc39 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 e6539e2c13a..a48925b28d8 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 140cbd309a3..c11f37dc0e1 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 dc4de3e0449..144df4bbed9 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 09f1504e30e..c80fc3cbf5a 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 b5e84453c1f..305d3ffd7c7 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 6720c17f717..5a3aadd7362 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 953c0c5102e..78c9e633083 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 3d1117feb5c..cbfd8b54537 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 62b7a1924af..323c12e2379 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 a7319ceff97..d9630d99cc8 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 71ef16a7588..efb3df62f5f 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 da85df5b66a..e70a75db450 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 4a62667e3ef..93d801a1571 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 08e8e27d092..94597e42b1c 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 e28997a9650..b45b82919a8 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 635862ad654..c1e520d29a6 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 c362336be55..307bdb074d5 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 dbe64eb1588..35b439275b6 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 9363521ddc8..a1cf21bffa8 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 8eeb536db51..3777cc1e50e 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 d4e6c257623..22738514829 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 45550f08969..e6c6b5c1d99 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 3a13f9a8811..67bc7902804 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 b3b3e2e65a2..a5cb1fcb640 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 7e904b582cd..78f9bec0bc5 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 49c367f3e57..10b5baa40df 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 9a7357d3063..8d8657fbbb8 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 56223d7bd0a..0a6da260764 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 5299b513089..25fd93513c0 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 795a50ef063..51427b54cc9 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 090fb882b42..b7d0fc29682 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 3023d8cc9c0..6008ed11700 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 d30c69363e3..93d7f966e89 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 b6f1a7e06da..246f528974a 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 1a2ef8dd320..5bed96e6965 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 df712f23ae3..5085554d25e 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 bf922cb3ba4..bc4104688bf 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 b853a8445af..8c1e7368deb 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 bf4dd451b4e..ecc2342b0fc 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 881c0878356..1c286e60551 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 00c1d3ea41e..01da86079de 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 db52d06a3a0..b324f29983d 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 ad986159e41..c73e4eae7c8 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 39c03e58f99..1af29f2d405 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 725bea80599..db54ddf8917 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 0d71c785670..708057ed63e 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 8061ee466f4..cb5647e7e22 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 62e28a886c9..f04a731c103 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 21967f2127d..154f424acd9 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 9a167da5cee..e0cc852277b 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 9fcba08d0ee..69ea9d11218 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 84447656400..d63591a75f1 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 25375a76cb8..a4991df4c25 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 ea820329c27..7bcd29d1445 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 189b8fa3494..b5a243fc47d 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 14927221970..0bd970565bc 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 4ed307c494b..03881a6b79f 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 a440e5b6739..a733da6ca68 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 2efdeadbde7..c28c4e327da 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 0be17a842dd..0e56c0d102b 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 04682ec6992..87d8aa45ec8 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 3d46b47c5d2..57557d6d465 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 680ab4f8a49..33be53050c8 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 474ff2a3e58..b332a184f65 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 a83b6f644fe..ceb301e27b1 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 9abe2be5057..295e632b461 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 a9c2b4b8dca..fd72054035e 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 c45c9cd350b..fa8d278b355 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 b49e31f8f67..35efe8b57cc 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 c7baece6972..5b0cdc29e9b 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 7a3b83ba5dc..a77923c7961 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 03bed48f582..0a2253a11e5 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 bee7f255733..c75e783e079 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 861264d82f4..38dafa92685 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 76f200f9f47..d0b23eadc4e 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 0562c9ada10..bfd7b687f45 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 93a2c280223..5a5a1f91130 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 ed7f5c292b2..cbf5cd257a6 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 b50a3dd2bfc..07ab6d3c392 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 d43f563b57a..22106504c29 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 0531574b408..33793107c69 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 1af0713696b..c2e33ab18b6 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 73d6df73daf..50ae2ad4a6c 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 eec36e1a57d..0c62d05c3f9 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 3f062c87d87..2f88a8bbd4b 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 ef85771b720..e37cebe82ec 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 c70d482bd0b..cddcc181d95 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 8e9b64774d5..b0cf9b295fa 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 3bf713d337e..673bf03b017 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
-- 
GitLab