diff --git a/cms/__init__.py b/cms/__init__.py index f9ed0bb3cea1..34c8992065be 100644 --- a/cms/__init__.py +++ b/cms/__init__.py @@ -1,9 +1,9 @@ +# ruff: noqa: I001 """ Celery needs to be loaded when the cms modules are so that task registration and discovery can work correctly. Import sorting is intentionally disabled in this module. -isort:skip_file """ diff --git a/cms/conftest.py b/cms/conftest.py index 131ea8e04831..ee83fb8c420e 100644 --- a/cms/conftest.py +++ b/cms/conftest.py @@ -1,3 +1,4 @@ +# ruff: noqa: I001 """ Studio unit test configuration and fixtures. @@ -13,7 +14,7 @@ from openedx.core.pytest_hooks import DeferPlugin # Patch the xml libs before anything else. -from openedx.core.lib.safe_lxml import defuse_xml_libs # isort:skip +from openedx.core.lib.safe_lxml import defuse_xml_libs # must patch xml libs before other imports execute defuse_xml_libs() diff --git a/cms/djangoapps/api/urls.py b/cms/djangoapps/api/urls.py index 8fd8495647b6..7c41fb966233 100644 --- a/cms/djangoapps/api/urls.py +++ b/cms/djangoapps/api/urls.py @@ -3,8 +3,7 @@ """ -from django.urls import include -from django.urls import path +from django.urls import include, path app_name = 'cms.djangoapps.api' diff --git a/cms/djangoapps/api/v1/tests/test_serializers/test_course_runs.py b/cms/djangoapps/api/v1/tests/test_serializers/test_course_runs.py index c648b2e5b875..690eb00565d8 100644 --- a/cms/djangoapps/api/v1/tests/test_serializers/test_course_runs.py +++ b/cms/djangoapps/api/v1/tests/test_serializers/test_course_runs.py @@ -2,6 +2,7 @@ import datetime + import ddt import pytz from django.test import RequestFactory @@ -9,7 +10,9 @@ from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole from common.djangoapps.student.tests.factories import UserFactory from openedx.core.lib.courses import course_image_url -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ...serializers.course_runs import CourseRunSerializer diff --git a/cms/djangoapps/api/v1/tests/test_views/test_course_runs.py b/cms/djangoapps/api/v1/tests/test_views/test_course_runs.py index 78261a421424..40d25cf901a2 100644 --- a/cms/djangoapps/api/v1/tests/test_views/test_course_runs.py +++ b/cms/djangoapps/api/v1/tests/test_views/test_course_runs.py @@ -20,8 +20,13 @@ from xmodule.contentstore.django import contentstore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.exceptions import NotFoundError # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + CourseFactory, + ToyCourseFactory, +) from ...serializers.course_runs import CourseRunSerializer from ..utils import serialize_datetime diff --git a/cms/djangoapps/api/v1/views/course_runs.py b/cms/djangoapps/api/v1/views/course_runs.py index 31c30d2d139a..9752e0ff074b 100644 --- a/cms/djangoapps/api/v1/views/course_runs.py +++ b/cms/djangoapps/api/v1/views/course_runs.py @@ -15,7 +15,7 @@ CourseRunCreateSerializer, CourseRunImageSerializer, CourseRunRerunSerializer, - CourseRunSerializer + CourseRunSerializer, ) diff --git a/cms/djangoapps/contentstore/api/tests/base.py b/cms/djangoapps/contentstore/api/tests/base.py index dd460734645c..36e87ea7eba8 100644 --- a/cms/djangoapps/contentstore/api/tests/base.py +++ b/cms/djangoapps/contentstore/api/tests/base.py @@ -5,11 +5,10 @@ from django.urls import reverse from rest_framework.test import APITestCase -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory -from common.djangoapps.student.tests.factories import StaffFactory -from common.djangoapps.student.tests.factories import UserFactory +from common.djangoapps.student.tests.factories import StaffFactory, UserFactory +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory # pylint: disable=unused-variable diff --git a/cms/djangoapps/contentstore/api/tests/test_import.py b/cms/djangoapps/contentstore/api/tests/test_import.py index 0f989a8151c0..3ed98b3fe353 100644 --- a/cms/djangoapps/contentstore/api/tests/test_import.py +++ b/cms/djangoapps/contentstore/api/tests/test_import.py @@ -12,12 +12,11 @@ from rest_framework import status from rest_framework.test import APITestCase from user_tasks.models import UserTaskStatus + +from common.djangoapps.student.tests.factories import StaffFactory, UserFactory from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from common.djangoapps.student.tests.factories import StaffFactory -from common.djangoapps.student.tests.factories import UserFactory - class CourseImportViewTest(SharedModuleStoreTestCase, APITestCase): """ diff --git a/cms/djangoapps/contentstore/api/tests/test_quality.py b/cms/djangoapps/contentstore/api/tests/test_quality.py index aa6b71e054be..46450c297e71 100644 --- a/cms/djangoapps/contentstore/api/tests/test_quality.py +++ b/cms/djangoapps/contentstore/api/tests/test_quality.py @@ -2,12 +2,13 @@ Tests for the course import API views """ -from rest_framework.test import APIClient +from openedx_authz.constants.roles import COURSE_DATA_RESEARCHER, COURSE_STAFF from rest_framework import status -from openedx_authz.constants.roles import COURSE_STAFF, COURSE_DATA_RESEARCHER +from rest_framework.test import APIClient from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.authz.tests.mixins import CourseAuthzTestMixin + from .base import BaseCourseViewTest diff --git a/cms/djangoapps/contentstore/api/tests/test_validation.py b/cms/djangoapps/contentstore/api/tests/test_validation.py index a091eedcc577..fab2089af8f1 100644 --- a/cms/djangoapps/contentstore/api/tests/test_validation.py +++ b/cms/djangoapps/contentstore/api/tests/test_validation.py @@ -7,23 +7,21 @@ import ddt import factory - from django.conf import settings from django.contrib.auth import get_user_model from django.test.utils import override_settings from django.urls import reverse +from openedx_authz.constants.roles import COURSE_DATA_RESEARCHER, COURSE_STAFF from rest_framework import status -from rest_framework.test import APITestCase -from rest_framework.test import APIClient -from openedx.core.djangoapps.authz.tests.mixins import CourseAuthzTestMixin -from openedx_authz.constants.roles import COURSE_STAFF, COURSE_DATA_RESEARCHER +from rest_framework.test import APIClient, APITestCase +from cms.djangoapps.contentstore.api.tests.base import BaseCourseViewTest from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory from common.djangoapps.student.tests.factories import StaffFactory, UserFactory +from openedx.core.djangoapps.authz.tests.mixins import CourseAuthzTestMixin from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory -from cms.djangoapps.contentstore.api.tests.base import BaseCourseViewTest User = get_user_model() diff --git a/cms/djangoapps/contentstore/api/views/course_quality.py b/cms/djangoapps/contentstore/api/views/course_quality.py index 6ff2c02e2f6c..1f51622cb4ab 100644 --- a/cms/djangoapps/contentstore/api/views/course_quality.py +++ b/cms/djangoapps/contentstore/api/views/course_quality.py @@ -4,16 +4,16 @@ import numpy as np from edxval.api import get_course_videos_qset +from openedx_authz.constants.permissions import COURSES_VIEW_COURSE from rest_framework.generics import GenericAPIView from rest_framework.response import Response -from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission from scipy import stats -from openedx_authz.constants.permissions import COURSES_VIEW_COURSE +from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission +from openedx.core.djangoapps.authz.decorators import authz_permission_required from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes from openedx.core.lib.cache_utils import request_cached from openedx.core.lib.graph_traversals import traverse_pre_order -from openedx.core.djangoapps.authz.decorators import authz_permission_required from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from .utils import get_bool_param diff --git a/cms/djangoapps/contentstore/api/views/course_validation.py b/cms/djangoapps/contentstore/api/views/course_validation.py index fd3e447b2746..56ff5fb0ed21 100644 --- a/cms/djangoapps/contentstore/api/views/course_validation.py +++ b/cms/djangoapps/contentstore/api/views/course_validation.py @@ -5,23 +5,23 @@ import edx_api_doc_tools as apidocs from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser +from openedx_authz.constants.permissions import COURSES_VIEW_COURSE from pytz import UTC from rest_framework import serializers, status from rest_framework.generics import GenericAPIView from rest_framework.response import Response -from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission from user_tasks.models import UserTaskStatus from user_tasks.views import StatusViewSet -from openedx_authz.constants.permissions import COURSES_VIEW_COURSE from cms.djangoapps.contentstore.course_info_model import get_course_updates from cms.djangoapps.contentstore.tasks import migrate_course_legacy_library_blocks_to_item_bank from cms.djangoapps.contentstore.views.certificates import CertificateManager from common.djangoapps.util.proctoring import requires_escalation_email +from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission +from openedx.core.djangoapps.authz.decorators import authz_permission_required from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser from openedx.core.lib.api.serializers import StatusSerializerWithUuid from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes -from openedx.core.djangoapps.authz.decorators import authz_permission_required from xmodule.course_metadata_utils import DEFAULT_GRADING_POLICY # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order diff --git a/cms/djangoapps/contentstore/asset_storage_handlers.py b/cms/djangoapps/contentstore/asset_storage_handlers.py index bbb1deaad21a..402ef9d70062 100644 --- a/cms/djangoapps/contentstore/asset_storage_handlers.py +++ b/cms/djangoapps/contentstore/asset_storage_handlers.py @@ -17,22 +17,22 @@ from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.http import require_http_methods, require_POST from opaque_keys.edx.keys import AssetKey, CourseKey -from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission -from openedx.core.djangoapps.authz.decorators import user_has_course_permission +from openedx_authz.constants.permissions import ( + COURSES_CREATE_FILES, + COURSES_DELETE_FILES, + COURSES_EDIT_FILES, + COURSES_VIEW_FILES, +) +from openedx_filters.content_authoring.filters import LMSPageURLRequested from pymongo import ASCENDING, DESCENDING from common.djangoapps.util.date_utils import get_default_time_display from common.djangoapps.util.json_request import JsonResponse +from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission +from openedx.core.djangoapps.authz.decorators import user_has_course_permission from openedx.core.djangoapps.contentserver.caching import del_cached_content from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.user_api.models import UserPreference -from openedx_authz.constants.permissions import ( - COURSES_VIEW_FILES, - COURSES_CREATE_FILES, - COURSES_DELETE_FILES, - COURSES_EDIT_FILES, -) -from openedx_filters.content_authoring.filters import LMSPageURLRequested from openedx.core.toggles import enable_authz_course_authoring from xmodule.contentstore.content import StaticContent # lint-amnesty, pylint: disable=wrong-import-order from xmodule.contentstore.django import contentstore # lint-amnesty, pylint: disable=wrong-import-order @@ -43,7 +43,6 @@ from .exceptions import AssetNotFoundException, AssetSizeTooLargeException from .utils import get_files_uploads_url, get_response_format, request_response_format_is_json - REQUEST_DEFAULTS = { 'page': 0, 'page_size': 50, diff --git a/cms/djangoapps/contentstore/core/course_optimizer_provider.py b/cms/djangoapps/contentstore/core/course_optimizer_provider.py index 134329992cfe..434d8729e77e 100644 --- a/cms/djangoapps/contentstore/core/course_optimizer_provider.py +++ b/cms/djangoapps/contentstore/core/course_optimizer_provider.py @@ -11,7 +11,7 @@ CourseLinkCheckTask, CourseLinkUpdateTask, LinkState, - extract_content_URLs_from_course + extract_content_URLs_from_course, ) from cms.djangoapps.contentstore.utils import create_course_info_usage_key, get_previous_run_course_key from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import get_xblock diff --git a/cms/djangoapps/contentstore/core/tests/test_course_optimizer_provider.py b/cms/djangoapps/contentstore/core/tests/test_course_optimizer_provider.py index 0780848dfda9..274f45fef705 100644 --- a/cms/djangoapps/contentstore/core/tests/test_course_optimizer_provider.py +++ b/cms/djangoapps/contentstore/core/tests/test_course_optimizer_provider.py @@ -11,7 +11,7 @@ _create_dto_recursive, _update_node_tree_and_dictionary, generate_broken_links_descriptor, - sort_course_sections + sort_course_sections, ) from cms.djangoapps.contentstore.tasks import LinkState, extract_content_URLs_from_course from cms.djangoapps.contentstore.tests.utils import CourseTestCase diff --git a/cms/djangoapps/contentstore/course_group_config.py b/cms/djangoapps/contentstore/course_group_config.py index a6babd0a0c2f..02757176ae80 100644 --- a/cms/djangoapps/contentstore/course_group_config.py +++ b/cms/djangoapps/contentstore/course_group_config.py @@ -12,6 +12,7 @@ from cms.djangoapps.contentstore.utils import reverse_usage_url from common.djangoapps.util.db import MYSQL_MAX_INT, generate_int_id from lms.lib.utils import get_parent_unit + # Re-exported for backward compatibility - other modules import these from here from openedx.core.djangoapps.course_groups.constants import ( # pylint: disable=unused-import COHORT_SCHEME, @@ -21,8 +22,14 @@ RANDOM_SCHEME, ) from openedx.core.djangoapps.course_groups.partition_scheme import get_cohorted_user_partition -from xmodule.partitions.partitions import MINIMUM_UNUSED_PARTITION_ID, ReadOnlyUserPartitionError, UserPartition # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions_service import get_all_partitions_for_course # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.partitions.partitions import ( # lint-amnesty, pylint: disable=wrong-import-order + MINIMUM_UNUSED_PARTITION_ID, + ReadOnlyUserPartitionError, + UserPartition, +) +from xmodule.partitions.partitions_service import ( + get_all_partitions_for_course, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.split_test_block import get_split_user_partitions # lint-amnesty, pylint: disable=wrong-import-order MINIMUM_GROUP_ID = MINIMUM_UNUSED_PARTITION_ID diff --git a/cms/djangoapps/contentstore/course_info_model.py b/cms/djangoapps/contentstore/course_info_model.py index e8a359d80564..16f2fbd197f6 100644 --- a/cms/djangoapps/contentstore/course_info_model.py +++ b/cms/djangoapps/contentstore/course_info_model.py @@ -19,7 +19,7 @@ from django.http import HttpResponseBadRequest from django.utils.translation import gettext as _ -from cms.djangoapps.contentstore.utils import track_course_update_event, send_course_update_notification +from cms.djangoapps.contentstore.utils import send_course_update_notification, track_course_update_event from openedx.core.lib.xblock_utils import get_course_update_items from xmodule.html_block import CourseInfoBlock # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order diff --git a/cms/djangoapps/contentstore/helpers.py b/cms/djangoapps/contentstore/helpers.py index 9bfab1f1f385..8213eb9e2c56 100644 --- a/cms/djangoapps/contentstore/helpers.py +++ b/cms/djangoapps/contentstore/helpers.py @@ -7,43 +7,41 @@ Platform-wide Python APIs should be added to an appropriate api.py file instead. """ from __future__ import annotations + import json import logging import pathlib +import re import urllib -from lxml import etree from mimetypes import guess_type -import re -from attrs import frozen, Factory -from django.core.files.base import ContentFile +from attrs import Factory, frozen from django.conf import settings from django.contrib.auth import get_user_model +from django.core.files.base import ContentFile from django.utils.translation import gettext as _ +from edxval.api import create_external_video, create_or_update_video_transcript +from lxml import etree from opaque_keys.edx.keys import CourseKey, UsageKey from opaque_keys.edx.locator import DefinitionLocator, LocalId -from openedx.core.djangoapps.content_tagging.types import TagValuesByObjectIdDict from xblock.core import XBlock from xblock.fields import ScopeIds from xblock.runtime import IdGenerator -from xmodule.contentstore.content import StaticContent -from xmodule.contentstore.django import contentstore -from xmodule.exceptions import NotFoundError -from xmodule.modulestore.django import modulestore -from xmodule.xml_block import XmlMixin -from openedx.core.djangoapps.video_config.transcripts_utils import Transcript, build_components_import_path -from edxval.api import ( - create_external_video, - create_or_update_video_transcript, -) +import openedx.core.djangoapps.content_staging.api as content_staging_api +import openedx.core.djangoapps.content_tagging.api as content_tagging_api from cms.djangoapps.models.settings.course_grading import CourseGradingModel from cms.lib.xblock.upstream_sync import UpstreamLink, UpstreamLinkException from cms.lib.xblock.upstream_sync_block import fetch_customizable_fields_from_block -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers -import openedx.core.djangoapps.content_staging.api as content_staging_api -import openedx.core.djangoapps.content_tagging.api as content_tagging_api from openedx.core.djangoapps.content_staging.data import LIBRARY_SYNC_PURPOSE +from openedx.core.djangoapps.content_tagging.types import TagValuesByObjectIdDict +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.djangoapps.video_config.transcripts_utils import Transcript, build_components_import_path +from xmodule.contentstore.content import StaticContent +from xmodule.contentstore.django import contentstore +from xmodule.exceptions import NotFoundError +from xmodule.modulestore.django import modulestore +from xmodule.xml_block import XmlMixin from .utils import reverse_course_url, reverse_library_url, reverse_usage_url diff --git a/cms/djangoapps/contentstore/management/commands/backfill_course_outlines.py b/cms/djangoapps/contentstore/management/commands/backfill_course_outlines.py index 99718ce0dd67..04c10f477fff 100644 --- a/cms/djangoapps/contentstore/management/commands/backfill_course_outlines.py +++ b/cms/djangoapps/contentstore/management/commands/backfill_course_outlines.py @@ -12,10 +12,7 @@ from django.core.management.base import BaseCommand from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from openedx.core.djangoapps.content.learning_sequences.api import ( - get_course_keys_with_outlines, - key_supports_outlines, -) +from openedx.core.djangoapps.content.learning_sequences.api import get_course_keys_with_outlines, key_supports_outlines from ...tasks import update_outline_from_modulestore_task diff --git a/cms/djangoapps/contentstore/management/commands/backfill_course_tabs.py b/cms/djangoapps/contentstore/management/commands/backfill_course_tabs.py index 768c3a53f7ac..c2d8a187eb2b 100644 --- a/cms/djangoapps/contentstore/management/commands/backfill_course_tabs.py +++ b/cms/djangoapps/contentstore/management/commands/backfill_course_tabs.py @@ -12,11 +12,11 @@ import logging from django.core.management.base import BaseCommand -from xmodule.tabs import CourseTabList -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.django import modulestore from cms.djangoapps.contentstore.models import BackfillCourseTabsConfig +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore +from xmodule.tabs import CourseTabList logger = logging.getLogger(__name__) diff --git a/cms/djangoapps/contentstore/management/commands/compare_course_index_entries.py b/cms/djangoapps/contentstore/management/commands/compare_course_index_entries.py index bbb5bd79fe65..fb7e2d714175 100644 --- a/cms/djangoapps/contentstore/management/commands/compare_course_index_entries.py +++ b/cms/djangoapps/contentstore/management/commands/compare_course_index_entries.py @@ -1,10 +1,12 @@ """A Command to determine if the Mongo active_versions and Django course_index tables are out of sync""" import logging -from django.core.management.base import BaseCommand + from django.conf import settings +from django.core.management.base import BaseCommand from opaque_keys.edx.locator import CourseLocator + from common.djangoapps.split_modulestore_django.models import SplitModulestoreCourseIndex -from xmodule.modulestore.split_mongo.mongo_connection import MongoPersistenceBackend, DjangoFlexPersistenceBackend +from xmodule.modulestore.split_mongo.mongo_connection import DjangoFlexPersistenceBackend, MongoPersistenceBackend logger = logging.getLogger(__name__) diff --git a/cms/djangoapps/contentstore/management/commands/delete_v1_libraries.py b/cms/djangoapps/contentstore/management/commands/delete_v1_libraries.py index b9a4368f6d6b..f9f049054d46 100644 --- a/cms/djangoapps/contentstore/management/commands/delete_v1_libraries.py +++ b/cms/djangoapps/contentstore/management/commands/delete_v1_libraries.py @@ -3,16 +3,13 @@ import logging from textwrap import dedent +from celery import group from django.core.management import BaseCommand, CommandError - from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import LibraryLocator -from xmodule.modulestore.django import modulestore - -from celery import group - from cms.djangoapps.contentstore.tasks import delete_v1_library +from xmodule.modulestore.django import modulestore from .prompt import query_yes_no diff --git a/cms/djangoapps/contentstore/management/commands/reindex_course.py b/cms/djangoapps/contentstore/management/commands/reindex_course.py index 0bd52b6cc16e..557267986a9b 100644 --- a/cms/djangoapps/contentstore/management/commands/reindex_course.py +++ b/cms/djangoapps/contentstore/management/commands/reindex_course.py @@ -2,12 +2,12 @@ import logging +from datetime import date, datetime from textwrap import dedent from time import time -from datetime import date, datetime -from django.core.management import BaseCommand, CommandError from django.conf import settings +from django.core.management import BaseCommand, CommandError from elasticsearch import exceptions from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey diff --git a/cms/djangoapps/contentstore/management/commands/replace_v1_lib_refs_with_v2_in_courses.py b/cms/djangoapps/contentstore/management/commands/replace_v1_lib_refs_with_v2_in_courses.py index 6c19a89cf3ff..13ffa9494de0 100644 --- a/cms/djangoapps/contentstore/management/commands/replace_v1_lib_refs_with_v2_in_courses.py +++ b/cms/djangoapps/contentstore/management/commands/replace_v1_lib_refs_with_v2_in_courses.py @@ -3,18 +3,18 @@ edits all xblocks in courses which refer to the v1 library to point to the v2 library. """ -import logging import csv +import logging -from django.core.management import BaseCommand, CommandError from celery import group +from django.core.management import BaseCommand, CommandError -from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from cms.djangoapps.contentstore.tasks import ( replace_all_library_source_blocks_ids_for_course, + undo_all_library_source_blocks_ids_for_course, validate_all_library_source_blocks_ids_for_course, - undo_all_library_source_blocks_ids_for_course ) +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview log = logging.getLogger(__name__) diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_backfill_course_outlines.py b/cms/djangoapps/contentstore/management/commands/tests/test_backfill_course_outlines.py index 53a6c3b5571a..60b1eebd228c 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_backfill_course_outlines.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_backfill_course_outlines.py @@ -6,8 +6,13 @@ from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.content.learning_sequences.api import get_course_keys_with_outlines -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) from ....outlines import update_outline_from_modulestore diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_backfill_course_tabs.py b/cms/djangoapps/contentstore/management/commands/tests/test_backfill_course_tabs.py index a83eb621b30e..8af72088b16b 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_backfill_course_tabs.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_backfill_course_tabs.py @@ -5,12 +5,12 @@ import ddt from django.core.management import call_command + +from cms.djangoapps.contentstore.models import BackfillCourseTabsConfig from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from cms.djangoapps.contentstore.models import BackfillCourseTabsConfig - @ddt.ddt class BackfillCourseTabsTest(ModuleStoreTestCase): diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_backfill_orgs_and_org_courses.py b/cms/djangoapps/contentstore/management/commands/tests/test_backfill_orgs_and_org_courses.py index 57deafadae7d..461db23169de 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_backfill_orgs_and_org_courses.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_backfill_orgs_and_org_courses.py @@ -12,11 +12,13 @@ add_organization_course, get_organization_by_short_name, get_organization_courses, - get_organizations + get_organizations, ) from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import LibraryFactory # lint-amnesty, pylint: disable=wrong-import-order from .. import backfill_orgs_and_org_courses diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_clean_stale_certificate_availability_dates.py b/cms/djangoapps/contentstore/management/commands/tests/test_clean_stale_certificate_availability_dates.py index 42b3ca408aa2..e9548be04c79 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_clean_stale_certificate_availability_dates.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_clean_stale_certificate_availability_dates.py @@ -3,8 +3,8 @@ """ from datetime import datetime, timedelta -from django.core.management import CommandError, call_command import pytz +from django.core.management import CommandError, call_command from cms.djangoapps.contentstore.models import CleanStaleCertificateAvailabilityDatesConfig from openedx.core.lib.courses import get_course_by_id diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_cleanup_assets.py b/cms/djangoapps/contentstore/management/commands/tests/test_cleanup_assets.py index e31d566543fe..049652fac857 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_cleanup_assets.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_cleanup_assets.py @@ -5,6 +5,7 @@ from unittest import skip + from django.conf import settings from django.core.management import call_command from opaque_keys.edx.keys import CourseKey diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_delete_course.py b/cms/djangoapps/contentstore/management/commands/tests/test_delete_course.py index ccdcde990135..4df8ca479ec5 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_delete_course.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_delete_course.py @@ -6,15 +6,15 @@ from unittest import mock from django.core.management import CommandError, call_command + +from common.djangoapps.student.roles import CourseInstructorRole +from common.djangoapps.student.tests.factories import UserFactory from xmodule.contentstore.content import StaticContent from xmodule.contentstore.django import contentstore from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from common.djangoapps.student.roles import CourseInstructorRole -from common.djangoapps.student.tests.factories import UserFactory - class DeleteCourseTests(ModuleStoreTestCase): """ diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_export_all_courses.py b/cms/djangoapps/contentstore/management/commands/tests/test_export_all_courses.py index 5c01abde69ab..027455a73547 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_export_all_courses.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_export_all_courses.py @@ -10,7 +10,9 @@ from cms.djangoapps.contentstore.management.commands.export_all_courses import export_courses_to_output_path from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_export_olx.py b/cms/djangoapps/contentstore/management/commands/tests/test_export_olx.py index 8f5505ede5c1..49ba208b11e5 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_export_olx.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_export_olx.py @@ -12,13 +12,12 @@ from django.core.management import CommandError, call_command from path import Path as path +from openedx.core.djangoapps.content_tagging.tests.test_objecttag_export_helpers import TaggedCourseMixin 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 openedx.core.djangoapps.content_tagging.tests.test_objecttag_export_helpers import TaggedCourseMixin - class TestArgParsingCourseExportOlx(unittest.TestCase): """ diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_fix_not_found.py b/cms/djangoapps/contentstore/management/commands/tests/test_fix_not_found.py index b9372d15204b..b957e95eae88 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_fix_not_found.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_fix_not_found.py @@ -7,7 +7,7 @@ from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory class TestFixNotFound(ModuleStoreTestCase): diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_force_publish.py b/cms/djangoapps/contentstore/management/commands/tests/test_force_publish.py index ea16707d7eb8..bfe123010f90 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_force_publish.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_force_publish.py @@ -10,8 +10,14 @@ from cms.djangoapps.contentstore.management.commands.force_publish import Command from cms.djangoapps.contentstore.management.commands.utils import get_course_versions from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order + ModuleStoreTestCase, + SharedModuleStoreTestCase, +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) class TestForcePublish(SharedModuleStoreTestCase): diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_import.py b/cms/djangoapps/contentstore/management/commands/tests/test_import.py index 5b90973b0463..900a1e25ead7 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_import.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_import.py @@ -12,7 +12,9 @@ from openedx.core.djangoapps.django_comment_common.utils import are_permissions_roles_seeded from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) class TestImport(ModuleStoreTestCase): diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_reindex_courses.py b/cms/djangoapps/contentstore/management/commands/tests/test_reindex_courses.py index 6d14b4a339f2..c7fb4249b0b4 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_reindex_courses.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_reindex_courses.py @@ -1,16 +1,22 @@ """ Tests for course reindex command """ +from datetime import datetime, timedelta from unittest import mock import ddt from django.core.management import CommandError, call_command + from cms.djangoapps.contentstore.management.commands.reindex_course import Command as ReindexCommand from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, LibraryFactory # lint-amnesty, pylint: disable=wrong-import-order -from datetime import datetime, timedelta +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + CourseFactory, + LibraryFactory, +) @ddt.ddt diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_reindex_library.py b/cms/djangoapps/contentstore/management/commands/tests/test_reindex_library.py index d5013cf69462..6ba5ac63625f 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_reindex_library.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_reindex_library.py @@ -11,8 +11,13 @@ from cms.djangoapps.contentstore.management.commands.reindex_library import Command as ReindexCommand from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, LibraryFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + CourseFactory, + LibraryFactory, +) @ddt.ddt diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_sync_courses.py b/cms/djangoapps/contentstore/management/commands/tests/test_sync_courses.py index 6894bc49556f..a58c891c4730 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_sync_courses.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_sync_courses.py @@ -13,7 +13,9 @@ from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) COMMAND_MODULE = 'cms.djangoapps.contentstore.management.commands.sync_courses' diff --git a/cms/djangoapps/contentstore/migrations/0001_squashed_0015_switch_to_openedx_content.py b/cms/djangoapps/contentstore/migrations/0001_squashed_0015_switch_to_openedx_content.py index b39c898d56fa..d33c265979c5 100644 --- a/cms/djangoapps/contentstore/migrations/0001_squashed_0015_switch_to_openedx_content.py +++ b/cms/djangoapps/contentstore/migrations/0001_squashed_0015_switch_to_openedx_content.py @@ -1,11 +1,12 @@ # Generated by Django 5.2.10 on 2026-01-30 01:23 +import uuid + import django.db.migrations.operations.special import django.db.models.deletion import opaque_keys.edx.django.models import openedx_django_lib.fields import openedx_django_lib.validators -import uuid from django.conf import settings from django.db import migrations, models diff --git a/cms/djangoapps/contentstore/migrations/0007_backfillcoursetabsconfig.py b/cms/djangoapps/contentstore/migrations/0007_backfillcoursetabsconfig.py index 2123798d83e8..235373267153 100644 --- a/cms/djangoapps/contentstore/migrations/0007_backfillcoursetabsconfig.py +++ b/cms/djangoapps/contentstore/migrations/0007_backfillcoursetabsconfig.py @@ -1,8 +1,8 @@ # Generated by Django 3.2.12 on 2022-03-18 13:49 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/cms/djangoapps/contentstore/migrations/0008_cleanstalecertificateavailabilitydatesconfig.py b/cms/djangoapps/contentstore/migrations/0008_cleanstalecertificateavailabilitydatesconfig.py index 50187a8cac54..034c8fbbdc13 100644 --- a/cms/djangoapps/contentstore/migrations/0008_cleanstalecertificateavailabilitydatesconfig.py +++ b/cms/djangoapps/contentstore/migrations/0008_cleanstalecertificateavailabilitydatesconfig.py @@ -1,8 +1,8 @@ # Generated by Django 3.2.13 on 2022-07-11 17:08 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/cms/djangoapps/contentstore/migrations/0011_enable_markdown_editor_flag_by_default.py b/cms/djangoapps/contentstore/migrations/0011_enable_markdown_editor_flag_by_default.py index 491ae0e4224a..266bcdf9db3a 100644 --- a/cms/djangoapps/contentstore/migrations/0011_enable_markdown_editor_flag_by_default.py +++ b/cms/djangoapps/contentstore/migrations/0011_enable_markdown_editor_flag_by_default.py @@ -1,8 +1,6 @@ from django.db import migrations -from cms.djangoapps.contentstore.toggles import ( - ENABLE_REACT_MARKDOWN_EDITOR -) +from cms.djangoapps.contentstore.toggles import ENABLE_REACT_MARKDOWN_EDITOR def create_flag(apps, schema_editor): diff --git a/cms/djangoapps/contentstore/migrations/0012_componentlink_top_level_parent_and_more.py b/cms/djangoapps/contentstore/migrations/0012_componentlink_top_level_parent_and_more.py index 02f94f4b6593..e7f3fd688d8b 100644 --- a/cms/djangoapps/contentstore/migrations/0012_componentlink_top_level_parent_and_more.py +++ b/cms/djangoapps/contentstore/migrations/0012_componentlink_top_level_parent_and_more.py @@ -1,7 +1,7 @@ # Generated by Django 4.2.23 on 2025-08-04 18:56 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/cms/djangoapps/contentstore/models.py b/cms/djangoapps/contentstore/models.py index 0685b93f0281..b1910750541f 100644 --- a/cms/djangoapps/contentstore/models.py +++ b/cms/djangoapps/contentstore/models.py @@ -17,11 +17,7 @@ from opaque_keys.edx.locator import LibraryContainerLocator from openedx_content.api import get_published_version from openedx_content.models_api import Component, Container -from openedx_django_lib.fields import ( - immutable_uuid_field, - key_field, - manual_date_time_field, -) +from openedx_django_lib.fields import immutable_uuid_field, key_field, manual_date_time_field logger = logging.getLogger(__name__) diff --git a/cms/djangoapps/contentstore/outlines.py b/cms/djangoapps/contentstore/outlines.py index 72d5c4f257f0..aad3b378a6f0 100644 --- a/cms/djangoapps/contentstore/outlines.py +++ b/cms/djangoapps/contentstore/outlines.py @@ -16,7 +16,7 @@ CourseSectionData, CourseVisibility, ExamData, - VisibilityData + VisibilityData, ) from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order diff --git a/cms/djangoapps/contentstore/proctoring.py b/cms/djangoapps/contentstore/proctoring.py index bd33049006c4..31042c249c50 100644 --- a/cms/djangoapps/contentstore/proctoring.py +++ b/cms/djangoapps/contentstore/proctoring.py @@ -16,7 +16,7 @@ get_exam_by_content_id, remove_review_policy, update_exam, - update_review_policy + update_review_policy, ) from edx_proctoring.exceptions import ProctoredExamNotFoundException, ProctoredExamReviewPolicyNotFoundException diff --git a/cms/djangoapps/contentstore/rest_api/urls.py b/cms/djangoapps/contentstore/rest_api/urls.py index 7296f7bb9858..af2694bfbbc5 100644 --- a/cms/djangoapps/contentstore/rest_api/urls.py +++ b/cms/djangoapps/contentstore/rest_api/urls.py @@ -2,8 +2,7 @@ Contentstore API URLs. """ -from django.urls import path -from django.urls import include +from django.urls import include, path from .v0 import urls as v0_urls from .v1 import urls as v1_urls diff --git a/cms/djangoapps/contentstore/rest_api/v0/__init__.py b/cms/djangoapps/contentstore/rest_api/v0/__init__.py index 4ceefe6ead69..1af3b679fc9f 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/__init__.py +++ b/cms/djangoapps/contentstore/rest_api/v0/__init__.py @@ -2,11 +2,5 @@ Views for v0 contentstore API. """ -from cms.djangoapps.contentstore.rest_api.v0.views.assets import ( - AssetsCreateRetrieveView, - AssetsUpdateDestroyView -) -from cms.djangoapps.contentstore.rest_api.v0.views.xblock import ( - XblockView, - XblockCreateView -) +from cms.djangoapps.contentstore.rest_api.v0.views.assets import AssetsCreateRetrieveView, AssetsUpdateDestroyView +from cms.djangoapps.contentstore.rest_api.v0.views.xblock import XblockCreateView, XblockView diff --git a/cms/djangoapps/contentstore/rest_api/v0/serializers/advanced_settings.py b/cms/djangoapps/contentstore/rest_api/v0/serializers/advanced_settings.py index 152ca95be341..31b3d27d08ea 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/serializers/advanced_settings.py +++ b/cms/djangoapps/contentstore/rest_api/v0/serializers/advanced_settings.py @@ -1,23 +1,15 @@ """ Serializers for course advanced settings""" -from typing import Type, Dict as DictType +from typing import Dict as DictType +from typing import Type from django.utils.translation import gettext_lazy as _ from rest_framework import serializers from rest_framework.fields import Field as SerializerField -from xblock.fields import ( - Boolean, - Date, - DateTime, - Dict, - Field as XBlockField, - Float, - Integer, - List, - String, -) -from xmodule.course_block import CourseFields, EmailString +from xblock.fields import Boolean, Date, DateTime, Dict, Float, Integer, List, String +from xblock.fields import Field as XBlockField from cms.djangoapps.models.settings.course_metadata import CourseMetadata +from xmodule.course_block import CourseFields, EmailString # Maps xblock fields to their corresponding Django Rest Framework serializer field XBLOCK_DRF_FIELD_MAP = [ diff --git a/cms/djangoapps/contentstore/rest_api/v0/serializers/assets.py b/cms/djangoapps/contentstore/rest_api/v0/serializers/assets.py index 7ecb473d1ade..d8015baad71b 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/serializers/assets.py +++ b/cms/djangoapps/contentstore/rest_api/v0/serializers/assets.py @@ -2,6 +2,7 @@ API Serializers for assets """ from rest_framework import serializers + from cms.djangoapps.contentstore.rest_api.serializers.common import StrictSerializer diff --git a/cms/djangoapps/contentstore/rest_api/v0/serializers/tabs.py b/cms/djangoapps/contentstore/rest_api/v0/serializers/tabs.py index ad6c1d645e57..9f5b6af7321d 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/serializers/tabs.py +++ b/cms/djangoapps/contentstore/rest_api/v0/serializers/tabs.py @@ -3,9 +3,9 @@ from django.utils.translation import gettext_lazy as _ from rest_framework import serializers -from xmodule.tabs import CourseTab from openedx.core.lib.api.serializers import UsageKeyField +from xmodule.tabs import CourseTab class CourseTabSerializer(serializers.Serializer): # pylint: disable=abstract-method diff --git a/cms/djangoapps/contentstore/rest_api/v0/serializers/transcripts.py b/cms/djangoapps/contentstore/rest_api/v0/serializers/transcripts.py index d0cb92e9060e..269d6057041e 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/serializers/transcripts.py +++ b/cms/djangoapps/contentstore/rest_api/v0/serializers/transcripts.py @@ -2,6 +2,7 @@ API Serializers for transcripts """ from rest_framework import serializers + from cms.djangoapps.contentstore.rest_api.serializers.common import StrictSerializer diff --git a/cms/djangoapps/contentstore/rest_api/v0/serializers/xblock.py b/cms/djangoapps/contentstore/rest_api/v0/serializers/xblock.py index e95a76e91899..48ef9f82d580 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/serializers/xblock.py +++ b/cms/djangoapps/contentstore/rest_api/v0/serializers/xblock.py @@ -2,6 +2,7 @@ API Serializers for xblocks """ from rest_framework import serializers + from cms.djangoapps.contentstore.rest_api.serializers.common import StrictSerializer # The XblockSerializer is designed to be scalable and generic. As such, its structure diff --git a/cms/djangoapps/contentstore/rest_api/v0/tests/test_advanced_settings.py b/cms/djangoapps/contentstore/rest_api/v0/tests/test_advanced_settings.py index f3c3806578c6..30556bc8649b 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/tests/test_advanced_settings.py +++ b/cms/djangoapps/contentstore/rest_api/v0/tests/test_advanced_settings.py @@ -2,23 +2,23 @@ Tests for the course advanced settings API. """ import json -import pkg_resources from unittest.mock import patch import casbin import ddt +import pkg_resources from django.test import override_settings from django.urls import reverse from milestones.tests.utils import MilestonesTestCaseMixin +from openedx_authz.api.users import assign_role_to_user_in_scope +from openedx_authz.constants.roles import COURSE_STAFF +from openedx_authz.engine.enforcer import AuthzEnforcer +from openedx_authz.engine.utils import migrate_policy_between_enforcers from rest_framework.test import APIClient from cms.djangoapps.contentstore.tests.utils import CourseTestCase from common.djangoapps.student.tests.factories import UserFactory from openedx.core import toggles as core_toggles -from openedx_authz.api.users import assign_role_to_user_in_scope -from openedx_authz.constants.roles import COURSE_STAFF -from openedx_authz.engine.enforcer import AuthzEnforcer -from openedx_authz.engine.utils import migrate_policy_between_enforcers @ddt.ddt diff --git a/cms/djangoapps/contentstore/rest_api/v0/tests/test_assets.py b/cms/djangoapps/contentstore/rest_api/v0/tests/test_assets.py index 3772dbb64e77..bfd710d499d2 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/tests/test_assets.py +++ b/cms/djangoapps/contentstore/rest_api/v0/tests/test_assets.py @@ -5,17 +5,16 @@ not the underlying Xblock service. It checks that the assets_handler method of the Xblock service is called with the expected parameters. """ -from unittest.mock import patch, MagicMock +from unittest.mock import MagicMock, patch from django.core.files import File from django.http import JsonResponse from django.urls import reverse from rest_framework import status from rest_framework.test import APITestCase -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from cms.djangoapps.contentstore.tests.test_utils import AuthorizeStaffTestCase - +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase ASSET_KEY_STRING = "asset-v1:dede+aba+weagi+type@asset+block@_0e37192a-42c4-441e-a3e1-8e40ec304e2e.jpg" mock_image = MagicMock(file=File) diff --git a/cms/djangoapps/contentstore/rest_api/v0/tests/test_authoring_grading.py b/cms/djangoapps/contentstore/rest_api/v0/tests/test_authoring_grading.py index 9a8ce73aa7de..9c70c7e6fab5 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/tests/test_authoring_grading.py +++ b/cms/djangoapps/contentstore/rest_api/v0/tests/test_authoring_grading.py @@ -11,6 +11,7 @@ from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.authz.tests.mixins import CourseAuthzTestMixin + class AuthoringGradingViewAuthzTest(CourseAuthzTestMixin, BaseCourseViewTest): """ Tests Authoring Grading configuration API authorization using openedx-authz. diff --git a/cms/djangoapps/contentstore/rest_api/v0/tests/test_course_optimizer.py b/cms/djangoapps/contentstore/rest_api/v0/tests/test_course_optimizer.py index 14d5a20fb41b..4f0dfe189204 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/tests/test_course_optimizer.py +++ b/cms/djangoapps/contentstore/rest_api/v0/tests/test_course_optimizer.py @@ -2,10 +2,10 @@ Unit tests for course optimizer """ from django.test import TestCase -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from django.urls import reverse from cms.djangoapps.contentstore.tests.test_utils import AuthorizeStaffTestCase +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase class TestGetLinkCheckStatus(AuthorizeStaffTestCase, ModuleStoreTestCase, TestCase): diff --git a/cms/djangoapps/contentstore/rest_api/v0/tests/test_tabs.py b/cms/djangoapps/contentstore/rest_api/v0/tests/test_tabs.py index 5e83c9313617..46a804662c5e 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/tests/test_tabs.py +++ b/cms/djangoapps/contentstore/rest_api/v0/tests/test_tabs.py @@ -8,10 +8,10 @@ import ddt from django.urls import reverse -from xmodule.modulestore.tests.factories import BlockFactory -from xmodule.tabs import CourseTabList from cms.djangoapps.contentstore.tests.utils import CourseTestCase +from xmodule.modulestore.tests.factories import BlockFactory +from xmodule.tabs import CourseTabList @ddt.ddt diff --git a/cms/djangoapps/contentstore/rest_api/v0/tests/test_xblock.py b/cms/djangoapps/contentstore/rest_api/v0/tests/test_xblock.py index 512c92f6ffe9..f192e39c757a 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/tests/test_xblock.py +++ b/cms/djangoapps/contentstore/rest_api/v0/tests/test_xblock.py @@ -4,15 +4,14 @@ It checks that the xblock_handler method of the Xblock service is called with the expected parameters. """ from unittest.mock import patch -from django.http import JsonResponse +from django.http import JsonResponse from django.urls import reverse from rest_framework import status from rest_framework.test import APITestCase -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from cms.djangoapps.contentstore.tests.test_utils import AuthorizeStaffTestCase - +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase TEST_LOCATOR = "block-v1:dede+aba+weagi+type@problem+block@ba6327f840da49289fb27a9243913478" VERSION = "v0" diff --git a/cms/djangoapps/contentstore/rest_api/v0/urls.py b/cms/djangoapps/contentstore/rest_api/v0/urls.py index 974d1b98a0c4..65d45a98126d 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/urls.py +++ b/cms/djangoapps/contentstore/rest_api/v0/urls.py @@ -1,7 +1,7 @@ """ Contenstore API v0 URLs. """ from django.conf import settings -from django.urls import re_path, path +from django.urls import path, re_path from openedx.core.constants import COURSE_ID_PATTERN @@ -19,10 +19,10 @@ TranscriptView, YoutubeTranscriptCheckView, YoutubeTranscriptUploadView, + assets, + authoring_videos, + xblock, ) -from .views import assets -from .views import authoring_videos -from .views import xblock app_name = "v0" diff --git a/cms/djangoapps/contentstore/rest_api/v0/views/advanced_settings.py b/cms/djangoapps/contentstore/rest_api/v0/views/advanced_settings.py index fe9689f45902..e7baf54b375d 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/views/advanced_settings.py +++ b/cms/djangoapps/contentstore/rest_api/v0/views/advanced_settings.py @@ -1,20 +1,21 @@ """ API Views for course advanced settings """ -from django import forms import edx_api_doc_tools as apidocs +from django import forms from opaque_keys.edx.keys import CourseKey from rest_framework.exceptions import ValidationError from rest_framework.request import Request from rest_framework.response import Response from rest_framework.views import APIView -from xmodule.modulestore.django import modulestore -from cms.djangoapps.models.settings.course_metadata import CourseMetadata from cms.djangoapps.contentstore.api.views.utils import get_bool_param +from cms.djangoapps.models.settings.course_metadata import CourseMetadata from common.djangoapps.student.auth import check_course_advanced_settings_access from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, verify_course_exists, view_auth_classes -from ..serializers import CourseAdvancedSettingsSerializer +from xmodule.modulestore.django import modulestore + from ....views.course import update_course_advanced_settings +from ..serializers import CourseAdvancedSettingsSerializer @view_auth_classes(is_authenticated=True) diff --git a/cms/djangoapps/contentstore/rest_api/v0/views/api_heartbeat.py b/cms/djangoapps/contentstore/rest_api/v0/views/api_heartbeat.py index 2a5851f20376..78aa655f652a 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/views/api_heartbeat.py +++ b/cms/djangoapps/contentstore/rest_api/v0/views/api_heartbeat.py @@ -1,9 +1,10 @@ """ View For Getting the Status of The Authoring API """ import edx_api_doc_tools as apidocs -from rest_framework.views import APIView +from rest_framework import status from rest_framework.request import Request from rest_framework.response import Response -from rest_framework import status +from rest_framework.views import APIView + from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes diff --git a/cms/djangoapps/contentstore/rest_api/v0/views/assets.py b/cms/djangoapps/contentstore/rest_api/v0/views/assets.py index a7a495256514..868614951fc4 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/views/assets.py +++ b/cms/djangoapps/contentstore/rest_api/v0/views/assets.py @@ -2,20 +2,19 @@ Public rest API endpoints for the CMS API Assets. """ import logging -from rest_framework.generics import CreateAPIView, RetrieveAPIView, UpdateAPIView, DestroyAPIView -from django.views.decorators.csrf import csrf_exempt -from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes -from common.djangoapps.util.json_request import expect_json_in_class_view +from django.views.decorators.csrf import csrf_exempt +from rest_framework.generics import CreateAPIView, DestroyAPIView, RetrieveAPIView, UpdateAPIView +from rest_framework.parsers import FormParser, JSONParser, MultiPartParser from cms.djangoapps.contentstore.api import course_author_access_required - from cms.djangoapps.contentstore.asset_storage_handlers import handle_assets +from common.djangoapps.util.json_request import expect_json_in_class_view +from openedx.core.lib.api.parsers import TypedFileUploadParser +from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes from ..serializers.assets import AssetSerializer from .utils import validate_request_with_serializer -from rest_framework.parsers import (MultiPartParser, FormParser, JSONParser) -from openedx.core.lib.api.parsers import TypedFileUploadParser log = logging.getLogger(__name__) diff --git a/cms/djangoapps/contentstore/rest_api/v0/views/authoring_grading.py b/cms/djangoapps/contentstore/rest_api/v0/views/authoring_grading.py index 058c9cef9c8a..db3fffd17fa7 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/views/authoring_grading.py +++ b/cms/djangoapps/contentstore/rest_api/v0/views/authoring_grading.py @@ -12,6 +12,7 @@ from openedx.core.djangoapps.authz.decorators import authz_permission_required from openedx.core.djangoapps.credit.tasks import update_credit_course_requirements from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, verify_course_exists, view_auth_classes + from ..serializers import CourseGradingModelSerializer diff --git a/cms/djangoapps/contentstore/rest_api/v0/views/authoring_videos.py b/cms/djangoapps/contentstore/rest_api/v0/views/authoring_videos.py index f97bf7a98d16..5a7563c2372e 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/views/authoring_videos.py +++ b/cms/djangoapps/contentstore/rest_api/v0/views/authoring_videos.py @@ -2,32 +2,24 @@ Public rest API endpoints for the Authoring API video assets. """ import logging -from rest_framework.generics import ( - CreateAPIView, - RetrieveAPIView, - DestroyAPIView -) -from rest_framework.parsers import (MultiPartParser, FormParser) -from django.views.decorators.csrf import csrf_exempt -from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes -from openedx.core.lib.api.parsers import TypedFileUploadParser -from common.djangoapps.util.json_request import expect_json_in_class_view - -from ....api import course_author_access_required +from django.views.decorators.csrf import csrf_exempt +from rest_framework.generics import CreateAPIView, DestroyAPIView, RetrieveAPIView +from rest_framework.parsers import FormParser, MultiPartParser +from cms.djangoapps.contentstore.rest_api.v1.serializers import VideoImageSerializer, VideoUploadSerializer from cms.djangoapps.contentstore.video_storage_handlers import ( - handle_videos, + enabled_video_features, get_video_encodings_download, handle_video_images, - enabled_video_features -) -from cms.djangoapps.contentstore.rest_api.v1.serializers import ( - VideoUploadSerializer, - VideoImageSerializer, + handle_videos, ) -from .utils import validate_request_with_serializer +from common.djangoapps.util.json_request import expect_json_in_class_view +from openedx.core.lib.api.parsers import TypedFileUploadParser +from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes +from ....api import course_author_access_required +from .utils import validate_request_with_serializer log = logging.getLogger(__name__) diff --git a/cms/djangoapps/contentstore/rest_api/v0/views/course_optimizer.py b/cms/djangoapps/contentstore/rest_api/v0/views/course_optimizer.py index bd37ae837916..9b012d918e06 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/views/course_optimizer.py +++ b/cms/djangoapps/contentstore/rest_api/v0/views/course_optimizer.py @@ -15,19 +15,15 @@ sort_course_sections, ) from cms.djangoapps.contentstore.rest_api.v0.serializers.course_optimizer import ( + CourseRerunLinkUpdateRequestSerializer, CourseRerunLinkUpdateStatusSerializer, LinkCheckSerializer, - CourseRerunLinkUpdateRequestSerializer, ) from cms.djangoapps.contentstore.tasks import check_broken_links, update_course_rerun_links from cms.djangoapps.contentstore.toggles import enable_course_optimizer_check_prev_run_links from common.djangoapps.student.auth import has_course_author_access, has_studio_read_access from common.djangoapps.util.json_request import JsonResponse -from openedx.core.lib.api.view_utils import ( - DeveloperErrorViewMixin, - verify_course_exists, - view_auth_classes, -) +from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, verify_course_exists, view_auth_classes @view_auth_classes(is_authenticated=True) diff --git a/cms/djangoapps/contentstore/rest_api/v0/views/tabs.py b/cms/djangoapps/contentstore/rest_api/v0/views/tabs.py index 968af2246aa3..a17915c42700 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/views/tabs.py +++ b/cms/djangoapps/contentstore/rest_api/v0/views/tabs.py @@ -7,13 +7,14 @@ from rest_framework.request import Request from rest_framework.response import Response from rest_framework.views import APIView -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.exceptions import ItemNotFoundError from common.djangoapps.student.auth import has_studio_read_access, has_studio_write_access from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, verify_course_exists, view_auth_classes -from ..serializers import CourseTabSerializer, CourseTabUpdateSerializer, TabIDLocatorSerializer +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.exceptions import ItemNotFoundError + from ....views.tabs import edit_tab_handler, get_course_tabs, reorder_tabs_handler +from ..serializers import CourseTabSerializer, CourseTabUpdateSerializer, TabIDLocatorSerializer @view_auth_classes(is_authenticated=True) diff --git a/cms/djangoapps/contentstore/rest_api/v0/views/transcripts.py b/cms/djangoapps/contentstore/rest_api/v0/views/transcripts.py index 3344fdbd1f43..11c33d7e5a81 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/views/transcripts.py +++ b/cms/djangoapps/contentstore/rest_api/v0/views/transcripts.py @@ -2,28 +2,24 @@ Public rest API endpoints for the CMS API video assets. """ import logging -from rest_framework.generics import ( - CreateAPIView, - RetrieveAPIView, - DestroyAPIView -) -from django.views.decorators.csrf import csrf_exempt -from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes -from common.djangoapps.util.json_request import expect_json_in_class_view +from django.views.decorators.csrf import csrf_exempt +from rest_framework.generics import CreateAPIView, DestroyAPIView, RetrieveAPIView +from rest_framework.parsers import FormParser, MultiPartParser from cms.djangoapps.contentstore.api import course_author_access_required -from cms.djangoapps.contentstore.views.transcripts_ajax import check_transcripts, replace_transcripts +from cms.djangoapps.contentstore.rest_api.v0.views.utils import validate_request_with_serializer from cms.djangoapps.contentstore.transcript_storage_handlers import ( - upload_transcript, delete_video_transcript_or_404, handle_transcript_download, + upload_transcript, ) -from ..serializers import TranscriptSerializer, YoutubeTranscriptCheckSerializer, YoutubeTranscriptUploadSerializer -from rest_framework.parsers import (MultiPartParser, FormParser) +from cms.djangoapps.contentstore.views.transcripts_ajax import check_transcripts, replace_transcripts +from common.djangoapps.util.json_request import expect_json_in_class_view from openedx.core.lib.api.parsers import TypedFileUploadParser +from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes -from cms.djangoapps.contentstore.rest_api.v0.views.utils import validate_request_with_serializer +from ..serializers import TranscriptSerializer, YoutubeTranscriptCheckSerializer, YoutubeTranscriptUploadSerializer log = logging.getLogger(__name__) diff --git a/cms/djangoapps/contentstore/rest_api/v0/views/utils.py b/cms/djangoapps/contentstore/rest_api/v0/views/utils.py index 7175b76c7c26..288c8957bae8 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/views/utils.py +++ b/cms/djangoapps/contentstore/rest_api/v0/views/utils.py @@ -2,6 +2,7 @@ Utilities for the REST API views. """ from functools import wraps + from django.http import HttpResponseBadRequest diff --git a/cms/djangoapps/contentstore/rest_api/v0/views/xblock.py b/cms/djangoapps/contentstore/rest_api/v0/views/xblock.py index 8e678ae845e0..79217971bb67 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/views/xblock.py +++ b/cms/djangoapps/contentstore/rest_api/v0/views/xblock.py @@ -2,19 +2,18 @@ Public rest API endpoints for the CMS API. """ import logging -from rest_framework.generics import RetrieveUpdateDestroyAPIView, CreateAPIView -from django.views.decorators.csrf import csrf_exempt -from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes -from common.djangoapps.util.json_request import expect_json_in_class_view +from django.views.decorators.csrf import csrf_exempt +from rest_framework.generics import CreateAPIView, RetrieveUpdateDestroyAPIView from cms.djangoapps.contentstore.api import course_author_access_required from cms.djangoapps.contentstore.xblock_storage_handlers import view_handlers +from common.djangoapps.util.json_request import expect_json_in_class_view +from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes from ..serializers import XblockSerializer from .utils import validate_request_with_serializer - log = logging.getLogger(__name__) handle_xblock = view_handlers.handle_xblock diff --git a/cms/djangoapps/contentstore/rest_api/v1/serializers/__init__.py b/cms/djangoapps/contentstore/rest_api/v1/serializers/__init__.py index f96cb9adeaa8..dab1392d1ef4 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/serializers/__init__.py +++ b/cms/djangoapps/contentstore/rest_api/v1/serializers/__init__.py @@ -9,7 +9,7 @@ from .course_waffle_flags import CourseWaffleFlagsSerializer from .grading import CourseGradingModelSerializer, CourseGradingSerializer from .group_configurations import CourseGroupConfigurationsSerializer -from .home import StudioHomeSerializer, CourseHomeTabSerializer, LibraryTabSerializer +from .home import CourseHomeTabSerializer, LibraryTabSerializer, StudioHomeSerializer from .proctoring import ( LimitedProctoredExamSettingsSerializer, ProctoredExamConfigurationSerializer, @@ -18,7 +18,7 @@ ) from .settings import CourseSettingsSerializer from .textbooks import CourseTextbooksSerializer -from .vertical_block import ContainerHandlerSerializer, ContainerChildrenSerializer +from .vertical_block import ContainerChildrenSerializer, ContainerHandlerSerializer from .videos import ( CourseVideosSerializer, VideoDownloadSerializer, diff --git a/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py b/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py index 5df4804027cb..a12b8922557b 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py @@ -5,10 +5,7 @@ from django.urls import reverse from rest_framework import serializers -from cms.djangoapps.contentstore.helpers import ( - xblock_studio_url, - xblock_type_display_name, -) +from cms.djangoapps.contentstore.helpers import xblock_studio_url, xblock_type_display_name from openedx.core.djangoapps.content_tagging.toggles import is_tagging_feature_disabled diff --git a/cms/djangoapps/contentstore/rest_api/v1/serializers/videos.py b/cms/djangoapps/contentstore/rest_api/v1/serializers/videos.py index bd85fdb77220..11620eb9c353 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/serializers/videos.py +++ b/cms/djangoapps/contentstore/rest_api/v1/serializers/videos.py @@ -2,6 +2,7 @@ API Serializers for videos """ from rest_framework import serializers + from cms.djangoapps.contentstore.rest_api.serializers.common import StrictSerializer diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/__init__.py b/cms/djangoapps/contentstore/rest_api/v1/views/__init__.py index d4fcfd5f2e3f..a7e87082c192 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/__init__.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/__init__.py @@ -15,8 +15,4 @@ from .settings import CourseSettingsView from .textbooks import CourseTextbooksView from .vertical_block import ContainerHandlerView, vertical_container_children_redirect_view -from .videos import ( - CourseVideosView, - VideoDownloadView, - VideoUsageView, -) +from .videos import CourseVideosView, VideoDownloadView, VideoUsageView diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/certificates.py b/cms/djangoapps/contentstore/rest_api/v1/views/certificates.py index 5cb1d2da45d2..43069553a067 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/certificates.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/certificates.py @@ -2,23 +2,16 @@ import edx_api_doc_tools as apidocs from opaque_keys.edx.keys import CourseKey +from openedx_authz.constants.permissions import COURSES_MANAGE_CERTIFICATES from rest_framework.request import Request from rest_framework.response import Response from rest_framework.views import APIView -from openedx_authz.constants.permissions import COURSES_MANAGE_CERTIFICATES - +from cms.djangoapps.contentstore.rest_api.v1.serializers import CourseCertificatesSerializer from cms.djangoapps.contentstore.utils import get_certificates_context -from cms.djangoapps.contentstore.rest_api.v1.serializers import ( - CourseCertificatesSerializer, -) from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission from openedx.core.djangoapps.authz.decorators import user_has_course_permission -from openedx.core.lib.api.view_utils import ( - DeveloperErrorViewMixin, - verify_course_exists, - view_auth_classes, -) +from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, verify_course_exists, view_auth_classes from xmodule.modulestore.django import modulestore diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/course_details.py b/cms/djangoapps/contentstore/rest_api/v1/views/course_details.py index d5ccf3c6165e..ac021f378a43 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/course_details.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/course_details.py @@ -2,18 +2,19 @@ import edx_api_doc_tools as apidocs from django.core.exceptions import ValidationError -from common.djangoapps.util.json_request import JsonResponseBadRequest from opaque_keys.edx.keys import CourseKey from rest_framework.request import Request from rest_framework.response import Response from rest_framework.views import APIView + from common.djangoapps.student.auth import has_studio_read_access +from common.djangoapps.util.json_request import JsonResponseBadRequest from openedx.core.djangoapps.models.course_details import CourseDetails from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, verify_course_exists, view_auth_classes from xmodule.modulestore.django import modulestore -from ..serializers import CourseDetailsSerializer from ....utils import update_course_details +from ..serializers import CourseDetailsSerializer @view_auth_classes(is_authenticated=True) diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/course_index.py b/cms/djangoapps/contentstore/rest_api/v1/views/course_index.py index 42b5b1e9d78d..1dbfc52548ba 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/course_index.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/course_index.py @@ -5,17 +5,14 @@ import edx_api_doc_tools as apidocs from django.conf import settings from opaque_keys.edx.keys import CourseKey +from rest_framework.fields import BooleanField from rest_framework.request import Request from rest_framework.response import Response from rest_framework.views import APIView -from rest_framework.fields import BooleanField from cms.djangoapps.contentstore.config.waffle import CUSTOM_RELATIVE_DATES from cms.djangoapps.contentstore.rest_api.v1.mixins import ContainerHandlerMixin -from cms.djangoapps.contentstore.rest_api.v1.serializers import ( - CourseIndexSerializer, - ContainerChildrenSerializer, -) +from cms.djangoapps.contentstore.rest_api.v1.serializers import ContainerChildrenSerializer, CourseIndexSerializer from cms.djangoapps.contentstore.utils import ( get_course_index_context, get_user_partition_info, diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/course_rerun.py b/cms/djangoapps/contentstore/rest_api/v1/views/course_rerun.py index fe39858c5380..dbec4b0b8441 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/course_rerun.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/course_rerun.py @@ -6,8 +6,8 @@ from rest_framework.response import Response from rest_framework.views import APIView -from cms.djangoapps.contentstore.utils import get_course_rerun_context from cms.djangoapps.contentstore.rest_api.v1.serializers import CourseRerunSerializer +from cms.djangoapps.contentstore.utils import get_course_rerun_context from common.djangoapps.student.roles import GlobalStaff from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, verify_course_exists, view_auth_classes from xmodule.modulestore.django import modulestore diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/grading.py b/cms/djangoapps/contentstore/rest_api/v1/views/grading.py index 054ec4745bd8..a27cfd144a56 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/grading.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/grading.py @@ -3,7 +3,7 @@ import edx_api_doc_tools as apidocs from django.conf import settings from opaque_keys.edx.keys import CourseKey -from openedx_authz.constants.permissions import COURSES_VIEW_GRADING_SETTINGS, COURSES_EDIT_GRADING_SETTINGS +from openedx_authz.constants.permissions import COURSES_EDIT_GRADING_SETTINGS, COURSES_VIEW_GRADING_SETTINGS from rest_framework.request import Request from rest_framework.response import Response from rest_framework.views import APIView @@ -16,8 +16,8 @@ from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, verify_course_exists, view_auth_classes from xmodule.modulestore.django import modulestore -from ..serializers import CourseGradingModelSerializer, CourseGradingSerializer from ....utils import get_course_grading +from ..serializers import CourseGradingModelSerializer, CourseGradingSerializer @view_auth_classes(is_authenticated=True) diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/group_configurations.py b/cms/djangoapps/contentstore/rest_api/v1/views/group_configurations.py index 89f94b04f17b..4de2dd8a16b7 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/group_configurations.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/group_configurations.py @@ -2,22 +2,16 @@ import edx_api_doc_tools as apidocs from opaque_keys.edx.keys import CourseKey +from openedx_authz.constants.permissions import COURSES_MANAGE_GROUP_CONFIGURATIONS from rest_framework.request import Request from rest_framework.response import Response from rest_framework.views import APIView -from openedx_authz.constants.permissions import COURSES_MANAGE_GROUP_CONFIGURATIONS +from cms.djangoapps.contentstore.rest_api.v1.serializers import CourseGroupConfigurationsSerializer from cms.djangoapps.contentstore.utils import get_group_configurations_context -from cms.djangoapps.contentstore.rest_api.v1.serializers import ( - CourseGroupConfigurationsSerializer, -) from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission from openedx.core.djangoapps.authz.decorators import authz_permission_required -from openedx.core.lib.api.view_utils import ( - DeveloperErrorViewMixin, - verify_course_exists, - view_auth_classes, -) +from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, verify_course_exists, view_auth_classes from xmodule.modulestore.django import modulestore diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/help_urls.py b/cms/djangoapps/contentstore/rest_api/v1/views/help_urls.py index 09798485a37f..bb18b227ee9a 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/help_urls.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/help_urls.py @@ -3,6 +3,7 @@ from rest_framework.request import Request from rest_framework.response import Response from rest_framework.views import APIView + from openedx.core.lib.api.view_utils import view_auth_classes from ....utils import get_help_urls diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/proctoring.py b/cms/djangoapps/contentstore/rest_api/v1/views/proctoring.py index 28296513a5e6..106d66566faf 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/proctoring.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/proctoring.py @@ -1,8 +1,8 @@ """ API Views for proctored exam settings and proctoring error """ import copy -from django.conf import settings import edx_api_doc_tools as apidocs +from django.conf import settings from opaque_keys.edx.keys import CourseKey from rest_framework import status from rest_framework.exceptions import NotFound @@ -10,17 +10,18 @@ from rest_framework.response import Response from rest_framework.views import APIView -from cms.djangoapps.contentstore.views.course import get_course_and_check_access from cms.djangoapps.contentstore.utils import get_proctored_exam_settings_url +from cms.djangoapps.contentstore.views.course import get_course_and_check_access from cms.djangoapps.models.settings.course_metadata import CourseMetadata from common.djangoapps.student.auth import check_course_advanced_settings_access -from xmodule.course_block import ( - get_available_providers, - get_requires_escalation_email_providers, -) # lint-amnesty, pylint: disable=wrong-import-order from openedx.core.djangoapps.course_apps.toggles import exams_ida_enabled from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, verify_course_exists, view_auth_classes +from xmodule.course_block import ( # lint-amnesty, pylint: disable=wrong-import-order + get_available_providers, + get_requires_escalation_email_providers, +) from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order + from ..serializers import ( LimitedProctoredExamSettingsSerializer, ProctoredExamConfigurationSerializer, diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/settings.py b/cms/djangoapps/contentstore/rest_api/v1/views/settings.py index fbb05cba4de2..6c74d832dafc 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/settings.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/settings.py @@ -12,8 +12,8 @@ from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, verify_course_exists, view_auth_classes from xmodule.modulestore.django import modulestore -from ..serializers import CourseSettingsSerializer from ....utils import get_course_settings +from ..serializers import CourseSettingsSerializer @view_auth_classes(is_authenticated=True) diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_certificates.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_certificates.py index 719c83dc814f..edf87449ef36 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_certificates.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_certificates.py @@ -2,10 +2,9 @@ Unit tests for the course's certificate. """ from django.urls import reverse +from openedx_authz.constants.roles import COURSE_EDITOR, COURSE_STAFF from rest_framework import status -from openedx_authz.constants.roles import COURSE_STAFF, COURSE_EDITOR - from cms.djangoapps.contentstore.tests.utils import CourseTestCase from cms.djangoapps.contentstore.views.tests.test_certificates import HelperMethods from openedx.core.djangoapps.authz.tests.mixins import CourseAuthoringAuthzTestMixin diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_index.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_index.py index 310d0ba80adc..9ec6434bd96a 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_index.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_index.py @@ -4,9 +4,8 @@ from django.conf import settings from django.test import RequestFactory from django.urls import reverse -from rest_framework import status - from edx_toggles.toggles.testutils import override_waffle_flag +from rest_framework import status from cms.djangoapps.contentstore.config.waffle import CUSTOM_RELATIVE_DATES from cms.djangoapps.contentstore.rest_api.v1.mixins import PermissionAccessMixin diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_rerun.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_rerun.py index e25904ad465f..2c97422d9783 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_rerun.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_rerun.py @@ -4,8 +4,8 @@ from django.urls import reverse from rest_framework import status -from cms.djangoapps.contentstore.tests.utils import CourseTestCase from cms.djangoapps.contentstore.rest_api.v1.mixins import PermissionAccessMixin +from cms.djangoapps.contentstore.tests.utils import CourseTestCase class CourseRerunViewTest(CourseTestCase, PermissionAccessMixin): diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_team.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_team.py index c0abca08196c..967f583f02d1 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_team.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_team.py @@ -5,9 +5,9 @@ from django.urls import reverse from rest_framework import status +from cms.djangoapps.contentstore.tests.utils import CourseTestCase from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole from common.djangoapps.student.tests.factories import UserFactory -from cms.djangoapps.contentstore.tests.utils import CourseTestCase from ...mixins import PermissionAccessMixin diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_group_configurations.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_group_configurations.py index 2e1e0d7405ba..b246e676be5d 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_group_configurations.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_group_configurations.py @@ -2,21 +2,16 @@ Unit tests for the course's setting group configuration. """ from django.urls import reverse +from openedx_authz.constants.roles import COURSE_DATA_RESEARCHER, COURSE_STAFF from rest_framework import status from rest_framework.test import APIClient from cms.djangoapps.contentstore.api.tests.base import BaseCourseViewTest -from cms.djangoapps.contentstore.course_group_config import ( - CONTENT_GROUP_CONFIGURATION_NAME, -) +from cms.djangoapps.contentstore.course_group_config import CONTENT_GROUP_CONFIGURATION_NAME from cms.djangoapps.contentstore.tests.utils import CourseTestCase from common.djangoapps.student.tests.factories import UserFactory -from openedx_authz.constants.roles import COURSE_DATA_RESEARCHER, COURSE_STAFF from openedx.core.djangoapps.authz.tests.mixins import CourseAuthzTestMixin -from xmodule.partitions.partitions import ( - Group, - UserPartition, -) # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.partitions.partitions import Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order from ...mixins import PermissionAccessMixin diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_proctoring.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_proctoring.py index 6cf08fe101e9..527355ddc150 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_proctoring.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_proctoring.py @@ -15,12 +15,10 @@ from cms.djangoapps.contentstore.tests.utils import CourseTestCase from openedx.core import toggles as core_toggles from openedx.core.djangoapps.course_apps.toggles import EXAMS_IDA -from xmodule.modulestore.django import ( - modulestore, -) # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ( +from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order ModuleStoreTestCase, -) # lint-amnesty, pylint: disable=wrong-import-order +) from ...mixins import PermissionAccessMixin diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_vertical_block.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_vertical_block.py index cd1e1a99d074..f9955b7f06af 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_vertical_block.py @@ -5,27 +5,17 @@ from urllib.parse import quote from django.urls import reverse -from rest_framework import status from edx_toggles.toggles.testutils import override_waffle_flag +from rest_framework import status from xblock.validation import ValidationMessage from cms.djangoapps.contentstore.tests.utils import CourseTestCase -from openedx.core.djangoapps.content_tagging.toggles import DISABLE_TAGGING_FEATURE from openedx.core.djangoapps.content_libraries.tests import ContentLibrariesRestApiTest -from xmodule.partitions.partitions import ( - ENROLLMENT_TRACK_PARTITION_ID, - Group, - UserPartition, -) -from xmodule.modulestore.django import ( - modulestore, -) # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import ( - BlockFactory, -) # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore import ( - ModuleStoreEnum, -) # lint-amnesty, pylint: disable=wrong-import-order +from openedx.core.djangoapps.content_tagging.toggles import DISABLE_TAGGING_FEATURE +from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.factories import BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID, Group, UserPartition class BaseXBlockContainer(CourseTestCase, ContentLibrariesRestApiTest): diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_videos.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_videos.py index 1d086cb9fda0..91fe2ab0d7d1 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_videos.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_videos.py @@ -16,9 +16,9 @@ ) from rest_framework import status -from cms.djangoapps.contentstore.video_storage_handlers import get_all_transcript_languages from cms.djangoapps.contentstore.tests.utils import CourseTestCase from cms.djangoapps.contentstore.utils import reverse_course_url +from cms.djangoapps.contentstore.video_storage_handlers import get_all_transcript_languages from ...mixins import PermissionAccessMixin diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/textbooks.py b/cms/djangoapps/contentstore/rest_api/v1/views/textbooks.py index 620b40235b73..78aed5c5f24d 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/textbooks.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/textbooks.py @@ -6,16 +6,10 @@ from rest_framework.response import Response from rest_framework.views import APIView +from cms.djangoapps.contentstore.rest_api.v1.serializers import CourseTextbooksSerializer from cms.djangoapps.contentstore.utils import get_textbooks_context -from cms.djangoapps.contentstore.rest_api.v1.serializers import ( - CourseTextbooksSerializer, -) from common.djangoapps.student.auth import has_studio_read_access -from openedx.core.lib.api.view_utils import ( - DeveloperErrorViewMixin, - verify_course_exists, - view_auth_classes, -) +from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, verify_course_exists, view_auth_classes from xmodule.modulestore.django import modulestore diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py b/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py index 0af99137e9e2..4b178e18f702 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py @@ -10,12 +10,8 @@ from rest_framework.views import APIView from cms.djangoapps.contentstore.rest_api.v1.mixins import ContainerHandlerMixin -from cms.djangoapps.contentstore.rest_api.v1.serializers import ( - ContainerHandlerSerializer, -) -from cms.djangoapps.contentstore.utils import ( - get_container_handler_context, -) +from cms.djangoapps.contentstore.rest_api.v1.serializers import ContainerHandlerSerializer +from cms.djangoapps.contentstore.utils import get_container_handler_context from cms.djangoapps.contentstore.views.component import _get_item_in_course from openedx.core.lib.api.view_utils import view_auth_classes from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/videos.py b/cms/djangoapps/contentstore/rest_api/v1/views/videos.py index c41deec0e5da..08d67b7e33cd 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/videos.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/videos.py @@ -1,29 +1,25 @@ """ Public rest API endpoints for contentstore API video assets (outside authoring API) """ -import edx_api_doc_tools as apidocs import logging + +import edx_api_doc_tools as apidocs from opaque_keys.edx.keys import CourseKey from rest_framework.request import Request from rest_framework.response import Response from rest_framework.views import APIView -from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes, verify_course_exists -from common.djangoapps.student.auth import has_studio_read_access - -from ....utils import get_course_videos_context - -from cms.djangoapps.contentstore.video_storage_handlers import ( - get_video_usage_path, - create_video_zip, -) +import cms.djangoapps.contentstore.toggles as contentstore_toggles from cms.djangoapps.contentstore.rest_api.v1.serializers import ( CourseVideosSerializer, + VideoDownloadSerializer, VideoUsageSerializer, - VideoDownloadSerializer ) -import cms.djangoapps.contentstore.toggles as contentstore_toggles +from cms.djangoapps.contentstore.video_storage_handlers import create_video_zip, get_video_usage_path +from common.djangoapps.student.auth import has_studio_read_access +from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, verify_course_exists, view_auth_classes +from ....utils import get_course_videos_context log = logging.getLogger(__name__) toggles = contentstore_toggles diff --git a/cms/djangoapps/contentstore/rest_api/v2/serializers/__init__.py b/cms/djangoapps/contentstore/rest_api/v2/serializers/__init__.py index 4a48fd6395ea..3db7172bdfb9 100644 --- a/cms/djangoapps/contentstore/rest_api/v2/serializers/__init__.py +++ b/cms/djangoapps/contentstore/rest_api/v2/serializers/__init__.py @@ -3,8 +3,8 @@ from cms.djangoapps.contentstore.rest_api.v2.serializers.downstreams import ( ComponentLinksSerializer, ContainerLinksSerializer, + PublishableEntityLinkSerializer, PublishableEntityLinksSummarySerializer, - PublishableEntityLinkSerializer ) from cms.djangoapps.contentstore.rest_api.v2.serializers.home import CourseHomeTabSerializerV2 diff --git a/cms/djangoapps/contentstore/rest_api/v2/views/downstreams.py b/cms/djangoapps/contentstore/rest_api/v2/views/downstreams.py index 16dc977c8af8..6305fc0a6df2 100644 --- a/cms/djangoapps/contentstore/rest_api/v2/views/downstreams.py +++ b/cms/djangoapps/contentstore/rest_api/v2/views/downstreams.py @@ -81,20 +81,20 @@ """ import logging +from itertools import chain from attrs import asdict as attrs_asdict -from django.db.models import QuerySet from django.contrib.auth.models import User # pylint: disable=imported-auth-user +from django.db.models import QuerySet from edx_rest_framework_extensions.paginators import DefaultPagination from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey, UsageKey -from opaque_keys.edx.locator import LibraryUsageLocatorV2, LibraryContainerLocator, LibraryLocatorV2 -from rest_framework.exceptions import NotFound, ValidationError, PermissionDenied +from opaque_keys.edx.locator import LibraryContainerLocator, LibraryLocatorV2, LibraryUsageLocatorV2 +from rest_framework.exceptions import NotFound, PermissionDenied, ValidationError from rest_framework.fields import BooleanField from rest_framework.request import Request from rest_framework.response import Response from rest_framework.views import APIView -from itertools import chain from xblock.core import XBlock from cms.djangoapps.contentstore.models import ComponentLink, ContainerLink, EntityLinkBase @@ -115,14 +115,11 @@ from cms.lib.xblock.upstream_sync_block import fetch_customizable_fields_from_block from cms.lib.xblock.upstream_sync_container import fetch_customizable_fields_from_container from common.djangoapps.student.auth import has_studio_read_access, has_studio_write_access -from openedx.core.lib.api.view_utils import ( - DeveloperErrorViewMixin, - view_auth_classes, -) from openedx.core.djangoapps.content_libraries import api as lib_api +from openedx.core.djangoapps.video_config.transcripts_utils import clear_transcripts +from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError -from openedx.core.djangoapps.video_config.transcripts_utils import clear_transcripts logger = logging.getLogger(__name__) diff --git a/cms/djangoapps/contentstore/rest_api/v2/views/home.py b/cms/djangoapps/contentstore/rest_api/v2/views/home.py index 9d37684bfd81..404d088b3e3e 100644 --- a/cms/djangoapps/contentstore/rest_api/v2/views/home.py +++ b/cms/djangoapps/contentstore/rest_api/v2/views/home.py @@ -1,16 +1,16 @@ """HomePageCoursesViewV2 APIView for getting content available to the logged in user.""" -import edx_api_doc_tools as apidocs from collections import OrderedDict -from rest_framework.response import Response + +import edx_api_doc_tools as apidocs +from rest_framework.pagination import PageNumberPagination from rest_framework.request import Request +from rest_framework.response import Response from rest_framework.views import APIView -from rest_framework.pagination import PageNumberPagination - -from openedx.core.lib.api.view_utils import view_auth_classes -from cms.djangoapps.contentstore.utils import get_course_context_v2 from cms.djangoapps.contentstore.rest_api.v2.serializers import CourseHomeTabSerializerV2 +from cms.djangoapps.contentstore.utils import get_course_context_v2 +from openedx.core.lib.api.view_utils import view_auth_classes class HomePageCoursesPaginator(PageNumberPagination): diff --git a/cms/djangoapps/contentstore/rest_api/v2/views/tests/test_downstream_sync_integration.py b/cms/djangoapps/contentstore/rest_api/v2/views/tests/test_downstream_sync_integration.py index a65df36fe65d..822fc513ee2b 100644 --- a/cms/djangoapps/contentstore/rest_api/v2/views/tests/test_downstream_sync_integration.py +++ b/cms/djangoapps/contentstore/rest_api/v2/views/tests/test_downstream_sync_integration.py @@ -7,13 +7,13 @@ from xml.etree import ElementTree import ddt -from opaque_keys.edx.keys import UsageKey from freezegun import freeze_time +from opaque_keys.edx.keys import UsageKey -from openedx.core.djangoapps.content_libraries.tests import ContentLibrariesRestApiTest from cms.djangoapps.contentstore.xblock_storage_handlers.xblock_helpers import get_block_key_string +from openedx.core.djangoapps.content_libraries.tests import ContentLibrariesRestApiTest from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, ImmediateOnCommitMixin +from xmodule.modulestore.tests.django_utils import ImmediateOnCommitMixin, ModuleStoreTestCase from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory diff --git a/cms/djangoapps/contentstore/rest_api/v2/views/utils.py b/cms/djangoapps/contentstore/rest_api/v2/views/utils.py index 740608c6ae77..840ba2c0e0b0 100644 --- a/cms/djangoapps/contentstore/rest_api/v2/views/utils.py +++ b/cms/djangoapps/contentstore/rest_api/v2/views/utils.py @@ -1,12 +1,13 @@ """ Common utilities for V2 APIs. """ -from rest_framework.response import Response -from rest_framework.generics import GenericAPIView from rest_framework import permissions -from cms.djangoapps.contentstore.rest_api.v2.serializers.utils import NumericalInputValidationRequestSerializer +from rest_framework.generics import GenericAPIView +from rest_framework.response import Response from xblocks_contrib.problem.capa.inputtypes import preview_numeric_input +from cms.djangoapps.contentstore.rest_api.v2.serializers.utils import NumericalInputValidationRequestSerializer + class NumericalInputValidationView(GenericAPIView): """Class in charge of NumericalInputValidations""" diff --git a/cms/djangoapps/contentstore/signals/handlers.py b/cms/djangoapps/contentstore/signals/handlers.py index e28cbf313acb..64cf1d733bb7 100644 --- a/cms/djangoapps/contentstore/signals/handlers.py +++ b/cms/djangoapps/contentstore/signals/handlers.py @@ -50,9 +50,9 @@ from ..tasks import ( create_or_update_upstream_links, handle_create_xblock_upstream_link, - handle_update_xblock_upstream_link, handle_unlink_upstream_block, handle_unlink_upstream_container, + handle_update_xblock_upstream_link, ) from .signals import GRADING_POLICY_CHANGED @@ -132,7 +132,7 @@ def listen_for_course_publish(sender, course_key, **kwargs): # pylint: disable= from cms.djangoapps.contentstore.tasks import ( update_outline_from_modulestore_task, update_search_index, - update_special_exams_and_publish + update_special_exams_and_publish, ) # DEVELOPER README: probably all tasks here should use transaction.on_commit diff --git a/cms/djangoapps/contentstore/signals/tests/test_handlers.py b/cms/djangoapps/contentstore/signals/tests/test_handlers.py index e70a62508f42..87e57e311dae 100644 --- a/cms/djangoapps/contentstore/signals/tests/test_handlers.py +++ b/cms/djangoapps/contentstore/signals/tests/test_handlers.py @@ -9,8 +9,8 @@ from openedx_events.content_authoring.data import CourseCatalogData, CourseScheduleData import cms.djangoapps.contentstore.signals.handlers as sh -from xmodule.modulestore.edit_info import EditInfoMixin from xmodule.modulestore.django import SignalHandler +from xmodule.modulestore.edit_info import EditInfoMixin from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import SampleCourseFactory diff --git a/cms/djangoapps/contentstore/storage.py b/cms/djangoapps/contentstore/storage.py index 83308ebd86b0..b1e9a37bc761 100644 --- a/cms/djangoapps/contentstore/storage.py +++ b/cms/djangoapps/contentstore/storage.py @@ -4,10 +4,11 @@ from django.conf import settings -from common.djangoapps.util.storage import resolve_storage_backend from storages.backends.s3boto3 import S3Boto3Storage from storages.utils import setting +from common.djangoapps.util.storage import resolve_storage_backend + class ImportExportS3Storage(S3Boto3Storage): # pylint: disable=abstract-method """ diff --git a/cms/djangoapps/contentstore/tasks.py b/cms/djangoapps/contentstore/tasks.py index 983471e1ebef..b8c1220f6d38 100644 --- a/cms/djangoapps/contentstore/tasks.py +++ b/cms/djangoapps/contentstore/tasks.py @@ -29,7 +29,7 @@ set_code_owner_attribute, set_code_owner_attribute_from_module, set_custom_attribute, - set_custom_attributes_for_course_key + set_custom_attributes_for_course_key, ) from olxcleaner.exceptions import ErrorLevel from olxcleaner.reporting import report_error_summary, report_errors @@ -50,7 +50,7 @@ from cms.djangoapps.contentstore.courseware_index import ( CoursewareSearchIndexer, LibrarySearchIndexer, - SearchIndexingError + SearchIndexingError, ) from cms.djangoapps.contentstore.storage import course_import_export_storage from cms.djangoapps.contentstore.toggles import enable_course_optimizer_check_prev_run_links @@ -63,7 +63,7 @@ get_previous_run_course_key, initialize_permissions, reverse_usage_url, - translation_language + translation_language, ) from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import get_block_info from cms.djangoapps.models.settings.course_metadata import CourseMetadata @@ -94,12 +94,12 @@ from xmodule.tabs import StaticTab from xmodule.util.keys import BlockKey +from .api import get_ready_to_migrate_legacy_library_content_blocks from .models import ComponentLink, ContainerLink, LearningContextLinksStatus, LearningContextLinksStatusChoices from .outlines import update_outline_from_modulestore from .outlines_regenerate import CourseOutlineRegenerate from .toggles import bypass_olx_failure_enabled from .utils import course_import_olx_validation_is_enabled -from .api import get_ready_to_migrate_legacy_library_content_blocks User = get_user_model() diff --git a/cms/djangoapps/contentstore/tests/test_bulk_enabledisable_discussions.py b/cms/djangoapps/contentstore/tests/test_bulk_enabledisable_discussions.py index 149a7a53182f..0d394e203460 100644 --- a/cms/djangoapps/contentstore/tests/test_bulk_enabledisable_discussions.py +++ b/cms/djangoapps/contentstore/tests/test_bulk_enabledisable_discussions.py @@ -5,12 +5,12 @@ from django.urls import reverse from opaque_keys.edx.keys import CourseKey -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory from cms.djangoapps.contentstore.tests.utils import AjaxEnabledTestClient from common.djangoapps.student.tests.factories import UserFactory +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory class BulkEnableDisableDiscussionsTestCase(ModuleStoreTestCase): diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 431a155d20a9..da48930bc49a 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -21,7 +21,7 @@ from django.test import TestCase from django.test.utils import override_settings from django.urls import reverse -from edx_toggles.toggles.testutils import override_waffle_switch, override_waffle_flag +from edx_toggles.toggles.testutils import override_waffle_flag, override_waffle_switch from edxval.api import create_video, get_videos_for_course from fs.osfs import OSFS from lxml import etree @@ -29,6 +29,19 @@ from opaque_keys.edx.keys import AssetKey, CourseKey, UsageKey from opaque_keys.edx.locations import CourseLocator from path import Path as path + +from cms.djangoapps.contentstore import toggles +from cms.djangoapps.contentstore.config import waffle +from cms.djangoapps.contentstore.tests.utils import AjaxEnabledTestClient, CourseTestCase, get_url, parse_json +from cms.djangoapps.contentstore.utils import delete_course, reverse_course_url, reverse_url +from cms.djangoapps.contentstore.views.component import ADVANCED_COMPONENT_TYPES +from common.djangoapps.course_action_state.managers import CourseActionStateItemNotFoundError +from common.djangoapps.course_action_state.models import CourseRerunState, CourseRerunUIStateManager +from common.djangoapps.student import auth +from common.djangoapps.student.models import CourseEnrollment +from common.djangoapps.student.roles import CourseCreatorRole, CourseInstructorRole +from openedx.core.djangoapps.django_comment_common.utils import are_permissions_roles_seeded +from openedx.core.lib.tempdir import mkdtemp_clean from xmodule.capa_block import ProblemBlock from xmodule.contentstore.content import StaticContent from xmodule.contentstore.django import contentstore @@ -41,29 +54,12 @@ from xmodule.modulestore.inheritance import own_metadata from xmodule.modulestore.split_mongo import BlockKey from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory, check_mongo_calls +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory, check_mongo_calls from xmodule.modulestore.xml_exporter import export_course_to_xml from xmodule.modulestore.xml_importer import import_course_from_xml, perform_xlint from xmodule.seq_block import SequenceBlock from xmodule.video_block import VideoBlock -from cms.djangoapps.contentstore import toggles -from cms.djangoapps.contentstore.config import waffle -from cms.djangoapps.contentstore.tests.utils import AjaxEnabledTestClient, CourseTestCase, get_url, parse_json -from cms.djangoapps.contentstore.utils import ( - delete_course, - reverse_course_url, - reverse_url, -) -from cms.djangoapps.contentstore.views.component import ADVANCED_COMPONENT_TYPES -from common.djangoapps.course_action_state.managers import CourseActionStateItemNotFoundError -from common.djangoapps.course_action_state.models import CourseRerunState, CourseRerunUIStateManager -from common.djangoapps.student import auth -from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.roles import CourseCreatorRole, CourseInstructorRole -from openedx.core.djangoapps.django_comment_common.utils import are_permissions_roles_seeded -from openedx.core.lib.tempdir import mkdtemp_clean - TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex diff --git a/cms/djangoapps/contentstore/tests/test_course_create_rerun.py b/cms/djangoapps/contentstore/tests/test_course_create_rerun.py index a03e8e9cd2f5..b1c484b7f262 100644 --- a/cms/djangoapps/contentstore/tests/test_course_create_rerun.py +++ b/cms/djangoapps/contentstore/tests/test_course_create_rerun.py @@ -17,17 +17,17 @@ from organizations.api import add_organization, get_course_organizations, get_organization_by_short_name from organizations.exceptions import InvalidOrganizationException from organizations.models import Organization -from xmodule.course_block import CourseFields -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from cms.djangoapps.contentstore.tests.utils import AjaxEnabledTestClient, parse_json +from cms.djangoapps.contentstore.views.course import get_allowed_organizations, user_can_create_organizations from cms.djangoapps.course_creators.admin import CourseCreatorAdmin from cms.djangoapps.course_creators.models import CourseCreator -from cms.djangoapps.contentstore.views.course import get_allowed_organizations, user_can_create_organizations from common.djangoapps.student.auth import update_org_role from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole, OrgContentCreatorRole from common.djangoapps.student.tests.factories import AdminFactory, UserFactory +from xmodule.course_block import CourseFields +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory def mock_render_to_string(template_name, context): diff --git a/cms/djangoapps/contentstore/tests/test_course_listing.py b/cms/djangoapps/contentstore/tests/test_course_listing.py index d2fc51411482..304df7962cb9 100644 --- a/cms/djangoapps/contentstore/tests/test_course_listing.py +++ b/cms/djangoapps/contentstore/tests/test_course_listing.py @@ -18,7 +18,7 @@ _accessible_courses_iter_for_tests, _accessible_courses_list_from_groups, _accessible_courses_summary_iter, - get_courses_accessible_to_user + get_courses_accessible_to_user, ) from common.djangoapps.course_action_state.models import CourseRerunState from common.djangoapps.student.models.user import CourseAccessRole @@ -29,7 +29,7 @@ GlobalStaff, OrgInstructorRole, OrgStaffRole, - UserBasedRole + UserBasedRole, ) from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.content.course_overviews.models import CourseOverview @@ -37,7 +37,9 @@ from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES from openedx.core.djangolib.testing.utils import AUTHZ_TABLES from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order TOTAL_COURSES_COUNT = 10 diff --git a/cms/djangoapps/contentstore/tests/test_course_settings.py b/cms/djangoapps/contentstore/tests/test_course_settings.py index 876bb37ee783..770a44c01a75 100644 --- a/cms/djangoapps/contentstore/tests/test_course_settings.py +++ b/cms/djangoapps/contentstore/tests/test_course_settings.py @@ -34,7 +34,7 @@ from cms.djangoapps.models.settings.course_grading import ( GRADING_POLICY_CHANGED_EVENT_TYPE, CourseGradingModel, - hash_grading_policy + hash_grading_policy, ) from cms.djangoapps.models.settings.course_metadata import CourseMetadata from cms.djangoapps.models.settings.encoder import CourseSettingsEncoder @@ -46,7 +46,7 @@ from common.djangoapps.xblock_django.models import XBlockStudioConfigurationFlag from openedx.core.djangoapps.discussions.config.waffle import ( ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND, - OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG + OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG, ) from openedx.core.djangoapps.models.course_details import CourseDetails from openedx.core.lib.teams_config import TeamsConfig diff --git a/cms/djangoapps/contentstore/tests/test_courseware_index.py b/cms/djangoapps/contentstore/tests/test_courseware_index.py index 3ab3fa373f81..ee7bc4e49afb 100644 --- a/cms/djangoapps/contentstore/tests/test_courseware_index.py +++ b/cms/djangoapps/contentstore/tests/test_courseware_index.py @@ -5,7 +5,7 @@ import time from datetime import datetime from unittest import skip -from unittest.mock import patch, Mock +from unittest.mock import Mock, patch import ddt import pytest @@ -18,7 +18,7 @@ CourseAboutSearchIndexer, CoursewareSearchIndexer, LibrarySearchIndexer, - SearchIndexingError + SearchIndexingError, ) from cms.djangoapps.contentstore.signals.handlers import listen_for_course_publish, listen_for_library_update from cms.djangoapps.contentstore.tasks import update_search_index @@ -31,11 +31,15 @@ from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import SignalHandler, modulestore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order - ModuleStoreTestCase, TEST_DATA_SPLIT_MODULESTORE, + ModuleStoreTestCase, SharedModuleStoreTestCase, ) -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory, LibraryFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, + LibraryFactory, +) from xmodule.partitions.partitions import UserPartition # lint-amnesty, pylint: disable=wrong-import-order COURSE_CHILD_STRUCTURE = { diff --git a/cms/djangoapps/contentstore/tests/test_exams.py b/cms/djangoapps/contentstore/tests/test_exams.py index 823038957714..1e3ad0657d78 100644 --- a/cms/djangoapps/contentstore/tests/test_exams.py +++ b/cms/djangoapps/contentstore/tests/test_exams.py @@ -3,7 +3,7 @@ """ import itertools from datetime import datetime, timedelta, timezone -from unittest.mock import patch, Mock +from unittest.mock import Mock, patch import ddt from django.conf import settings @@ -14,7 +14,7 @@ from cms.djangoapps.contentstore.signals.handlers import listen_for_course_publish from openedx.core.djangoapps.course_apps.toggles import EXAMS_IDA from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory @ddt.ddt diff --git a/cms/djangoapps/contentstore/tests/test_filters.py b/cms/djangoapps/contentstore/tests/test_filters.py index 4011ae728b34..b6deb542f814 100644 --- a/cms/djangoapps/contentstore/tests/test_filters.py +++ b/cms/djangoapps/contentstore/tests/test_filters.py @@ -4,12 +4,12 @@ from datetime import datetime from urllib.parse import urljoin -from pytz import UTC - from django.test import override_settings -from cms.djangoapps.contentstore import asset_storage_handlers from opaque_keys.edx.locator import CourseLocator from openedx_filters import PipelineStep +from pytz import UTC + +from cms.djangoapps.contentstore import asset_storage_handlers from xmodule.contentstore.content import StaticContent from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase diff --git a/cms/djangoapps/contentstore/tests/test_gating.py b/cms/djangoapps/contentstore/tests/test_gating.py index 91d2395bfde4..44ac699b8504 100644 --- a/cms/djangoapps/contentstore/tests/test_gating.py +++ b/cms/djangoapps/contentstore/tests/test_gating.py @@ -9,8 +9,13 @@ from cms.djangoapps.contentstore.signals.handlers import handle_item_deleted from openedx.core.lib.gating import api as gating_api -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) class TestHandleItemDeleted(ModuleStoreTestCase, MilestonesTestCaseMixin): diff --git a/cms/djangoapps/contentstore/tests/test_i18n.py b/cms/djangoapps/contentstore/tests/test_i18n.py index 3ee991493196..0db5a03aa9a7 100644 --- a/cms/djangoapps/contentstore/tests/test_i18n.py +++ b/cms/djangoapps/contentstore/tests/test_i18n.py @@ -5,16 +5,15 @@ from unittest import mock from django.utils import translation - from django.utils.translation import get_language from xblock.core import XBlock + +from cms.djangoapps.contentstore.views.preview import _prepare_runtime_for_preview from xmodule.modulestore.django import XBlockI18nService from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory from xmodule.tests.test_export import PureXBlock -from cms.djangoapps.contentstore.views.preview import _prepare_runtime_for_preview - class FakeTranslations(XBlockI18nService): """A test GNUTranslations class that takes a map of msg -> translations.""" diff --git a/cms/djangoapps/contentstore/tests/test_import.py b/cms/djangoapps/contentstore/tests/test_import.py index dbcef8e79ba7..ff5f4f39603a 100644 --- a/cms/djangoapps/contentstore/tests/test_import.py +++ b/cms/djangoapps/contentstore/tests/test_import.py @@ -11,10 +11,12 @@ import ddt from django.conf import settings +from django.core.files.storage import storages from django.test.client import Client from django.test.utils import override_settings -from django.core.files.storage import storages +from storages.backends.s3boto3 import S3Boto3Storage +from common.djangoapps.util.storage import resolve_storage_backend from xmodule.contentstore.django import contentstore from xmodule.exceptions import NotFoundError from xmodule.modulestore import ModuleStoreEnum @@ -22,9 +24,6 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.xml_importer import import_course_from_xml -from common.djangoapps.util.storage import resolve_storage_backend -from storages.backends.s3boto3 import S3Boto3Storage - TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex diff --git a/cms/djangoapps/contentstore/tests/test_libraries.py b/cms/djangoapps/contentstore/tests/test_libraries.py index 376ba56d8dd9..5b20b2c254c9 100644 --- a/cms/djangoapps/contentstore/tests/test_libraries.py +++ b/cms/djangoapps/contentstore/tests/test_libraries.py @@ -8,15 +8,9 @@ import ddt from django.test.utils import override_settings from opaque_keys.edx.locator import CourseKey, LibraryLocator -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_MODULESTORE, ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory -from xmodule.x_module import STUDIO_VIEW from cms.djangoapps.contentstore.tests.utils import AjaxEnabledTestClient, parse_json -from cms.djangoapps.contentstore.utils import reverse_library_url, reverse_url, \ - reverse_usage_url, duplicate_block +from cms.djangoapps.contentstore.utils import duplicate_block, reverse_library_url, reverse_url, reverse_usage_url from cms.djangoapps.contentstore.views.preview import _load_preview_block from cms.djangoapps.contentstore.views.tests.test_library import LIBRARY_REST_URL from cms.djangoapps.course_creators.views import add_user_with_status_granted @@ -28,10 +22,15 @@ LibraryUserRole, OrgInstructorRole, OrgLibraryUserRole, - OrgStaffRole + OrgStaffRole, ) from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.xblock_django.user_service import DjangoXBlockUserService +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory +from xmodule.x_module import STUDIO_VIEW class LibraryTestCase(ModuleStoreTestCase): diff --git a/cms/djangoapps/contentstore/tests/test_orphan.py b/cms/djangoapps/contentstore/tests/test_orphan.py index 244eecebf9af..63bf0e012997 100644 --- a/cms/djangoapps/contentstore/tests/test_orphan.py +++ b/cms/djangoapps/contentstore/tests/test_orphan.py @@ -12,7 +12,10 @@ from common.djangoapps.student.models import CourseEnrollment from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.search import path_to_location # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls_range # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + CourseFactory, + check_mongo_calls_range, +) class TestOrphanBase(CourseTestCase): diff --git a/cms/djangoapps/contentstore/tests/test_outlines.py b/cms/djangoapps/contentstore/tests/test_outlines.py index 108edd82df43..6586c9b84eee 100644 --- a/cms/djangoapps/contentstore/tests/test_outlines.py +++ b/cms/djangoapps/contentstore/tests/test_outlines.py @@ -9,8 +9,13 @@ from openedx.core.djangoapps.content.learning_sequences.api import get_course_outline from openedx.core.djangoapps.content.learning_sequences.data import CourseOutlineData, ExamData, VisibilityData from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) from ..outlines import get_outline_from_modulestore diff --git a/cms/djangoapps/contentstore/tests/test_permissions.py b/cms/djangoapps/contentstore/tests/test_permissions.py index d8fad571658d..a811dc31e995 100644 --- a/cms/djangoapps/contentstore/tests/test_permissions.py +++ b/cms/djangoapps/contentstore/tests/test_permissions.py @@ -12,7 +12,9 @@ from common.djangoapps.student import auth from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole, OrgInstructorRole, OrgStaffRole from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) class TestCourseAccess(ModuleStoreTestCase): diff --git a/cms/djangoapps/contentstore/tests/test_proctoring.py b/cms/djangoapps/contentstore/tests/test_proctoring.py index d9b83a811ef0..aa3d46bfd553 100644 --- a/cms/djangoapps/contentstore/tests/test_proctoring.py +++ b/cms/djangoapps/contentstore/tests/test_proctoring.py @@ -4,18 +4,18 @@ from datetime import datetime, timedelta -from unittest.mock import patch, Mock +from unittest.mock import Mock, patch import ddt from django.conf import settings from edx_proctoring.api import get_all_exams_for_course, get_review_policy_by_exam_id from pytz import UTC -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory from cms.djangoapps.contentstore.signals.handlers import listen_for_course_publish from common.djangoapps.student.tests.factories import UserFactory +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory @ddt.ddt diff --git a/cms/djangoapps/contentstore/tests/test_signals.py b/cms/djangoapps/contentstore/tests/test_signals.py index de66134a440f..8e9a0a915ed2 100644 --- a/cms/djangoapps/contentstore/tests/test_signals.py +++ b/cms/djangoapps/contentstore/tests/test_signals.py @@ -8,7 +8,9 @@ from cms.djangoapps.contentstore.signals.handlers import GRADING_POLICY_COUNTDOWN_SECONDS, handle_grading_policy_changed from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/cms/djangoapps/contentstore/tests/test_tasks.py b/cms/djangoapps/contentstore/tests/test_tasks.py index 5a76b7d67fe7..fc144e1222e2 100644 --- a/cms/djangoapps/contentstore/tests/test_tasks.py +++ b/cms/djangoapps/contentstore/tests/test_tasks.py @@ -5,11 +5,11 @@ import json import logging from unittest import mock -from unittest.mock import AsyncMock, patch, MagicMock +from unittest.mock import AsyncMock, MagicMock, patch from uuid import uuid4 -from celery import Task import pytest +from celery import Task from django.conf import settings from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.test.utils import override_settings @@ -29,19 +29,23 @@ from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) + from ..tasks import ( LinkState, - export_olx, - update_special_exams_and_publish, - rerun_course, - _validate_urls_access_in_batches, - _filter_by_status, _check_broken_links, + _convert_to_standard_url, + _filter_by_status, _is_studio_url, _scan_course_for_links, - _convert_to_standard_url, - extract_content_URLs_from_course + _validate_urls_access_in_batches, + export_olx, + extract_content_URLs_from_course, + rerun_course, + update_special_exams_and_publish, ) logging = logging.getLogger(__name__) diff --git a/cms/djangoapps/contentstore/tests/test_transcripts_utils.py b/cms/djangoapps/contentstore/tests/test_transcripts_utils.py index 9163ff1ffc75..16587ac798bd 100644 --- a/cms/djangoapps/contentstore/tests/test_transcripts_utils.py +++ b/cms/djangoapps/contentstore/tests/test_transcripts_utils.py @@ -1,12 +1,12 @@ """ Tests for transcripts_utils. """ -from contextlib import contextmanager import copy import json import re import tempfile import textwrap import unittest +from contextlib import contextmanager from unittest.mock import patch from uuid import uuid4 @@ -15,16 +15,21 @@ from django.conf import settings from django.test.utils import override_settings from django.utils import translation +from xblocks_contrib.video.exceptions import TranscriptsGenerationException from cms.djangoapps.contentstore.tests.utils import setup_caption_responses from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.video_config import transcripts_utils # lint-amnesty, pylint: disable=wrong-import-order from xmodule.contentstore.content import StaticContent # lint-amnesty, pylint: disable=wrong-import-order from xmodule.contentstore.django import contentstore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.exceptions import NotFoundError # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order -from openedx.core.djangoapps.video_config import transcripts_utils # lint-amnesty, pylint: disable=wrong-import-order -from xblocks_contrib.video.exceptions import TranscriptsGenerationException +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex diff --git a/cms/djangoapps/contentstore/tests/test_upstream_downstream_links.py b/cms/djangoapps/contentstore/tests/test_upstream_downstream_links.py index 5c3ba8386480..594036dbd23f 100644 --- a/cms/djangoapps/contentstore/tests/test_upstream_downstream_links.py +++ b/cms/djangoapps/contentstore/tests/test_upstream_downstream_links.py @@ -14,10 +14,10 @@ from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangolib.testing.utils import skip_unless_cms -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, ImmediateOnCommitMixin +from xmodule.modulestore.tests.django_utils import ImmediateOnCommitMixin, ModuleStoreTestCase from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory -from ..models import ContainerLink, LearningContextLinksStatus, LearningContextLinksStatusChoices, ComponentLink +from ..models import ComponentLink, ContainerLink, LearningContextLinksStatus, LearningContextLinksStatusChoices class BaseUpstreamLinksHelpers(TestCase): diff --git a/cms/djangoapps/contentstore/tests/test_users_default_role.py b/cms/djangoapps/contentstore/tests/test_users_default_role.py index 1abf0a0ec697..3ceb6ddca3d1 100644 --- a/cms/djangoapps/contentstore/tests/test_users_default_role.py +++ b/cms/djangoapps/contentstore/tests/test_users_default_role.py @@ -5,12 +5,11 @@ from unittest import skip -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase - from cms.djangoapps.contentstore.tests.utils import AjaxEnabledTestClient from cms.djangoapps.contentstore.utils import delete_course, reverse_url from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase class TestUsersDefaultRole(ModuleStoreTestCase): diff --git a/cms/djangoapps/contentstore/tests/test_utils.py b/cms/djangoapps/contentstore/tests/test_utils.py index 48e0c425cec7..aab36e3c4b6e 100644 --- a/cms/djangoapps/contentstore/tests/test_utils.py +++ b/cms/djangoapps/contentstore/tests/test_utils.py @@ -32,10 +32,7 @@ ModuleStoreTestCase, SharedModuleStoreTestCase, ) -from xmodule.modulestore.tests.factories import ( - BlockFactory, - CourseFactory, -) +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory from xmodule.partitions.partitions import Group, UserPartition diff --git a/cms/djangoapps/contentstore/tests/test_video_utils.py b/cms/djangoapps/contentstore/tests/test_video_utils.py index e65e4f6638c6..5059a399b80c 100644 --- a/cms/djangoapps/contentstore/tests/test_video_utils.py +++ b/cms/djangoapps/contentstore/tests/test_video_utils.py @@ -4,8 +4,7 @@ from datetime import datetime -from unittest import TestCase -from unittest import mock +from unittest import TestCase, mock import ddt import pytz @@ -23,7 +22,7 @@ YOUTUBE_THUMBNAIL_SIZES, download_youtube_video_thumbnail, scrape_youtube_thumbnail, - validate_video_image + validate_video_image, ) from openedx.core.djangoapps.profile_images.tests.helpers import make_image_file diff --git a/cms/djangoapps/contentstore/tests/tests.py b/cms/djangoapps/contentstore/tests/tests.py index d151b1d58526..6a7a1a2779a5 100644 --- a/cms/djangoapps/contentstore/tests/tests.py +++ b/cms/djangoapps/contentstore/tests/tests.py @@ -25,7 +25,9 @@ from cms.djangoapps.contentstore.tests.test_course_settings import CourseTestCase from cms.djangoapps.contentstore.tests.utils import AjaxEnabledTestClient, parse_json, registration, user from cms.djangoapps.contentstore.utils import get_studio_home_url -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/cms/djangoapps/contentstore/tests/utils.py b/cms/djangoapps/contentstore/tests/utils.py index 42f57563c292..0b117f1dfa24 100644 --- a/cms/djangoapps/contentstore/tests/utils.py +++ b/cms/djangoapps/contentstore/tests/utils.py @@ -9,17 +9,16 @@ from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.test.client import Client from opaque_keys.edx.keys import AssetKey + +from cms.djangoapps.contentstore.utils import reverse_url +from common.djangoapps.student.models import Registration +from openedx.core.djangoapps.video_config.tests.test_transcripts_utils import YoutubeVideoHTMLResponse from xmodule.contentstore.django import contentstore from xmodule.modulestore.inheritance import own_metadata from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.utils import ProceduralCourseTestMixin -from openedx.core.djangoapps.video_config.tests.test_transcripts_utils import YoutubeVideoHTMLResponse - -from cms.djangoapps.contentstore.utils import reverse_url -from common.djangoapps.student.models import Registration - TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT diff --git a/cms/djangoapps/contentstore/toggles.py b/cms/djangoapps/contentstore/toggles.py index 7aadfe64e94d..0b5729f9cb49 100644 --- a/cms/djangoapps/contentstore/toggles.py +++ b/cms/djangoapps/contentstore/toggles.py @@ -2,10 +2,10 @@ CMS feature toggles. """ from edx_toggles.toggles import SettingToggle, WaffleFlag + from openedx.core.djangoapps.content.search import api as search_api from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag - # .. toggle_name: ENABLE_EXPORT_GIT # .. toggle_implementation: SettingToggle # .. toggle_default: False diff --git a/cms/djangoapps/contentstore/transcript_storage_handlers.py b/cms/djangoapps/contentstore/transcript_storage_handlers.py index 2c254eb359b3..293475232c95 100644 --- a/cms/djangoapps/contentstore/transcript_storage_handlers.py +++ b/cms/djangoapps/contentstore/transcript_storage_handlers.py @@ -11,20 +11,22 @@ from django.utils.translation import gettext as _ from edxval.api import ( create_or_update_video_transcript, - delete_video_transcript as delete_video_transcript_source_function, get_3rd_party_transcription_plans, get_available_transcript_languages, + get_video_transcript, get_video_transcript_data, update_transcript_credentials_state_for_org, - get_video_transcript ) +from edxval.api import delete_video_transcript as delete_video_transcript_source_function from opaque_keys.edx.keys import CourseKey +from xblocks_contrib.video.exceptions import TranscriptsGenerationException from common.djangoapps.util.json_request import JsonResponse from openedx.core.djangoapps.video_config.models import VideoTranscriptEnabledFlag +from openedx.core.djangoapps.video_config.transcripts_utils import ( + Transcript, # lint-amnesty, pylint: disable=wrong-import-order +) from openedx.core.djangoapps.video_pipeline.api import update_3rd_party_transcription_service_credentials -from openedx.core.djangoapps.video_config.transcripts_utils import Transcript # lint-amnesty, pylint: disable=wrong-import-order -from xblocks_contrib.video.exceptions import TranscriptsGenerationException from .toggles import use_mock_video_uploads from .video_storage_handlers import TranscriptProvider diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index ce4eee624091..0dd56a1272a0 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -27,7 +27,6 @@ from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey, UsageKey, UsageKeyV2 from opaque_keys.edx.locator import BlockUsageLocator, LibraryContainerLocator, LibraryLocator -from openedx.core.djangoapps.video_config.services import VideoConfigService from openedx_events.content_authoring.data import DuplicatedXBlockData from openedx_events.content_authoring.signals import XBLOCK_DUPLICATED from openedx_events.learning.data import CourseNotificationData @@ -63,11 +62,7 @@ from common.djangoapps.student import auth from common.djangoapps.student.auth import STUDIO_EDIT_ROLES, has_studio_read_access, has_studio_write_access from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.roles import ( - CourseInstructorRole, - CourseStaffRole, - GlobalStaff, -) +from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole, GlobalStaff from common.djangoapps.track import contexts from common.djangoapps.util.course import get_link_for_about_page from common.djangoapps.util.date_utils import get_default_time_display @@ -93,6 +88,7 @@ from openedx.core.djangoapps.models.course_details import CourseDetails from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.site_configuration.models import SiteConfiguration +from openedx.core.djangoapps.video_config.services import VideoConfigService from openedx.core.djangoapps.xblock.api import get_component_from_usage_key from openedx.core.lib.courses import course_image_url from openedx.core.lib.html_to_text import html_to_text @@ -1418,7 +1414,7 @@ def get_course_settings(request, course_key, course_block): It is used for both DRF and django views. """ - from .views.course import get_courses_accessible_to_user, _process_courses_list + from .views.course import _process_courses_list, get_courses_accessible_to_user credit_eligibility_enabled = settings.FEATURES.get('ENABLE_CREDIT_ELIGIBILITY', False) upload_asset_url = reverse_course_url('assets_handler', course_key) @@ -1594,12 +1590,8 @@ def get_library_context(request, request_is_json=False): get_allowed_organizations_for_libraries, user_can_create_organizations, ) - from cms.djangoapps.contentstore.views.library import ( - user_can_view_create_library_button, - ) - from openedx.core.djangoapps.content_libraries.api import ( - user_can_create_library, - ) + from cms.djangoapps.contentstore.views.library import user_can_view_create_library_button + from openedx.core.djangoapps.content_libraries.api import user_can_create_library is_migrated: bool | None # None means: do not filter on is_migrated if (is_migrated_param := request.GET.get('is_migrated')) is not None: @@ -1654,10 +1646,7 @@ def get_course_context(request): It is used for both DRF and django views. """ - from cms.djangoapps.contentstore.views.course import ( - get_courses_accessible_to_user, - _process_courses_list, - ) + from cms.djangoapps.contentstore.views.course import _process_courses_list, get_courses_accessible_to_user def format_in_process_course_view(uca): """ @@ -1693,9 +1682,7 @@ def get_course_context_v2(request): # Importing here to avoid circular imports: # ImportError: cannot import name 'reverse_course_url' from partially initialized module # 'cms.djangoapps.contentstore.utils' (most likely due to a circular import) - from cms.djangoapps.contentstore.views.course import ( - get_courses_accessible_to_user, - ) + from cms.djangoapps.contentstore.views.course import get_courses_accessible_to_user def format_in_process_course_view(uca): """ @@ -1732,17 +1719,13 @@ def get_home_context(request, no_course=False): """ from cms.djangoapps.contentstore.views.course import ( + _get_course_creator_status, get_allowed_organizations, get_allowed_organizations_for_libraries, user_can_create_organizations, - _get_course_creator_status, - ) - from cms.djangoapps.contentstore.views.library import ( - user_can_view_create_library_button, - ) - from openedx.core.djangoapps.content_libraries.api import ( - user_can_create_library, ) + from cms.djangoapps.contentstore.views.library import user_can_view_create_library_button + from openedx.core.djangoapps.content_libraries.api import user_can_create_library active_courses = [] archived_courses = [] @@ -1817,16 +1800,15 @@ def get_course_videos_context(course_block, pagination_conf, course_key=None): get_transcript_credentials_state_for_org, get_transcript_preferences, ) + from openedx.core.djangoapps.video_config.models import VideoTranscriptEnabledFlag from openedx.core.djangoapps.video_config.toggles import use_xpert_translations_component - from openedx.core.djangoapps.video_config.transcripts_utils import Transcript # lint-amnesty, pylint: disable=wrong-import-order - - from .video_storage_handlers import ( - get_all_transcript_languages, - _get_index_videos, - _get_default_video_image_url + from openedx.core.djangoapps.video_config.transcripts_utils import ( + Transcript, # lint-amnesty, pylint: disable=wrong-import-order ) + from .video_storage_handlers import _get_default_video_image_url, _get_index_videos, get_all_transcript_languages + VIDEO_SUPPORTED_FILE_FORMATS = { '.mp4': 'video/mp4', '.mov': 'video/quicktime', @@ -1913,9 +1895,9 @@ def _get_course_index_context(request, course_key, course_block): """ from cms.djangoapps.contentstore.views.course import ( - course_outline_initial_state, _course_outline_json, _deprecated_blocks_info, + course_outline_initial_state, ) from openedx.core.djangoapps.content_staging import api as content_staging_api @@ -1998,13 +1980,13 @@ def get_container_handler_context(request, usage_key, course, xblock): # pylint It is used for both DRF and django views. """ + from cms.djangoapps.contentstore.helpers import get_parent_xblock, is_unit from cms.djangoapps.contentstore.views.component import ( - get_component_templates, - get_unit_tags, CONTAINER_TEMPLATES, LIBRARY_BLOCK_TYPES, + get_component_templates, + get_unit_tags, ) - from cms.djangoapps.contentstore.helpers import get_parent_xblock, is_unit from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import ( add_container_page_publishing_info, create_xblock_info, @@ -2188,11 +2170,12 @@ def get_group_configurations_context(course, store): """ from cms.djangoapps.contentstore.course_group_config import ( - COHORT_SCHEME, ENROLLMENT_SCHEME, GroupConfiguration, RANDOM_SCHEME - ) - from cms.djangoapps.contentstore.views.course import ( - are_content_experiments_enabled + COHORT_SCHEME, + ENROLLMENT_SCHEME, + RANDOM_SCHEME, + GroupConfiguration, ) + from cms.djangoapps.contentstore.views.course import are_content_experiments_enabled from xmodule.partitions.partitions import UserPartition # lint-amnesty, pylint: disable=wrong-import-order course_key = course.id diff --git a/cms/djangoapps/contentstore/video_storage_handlers.py b/cms/djangoapps/contentstore/video_storage_handlers.py index 46215ae90362..b90ae5dd1766 100644 --- a/cms/djangoapps/contentstore/video_storage_handlers.py +++ b/cms/djangoapps/contentstore/video_storage_handlers.py @@ -9,15 +9,17 @@ import json import logging import os -import requests -import shutil import pathlib +import shutil import zipfile -import boto3 - from contextlib import closing from datetime import datetime, timedelta +from tempfile import NamedTemporaryFile, mkdtemp from uuid import uuid4 +from wsgiref.util import FileWrapper + +import boto3 +import requests from django.conf import settings from django.contrib.staticfiles.storage import staticfiles_storage from django.http import FileResponse, HttpResponseNotFound, StreamingHttpResponse @@ -32,13 +34,13 @@ create_video, get_3rd_party_transcription_plans, get_available_transcript_languages, - get_video_transcript_url, get_transcript_preferences, + get_video_transcript_url, get_videos_for_course, remove_transcript_preferences, remove_video_for_course, update_video_image, - update_video_status + update_video_status, ) from fs.osfs import OSFS from opaque_keys import InvalidKeyError @@ -47,16 +49,11 @@ from pytz import UTC from rest_framework import status as rest_status from rest_framework.response import Response -from tempfile import NamedTemporaryFile, mkdtemp -from wsgiref.util import FileWrapper from common.djangoapps.util.json_request import JsonResponse from openedx.core.djangoapps.video_config.models import VideoTranscriptEnabledFlag from openedx.core.djangoapps.video_config.toggles import PUBLIC_VIDEO_SHARE -from openedx.core.djangoapps.video_pipeline.config.waffle import ( - DEPRECATE_YOUTUBE, - ENABLE_DEVSTACK_VIDEO_UPLOADS, -) +from openedx.core.djangoapps.video_pipeline.config.waffle import DEPRECATE_YOUTUBE, ENABLE_DEVSTACK_VIDEO_UPLOADS from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order diff --git a/cms/djangoapps/contentstore/views/__init__.py b/cms/djangoapps/contentstore/views/__init__.py index ba87c54d38c0..7c9eec03cdc6 100644 --- a/cms/djangoapps/contentstore/views/__init__.py +++ b/cms/djangoapps/contentstore/views/__init__.py @@ -1,6 +1,7 @@ "All view functions for contentstore, broken out into submodules" from .assets import * +from .block import * from .checklists import * from .component import * from .course import * # lint-amnesty, pylint: disable=redefined-builtin @@ -9,7 +10,6 @@ from .export_git import * from .helpers import * from .import_export import * -from .block import * from .library import * from .preview import * from .public import * diff --git a/cms/djangoapps/contentstore/views/assets.py b/cms/djangoapps/contentstore/views/assets.py index c9ae16a1402c..beb378e8a759 100644 --- a/cms/djangoapps/contentstore/views/assets.py +++ b/cms/djangoapps/contentstore/views/assets.py @@ -3,15 +3,14 @@ from django.contrib.auth.decorators import login_required from django.views.decorators.csrf import ensure_csrf_cookie + +from cms.djangoapps.contentstore.asset_storage_handlers import delete_asset as delete_asset_source_function +from cms.djangoapps.contentstore.asset_storage_handlers import get_asset_json as get_asset_json_source_function +from cms.djangoapps.contentstore.asset_storage_handlers import get_asset_usage_path_json, handle_assets +from cms.djangoapps.contentstore.asset_storage_handlers import get_file_size as get_file_size_source_function +from cms.djangoapps.contentstore.asset_storage_handlers import update_asset as update_asset_source_function from cms.djangoapps.contentstore.asset_storage_handlers import ( - handle_assets, - get_asset_usage_path_json, update_course_run_asset as update_course_run_asset_source_function, - get_file_size as get_file_size_source_function, - delete_asset as delete_asset_source_function, - get_asset_json as get_asset_json_source_function, - update_asset as update_asset_source_function, - ) __all__ = ['assets_handler', 'asset_usage_path_handler'] diff --git a/cms/djangoapps/contentstore/views/block.py b/cms/djangoapps/contentstore/views/block.py index b57042085df2..e606477ee222 100644 --- a/cms/djangoapps/contentstore/views/block.py +++ b/cms/djangoapps/contentstore/views/block.py @@ -15,51 +15,32 @@ from web_fragments.fragment import Fragment from cms.djangoapps.contentstore.utils import load_services_for_studio +from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import ( + create_xblock_info, + delete_orphans, + get_block_info, + get_xblock, + handle_xblock, +) +from cms.djangoapps.contentstore.xblock_storage_handlers.xblock_helpers import get_tags_count, usage_key_with_run from cms.lib.xblock.authoring_mixin import VISIBILITY_VIEW from common.djangoapps.edxmako.shortcuts import render_to_response, render_to_string -from common.djangoapps.student.auth import ( - has_studio_read_access, - has_studio_write_access, -) +from common.djangoapps.student.auth import has_studio_read_access, has_studio_write_access from common.djangoapps.util.json_request import JsonResponse, expect_json -from openedx.core.lib.xblock_utils import ( - hash_resource, - request_token, - wrap_xblock, - wrap_xblock_aside, -) -from xmodule.modulestore.django import ( - modulestore, -) # lint-amnesty, pylint: disable=wrong-import-order from openedx.core.djangoapps.content_tagging.toggles import is_tagging_feature_disabled - -from xmodule.x_module import ( +from openedx.core.lib.xblock_utils import hash_resource, request_token, wrap_xblock, wrap_xblock_aside +from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.x_module import ( # lint-amnesty, pylint: disable=wrong-import-order AUTHOR_VIEW, PREVIEW_VIEWS, STUDENT_VIEW, STUDIO_VIEW, -) # lint-amnesty, pylint: disable=wrong-import-order - - -from ..helpers import ( - is_unit, -) -from .preview import get_preview_fragment -from .component import _get_item_in_course -from ..utils import get_container_handler_context - -from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import ( - handle_xblock, - create_xblock_info, - get_block_info, - get_xblock, - delete_orphans, -) -from cms.djangoapps.contentstore.xblock_storage_handlers.xblock_helpers import ( - usage_key_with_run, - get_tags_count, ) +from ..helpers import is_unit +from ..utils import get_container_handler_context +from .component import _get_item_in_course +from .preview import get_preview_fragment __all__ = [ "orphan_handler", diff --git a/cms/djangoapps/contentstore/views/certificate_manager.py b/cms/djangoapps/contentstore/views/certificate_manager.py index 081afdcc0dd7..d0c0d7483174 100644 --- a/cms/djangoapps/contentstore/views/certificate_manager.py +++ b/cms/djangoapps/contentstore/views/certificate_manager.py @@ -6,16 +6,15 @@ from django.conf import settings from django.utils.translation import gettext as _ - -from common.djangoapps.course_modes.models import CourseMode from eventtracking import tracker from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import AssetKey -from .assets import delete_asset +from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.util.db import MYSQL_MAX_INT, generate_int_id from ..exceptions import AssetNotFoundException +from .assets import delete_asset CERTIFICATE_SCHEMA_VERSION = 1 CERTIFICATE_MINIMUM_ID = 100 diff --git a/cms/djangoapps/contentstore/views/certificates.py b/cms/djangoapps/contentstore/views/certificates.py index 50039cf00d08..0d3d1c23eba4 100644 --- a/cms/djangoapps/contentstore/views/certificates.py +++ b/cms/djangoapps/contentstore/views/certificates.py @@ -29,35 +29,29 @@ from django.core.exceptions import PermissionDenied from django.http import HttpResponse from django.shortcuts import redirect -from django.utils.translation import gettext as _ from django.utils.decorators import method_decorator +from django.utils.translation import gettext as _ from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.http import require_http_methods -from rest_framework.views import APIView +from opaque_keys.edx.keys import CourseKey +from rest_framework import status from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response -from rest_framework import status -from opaque_keys.edx.keys import CourseKey +from rest_framework.views import APIView -from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin +from cms.djangoapps.contentstore.views.permissions import HasStudioWriteAccess +from cms.djangoapps.contentstore.views.serializers import CertificateActivationSerializer, CertificateSerializer from common.djangoapps.edxmako.shortcuts import render_to_response from common.djangoapps.student.auth import has_studio_write_access from common.djangoapps.student.roles import GlobalStaff - from common.djangoapps.util.json_request import JsonResponse +from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin from xmodule.modulestore import EdxJSONEncoder # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from cms.djangoapps.contentstore.views.serializers import CertificateActivationSerializer, CertificateSerializer -from cms.djangoapps.contentstore.views.permissions import HasStudioWriteAccess - -from .certificate_manager import CertificateManager, CertificateValidationError from ..toggles import use_new_certificates_page -from ..utils import ( - get_certificates_context, - get_certificates_url, - reverse_course_url, -) +from ..utils import get_certificates_context, get_certificates_url, reverse_course_url +from .certificate_manager import CertificateManager, CertificateValidationError CERTIFICATE_MINIMUM_ID = 100 diff --git a/cms/djangoapps/contentstore/views/component.py b/cms/djangoapps/contentstore/views/component.py index b744142a4e4b..ec24af1a3e7d 100644 --- a/cms/djangoapps/contentstore/views/component.py +++ b/cms/djangoapps/contentstore/views/component.py @@ -21,24 +21,16 @@ from xblock.plugin import PluginMissingError from xblock.runtime import Mixologist +from cms.djangoapps.contentstore.helpers import get_parent_if_split_test, is_library_content, is_unit +from cms.djangoapps.contentstore.toggles import libraries_v1_enabled, libraries_v2_enabled, use_new_unit_page +from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import load_services_for_studio from common.djangoapps.edxmako.shortcuts import render_to_response from common.djangoapps.student.auth import has_course_author_access from common.djangoapps.xblock_django.api import authorable_xblocks, disabled_xblocks from common.djangoapps.xblock_django.models import XBlockStudioConfigurationFlag -from cms.djangoapps.contentstore.helpers import ( - get_parent_if_split_test, - is_unit, - is_library_content, -) -from cms.djangoapps.contentstore.toggles import ( - libraries_v1_enabled, - libraries_v2_enabled, - use_new_unit_page, -) -from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import load_services_for_studio -from openedx.core.lib.xblock_utils import get_aside_from_xblock, is_xblock_aside -from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration from openedx.core.djangoapps.content_tagging.api import get_object_tags +from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration +from openedx.core.lib.xblock_utils import get_aside_from_xblock, is_xblock_aside from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index 2e4d7e27ffde..58dcc773172a 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -14,12 +14,8 @@ from django.conf import settings from django.contrib.auth import get_user_model from django.contrib.auth.decorators import login_required -from django.core.exceptions import ( - FieldError, - ImproperlyConfigured, - PermissionDenied, - ValidationError as DjangoValidationError, -) +from django.core.exceptions import FieldError, ImproperlyConfigured, PermissionDenied +from django.core.exceptions import ValidationError as DjangoValidationError from django.db.models import QuerySet from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseNotFound from django.shortcuts import redirect @@ -27,72 +23,71 @@ from django.utils.translation import gettext as _ from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.http import require_GET, require_http_methods -from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiRequest, OpenApiResponse +from drf_spectacular.utils import OpenApiParameter, OpenApiRequest, OpenApiResponse, extend_schema from edx_django_utils.monitoring import function_trace from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import BlockUsageLocator +from openedx_authz.constants.permissions import ( + COURSES_MANAGE_COURSE_UPDATES, + COURSES_MANAGE_GROUP_CONFIGURATIONS, + COURSES_VIEW_COURSE_UPDATES, +) from organizations.api import add_organization_course, ensure_organization from organizations.exceptions import InvalidOrganizationException -from rest_framework.exceptions import ValidationError +from organizations.models import Organization from rest_framework.decorators import api_view -from openedx.core.lib.api.view_utils import view_auth_classes +from rest_framework.exceptions import ValidationError +from cms.djangoapps.contentstore.api.views.utils import get_bool_param from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import create_xblock_info -from cms.djangoapps.course_creators.views import add_user_with_status_unrequested, get_course_creator_status from cms.djangoapps.course_creators.models import CourseCreator +from cms.djangoapps.course_creators.views import add_user_with_status_unrequested, get_course_creator_status from cms.djangoapps.models.settings.course_grading import CourseGradingModel from cms.djangoapps.models.settings.course_metadata import CourseMetadata from cms.djangoapps.models.settings.encoder import CourseSettingsEncoder from cms.djangoapps.modulestore_migrator.data import ModulestoreMigration -from cms.djangoapps.contentstore.api.views.utils import get_bool_param from common.djangoapps.course_action_state.managers import CourseActionStateItemNotFoundError from common.djangoapps.course_action_state.models import CourseRerunState, CourseRerunUIStateManager from common.djangoapps.edxmako.shortcuts import render_to_response from common.djangoapps.student.auth import ( has_course_author_access, + has_studio_advanced_settings_access, has_studio_read_access, has_studio_write_access, - has_studio_advanced_settings_access, is_content_creator, ) -from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission -from openedx.core.djangoapps.authz.decorators import user_has_course_permission -from openedx_authz.constants.permissions import ( - COURSES_MANAGE_COURSE_UPDATES, - COURSES_VIEW_COURSE_UPDATES, - COURSES_MANAGE_GROUP_CONFIGURATIONS, -) from common.djangoapps.student.roles import ( CourseInstructorRole, CourseStaffRole, GlobalStaff, - UserBasedRole, OrgStaffRole, + UserBasedRole, strict_role_checking, ) from common.djangoapps.util.json_request import JsonResponse, JsonResponseBadRequest, expect_json from common.djangoapps.util.string_utils import _has_non_ascii_characters +from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission +from openedx.core.djangoapps.authz.decorators import user_has_course_permission from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.credit.tasks import update_credit_course_requirements from openedx.core.djangoapps.models.course_details import CourseDetails from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangolib.js_utils import dump_js_escaped_json +from openedx.core.lib.api.view_utils import view_auth_classes from openedx.core.lib.course_tabs import CourseTabPluginManager -from organizations.models import Organization from xmodule.course_block import CourseBlock, CourseFields # lint-amnesty, pylint: disable=wrong-import-order from xmodule.error_block import ErrorBlock # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore import EdxJSONEncoder # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.exceptions import DuplicateCourseError # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.tabs import CourseTab, CourseTabList, InvalidTabsException # lint-amnesty, pylint: disable=wrong-import-order - -from ..course_group_config import ( - COHORT_SCHEME, - RANDOM_SCHEME, - GroupConfiguration, - GroupConfigurationsValidationError +from xmodule.tabs import ( # lint-amnesty, pylint: disable=wrong-import-order + CourseTab, + CourseTabList, + InvalidTabsException, ) + +from ..course_group_config import COHORT_SCHEME, RANDOM_SCHEME, GroupConfiguration, GroupConfigurationsValidationError from ..course_info_model import delete_course_update, get_course_updates, update_course_updates from ..courseware_index import CoursewareSearchIndexer, SearchIndexingError from ..tasks import rerun_course as rerun_course_task @@ -101,7 +96,7 @@ use_new_advanced_settings_page, use_new_grading_page, use_new_group_configurations_page, - use_new_schedule_details_page + use_new_schedule_details_page, ) from ..utils import ( add_instructor, @@ -117,8 +112,8 @@ get_proctored_exam_settings_url, get_schedule_details_url, get_studio_home_url, - get_updates_url, get_textbooks_url, + get_updates_url, initialize_permissions, remove_all_instructors, reverse_course_url, diff --git a/cms/djangoapps/contentstore/views/entrance_exam.py b/cms/djangoapps/contentstore/views/entrance_exam.py index 5d914366bd9e..c3c442ce45d8 100644 --- a/cms/djangoapps/contentstore/views/entrance_exam.py +++ b/cms/djangoapps/contentstore/views/entrance_exam.py @@ -15,6 +15,8 @@ from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey, UsageKey +from cms.djangoapps.contentstore.xblock_storage_handlers.create_xblock import create_xblock +from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import delete_item from cms.djangoapps.models.settings.course_metadata import CourseMetadata from common.djangoapps.student.auth import has_course_author_access from common.djangoapps.util import milestones_helpers @@ -24,8 +26,6 @@ from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order from ..helpers import remove_entrance_exam_graders -from cms.djangoapps.contentstore.xblock_storage_handlers.create_xblock import create_xblock -from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import delete_item __all__ = ['entrance_exam', ] diff --git a/cms/djangoapps/contentstore/views/import_export.py b/cms/djangoapps/contentstore/views/import_export.py index 26d5b790cf52..33f44b4de935 100644 --- a/cms/djangoapps/contentstore/views/import_export.py +++ b/cms/djangoapps/contentstore/views/import_export.py @@ -11,7 +11,6 @@ import re import shutil from wsgiref.util import FileWrapper -from openedx_authz.constants.permissions import COURSES_EXPORT_COURSE, COURSES_IMPORT_COURSE from django.conf import settings from django.contrib.auth.decorators import login_required @@ -28,29 +27,25 @@ from edx_django_utils.monitoring import set_custom_attribute, set_custom_attributes_for_course_key from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import LibraryLocator +from openedx_authz.constants.permissions import COURSES_EXPORT_COURSE, COURSES_IMPORT_COURSE from path import Path as path from storages.backends.s3boto3 import S3Boto3Storage from user_tasks.conf import settings as user_tasks_settings from user_tasks.models import UserTaskArtifact, UserTaskStatus -from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission -from openedx.core.djangoapps.authz.decorators import user_has_course_permission from common.djangoapps.edxmako.shortcuts import render_to_response from common.djangoapps.util.json_request import JsonResponse from common.djangoapps.util.monitoring import monitor_import_failure from common.djangoapps.util.views import ensure_valid_course_key +from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission +from openedx.core.djangoapps.authz.decorators import user_has_course_permission from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from ..storage import course_import_export_storage from ..tasks import CourseExportTask, CourseImportTask, export_olx, import_olx from ..toggles import use_new_export_page, use_new_import_page -from ..utils import ( - reverse_course_url, - reverse_library_url, - get_export_url, - get_import_url, - IMPORTABLE_FILE_TYPES, -) +from ..utils import IMPORTABLE_FILE_TYPES, get_export_url, get_import_url, reverse_course_url, reverse_library_url + __all__ = [ 'import_handler', 'import_status_handler', 'export_handler', 'export_output_handler', 'export_status_handler', diff --git a/cms/djangoapps/contentstore/views/library.py b/cms/djangoapps/contentstore/views/library.py index bcc0ffe84842..6440fb0526cd 100644 --- a/cms/djangoapps/contentstore/views/library.py +++ b/cms/djangoapps/contentstore/views/library.py @@ -19,10 +19,8 @@ from opaque_keys.edx.locator import LibraryLocator, LibraryUsageLocator from organizations.api import ensure_organization from organizations.exceptions import InvalidOrganizationException -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.exceptions import DuplicateCourseError +from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import create_xblock_info from cms.djangoapps.course_creators.views import get_course_creator_status from common.djangoapps.edxmako.shortcuts import render_to_response from common.djangoapps.student.auth import ( @@ -40,11 +38,13 @@ UserBasedRole, ) from common.djangoapps.util.json_request import JsonResponse, JsonResponseBadRequest, expect_json +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.exceptions import DuplicateCourseError -from ..utils import add_instructor, reverse_library_url from ..toggles import libraries_v1_enabled +from ..utils import add_instructor, reverse_library_url from .component import CONTAINER_TEMPLATES, get_component_templates -from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import create_xblock_info from .user import user_with_role __all__ = ['library_handler', 'manage_library_users'] diff --git a/cms/djangoapps/contentstore/views/preview.py b/cms/djangoapps/contentstore/views/preview.py index 6600430a7a89..77de2f4f263f 100644 --- a/cms/djangoapps/contentstore/views/preview.py +++ b/cms/djangoapps/contentstore/views/preview.py @@ -4,8 +4,8 @@ from functools import partial from django.conf import settings -from django.core.cache import cache from django.contrib.auth.decorators import login_required +from django.core.cache import cache from django.http import Http404, HttpResponseBadRequest from django.urls import reverse from django.utils.translation import gettext as _ @@ -18,36 +18,31 @@ from xblock.exceptions import NoSuchHandlerError, NotFoundError, ProcessingError from xblock.runtime import KvsFieldData -from openedx.core.djangoapps.video_config.services import VideoConfigService -from openedx.core.djangoapps.discussions.services import DiscussionConfigService -from xmodule.contentstore.django import contentstore -from xmodule.exceptions import NotFoundError as XModuleNotFoundError -from xmodule.modulestore.django import XBlockI18nService, modulestore -from xmodule.partitions.partitions_service import PartitionService -from xmodule.services import SettingsService, TeamsConfigurationService, XQueueService -from xmodule.studio_editable import has_author_view -from xmodule.util.sandboxing import SandboxService -from xmodule.util.builtin_assets import add_webpack_js_to_fragment -from xmodule.x_module import AUTHOR_VIEW, PREVIEW_VIEWS, STUDENT_VIEW, XModuleMixin -from cms.djangoapps.xblock_config.models import StudioConfig from cms.djangoapps.contentstore.toggles import individualize_anonymous_user_id +from cms.djangoapps.xblock_config.models import StudioConfig from cms.lib.xblock.field_data import CmsFieldData from cms.lib.xblock.upstream_sync import UpstreamLink +from common.djangoapps.edxmako.services import MakoService +from common.djangoapps.edxmako.shortcuts import render_to_string from common.djangoapps.static_replace.services import ReplaceURLService from common.djangoapps.static_replace.wrapper import replace_urls_wrapper from common.djangoapps.student.models import anonymous_id_for_user -from common.djangoapps.edxmako.shortcuts import render_to_string -from common.djangoapps.edxmako.services import MakoService from common.djangoapps.xblock_django.user_service import DjangoXBlockUserService from lms.djangoapps.lms_xblock.field_data import LmsFieldData -from openedx.core.lib.license import wrap_with_license +from openedx.core.djangoapps.discussions.services import DiscussionConfigService +from openedx.core.djangoapps.video_config.services import VideoConfigService from openedx.core.lib.cache_utils import CacheService -from openedx.core.lib.xblock_utils import ( - request_token, - wrap_fragment, - wrap_xblock, - wrap_xblock_aside -) +from openedx.core.lib.license import wrap_with_license +from openedx.core.lib.xblock_utils import request_token, wrap_fragment, wrap_xblock, wrap_xblock_aside +from xmodule.contentstore.django import contentstore +from xmodule.exceptions import NotFoundError as XModuleNotFoundError +from xmodule.modulestore.django import XBlockI18nService, modulestore +from xmodule.partitions.partitions_service import PartitionService +from xmodule.services import SettingsService, TeamsConfigurationService, XQueueService +from xmodule.studio_editable import has_author_view +from xmodule.util.builtin_assets import add_webpack_js_to_fragment +from xmodule.util.sandboxing import SandboxService +from xmodule.x_module import AUTHOR_VIEW, PREVIEW_VIEWS, STUDENT_VIEW, XModuleMixin from ..utils import StudioPermissionsService, get_visibility_partition_info from .access import get_user_role diff --git a/cms/djangoapps/contentstore/views/serializers.py b/cms/djangoapps/contentstore/views/serializers.py index 71608fb0deab..6f49cc95c728 100644 --- a/cms/djangoapps/contentstore/views/serializers.py +++ b/cms/djangoapps/contentstore/views/serializers.py @@ -5,12 +5,13 @@ Add new serializers here as needed for API endpoints in this module. """ -from rest_framework import serializers from django.core.exceptions import PermissionDenied +from rest_framework import serializers from cms.djangoapps.contentstore.views.certificate_manager import ( CERTIFICATE_SCHEMA_VERSION, - CertificateManager, Certificate, + Certificate, + CertificateManager, ) from common.djangoapps.student.roles import GlobalStaff diff --git a/cms/djangoapps/contentstore/views/tabs.py b/cms/djangoapps/contentstore/views/tabs.py index 8fa9d024458d..c4886203630c 100644 --- a/cms/djangoapps/contentstore/views/tabs.py +++ b/cms/djangoapps/contentstore/views/tabs.py @@ -12,14 +12,15 @@ from django.views.decorators.http import require_http_methods from opaque_keys.edx.keys import CourseKey, UsageKey from rest_framework.exceptions import ValidationError + +from common.djangoapps.student.auth import has_course_author_access +from common.djangoapps.util.json_request import JsonResponse, JsonResponseBadRequest, expect_json from xmodule.course_block import CourseBlock from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.tabs import CourseTab, CourseTabList, InvalidTabsException, StaticTab -from common.djangoapps.student.auth import has_course_author_access -from common.djangoapps.util.json_request import JsonResponse, JsonResponseBadRequest, expect_json -from ..utils import get_pages_and_resources_url, get_custom_pages_url +from ..utils import get_custom_pages_url, get_pages_and_resources_url __all__ = ["tabs_handler", "update_tabs_handler"] diff --git a/cms/djangoapps/contentstore/views/tests/test_assets.py b/cms/djangoapps/contentstore/views/tests/test_assets.py index b8abc69cb441..2467e41a9562 100644 --- a/cms/djangoapps/contentstore/views/tests/test_assets.py +++ b/cms/djangoapps/contentstore/views/tests/test_assets.py @@ -14,26 +14,25 @@ from django.test.utils import override_settings from opaque_keys.edx.keys import AssetKey from opaque_keys.edx.locator import CourseLocator -from openedx_authz.constants.roles import COURSE_AUDITOR, COURSE_EDITOR, COURSE_ADMIN -from rest_framework.test import APIClient - +from openedx_authz.constants.roles import COURSE_ADMIN, COURSE_AUDITOR, COURSE_EDITOR from PIL import Image from pytz import UTC +from rest_framework.test import APIClient -from common.djangoapps.student.tests.factories import UserFactory from cms.djangoapps.contentstore.tests.utils import CourseTestCase from cms.djangoapps.contentstore.utils import reverse_course_url from cms.djangoapps.contentstore.views import assets from common.djangoapps.static_replace import replace_static_urls +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.authz.tests.mixins import CourseAuthzTestMixin from xmodule.assetstore import AssetMetadata # lint-amnesty, pylint: disable=wrong-import-order from xmodule.contentstore.content import StaticContent # lint-amnesty, pylint: disable=wrong-import-order from xmodule.contentstore.django import contentstore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.xml_importer import import_course_from_xml # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT diff --git a/cms/djangoapps/contentstore/views/tests/test_block.py b/cms/djangoapps/contentstore/views/tests/test_block.py index 31f5244e2f55..0f425d325ade 100644 --- a/cms/djangoapps/contentstore/views/tests/test_block.py +++ b/cms/djangoapps/contentstore/views/tests/test_block.py @@ -7,23 +7,22 @@ from unittest.mock import Mock, PropertyMock, patch import ddt +from bs4 import BeautifulSoup from django.conf import settings from django.http import Http404 from django.test import TestCase from django.test.client import RequestFactory -from django.urls import reverse from django.test.utils import override_settings -from openedx.core.djangoapps.video_config.toggles import PUBLIC_VIDEO_SHARE -from openedx_events.content_authoring.data import DuplicatedXBlockData -from openedx_events.content_authoring.signals import XBLOCK_DUPLICATED -from openedx_events.tests.utils import OpenEdxEventsTestMixin +from django.urls import reverse from edx_proctoring.exceptions import ProctoredExamNotFoundException from opaque_keys import InvalidKeyError from opaque_keys.edx.asides import AsideUsageKeyV2 from opaque_keys.edx.keys import CourseKey, UsageKey from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator +from openedx_events.content_authoring.data import DuplicatedXBlockData +from openedx_events.content_authoring.signals import XBLOCK_DUPLICATED +from openedx_events.tests.utils import OpenEdxEventsTestMixin from pytz import UTC -from bs4 import BeautifulSoup from web_fragments.fragment import Fragment from webob import Response from xblock.core import XBlockAside @@ -32,37 +31,19 @@ from xblock.runtime import DictKeyValueStore, KvsFieldData from xblock.test.tools import TestRuntime from xblock.validation import ValidationMessage -from xmodule.course_block import DEFAULT_START_DATE -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.exceptions import ItemNotFoundError -from xmodule.modulestore.tests.django_utils import ( - TEST_DATA_SPLIT_MODULESTORE, - ModuleStoreTestCase, -) -from xmodule.modulestore.tests.factories import ( - CourseFactory, - BlockFactory, - LibraryFactory, - check_mongo_calls, -) -from xmodule.partitions.partitions import ( - ENROLLMENT_TRACK_PARTITION_ID, - MINIMUM_UNUSED_PARTITION_ID, - Group, - UserPartition, -) -from xmodule.partitions.tests.test_partitions import MockPartitionService -from xmodule.x_module import STUDENT_VIEW, STUDIO_VIEW from cms.djangoapps.contentstore.tests.utils import CourseTestCase -from cms.djangoapps.contentstore.utils import ( - reverse_course_url, - reverse_usage_url, - duplicate_block, - update_from_source, -) +from cms.djangoapps.contentstore.utils import duplicate_block, reverse_course_url, reverse_usage_url, update_from_source from cms.djangoapps.contentstore.xblock_storage_handlers import view_handlers as item_module +from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import ( + ALWAYS, + VisibilityState, + _get_source_index, + _xblock_type_and_display_name, + add_container_page_publishing_info, + create_xblock_info, + get_block_info, +) from common.djangoapps.student.tests.factories import StaffFactory, UserFactory from common.djangoapps.xblock_django.models import ( XBlockConfiguration, @@ -70,21 +51,27 @@ XBlockStudioConfigurationFlag, ) from common.djangoapps.xblock_django.user_service import DjangoXBlockUserService +from common.test.utils import assert_dict_contains_subset from lms.djangoapps.lms_xblock.mixin import NONSENSICAL_ACCESS_RESTRICTION -from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration from openedx.core.djangoapps.content_tagging import api as tagging_api - -from ..component import component_handler, DEFAULT_ADVANCED_MODULES, get_component_templates -from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import ( - ALWAYS, - VisibilityState, - get_block_info, - _get_source_index, - _xblock_type_and_display_name, - add_container_page_publishing_info, - create_xblock_info, +from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration +from openedx.core.djangoapps.video_config.toggles import PUBLIC_VIDEO_SHARE +from xmodule.course_block import DEFAULT_START_DATE +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.exceptions import ItemNotFoundError +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory, LibraryFactory, check_mongo_calls +from xmodule.partitions.partitions import ( + ENROLLMENT_TRACK_PARTITION_ID, + MINIMUM_UNUSED_PARTITION_ID, + Group, + UserPartition, ) -from common.test.utils import assert_dict_contains_subset +from xmodule.partitions.tests.test_partitions import MockPartitionService +from xmodule.x_module import STUDENT_VIEW, STUDIO_VIEW + +from ..component import DEFAULT_ADVANCED_MODULES, component_handler, get_component_templates class AsideTest(XBlockAside): diff --git a/cms/djangoapps/contentstore/views/tests/test_clipboard_paste.py b/cms/djangoapps/contentstore/views/tests/test_clipboard_paste.py index ba6d0b243165..acbc8a9b497a 100644 --- a/cms/djangoapps/contentstore/views/tests/test_clipboard_paste.py +++ b/cms/djangoapps/contentstore/views/tests/test_clipboard_paste.py @@ -5,7 +5,6 @@ """ import ddt from opaque_keys.edx.keys import UsageKey -from rest_framework.test import APIClient from openedx_events.content_authoring.signals import ( LIBRARY_BLOCK_DELETED, XBLOCK_CREATED, @@ -15,13 +14,14 @@ from openedx_events.tests.utils import OpenEdxEventsTestMixin from openedx_tagging.models import Tag from organizations.models import Organization -from xmodule.modulestore.django import contentstore, modulestore -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, upload_file_to_course, ImmediateOnCommitMixin -from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory, ToyCourseFactory, LibraryFactory +from rest_framework.test import APIClient from cms.djangoapps.contentstore.utils import reverse_usage_url from openedx.core.djangoapps.content_libraries import api as library_api from openedx.core.djangoapps.content_tagging import api as tagging_api +from xmodule.modulestore.django import contentstore, modulestore +from xmodule.modulestore.tests.django_utils import ImmediateOnCommitMixin, ModuleStoreTestCase, upload_file_to_course +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory, LibraryFactory, ToyCourseFactory CLIPBOARD_ENDPOINT = "/api/content-staging/v1/clipboard/" XBLOCK_ENDPOINT = "/xblock/" diff --git a/cms/djangoapps/contentstore/views/tests/test_container_page.py b/cms/djangoapps/contentstore/views/tests/test_container_page.py index e6b58257b69d..5c27aea44c30 100644 --- a/cms/djangoapps/contentstore/views/tests/test_container_page.py +++ b/cms/djangoapps/contentstore/views/tests/test_container_page.py @@ -6,20 +6,23 @@ import datetime import re from unittest.mock import Mock, patch +from urllib.parse import quote from django.http import Http404 from django.test.client import RequestFactory from django.urls import reverse from edx_toggles.toggles.testutils import override_waffle_flag from pytz import UTC -from urllib.parse import quote import cms.djangoapps.contentstore.views.component as views from cms.djangoapps.contentstore import toggles from cms.djangoapps.contentstore.tests.test_libraries import LibraryTestCase from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) from .utils import StudioPageTestCase diff --git a/cms/djangoapps/contentstore/views/tests/test_course_index.py b/cms/djangoapps/contentstore/views/tests/test_course_index.py index 58c425c601a3..e7ae0d2101db 100644 --- a/cms/djangoapps/contentstore/views/tests/test_course_index.py +++ b/cms/djangoapps/contentstore/views/tests/test_course_index.py @@ -15,19 +15,19 @@ from cms.djangoapps.contentstore.courseware_index import CoursewareSearchIndexer, SearchIndexingError from cms.djangoapps.contentstore.tests.utils import CourseTestCase -from cms.djangoapps.contentstore.utils import ( - reverse_course_url, - reverse_usage_url -) +from cms.djangoapps.contentstore.utils import reverse_course_url, reverse_usage_url +from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import VisibilityState, create_xblock_info from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE -from xmodule.modulestore.tests.factories import BlockFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + check_mongo_calls, +) from ..course import _deprecated_blocks_info, course_outline_initial_state, reindex_course_and_check_access -from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import VisibilityState, create_xblock_info @ddt.ddt diff --git a/cms/djangoapps/contentstore/views/tests/test_credit_eligibility.py b/cms/djangoapps/contentstore/views/tests/test_credit_eligibility.py index 66e42598bee6..fbce1f0502a5 100644 --- a/cms/djangoapps/contentstore/views/tests/test_credit_eligibility.py +++ b/cms/djangoapps/contentstore/views/tests/test_credit_eligibility.py @@ -4,6 +4,7 @@ from unittest import mock + from edx_toggles.toggles.testutils import override_waffle_flag from cms.djangoapps.contentstore import toggles diff --git a/cms/djangoapps/contentstore/views/tests/test_discussion_enabled.py b/cms/djangoapps/contentstore/views/tests/test_discussion_enabled.py index d19f18f2e264..972c73d88175 100644 --- a/cms/djangoapps/contentstore/views/tests/test_discussion_enabled.py +++ b/cms/djangoapps/contentstore/views/tests/test_discussion_enabled.py @@ -5,10 +5,9 @@ import json -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory - from cms.djangoapps.contentstore.tests.utils import CourseTestCase from cms.djangoapps.contentstore.utils import reverse_usage_url +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory class TestDiscussionEnabled(CourseTestCase): diff --git a/cms/djangoapps/contentstore/views/tests/test_entrance_exam.py b/cms/djangoapps/contentstore/views/tests/test_entrance_exam.py index dea52cbe7b6f..b3b3d013a43e 100644 --- a/cms/djangoapps/contentstore/views/tests/test_entrance_exam.py +++ b/cms/djangoapps/contentstore/views/tests/test_entrance_exam.py @@ -11,8 +11,10 @@ from milestones.tests.utils import MilestonesTestCaseMixin from opaque_keys.edx.keys import UsageKey +from cms.djangoapps.contentstore.helpers import GRADER_TYPES from cms.djangoapps.contentstore.tests.utils import AjaxEnabledTestClient, CourseTestCase from cms.djangoapps.contentstore.utils import reverse_url +from cms.djangoapps.contentstore.xblock_storage_handlers.create_xblock import create_xblock from cms.djangoapps.models.settings.course_grading import CourseGradingModel from cms.djangoapps.models.settings.course_metadata import CourseMetadata from common.djangoapps.student.tests.factories import UserFactory @@ -24,10 +26,8 @@ create_entrance_exam, delete_entrance_exam, remove_entrance_exam_milestone_reference, - update_entrance_exam + update_entrance_exam, ) -from cms.djangoapps.contentstore.helpers import GRADER_TYPES -from cms.djangoapps.contentstore.xblock_storage_handlers.create_xblock import create_xblock @override_settings(ENTRANCE_EXAMS=True) diff --git a/cms/djangoapps/contentstore/views/tests/test_gating.py b/cms/djangoapps/contentstore/views/tests/test_gating.py index 73febb91e6b9..7789d70fc16d 100644 --- a/cms/djangoapps/contentstore/views/tests/test_gating.py +++ b/cms/djangoapps/contentstore/views/tests/test_gating.py @@ -7,14 +7,13 @@ from unittest.mock import patch import ddt -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE -from xmodule.modulestore.tests.factories import BlockFactory from cms.djangoapps.contentstore.tests.utils import CourseTestCase from cms.djangoapps.contentstore.utils import reverse_usage_url -from openedx.core.lib.gating.api import GATING_NAMESPACE_QUALIFIER - from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import VisibilityState +from openedx.core.lib.gating.api import GATING_NAMESPACE_QUALIFIER +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE +from xmodule.modulestore.tests.factories import BlockFactory @ddt.ddt diff --git a/cms/djangoapps/contentstore/views/tests/test_group_configurations.py b/cms/djangoapps/contentstore/views/tests/test_group_configurations.py index 70a503cc2d75..b06eaff6edc6 100644 --- a/cms/djangoapps/contentstore/views/tests/test_group_configurations.py +++ b/cms/djangoapps/contentstore/views/tests/test_group_configurations.py @@ -6,31 +6,41 @@ import json from operator import itemgetter from unittest.mock import patch -from edx_toggles.toggles.testutils import override_waffle_flag -from rest_framework import status import ddt +from django.test import Client +from edx_toggles.toggles.testutils import override_waffle_flag +from openedx_authz.constants.roles import COURSE_DATA_RESEARCHER, COURSE_STAFF +from rest_framework import status from cms.djangoapps.contentstore import toggles +from cms.djangoapps.contentstore.api.tests.base import BaseCourseViewTest from cms.djangoapps.contentstore.course_group_config import ( CONTENT_GROUP_CONFIGURATION_NAME, ENROLLMENT_SCHEME, - GroupConfiguration + GroupConfiguration, ) -from django.test import Client -from cms.djangoapps.contentstore.api.tests.base import BaseCourseViewTest from cms.djangoapps.contentstore.tests.utils import CourseTestCase -from common.djangoapps.student.tests.factories import UserFactory from cms.djangoapps.contentstore.utils import reverse_course_url, reverse_usage_url -from openedx_authz.constants.roles import COURSE_DATA_RESEARCHER, COURSE_STAFF +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.authz.tests.mixins import CourseAuthzTestMixin from openedx.features.content_type_gating.helpers import CONTENT_GATING_PARTITION_ID from openedx.features.content_type_gating.partitions import CONTENT_TYPE_GATING_SCHEME from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID, Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.validation import StudioValidation, StudioValidationMessage # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) +from xmodule.partitions.partitions import ( # lint-amnesty, pylint: disable=wrong-import-order + ENROLLMENT_TRACK_PARTITION_ID, + Group, + UserPartition, +) +from xmodule.validation import ( # lint-amnesty, pylint: disable=wrong-import-order + StudioValidation, + StudioValidationMessage, +) GROUP_CONFIGURATION_JSON = { 'name': 'Test name', diff --git a/cms/djangoapps/contentstore/views/tests/test_helpers.py b/cms/djangoapps/contentstore/views/tests/test_helpers.py index e64cbaf46335..9d734a6b932d 100644 --- a/cms/djangoapps/contentstore/views/tests/test_helpers.py +++ b/cms/djangoapps/contentstore/views/tests/test_helpers.py @@ -2,11 +2,14 @@ Unit tests for helpers.py. """ -from unittest.mock import patch, Mock +from unittest.mock import Mock, patch from urllib.parse import quote from cms.djangoapps.contentstore.tests.utils import CourseTestCase -from xmodule.modulestore.tests.factories import BlockFactory, LibraryFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + LibraryFactory, +) from ...helpers import xblock_embed_lms_url, xblock_lms_url, xblock_studio_url, xblock_type_display_name diff --git a/cms/djangoapps/contentstore/views/tests/test_import_export.py b/cms/djangoapps/contentstore/views/tests/test_import_export.py index 170c341c32be..5a44c0b391bf 100644 --- a/cms/djangoapps/contentstore/views/tests/test_import_export.py +++ b/cms/djangoapps/contentstore/views/tests/test_import_export.py @@ -26,15 +26,15 @@ from edx_toggles.toggles.testutils import override_waffle_flag from milestones.tests.utils import MilestonesTestCaseMixin from opaque_keys.edx.locator import LibraryLocator +from openedx_authz.constants.roles import COURSE_DATA_RESEARCHER, COURSE_STAFF from path import Path as path -from storages.backends.s3boto3 import S3Boto3Storage -from user_tasks.models import UserTaskStatus from rest_framework import status from rest_framework.test import APIClient +from storages.backends.s3boto3 import S3Boto3Storage +from user_tasks.models import UserTaskStatus - -from cms.djangoapps.contentstore import toggles from cms.djangoapps.contentstore import errors as import_error +from cms.djangoapps.contentstore import toggles from cms.djangoapps.contentstore.api.tests.base import BaseCourseViewTest from cms.djangoapps.contentstore.storage import course_import_export_storage from cms.djangoapps.contentstore.tests.test_libraries import LibraryTestCase @@ -47,7 +47,6 @@ from common.djangoapps.util import milestones_helpers from openedx.core.djangoapps.authz.tests.mixins import CourseAuthzTestMixin from openedx.core.lib.extract_archive import safe_extractall -from openedx_authz.constants.roles import COURSE_DATA_RESEARCHER, COURSE_STAFF from xmodule.contentstore.django import contentstore from xmodule.modulestore import LIBRARY_ROOT, ModuleStoreEnum from xmodule.modulestore.django import modulestore @@ -60,7 +59,7 @@ CourseImportManager, ErrorReadingFileException, import_course_from_xml, - import_library_from_xml + import_library_from_xml, ) TASK_LOGGER = 'cms.djangoapps.contentstore.tasks.LOGGER' diff --git a/cms/djangoapps/contentstore/views/tests/test_library.py b/cms/djangoapps/contentstore/views/tests/test_library.py index fd62faa56db1..2edbdede811c 100644 --- a/cms/djangoapps/contentstore/views/tests/test_library.py +++ b/cms/djangoapps/contentstore/views/tests/test_library.py @@ -18,16 +18,15 @@ from cms.djangoapps.contentstore.tests.utils import AjaxEnabledTestClient, CourseTestCase, parse_json from cms.djangoapps.contentstore.utils import reverse_course_url, reverse_library_url -from cms.djangoapps.course_creators.views import add_user_with_status_granted as grant_course_creator_status -from common.djangoapps.student.roles import LibraryUserRole, CourseStaffRole, CourseInstructorRole -from xmodule.modulestore.tests.factories import LibraryFactory # lint-amnesty, pylint: disable=wrong-import-order from cms.djangoapps.course_creators.models import CourseCreator - +from cms.djangoapps.course_creators.views import add_user_with_status_granted as grant_course_creator_status from common.djangoapps.student import auth +from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole, LibraryUserRole +from xmodule.modulestore.tests.factories import LibraryFactory # lint-amnesty, pylint: disable=wrong-import-order from ..component import get_component_templates -from ..library import user_can_create_library from ..course import get_allowed_organizations_for_libraries +from ..library import user_can_create_library LIBRARY_REST_URL = '/library/' # URL for GET/POST requests involving libraries diff --git a/cms/djangoapps/contentstore/views/tests/test_preview.py b/cms/djangoapps/contentstore/views/tests/test_preview.py index b97a1a41105e..bd969a6c3a5b 100644 --- a/cms/djangoapps/contentstore/views/tests/test_preview.py +++ b/cms/djangoapps/contentstore/views/tests/test_preview.py @@ -5,25 +5,27 @@ from unittest import mock import ddt -from common.djangoapps.xblock_django.constants import ATTR_KEY_ANONYMOUS_USER_ID, ATTR_KEY_DEPRECATED_ANONYMOUS_USER_ID from django.test.client import Client, RequestFactory from django.test.utils import override_settings from edx_toggles.toggles.testutils import override_waffle_flag from web_fragments.fragment import Fragment from xblock.core import XBlock, XBlockAside +from cms.djangoapps.contentstore.toggles import INDIVIDUALIZE_ANONYMOUS_USER_ID +from cms.djangoapps.contentstore.utils import reverse_usage_url +from cms.djangoapps.xblock_config.models import StudioConfig +from common.djangoapps import static_replace +from common.djangoapps.student.tests.factories import UserFactory +from common.djangoapps.xblock_django.constants import ATTR_KEY_ANONYMOUS_USER_ID, ATTR_KEY_DEPRECATED_ANONYMOUS_USER_ID from xmodule.contentstore.django import contentstore from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ( - TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase, upload_file_to_course, + TEST_DATA_SPLIT_MODULESTORE, + ModuleStoreTestCase, + upload_file_to_course, ) -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory from xmodule.modulestore.tests.test_asides import AsideTestType -from cms.djangoapps.contentstore.utils import reverse_usage_url -from cms.djangoapps.contentstore.toggles import INDIVIDUALIZE_ANONYMOUS_USER_ID -from cms.djangoapps.xblock_config.models import StudioConfig -from common.djangoapps import static_replace -from common.djangoapps.student.tests.factories import UserFactory from ..preview import _prepare_runtime_for_preview, get_preview_fragment diff --git a/cms/djangoapps/contentstore/views/tests/test_tabs.py b/cms/djangoapps/contentstore/views/tests/test_tabs.py index b4e4d17181ef..d48744f330a8 100644 --- a/cms/djangoapps/contentstore/views/tests/test_tabs.py +++ b/cms/djangoapps/contentstore/views/tests/test_tabs.py @@ -8,8 +8,13 @@ from cms.djangoapps.contentstore.utils import reverse_course_url from cms.djangoapps.contentstore.views import tabs from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) from xmodule.tabs import CourseTabList # lint-amnesty, pylint: disable=wrong-import-order from xmodule.x_module import STUDENT_VIEW # lint-amnesty, pylint: disable=wrong-import-order diff --git a/cms/djangoapps/contentstore/views/tests/test_textbooks.py b/cms/djangoapps/contentstore/views/tests/test_textbooks.py index 0756d236ed42..0b6e01f6a5ee 100644 --- a/cms/djangoapps/contentstore/views/tests/test_textbooks.py +++ b/cms/djangoapps/contentstore/views/tests/test_textbooks.py @@ -4,7 +4,6 @@ import json from unittest import TestCase - from cms.djangoapps.contentstore.tests.utils import CourseTestCase from cms.djangoapps.contentstore.utils import reverse_course_url diff --git a/cms/djangoapps/contentstore/views/tests/test_transcript_settings.py b/cms/djangoapps/contentstore/views/tests/test_transcript_settings.py index 4edea5665e22..7969bb781a83 100644 --- a/cms/djangoapps/contentstore/views/tests/test_transcript_settings.py +++ b/cms/djangoapps/contentstore/views/tests/test_transcript_settings.py @@ -14,12 +14,12 @@ from cms.djangoapps.contentstore.tests.utils import CourseTestCase from cms.djangoapps.contentstore.transcript_storage_handlers import ( TranscriptionProviderErrorType, - validate_transcript_credentials + validate_transcript_credentials, ) from cms.djangoapps.contentstore.utils import reverse_course_url from common.djangoapps.student.roles import CourseStaffRole -from openedx.core.djangoapps.profile_images.tests.helpers import make_image_file from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_for_user +from openedx.core.djangoapps.profile_images.tests.helpers import make_image_file @ddt.ddt diff --git a/cms/djangoapps/contentstore/views/tests/test_transcripts.py b/cms/djangoapps/contentstore/views/tests/test_transcripts.py index a3b70641ed3c..a6be91ef34b6 100644 --- a/cms/djangoapps/contentstore/views/tests/test_transcripts.py +++ b/cms/djangoapps/contentstore/views/tests/test_transcripts.py @@ -18,21 +18,21 @@ from organizations.tests.factories import OrganizationFactory from cms.djangoapps.contentstore.tests.utils import CourseTestCase, setup_caption_responses -from openedx.core.djangoapps.contentserver.caching import del_cached_content from openedx.core.djangoapps.content_libraries import api as lib_api -from xmodule.contentstore.content import StaticContent # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.contentstore.django import contentstore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.exceptions import NotFoundError # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.video_block import VideoBlock # lint-amnesty, pylint: disable=wrong-import-order +from openedx.core.djangoapps.contentserver.caching import del_cached_content from openedx.core.djangoapps.video_config.transcripts_utils import ( # lint-amnesty, pylint: disable=wrong-import-order GetTranscriptsFromYouTubeException, Transcript, - get_video_transcript_content, get_transcript, + get_video_transcript_content, remove_subs_from_store, ) from openedx.core.djangoapps.xblock import api as xblock_api +from xmodule.contentstore.content import StaticContent # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.contentstore.django import contentstore # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.exceptions import NotFoundError # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.video_block import VideoBlock # lint-amnesty, pylint: disable=wrong-import-order TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex diff --git a/cms/djangoapps/contentstore/views/tests/test_videos.py b/cms/djangoapps/contentstore/views/tests/test_videos.py index e42ef2198c8d..c170edfb427c 100644 --- a/cms/djangoapps/contentstore/views/tests/test_videos.py +++ b/cms/djangoapps/contentstore/views/tests/test_videos.py @@ -12,11 +12,10 @@ from unittest.mock import Mock, patch import dateutil.parser -from common.djangoapps.student.tests.factories import UserFactory import ddt import pytz -from django.test import TestCase from django.conf import settings +from django.test import TestCase from django.test.utils import override_settings from django.urls import reverse from edx_toggles.toggles.testutils import override_waffle_flag, override_waffle_switch @@ -27,33 +26,29 @@ create_video, get_course_video_image_url, get_transcript_preferences, - get_video_info + get_video_info, ) + from cms.djangoapps.contentstore.models import VideoUploadConfig from cms.djangoapps.contentstore.tests.utils import CourseTestCase from cms.djangoapps.contentstore.utils import reverse_course_url -from openedx.core.djangoapps.profile_images.tests.helpers import make_image_file -from openedx.core.djangoapps.video_pipeline.config.waffle import ( - DEPRECATE_YOUTUBE, - ENABLE_DEVSTACK_VIDEO_UPLOADS, -) -from openedx.core.djangoapps.waffle_utils.models import WaffleFlagCourseOverrideModel -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order - -from ..videos import ( - KEY_EXPIRATION_IN_SECONDS, - VIDEO_IMAGE_UPLOAD_ENABLED, -) from cms.djangoapps.contentstore.video_storage_handlers import ( - TranscriptProvider, + PUBLIC_VIDEO_SHARE, StatusDisplayStrings, + TranscriptProvider, convert_video_status, storage_service_bucket, storage_service_key, - PUBLIC_VIDEO_SHARE ) +from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.profile_images.tests.helpers import make_image_file +from openedx.core.djangoapps.video_pipeline.config.waffle import DEPRECATE_YOUTUBE, ENABLE_DEVSTACK_VIDEO_UPLOADS +from openedx.core.djangoapps.waffle_utils.models import WaffleFlagCourseOverrideModel +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order + +from ..videos import KEY_EXPIRATION_IN_SECONDS, VIDEO_IMAGE_UPLOAD_ENABLED def setup_s3_mocks(mock_boto3_resource, bucket_name='test-bucket'): diff --git a/cms/djangoapps/contentstore/views/transcript_settings.py b/cms/djangoapps/contentstore/views/transcript_settings.py index 776d3432b5ec..02524b7f71de 100644 --- a/cms/djangoapps/contentstore/views/transcript_settings.py +++ b/cms/djangoapps/contentstore/views/transcript_settings.py @@ -12,11 +12,11 @@ from rest_framework.decorators import api_view from cms.djangoapps.contentstore.transcript_storage_handlers import ( - validate_transcript_upload_data, - upload_transcript, delete_video_transcript, handle_transcript_credentials, handle_transcript_download, + upload_transcript, + validate_transcript_upload_data, ) from common.djangoapps.student.auth import has_studio_write_access from common.djangoapps.util.json_request import JsonResponse, expect_json diff --git a/cms/djangoapps/contentstore/views/transcripts_ajax.py b/cms/djangoapps/contentstore/views/transcripts_ajax.py index 362772c4471f..56f66474714c 100644 --- a/cms/djangoapps/contentstore/views/transcripts_ajax.py +++ b/cms/djangoapps/contentstore/views/transcripts_ajax.py @@ -21,15 +21,12 @@ from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import UsageKey, UsageKeyV2 from opaque_keys.edx.locator import LibraryLocatorV2 +from xblocks_contrib.video.exceptions import TranscriptsGenerationException from cms.djangoapps.contentstore.video_storage_handlers import TranscriptProvider from common.djangoapps.student.auth import has_course_author_access from common.djangoapps.util.json_request import JsonResponse -from xmodule.contentstore.content import StaticContent # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.contentstore.django import contentstore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.exceptions import NotFoundError # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order +from openedx.core.djangoapps.content_libraries import api as lib_api from openedx.core.djangoapps.video_config.transcripts_utils import ( # lint-amnesty, pylint: disable=wrong-import-order GetTranscriptsFromYouTubeException, Transcript, @@ -43,10 +40,13 @@ get_transcript_link_from_youtube, get_transcript_links_from_youtube, ) -from xblocks_contrib.video.exceptions import TranscriptsGenerationException -from openedx.core.djangoapps.content_libraries import api as lib_api from openedx.core.djangoapps.xblock import api as xblock_api from openedx.core.djangoapps.xblock.data import CheckPerm +from xmodule.contentstore.content import StaticContent # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.contentstore.django import contentstore # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.exceptions import NotFoundError # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order __all__ = [ 'upload_transcripts', diff --git a/cms/djangoapps/contentstore/views/user.py b/cms/djangoapps/contentstore/views/user.py index 80a09db96dd3..70ff9e701996 100644 --- a/cms/djangoapps/contentstore/views/user.py +++ b/cms/djangoapps/contentstore/views/user.py @@ -21,7 +21,7 @@ from common.djangoapps.util.json_request import JsonResponse, expect_json from ..toggles import use_new_course_team_page -from ..utils import get_course_team_url, get_course_team +from ..utils import get_course_team, get_course_team_url __all__ = ['request_course_creator', 'course_team_handler'] diff --git a/cms/djangoapps/contentstore/views/videos.py b/cms/djangoapps/contentstore/views/videos.py index 2eac141b9c9e..fce74919d34e 100644 --- a/cms/djangoapps/contentstore/views/videos.py +++ b/cms/djangoapps/contentstore/views/videos.py @@ -4,32 +4,46 @@ import logging + from django.contrib.auth.decorators import login_required from django.views.decorators.http import require_GET, require_http_methods, require_POST from edx_toggles.toggles import WaffleSwitch from rest_framework.decorators import api_view from cms.djangoapps.contentstore.video_storage_handlers import ( - handle_videos, - handle_generate_video_upload_link, - handle_video_images, check_video_images_upload_enabled, enabled_video_features, - handle_transcript_preferences, + get_course_youtube_edx_video_ids, get_video_encodings_download, - validate_transcript_preferences as validate_transcript_preferences_source_function, + handle_generate_video_upload_link, + handle_transcript_preferences, + handle_video_images, + handle_videos, +) +from cms.djangoapps.contentstore.video_storage_handlers import ( convert_video_status as convert_video_status_source_function, +) +from cms.djangoapps.contentstore.video_storage_handlers import ( get_all_transcript_languages as get_all_transcript_languages_source_function, - videos_index_html as videos_index_html_source_function, - videos_index_json as videos_index_json_source_function, - videos_post as videos_post_source_function, +) +from cms.djangoapps.contentstore.video_storage_handlers import ( + is_status_update_request as is_status_update_request_source_function, +) +from cms.djangoapps.contentstore.video_storage_handlers import ( + send_video_status_update as send_video_status_update_source_function, +) +from cms.djangoapps.contentstore.video_storage_handlers import ( storage_service_bucket as storage_service_bucket_source_function, +) +from cms.djangoapps.contentstore.video_storage_handlers import ( storage_service_key as storage_service_key_source_function, - send_video_status_update as send_video_status_update_source_function, - is_status_update_request as is_status_update_request_source_function, - get_course_youtube_edx_video_ids, ) - +from cms.djangoapps.contentstore.video_storage_handlers import ( + validate_transcript_preferences as validate_transcript_preferences_source_function, +) +from cms.djangoapps.contentstore.video_storage_handlers import videos_index_html as videos_index_html_source_function +from cms.djangoapps.contentstore.video_storage_handlers import videos_index_json as videos_index_json_source_function +from cms.djangoapps.contentstore.video_storage_handlers import videos_post as videos_post_source_function from common.djangoapps.util.json_request import expect_json from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag from openedx.core.lib.api.view_utils import view_auth_classes diff --git a/cms/djangoapps/contentstore/xblock_storage_handlers/create_xblock.py b/cms/djangoapps/contentstore/xblock_storage_handlers/create_xblock.py index 64b5c442bc76..4a716ad09c3f 100644 --- a/cms/djangoapps/contentstore/xblock_storage_handlers/create_xblock.py +++ b/cms/djangoapps/contentstore/xblock_storage_handlers/create_xblock.py @@ -5,14 +5,14 @@ from uuid import uuid4 from django.utils.translation import gettext as _ -from xmodule.modulestore.django import modulestore -from xmodule.tabs import StaticTab from cms.djangoapps.models.settings.course_grading import CourseGradingModel from openedx.core.toggles import ENTRANCE_EXAMS +from xmodule.modulestore.django import modulestore +from xmodule.tabs import StaticTab -from .xblock_helpers import usage_key_with_run from ..helpers import GRADER_TYPES, remove_entrance_exam_graders +from .xblock_helpers import usage_key_with_run def create_xblock(parent_locator, user, category, display_name, boilerplate=None, is_entrance_exam=False): diff --git a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py index 9a30807b60a3..b7815377b407 100644 --- a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py +++ b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py @@ -20,11 +20,14 @@ from django.http import HttpResponse, HttpResponseBadRequest from django.utils.translation import gettext as _ from edx_django_utils.plugins import pluggable_override -from openedx_content import api as content_api -from openedx_content import models_api as content_models -from openedx.core.djangoapps.content_libraries.api import ContainerMetadata, LibraryXBlockMetadata -from openedx.core.djangoapps.content_tagging.api import get_object_tag_counts -from openedx.core import toggles as core_toggles +from edx_proctoring.api import ( + does_backend_support_onboarding, + get_exam_by_content_id, + get_exam_configuration_dashboard_url, +) +from edx_proctoring.exceptions import ProctoredExamNotFoundException +from help_tokens.core import HelpUrlExpert +from opaque_keys.edx.locator import LibraryUsageLocator, LibraryUsageLocatorV2 from openedx_authz import api as authz_api from openedx_authz.constants.permissions import ( COURSES_EDIT_COURSE_CONTENT, @@ -34,17 +37,10 @@ COURSES_VIEW_COURSE, COURSES_VIEW_COURSE_UPDATES, ) -from edx_proctoring.api import ( - does_backend_support_onboarding, - get_exam_by_content_id, - get_exam_configuration_dashboard_url, -) -from edx_proctoring.exceptions import ProctoredExamNotFoundException -from help_tokens.core import HelpUrlExpert -from opaque_keys.edx.locator import LibraryUsageLocator, LibraryUsageLocatorV2 +from openedx_content import api as content_api +from openedx_content import models_api as content_models from xblock.core import XBlock from xblock.fields import Scope -from .xblock_helpers import get_block_key_string from cms.djangoapps.contentstore.helpers import StaticFileNotices from cms.djangoapps.models.settings.course_grading import CourseGradingModel @@ -53,19 +49,19 @@ from cms.lib.xblock.upstream_sync_block import sync_from_upstream_block from cms.lib.xblock.upstream_sync_container import sync_from_upstream_container from common.djangoapps.static_replace import replace_static_urls -from common.djangoapps.student.auth import ( - has_studio_read_access, - has_studio_write_access, -) +from common.djangoapps.student.auth import has_studio_read_access, has_studio_write_access from common.djangoapps.util.date_utils import get_default_time_display from common.djangoapps.util.json_request import JsonResponse, expect_json from common.djangoapps.util.proctoring import show_review_rules +from openedx.core import toggles as core_toggles from openedx.core.djangoapps.bookmarks import api as bookmarks_api +from openedx.core.djangoapps.content_libraries.api import ContainerMetadata, LibraryXBlockMetadata +from openedx.core.djangoapps.content_tagging.api import get_object_tag_counts from openedx.core.djangoapps.content_tagging.toggles import is_tagging_feature_disabled from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration from openedx.core.djangoapps.video_config.toggles import PUBLIC_VIDEO_SHARE -from openedx.core.lib.gating import api as gating_api from openedx.core.lib.cache_utils import request_cached +from openedx.core.lib.gating import api as gating_api from openedx.core.lib.xblock_utils import get_icon from openedx.core.toggles import ENTRANCE_EXAMS from xmodule.course_block import DEFAULT_START_DATE @@ -76,35 +72,34 @@ from xmodule.modulestore.inheritance import own_metadata from xmodule.tabs import CourseTabList +from ..helpers import ( + concat_static_file_notices, + get_parent_xblock, + import_staged_content_from_user_clipboard, + import_static_assets_for_library_sync, + is_unit, + xblock_embed_lms_url, + xblock_lms_url, + xblock_primary_child_category, + xblock_studio_url, + xblock_type_display_name, +) from ..utils import ( ancestor_has_staff_lock, + duplicate_block, find_release_date_source, find_staff_lock_source, get_split_group_display_name, + get_taxonomy_tags_widget_url, get_user_partition_info, get_visibility_partition_info, has_children_visible_to_specific_partition_groups, is_currently_visible_to_students, is_self_paced, - get_taxonomy_tags_widget_url, load_services_for_studio, - duplicate_block, ) - from .create_xblock import create_xblock -from .xblock_helpers import usage_key_with_run -from ..helpers import ( - concat_static_file_notices, - get_parent_xblock, - import_staged_content_from_user_clipboard, - import_static_assets_for_library_sync, - is_unit, - xblock_embed_lms_url, - xblock_lms_url, - xblock_primary_child_category, - xblock_studio_url, - xblock_type_display_name, -) +from .xblock_helpers import get_block_key_string, usage_key_with_run log = logging.getLogger(__name__) diff --git a/cms/djangoapps/contentstore/xblock_storage_handlers/xblock_helpers.py b/cms/djangoapps/contentstore/xblock_storage_handlers/xblock_helpers.py index 82ed7297d5af..031548cc3d26 100644 --- a/cms/djangoapps/contentstore/xblock_storage_handlers/xblock_helpers.py +++ b/cms/djangoapps/contentstore/xblock_storage_handlers/xblock_helpers.py @@ -4,9 +4,10 @@ from opaque_keys.edx.keys import UsageKey from xblock.core import XBlock + +from openedx.core.djangoapps.content_tagging.api import get_object_tag_counts from xmodule.modulestore.django import modulestore from xmodule.util.keys import BlockKey -from openedx.core.djangoapps.content_tagging.api import get_object_tag_counts def usage_key_with_run(usage_key_string: str) -> UsageKey: diff --git a/cms/djangoapps/course_creators/admin.py b/cms/djangoapps/course_creators/admin.py index a1d34b3897fc..ca8d1ca73e69 100644 --- a/cms/djangoapps/course_creators/admin.py +++ b/cms/djangoapps/course_creators/admin.py @@ -18,7 +18,7 @@ CourseCreator, send_admin_notification, send_user_notification, - update_creator_state + update_creator_state, ) from cms.djangoapps.course_creators.views import update_course_creator_group, update_org_content_creator_role from common.djangoapps.edxmako.shortcuts import render_to_string diff --git a/cms/djangoapps/course_creators/models.py b/cms/djangoapps/course_creators/models.py index 81734afbeba6..977beb196aa9 100644 --- a/cms/djangoapps/course_creators/models.py +++ b/cms/djangoapps/course_creators/models.py @@ -7,7 +7,6 @@ from django.db.models.signals import post_init, post_save from django.dispatch import Signal, receiver from django.utils import timezone - from django.utils.translation import gettext_lazy as _ from organizations.models import Organization diff --git a/cms/djangoapps/course_creators/tests/test_views.py b/cms/djangoapps/course_creators/tests/test_views.py index 5ea37b37fcbf..6001363c0355 100644 --- a/cms/djangoapps/course_creators/tests/test_views.py +++ b/cms/djangoapps/course_creators/tests/test_views.py @@ -15,7 +15,7 @@ get_course_creator_status, update_course_creator_group, update_org_content_creator_role, - user_requested_access + user_requested_access, ) from common.djangoapps.student import auth from common.djangoapps.student.roles import CourseCreatorRole, OrgContentCreatorRole diff --git a/cms/djangoapps/export_course_metadata/management/commands/export_course_metadata_for_all_courses.py b/cms/djangoapps/export_course_metadata/management/commands/export_course_metadata_for_all_courses.py index 6b639b621f78..185eeb187846 100644 --- a/cms/djangoapps/export_course_metadata/management/commands/export_course_metadata_for_all_courses.py +++ b/cms/djangoapps/export_course_metadata/management/commands/export_course_metadata_for_all_courses.py @@ -4,10 +4,9 @@ from django.core.management.base import BaseCommand -from xmodule.modulestore.django import modulestore - from cms.djangoapps.export_course_metadata.signals import export_course_metadata # pylint: disable=unused-import from cms.djangoapps.export_course_metadata.tasks import export_course_metadata_task +from xmodule.modulestore.django import modulestore class Command(BaseCommand): diff --git a/cms/djangoapps/export_course_metadata/management/commands/tests/test_export_course_metadata_for_all_courses.py b/cms/djangoapps/export_course_metadata/management/commands/tests/test_export_course_metadata_for_all_courses.py index 18872e1459ed..1cf18411b85f 100644 --- a/cms/djangoapps/export_course_metadata/management/commands/tests/test_export_course_metadata_for_all_courses.py +++ b/cms/djangoapps/export_course_metadata/management/commands/tests/test_export_course_metadata_for_all_courses.py @@ -5,10 +5,10 @@ from unittest.mock import patch from edx_toggles.toggles.testutils import override_waffle_flag -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from cms.djangoapps.export_course_metadata.toggles import EXPORT_COURSE_METADATA_FLAG +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory from ..export_course_metadata_for_all_courses import export_course_metadata_for_all_courses diff --git a/cms/djangoapps/export_course_metadata/signals.py b/cms/djangoapps/export_course_metadata/signals.py index 4d6fbefd478f..0480200b33b6 100644 --- a/cms/djangoapps/export_course_metadata/signals.py +++ b/cms/djangoapps/export_course_metadata/signals.py @@ -3,6 +3,7 @@ """ from django.dispatch import receiver + from xmodule.modulestore.django import SignalHandler from .tasks import export_course_metadata_task diff --git a/cms/djangoapps/export_course_metadata/storage.py b/cms/djangoapps/export_course_metadata/storage.py index dd63acdf14a1..2db5b380253a 100644 --- a/cms/djangoapps/export_course_metadata/storage.py +++ b/cms/djangoapps/export_course_metadata/storage.py @@ -4,9 +4,10 @@ from django.conf import settings -from common.djangoapps.util.storage import resolve_storage_backend from storages.backends.s3boto3 import S3Boto3Storage +from common.djangoapps.util.storage import resolve_storage_backend + class CourseMetadataExportS3Storage(S3Boto3Storage): # pylint: disable=abstract-method """ diff --git a/cms/djangoapps/export_course_metadata/tasks.py b/cms/djangoapps/export_course_metadata/tasks.py index 63974efb0fd3..c95b91adde28 100644 --- a/cms/djangoapps/export_course_metadata/tasks.py +++ b/cms/djangoapps/export_course_metadata/tasks.py @@ -8,6 +8,7 @@ from django.core.files.base import ContentFile from edx_django_utils.monitoring import set_code_owner_attribute from opaque_keys.edx.keys import CourseKey + from openedx.core.djangoapps.schedules.content_highlights import get_all_course_highlights from .storage import course_metadata_export_storage diff --git a/cms/djangoapps/export_course_metadata/test_signals.py b/cms/djangoapps/export_course_metadata/test_signals.py index 876dcb224c18..f3523a66690a 100644 --- a/cms/djangoapps/export_course_metadata/test_signals.py +++ b/cms/djangoapps/export_course_metadata/test_signals.py @@ -3,16 +3,17 @@ """ from unittest.mock import patch -from django.test.utils import override_settings -from django.conf import settings +from django.conf import settings +from django.core.files.storage import storages +from django.test.utils import override_settings from edx_toggles.toggles.testutils import override_waffle_flag +from storages.backends.s3boto3 import S3Boto3Storage + +from common.djangoapps.util.storage import resolve_storage_backend from xmodule.modulestore.django import SignalHandler from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory -from common.djangoapps.util.storage import resolve_storage_backend -from storages.backends.s3boto3 import S3Boto3Storage -from django.core.files.storage import storages +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory from .signals import export_course_metadata from .toggles import EXPORT_COURSE_METADATA_FLAG diff --git a/cms/djangoapps/models/settings/waffle.py b/cms/djangoapps/models/settings/waffle.py index 0ca488a0b7b0..6756cdda8722 100644 --- a/cms/djangoapps/models/settings/waffle.py +++ b/cms/djangoapps/models/settings/waffle.py @@ -3,7 +3,6 @@ """ from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag - WAFFLE_NAMESPACE = 'grades' # edx/edx-platform feature diff --git a/cms/djangoapps/modulestore_migrator/admin.py b/cms/djangoapps/modulestore_migrator/admin.py index 1a06170d294b..f64b29f0b0f4 100644 --- a/cms/djangoapps/modulestore_migrator/admin.py +++ b/cms/djangoapps/modulestore_migrator/admin.py @@ -7,8 +7,6 @@ from django.contrib import admin, messages from django.contrib.admin.helpers import ActionForm from django.db import models - - from opaque_keys import InvalidKeyError from opaque_keys.edx.locator import LibraryCollectionLocator, LibraryLocatorV2 from user_tasks.models import UserTaskStatus @@ -17,8 +15,7 @@ from . import api from .data import CompositionLevel, RepeatHandlingStrategy -from .models import ModulestoreSource, ModulestoreMigration, ModulestoreBlockSource, ModulestoreBlockMigration - +from .models import ModulestoreBlockMigration, ModulestoreBlockSource, ModulestoreMigration, ModulestoreSource log = logging.getLogger(__name__) diff --git a/cms/djangoapps/modulestore_migrator/api/read_api.py b/cms/djangoapps/modulestore_migrator/api/read_api.py index c418223b4db7..064223dc9633 100644 --- a/cms/djangoapps/modulestore_migrator/api/read_api.py +++ b/cms/djangoapps/modulestore_migrator/api/read_api.py @@ -5,35 +5,33 @@ import typing as t from uuid import UUID -from django.conf import settings +from django.conf import settings from opaque_keys.edx.keys import UsageKey -from opaque_keys.edx.locator import ( - LibraryLocatorV2, LibraryUsageLocatorV2, LibraryContainerLocator -) -from openedx_content.api import get_draft_version, get_all_drafts -from openedx_content.models_api import ( - PublishableEntityVersion, PublishableEntity, DraftChangeLogRecord -) +from opaque_keys.edx.locator import LibraryContainerLocator, LibraryLocatorV2, LibraryUsageLocatorV2 +from openedx_content.api import get_all_drafts, get_draft_version +from openedx_content.models_api import DraftChangeLogRecord, PublishableEntity, PublishableEntityVersion from xblock.plugin import PluginMissingError +from openedx.core.djangoapps.content.search.api import fetch_block_types, get_all_blocks_from_context from openedx.core.djangoapps.content_libraries.api import ( - library_component_usage_key, library_container_locator, - validate_can_add_block_to_library, BlockLimitReachedError, - IncompatibleTypesError, LibraryBlockAlreadyExists, - ContentLibrary -) -from openedx.core.djangoapps.content.search.api import ( - fetch_block_types, - get_all_blocks_from_context, + BlockLimitReachedError, + ContentLibrary, + IncompatibleTypesError, + LibraryBlockAlreadyExists, + library_component_usage_key, + library_container_locator, + validate_can_add_block_to_library, ) +from .. import models from ..data import ( - SourceContextKey, ModulestoreMigration, ModulestoreBlockMigrationResult, - ModulestoreBlockMigrationSuccess, ModulestoreBlockMigrationFailure + ModulestoreBlockMigrationFailure, + ModulestoreBlockMigrationResult, + ModulestoreBlockMigrationSuccess, + ModulestoreMigration, + SourceContextKey, ) -from .. import models - __all__ = ( 'get_forwarding', diff --git a/cms/djangoapps/modulestore_migrator/api/write_api.py b/cms/djangoapps/modulestore_migrator/api/write_api.py index a84d5bf11b5e..52a1d9ec45fe 100644 --- a/cms/djangoapps/modulestore_migrator/api/write_api.py +++ b/cms/djangoapps/modulestore_migrator/api/write_api.py @@ -7,12 +7,11 @@ from opaque_keys.edx.locator import LibraryLocatorV2 from openedx_content.api import get_collection -from openedx.core.types.user import AuthUser from openedx.core.djangoapps.content_libraries.api import get_library +from openedx.core.types.user import AuthUser -from ..data import SourceContextKey, CompositionLevel, RepeatHandlingStrategy -from .. import tasks, models - +from .. import models, tasks +from ..data import CompositionLevel, RepeatHandlingStrategy, SourceContextKey __all__ = ( 'start_migration_to_library', diff --git a/cms/djangoapps/modulestore_migrator/migrations/0001_initial.py b/cms/djangoapps/modulestore_migrator/migrations/0001_initial.py index 42d1df5bad1b..d02df0c6ad41 100644 --- a/cms/djangoapps/modulestore_migrator/migrations/0001_initial.py +++ b/cms/djangoapps/modulestore_migrator/migrations/0001_initial.py @@ -1,10 +1,10 @@ # Generated by Django 4.2.24 on 2025-09-10 15:14 -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields import opaque_keys.edx.django.models +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/cms/djangoapps/modulestore_migrator/migrations/0002_alter_modulestoremigration_task_status.py b/cms/djangoapps/modulestore_migrator/migrations/0002_alter_modulestoremigration_task_status.py index ed3a299c30c0..577c8f6cb37f 100644 --- a/cms/djangoapps/modulestore_migrator/migrations/0002_alter_modulestoremigration_task_status.py +++ b/cms/djangoapps/modulestore_migrator/migrations/0002_alter_modulestoremigration_task_status.py @@ -1,7 +1,7 @@ # Generated by Django 4.2.24 on 2025-09-29 20:28 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/cms/djangoapps/modulestore_migrator/models.py b/cms/djangoapps/modulestore_migrator/models.py index 6571a28137dc..ad465be2150e 100644 --- a/cms/djangoapps/modulestore_migrator/models.py +++ b/cms/djangoapps/modulestore_migrator/models.py @@ -7,10 +7,7 @@ from django.db import models from django.utils.translation import gettext_lazy as _ from model_utils.models import TimeStampedModel -from opaque_keys.edx.django.models import ( - LearningContextKeyField, - UsageKeyField, -) +from opaque_keys.edx.django.models import LearningContextKeyField, UsageKeyField from openedx_content.models_api import ( Collection, DraftChangeLog, diff --git a/cms/djangoapps/modulestore_migrator/rest_api/v1/serializers.py b/cms/djangoapps/modulestore_migrator/rest_api/v1/serializers.py index 54d9fb6dd7cc..797c42d9a5b3 100644 --- a/cms/djangoapps/modulestore_migrator/rest_api/v1/serializers.py +++ b/cms/djangoapps/modulestore_migrator/rest_api/v1/serializers.py @@ -11,10 +11,7 @@ from user_tasks.serializers import StatusSerializer from cms.djangoapps.modulestore_migrator.data import CompositionLevel, RepeatHandlingStrategy -from cms.djangoapps.modulestore_migrator.models import ( - ModulestoreMigration, - ModulestoreSource, -) +from cms.djangoapps.modulestore_migrator.models import ModulestoreMigration, ModulestoreSource class LibraryMigrationCollectionSerializer(serializers.ModelSerializer): diff --git a/cms/djangoapps/modulestore_migrator/rest_api/v1/views.py b/cms/djangoapps/modulestore_migrator/rest_api/v1/views.py index 18f066291088..0b76c01cdaaa 100644 --- a/cms/djangoapps/modulestore_migrator/rest_api/v1/views.py +++ b/cms/djangoapps/modulestore_migrator/rest_api/v1/views.py @@ -9,7 +9,7 @@ from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey -from opaque_keys.edx.locator import LibraryLocatorV2, CourseLocator, LibraryLocator +from opaque_keys.edx.locator import CourseLocator, LibraryLocator, LibraryLocatorV2 from rest_framework import status from rest_framework.decorators import action from rest_framework.exceptions import ParseError, PermissionDenied, ValidationError @@ -31,8 +31,11 @@ from ... import models from ...data import ( - SourceContextKey, ModulestoreMigration, ModulestoreBlockMigrationResult, - CompositionLevel, RepeatHandlingStrategy, + CompositionLevel, + ModulestoreBlockMigrationResult, + ModulestoreMigration, + RepeatHandlingStrategy, + SourceContextKey, ) from .serializers import ( BlockMigrationInfoSerializer, @@ -40,8 +43,8 @@ LibraryMigrationCourseSerializer, MigrationInfoResponseSerializer, ModulestoreMigrationSerializer, - StatusWithModulestoreMigrationsSerializer, PreviewMigrationSerializer, + StatusWithModulestoreMigrationsSerializer, ) log = logging.getLogger(__name__) diff --git a/cms/djangoapps/modulestore_migrator/tasks.py b/cms/djangoapps/modulestore_migrator/tasks.py index 6e821775440f..eb69bb4d1a62 100644 --- a/cms/djangoapps/modulestore_migrator/tasks.py +++ b/cms/djangoapps/modulestore_migrator/tasks.py @@ -51,10 +51,10 @@ from xmodule.modulestore import exceptions as modulestore_exceptions from xmodule.modulestore.django import modulestore -from . import models, data +from . import data, models +from .api.read_api import get_migration_blocks, get_migrations from .constants import CONTENT_STAGING_PURPOSE_TEMPLATE from .data import CompositionLevel, RepeatHandlingStrategy, SourceContextKey -from .api.read_api import get_migrations, get_migration_blocks log = get_task_logger(__name__) diff --git a/cms/djangoapps/modulestore_migrator/tests/test_api.py b/cms/djangoapps/modulestore_migrator/tests/test_api.py index ba7135ad87e1..311d2b5b69ea 100644 --- a/cms/djangoapps/modulestore_migrator/tests/test_api.py +++ b/cms/djangoapps/modulestore_migrator/tests/test_api.py @@ -2,9 +2,10 @@ Test cases for the modulestore migrator API. """ -import pytest from unittest.mock import patch -from opaque_keys.edx.locator import LibraryLocator, LibraryLocatorV2, CourseLocator + +import pytest +from opaque_keys.edx.locator import CourseLocator, LibraryLocator, LibraryLocatorV2 from openedx_content import api as content_api from openedx_content import models_api as content_models from organizations.tests.factories import OrganizationFactory @@ -15,9 +16,8 @@ from cms.djangoapps.modulestore_migrator.tests.factories import ModulestoreSourceFactory from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.content_libraries import api as lib_api - -from xmodule.modulestore.tests.utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import BlockFactory, LibraryFactory +from xmodule.modulestore.tests.utils import ModuleStoreTestCase @pytest.mark.django_db diff --git a/cms/djangoapps/modulestore_migrator/tests/test_rest_api.py b/cms/djangoapps/modulestore_migrator/tests/test_rest_api.py index 78472d41098c..a3682c0d2d47 100644 --- a/cms/djangoapps/modulestore_migrator/tests/test_rest_api.py +++ b/cms/djangoapps/modulestore_migrator/tests/test_rest_api.py @@ -9,9 +9,7 @@ from django.contrib.auth import get_user_model from django.test import TestCase -from opaque_keys.edx.locator import ( - BlockUsageLocator, CourseLocator, LibraryLocatorV2, LibraryUsageLocatorV2 -) +from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator, LibraryLocatorV2, LibraryUsageLocatorV2 from organizations.tests.factories import OrganizationFactory from rest_framework import status from rest_framework.exceptions import PermissionDenied @@ -19,14 +17,12 @@ from user_tasks.models import UserTaskStatus from cms.djangoapps.modulestore_migrator.data import ( - ModulestoreMigration, - ModulestoreBlockMigrationSuccess, ModulestoreBlockMigrationFailure, + ModulestoreBlockMigrationSuccess, + ModulestoreMigration, ) -from cms.djangoapps.modulestore_migrator.models import ( - ModulestoreMigration as ModulestoreMigrationModel, - ModulestoreSource, -) +from cms.djangoapps.modulestore_migrator.models import ModulestoreMigration as ModulestoreMigrationModel +from cms.djangoapps.modulestore_migrator.models import ModulestoreSource from cms.djangoapps.modulestore_migrator.rest_api.v1.views import ( BlockMigrationInfo, BulkMigrationViewSet, @@ -36,7 +32,6 @@ ) from openedx.core.djangoapps.content_libraries import api as lib_api - User = get_user_model() diff --git a/cms/djangoapps/modulestore_migrator/tests/test_tasks.py b/cms/djangoapps/modulestore_migrator/tests/test_tasks.py index 1f95f9d4024d..3ee2f76ca90a 100644 --- a/cms/djangoapps/modulestore_migrator/tests/test_tasks.py +++ b/cms/djangoapps/modulestore_migrator/tests/test_tasks.py @@ -16,10 +16,7 @@ from user_tasks.tasks import UserTaskStatus from cms.djangoapps.modulestore_migrator.data import CompositionLevel, RepeatHandlingStrategy -from cms.djangoapps.modulestore_migrator.models import ( - ModulestoreMigration, - ModulestoreSource, -) +from cms.djangoapps.modulestore_migrator.models import ModulestoreMigration, ModulestoreSource from cms.djangoapps.modulestore_migrator.tasks import ( MigrationStep, _BulkMigrationTask, @@ -33,7 +30,7 @@ from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.content_libraries import api as lib_api from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, LibraryFactory, BlockFactory +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory, LibraryFactory from .. import api as migrator_api diff --git a/cms/djangoapps/xblock_config/admin.py b/cms/djangoapps/xblock_config/admin.py index 6fa0afdfb979..eddd35256c33 100644 --- a/cms/djangoapps/xblock_config/admin.py +++ b/cms/djangoapps/xblock_config/admin.py @@ -8,5 +8,4 @@ from cms.djangoapps.xblock_config.models import StudioConfig - admin.site.register(StudioConfig, ConfigurationModelAdmin) diff --git a/cms/djangoapps/xblock_config/migrations/0001_squashed_0003_move_course_edit_lti_fields_enabled_flag_model_to_lti_consumer.py b/cms/djangoapps/xblock_config/migrations/0001_squashed_0003_move_course_edit_lti_fields_enabled_flag_model_to_lti_consumer.py index 0093da42bfea..1cd9f800f92d 100644 --- a/cms/djangoapps/xblock_config/migrations/0001_squashed_0003_move_course_edit_lti_fields_enabled_flag_model_to_lti_consumer.py +++ b/cms/djangoapps/xblock_config/migrations/0001_squashed_0003_move_course_edit_lti_fields_enabled_flag_model_to_lti_consumer.py @@ -1,9 +1,9 @@ # Generated by Django 2.2.24 on 2021-06-29 09:29 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import opaque_keys.edx.django.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/cms/envs/common.py b/cms/envs/common.py index dc74d9f5e8d4..c9b123e7c3c4 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -40,22 +40,19 @@ import importlib.util import os - -from corsheaders.defaults import default_headers as corsheaders_default_headers from datetime import timedelta +from corsheaders.defaults import default_headers as corsheaders_default_headers from django.utils.translation import gettext_lazy as _ from openedx_content.settings_api import openedx_content_backcompat_apps_to_install - -from openedx.envs.common import * # pylint: disable=wildcard-import - from path import Path as path from cms.lib.xblock.authoring_mixin import AuthoringMixin from cms.lib.xblock.upstream_sync import UpstreamSyncMixin -from xmodule.x_module import ResourceTemplates from openedx.core.lib.derived import Derived from openedx.core.lib.features_setting_proxy import FeaturesProxy +from openedx.envs.common import * # pylint: disable=wildcard-import +from xmodule.x_module import ResourceTemplates # A proxy for feature flags stored in the settings namespace FEATURES = FeaturesProxy(globals()) @@ -1080,7 +1077,8 @@ def make_lms_template_path(settings): ############## Installed Django Apps ######################### -from edx_django_utils.plugins import get_plugin_apps, add_plugins +from edx_django_utils.plugins import add_plugins, get_plugin_apps + from openedx.core.djangoapps.plugins.constants import ProjectType, SettingsType INSTALLED_APPS.extend(get_plugin_apps(ProjectType.CMS)) diff --git a/cms/envs/devstack.py b/cms/envs/devstack.py index 23f0c17cc531..41a6d4320889 100644 --- a/cms/envs/devstack.py +++ b/cms/envs/devstack.py @@ -1,3 +1,4 @@ +# ruff: noqa: I001 - settings file: star-import order is semantically significant """ Specific overrides to the base prod settings to make development easier. """ @@ -229,6 +230,7 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing # pylint: disable=wrong-import-order, wrong-import-position from edx_django_utils.plugins import add_plugins + # pylint: disable=wrong-import-order, wrong-import-position from openedx.core.djangoapps.plugins.constants import ProjectType, SettingsType diff --git a/cms/envs/docker-production.py b/cms/envs/docker-production.py index 17a8b7c71fa2..9f7475e831de 100644 --- a/cms/envs/docker-production.py +++ b/cms/envs/docker-production.py @@ -1,9 +1,10 @@ +# ruff: noqa: I001 - settings file: star-import order is semantically significant """ Specific overrides to the base prod settings for a docker production deployment. """ -from .production import * # pylint: disable=wildcard-import, unused-wildcard-import - from openedx.core.lib.logsettings import get_docker_logger_config +from .production import * # pylint: disable=wildcard-import, unused-wildcard-import + LOGGING = get_docker_logger_config() diff --git a/cms/envs/production.py b/cms/envs/production.py index c5ce5d9f5544..aba860f573c9 100644 --- a/cms/envs/production.py +++ b/cms/envs/production.py @@ -1,3 +1,4 @@ +# ruff: noqa: I001 - settings file: star-import order is semantically significant """ Override common.py with key-value pairs from YAML (plus some extra defaults & post-processing). @@ -13,8 +14,8 @@ import codecs import os import warnings -import yaml +import yaml from django.core.exceptions import ImproperlyConfigured from django.urls import reverse_lazy from edx_django_utils.plugins import add_plugins @@ -22,14 +23,13 @@ from path import Path as path from openedx.core.djangoapps.plugins.constants import ProjectType, SettingsType - -from .common import * - from openedx.core.lib.derived import derive_settings # lint-amnesty, pylint: disable=wrong-import-order +from openedx.core.lib.features_setting_proxy import FeaturesProxy from openedx.core.lib.logsettings import get_logger_config # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.modulestore_settings import convert_module_store_setting_if_needed # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.modulestore_settings import \ + convert_module_store_setting_if_needed # lint-amnesty, pylint: disable=wrong-import-order -from openedx.core.lib.features_setting_proxy import FeaturesProxy +from .common import * # A proxy for feature flags stored in the settings namespace FEATURES = FeaturesProxy(globals()) diff --git a/cms/envs/test.py b/cms/envs/test.py index d8cd3f3f9577..91e1091017d1 100644 --- a/cms/envs/test.py +++ b/cms/envs/test.py @@ -13,21 +13,20 @@ # pylint: disable=wildcard-import, unused-wildcard-import -import os + +import os # noqa: I001 - suppresses linting for this whole block, sort imports manually as needed import tempfile from django.utils.translation import gettext_lazy from edx_django_utils.plugins import add_plugins -from xmodule.modulestore.modulestore_settings import update_module_store_settings # pylint: disable=wrong-import-order - from openedx.core.djangoapps.plugins.constants import ProjectType, SettingsType from openedx.core.lib.derived import derive_settings from openedx.core.lib.features_setting_proxy import FeaturesProxy +from xmodule.modulestore.modulestore_settings import update_module_store_settings # pylint: disable=wrong-import-order from .common import * - -from openedx.envs.test import * # pylint: disable=wrong-import-order +from openedx.envs.test import * # must come after .common to override Derived values with literals # A proxy for feature flags stored in the settings namespace FEATURES = FeaturesProxy(globals()) diff --git a/cms/lib/xblock/authoring_mixin.py b/cms/lib/xblock/authoring_mixin.py index 3551059cd0c9..64fdbe9799d6 100644 --- a/cms/lib/xblock/authoring_mixin.py +++ b/cms/lib/xblock/authoring_mixin.py @@ -8,8 +8,7 @@ from django.conf import settings from web_fragments.fragment import Fragment from xblock.core import XBlock, XBlockMixin -from xblock.fields import String, Scope - +from xblock.fields import Scope, String log = logging.getLogger(__name__) diff --git a/cms/lib/xblock/tagging/test.py b/cms/lib/xblock/tagging/test.py index cee2bf5e000c..9dd86b982332 100644 --- a/cms/lib/xblock/tagging/test.py +++ b/cms/lib/xblock/tagging/test.py @@ -24,8 +24,13 @@ from common.djangoapps.student.tests.factories import UserFactory from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) @ddt.ddt diff --git a/cms/lib/xblock/test/test_authoring_mixin.py b/cms/lib/xblock/test/test_authoring_mixin.py index eee86df8bf4f..1cbafe959fa8 100644 --- a/cms/lib/xblock/test/test_authoring_mixin.py +++ b/cms/lib/xblock/test/test_authoring_mixin.py @@ -6,18 +6,18 @@ from django.conf import settings from django.test.utils import override_settings from xblock.core import XBlock + +from common.djangoapps.course_modes.tests.factories import CourseModeFactory from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory from xmodule.partitions.partitions import ( ENROLLMENT_TRACK_PARTITION_ID, MINIMUM_UNUSED_PARTITION_ID, Group, - UserPartition + UserPartition, ) from xmodule.tests.test_export import PureXBlock -from common.djangoapps.course_modes.tests.factories import CourseModeFactory - class AuthoringMixinTestCase(ModuleStoreTestCase): """ diff --git a/cms/lib/xblock/test/test_runtime.py b/cms/lib/xblock/test/test_runtime.py index 42b79a176ffb..51160175c288 100644 --- a/cms/lib/xblock/test/test_runtime.py +++ b/cms/lib/xblock/test/test_runtime.py @@ -4,9 +4,8 @@ from unittest import TestCase -from urllib.parse import urlparse - from unittest.mock import Mock +from urllib.parse import urlparse from cms.lib.xblock.runtime import handler_url diff --git a/cms/lib/xblock/test/test_upstream_sync.py b/cms/lib/xblock/test/test_upstream_sync.py index 1af3914658ce..964e559c270b 100644 --- a/cms/lib/xblock/test/test_upstream_sync.py +++ b/cms/lib/xblock/test/test_upstream_sync.py @@ -7,6 +7,7 @@ from organizations.api import ensure_organization from organizations.models import Organization +from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import save_xblock_with_callback from cms.lib.xblock.upstream_sync import ( BadDownstream, BadUpstream, @@ -15,8 +16,7 @@ decline_sync, sever_upstream_link, ) -from cms.lib.xblock.upstream_sync_block import sync_from_upstream_block, fetch_customizable_fields_from_block -from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import save_xblock_with_callback +from cms.lib.xblock.upstream_sync_block import fetch_customizable_fields_from_block, sync_from_upstream_block from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.content_libraries import api as libs from openedx.core.djangoapps.content_tagging import api as tagging_api diff --git a/cms/lib/xblock/upstream_sync.py b/cms/lib/xblock/upstream_sync.py index 21f4201cdfde..ada38ff8a265 100644 --- a/cms/lib/xblock/upstream_sync.py +++ b/cms/lib/xblock/upstream_sync.py @@ -253,9 +253,10 @@ def get_for_block(cls, downstream: XBlock) -> t.Self: Otherwise, raises an UpstreamLinkException. """ # We import these here b/c UpstreamSyncMixin is used by cms/envs, which loads before the djangoapps are ready. - from openedx.core.djangoapps.content_libraries import api as lib_api from openedx_content import api as content_api + from openedx.core.djangoapps.content_libraries import api as lib_api + if not isinstance(downstream, UpstreamSyncMixin): raise BadDownstream(_("Downstream is not an XBlock or is missing required UpstreamSyncMixin")) if not downstream.upstream: diff --git a/cms/lib/xblock/upstream_sync_block.py b/cms/lib/xblock/upstream_sync_block.py index 6b5d14ffc5ed..7099080511ef 100644 --- a/cms/lib/xblock/upstream_sync_block.py +++ b/cms/lib/xblock/upstream_sync_block.py @@ -96,7 +96,11 @@ def _load_upstream_block(downstream: XBlock, user: User) -> XBlock: If `downstream` lacks a valid+supported upstream link, this raises an UpstreamLinkException. """ # We import load_block here b/c UpstreamSyncMixin is used by cms/envs, which loads before the djangoapps are ready. - from openedx.core.djangoapps.xblock.api import load_block, CheckPerm, LatestVersion # pylint: disable=wrong-import-order + from openedx.core.djangoapps.xblock.api import ( # pylint: disable=wrong-import-order + CheckPerm, + LatestVersion, + load_block, + ) try: lib_block: XBlock = load_block( LibraryUsageLocatorV2.from_string(downstream.upstream), @@ -190,6 +194,7 @@ def _update_tags(*, upstream: XBlock, downstream: XBlock) -> None: Update tags from `upstream` to `downstream` """ from openedx.core.djangoapps.content_tagging.api import copy_tags_as_read_only + # For any block synced with an upstream, copy the tags as read_only # This keeps tags added locally. copy_tags_as_read_only( diff --git a/cms/lib/xblock/upstream_sync_container.py b/cms/lib/xblock/upstream_sync_container.py index 4e8302323808..59b5beb262ac 100644 --- a/cms/lib/xblock/upstream_sync_container.py +++ b/cms/lib/xblock/upstream_sync_container.py @@ -13,6 +13,7 @@ from xblock.core import XBlock from openedx.core.djangoapps.content_libraries import api as lib_api + from .upstream_sync import UpstreamLink if t.TYPE_CHECKING: @@ -131,6 +132,7 @@ def _update_tags(*, upstream: lib_api.ContainerMetadata, downstream: XBlock) -> Update tags from `upstream` to `downstream` """ from openedx.core.djangoapps.content_tagging.api import copy_tags_as_read_only + # For any block synced with an upstream, copy the tags as read_only # This keeps tags added locally. copy_tags_as_read_only( diff --git a/cms/urls.py b/cms/urls.py index 048339bc9fe9..d7414bc2a1a9 100644 --- a/cms/urls.py +++ b/cms/urls.py @@ -2,15 +2,14 @@ Urls of Studio. """ +from auth_backends.urls import oauth2_urlpatterns from django.conf import settings from django.conf.urls.static import static +from django.contrib import admin from django.contrib.admin import autodiscover as django_autodiscover -from django.urls import include -from django.urls import path, re_path +from django.urls import include, path, re_path from django.utils.translation import gettext_lazy as _ -from django.contrib import admin from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView -from auth_backends.urls import oauth2_urlpatterns from edx_api_doc_tools import make_docs_urls import openedx.core.djangoapps.common_views.xblock @@ -20,11 +19,10 @@ from cms.djangoapps.contentstore import views as contentstore_views from cms.djangoapps.contentstore.views.block import xblock_edit_view from cms.djangoapps.contentstore.views.organization import OrganizationListView +from openedx.core import toggles as core_toggles from openedx.core.apidocs import api_info from openedx.core.djangoapps.password_policy import compliance as password_policy_compliance from openedx.core.djangoapps.password_policy.forms import PasswordPolicyAwareAdminAuthForm -from openedx.core import toggles as core_toggles - django_autodiscover() admin.site.site_header = _('Studio Administration') @@ -265,11 +263,11 @@ # Enable Web/HTML Certificates if settings.FEATURES.get('CERTIFICATES_HTML_VIEW'): - from cms.djangoapps.contentstore.views.certificates import ( + from cms.djangoapps.contentstore.views.certificates import ( # noqa: I001 - conditional import inside if block CertificateActivationAPIView, CertificateDetailAPIView, certificates_list_handler, - signatory_detail_handler, + signatory_detail_handler ) urlpatterns += [ @@ -344,9 +342,9 @@ ] # pylint: disable=wrong-import-position, wrong-import-order -from edx_django_utils.plugins import get_plugin_url_patterns # isort:skip +from edx_django_utils.plugins import get_plugin_url_patterns # noqa: I001 - must be after urlpatterns are built # pylint: disable=wrong-import-position -from openedx.core.djangoapps.plugins.constants import ProjectType # isort:skip +from openedx.core.djangoapps.plugins.constants import ProjectType # noqa: I001 - must be after urlpatterns are built urlpatterns.extend(get_plugin_url_patterns(ProjectType.CMS)) diff --git a/cms/urls_dev.py b/cms/urls_dev.py index 200d8576917b..1aed9c131c3a 100644 --- a/cms/urls_dev.py +++ b/cms/urls_dev.py @@ -6,6 +6,7 @@ from django.urls import path + from cms.djangoapps.contentstore.views.dev import dev_mode urlpatterns = [ diff --git a/cms/wsgi.py b/cms/wsgi.py index 9c9af4299844..10a8292b7e47 100644 --- a/cms/wsgi.py +++ b/cms/wsgi.py @@ -1,3 +1,4 @@ +# ruff: noqa: I001 """ WSGI config for CMS. @@ -8,7 +9,6 @@ ``WSGI_APPLICATION`` setting. Import sorting is intentionally disabled in this module. -isort:skip_file """ # Patch the xml libs before anything else. diff --git a/common/djangoapps/course_modes/admin.py b/common/djangoapps/course_modes/admin.py index 76eabd20bf80..c9650c2c341b 100644 --- a/common/djangoapps/course_modes/admin.py +++ b/common/djangoapps/course_modes/admin.py @@ -11,6 +11,8 @@ from opaque_keys.edx.keys import CourseKey from common.djangoapps.course_modes.models import CourseMode, CourseModeExpirationConfig +from common.djangoapps.util.date_utils import get_time_display + # Technically, we shouldn't be doing this, since verify_student is defined # in LMS, and course_modes is defined in common. # @@ -23,7 +25,6 @@ # the verification deadline table won't exist. from lms.djangoapps.verify_student import models as verification_models from openedx.core.lib.courses import clean_course_id -from common.djangoapps.util.date_utils import get_time_display COURSE_MODE_SLUG_CHOICES = [(key, enrollment_mode['display_name']) for key, enrollment_mode in settings.COURSE_ENROLLMENT_MODES.items()] diff --git a/common/djangoapps/course_modes/migrations/0012_historicalcoursemode.py b/common/djangoapps/course_modes/migrations/0012_historicalcoursemode.py index 48d0a39cf4ce..45c3c05357e2 100644 --- a/common/djangoapps/course_modes/migrations/0012_historicalcoursemode.py +++ b/common/djangoapps/course_modes/migrations/0012_historicalcoursemode.py @@ -1,12 +1,13 @@ # Generated by Django 1.11.21 on 2019-06-19 01:31 -from django.conf import settings +import re + import django.core.validators -from django.db import migrations, models import django.db.models.deletion -import re import simple_history.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/common/djangoapps/course_modes/models.py b/common/djangoapps/course_modes/models.py index a739a9076fac..25428305c155 100644 --- a/common/djangoapps/course_modes/models.py +++ b/common/djangoapps/course_modes/models.py @@ -3,9 +3,10 @@ """ +import logging from collections import defaultdict, namedtuple from datetime import timedelta -import logging + from config_models.models import ConfigurationModel from django.conf import settings from django.core.exceptions import ValidationError @@ -13,7 +14,6 @@ from django.db import models from django.db.models import Q from django.dispatch import receiver - from django.utils.timezone import now from django.utils.translation import gettext_lazy as _ from edx_django_utils.cache import RequestCache diff --git a/common/djangoapps/course_modes/rest_api/serializers.py b/common/djangoapps/course_modes/rest_api/serializers.py index 862bb34de3ff..c8ce6f5a46e2 100644 --- a/common/djangoapps/course_modes/rest_api/serializers.py +++ b/common/djangoapps/course_modes/rest_api/serializers.py @@ -3,8 +3,8 @@ """ -from rest_framework import serializers from opaque_keys.edx.keys import CourseKey +from rest_framework import serializers from common.djangoapps.course_modes.models import CourseMode from openedx.core.djangoapps.content.course_overviews.models import CourseOverview diff --git a/common/djangoapps/course_modes/rest_api/urls.py b/common/djangoapps/course_modes/rest_api/urls.py index 9c807b0c1138..8510b5794c56 100644 --- a/common/djangoapps/course_modes/rest_api/urls.py +++ b/common/djangoapps/course_modes/rest_api/urls.py @@ -3,8 +3,7 @@ """ -from django.urls import include -from django.urls import path +from django.urls import include, path app_name = 'common.djangoapps.course_modes.rest_api' diff --git a/common/djangoapps/course_modes/rest_api/v1/tests/test_views.py b/common/djangoapps/course_modes/rest_api/v1/tests/test_views.py index 33e06e857cd8..008c16897b22 100644 --- a/common/djangoapps/course_modes/rest_api/v1/tests/test_views.py +++ b/common/djangoapps/course_modes/rest_api/v1/tests/test_views.py @@ -10,14 +10,16 @@ from rest_framework import status from rest_framework.test import APITestCase -from common.djangoapps.course_modes.rest_api.v1.views import CourseModesView from common.djangoapps.course_modes.models import CourseMode +from common.djangoapps.course_modes.rest_api.v1.views import CourseModesView from common.djangoapps.course_modes.tests.factories import CourseModeFactory +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangoapps.user_authn.tests.utils import JWT_AUTH_TYPES, AuthAndScopesTestMixin, AuthType from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) @ddt.ddt diff --git a/common/djangoapps/course_modes/rest_api/v1/urls.py b/common/djangoapps/course_modes/rest_api/v1/urls.py index 6a066d7e6357..4ff01e3115a3 100644 --- a/common/djangoapps/course_modes/rest_api/v1/urls.py +++ b/common/djangoapps/course_modes/rest_api/v1/urls.py @@ -4,8 +4,8 @@ from django.conf import settings - from django.urls import re_path + from common.djangoapps.course_modes.rest_api.v1 import views app_name = 'v1' diff --git a/common/djangoapps/course_modes/rest_api/v1/views.py b/common/djangoapps/course_modes/rest_api/v1/views.py index 7c37d8596de8..60fe3341ade1 100644 --- a/common/djangoapps/course_modes/rest_api/v1/views.py +++ b/common/djangoapps/course_modes/rest_api/v1/views.py @@ -14,8 +14,8 @@ from rest_framework.generics import ListCreateAPIView, RetrieveUpdateDestroyAPIView from rest_framework.response import Response -from common.djangoapps.course_modes.rest_api.serializers import CourseModeSerializer from common.djangoapps.course_modes.models import CourseMode +from common.djangoapps.course_modes.rest_api.serializers import CourseModeSerializer from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser from openedx.core.lib.api.parsers import MergePatchParser diff --git a/common/djangoapps/course_modes/tests/test_admin.py b/common/djangoapps/course_modes/tests/test_admin.py index 7a01b6794987..5b347bc4d812 100644 --- a/common/djangoapps/course_modes/tests/test_admin.py +++ b/common/djangoapps/course_modes/tests/test_admin.py @@ -3,16 +3,19 @@ """ from datetime import datetime, timedelta +from zoneinfo import ZoneInfo import ddt from django.conf import settings from django.urls import reverse from pytz import timezone -from zoneinfo import ZoneInfo from common.djangoapps.course_modes.admin import CourseModeForm from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory +from common.djangoapps.student.tests.factories import UserFactory +from common.djangoapps.util.date_utils import get_time_display + # Technically, we shouldn't be importing verify_student, since it's # defined in the LMS and course_modes is in common. However, the benefits # of putting all this configuration in one place outweigh the downsides. @@ -20,9 +23,9 @@ from lms.djangoapps.verify_student.models import VerificationDeadline from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.tests.factories import UserFactory -from common.djangoapps.util.date_utils import get_time_display -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/common/djangoapps/course_modes/tests/test_models.py b/common/djangoapps/course_modes/tests/test_models.py index 35ea05f69203..c8d97f55fb97 100644 --- a/common/djangoapps/course_modes/tests/test_models.py +++ b/common/djangoapps/course_modes/tests/test_models.py @@ -21,11 +21,13 @@ CourseMode, Mode, get_cosmetic_display_price, - invalidate_course_mode_cache + invalidate_course_mode_cache, ) from common.djangoapps.course_modes.tests.factories import CourseModeFactory from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/common/djangoapps/course_modes/tests/test_signals.py b/common/djangoapps/course_modes/tests/test_signals.py index e4323f825a25..dfe87101892b 100644 --- a/common/djangoapps/course_modes/tests/test_signals.py +++ b/common/djangoapps/course_modes/tests/test_signals.py @@ -13,9 +13,16 @@ from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.signals import _listen_for_course_publish from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) +from xmodule.partitions.partitions import ( + ENROLLMENT_TRACK_PARTITION_ID, # lint-amnesty, pylint: disable=wrong-import-order +) @ddt.ddt diff --git a/common/djangoapps/course_modes/tests/test_views.py b/common/djangoapps/course_modes/tests/test_views.py index 65b4980eba01..062fcc8fb025 100644 --- a/common/djangoapps/course_modes/tests/test_views.py +++ b/common/djangoapps/course_modes/tests/test_views.py @@ -29,7 +29,9 @@ from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme from openedx.core.djangolib.testing.utils import skip_unless_lms from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order # Name of the method to mock for Content Type Gating. diff --git a/common/djangoapps/course_modes/urls.py b/common/djangoapps/course_modes/urls.py index 8c3e562688d8..c02486789abe 100644 --- a/common/djangoapps/course_modes/urls.py +++ b/common/djangoapps/course_modes/urls.py @@ -2,8 +2,8 @@ from django.conf import settings - from django.urls import re_path + from common.djangoapps.course_modes import views urlpatterns = [ diff --git a/common/djangoapps/course_modes/views.py b/common/djangoapps/course_modes/views.py index 09164dc40e7c..2824214e27b2 100644 --- a/common/djangoapps/course_modes/views.py +++ b/common/djangoapps/course_modes/views.py @@ -6,6 +6,7 @@ import decimal import json import logging +from urllib.parse import urljoin # lint-amnesty, pylint: disable=wrong-import-order import six import waffle # lint-amnesty, pylint: disable=invalid-django-waffle-import @@ -23,12 +24,13 @@ from django.views.generic.base import View from edx_django_utils.monitoring.utils import increment from opaque_keys.edx.keys import CourseKey -from urllib.parse import urljoin # lint-amnesty, pylint: disable=wrong-import-order -from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.helpers import get_course_final_price, get_verified_track_links +from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.edxmako.shortcuts import render_to_response +from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.util.date_utils import strftime_localized_html +from common.djangoapps.util.db import outer_atomic from lms.djangoapps.commerce.utils import EcommerceService from lms.djangoapps.experiments.utils import get_experiment_user_metadata_context from lms.djangoapps.verify_student.services import IDVerificationService @@ -36,12 +38,10 @@ from openedx.core.djangoapps.embargo import api as embargo_api from openedx.core.djangoapps.enrollments.permissions import ENROLL_IN_COURSE from openedx.features.content_type_gating.models import ContentTypeGatingConfig -from openedx.features.course_duration_limits.models import CourseDurationLimitConfig from openedx.features.course_duration_limits.access import get_user_course_duration, get_user_course_expiration_date +from openedx.features.course_duration_limits.models import CourseDurationLimitConfig from openedx.features.course_experience import course_home_url from openedx.features.enterprise_support.api import enterprise_customer_for_request -from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.util.db import outer_atomic from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order LOG = logging.getLogger(__name__) diff --git a/common/djangoapps/edxmako/__init__.py b/common/djangoapps/edxmako/__init__.py index 29b1342dedd0..f319d5b97afe 100644 --- a/common/djangoapps/edxmako/__init__.py +++ b/common/djangoapps/edxmako/__init__.py @@ -13,7 +13,12 @@ # limitations under the License. LOOKUP = {} -from .paths import add_lookup, clear_lookups, lookup_template, save_lookups # lint-amnesty, pylint: disable=wrong-import-position +from .paths import ( # lint-amnesty, pylint: disable=wrong-import-position + add_lookup, + clear_lookups, + lookup_template, + save_lookups, +) class Engines: diff --git a/common/djangoapps/edxmako/paths.py b/common/djangoapps/edxmako/paths.py index 3da9844eedc2..cd44dfaa379e 100644 --- a/common/djangoapps/edxmako/paths.py +++ b/common/djangoapps/edxmako/paths.py @@ -3,8 +3,8 @@ """ import contextlib import hashlib -import os import importlib.resources as resources +import os from django.conf import settings from mako.exceptions import TopLevelLookupException diff --git a/common/djangoapps/edxmako/services.py b/common/djangoapps/edxmako/services.py index f3fb5bfe7ce1..79ff9c7fca4a 100644 --- a/common/djangoapps/edxmako/services.py +++ b/common/djangoapps/edxmako/services.py @@ -5,8 +5,8 @@ from django.template.utils import InvalidTemplateEngineError from xblock.reference.plugins import Service -from common.djangoapps.edxmako.shortcuts import render_to_string from common.djangoapps.edxmako import Engines +from common.djangoapps.edxmako.shortcuts import render_to_string try: engines[Engines.PREVIEW] diff --git a/common/djangoapps/edxmako/shortcuts.py b/common/djangoapps/edxmako/shortcuts.py index a8b0e7a0d9f5..f08fcef65b22 100644 --- a/common/djangoapps/edxmako/shortcuts.py +++ b/common/djangoapps/edxmako/shortcuts.py @@ -16,14 +16,14 @@ import logging from django.conf import settings +from django.core.exceptions import ValidationError +from django.core.validators import URLValidator from django.http import HttpResponse # lint-amnesty, pylint: disable=unused-import from django.template import engines -from django.urls import reverse, NoReverseMatch +from django.urls import NoReverseMatch, reverse +from edx_django_utils.monitoring import set_custom_attribute from six.moves.urllib.parse import urljoin -from django.core.validators import URLValidator -from django.core.exceptions import ValidationError -from edx_django_utils.monitoring import set_custom_attribute from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from xmodule.util.xmodule_django import get_current_request_hostname # lint-amnesty, pylint: disable=wrong-import-order diff --git a/common/djangoapps/edxmako/template.py b/common/djangoapps/edxmako/template.py index 855a2714b865..ec67cc92b222 100644 --- a/common/djangoapps/edxmako/template.py +++ b/common/djangoapps/edxmako/template.py @@ -14,11 +14,11 @@ from django.conf import settings -from django.template import Context, engines, Origin +from django.template import Context, Origin, engines from edx_django_utils.cache import RequestCache from mako.template import Template as MakoTemplate -from . import Engines, LOOKUP +from . import LOOKUP, Engines from .request_context import get_template_request_context from .shortcuts import is_any_marketing_link_set, is_marketing_link_set, marketing_link diff --git a/common/djangoapps/edxmako/tests.py b/common/djangoapps/edxmako/tests.py index 51c2ab4efdd1..0386db0cb472 100644 --- a/common/djangoapps/edxmako/tests.py +++ b/common/djangoapps/edxmako/tests.py @@ -18,7 +18,7 @@ is_any_marketing_link_set, is_marketing_link_set, marketing_link, - render_to_string + render_to_string, ) from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.util.testing import UrlResetMixin diff --git a/common/djangoapps/entitlements/management/commands/expire_and_create_entitlements.py b/common/djangoapps/entitlements/management/commands/expire_and_create_entitlements.py index 482d8dc8fe5d..01dea8ef3022 100644 --- a/common/djangoapps/entitlements/management/commands/expire_and_create_entitlements.py +++ b/common/djangoapps/entitlements/management/commands/expire_and_create_entitlements.py @@ -4,14 +4,14 @@ """ import logging from datetime import date -from dateutil.relativedelta import relativedelta from math import ceil from textwrap import dedent +from dateutil.relativedelta import relativedelta from django.core.management import BaseCommand -from common.djangoapps.entitlements.tasks import expire_and_create_entitlements from common.djangoapps.entitlements.models import CourseEntitlement +from common.djangoapps.entitlements.tasks import expire_and_create_entitlements logger = logging.getLogger(__name__) # pylint: disable=invalid-name diff --git a/common/djangoapps/entitlements/migrations/0011_historicalcourseentitlement.py b/common/djangoapps/entitlements/migrations/0011_historicalcourseentitlement.py index def96d3e9920..8fcaf7b5a821 100644 --- a/common/djangoapps/entitlements/migrations/0011_historicalcourseentitlement.py +++ b/common/djangoapps/entitlements/migrations/0011_historicalcourseentitlement.py @@ -1,13 +1,14 @@ # Generated by Django 1.11.20 on 2019-05-30 21:13 -from django.conf import settings -from django.db import migrations, models +import uuid + import django.db.models.deletion import django.utils.timezone import model_utils.fields import simple_history.models -import uuid +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): # lint-amnesty, pylint: disable=missing-class-docstring diff --git a/common/djangoapps/entitlements/migrations/0013_historicalcourseentitlementsupportdetail.py b/common/djangoapps/entitlements/migrations/0013_historicalcourseentitlementsupportdetail.py index e80a5e9ce2c2..f2978a55246a 100644 --- a/common/djangoapps/entitlements/migrations/0013_historicalcourseentitlementsupportdetail.py +++ b/common/djangoapps/entitlements/migrations/0013_historicalcourseentitlementsupportdetail.py @@ -1,12 +1,12 @@ # Generated by Django 1.11.26 on 2019-12-17 14:08 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields import simple_history.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): # lint-amnesty, pylint: disable=missing-class-docstring diff --git a/common/djangoapps/entitlements/models.py b/common/djangoapps/entitlements/models.py index 78559c538011..4cf60c02b1e7 100644 --- a/common/djangoapps/entitlements/models.py +++ b/common/djangoapps/entitlements/models.py @@ -8,7 +8,6 @@ from django.conf import settings from django.contrib.sites.models import Site from django.db import IntegrityError, models, transaction - from django.utils.timezone import now from model_utils import Choices from model_utils.models import TimeStampedModel diff --git a/common/djangoapps/entitlements/rest_api/urls.py b/common/djangoapps/entitlements/rest_api/urls.py index 740bce95a7c2..154e0919fe6d 100644 --- a/common/djangoapps/entitlements/rest_api/urls.py +++ b/common/djangoapps/entitlements/rest_api/urls.py @@ -2,8 +2,7 @@ URLs file for the Entitlements API. """ -from django.urls import include -from django.urls import path +from django.urls import include, path app_name = 'entitlements' urlpatterns = [ diff --git a/common/djangoapps/entitlements/rest_api/v1/tests/test_views.py b/common/djangoapps/entitlements/rest_api/v1/tests/test_views.py index 2f007ae6ed3b..6a834edccdcd 100644 --- a/common/djangoapps/entitlements/rest_api/v1/tests/test_views.py +++ b/common/djangoapps/entitlements/rest_api/v1/tests/test_views.py @@ -23,8 +23,9 @@ from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory from openedx.core.djangoapps.user_api.models import UserOrgTag from openedx.core.djangolib.testing.utils import skip_unless_lms -from xmodule.modulestore.tests.django_utils import \ - ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order log = logging.getLogger(__name__) @@ -34,7 +35,7 @@ from common.djangoapps.entitlements.models import ( # lint-amnesty, pylint: disable=line-too-long CourseEntitlement, CourseEntitlementPolicy, - CourseEntitlementSupportDetail + CourseEntitlementSupportDetail, ) from common.djangoapps.entitlements.rest_api.v1.serializers import CourseEntitlementSerializer from common.djangoapps.entitlements.rest_api.v1.views import set_entitlement_policy diff --git a/common/djangoapps/entitlements/rest_api/v1/urls.py b/common/djangoapps/entitlements/rest_api/v1/urls.py index e04341b5ef50..434fb356403f 100644 --- a/common/djangoapps/entitlements/rest_api/v1/urls.py +++ b/common/djangoapps/entitlements/rest_api/v1/urls.py @@ -2,8 +2,7 @@ URLs for the V1 of the Entitlements API. """ -from django.urls import include -from django.urls import path, re_path +from django.urls import include, path, re_path from rest_framework.routers import DefaultRouter from .views import EntitlementEnrollmentViewSet, EntitlementViewSet diff --git a/common/djangoapps/entitlements/rest_api/v1/views.py b/common/djangoapps/entitlements/rest_api/v1/views.py index 4f3dd54b52a7..fd60e462d7dd 100644 --- a/common/djangoapps/entitlements/rest_api/v1/views.py +++ b/common/djangoapps/entitlements/rest_api/v1/views.py @@ -20,7 +20,7 @@ from common.djangoapps.entitlements.models import ( # lint-amnesty, pylint: disable=line-too-long CourseEntitlement, CourseEntitlementPolicy, - CourseEntitlementSupportDetail + CourseEntitlementSupportDetail, ) from common.djangoapps.entitlements.rest_api.v1.filters import CourseEntitlementFilter from common.djangoapps.entitlements.rest_api.v1.permissions import IsAdminOrSupportOrAuthenticatedReadOnly diff --git a/common/djangoapps/entitlements/tests/test_models.py b/common/djangoapps/entitlements/tests/test_models.py index e0500da454a2..4abac33fbe83 100644 --- a/common/djangoapps/entitlements/tests/test_models.py +++ b/common/djangoapps/entitlements/tests/test_models.py @@ -17,13 +17,15 @@ from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangolib.testing.utils import skip_unless_lms -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order # Entitlements is not in CMS' INSTALLED_APPS so these imports will error during test collection if settings.ROOT_URLCONF == 'lms.urls': - from common.djangoapps.entitlements.tests.factories import CourseEntitlementFactory from common.djangoapps.entitlements.models import CourseEntitlement + from common.djangoapps.entitlements.tests.factories import CourseEntitlementFactory @skip_unless_lms diff --git a/common/djangoapps/entitlements/tests/test_utils.py b/common/djangoapps/entitlements/tests/test_utils.py index cc2235edb028..0be720b2aa57 100644 --- a/common/djangoapps/entitlements/tests/test_utils.py +++ b/common/djangoapps/entitlements/tests/test_utils.py @@ -15,10 +15,12 @@ TEST_PASSWORD, CourseEnrollmentFactory, CourseOverviewFactory, - UserFactory + UserFactory, ) from openedx.core.djangolib.testing.utils import skip_unless_lms -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) # Entitlements is not in CMS' INSTALLED_APPS so these imports will error during test collection if settings.ROOT_URLCONF == 'lms.urls': diff --git a/common/djangoapps/split_modulestore_django/migrations/0001_initial.py b/common/djangoapps/split_modulestore_django/migrations/0001_initial.py index 46f3381044ba..76041ecb0e54 100644 --- a/common/djangoapps/split_modulestore_django/migrations/0001_initial.py +++ b/common/djangoapps/split_modulestore_django/migrations/0001_initial.py @@ -1,10 +1,10 @@ # Generated by Django 2.2.20 on 2021-05-07 18:29, manually modified to make "course_id" column case sensitive -from django.conf import settings -from django.db import migrations, models, connection import django.db.models.deletion import opaque_keys.edx.django.models import simple_history.models +from django.conf import settings +from django.db import connection, migrations, models def generate_split_module_sql(db_engine): diff --git a/common/djangoapps/split_modulestore_django/migrations/0002_data_migration.py b/common/djangoapps/split_modulestore_django/migrations/0002_data_migration.py index b7abc10a984c..ba9f16f44e58 100644 --- a/common/djangoapps/split_modulestore_django/migrations/0002_data_migration.py +++ b/common/djangoapps/split_modulestore_django/migrations/0002_data_migration.py @@ -1,4 +1,5 @@ import logging + from django.db import migrations, models from django.db.utils import IntegrityError diff --git a/common/djangoapps/split_modulestore_django/migrations/0004_courseid_unique_ci.py b/common/djangoapps/split_modulestore_django/migrations/0004_courseid_unique_ci.py index 90aa952be2fe..125e0b3db028 100644 --- a/common/djangoapps/split_modulestore_django/migrations/0004_courseid_unique_ci.py +++ b/common/djangoapps/split_modulestore_django/migrations/0004_courseid_unique_ci.py @@ -1,8 +1,8 @@ # Generated by Django 5.2.11 on 2026-02-19 23:23 import django.db.models.functions.text -from django.db import migrations, models import opaque_keys.edx.django.models +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/common/djangoapps/split_modulestore_django/models.py b/common/djangoapps/split_modulestore_django/models.py index a3c5b6604f3a..6d4f92037fc1 100644 --- a/common/djangoapps/split_modulestore_django/models.py +++ b/common/djangoapps/split_modulestore_django/models.py @@ -4,8 +4,8 @@ from bson.objectid import ObjectId from django.contrib.auth import get_user_model from django.db import models -from opaque_keys.edx.locator import CourseLocator, LibraryLocator from opaque_keys.edx.django.models import LearningContextKeyField +from opaque_keys.edx.locator import CourseLocator, LibraryLocator from simple_history.models import HistoricalRecords from xmodule.modulestore import ModuleStoreEnum diff --git a/common/djangoapps/split_modulestore_django/tests/test_models.py b/common/djangoapps/split_modulestore_django/tests/test_models.py index 8cdb1797abda..a6db12aa8fb8 100644 --- a/common/djangoapps/split_modulestore_django/tests/test_models.py +++ b/common/djangoapps/split_modulestore_django/tests/test_models.py @@ -1,11 +1,11 @@ """ Unit tests for SplitModulestoreCourseIndex """ from datetime import datetime +import pytest from bson.objectid import ObjectId from django.db import IntegrityError, transaction from django.test import TestCase from opaque_keys.edx.keys import CourseKey -import pytest from common.djangoapps.split_modulestore_django.models import SplitModulestoreCourseIndex from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order diff --git a/common/djangoapps/static_replace/services.py b/common/djangoapps/static_replace/services.py index 010cb96be0d3..348602b9cefb 100644 --- a/common/djangoapps/static_replace/services.py +++ b/common/djangoapps/static_replace/services.py @@ -4,11 +4,7 @@ from xblock.reference.plugins import Service -from common.djangoapps.static_replace import ( - replace_course_urls, - replace_jump_to_id_urls, - replace_static_urls -) +from common.djangoapps.static_replace import replace_course_urls, replace_jump_to_id_urls, replace_static_urls class ReplaceURLService(Service): diff --git a/common/djangoapps/static_replace/test/test_static_replace.py b/common/djangoapps/static_replace/test/test_static_replace.py index c71f8fa15c6a..1d6cc6fe43f5 100644 --- a/common/djangoapps/static_replace/test/test_static_replace.py +++ b/common/djangoapps/static_replace/test/test_static_replace.py @@ -1,10 +1,9 @@ """Tests for static_replace""" -from functools import partial - import re +from functools import partial from io import BytesIO from unittest.mock import Mock, patch -from urllib.parse import parse_qsl, quote, urlparse, urlunparse, urlencode +from urllib.parse import parse_qsl, quote, urlencode, urlparse, urlunparse import ddt import pytest @@ -18,8 +17,8 @@ make_static_urls_absolute, process_static_urls, replace_course_urls, - replace_static_urls, replace_jump_to_id_urls, + replace_static_urls, ) from common.djangoapps.static_replace.services import ReplaceURLService from common.djangoapps.static_replace.wrapper import replace_urls_wrapper @@ -30,8 +29,13 @@ from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.mongo import MongoModuleStore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + CourseFactory, + check_mongo_calls, +) from xmodule.modulestore.xml import XMLModuleStore # lint-amnesty, pylint: disable=wrong-import-order DATA_DIRECTORY = 'data_dir' diff --git a/common/djangoapps/status/models.py b/common/djangoapps/status/models.py index 6685643432a1..167c86ffaf92 100644 --- a/common/djangoapps/status/models.py +++ b/common/djangoapps/status/models.py @@ -8,7 +8,6 @@ from django.contrib import admin from django.core.cache import cache from django.db import models - from opaque_keys.edx.django.models import CourseKeyField from openedx.core.djangolib.markup import HTML diff --git a/common/djangoapps/student/admin.py b/common/djangoapps/student/admin.py index 151c6ab5b8ca..3915e997d7de 100644 --- a/common/djangoapps/student/admin.py +++ b/common/djangoapps/student/admin.py @@ -2,11 +2,10 @@ from functools import wraps -from dal_select2.views import Select2ListView -from dal_select2.widgets import ListSelect2 -from django_countries import countries from config_models.admin import ConfigurationModelAdmin +from dal_select2.views import Select2ListView +from dal_select2.widgets import ListSelect2 from django import forms from django.conf import settings from django.contrib import admin @@ -20,15 +19,16 @@ from django.db import models, router, transaction from django.http import HttpResponseRedirect from django.http.request import QueryDict -from django.urls import reverse, path +from django.urls import path, reverse from django.utils.decorators import method_decorator -from django.utils.translation import ngettext from django.utils.translation import gettext_lazy as _ +from django.utils.translation import ngettext +from django_countries import countries +from edx_toggles.toggles import WaffleSwitch from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey -from edx_toggles.toggles import WaffleSwitch -from openedx.core.lib.courses import clean_course_id +from common.djangoapps.student.constants import LANGUAGE_CHOICES from common.djangoapps.student.models import ( AccountRecovery, AccountRecoveryConfiguration, @@ -49,10 +49,10 @@ UserAttribute, UserCelebration, UserProfile, - UserTestGroup + UserTestGroup, ) -from common.djangoapps.student.constants import LANGUAGE_CHOICES from common.djangoapps.student.roles import REGISTERED_ACCESS_ROLES +from openedx.core.lib.courses import clean_course_id from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order User = get_user_model() # pylint:disable=invalid-name diff --git a/common/djangoapps/student/api.py b/common/djangoapps/student/api.py index c5bd7b861871..478c46a0cd5c 100644 --- a/common/djangoapps/student/api.py +++ b/common/djangoapps/student/api.py @@ -4,33 +4,27 @@ """ -from typing import TYPE_CHECKING import logging +from typing import TYPE_CHECKING -from django.contrib.auth import get_user_model from django.conf import settings +from django.contrib.auth import get_user_model from opaque_keys.edx.keys import CourseKey from common.djangoapps.student.models import CourseEnrollment +from common.djangoapps.student.models_api import ALLOWEDTOENROLL_TO_ENROLLED as _ALLOWEDTOENROLL_TO_ENROLLED +from common.djangoapps.student.models_api import ALLOWEDTOENROLL_TO_UNENROLLED as _ALLOWEDTOENROLL_TO_UNENROLLED +from common.djangoapps.student.models_api import DEFAULT_TRANSITION_STATE as _DEFAULT_TRANSITION_STATE +from common.djangoapps.student.models_api import ENROLLED_TO_ENROLLED as _ENROLLED_TO_ENROLLED +from common.djangoapps.student.models_api import ENROLLED_TO_UNENROLLED as _ENROLLED_TO_UNENROLLED +from common.djangoapps.student.models_api import UNENROLLED_TO_ALLOWEDTOENROLL as _UNENROLLED_TO_ALLOWEDTOENROLL +from common.djangoapps.student.models_api import UNENROLLED_TO_ENROLLED as _UNENROLLED_TO_ENROLLED +from common.djangoapps.student.models_api import UNENROLLED_TO_UNENROLLED as _UNENROLLED_TO_UNENROLLED from common.djangoapps.student.models_api import create_manual_enrollment_audit as _create_manual_enrollment_audit from common.djangoapps.student.models_api import get_course_access_role from common.djangoapps.student.models_api import get_course_enrollment as _get_course_enrollment -from common.djangoapps.student.models_api import ( - ENROLLED_TO_ENROLLED as _ENROLLED_TO_ENROLLED, - ENROLLED_TO_UNENROLLED as _ENROLLED_TO_UNENROLLED, - UNENROLLED_TO_ENROLLED as _UNENROLLED_TO_ENROLLED, - UNENROLLED_TO_UNENROLLED as _UNENROLLED_TO_UNENROLLED, - UNENROLLED_TO_ALLOWEDTOENROLL as _UNENROLLED_TO_ALLOWEDTOENROLL, - ALLOWEDTOENROLL_TO_ENROLLED as _ALLOWEDTOENROLL_TO_ENROLLED, - ALLOWEDTOENROLL_TO_UNENROLLED as _ALLOWEDTOENROLL_TO_UNENROLLED, - DEFAULT_TRANSITION_STATE as _DEFAULT_TRANSITION_STATE, -) -from common.djangoapps.student.roles import ( - CourseInstructorRole, - CourseStaffRole, - GlobalStaff, - REGISTERED_ACCESS_ROLES as _REGISTERED_ACCESS_ROLES, -) +from common.djangoapps.student.roles import REGISTERED_ACCESS_ROLES as _REGISTERED_ACCESS_ROLES +from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole, GlobalStaff from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers if TYPE_CHECKING: diff --git a/common/djangoapps/student/apps.py b/common/djangoapps/student/apps.py index e1ec51afcac7..80758379c07f 100644 --- a/common/djangoapps/student/apps.py +++ b/common/djangoapps/student/apps.py @@ -21,7 +21,8 @@ def ready(self): # The django-simple-history model on CourseEnrollment creates performance # problems in testing, we mock it here so that the mock impacts all tests. if os.environ.get('DISABLE_COURSEENROLLMENT_HISTORY', False): - import common.djangoapps.student.models as student_models from unittest.mock import MagicMock + import common.djangoapps.student.models as student_models + student_models.CourseEnrollment.history = MagicMock() diff --git a/common/djangoapps/student/auth.py b/common/djangoapps/student/auth.py index b9abbe1efaf2..71a2cfeb5990 100644 --- a/common/djangoapps/student/auth.py +++ b/common/djangoapps/student/auth.py @@ -13,7 +13,6 @@ from openedx_authz import api as authz_api from openedx_authz.constants.permissions import COURSES_MANAGE_ADVANCED_SETTINGS -from openedx.core import toggles as core_toggles from common.djangoapps.student.roles import ( CourseBetaTesterRole, CourseCreatorRole, @@ -29,6 +28,7 @@ OrgStaffRole, strict_role_checking, ) +from openedx.core import toggles as core_toggles # Studio permissions: STUDIO_EDIT_ROLES = 8 diff --git a/common/djangoapps/student/forms.py b/common/djangoapps/student/forms.py index 8e5a663dcdee..76483be71b6f 100644 --- a/common/djangoapps/student/forms.py +++ b/common/djangoapps/student/forms.py @@ -9,13 +9,13 @@ from edx_ace import ace from edx_ace.recipient import Recipient +from common.djangoapps.student.message_types import AccountRecovery as AccountRecoveryMessage from openedx.core.djangoapps.ace_common.template_context import get_base_template_context from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.theming.helpers import get_current_site -from openedx.core.djangoapps.user_authn.toggles import should_redirect_to_authn_microfrontend from openedx.core.djangoapps.user_api.preferences.api import get_user_preference -from common.djangoapps.student.message_types import AccountRecovery as AccountRecoveryMessage +from openedx.core.djangoapps.user_authn.toggles import should_redirect_to_authn_microfrontend def send_account_recovery_email_for_user(user, request, email=None): diff --git a/common/djangoapps/student/helpers.py b/common/djangoapps/student/helpers.py index 834c230871da..6a510649f7b3 100644 --- a/common/djangoapps/student/helpers.py +++ b/common/djangoapps/student/helpers.py @@ -32,28 +32,28 @@ UserProfile, email_exists_or_retired, unique_id_for_user, - username_exists_or_retired + username_exists_or_retired, ) from common.djangoapps.util.password_policy_validators import normalize_password from lms.djangoapps.certificates.api import ( + auto_certificate_generation_enabled, + certificate_status_for_student, certificates_viewable_for_course, - has_self_generated_certificates_enabled, get_certificate_url, has_html_certificates_enabled, - certificate_status_for_student, - auto_certificate_generation_enabled, + has_self_generated_certificates_enabled, ) from lms.djangoapps.certificates.data import CertificateStatuses from lms.djangoapps.course_blocks.api import get_course_blocks +from lms.djangoapps.course_home_api.dates.serializers import DateSummarySerializer +from lms.djangoapps.courseware.context_processor import user_timezone_locale_prefs +from lms.djangoapps.courseware.courses import get_course_date_blocks, get_course_with_access +from lms.djangoapps.courseware.date_summary import TodaysDate from lms.djangoapps.grades.api import CourseGradeFactory from lms.djangoapps.instructor import access from lms.djangoapps.verify_student.models import VerificationDeadline from lms.djangoapps.verify_student.services import IDVerificationService from lms.djangoapps.verify_student.utils import is_verification_expiring_soon, verification_for_datetime -from lms.djangoapps.courseware.courses import get_course_date_blocks, get_course_with_access -from lms.djangoapps.courseware.date_summary import TodaysDate -from lms.djangoapps.courseware.context_processor import user_timezone_locale_prefs -from lms.djangoapps.course_home_api.dates.serializers import DateSummarySerializer from openedx.core.djangoapps.content.block_structure.exceptions import UsageKeyNotInBlockStructure from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.theming.helpers import get_themes diff --git a/common/djangoapps/student/management/commands/_create_users.py b/common/djangoapps/student/management/commands/_create_users.py index f3e739ac48df..a619fccb23e4 100644 --- a/common/djangoapps/student/management/commands/_create_users.py +++ b/common/djangoapps/student/management/commands/_create_users.py @@ -1,14 +1,12 @@ """ Shared behavior between create_test_users and create_random_users """ from django.contrib.auth import get_user_model from django.core.validators import ValidationError -from xmodule.modulestore.django import modulestore - +from common.djangoapps.student.helpers import AccountValidationError, do_create_account +from common.djangoapps.student.models import CourseEnrollment from lms.djangoapps.instructor.access import allow_access from openedx.core.djangoapps.user_authn.views.registration_form import AccountCreationForm -from common.djangoapps.student.helpers import do_create_account, AccountValidationError -from common.djangoapps.student.models import CourseEnrollment - +from xmodule.modulestore.django import modulestore User = get_user_model() diff --git a/common/djangoapps/student/management/commands/backfill_is_disabled.py b/common/djangoapps/student/management/commands/backfill_is_disabled.py index b941bbc5cb82..cfd13e8b5bbf 100644 --- a/common/djangoapps/student/management/commands/backfill_is_disabled.py +++ b/common/djangoapps/student/management/commands/backfill_is_disabled.py @@ -9,12 +9,14 @@ import logging import time -from django.core.management.base import BaseCommand + +import requests from django.contrib.auth import get_user_model from django.contrib.auth.hashers import UNUSABLE_PASSWORD_PREFIX +from django.core.management.base import BaseCommand from django.db import DatabaseError + from common.djangoapps.track import segment -import requests LOGGER = logging.getLogger(__name__) User = get_user_model() diff --git a/common/djangoapps/student/management/commands/bulk_change_enrollment.py b/common/djangoapps/student/management/commands/bulk_change_enrollment.py index 0b71ac67e254..c5f59bb6a12b 100644 --- a/common/djangoapps/student/management/commands/bulk_change_enrollment.py +++ b/common/djangoapps/student/management/commands/bulk_change_enrollment.py @@ -9,8 +9,8 @@ from opaque_keys.edx.keys import CourseKey from common.djangoapps.course_modes.models import CourseMode -from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from common.djangoapps.student.models import CourseEnrollment +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order logger = logging.getLogger(__name__) # pylint: disable=invalid-name diff --git a/common/djangoapps/student/management/commands/bulk_change_enrollment_csv.py b/common/djangoapps/student/management/commands/bulk_change_enrollment_csv.py index 69f2e35de44a..3b307f9b0c35 100644 --- a/common/djangoapps/student/management/commands/bulk_change_enrollment_csv.py +++ b/common/djangoapps/student/management/commands/bulk_change_enrollment_csv.py @@ -6,17 +6,20 @@ import logging from os import path -import unicodecsv +import unicodecsv from django.core.exceptions import ObjectDoesNotExist from django.core.management.base import BaseCommand, CommandError from django.db import transaction from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey -from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentAttribute, User - -from common.djangoapps.student.models import BulkChangeEnrollmentConfiguration +from common.djangoapps.student.models import ( + BulkChangeEnrollmentConfiguration, + CourseEnrollment, + CourseEnrollmentAttribute, + User, +) logger = logging.getLogger('common.djangoapps.student.management.commands.bulk_change_enrollment_csv') diff --git a/common/djangoapps/student/management/commands/bulk_unenroll.py b/common/djangoapps/student/management/commands/bulk_unenroll.py index 4c73f3dbb943..fa8d95bf6217 100644 --- a/common/djangoapps/student/management/commands/bulk_unenroll.py +++ b/common/djangoapps/student/management/commands/bulk_unenroll.py @@ -7,7 +7,8 @@ from django.core.management.base import BaseCommand from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey -from common.djangoapps.student.models import CourseEnrollment, BulkUnenrollConfiguration + +from common.djangoapps.student.models import BulkUnenrollConfiguration, CourseEnrollment logger = logging.getLogger(__name__) # pylint: disable=invalid-name diff --git a/common/djangoapps/student/management/commands/bulk_update_email.py b/common/djangoapps/student/management/commands/bulk_update_email.py index e5c191a0ad12..80d6b5fc0e39 100644 --- a/common/djangoapps/student/management/commands/bulk_update_email.py +++ b/common/djangoapps/student/management/commands/bulk_update_email.py @@ -7,9 +7,8 @@ import logging from os import path -from django.core.management.base import BaseCommand, CommandError - from django.contrib.auth import get_user_model +from django.core.management.base import BaseCommand, CommandError logger = logging.getLogger('common.djangoapps.student.management.commands.bulk_update_email') diff --git a/common/djangoapps/student/management/commands/change_eligibility_deadline.py b/common/djangoapps/student/management/commands/change_eligibility_deadline.py index c44611cc58d9..3295713297fe 100644 --- a/common/djangoapps/student/management/commands/change_eligibility_deadline.py +++ b/common/djangoapps/student/management/commands/change_eligibility_deadline.py @@ -9,8 +9,8 @@ from opaque_keys.edx.keys import CourseKey from common.djangoapps.course_modes.models import CourseMode -from openedx.core.djangoapps.credit.models import CreditEligibility from common.djangoapps.student.models import CourseEnrollment, User +from openedx.core.djangoapps.credit.models import CreditEligibility logger = logging.getLogger(__name__) # pylint: disable=invalid-name diff --git a/common/djangoapps/student/management/commands/change_enrollment.py b/common/djangoapps/student/management/commands/change_enrollment.py index fa322fdd7be0..41d669f2a98d 100644 --- a/common/djangoapps/student/management/commands/change_enrollment.py +++ b/common/djangoapps/student/management/commands/change_enrollment.py @@ -8,8 +8,8 @@ from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey -from openedx.core.djangoapps.credit.email_utils import get_credit_provider_attribute_values from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentAttribute, User +from openedx.core.djangoapps.credit.email_utils import get_credit_provider_attribute_values logger = logging.getLogger(__name__) # pylint: disable=invalid-name diff --git a/common/djangoapps/student/management/commands/change_enterprise_user_username.py b/common/djangoapps/student/management/commands/change_enterprise_user_username.py index 51d037f6a3e2..5d71cb96e767 100644 --- a/common/djangoapps/student/management/commands/change_enterprise_user_username.py +++ b/common/djangoapps/student/management/commands/change_enterprise_user_username.py @@ -7,7 +7,6 @@ from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.core.management import BaseCommand - from enterprise.models import EnterpriseCustomerUser LOGGER = logging.getLogger(__name__) diff --git a/common/djangoapps/student/management/commands/recover_account.py b/common/djangoapps/student/management/commands/recover_account.py index 7b156abdc510..df358603325a 100644 --- a/common/djangoapps/student/management/commands/recover_account.py +++ b/common/djangoapps/student/management/commands/recover_account.py @@ -4,14 +4,14 @@ import logging from os import path -import unicodecsv -from django.db.models import Q -from django.contrib.sites.models import Site -from django.core.management.base import BaseCommand, CommandError -from django.contrib.auth import get_user_model +import unicodecsv from django.conf import settings +from django.contrib.auth import get_user_model from django.contrib.auth.tokens import default_token_generator +from django.contrib.sites.models import Site +from django.core.management.base import BaseCommand, CommandError +from django.db.models import Q from django.urls import reverse from django.utils.http import int_to_base36 from edx_ace import ace @@ -19,12 +19,12 @@ from eventtracking import tracker from common.djangoapps.student.models import AccountRecoveryConfiguration -from openedx.core.djangoapps.user_authn.toggles import should_redirect_to_authn_microfrontend from openedx.core.djangoapps.ace_common.template_context import get_base_template_context 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.preferences.api import get_user_preference from openedx.core.djangoapps.user_authn.message_types import PasswordReset +from openedx.core.djangoapps.user_authn.toggles import should_redirect_to_authn_microfrontend from openedx.core.lib.celery.task_utils import emulate_http_request logger = logging.getLogger(__name__) # pylint: disable=invalid-name diff --git a/common/djangoapps/student/management/tests/test_bulk_change_enrollment.py b/common/djangoapps/student/management/tests/test_bulk_change_enrollment.py index 4d98679c7cd4..d707d1792af1 100644 --- a/common/djangoapps/student/management/tests/test_bulk_change_enrollment.py +++ b/common/djangoapps/student/management/tests/test_bulk_change_enrollment.py @@ -12,7 +12,9 @@ from common.djangoapps.student.models import EVENT_NAME_ENROLLMENT_MODE_CHANGED, CourseEnrollment from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/common/djangoapps/student/management/tests/test_bulk_change_enrollment_csv.py b/common/djangoapps/student/management/tests/test_bulk_change_enrollment_csv.py index b2b8176049ee..2338691f2031 100644 --- a/common/djangoapps/student/management/tests/test_bulk_change_enrollment_csv.py +++ b/common/djangoapps/student/management/tests/test_bulk_change_enrollment_csv.py @@ -13,7 +13,9 @@ from common.djangoapps.student.models import BulkChangeEnrollmentConfiguration, CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangolib.testing.utils import skip_unless_lms -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order LOGGER_NAME = 'common.djangoapps.student.management.commands.bulk_change_enrollment_csv' diff --git a/common/djangoapps/student/management/tests/test_bulk_unenroll.py b/common/djangoapps/student/management/tests/test_bulk_unenroll.py index fc48af3282e1..1866214e08f9 100644 --- a/common/djangoapps/student/management/tests/test_bulk_unenroll.py +++ b/common/djangoapps/student/management/tests/test_bulk_unenroll.py @@ -9,7 +9,9 @@ from common.djangoapps.course_modes.tests.factories import CourseModeFactory from common.djangoapps.student.models import BulkUnenrollConfiguration, CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order LOGGER_NAME = 'common.djangoapps.student.management.commands.bulk_unenroll' diff --git a/common/djangoapps/student/management/tests/test_change_eligibility_deadline.py b/common/djangoapps/student/management/tests/test_change_eligibility_deadline.py index 1cbfa1b2c846..a85808d0e8a9 100644 --- a/common/djangoapps/student/management/tests/test_change_eligibility_deadline.py +++ b/common/djangoapps/student/management/tests/test_change_eligibility_deadline.py @@ -2,17 +2,19 @@ from datetime import datetime, timedelta -import pytest +import pytest from django.core.management import call_command from opaque_keys import InvalidKeyError from testfixtures import LogCapture from common.djangoapps.course_modes.tests.factories import CourseMode -from openedx.core.djangoapps.credit.models import CreditCourse, CreditEligibility from common.djangoapps.student.models import CourseEnrollment, User from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from openedx.core.djangoapps.credit.models import CreditCourse, CreditEligibility +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order LOGGER_NAME = 'common.djangoapps.student.management.commands.change_eligibility_deadline' diff --git a/common/djangoapps/student/management/tests/test_change_enrollment.py b/common/djangoapps/student/management/tests/test_change_enrollment.py index 61e024cbc83a..ddca50d6f6f5 100644 --- a/common/djangoapps/student/management/tests/test_change_enrollment.py +++ b/common/djangoapps/student/management/tests/test_change_enrollment.py @@ -9,7 +9,9 @@ from common.djangoapps.course_modes.tests.factories import CourseModeFactory from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/common/djangoapps/student/management/tests/test_change_enterprise_user_username.py b/common/djangoapps/student/management/tests/test_change_enterprise_user_username.py index a1354feab555..210aedc5d732 100644 --- a/common/djangoapps/student/management/tests/test_change_enterprise_user_username.py +++ b/common/djangoapps/student/management/tests/test_change_enterprise_user_username.py @@ -4,6 +4,7 @@ from unittest import mock + from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.contrib.sites.models import Site from django.core.management import call_command diff --git a/common/djangoapps/student/management/tests/test_create_random_users.py b/common/djangoapps/student/management/tests/test_create_random_users.py index dace6f6fd9cf..d5d1ecc81098 100644 --- a/common/djangoapps/student/management/tests/test_create_random_users.py +++ b/common/djangoapps/student/management/tests/test_create_random_users.py @@ -9,7 +9,9 @@ from opaque_keys import InvalidKeyError from common.djangoapps.student.models import CourseEnrollment -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/common/djangoapps/student/management/tests/test_create_test_users.py b/common/djangoapps/student/management/tests/test_create_test_users.py index 9258b15f4fea..af0beb3d9903 100644 --- a/common/djangoapps/student/management/tests/test_create_test_users.py +++ b/common/djangoapps/student/management/tests/test_create_test_users.py @@ -13,7 +13,9 @@ from common.djangoapps.student.helpers import AccountValidationError from common.djangoapps.student.models import CourseAccessRole, CourseEnrollment from common.djangoapps.student.roles import CourseStaffRole -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/common/djangoapps/student/management/tests/test_recover_account.py b/common/djangoapps/student/management/tests/test_recover_account.py index cb637ec71989..488f4876a3d4 100644 --- a/common/djangoapps/student/management/tests/test_recover_account.py +++ b/common/djangoapps/student/management/tests/test_recover_account.py @@ -3,20 +3,18 @@ """ import re from tempfile import NamedTemporaryFile -import pytest -from django.core import mail +import pytest from django.conf import settings from django.contrib.auth import get_user_model -from django.core.management import call_command, CommandError +from django.core import mail from django.core.files.uploadedfile import SimpleUploadedFile -from django.test import TestCase, RequestFactory, override_settings - - +from django.core.management import CommandError, call_command +from django.test import RequestFactory, TestCase, override_settings from testfixtures import LogCapture -from common.djangoapps.student.tests.factories import UserFactory -from common.djangoapps.student.models import AccountRecoveryConfiguration +from common.djangoapps.student.models import AccountRecoveryConfiguration +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangolib.testing.utils import skip_unless_lms LOGGER_NAME = 'common.djangoapps.student.management.commands.recover_account' diff --git a/common/djangoapps/student/management/tests/test_retrieve_unsubscribed_emails.py b/common/djangoapps/student/management/tests/test_retrieve_unsubscribed_emails.py index e86badf88511..eec169234734 100644 --- a/common/djangoapps/student/management/tests/test_retrieve_unsubscribed_emails.py +++ b/common/djangoapps/student/management/tests/test_retrieve_unsubscribed_emails.py @@ -2,8 +2,7 @@ from datetime import datetime, timedelta from tempfile import NamedTemporaryFile -from unittest.mock import call -from unittest.mock import patch, MagicMock +from unittest.mock import MagicMock, call, patch import six from django.conf import settings diff --git a/common/djangoapps/student/management/tests/test_transfer_students.py b/common/djangoapps/student/management/tests/test_transfer_students.py index e25941715147..eebd5175b63c 100644 --- a/common/djangoapps/student/management/tests/test_transfer_students.py +++ b/common/djangoapps/student/management/tests/test_transfer_students.py @@ -13,12 +13,14 @@ EVENT_NAME_ENROLLMENT_ACTIVATED, EVENT_NAME_ENROLLMENT_DEACTIVATED, EVENT_NAME_ENROLLMENT_MODE_CHANGED, - CourseEnrollment + CourseEnrollment, ) from common.djangoapps.student.signals import UNENROLL_DONE from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangolib.testing.utils import skip_unless_lms -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/common/djangoapps/student/middleware.py b/common/djangoapps/student/middleware.py index 43dcda960d6e..0468792440fb 100644 --- a/common/djangoapps/student/middleware.py +++ b/common/djangoapps/student/middleware.py @@ -9,8 +9,8 @@ from django.utils.deprecation import MiddlewareMixin from django.utils.translation import gettext as _ -from openedx.core.djangolib.markup import HTML, Text from common.djangoapps.student.models import UserStanding +from openedx.core.djangolib.markup import HTML, Text class UserStandingMiddleware(MiddlewareMixin): diff --git a/common/djangoapps/student/migrations/0047_courseaccessrolehistory.py b/common/djangoapps/student/migrations/0047_courseaccessrolehistory.py index ba2f1da9ef76..5a7e8fb4d0aa 100644 --- a/common/djangoapps/student/migrations/0047_courseaccessrolehistory.py +++ b/common/djangoapps/student/migrations/0047_courseaccessrolehistory.py @@ -1,11 +1,11 @@ # Generated by Django 4.2.23 on 2025-08-22 10:13 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields import opaque_keys.edx.django.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/common/djangoapps/student/models/course_enrollment.py b/common/djangoapps/student/models/course_enrollment.py index 2f0b3d9cd3eb..eef5804d1380 100644 --- a/common/djangoapps/student/models/course_enrollment.py +++ b/common/djangoapps/student/models/course_enrollment.py @@ -602,9 +602,9 @@ def emit_event(self, event_name, enterprise_uuid=None): """ Emits an event to explicitly track course enrollment and unenrollment. """ - from openedx.core.djangoapps.schedules.config import set_up_external_updates_for_enrollment - from common.djangoapps.student.toggles import should_send_enrollment_email from common.djangoapps.student.tasks import send_course_enrollment_email + from common.djangoapps.student.toggles import should_send_enrollment_email + from openedx.core.djangoapps.schedules.config import set_up_external_updates_for_enrollment segment_properties = { 'category': 'conversion', diff --git a/common/djangoapps/student/models/user.py b/common/djangoapps/student/models/user.py index a9055d52479c..6289c78c173c 100644 --- a/common/djangoapps/student/models/user.py +++ b/common/djangoapps/student/models/user.py @@ -33,7 +33,7 @@ from django.core.validators import FileExtensionValidator, RegexValidator from django.db import IntegrityError, models from django.db.models import Q -from django.db.models.signals import post_save, pre_save, post_delete +from django.db.models.signals import post_delete, post_save, pre_save from django.db.utils import ProgrammingError from django.dispatch import receiver from django.utils.translation import gettext_lazy as _ @@ -45,7 +45,6 @@ from model_utils.models import TimeStampedModel from opaque_keys.edx.django.models import CourseKeyField, LearningContextKeyField from pytz import UTC, timezone -from openedx.core.lib import user_util import openedx.core.djangoapps.django_comment_common.comment_client as cc from common.djangoapps.util.model_utils import emit_field_changed_events, get_changed_fields_dict @@ -54,6 +53,7 @@ from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.xmodule_django.models import NoneToEmptyManager from openedx.core.djangolib.model_mixins import DeletableByUserValue +from openedx.core.lib import user_util from openedx.core.toggles import ENTRANCE_EXAMS from .course_enrollment import ( @@ -62,7 +62,7 @@ CourseEnrollmentAllowed, CourseOverview, ManualEnrollmentAudit, - segment + segment, ) User = get_user_model() diff --git a/common/djangoapps/student/models_api.py b/common/djangoapps/student/models_api.py index c8740fd339fc..d019c6796709 100644 --- a/common/djangoapps/student/models_api.py +++ b/common/djangoapps/student/models_api.py @@ -5,20 +5,17 @@ import logging from zoneinfo import ZoneInfo - +from common.djangoapps.student.models import ALLOWEDTOENROLL_TO_ENROLLED as _ALLOWEDTOENROLL_TO_ENROLLED +from common.djangoapps.student.models import ALLOWEDTOENROLL_TO_UNENROLLED as _ALLOWEDTOENROLL_TO_UNENROLLED +from common.djangoapps.student.models import DEFAULT_TRANSITION_STATE as _DEFAULT_TRANSITION_STATE +from common.djangoapps.student.models import ENROLLED_TO_ENROLLED as _ENROLLED_TO_ENROLLED +from common.djangoapps.student.models import ENROLLED_TO_UNENROLLED as _ENROLLED_TO_UNENROLLED +from common.djangoapps.student.models import UNENROLLED_TO_ALLOWEDTOENROLL as _UNENROLLED_TO_ALLOWEDTOENROLL +from common.djangoapps.student.models import UNENROLLED_TO_ENROLLED as _UNENROLLED_TO_ENROLLED +from common.djangoapps.student.models import UNENROLLED_TO_UNENROLLED as _UNENROLLED_TO_UNENROLLED from common.djangoapps.student.models import CourseAccessRole as _CourseAccessRole from common.djangoapps.student.models import CourseEnrollment as _CourseEnrollment from common.djangoapps.student.models import ManualEnrollmentAudit as _ManualEnrollmentAudit -from common.djangoapps.student.models import ( - ENROLLED_TO_ENROLLED as _ENROLLED_TO_ENROLLED, - ENROLLED_TO_UNENROLLED as _ENROLLED_TO_UNENROLLED, - UNENROLLED_TO_ENROLLED as _UNENROLLED_TO_ENROLLED, - UNENROLLED_TO_UNENROLLED as _UNENROLLED_TO_UNENROLLED, - UNENROLLED_TO_ALLOWEDTOENROLL as _UNENROLLED_TO_ALLOWEDTOENROLL, - ALLOWEDTOENROLL_TO_ENROLLED as _ALLOWEDTOENROLL_TO_ENROLLED, - ALLOWEDTOENROLL_TO_UNENROLLED as _ALLOWEDTOENROLL_TO_UNENROLLED, - DEFAULT_TRANSITION_STATE as _DEFAULT_TRANSITION_STATE, -) from common.djangoapps.student.models import PendingNameChange as _PendingNameChange from common.djangoapps.student.models import UserProfile as _UserProfile diff --git a/common/djangoapps/student/role_helpers.py b/common/djangoapps/student/role_helpers.py index ee58efab9ee4..0f4667e279f6 100644 --- a/common/djangoapps/student/role_helpers.py +++ b/common/djangoapps/student/role_helpers.py @@ -5,14 +5,6 @@ from django.contrib.auth import get_user_model -from openedx.core.djangoapps.django_comment_common.models import ( - FORUM_ROLE_ADMINISTRATOR, - FORUM_ROLE_COMMUNITY_TA, - FORUM_ROLE_GROUP_MODERATOR, - FORUM_ROLE_MODERATOR, - Role -) -from openedx.core.lib.cache_utils import request_cached from common.djangoapps.student.roles import ( AuthzCompatCourseAccessRole, CourseBetaTesterRole, @@ -23,7 +15,14 @@ OrgStaffRole, RoleCache, ) - +from openedx.core.djangoapps.django_comment_common.models import ( + FORUM_ROLE_ADMINISTRATOR, + FORUM_ROLE_COMMUNITY_TA, + FORUM_ROLE_GROUP_MODERATOR, + FORUM_ROLE_MODERATOR, + Role, +) +from openedx.core.lib.cache_utils import request_cached User = get_user_model() diff --git a/common/djangoapps/student/roles.py b/common/djangoapps/student/roles.py index 3ae766dffc89..6a26e0f4db70 100644 --- a/common/djangoapps/student/roles.py +++ b/common/djangoapps/student/roles.py @@ -11,15 +11,15 @@ from dataclasses import dataclass from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user -from common.djangoapps.student.signals.signals import emit_course_access_role_added, emit_course_access_role_removed from opaque_keys.edx.django.models import CourseKeyField from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import CourseLocator from openedx_authz.api import users as authz_api -from openedx_authz.api.data import RoleAssignmentData, CourseOverviewData +from openedx_authz.api.data import CourseOverviewData, RoleAssignmentData from openedx_authz.constants import roles as authz_roles from common.djangoapps.student.models import CourseAccessRole +from common.djangoapps.student.signals.signals import emit_course_access_role_added, emit_course_access_role_removed from openedx.core.lib.cache_utils import get_cache from openedx.core.toggles import enable_authz_course_authoring @@ -429,8 +429,9 @@ def _legacy_add_users(self, users): """ # silently ignores anonymous and inactive users so that any that are # legit get updated. - from common.djangoapps.student.models import \ - CourseAccessRole # lint-amnesty, pylint: disable=redefined-outer-name, reimported + from common.djangoapps.student.models import ( # lint-amnesty, pylint: disable=redefined-outer-name, reimported + CourseAccessRole, + ) for user in users: if user.is_authenticated and user.is_active: CourseAccessRole.objects.get_or_create( diff --git a/common/djangoapps/student/signals/__init__.py b/common/djangoapps/student/signals/__init__.py index 06ac888896e0..2c37a781389b 100644 --- a/common/djangoapps/student/signals/__init__.py +++ b/common/djangoapps/student/signals/__init__.py @@ -1,11 +1,11 @@ # lint-amnesty, pylint: disable=missing-module-docstring from common.djangoapps.student.signals.signals import ( - emit_course_access_role_added, - emit_course_access_role_removed, ENROLL_STATUS_CHANGE, ENROLLMENT_TRACK_UPDATED, REFUND_ORDER, UNENROLL_DONE, - USER_EMAIL_CHANGED + USER_EMAIL_CHANGED, + emit_course_access_role_added, + emit_course_access_role_removed, ) diff --git a/common/djangoapps/student/signals/receivers.py b/common/djangoapps/student/signals/receivers.py index 529ac261b412..5394bc8074f9 100644 --- a/common/djangoapps/student/signals/receivers.py +++ b/common/djangoapps/student/signals/receivers.py @@ -5,14 +5,13 @@ # pylint: disable=unused-argument import logging from asyncio.log import logger + from django.conf import settings from django.contrib.auth import get_user_model from django.db import IntegrityError from django.db.models.signals import post_delete, post_save, pre_save from django.dispatch import receiver -from lms.djangoapps.courseware.toggles import courseware_mfe_progress_milestones_are_active -from lms.djangoapps.utils import get_email_client from common.djangoapps.student.helpers import EMAIL_EXISTS_MSG_FMT, USERNAME_EXISTS_MSG_FMT, AccountValidationError from common.djangoapps.student.models import ( CourseAccessRole, @@ -20,14 +19,16 @@ CourseEnrollmentCelebration, PendingNameChange, is_email_retired, - is_username_retired + is_username_retired, ) from common.djangoapps.student.models_api import confirm_name_change from common.djangoapps.student.signals import ( + USER_EMAIL_CHANGED, emit_course_access_role_added, emit_course_access_role_removed, - USER_EMAIL_CHANGED, ) +from lms.djangoapps.courseware.toggles import courseware_mfe_progress_milestones_are_active +from lms.djangoapps.utils import get_email_client from openedx.core.djangoapps.safe_sessions.middleware import EmailChangeMiddleware from openedx.features.name_affirmation_api.utils import is_name_affirmation_installed diff --git a/common/djangoapps/student/signals/signals.py b/common/djangoapps/student/signals/signals.py index a9fe3cf1f5e6..3aab4c732aa0 100644 --- a/common/djangoapps/student/signals/signals.py +++ b/common/djangoapps/student/signals/signals.py @@ -4,11 +4,9 @@ from django.dispatch import Signal - from openedx_events.learning.data import CourseAccessRoleData, UserData, UserPersonalData from openedx_events.learning.signals import COURSE_ACCESS_ROLE_ADDED, COURSE_ACCESS_ROLE_REMOVED - # The purely documentational providing_args argument for Signal is deprecated. # So we are moving the args to a comment. diff --git a/common/djangoapps/student/tasks.py b/common/djangoapps/student/tasks.py index 2d436c7c9b0a..ab7356ebc9c4 100644 --- a/common/djangoapps/student/tasks.py +++ b/common/djangoapps/student/tasks.py @@ -2,23 +2,21 @@ Celery task for course enrollment email """ import logging + from celery import shared_task from django.conf import settings from django.contrib.auth import get_user_model from edx_django_utils.monitoring import set_code_owner_attribute from opaque_keys.edx.keys import CourseKey -from common.djangoapps.track import segment from common.djangoapps.course_modes.models import CourseMode -from common.djangoapps.student.helpers import ( - get_course_dates_for_email, - get_instructors, -) +from common.djangoapps.student.helpers import get_course_dates_for_email, get_instructors +from common.djangoapps.track import segment from lms.djangoapps.utils import get_email_client from openedx.core.djangoapps.catalog.utils import ( + get_course_run_details, get_course_uuid_for_course, get_owners_for_course, - get_course_run_details, ) from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.features.course_experience import ENABLE_COURSE_GOALS diff --git a/common/djangoapps/student/tests/factories.py b/common/djangoapps/student/tests/factories.py index 21fa9a1b44f1..10aaba5071e1 100644 --- a/common/djangoapps/student/tests/factories.py +++ b/common/djangoapps/student/tests/factories.py @@ -24,14 +24,16 @@ User, UserAttribute, UserProfile, - UserStanding + UserStanding, +) +from common.djangoapps.student.roles import ( + CourseBetaTesterRole, + CourseInstructorRole, + CourseStaffRole, + GlobalStaff, + OrgInstructorRole, + OrgStaffRole, ) -from common.djangoapps.student.roles import GlobalStaff -from common.djangoapps.student.roles import CourseBetaTesterRole -from common.djangoapps.student.roles import CourseInstructorRole -from common.djangoapps.student.roles import CourseStaffRole -from common.djangoapps.student.roles import OrgInstructorRole -from common.djangoapps.student.roles import OrgStaffRole from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory diff --git a/common/djangoapps/student/tests/test_admin_views.py b/common/djangoapps/student/tests/test_admin_views.py index da8376fbbe5e..0068b3cd8da9 100644 --- a/common/djangoapps/student/tests/test_admin_views.py +++ b/common/djangoapps/student/tests/test_admin_views.py @@ -10,7 +10,6 @@ import ddt import pytest - from django.contrib.admin.sites import AdminSite from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.forms import ValidationError @@ -23,13 +22,15 @@ COURSE_ENROLLMENT_ADMIN_SWITCH, AllowedAuthUserForm, CourseEnrollmentForm, - UserAdmin + UserAdmin, ) from common.djangoapps.student.models import AllowedAuthUser, CourseEnrollment, LoginFailures from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory, UserProfileFactory from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/common/djangoapps/student/tests/test_api.py b/common/djangoapps/student/tests/test_api.py index 4757790e727f..637df5f1979d 100644 --- a/common/djangoapps/student/tests/test_api.py +++ b/common/djangoapps/student/tests/test_api.py @@ -2,13 +2,10 @@ Test Student api.py """ -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory - from common.djangoapps.student.api import ( + get_course_enrollments, is_user_enrolled_in_course, is_user_staff_or_instructor_in_course, - get_course_enrollments, ) from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import ( @@ -18,6 +15,8 @@ StaffFactory, UserFactory, ) +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class TestStudentApi(SharedModuleStoreTestCase): diff --git a/common/djangoapps/student/tests/test_authz.py b/common/djangoapps/student/tests/test_authz.py index 70636e04b68a..b428395a0f0e 100644 --- a/common/djangoapps/student/tests/test_authz.py +++ b/common/djangoapps/student/tests/test_authz.py @@ -11,21 +11,21 @@ from django.test import TestCase, override_settings from opaque_keys.edx.locator import CourseLocator -from common.djangoapps.student.models.user import CourseAccessRole from common.djangoapps.student.auth import ( add_users, has_studio_read_access, has_studio_write_access, remove_users, update_org_role, - user_has_role + user_has_role, ) +from common.djangoapps.student.models.user import CourseAccessRole from common.djangoapps.student.roles import ( CourseCreatorRole, CourseInstructorRole, CourseLimitedStaffRole, CourseStaffRole, - OrgContentCreatorRole + OrgContentCreatorRole, ) from common.djangoapps.student.tests.factories import AdminFactory, UserFactory diff --git a/common/djangoapps/student/tests/test_bulk_email_settings.py b/common/djangoapps/student/tests/test_bulk_email_settings.py index 308ccf66e09d..0f50bb49475a 100644 --- a/common/djangoapps/student/tests/test_bulk_email_settings.py +++ b/common/djangoapps/student/tests/test_bulk_email_settings.py @@ -7,13 +7,16 @@ from django.urls import reverse +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory + # This import is for an lms djangoapp. # Its testcases are only run under lms. from lms.djangoapps.bulk_email.api import is_bulk_email_feature_enabled from lms.djangoapps.bulk_email.models import BulkEmailFlag, CourseAuthorization -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from openedx.core.djangolib.testing.utils import skip_unless_lms -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/common/djangoapps/student/tests/test_certificates.py b/common/djangoapps/student/tests/test_certificates.py index 914e255df944..f6a3d4307330 100644 --- a/common/djangoapps/student/tests/test_certificates.py +++ b/common/djangoapps/student/tests/test_certificates.py @@ -8,17 +8,17 @@ from django.conf import settings from django.test.utils import override_settings from django.urls import reverse -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.data import CertificatesDisplayBehaviors from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory -from openedx.core.djangolib.testing.utils import skip_unless_lms from lms.djangoapps.certificates.api import get_certificate_url from lms.djangoapps.certificates.data import CertificateStatuses from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration_context +from openedx.core.djangolib.testing.utils import skip_unless_lms +from xmodule.data import CertificatesDisplayBehaviors +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory # pylint: disable=no-member diff --git a/common/djangoapps/student/tests/test_configuration_overrides.py b/common/djangoapps/student/tests/test_configuration_overrides.py index fc69bdd17497..b653b8915cb0 100644 --- a/common/djangoapps/student/tests/test_configuration_overrides.py +++ b/common/djangoapps/student/tests/test_configuration_overrides.py @@ -4,8 +4,8 @@ import json - from unittest import mock + from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.test import TestCase from django.test.utils import override_settings diff --git a/common/djangoapps/student/tests/test_course_listing.py b/common/djangoapps/student/tests/test_course_listing.py index 3034c697f2bb..349f8a473ac5 100644 --- a/common/djangoapps/student/tests/test_course_listing.py +++ b/common/djangoapps/student/tests/test_course_listing.py @@ -4,21 +4,24 @@ """ from unittest import mock + from django.conf import settings from django.test.client import Client from milestones.tests.utils import MilestonesTestCaseMixin -from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from openedx.core.djangolib.testing.utils import skip_unless_lms from common.djangoapps.student.models import CourseEnrollment # lint-amnesty, pylint: disable=unused-import from common.djangoapps.student.roles import GlobalStaff from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.student.views import get_course_enrollments from common.djangoapps.util.milestones_helpers import get_pre_requisite_courses_not_completed, set_prerequisite_courses +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview +from openedx.core.djangolib.testing.utils import skip_unless_lms from xmodule.error_block import ErrorBlock # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/common/djangoapps/student/tests/test_credit.py b/common/djangoapps/student/tests/test_credit.py index 20ba9cd72ebc..445e9dc2eab1 100644 --- a/common/djangoapps/student/tests/test_credit.py +++ b/common/djangoapps/student/tests/test_credit.py @@ -16,7 +16,9 @@ from openedx.core.djangoapps.credit import api as credit_api from openedx.core.djangoapps.credit.models import CreditCourse, CreditEligibility, CreditProvider from openedx.core.djangolib.testing.utils import skip_unless_lms -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order TEST_CREDIT_PROVIDER_SECRET_KEY = "931433d583c84ca7ba41784bad3232e6" diff --git a/common/djangoapps/student/tests/test_email.py b/common/djangoapps/student/tests/test_email.py index bcede1821376..75626f3a8f5e 100644 --- a/common/djangoapps/student/tests/test_email.py +++ b/common/djangoapps/student/tests/test_email.py @@ -26,7 +26,7 @@ SETTING_CHANGE_INITIATED, confirm_email_change, do_email_change_request, - validate_new_email + validate_new_email, ) from common.djangoapps.third_party_auth.views import inactive_user_view from common.djangoapps.util.testing import EventTestMixin @@ -34,7 +34,9 @@ from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangolib.testing.utils import CacheIsolationMixin, CacheIsolationTestCase, skip_unless_lms from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/common/djangoapps/student/tests/test_enrollment.py b/common/djangoapps/student/tests/test_enrollment.py index fee4ec39906f..767479ac2756 100644 --- a/common/djangoapps/student/tests/test_enrollment.py +++ b/common/djangoapps/student/tests/test_enrollment.py @@ -9,8 +9,6 @@ from django.conf import settings from django.urls import reverse from openedx_events.tests.utils import OpenEdxEventsTestMixin -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory @@ -18,13 +16,15 @@ SCORE_RECALCULATION_DELAY_ON_ENROLLMENT_UPDATE, CourseEnrollment, CourseFullError, - EnrollmentClosedError + EnrollmentClosedError, ) from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole from common.djangoapps.student.tests.factories import CourseEnrollmentAllowedFactory, UserFactory from common.djangoapps.util.testing import UrlResetMixin from openedx.core.djangoapps.embargo.test_utils import restrict_course from openedx.core.djangolib.testing.utils import skip_unless_lms +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory @ddt.ddt diff --git a/common/djangoapps/student/tests/test_events.py b/common/djangoapps/student/tests/test_events.py index 7c9d625118d0..64f13a4e4c94 100644 --- a/common/djangoapps/student/tests/test_events.py +++ b/common/djangoapps/student/tests/test_events.py @@ -16,14 +16,14 @@ CourseData, CourseEnrollmentData, UserData, - UserPersonalData + UserPersonalData, ) from openedx_events.learning.signals import ( # lint-amnesty, pylint: disable=wrong-import-order COURSE_ACCESS_ROLE_ADDED, COURSE_ACCESS_ROLE_REMOVED, COURSE_ENROLLMENT_CHANGED, COURSE_ENROLLMENT_CREATED, - COURSE_UNENROLLMENT_COMPLETED + COURSE_UNENROLLMENT_COMPLETED, ) from openedx_events.tests.utils import OpenEdxEventsTestMixin # lint-amnesty, pylint: disable=wrong-import-order @@ -31,12 +31,13 @@ from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole from common.djangoapps.student.tests.factories import CourseEnrollmentAllowedFactory, UserFactory, UserProfileFactory from common.djangoapps.student.tests.tests import UserSettingsEventTestMixin +from common.test.utils import assert_dict_contains_subset from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangolib.testing.utils import skip_unless_lms -from xmodule.modulestore.tests.django_utils import \ - SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order -from common.test.utils import assert_dict_contains_subset class TestUserProfileEvents(UserSettingsEventTestMixin, TestCase): diff --git a/common/djangoapps/student/tests/test_filters.py b/common/djangoapps/student/tests/test_filters.py index bf79ed7ae402..2109755d26ac 100644 --- a/common/djangoapps/student/tests/test_filters.py +++ b/common/djangoapps/student/tests/test_filters.py @@ -6,14 +6,14 @@ from django.test import override_settings from django.urls import reverse from openedx_filters import PipelineStep -from openedx_filters.learning.filters import DashboardRenderStarted, CourseEnrollmentStarted, CourseUnenrollmentStarted +from openedx_filters.learning.filters import CourseEnrollmentStarted, CourseUnenrollmentStarted, DashboardRenderStarted from rest_framework import status -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student.models import CourseEnrollment, EnrollmentNotAllowed, UnenrollmentNotAllowed from common.djangoapps.student.tests.factories import UserFactory, UserProfileFactory from openedx.core.djangolib.testing.utils import skip_unless_lms +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class TestEnrollmentPipelineStep(PipelineStep): diff --git a/common/djangoapps/student/tests/test_linkedin.py b/common/djangoapps/student/tests/test_linkedin.py index 87c2d404aeff..ec2e638dbcc2 100644 --- a/common/djangoapps/student/tests/test_linkedin.py +++ b/common/djangoapps/student/tests/test_linkedin.py @@ -2,6 +2,7 @@ from types import SimpleNamespace from urllib.parse import quote + import ddt from django.conf import settings from django.test import TestCase diff --git a/common/djangoapps/student/tests/test_models.py b/common/djangoapps/student/tests/test_models.py index 69f19da3dc18..1743280c2edd 100644 --- a/common/djangoapps/student/tests/test_models.py +++ b/common/djangoapps/student/tests/test_models.py @@ -7,9 +7,9 @@ import ddt from crum import set_current_request +from django.conf import settings from django.contrib.auth.models import AnonymousUser, User # lint-amnesty, pylint: disable=imported-auth-user from django.core.cache import cache -from django.conf import settings from django.db.models.functions import Lower from django.test import TestCase, override_settings from edx_toggles.toggles.testutils import override_waffle_flag @@ -29,7 +29,7 @@ PendingNameChange, UserAttribute, UserCelebration, - UserProfile + UserProfile, ) from common.djangoapps.student.models_api import confirm_name_change, do_name_change_request, get_name from common.djangoapps.student.tests.factories import AccountRecoveryFactory, CourseEnrollmentFactory, UserFactory @@ -44,7 +44,10 @@ from openedx.core.djangoapps.user_api.preferences.api import set_user_preference from openedx.core.djangolib.testing.utils import skip_unless_lms from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order + ModuleStoreTestCase, + SharedModuleStoreTestCase, +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/common/djangoapps/student/tests/test_password_policy.py b/common/djangoapps/student/tests/test_password_policy.py index fb84c049de04..4c0f616cf50c 100644 --- a/common/djangoapps/student/tests/test_password_policy.py +++ b/common/djangoapps/student/tests/test_password_policy.py @@ -4,10 +4,12 @@ import json + from django.test import TestCase from django.test.client import RequestFactory from django.test.utils import override_settings from django.urls import reverse + from common.djangoapps.util.password_policy_validators import create_validator_config diff --git a/common/djangoapps/student/tests/test_receivers.py b/common/djangoapps/student/tests/test_receivers.py index 424df4759d3e..33cf43a21fae 100644 --- a/common/djangoapps/student/tests/test_receivers.py +++ b/common/djangoapps/student/tests/test_receivers.py @@ -9,9 +9,11 @@ from common.djangoapps.student.signals.signals import USER_EMAIL_CHANGED from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory, UserProfileFactory from lms.djangoapps.courseware.toggles import COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES -from openedx.core.djangolib.testing.utils import skip_unless_lms, get_mock_request +from openedx.core.djangolib.testing.utils import get_mock_request, skip_unless_lms from openedx.features.name_affirmation_api.utils import is_name_affirmation_installed -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) name_affirmation_installed = is_name_affirmation_installed() if name_affirmation_installed: diff --git a/common/djangoapps/student/tests/test_recent_enrollments.py b/common/djangoapps/student/tests/test_recent_enrollments.py index 327bf6b46e89..42ca5ebd6c54 100644 --- a/common/djangoapps/student/tests/test_recent_enrollments.py +++ b/common/djangoapps/student/tests/test_recent_enrollments.py @@ -10,13 +10,15 @@ from django.utils.timezone import now from opaque_keys.edx import locator -from common.test.utils import XssTestMixin from common.djangoapps.student.models import CourseEnrollment, DashboardConfiguration from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.student.views import get_course_enrollments from common.djangoapps.student.views.dashboard import _get_recently_enrolled_courses +from common.test.utils import XssTestMixin from openedx.core.djangolib.testing.utils import skip_unless_lms -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/common/djangoapps/student/tests/test_refunds.py b/common/djangoapps/student/tests/test_refunds.py index 60979d8e80d5..0afce01c62b8 100644 --- a/common/djangoapps/student/tests/test_refunds.py +++ b/common/djangoapps/student/tests/test_refunds.py @@ -10,6 +10,7 @@ import ddt import httpretty + # Explicitly import the cache from ConfigurationModel so we can reset it after each test from config_models.models import cache from django.test.client import Client @@ -26,7 +27,9 @@ from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory from openedx.core.djangoapps.commerce.utils import ECOMMERCE_DATE_FORMAT from openedx.core.djangolib.testing.utils import skip_unless_lms -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order log = logging.getLogger(__name__) diff --git a/common/djangoapps/student/tests/test_retirement.py b/common/djangoapps/student/tests/test_retirement.py index ffeb1af14fa2..c378bdc694a5 100644 --- a/common/djangoapps/student/tests/test_retirement.py +++ b/common/djangoapps/student/tests/test_retirement.py @@ -13,7 +13,6 @@ from django.test import TestCase from django.urls import reverse -from openedx.core.djangolib.testing.utils import skip_unless_lms from common.djangoapps.student.models import ( get_all_retired_usernames_by_username, get_potentially_retired_user_by_username, @@ -21,9 +20,10 @@ get_retired_email_by_email, get_retired_username_by_username, is_email_retired, - is_username_retired + is_username_retired, ) from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangolib.testing.utils import skip_unless_lms # Tell pytest it's ok to user the Django db pytestmark = pytest.mark.django_db diff --git a/common/djangoapps/student/tests/test_roles.py b/common/djangoapps/student/tests/test_roles.py index 9485a7ca84d1..c95d0c5af8a3 100644 --- a/common/djangoapps/student/tests/test_roles.py +++ b/common/djangoapps/student/tests/test_roles.py @@ -3,43 +3,43 @@ """ -import ddt from unittest.mock import patch + +import ddt from django.contrib.auth.models import Permission from django.test import TestCase from edx_toggles.toggles.testutils import override_waffle_flag from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import LibraryLocator - -from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx_authz.api.data import ContentLibraryData, RoleAssignmentData, RoleData, UserData from openedx_authz.engine.enforcer import AuthzEnforcer from common.djangoapps.student.admin import CourseAccessRoleHistoryAdmin from common.djangoapps.student.models import CourseAccessRoleHistory, User +from common.djangoapps.student.role_helpers import get_course_roles, has_staff_roles from common.djangoapps.student.roles import ( + ROLE_CACHE_UNGROUPED_ROLES__KEY, AuthzCompatCourseAccessRole, CourseAccessRole, CourseBetaTesterRole, + CourseDataResearcherRole, + CourseFinanceAdminRole, CourseInstructorRole, - CourseRole, CourseLimitedStaffRole, - CourseStaffRole, - CourseFinanceAdminRole, + CourseRole, CourseSalesAdminRole, - LibraryUserRole, - CourseDataResearcherRole, + CourseStaffRole, GlobalStaff, + LibraryUserRole, OrgContentCreatorRole, OrgInstructorRole, OrgStaffRole, RoleCache, get_authz_compat_course_access_roles_for_user, get_role_cache_key_for_course, - ROLE_CACHE_UNGROUPED_ROLES__KEY ) -from common.djangoapps.student.role_helpers import get_course_roles, has_staff_roles from common.djangoapps.student.tests.factories import AnonymousUserFactory, InstructorFactory, StaffFactory, UserFactory +from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.toggles import AUTHZ_COURSE_AUTHORING_FLAG @@ -69,9 +69,9 @@ def _seed_database_with_policies(cls): This simulates the one-time database seeding that would happen during application deployment, separate from the runtime policy loading. """ + import casbin import pkg_resources from openedx_authz.engine.utils import migrate_policy_between_enforcers - import casbin global_enforcer = AuthzEnforcer.get_enforcer() global_enforcer.load_policy() diff --git a/common/djangoapps/student/tests/test_tasks.py b/common/djangoapps/student/tests/test_tasks.py index 0921e4684b89..b4a5404fa854 100644 --- a/common/djangoapps/student/tests/test_tasks.py +++ b/common/djangoapps/student/tests/test_tasks.py @@ -1,16 +1,13 @@ """ Celery task tests """ -from unittest.mock import patch, Mock, PropertyMock +from unittest.mock import Mock, PropertyMock, patch import pytest from django.conf import settings from django.test.utils import override_settings -from common.djangoapps.student.tasks import ( - MAX_RETRIES, - send_course_enrollment_email -) +from common.djangoapps.student.tasks import MAX_RETRIES, send_course_enrollment_email from common.djangoapps.student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/common/djangoapps/student/tests/test_tracking_log.py b/common/djangoapps/student/tests/test_tracking_log.py index 45932b833e67..0691bf7eefbc 100644 --- a/common/djangoapps/student/tests/test_tracking_log.py +++ b/common/djangoapps/student/tests/test_tracking_log.py @@ -1,5 +1,5 @@ """Test to verify tracking logs are emitted correctly""" -from unittest.mock import patch, Mock +from unittest.mock import Mock, patch from django.test import TestCase diff --git a/common/djangoapps/student/tests/test_user_profile_properties.py b/common/djangoapps/student/tests/test_user_profile_properties.py index 886c026421e6..06ff21055644 100644 --- a/common/djangoapps/student/tests/test_user_profile_properties.py +++ b/common/djangoapps/student/tests/test_user_profile_properties.py @@ -2,14 +2,15 @@ import datetime -import pytest + import ddt +import pytest from django.core.cache import cache from django.core.exceptions import ValidationError -from openedx.core.djangolib.testing.utils import CacheIsolationTestCase from common.djangoapps.student.models import UserProfile from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangolib.testing.utils import CacheIsolationTestCase @ddt.ddt diff --git a/common/djangoapps/student/tests/test_views.py b/common/djangoapps/student/tests/test_views.py index ed8c98188a50..70ec3cb22aab 100644 --- a/common/djangoapps/student/tests/test_views.py +++ b/common/djangoapps/student/tests/test_views.py @@ -32,11 +32,11 @@ from common.djangoapps.util.milestones_helpers import ( get_course_milestones, remove_prerequisite_course, - set_prerequisite_courses + set_prerequisite_courses, ) from common.djangoapps.util.testing import UrlResetMixin # lint-amnesty, pylint: disable=unused-import -from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory from lms.djangoapps.certificates.data import CertificateStatuses +from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory from lms.djangoapps.commerce.utils import EcommerceService from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory from openedx.core.djangoapps.content.course_overviews.models import CourseOverview @@ -46,8 +46,13 @@ from openedx.features.course_duration_limits.models import CourseDurationLimitConfig from openedx.features.course_experience.tests.views.helpers import add_course_mode from xmodule.data import CertificatesDisplayBehaviors # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) TOMORROW = now() + timedelta(days=1) ONE_WEEK_AGO = now() - timedelta(weeks=1) diff --git a/common/djangoapps/student/tests/tests.py b/common/djangoapps/student/tests/tests.py index c4e5635be75a..9739433fe1c2 100644 --- a/common/djangoapps/student/tests/tests.py +++ b/common/djangoapps/student/tests/tests.py @@ -31,7 +31,7 @@ UserAttribute, anonymous_id_for_user, unique_id_for_user, - user_by_anonymous_id + user_by_anonymous_id, ) from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from common.djangoapps.student.toggles import REDIRECT_TO_COURSEWARE_AFTER_ENROLLMENT @@ -46,12 +46,18 @@ from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangoapps.programs.tests.mixins import ProgramsApiConfigMixin from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin +from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration_context from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms from openedx.features.course_experience.url_helpers import make_learning_mfe_courseware_url -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order from xmodule.data import CertificatesDisplayBehaviors # lint-amnesty, pylint: disable=wrong-import-order -from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration_context +from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order + ModuleStoreTestCase, + SharedModuleStoreTestCase, +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + CourseFactory, + check_mongo_calls, +) log = logging.getLogger(__name__) diff --git a/common/djangoapps/student/views/dashboard.py b/common/djangoapps/student/views/dashboard.py index 03061dcb065b..610a3fe86722 100644 --- a/common/djangoapps/student/views/dashboard.py +++ b/common/djangoapps/student/views/dashboard.py @@ -17,26 +17,36 @@ from django.utils.translation import gettext as _ from django.views.decorators.csrf import ensure_csrf_cookie from edx_django_utils import monitoring as monitoring_utils -from edx_django_utils.plugins import get_plugins_view_context +from edx_django_utils.plugins import get_plugins_view_context, pluggable_override from edx_toggles.toggles import WaffleFlag from opaque_keys.edx.keys import CourseKey from openedx_filters.learning.filters import DashboardRenderStarted -from edx_django_utils.plugins import pluggable_override -from lms.djangoapps.bulk_email.api import is_bulk_email_feature_enabled -from lms.djangoapps.bulk_email.models import Optout from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.edxmako.shortcuts import render_to_response, render_to_string from common.djangoapps.entitlements.models import CourseEntitlement +from common.djangoapps.student.api import COURSE_DASHBOARD_PLUGIN_VIEW_NAME +from common.djangoapps.student.helpers import cert_info, check_verify_status_by_course, get_resume_urls_for_enrollments +from common.djangoapps.student.models import ( + AccountRecovery, + CourseEnrollment, + CourseEnrollmentAttribute, + DashboardConfiguration, + PendingSecondaryEmailChange, + UserProfile, +) +from common.djangoapps.util.milestones_helpers import get_pre_requisite_courses_not_completed +from lms.djangoapps.bulk_email.api import is_bulk_email_feature_enabled +from lms.djangoapps.bulk_email.models import Optout from lms.djangoapps.commerce.utils import EcommerceService from lms.djangoapps.courseware.access import has_access -from lms.djangoapps.learner_home.waffle import learner_home_mfe_enabled from lms.djangoapps.experiments.utils import get_dashboard_course_info, get_experiment_user_metadata_context +from lms.djangoapps.learner_home.waffle import learner_home_mfe_enabled from lms.djangoapps.verify_student.services import IDVerificationService from openedx.core.djangoapps.catalog.utils import ( get_programs, get_pseudo_session_for_entitlement, - get_visible_sessions_for_entitlement + get_visible_sessions_for_entitlement, ) from openedx.core.djangoapps.credit.email_utils import get_credit_provider_attribute_values, make_providers_strings from openedx.core.djangoapps.plugins.constants import ProjectType @@ -53,18 +63,6 @@ get_enterprise_learner_portal_context, ) from openedx.features.enterprise_support.utils import is_enterprise_learner - -from common.djangoapps.student.api import COURSE_DASHBOARD_PLUGIN_VIEW_NAME -from common.djangoapps.student.helpers import cert_info, check_verify_status_by_course, get_resume_urls_for_enrollments -from common.djangoapps.student.models import ( - AccountRecovery, - CourseEnrollment, - CourseEnrollmentAttribute, - DashboardConfiguration, - PendingSecondaryEmailChange, - UserProfile -) -from common.djangoapps.util.milestones_helpers import get_pre_requisite_courses_not_completed from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order log = logging.getLogger("edx.student") diff --git a/common/djangoapps/student/views/management.py b/common/djangoapps/student/views/management.py index 3af83742613d..f98461675646 100644 --- a/common/djangoapps/student/views/management.py +++ b/common/djangoapps/student/views/management.py @@ -5,10 +5,10 @@ import datetime import logging +import re import urllib.parse import uuid from collections import namedtuple -import re from zoneinfo import ZoneInfo from django.conf import settings @@ -26,27 +26,69 @@ from django.urls import reverse from django.utils.translation import gettext as _ from django.views.decorators.csrf import csrf_exempt, ensure_csrf_cookie # lint-amnesty, pylint: disable=unused-import -from django.views.decorators.http import require_GET, require_http_methods, require_POST # lint-amnesty, pylint: disable=unused-import +from django.views.decorators.http import ( # lint-amnesty, pylint: disable=unused-import + require_GET, + require_http_methods, + require_POST, +) from edx_ace import ace from edx_ace.recipient import Recipient from edx_django_utils import monitoring as monitoring_utils from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication -from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser # lint-amnesty, pylint: disable=wrong-import-order +from edx_rest_framework_extensions.auth.session.authentication import ( + SessionAuthenticationAllowInactiveUser, # lint-amnesty, pylint: disable=wrong-import-order +) from eventtracking import tracker + # Note that this lives in LMS, so this dependency should be refactored. from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey from rest_framework.decorators import api_view, authentication_classes, permission_classes from rest_framework.permissions import IsAuthenticated +from common.djangoapps.course_modes.models import CourseMode +from common.djangoapps.edxmako.shortcuts import ( # lint-amnesty, pylint: disable=unused-import + marketing_link, + render_to_response, + render_to_string, +) +from common.djangoapps.entitlements.models import CourseEntitlement +from common.djangoapps.student.email_helpers import generate_activation_email_context +from common.djangoapps.student.helpers import ( + DISABLE_UNENROLL_CERT_STATES, + cert_info, + get_next_url_for_login_page, + get_redirect_url_with_host, +) +from common.djangoapps.student.message_types import ( # lint-amnesty, pylint: disable=line-too-long + AccountActivation, + EmailChange, + EmailChangeConfirmation, + RecoveryEmailCreate, +) +from common.djangoapps.student.models import ( # lint-amnesty, pylint: disable=unused-import + AccountRecovery, + CourseEnrollment, + EnrollmentNotAllowed, + PendingEmailChange, # unimport:skip + PendingSecondaryEmailChange, + Registration, + RegistrationCookieConfiguration, + UnenrollmentNotAllowed, + UserAttribute, + UserProfile, + UserSignupSource, + UserStanding, + create_comments_service_user, + email_exists_or_retired, +) +from common.djangoapps.student.signals import REFUND_ORDER, USER_EMAIL_CHANGED from common.djangoapps.student.toggles import should_redirect_to_courseware_after_enrollment from common.djangoapps.track import views as track_views +from common.djangoapps.util.db import outer_atomic +from common.djangoapps.util.json_request import JsonResponse from lms.djangoapps.bulk_email.models import Optout -from common.djangoapps.course_modes.models import CourseMode from lms.djangoapps.courseware.courses import get_courses, sort_by_announcement, sort_by_start_date -from common.djangoapps.edxmako.shortcuts import marketing_link, render_to_response, render_to_string # lint-amnesty, pylint: disable=unused-import -from common.djangoapps.entitlements.models import CourseEntitlement -from common.djangoapps.student.helpers import get_next_url_for_login_page, get_redirect_url_with_host from openedx.core.djangoapps.ace_common.template_context import get_base_template_context from openedx.core.djangoapps.catalog.utils import get_programs_with_type from openedx.core.djangoapps.embargo import api as embargo_api @@ -57,37 +99,14 @@ from openedx.core.djangoapps.user_api.preferences import api as preferences_api from openedx.core.djangoapps.user_authn.tasks import send_activation_email from openedx.core.djangoapps.user_authn.toggles import ( + is_auto_generated_username_enabled, should_redirect_to_authn_microfrontend, - is_auto_generated_username_enabled ) from openedx.core.djangolib.markup import HTML, Text from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser from openedx.features.course_experience.url_helpers import make_learning_mfe_courseware_url from openedx.features.discounts.applicability import FIRST_PURCHASE_DISCOUNT_OVERRIDE_FLAG from openedx.features.enterprise_support.utils import is_enterprise_learner -from common.djangoapps.student.email_helpers import generate_activation_email_context -from common.djangoapps.student.helpers import DISABLE_UNENROLL_CERT_STATES, cert_info -from common.djangoapps.student.message_types import AccountActivation, EmailChange, EmailChangeConfirmation, RecoveryEmailCreate # lint-amnesty, pylint: disable=line-too-long -from common.djangoapps.student.models import ( # lint-amnesty, pylint: disable=unused-import - AccountRecovery, - CourseEnrollment, - EnrollmentNotAllowed, - PendingEmailChange, # unimport:skip - PendingSecondaryEmailChange, - Registration, - RegistrationCookieConfiguration, - UnenrollmentNotAllowed, - UserAttribute, - UserProfile, - UserSignupSource, - UserStanding, - create_comments_service_user, - email_exists_or_retired -) -from common.djangoapps.student.signals import REFUND_ORDER -from common.djangoapps.util.db import outer_atomic -from common.djangoapps.util.json_request import JsonResponse -from common.djangoapps.student.signals import USER_EMAIL_CHANGED from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order log = logging.getLogger("edx.student") @@ -739,8 +758,10 @@ def validate_secondary_email(user, new_email): Enforce valid email addresses. """ - from openedx.core.djangoapps.user_api.accounts.api import get_email_validation_error, \ - get_secondary_email_validation_error + from openedx.core.djangoapps.user_api.accounts.api import ( + get_email_validation_error, + get_secondary_email_validation_error, + ) if get_email_validation_error(new_email): raise ValueError(_('Valid e-mail address required.')) diff --git a/common/djangoapps/third_party_auth/admin.py b/common/djangoapps/third_party_auth/admin.py index d44da6248ee2..ee222007b415 100644 --- a/common/djangoapps/third_party_auth/admin.py +++ b/common/djangoapps/third_party_auth/admin.py @@ -21,7 +21,7 @@ OAuth2ProviderConfig, SAMLConfiguration, SAMLProviderConfig, - SAMLProviderData + SAMLProviderData, ) from .tasks import fetch_saml_metadata, update_saml_users_social_auth_uid diff --git a/common/djangoapps/third_party_auth/api/permissions.py b/common/djangoapps/third_party_auth/api/permissions.py index f6eb430a367f..d38817d24878 100644 --- a/common/djangoapps/third_party_auth/api/permissions.py +++ b/common/djangoapps/third_party_auth/api/permissions.py @@ -10,7 +10,7 @@ IsSuperuser, JwtHasScope, JwtRestrictedApplication, - NotJwtRestrictedApplication + NotJwtRestrictedApplication, ) from rest_framework.permissions import BasePermission diff --git a/common/djangoapps/third_party_auth/api/tests/test_views.py b/common/djangoapps/third_party_auth/api/tests/test_views.py index 8f36305d33eb..5ff1b03d048a 100644 --- a/common/djangoapps/third_party_auth/api/tests/test_views.py +++ b/common/djangoapps/third_party_auth/api/tests/test_views.py @@ -20,7 +20,7 @@ from common.djangoapps.third_party_auth.api.permissions import ( JwtHasScope, JwtHasTpaProviderFilterForRequestedProvider, - JwtRestrictedApplication + JwtRestrictedApplication, ) from common.djangoapps.third_party_auth.tests.testutil import ThirdPartyAuthTestMixin from openedx.core.djangolib.testing.utils import skip_unless_lms diff --git a/common/djangoapps/third_party_auth/api/views.py b/common/djangoapps/third_party_auth/api/views.py index 5d9643c049a1..215d2a939961 100644 --- a/common/djangoapps/third_party_auth/api/views.py +++ b/common/djangoapps/third_party_auth/api/views.py @@ -17,17 +17,14 @@ from rest_framework.views import APIView from social_django.models import UserSocialAuth -from openedx.core.lib.api.authentication import ( - BearerAuthentication, - BearerAuthenticationAllowInactiveUser -) -from openedx.core.lib.api.permissions import ApiKeyHeaderPermission -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from common.djangoapps.third_party_auth import pipeline from common.djangoapps.third_party_auth.api import serializers from common.djangoapps.third_party_auth.api.permissions import TPA_PERMISSIONS -from common.djangoapps.third_party_auth.provider import Registry from common.djangoapps.third_party_auth.api.utils import filter_user_social_auth_queryset_by_provider +from common.djangoapps.third_party_auth.provider import Registry +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.lib.api.authentication import BearerAuthentication, BearerAuthenticationAllowInactiveUser +from openedx.core.lib.api.permissions import ApiKeyHeaderPermission class ProviderBaseThrottle(throttling.UserRateThrottle): diff --git a/common/djangoapps/third_party_auth/appleid.py b/common/djangoapps/third_party_auth/appleid.py index c1ff6a16086a..cd223c026aa4 100644 --- a/common/djangoapps/third_party_auth/appleid.py +++ b/common/djangoapps/third_party_auth/appleid.py @@ -75,13 +75,12 @@ import time import jwt +import social_django +from django.apps import apps from jwt.algorithms import RSAAlgorithm from jwt.exceptions import PyJWTError - -from django.apps import apps from social_core.backends.oauth import BaseOAuth2 from social_core.exceptions import AuthFailed -import social_django from common.djangoapps.third_party_auth.toggles import is_apple_user_migration_enabled diff --git a/common/djangoapps/third_party_auth/identityserver3.py b/common/djangoapps/third_party_auth/identityserver3.py index 95761f449633..b16d2a4bc63d 100644 --- a/common/djangoapps/third_party_auth/identityserver3.py +++ b/common/djangoapps/third_party_auth/identityserver3.py @@ -5,8 +5,8 @@ docs for adding a new backend to python-social-auth: https://python-social-auth.readthedocs.io/en/latest/backends/implementation.html#oauth """ -from social_core.backends.oauth import BaseOAuth2 from django.utils.functional import cached_property +from social_core.backends.oauth import BaseOAuth2 class IdentityServer3(BaseOAuth2): diff --git a/common/djangoapps/third_party_auth/lti.py b/common/djangoapps/third_party_auth/lti.py index 496b7dcbbbab..daa634a64f92 100644 --- a/common/djangoapps/third_party_auth/lti.py +++ b/common/djangoapps/third_party_auth/lti.py @@ -10,11 +10,11 @@ from django.contrib.auth import REDIRECT_FIELD_NAME from oauthlib.common import Request from oauthlib.oauth1.rfc5849.signature import ( - collect_parameters, - signature_base_string, base_string_uri, + collect_parameters, normalize_parameters, - sign_hmac_sha1 + sign_hmac_sha1, + signature_base_string, ) from social_core.backends.base import BaseAuth from social_core.exceptions import AuthFailed diff --git a/common/djangoapps/third_party_auth/management/commands/generate_and_store_apple_transfer_ids.py b/common/djangoapps/third_party_auth/management/commands/generate_and_store_apple_transfer_ids.py index ec193ba8a422..3b99df684978 100644 --- a/common/djangoapps/third_party_auth/management/commands/generate_and_store_apple_transfer_ids.py +++ b/common/djangoapps/third_party_auth/management/commands/generate_and_store_apple_transfer_ids.py @@ -5,19 +5,18 @@ import logging -import requests import time +import jwt +import requests from django.core.management.base import BaseCommand, CommandError from django.db import transaction from django.db.models import Q -import jwt from social_django.models import UserSocialAuth from social_django.utils import load_strategy - -from common.djangoapps.third_party_auth.models import AppleMigrationUserIdInfo from common.djangoapps.third_party_auth.appleid import AppleIdAuth +from common.djangoapps.third_party_auth.models import AppleMigrationUserIdInfo log = logging.getLogger(__name__) diff --git a/common/djangoapps/third_party_auth/management/commands/generate_and_store_new_apple_ids.py b/common/djangoapps/third_party_auth/management/commands/generate_and_store_new_apple_ids.py index 49ed93441165..d33ec223b93d 100644 --- a/common/djangoapps/third_party_auth/management/commands/generate_and_store_new_apple_ids.py +++ b/common/djangoapps/third_party_auth/management/commands/generate_and_store_new_apple_ids.py @@ -5,17 +5,17 @@ import logging -import requests import time +import jwt +import requests from django.core.management.base import BaseCommand, CommandError from django.db import transaction from django.db.models import Q -import jwt from social_django.utils import load_strategy -from common.djangoapps.third_party_auth.models import AppleMigrationUserIdInfo from common.djangoapps.third_party_auth.appleid import AppleIdAuth +from common.djangoapps.third_party_auth.models import AppleMigrationUserIdInfo log = logging.getLogger(__name__) diff --git a/common/djangoapps/third_party_auth/management/commands/saml.py b/common/djangoapps/third_party_auth/management/commands/saml.py index 6865ebf69987..84b8712287a0 100644 --- a/common/djangoapps/third_party_auth/management/commands/saml.py +++ b/common/djangoapps/third_party_auth/management/commands/saml.py @@ -7,8 +7,8 @@ from django.core.management.base import BaseCommand, CommandError +from common.djangoapps.third_party_auth.models import SAMLConfiguration, SAMLProviderConfig from common.djangoapps.third_party_auth.tasks import fetch_saml_metadata -from common.djangoapps.third_party_auth.models import SAMLProviderConfig, SAMLConfiguration class Command(BaseCommand): diff --git a/common/djangoapps/third_party_auth/management/commands/tests/test_generate_and_store_apple_transfer_ids.py b/common/djangoapps/third_party_auth/management/commands/tests/test_generate_and_store_apple_transfer_ids.py index e80b8069c913..bf8958fdf419 100644 --- a/common/djangoapps/third_party_auth/management/commands/tests/test_generate_and_store_apple_transfer_ids.py +++ b/common/djangoapps/third_party_auth/management/commands/tests/test_generate_and_store_apple_transfer_ids.py @@ -3,8 +3,8 @@ """ import json - from unittest import mock + from django.core.management import call_command from django.core.management.base import CommandError from django.test import TestCase diff --git a/common/djangoapps/third_party_auth/management/commands/tests/test_generate_and_store_new_apple_ids.py b/common/djangoapps/third_party_auth/management/commands/tests/test_generate_and_store_new_apple_ids.py index 2d79187215b2..34b93814c137 100644 --- a/common/djangoapps/third_party_auth/management/commands/tests/test_generate_and_store_new_apple_ids.py +++ b/common/djangoapps/third_party_auth/management/commands/tests/test_generate_and_store_new_apple_ids.py @@ -3,8 +3,8 @@ """ import json - from unittest import mock + from django.core.management import call_command from django.core.management.base import CommandError from django.test import TestCase diff --git a/common/djangoapps/third_party_auth/management/commands/tests/test_saml.py b/common/djangoapps/third_party_auth/management/commands/tests/test_saml.py index 625246d3212e..7947376f05c5 100644 --- a/common/djangoapps/third_party_auth/management/commands/tests/test_saml.py +++ b/common/djangoapps/third_party_auth/management/commands/tests/test_saml.py @@ -6,8 +6,8 @@ import os from io import StringIO - from unittest import mock + from ddt import ddt from django.contrib.sites.models import Site from django.core.management import call_command @@ -15,8 +15,8 @@ from requests import exceptions from requests.models import Response -from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms from common.djangoapps.third_party_auth.tests.factories import SAMLConfigurationFactory, SAMLProviderConfigFactory +from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms def mock_get(status_code=200): diff --git a/common/djangoapps/third_party_auth/management/commands/tests/test_update_new_apple_ids_in_social_auth.py b/common/djangoapps/third_party_auth/management/commands/tests/test_update_new_apple_ids_in_social_auth.py index be8f31736dcd..e94d86619fb4 100644 --- a/common/djangoapps/third_party_auth/management/commands/tests/test_update_new_apple_ids_in_social_auth.py +++ b/common/djangoapps/third_party_auth/management/commands/tests/test_update_new_apple_ids_in_social_auth.py @@ -3,6 +3,7 @@ """ from unittest import mock + from django.core.management import call_command from django.test import TestCase from social_django.models import UserSocialAuth diff --git a/common/djangoapps/third_party_auth/management/commands/update_new_apple_ids_in_social_auth.py b/common/djangoapps/third_party_auth/management/commands/update_new_apple_ids_in_social_auth.py index 2d39fe83be7a..7d33cb462b68 100644 --- a/common/djangoapps/third_party_auth/management/commands/update_new_apple_ids_in_social_auth.py +++ b/common/djangoapps/third_party_auth/management/commands/update_new_apple_ids_in_social_auth.py @@ -9,8 +9,8 @@ from django.db.models import Q from social_django.models import UserSocialAuth -from common.djangoapps.third_party_auth.models import AppleMigrationUserIdInfo from common.djangoapps.third_party_auth.appleid import AppleIdAuth +from common.djangoapps.third_party_auth.models import AppleMigrationUserIdInfo log = logging.getLogger(__name__) diff --git a/common/djangoapps/third_party_auth/migrations/0001_squashed_0026_auto_20200401_1932.py b/common/djangoapps/third_party_auth/migrations/0001_squashed_0026_auto_20200401_1932.py index 6b2de4549c84..715eebd5cf87 100644 --- a/common/djangoapps/third_party_auth/migrations/0001_squashed_0026_auto_20200401_1932.py +++ b/common/djangoapps/third_party_auth/migrations/0001_squashed_0026_auto_20200401_1932.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.12 on 2020-04-21 20:52 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion import openedx.core.lib.hash_utils from common.djangoapps.third_party_auth import models as third_party_auth_models diff --git a/common/djangoapps/third_party_auth/migrations/0004_auto_20200919_0955.py b/common/djangoapps/third_party_auth/migrations/0004_auto_20200919_0955.py index a397de017707..2a4574a17583 100644 --- a/common/djangoapps/third_party_auth/migrations/0004_auto_20200919_0955.py +++ b/common/djangoapps/third_party_auth/migrations/0004_auto_20200919_0955.py @@ -1,6 +1,7 @@ # Generated by Django 2.2.16 on 2020-09-19 09:55 from django.db import migrations, models + import openedx.core.lib.hash_utils diff --git a/common/djangoapps/third_party_auth/migrations/0009_historicalusersocialauth.py b/common/djangoapps/third_party_auth/migrations/0009_historicalusersocialauth.py index 5857822d1d42..6fed97266f9c 100644 --- a/common/djangoapps/third_party_auth/migrations/0009_historicalusersocialauth.py +++ b/common/djangoapps/third_party_auth/migrations/0009_historicalusersocialauth.py @@ -1,10 +1,10 @@ # Generated by Django 3.2.12 on 2022-04-15 01:04 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import simple_history.models import social_django.fields +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/common/djangoapps/third_party_auth/migrations/0012_alter_ltiproviderconfig_site_and_more.py b/common/djangoapps/third_party_auth/migrations/0012_alter_ltiproviderconfig_site_and_more.py index ba9854b1fc2c..ca1037d122c0 100644 --- a/common/djangoapps/third_party_auth/migrations/0012_alter_ltiproviderconfig_site_and_more.py +++ b/common/djangoapps/third_party_auth/migrations/0012_alter_ltiproviderconfig_site_and_more.py @@ -1,7 +1,7 @@ # Generated by Django 4.2.5 on 2023-09-25 09:45 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/common/djangoapps/third_party_auth/migrations/0013_default_site_id_wrapper_function.py b/common/djangoapps/third_party_auth/migrations/0013_default_site_id_wrapper_function.py index 250e5370854e..21223b8d5ff5 100644 --- a/common/djangoapps/third_party_auth/migrations/0013_default_site_id_wrapper_function.py +++ b/common/djangoapps/third_party_auth/migrations/0013_default_site_id_wrapper_function.py @@ -1,8 +1,9 @@ # Generated by Django 4.2.13 on 2024-05-13 19:22 -import common.djangoapps.third_party_auth.models -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models + +import common.djangoapps.third_party_auth.models class Migration(migrations.Migration): diff --git a/common/djangoapps/third_party_auth/migrations/0014_samlproviderconfig_optional_email_checkboxes.py b/common/djangoapps/third_party_auth/migrations/0014_samlproviderconfig_optional_email_checkboxes.py index 34fcf3c97b58..25bb88077f65 100644 --- a/common/djangoapps/third_party_auth/migrations/0014_samlproviderconfig_optional_email_checkboxes.py +++ b/common/djangoapps/third_party_auth/migrations/0014_samlproviderconfig_optional_email_checkboxes.py @@ -1,7 +1,7 @@ # Generated migration for adding optional checkbox skip configuration field -from django.db import migrations, models import django.utils.translation +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/common/djangoapps/third_party_auth/pipeline.py b/common/djangoapps/third_party_auth/pipeline.py index 4b8804ca3802..817fae083b2f 100644 --- a/common/djangoapps/third_party_auth/pipeline.py +++ b/common/djangoapps/third_party_auth/pipeline.py @@ -64,15 +64,15 @@ def B(*args, **kwargs): import json from collections import OrderedDict from logging import getLogger +from random import randint from smtplib import SMTPException from uuid import uuid4 -from random import randint import six import social_django from django.conf import settings +from django.contrib.auth import REDIRECT_FIELD_NAME, logout from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user -from django.contrib.auth import logout, REDIRECT_FIELD_NAME from django.core.mail.message import EmailMessage from django.http import HttpResponseBadRequest from django.shortcuts import redirect @@ -84,15 +84,6 @@ def B(*args, **kwargs): from common.djangoapps import third_party_auth from common.djangoapps.edxmako.shortcuts import render_to_string -from lms.djangoapps.verify_student.models import SSOVerification -from lms.djangoapps.verify_student.utils import earliest_allowed_verification_date -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers -from openedx.core.djangoapps.user_api import accounts -from openedx.core.djangoapps.user_api.accounts.utils import username_suffix_generator -from openedx.core.djangoapps.user_authn import cookies as user_authn_cookies -from openedx.core.djangoapps.user_authn.toggles import is_auto_generated_username_enabled -from openedx.core.djangoapps.user_authn.utils import is_safe_login_or_logout_redirect -from openedx.core.djangoapps.user_authn.views.utils import get_auto_generated_username from common.djangoapps.third_party_auth.utils import ( get_associated_user_by_email_response, get_user_from_email, @@ -103,6 +94,15 @@ def B(*args, **kwargs): ) from common.djangoapps.track import segment from common.djangoapps.util.json_request import JsonResponse +from lms.djangoapps.verify_student.models import SSOVerification +from lms.djangoapps.verify_student.utils import earliest_allowed_verification_date +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.djangoapps.user_api import accounts +from openedx.core.djangoapps.user_api.accounts.utils import username_suffix_generator +from openedx.core.djangoapps.user_authn import cookies as user_authn_cookies +from openedx.core.djangoapps.user_authn.toggles import is_auto_generated_username_enabled +from openedx.core.djangoapps.user_authn.utils import is_safe_login_or_logout_redirect +from openedx.core.djangoapps.user_authn.views.utils import get_auto_generated_username from . import provider diff --git a/common/djangoapps/third_party_auth/provider.py b/common/djangoapps/third_party_auth/provider.py index 5eaf0f1888de..e1eecf07ad92 100644 --- a/common/djangoapps/third_party_auth/provider.py +++ b/common/djangoapps/third_party_auth/provider.py @@ -5,8 +5,6 @@ from django.contrib.sites.models import Site -from openedx.core.djangoapps.theming.helpers import get_current_request - from common.djangoapps.third_party_auth.models import ( _LTI_BACKENDS, _PSA_OAUTH2_BACKENDS, @@ -14,8 +12,9 @@ LTIProviderConfig, OAuth2ProviderConfig, SAMLConfiguration, - SAMLProviderConfig + SAMLProviderConfig, ) +from openedx.core.djangoapps.theming.helpers import get_current_request class Registry: diff --git a/common/djangoapps/third_party_auth/saml.py b/common/djangoapps/third_party_auth/saml.py index ce5375ec95fb..96e75d6661c4 100644 --- a/common/djangoapps/third_party_auth/saml.py +++ b/common/djangoapps/third_party_auth/saml.py @@ -8,15 +8,15 @@ import requests from django.contrib.sites.models import Site from django.http import Http404 -from django.utils.functional import cached_property from django.utils.datastructures import MultiValueDictKeyError +from django.utils.functional import cached_property from django_countries import countries from onelogin.saml2.settings import OneLogin_Saml2_Settings from social_core.backends.saml import OID_EDU_PERSON_ENTITLEMENT, SAMLAuth, SAMLIdentityProvider -from social_core.exceptions import AuthForbidden, AuthMissingParameter, AuthInvalidParameter +from social_core.exceptions import AuthForbidden, AuthInvalidParameter, AuthMissingParameter -from openedx.core.djangoapps.theming.helpers import get_current_request from common.djangoapps.third_party_auth.exceptions import IncorrectConfigurationException +from openedx.core.djangoapps.theming.helpers import get_current_request STANDARD_SAML_PROVIDER_KEY = 'standard_saml_provider' SAP_SUCCESSFACTORS_SAML_KEY = 'sap_success_factors' diff --git a/common/djangoapps/third_party_auth/saml_configuration/tests/test_saml_configuration.py b/common/djangoapps/third_party_auth/saml_configuration/tests/test_saml_configuration.py index c2796d3c1676..341adace754d 100644 --- a/common/djangoapps/third_party_auth/saml_configuration/tests/test_saml_configuration.py +++ b/common/djangoapps/third_party_auth/saml_configuration/tests/test_saml_configuration.py @@ -1,14 +1,15 @@ """ Tests for SAMLConfiguration endpoints """ -from django.urls import reverse from django.contrib.sites.models import Site - +from django.urls import reverse from rest_framework import status from rest_framework.test import APITestCase + from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.third_party_auth.models import SAMLConfiguration from common.djangoapps.third_party_auth.tests.utils import skip_unless_thirdpartyauth + SAML_CONFIGURATIONS = [ { 'site': 1, diff --git a/common/djangoapps/third_party_auth/samlproviderconfig/serializers.py b/common/djangoapps/third_party_auth/samlproviderconfig/serializers.py index 4a01d0679c87..b8a046dbba5f 100644 --- a/common/djangoapps/third_party_auth/samlproviderconfig/serializers.py +++ b/common/djangoapps/third_party_auth/samlproviderconfig/serializers.py @@ -3,9 +3,10 @@ """ import logging + from rest_framework import serializers -from common.djangoapps.third_party_auth.models import SAMLProviderConfig, SAMLConfiguration +from common.djangoapps.third_party_auth.models import SAMLConfiguration, SAMLProviderConfig log = logging.getLogger(__name__) diff --git a/common/djangoapps/third_party_auth/samlproviderconfig/tests/test_samlproviderconfig.py b/common/djangoapps/third_party_auth/samlproviderconfig/tests/test_samlproviderconfig.py index c8e8487b659d..493018c7bd0a 100644 --- a/common/djangoapps/third_party_auth/samlproviderconfig/tests/test_samlproviderconfig.py +++ b/common/djangoapps/third_party_auth/samlproviderconfig/tests/test_samlproviderconfig.py @@ -4,17 +4,18 @@ import copy import re from uuid import uuid4 -from django.urls import reverse + from django.contrib.sites.models import Site +from django.urls import reverse from django.utils.http import urlencode +from enterprise.constants import ENTERPRISE_ADMIN_ROLE, ENTERPRISE_LEARNER_ROLE +from enterprise.models import EnterpriseCustomer, EnterpriseCustomerIdentityProvider from rest_framework import status from rest_framework.test import APITestCase -from enterprise.models import EnterpriseCustomerIdentityProvider, EnterpriseCustomer -from enterprise.constants import ENTERPRISE_ADMIN_ROLE, ENTERPRISE_LEARNER_ROLE from common.djangoapps.student.tests.factories import UserFactory +from common.djangoapps.third_party_auth.models import SAMLConfiguration, SAMLProviderConfig from common.djangoapps.third_party_auth.tests.samlutils import set_jwt_cookie -from common.djangoapps.third_party_auth.models import SAMLProviderConfig, SAMLConfiguration from common.djangoapps.third_party_auth.tests.utils import skip_unless_thirdpartyauth from common.djangoapps.third_party_auth.utils import convert_saml_slug_provider_id diff --git a/common/djangoapps/third_party_auth/samlproviderconfig/views.py b/common/djangoapps/third_party_auth/samlproviderconfig/views.py index 7286402df5bd..f4d06464fc17 100644 --- a/common/djangoapps/third_party_auth/samlproviderconfig/views.py +++ b/common/djangoapps/third_party_auth/samlproviderconfig/views.py @@ -2,19 +2,19 @@ Viewset for auth/saml/v0/samlproviderconfig """ -from django.shortcuts import get_list_or_404 from django.db.utils import IntegrityError +from django.shortcuts import get_list_or_404 from edx_rbac.mixins import PermissionRequiredMixin -from rest_framework import permissions, viewsets, status -from rest_framework.response import Response +from enterprise.models import EnterpriseCustomer, EnterpriseCustomerIdentityProvider +from rest_framework import permissions, status, viewsets from rest_framework.exceptions import ParseError, ValidationError +from rest_framework.response import Response -from enterprise.models import EnterpriseCustomerIdentityProvider, EnterpriseCustomer from common.djangoapps.third_party_auth.utils import validate_uuid4_string from ..models import SAMLProviderConfig -from .serializers import SAMLProviderConfigSerializer from ..utils import convert_saml_slug_provider_id +from .serializers import SAMLProviderConfigSerializer class SAMLProviderMixin: diff --git a/common/djangoapps/third_party_auth/samlproviderdata/views.py b/common/djangoapps/third_party_auth/samlproviderdata/views.py index b5d044bd0498..a8ae055f9d26 100644 --- a/common/djangoapps/third_party_auth/samlproviderdata/views.py +++ b/common/djangoapps/third_party_auth/samlproviderdata/views.py @@ -1,14 +1,14 @@ """ Viewset for auth/saml/v0/samlproviderdata """ -from datetime import datetime import logging -from requests.exceptions import SSLError, MissingSchema, HTTPError +from datetime import datetime from django.http import Http404 from django.shortcuts import get_object_or_404 from edx_rbac.mixins import PermissionRequiredMixin from enterprise.models import EnterpriseCustomerIdentityProvider +from requests.exceptions import HTTPError, MissingSchema, SSLError from rest_framework import permissions, status, viewsets from rest_framework.decorators import action from rest_framework.exceptions import ParseError @@ -19,7 +19,7 @@ create_or_update_bulk_saml_provider_data, fetch_metadata_xml, parse_metadata_xml, - validate_uuid4_string + validate_uuid4_string, ) from ..models import SAMLProviderConfig, SAMLProviderData diff --git a/common/djangoapps/third_party_auth/signals/tests/test_handlers.py b/common/djangoapps/third_party_auth/signals/tests/test_handlers.py index a948dc5b8fc2..71f7f9b77f80 100644 --- a/common/djangoapps/third_party_auth/signals/tests/test_handlers.py +++ b/common/djangoapps/third_party_auth/signals/tests/test_handlers.py @@ -2,13 +2,15 @@ Tests for SAML configuration signal handlers. """ -import ddt from unittest import mock from unittest.mock import call -from django.test import TestCase + +import ddt from django.contrib.sites.models import Site -from common.djangoapps.third_party_auth.tests.factories import SAMLConfigurationFactory, SAMLProviderConfigFactory +from django.test import TestCase + from common.djangoapps.third_party_auth.models import SAMLProviderConfig +from common.djangoapps.third_party_auth.tests.factories import SAMLConfigurationFactory, SAMLProviderConfigFactory @ddt.ddt diff --git a/common/djangoapps/third_party_auth/tests/data/saml_identity_provider_mock_data.py b/common/djangoapps/third_party_auth/tests/data/saml_identity_provider_mock_data.py index dc05b549e23b..3632badc854a 100644 --- a/common/djangoapps/third_party_auth/tests/data/saml_identity_provider_mock_data.py +++ b/common/djangoapps/third_party_auth/tests/data/saml_identity_provider_mock_data.py @@ -1,7 +1,7 @@ """Mock data for SAMLIdentityProvider""" -from social_core.backends.saml import OID_MAIL, OID_GIVEN_NAME, OID_SURNAME, OID_COMMON_NAME, OID_USERID +from social_core.backends.saml import OID_COMMON_NAME, OID_GIVEN_NAME, OID_MAIL, OID_SURNAME, OID_USERID expected_user_details = { 'username': 'myself', diff --git a/common/djangoapps/third_party_auth/tests/factories.py b/common/djangoapps/third_party_auth/tests/factories.py index b47da33d81e2..58acf574c1d8 100644 --- a/common/djangoapps/third_party_auth/tests/factories.py +++ b/common/djangoapps/third_party_auth/tests/factories.py @@ -7,9 +7,7 @@ from factory.django import DjangoModelFactory from faker import Factory as FakerFactory -from common.djangoapps.third_party_auth.models import ( - OAuth2ProviderConfig, SAMLConfiguration, SAMLProviderConfig -) +from common.djangoapps.third_party_auth.models import OAuth2ProviderConfig, SAMLConfiguration, SAMLProviderConfig from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory FAKER = FakerFactory.create() diff --git a/common/djangoapps/third_party_auth/tests/specs/base.py b/common/djangoapps/third_party_auth/tests/specs/base.py index 524cd64ff366..22ae2c77a950 100644 --- a/common/djangoapps/third_party_auth/tests/specs/base.py +++ b/common/djangoapps/third_party_auth/tests/specs/base.py @@ -9,29 +9,28 @@ import pytest from django import test -from django.conf import settings +from django.conf import settings # lint-amnesty, pylint: disable=reimported +from django.conf import settings as django_settings # pylint: disable=reimported from django.contrib import auth, messages from django.contrib.auth import models as auth_models from django.contrib.messages.storage import fallback from django.contrib.sessions.backends import cache -from django.urls import reverse from django.test import utils as django_utils -from django.conf import settings as django_settings # lint-amnesty, pylint: disable=reimported +from django.urls import reverse from social_core import actions, exceptions from social_django import utils as social_utils from social_django import views as social_views -from lms.djangoapps.commerce.tests import TEST_API_URL -from openedx.core.djangoapps.user_authn.views.login import login_user -from openedx.core.djangoapps.user_authn.views.login_form import login_and_registration_form -from openedx.core.djangoapps.user_authn.views.register import RegistrationView -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers -from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory from common.djangoapps.student import models as student_models from common.djangoapps.student.tests.factories import UserFactory - from common.djangoapps.third_party_auth import middleware, pipeline from common.djangoapps.third_party_auth.tests import testutil +from lms.djangoapps.commerce.tests import TEST_API_URL +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory +from openedx.core.djangoapps.user_authn.views.login import login_user +from openedx.core.djangoapps.user_authn.views.login_form import login_and_registration_form +from openedx.core.djangoapps.user_authn.views.register import RegistrationView def create_account(request): diff --git a/common/djangoapps/third_party_auth/tests/specs/test_generic.py b/common/djangoapps/third_party_auth/tests/specs/test_generic.py index b9a41914e9e3..cb82c780c1d9 100644 --- a/common/djangoapps/third_party_auth/tests/specs/test_generic.py +++ b/common/djangoapps/third_party_auth/tests/specs/test_generic.py @@ -3,6 +3,7 @@ """ from common.djangoapps.third_party_auth.tests import testutil from common.djangoapps.third_party_auth.tests.utils import skip_unless_thirdpartyauth + from .base import IntegrationTestMixin diff --git a/common/djangoapps/third_party_auth/tests/specs/test_lti.py b/common/djangoapps/third_party_auth/tests/specs/test_lti.py index 9b7935e550e6..4fdd03706e52 100644 --- a/common/djangoapps/third_party_auth/tests/specs/test_lti.py +++ b/common/djangoapps/third_party_auth/tests/specs/test_lti.py @@ -4,7 +4,7 @@ from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.urls import reverse -from oauthlib.oauth1.rfc5849 import Client, SIGNATURE_TYPE_BODY +from oauthlib.oauth1.rfc5849 import SIGNATURE_TYPE_BODY, Client from common.djangoapps.third_party_auth.tests import testutil from openedx.core.djangolib.testing.utils import skip_unless_lms diff --git a/common/djangoapps/third_party_auth/tests/specs/test_testshib.py b/common/djangoapps/third_party_auth/tests/specs/test_testshib.py index 47fcfa5b0bac..34331555bbeb 100644 --- a/common/djangoapps/third_party_auth/tests/specs/test_testshib.py +++ b/common/djangoapps/third_party_auth/tests/specs/test_testshib.py @@ -8,6 +8,7 @@ import os from unittest import skip from unittest.mock import MagicMock, patch +from urllib.parse import parse_qs, quote, urlparse import ddt import httpretty @@ -26,12 +27,11 @@ from common.djangoapps.third_party_auth.saml import log as saml_log from common.djangoapps.third_party_auth.tasks import fetch_saml_metadata from common.djangoapps.third_party_auth.tests import testutil, utils +from common.test.utils import assert_dict_contains_subset from openedx.core.djangoapps.user_authn.views.login import login_user from openedx.features.enterprise_support.tests.factories import EnterpriseCustomerFactory from .base import IntegrationTestMixin -from common.test.utils import assert_dict_contains_subset -from urllib.parse import urlparse, parse_qs, quote TESTSHIB_ENTITY_ID = "https://idp.testshib.org/idp/shibboleth" TESTSHIB_METADATA_URL = "https://mock.testshib.org/metadata/testshib-providers.xml" diff --git a/common/djangoapps/third_party_auth/tests/specs/test_twitter.py b/common/djangoapps/third_party_auth/tests/specs/test_twitter.py index d67373ccf679..a9a4e95cc55c 100644 --- a/common/djangoapps/third_party_auth/tests/specs/test_twitter.py +++ b/common/djangoapps/third_party_auth/tests/specs/test_twitter.py @@ -4,6 +4,7 @@ from unittest.mock import patch + from common.djangoapps.third_party_auth.tests.specs import base diff --git a/common/djangoapps/third_party_auth/tests/test_admin.py b/common/djangoapps/third_party_auth/tests/test_admin.py index 0acfb3492a6f..fdba2106244f 100644 --- a/common/djangoapps/third_party_auth/tests/test_admin.py +++ b/common/djangoapps/third_party_auth/tests/test_admin.py @@ -13,7 +13,6 @@ from common.djangoapps.third_party_auth.tests import testutil from common.djangoapps.third_party_auth.tests.utils import skip_unless_thirdpartyauth - TEST_PASSWORD = 'Password1234' diff --git a/common/djangoapps/third_party_auth/tests/test_identityserver3.py b/common/djangoapps/third_party_auth/tests/test_identityserver3.py index d25a6c81dfca..53499b661978 100644 --- a/common/djangoapps/third_party_auth/tests/test_identityserver3.py +++ b/common/djangoapps/third_party_auth/tests/test_identityserver3.py @@ -2,7 +2,9 @@ Unit tests for the IdentityServer3 OAuth2 Backend """ import json + import ddt + from common.djangoapps.third_party_auth.identityserver3 import IdentityServer3 from common.djangoapps.third_party_auth.tests import testutil from common.djangoapps.third_party_auth.tests.utils import skip_unless_thirdpartyauth diff --git a/common/djangoapps/third_party_auth/tests/test_middleware.py b/common/djangoapps/third_party_auth/tests/test_middleware.py index d99488b02aa1..503907202061 100644 --- a/common/djangoapps/third_party_auth/tests/test_middleware.py +++ b/common/djangoapps/third_party_auth/tests/test_middleware.py @@ -4,15 +4,16 @@ from unittest import mock + from django.contrib.messages.middleware import MessageMiddleware from django.http import HttpResponse from django.test.client import RequestFactory from requests.exceptions import HTTPError -from openedx.core.djangolib.testing.utils import skip_unless_lms from common.djangoapps.student.helpers import get_next_url_for_login_page from common.djangoapps.third_party_auth.middleware import ExceptionMiddleware from common.djangoapps.third_party_auth.tests.testutil import TestCase +from openedx.core.djangolib.testing.utils import skip_unless_lms class ThirdPartyAuthMiddlewareTestCase(TestCase): diff --git a/common/djangoapps/third_party_auth/tests/test_models.py b/common/djangoapps/third_party_auth/tests/test_models.py index ed0b74ebb396..4db68fec5d8c 100644 --- a/common/djangoapps/third_party_auth/tests/test_models.py +++ b/common/djangoapps/third_party_auth/tests/test_models.py @@ -2,10 +2,11 @@ Tests for third_party_auth/models.py. """ import unittest + from django.test import TestCase, override_settings -from .factories import SAMLProviderConfigFactory from ..models import SAMLProviderConfig, clean_username +from .factories import SAMLProviderConfigFactory class TestSamlProviderConfigModel(TestCase, unittest.TestCase): diff --git a/common/djangoapps/third_party_auth/tests/test_pipeline_integration.py b/common/djangoapps/third_party_auth/tests/test_pipeline_integration.py index 66c57118bfb9..f38fed62085b 100644 --- a/common/djangoapps/third_party_auth/tests/test_pipeline_integration.py +++ b/common/djangoapps/third_party_auth/tests/test_pipeline_integration.py @@ -8,7 +8,7 @@ import ddt import pytest from django import test -from django.contrib.auth import models, REDIRECT_FIELD_NAME +from django.contrib.auth import REDIRECT_FIELD_NAME, models from django.core import mail from social_django import models as social_models diff --git a/common/djangoapps/third_party_auth/tests/test_provider.py b/common/djangoapps/third_party_auth/tests/test_provider.py index 28e95c16b8f9..7dbb79a72cd7 100644 --- a/common/djangoapps/third_party_auth/tests/test_provider.py +++ b/common/djangoapps/third_party_auth/tests/test_provider.py @@ -12,7 +12,8 @@ from common.djangoapps.third_party_auth.tests import testutil from common.djangoapps.third_party_auth.tests.utils import skip_unless_thirdpartyauth from openedx.core.djangoapps.site_configuration.tests.test_util import ( - with_site_configuration, with_site_configuration_context + with_site_configuration, + with_site_configuration_context, ) SITE_DOMAIN_A = 'professionalx.example.com' diff --git a/common/djangoapps/third_party_auth/tests/test_saml.py b/common/djangoapps/third_party_auth/tests/test_saml.py index d6d3e0e27c24..aeb3b0e3e3ea 100644 --- a/common/djangoapps/third_party_auth/tests/test_saml.py +++ b/common/djangoapps/third_party_auth/tests/test_saml.py @@ -8,11 +8,11 @@ from social_core.exceptions import AuthMissingParameter from common.djangoapps.third_party_auth.dummy import DummyBackend -from common.djangoapps.third_party_auth.saml import EdXSAMLIdentityProvider, get_saml_idp_class, SAMLAuthBackend +from common.djangoapps.third_party_auth.saml import EdXSAMLIdentityProvider, SAMLAuthBackend, get_saml_idp_class from common.djangoapps.third_party_auth.tests.data.saml_identity_provider_mock_data import ( expected_user_details, mock_attributes, - mock_conf + mock_conf, ) from common.djangoapps.third_party_auth.tests.testutil import SAMLTestCase diff --git a/common/djangoapps/third_party_auth/tests/test_utils.py b/common/djangoapps/third_party_auth/tests/test_utils.py index c1b3fd98b545..c7d20a9a2a05 100644 --- a/common/djangoapps/third_party_auth/tests/test_utils.py +++ b/common/djangoapps/third_party_auth/tests/test_utils.py @@ -11,13 +11,13 @@ from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.third_party_auth.tests.testutil import TestCase from common.djangoapps.third_party_auth.utils import ( + convert_saml_slug_provider_id, get_associated_user_by_email_response, get_user_from_email, is_enterprise_customer_user, is_oauth_provider, parse_metadata_xml, user_exists, - convert_saml_slug_provider_id, ) from openedx.core.djangolib.testing.utils import skip_unless_lms from openedx.features.enterprise_support.tests.factories import ( diff --git a/common/djangoapps/third_party_auth/tests/test_views.py b/common/djangoapps/third_party_auth/tests/test_views.py index 859967ffa05f..3a5f46a44d41 100644 --- a/common/djangoapps/third_party_auth/tests/test_views.py +++ b/common/djangoapps/third_party_auth/tests/test_views.py @@ -18,6 +18,7 @@ from common.djangoapps.student.models import Registration from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.third_party_auth import pipeline + # Define some XML namespaces: from common.djangoapps.third_party_auth.utils import SAML_XML_NS from common.djangoapps.third_party_auth.views import inactive_user_view diff --git a/common/djangoapps/third_party_auth/tests/testutil.py b/common/djangoapps/third_party_auth/tests/testutil.py index 33eb30009b41..e9ba52ae0e2d 100644 --- a/common/djangoapps/third_party_auth/tests/testutil.py +++ b/common/djangoapps/third_party_auth/tests/testutil.py @@ -20,7 +20,7 @@ LTIProviderConfig, OAuth2ProviderConfig, SAMLConfiguration, - SAMLProviderConfig + SAMLProviderConfig, ) from common.djangoapps.third_party_auth.models import cache as config_cache from openedx.core.djangolib.testing.utils import CacheIsolationMixin diff --git a/common/djangoapps/third_party_auth/tests/utils.py b/common/djangoapps/third_party_auth/tests/utils.py index 8d1bafcdd887..1748d0a5030a 100644 --- a/common/djangoapps/third_party_auth/tests/utils.py +++ b/common/djangoapps/third_party_auth/tests/utils.py @@ -6,15 +6,15 @@ from unittest import skip import httpretty -from onelogin.saml2.utils import OneLogin_Saml2_Utils from oauth2_provider.models import Application +from onelogin.saml2.utils import OneLogin_Saml2_Utils from social_core.backends.facebook import API_VERSION as FACEBOOK_API_VERSION from social_core.backends.facebook import FacebookOAuth2 from social_django.models import Partial, UserSocialAuth from common.djangoapps.student.tests.factories import UserFactory -from .testutil import ThirdPartyAuthTestMixin, AUTH_FEATURE_ENABLED, AUTH_FEATURES_KEY +from .testutil import AUTH_FEATURE_ENABLED, AUTH_FEATURES_KEY, ThirdPartyAuthTestMixin @httpretty.activate diff --git a/common/djangoapps/third_party_auth/urls.py b/common/djangoapps/third_party_auth/urls.py index a5908da26fd0..2de05ad1b28b 100644 --- a/common/djangoapps/third_party_auth/urls.py +++ b/common/djangoapps/third_party_auth/urls.py @@ -1,7 +1,6 @@ """Url configuration for the auth module.""" -from django.urls import include -from django.urls import path, re_path +from django.urls import include, path, re_path from .views import ( IdPRedirectView, @@ -9,7 +8,7 @@ inactive_user_view, lti_login_and_complete_view, post_to_custom_auth_form, - saml_metadata_view + saml_metadata_view, ) urlpatterns = [ diff --git a/common/djangoapps/third_party_auth/utils.py b/common/djangoapps/third_party_auth/utils.py index 52474c343a5f..97da38ed51f4 100644 --- a/common/djangoapps/third_party_auth/utils.py +++ b/common/djangoapps/third_party_auth/utils.py @@ -16,11 +16,8 @@ from onelogin.saml2.utils import OneLogin_Saml2_Utils from requests import exceptions from social_core.pipeline.social_auth import associate_by_email -from common.djangoapps.student.models import ( - email_exists_or_retired, - username_exists_or_retired -) +from common.djangoapps.student.models import email_exists_or_retired, username_exists_or_retired from common.djangoapps.third_party_auth.models import OAuth2ProviderConfig, SAMLProviderData from openedx.core.djangolib.markup import Text diff --git a/common/djangoapps/third_party_auth/views.py b/common/djangoapps/third_party_auth/views.py index 2153354cbf9e..41554edfd8f4 100644 --- a/common/djangoapps/third_party_auth/views.py +++ b/common/djangoapps/third_party_auth/views.py @@ -6,10 +6,15 @@ from django.conf import settings from django.contrib.auth.decorators import login_required -from django.core.exceptions import ValidationError, PermissionDenied +from django.core.exceptions import PermissionDenied, ValidationError from django.db import DatabaseError from django.http import ( - Http404, HttpResponse, HttpResponseNotAllowed, HttpResponseNotFound, HttpResponseServerError, JsonResponse + Http404, + HttpResponse, + HttpResponseNotAllowed, + HttpResponseNotFound, + HttpResponseServerError, + JsonResponse, ) from django.shortcuts import redirect, render from django.urls import reverse diff --git a/common/djangoapps/track/backends/tests/test_mongodb.py b/common/djangoapps/track/backends/tests/test_mongodb.py index 6937438a70d9..3333c87832c0 100644 --- a/common/djangoapps/track/backends/tests/test_mongodb.py +++ b/common/djangoapps/track/backends/tests/test_mongodb.py @@ -1,6 +1,7 @@ # lint-amnesty, pylint: disable=missing-module-docstring from unittest.mock import patch + from django.test import TestCase from common.djangoapps.track.backends.mongodb import MongoBackend diff --git a/common/djangoapps/track/management/tests/test_tracked_command.py b/common/djangoapps/track/management/tests/test_tracked_command.py index 95d94c9ec04b..21e72b04f909 100644 --- a/common/djangoapps/track/management/tests/test_tracked_command.py +++ b/common/djangoapps/track/management/tests/test_tracked_command.py @@ -1,10 +1,10 @@ # lint-amnesty, pylint: disable=missing-module-docstring import json -from six import StringIO from django.core.management import call_command from django.test import TestCase +from six import StringIO class CommandsTestBase(TestCase): diff --git a/common/djangoapps/track/tests/test_shim.py b/common/djangoapps/track/tests/test_shim.py index 68500594fe7a..cb9a0a128680 100644 --- a/common/djangoapps/track/tests/test_shim.py +++ b/common/djangoapps/track/tests/test_shim.py @@ -3,18 +3,18 @@ from collections import namedtuple from unittest.mock import sentinel -import pytest + import ddt +import pytest from django.test.utils import override_settings +from opaque_keys.edx.locator import CourseLocator # lint-amnesty, pylint: disable=wrong-import-order from openedx.core.lib.tests.assertions.events import assert_events_equal -from opaque_keys.edx.locator import CourseLocator # lint-amnesty, pylint: disable=wrong-import-order from .. import transformers from ..shim import PrefixedEventProcessor from . import FROZEN_TIME, EventTrackingTestCase - LEGACY_SHIM_PROCESSOR = [ { 'ENGINE': 'common.djangoapps.track.shim.LegacyFieldMappingProcessor' diff --git a/common/djangoapps/track/views/__init__.py b/common/djangoapps/track/views/__init__.py index 140afbd0e640..aa4908f905eb 100644 --- a/common/djangoapps/track/views/__init__.py +++ b/common/djangoapps/track/views/__init__.py @@ -1,8 +1,8 @@ # lint-amnesty, pylint: disable=missing-module-docstring import json -import six +import six from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.http import HttpResponse from eventtracking import tracker as eventtracker diff --git a/common/djangoapps/track/views/tests/base.py b/common/djangoapps/track/views/tests/base.py index 69a68760234d..d85a8529a6b4 100644 --- a/common/djangoapps/track/views/tests/base.py +++ b/common/djangoapps/track/views/tests/base.py @@ -5,8 +5,8 @@ import json - from unittest.mock import sentinel + from django.test.client import RequestFactory from django.test.utils import override_settings diff --git a/common/djangoapps/track/views/tests/test_segmentio.py b/common/djangoapps/track/views/tests/test_segmentio.py index 2edb8395ebe8..dde61cb9c107 100644 --- a/common/djangoapps/track/views/tests/test_segmentio.py +++ b/common/djangoapps/track/views/tests/test_segmentio.py @@ -9,10 +9,14 @@ from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.test.utils import override_settings -from openedx.core.lib.tests.assertions.events import assert_event_matches from common.djangoapps.track.middleware import TrackMiddleware from common.djangoapps.track.views import segmentio -from common.djangoapps.track.views.tests.base import SEGMENTIO_TEST_ENDPOINT, SEGMENTIO_TEST_USER_ID, SegmentIOTrackingTestCaseBase # lint-amnesty, pylint: disable=line-too-long +from common.djangoapps.track.views.tests.base import ( # lint-amnesty, pylint: disable=line-too-long + SEGMENTIO_TEST_ENDPOINT, + SEGMENTIO_TEST_USER_ID, + SegmentIOTrackingTestCaseBase, +) +from openedx.core.lib.tests.assertions.events import assert_event_matches def expect_failure_with_message(message): diff --git a/common/djangoapps/track/views/tests/test_views.py b/common/djangoapps/track/views/tests/test_views.py index 1d77e2e5b925..f02490c3a5d5 100644 --- a/common/djangoapps/track/views/tests/test_views.py +++ b/common/djangoapps/track/views/tests/test_views.py @@ -7,10 +7,10 @@ from django.test.client import RequestFactory from django.test.utils import override_settings -from openedx.core.lib.tests.assertions.events import assert_event_matches from common.djangoapps.track import views from common.djangoapps.track.middleware import TrackMiddleware from common.djangoapps.track.tests import FROZEN_TIME, EventTrackingTestCase +from openedx.core.lib.tests.assertions.events import assert_event_matches TEST_USERNAME = 'test-username' TEST_USER_ID = 1000 diff --git a/common/djangoapps/util/cache.py b/common/djangoapps/util/cache.py index 3ec99efc636d..b35e3208da3f 100644 --- a/common/djangoapps/util/cache.py +++ b/common/djangoapps/util/cache.py @@ -11,6 +11,7 @@ from urllib.parse import urlencode from django.core import cache + # If we can't find a 'general' CACHE defined in settings.py, we simply fall back # to returning the default cache. This will happen with dev machines. from django.utils.translation import get_language diff --git a/common/djangoapps/util/course.py b/common/djangoapps/util/course.py index abef18a3263d..6eeaec0966f6 100644 --- a/common/djangoapps/util/course.py +++ b/common/djangoapps/util/course.py @@ -8,10 +8,10 @@ from django.conf import settings from opaque_keys.edx.keys import CourseKey, UsageKey +from openedx_filters.learning.filters import CourseAboutPageURLRequested from lms.djangoapps.branding.toggles import use_catalog_mfe from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers -from openedx_filters.learning.filters import CourseAboutPageURLRequested log = logging.getLogger(__name__) diff --git a/common/djangoapps/util/db.py b/common/djangoapps/util/db.py index 6291c6ea0075..9b7e9fe870e2 100644 --- a/common/djangoapps/util/db.py +++ b/common/djangoapps/util/db.py @@ -5,9 +5,11 @@ import random + # TransactionManagementError used below actually *does* derive from the standard "Exception" class. # lint-amnesty, pylint: disable=bad-option-value, nonstandard-exception from contextlib import contextmanager + from django.db import DEFAULT_DB_ALIAS, transaction # lint-amnesty, pylint: disable=unused-import from openedx.core.lib.cache_utils import get_cache diff --git a/common/djangoapps/util/milestones_helpers.py b/common/djangoapps/util/milestones_helpers.py index 94ec358f9286..c5784a95250a 100644 --- a/common/djangoapps/util/milestones_helpers.py +++ b/common/djangoapps/util/milestones_helpers.py @@ -15,7 +15,6 @@ from openedx.core.lib.cache_utils import get_cache from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order - NAMESPACE_CHOICES = { 'ENTRANCE_EXAM': 'entrance_exams' } diff --git a/common/djangoapps/util/model_utils.py b/common/djangoapps/util/model_utils.py index f41e2c171d29..69826b7617ec 100644 --- a/common/djangoapps/util/model_utils.py +++ b/common/djangoapps/util/model_utils.py @@ -2,7 +2,7 @@ Utilities for django models. """ -from typing import Dict, Any, Tuple +from typing import Any, Dict, Tuple from django.conf import settings from django.dispatch import Signal diff --git a/common/djangoapps/util/query.py b/common/djangoapps/util/query.py index 55c80e9d4024..917ab01df7e7 100644 --- a/common/djangoapps/util/query.py +++ b/common/djangoapps/util/query.py @@ -3,7 +3,6 @@ from django.conf import settings - _READ_REPLICA_DB_ALIAS = "read_replica" diff --git a/common/djangoapps/util/storage.py b/common/djangoapps/util/storage.py index b818acf90017..93789ad07a1d 100644 --- a/common/djangoapps/util/storage.py +++ b/common/djangoapps/util/storage.py @@ -1,12 +1,11 @@ """ Utility functions related to django storages """ import logging +from typing import List, Optional -from typing import Optional, List from django.conf import settings from django.core.files.storage import storages from django.utils.module_loading import import_string - logger = logging.getLogger(__name__) diff --git a/common/djangoapps/util/tests/test_course.py b/common/djangoapps/util/tests/test_course.py index f0baf5581479..31520827ea9f 100644 --- a/common/djangoapps/util/tests/test_course.py +++ b/common/djangoapps/util/tests/test_course.py @@ -7,10 +7,12 @@ from django.conf import settings from django.test import override_settings -from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from common.djangoapps.util.course import get_link_for_about_page +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/common/djangoapps/util/tests/test_date_utils.py b/common/djangoapps/util/tests/test_date_utils.py index f5f26d6eff9a..66d423d66082 100644 --- a/common/djangoapps/util/tests/test_date_utils.py +++ b/common/djangoapps/util/tests/test_date_utils.py @@ -10,12 +10,15 @@ import crum import ddt import pytest -from markupsafe import Markup - from django.test.client import RequestFactory +from markupsafe import Markup from common.djangoapps.util.date_utils import ( - almost_same_datetime, get_default_time_display, get_time_display, strftime_localized, strftime_localized_html + almost_same_datetime, + get_default_time_display, + get_time_display, + strftime_localized, + strftime_localized_html, ) diff --git a/common/djangoapps/util/tests/test_file.py b/common/djangoapps/util/tests/test_file.py index e90ac4e5b524..c6d2be5c7c87 100644 --- a/common/djangoapps/util/tests/test_file.py +++ b/common/djangoapps/util/tests/test_file.py @@ -9,8 +9,9 @@ from unittest.mock import Mock, patch from zoneinfo import ZoneInfo -import pytest import ddt +import pytest +from ccx_keys.locator import CCXLocator from django.core import exceptions from django.core.files.uploadedfile import SimpleUploadedFile from django.http import HttpRequest @@ -19,15 +20,13 @@ from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locations import CourseLocator -from ccx_keys.locator import CCXLocator - import common.djangoapps.util.file from common.djangoapps.util.file import ( FileValidationException, UniversalNewlineIterator, course_and_time_based_filename_generator, course_filename_prefix_generator, - store_uploaded_file + store_uploaded_file, ) diff --git a/common/djangoapps/util/tests/test_filters.py b/common/djangoapps/util/tests/test_filters.py index 9e8d6d5fdffa..60aa31adcd9c 100644 --- a/common/djangoapps/util/tests/test_filters.py +++ b/common/djangoapps/util/tests/test_filters.py @@ -2,11 +2,12 @@ Test that various filters are fired for models/views in the student app. """ from django.test import override_settings -from common.djangoapps.util import course from openedx_filters import PipelineStep + +from common.djangoapps.util import course +from openedx.core.djangolib.testing.utils import skip_unless_lms from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from openedx.core.djangolib.testing.utils import skip_unless_lms class TestPageURLRequestedPipelineStep(PipelineStep): diff --git a/common/djangoapps/util/tests/test_json_request.py b/common/djangoapps/util/tests/test_json_request.py index ad4ec9156bc0..3ede50ad1f36 100644 --- a/common/djangoapps/util/tests/test_json_request.py +++ b/common/djangoapps/util/tests/test_json_request.py @@ -5,8 +5,8 @@ import json import unittest - from unittest import mock + from django.http import HttpResponse, HttpResponseBadRequest from common.djangoapps.util.json_request import JsonResponse, JsonResponseBadRequest diff --git a/common/djangoapps/util/tests/test_keyword_sub_utils.py b/common/djangoapps/util/tests/test_keyword_sub_utils.py index 1478e39a4fdd..2e3fbcecc10c 100644 --- a/common/djangoapps/util/tests/test_keyword_sub_utils.py +++ b/common/djangoapps/util/tests/test_keyword_sub_utils.py @@ -8,7 +8,9 @@ from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.util import keyword_substitution as Ks from common.djangoapps.util.date_utils import get_default_time_display -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/common/djangoapps/util/tests/test_milestones_helpers.py b/common/djangoapps/util/tests/test_milestones_helpers.py index efff367d75bb..e1957000ab47 100644 --- a/common/djangoapps/util/tests/test_milestones_helpers.py +++ b/common/djangoapps/util/tests/test_milestones_helpers.py @@ -12,7 +12,9 @@ from milestones.models import MilestoneRelationshipType from common.djangoapps.util import milestones_helpers -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/common/djangoapps/util/tests/test_password_policy_validators.py b/common/djangoapps/util/tests/test_password_policy_validators.py index f5eea255bff2..23e9252839dd 100644 --- a/common/djangoapps/util/tests/test_password_policy_validators.py +++ b/common/djangoapps/util/tests/test_password_policy_validators.py @@ -12,7 +12,7 @@ from common.djangoapps.util.password_policy_validators import ( create_validator_config, password_validators_instruction_texts, - validate_password + validate_password, ) diff --git a/common/djangoapps/util/tests/test_resolve_storage_backend.py b/common/djangoapps/util/tests/test_resolve_storage_backend.py index cf0e0cbd0e94..9a30f8ba776b 100644 --- a/common/djangoapps/util/tests/test_resolve_storage_backend.py +++ b/common/djangoapps/util/tests/test_resolve_storage_backend.py @@ -2,13 +2,13 @@ Tests for the resolve_storage_backend function in common.djangoapps.util.storage. """ +from unittest.mock import MagicMock, patch + from django.test import TestCase from django.test.utils import override_settings -from unittest.mock import patch, MagicMock from common.djangoapps.util.storage import resolve_storage_backend - DEFAULT_STORAGE_CLASS_NAME = "FileSystemStorage" diff --git a/common/djangoapps/util/tests/test_sandboxing.py b/common/djangoapps/util/tests/test_sandboxing.py index e544a07e8585..8bc3cc7f9349 100644 --- a/common/djangoapps/util/tests/test_sandboxing.py +++ b/common/djangoapps/util/tests/test_sandboxing.py @@ -11,7 +11,7 @@ from xmodule.contentstore.django import contentstore from xmodule.modulestore.tests.django_utils import upload_file_to_course -from xmodule.util.sandboxing import can_execute_unsafe_code, SandboxService +from xmodule.util.sandboxing import SandboxService, can_execute_unsafe_code class SandboxingTest(TestCase): diff --git a/common/djangoapps/util/views.py b/common/djangoapps/util/views.py index 8a7901b2fccd..970207ad06c3 100644 --- a/common/djangoapps/util/views.py +++ b/common/djangoapps/util/views.py @@ -9,19 +9,19 @@ from django.conf import settings from django.contrib.auth.decorators import login_required from django.http import Http404, HttpResponse, HttpResponseForbidden, HttpResponseServerError +from django.shortcuts import redirect from django.views.decorators.csrf import ensure_csrf_cookie, requires_csrf_token from django.views.defaults import server_error -from django.shortcuts import redirect from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey, UsageKey +from common.djangoapps.edxmako.shortcuts import render_to_response +from common.djangoapps.student.roles import GlobalStaff +from common.djangoapps.track import views as track_views from lms.djangoapps.courseware.access import has_access from lms.djangoapps.courseware.masquerade import setup_masquerade from openedx.core.djangoapps.schedules.utils import reset_self_paced_schedule from openedx.features.course_experience.utils import dates_banner_should_display -from common.djangoapps.track import views as track_views -from common.djangoapps.edxmako.shortcuts import render_to_response -from common.djangoapps.student.roles import GlobalStaff log = logging.getLogger(__name__) diff --git a/common/djangoapps/xblock_django/admin.py b/common/djangoapps/xblock_django/admin.py index 0aba207a6237..a385d0d53518 100644 --- a/common/djangoapps/xblock_django/admin.py +++ b/common/djangoapps/xblock_django/admin.py @@ -7,7 +7,11 @@ from django.contrib import admin from django.utils.translation import gettext_lazy as _ -from common.djangoapps.xblock_django.models import XBlockConfiguration, XBlockStudioConfiguration, XBlockStudioConfigurationFlag # lint-amnesty, pylint: disable=line-too-long +from common.djangoapps.xblock_django.models import ( # lint-amnesty, pylint: disable=line-too-long + XBlockConfiguration, + XBlockStudioConfiguration, + XBlockStudioConfigurationFlag, +) class XBlockConfigurationAdmin(KeyedConfigurationModelAdmin): diff --git a/common/djangoapps/xblock_django/api.py b/common/djangoapps/xblock_django/api.py index 163683ab0c38..1470ae3a7cc9 100644 --- a/common/djangoapps/xblock_django/api.py +++ b/common/djangoapps/xblock_django/api.py @@ -3,8 +3,8 @@ """ -from openedx.core.lib.cache_utils import CacheInvalidationManager from common.djangoapps.xblock_django.models import XBlockConfiguration, XBlockStudioConfiguration +from openedx.core.lib.cache_utils import CacheInvalidationManager cacher = CacheInvalidationManager(model=XBlockConfiguration) diff --git a/common/djangoapps/xblock_django/management/commands/compile_xblock_translations.py b/common/djangoapps/xblock_django/management/commands/compile_xblock_translations.py index 77662a37388b..3623cd6b1565 100644 --- a/common/djangoapps/xblock_django/management/commands/compile_xblock_translations.py +++ b/common/djangoapps/xblock_django/management/commands/compile_xblock_translations.py @@ -4,13 +4,10 @@ from django.core.management.base import BaseCommand -from xmodule.modulestore import api as xmodule_api - from openedx.core.djangoapps.plugins.i18n_api import compile_po_files +from xmodule.modulestore import api as xmodule_api -from ...translation import ( - compile_xblock_js_messages, -) +from ...translation import compile_xblock_js_messages class Command(BaseCommand): diff --git a/common/djangoapps/xblock_django/tests/test_api.py b/common/djangoapps/xblock_django/tests/test_api.py index 886020f173a6..e0573261667b 100644 --- a/common/djangoapps/xblock_django/tests/test_api.py +++ b/common/djangoapps/xblock_django/tests/test_api.py @@ -1,9 +1,13 @@ """ Tests related to XBlock support API. """ -from openedx.core.djangolib.testing.utils import CacheIsolationTestCase from common.djangoapps.xblock_django.api import authorable_xblocks, deprecated_xblocks, disabled_xblocks -from common.djangoapps.xblock_django.models import XBlockConfiguration, XBlockStudioConfiguration, XBlockStudioConfigurationFlag # lint-amnesty, pylint: disable=line-too-long +from common.djangoapps.xblock_django.models import ( # lint-amnesty, pylint: disable=line-too-long + XBlockConfiguration, + XBlockStudioConfiguration, + XBlockStudioConfigurationFlag, +) +from openedx.core.djangolib.testing.utils import CacheIsolationTestCase class XBlockSupportTestCase(CacheIsolationTestCase): diff --git a/common/djangoapps/xblock_django/tests/test_commands.py b/common/djangoapps/xblock_django/tests/test_commands.py index 8a558b6bebe6..40ef1f3b01f8 100644 --- a/common/djangoapps/xblock_django/tests/test_commands.py +++ b/common/djangoapps/xblock_django/tests/test_commands.py @@ -2,17 +2,13 @@ Tests for the pull_xblock_translations management command. """ -from path import Path from unittest.mock import patch from django.core.management import call_command - from done import DoneXBlock +from path import Path -from xmodule.modulestore.api import ( - get_python_locale_root, - get_javascript_i18n_file_path, -) +from xmodule.modulestore.api import get_javascript_i18n_file_path, get_python_locale_root from xmodule.modulestore.tests.conftest import tmp_translations_dir diff --git a/common/djangoapps/xblock_django/tests/test_translation.py b/common/djangoapps/xblock_django/tests/test_translation.py index 4e4ed937c513..0b25cc66502d 100644 --- a/common/djangoapps/xblock_django/tests/test_translation.py +++ b/common/djangoapps/xblock_django/tests/test_translation.py @@ -4,10 +4,7 @@ from done import DoneXBlock -from ..translation import ( - get_non_xmodule_xblock_module_names, - get_non_xmodule_xblocks, -) +from ..translation import get_non_xmodule_xblock_module_names, get_non_xmodule_xblocks def test_get_non_xmodule_xblock_module_names(): diff --git a/common/djangoapps/xblock_django/tests/test_user_service.py b/common/djangoapps/xblock_django/tests/test_user_service.py index 603069d7400a..c6b81fed637b 100644 --- a/common/djangoapps/xblock_django/tests/test_user_service.py +++ b/common/djangoapps/xblock_django/tests/test_user_service.py @@ -7,13 +7,11 @@ from django.test import TestCase from opaque_keys.edx.keys import CourseKey -from openedx.core.djangoapps.user_api.preferences.api import set_user_preference -from openedx.core.djangoapps.external_user_ids.models import ExternalIdType from common.djangoapps.student.models import anonymous_id_for_user from common.djangoapps.student.tests.factories import AnonymousUserFactory, UserFactory from common.djangoapps.xblock_django.user_service import ( - ATTR_KEY_IS_AUTHENTICATED, ATTR_KEY_ANONYMOUS_USER_ID, + ATTR_KEY_IS_AUTHENTICATED, ATTR_KEY_REQUEST_COUNTRY_CODE, ATTR_KEY_USER_ID, ATTR_KEY_USER_IS_BETA_TESTER, @@ -23,8 +21,10 @@ ATTR_KEY_USER_ROLE, ATTR_KEY_USERNAME, USER_PREFERENCES_WHITE_LIST, - DjangoXBlockUserService + DjangoXBlockUserService, ) +from openedx.core.djangoapps.external_user_ids.models import ExternalIdType +from openedx.core.djangoapps.user_api.preferences.api import set_user_preference @ddt.ddt diff --git a/common/djangoapps/xblock_django/translation.py b/common/djangoapps/xblock_django/translation.py index 66f964268255..cdc21c0322b7 100644 --- a/common/djangoapps/xblock_django/translation.py +++ b/common/djangoapps/xblock_django/translation.py @@ -2,12 +2,12 @@ XBlock translations pulling and compilation logic. """ -import os import gettext +import os from django.utils.encoding import force_str +from django.utils.translation import get_language, override, to_locale from django.views.i18n import JavaScriptCatalog -from django.utils.translation import override, to_locale, get_language from statici18n.management.commands.compilejsi18n import Command as CompileI18NJSCommand from xblock.core import XBlock diff --git a/common/djangoapps/xblock_django/user_service.py b/common/djangoapps/xblock_django/user_service.py index 01221ddfa698..d82e3da1ec50 100644 --- a/common/djangoapps/xblock_django/user_service.py +++ b/common/djangoapps/xblock_django/user_service.py @@ -7,9 +7,9 @@ from opaque_keys.edx.keys import CourseKey from xblock.reference.user_service import UserService, XBlockUser +from common.djangoapps.student.models import anonymous_id_for_user, get_user_by_username_or_email, user_by_anonymous_id from openedx.core.djangoapps.external_user_ids.models import ExternalId from openedx.core.djangoapps.user_api.preferences.api import get_user_preferences -from common.djangoapps.student.models import anonymous_id_for_user, get_user_by_username_or_email, user_by_anonymous_id from .constants import ( ATTR_KEY_ANONYMOUS_USER_ID, @@ -17,15 +17,14 @@ ATTR_KEY_IS_AUTHENTICATED, ATTR_KEY_REQUEST_COUNTRY_CODE, ATTR_KEY_USER_ID, - ATTR_KEY_USERNAME, ATTR_KEY_USER_IS_BETA_TESTER, ATTR_KEY_USER_IS_GLOBAL_STAFF, ATTR_KEY_USER_IS_STAFF, ATTR_KEY_USER_PREFERENCES, ATTR_KEY_USER_ROLE, + ATTR_KEY_USERNAME, ) - USER_PREFERENCES_WHITE_LIST = ['pref-lang', 'time_zone'] diff --git a/common/test/utils.py b/common/test/utils.py index d2eb7231b071..e1f2fb925742 100644 --- a/common/test/utils.py +++ b/common/test/utils.py @@ -1,12 +1,10 @@ """ General testing utilities. """ -from unittest.mock import Mock, patch - - import functools import sys from contextlib import contextmanager +from unittest.mock import Mock, patch from django.dispatch import Signal from markupsafe import escape diff --git a/conftest.py b/conftest.py index 3fc522a9692c..50a9eb2d7105 100644 --- a/conftest.py +++ b/conftest.py @@ -6,10 +6,11 @@ import pytest +from cms.conftest import _django_clear_site_cache, pytest_configure # pylint: disable=unused-import + # Import hooks and fixture overrides from the cms package to # avoid duplicating the implementation -from cms.conftest import _django_clear_site_cache, pytest_configure # pylint: disable=unused-import # When using self.assertEquals, diffs are truncated. We don't want that, always diff --git a/docs/conf.py b/docs/conf.py index 297f508cdefa..a623a2a4d0a9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -14,7 +14,6 @@ import django import git from django.db.models.query import QuerySet - from path import Path root = Path('..').abspath() diff --git a/docs/docs_settings.py b/docs/docs_settings.py index 9f1c01ba934f..72a61580fda8 100644 --- a/docs/docs_settings.py +++ b/docs/docs_settings.py @@ -4,22 +4,21 @@ import all the Studio code. """ -from textwrap import dedent import os +from textwrap import dedent -from openedx.core.lib.derived import derive_settings - -from lms.envs.common import * # lint-amnesty, pylint: disable=wildcard-import from cms.envs.common import ( # lint-amnesty, pylint: disable=unused-import ADVANCED_PROBLEM_TYPES, COURSE_IMPORT_EXPORT_STORAGE, + ENABLE_SEND_XBLOCK_LIFECYCLE_EVENTS_OVER_BUS, + FRONTEND_REGISTER_URL, GIT_EXPORT_DEFAULT_IDENT, SCRAPE_YOUTUBE_THUMBNAILS_JOB_QUEUE, - VIDEO_TRANSCRIPT_MIGRATIONS_JOB_QUEUE, UPDATE_SEARCH_INDEX_JOB_QUEUE, - FRONTEND_REGISTER_URL, - ENABLE_SEND_XBLOCK_LIFECYCLE_EVENTS_OVER_BUS, + VIDEO_TRANSCRIPT_MIGRATIONS_JOB_QUEUE, ) +from lms.envs.common import * # lint-amnesty, pylint: disable=wildcard-import +from openedx.core.lib.derived import derive_settings # Turn on all the boolean feature flags, so that conditionally included # API endpoints will be found. diff --git a/lms/__init__.py b/lms/__init__.py index 008640ac7147..cd72386c5d3f 100644 --- a/lms/__init__.py +++ b/lms/__init__.py @@ -12,6 +12,7 @@ # FWIW, this is identical behavior to what happens in Kombu if pkg_resources # isn't available. import kombu.utils + kombu.utils.entrypoints = lambda namespace: iter([]) # This will make sure the app is always imported when Django starts so diff --git a/lms/djangoapps/badges/migrations/0002_data__migrate_assertions.py b/lms/djangoapps/badges/migrations/0002_data__migrate_assertions.py index 70368e949214..2cd81a55301d 100644 --- a/lms/djangoapps/badges/migrations/0002_data__migrate_assertions.py +++ b/lms/djangoapps/badges/migrations/0002_data__migrate_assertions.py @@ -11,8 +11,8 @@ def forwards(apps, schema_editor): """ Migrate the initial badge classes, assertions, and course image configurations from lms.djangoapps.certificates. """ - from xmodule.modulestore.django import modulestore from lms.djangoapps.badges.events import course_complete + from xmodule.modulestore.django import modulestore db_alias = schema_editor.connection.alias # This will need to be changed if badges/certificates get moved out of the default db for some reason. if db_alias != 'default': diff --git a/lms/djangoapps/branding/migrations/0001_initial.py b/lms/djangoapps/branding/migrations/0001_initial.py index 78161afbfa74..a984f1a724b0 100644 --- a/lms/djangoapps/branding/migrations/0001_initial.py +++ b/lms/djangoapps/branding/migrations/0001_initial.py @@ -1,6 +1,6 @@ -from django.db import migrations, models import django.db.models.deletion from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/branding/test_toggles.py b/lms/djangoapps/branding/test_toggles.py index a6797b80909b..3d1b05858fc9 100644 --- a/lms/djangoapps/branding/test_toggles.py +++ b/lms/djangoapps/branding/test_toggles.py @@ -3,7 +3,7 @@ """ import ddt -from django.test import override_settings, TestCase +from django.test import TestCase, override_settings from lms.djangoapps.branding.toggles import use_catalog_mfe diff --git a/lms/djangoapps/branding/tests/test_page.py b/lms/djangoapps/branding/tests/test_page.py index 46f10bd6923a..407e7fde74c1 100644 --- a/lms/djangoapps/branding/tests/test_page.py +++ b/lms/djangoapps/branding/tests/test_page.py @@ -20,9 +20,11 @@ from lms.djangoapps.branding.views import index from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from xmodule.course_block import CATALOG_VISIBILITY_ABOUT, CATALOG_VISIBILITY_NONE +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order FEATURES_WITH_STARTDATE = settings.FEATURES.copy() FEATURES_WITH_STARTDATE['DISABLE_START_DATES'] = False diff --git a/lms/djangoapps/branding/tests/test_views.py b/lms/djangoapps/branding/tests/test_views.py index 10c27192d11a..8e91af37f7ea 100644 --- a/lms/djangoapps/branding/tests/test_views.py +++ b/lms/djangoapps/branding/tests/test_views.py @@ -8,12 +8,11 @@ import six from django.conf import settings from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user -from django.test import override_settings, TestCase +from django.test import TestCase, override_settings from django.urls import reverse from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.branding.models import BrandingApiConfig - from openedx.core.djangoapps.dark_lang.models import DarkLangConfig from openedx.core.djangoapps.lang_pref.api import released_languages from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin diff --git a/lms/djangoapps/branding/views.py b/lms/djangoapps/branding/views.py index 33c5813f16ff..f92c47e5b6c8 100644 --- a/lms/djangoapps/branding/views.py +++ b/lms/djangoapps/branding/views.py @@ -16,12 +16,12 @@ from django.views.decorators.csrf import ensure_csrf_cookie import lms.djangoapps.branding.api as branding_api -from lms.djangoapps.branding.toggles import use_catalog_mfe import lms.djangoapps.courseware.views.views as courseware_views from common.djangoapps.edxmako.shortcuts import marketing_link, render_to_response from common.djangoapps.student import views as student_views from common.djangoapps.util.cache import cache_if_anonymous from common.djangoapps.util.json_request import JsonResponse +from lms.djangoapps.branding.toggles import use_catalog_mfe from openedx.core.djangoapps.lang_pref.api import released_languages from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers diff --git a/lms/djangoapps/bulk_email/admin.py b/lms/djangoapps/bulk_email/admin.py index bb8450953516..0098a581ea19 100644 --- a/lms/djangoapps/bulk_email/admin.py +++ b/lms/djangoapps/bulk_email/admin.py @@ -10,10 +10,10 @@ from lms.djangoapps.bulk_email.models import ( BulkEmailFlag, CourseAuthorization, - DisabledCourse, CourseEmail, CourseEmailTemplate, - Optout + DisabledCourse, + Optout, ) diff --git a/lms/djangoapps/bulk_email/api.py b/lms/djangoapps/bulk_email/api.py index 1cc9ee02a49b..49f4b789cf4f 100644 --- a/lms/djangoapps/bulk_email/api.py +++ b/lms/djangoapps/bulk_email/api.py @@ -9,17 +9,11 @@ from common.djangoapps.course_modes.models import CourseMode from lms.djangoapps.bulk_email.data import BulkEmailTargetChoices -from lms.djangoapps.bulk_email.models import ( - CohortTarget, - CourseEmail, - CourseModeTarget, - Target -) - +from lms.djangoapps.bulk_email.models import CohortTarget, CourseEmail, CourseModeTarget, Target from lms.djangoapps.bulk_email.models_api import ( is_bulk_email_disabled_for_course, is_bulk_email_feature_enabled, - is_user_opted_out_for_course + is_user_opted_out_for_course, ) from lms.djangoapps.discussion.notification_prefs.views import UsernameCipher from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers diff --git a/lms/djangoapps/bulk_email/apps.py b/lms/djangoapps/bulk_email/apps.py index 63a44fcfcde4..f4d65f455d46 100644 --- a/lms/djangoapps/bulk_email/apps.py +++ b/lms/djangoapps/bulk_email/apps.py @@ -9,5 +9,6 @@ class BulkEmailConfig(AppConfig): name = 'lms.djangoapps.bulk_email' def ready(self): - import lms.djangoapps.bulk_email.signals # lint-amnesty, pylint: disable=unused-import from edx_ace.signals import ACE_MESSAGE_SENT # lint-amnesty, pylint: disable=unused-import + + import lms.djangoapps.bulk_email.signals # lint-amnesty, pylint: disable=unused-import diff --git a/lms/djangoapps/bulk_email/migrations/0007_disabledcourse.py b/lms/djangoapps/bulk_email/migrations/0007_disabledcourse.py index 5591fcaffc62..55affdd0af84 100644 --- a/lms/djangoapps/bulk_email/migrations/0007_disabledcourse.py +++ b/lms/djangoapps/bulk_email/migrations/0007_disabledcourse.py @@ -1,7 +1,7 @@ # Generated by Django 3.2.9 on 2021-11-22 16:05 -from django.db import migrations, models import opaque_keys.edx.django.models +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/bulk_email/models.py b/lms/djangoapps/bulk_email/models.py index 4ee71be0399c..7e341b1632b7 100644 --- a/lms/djangoapps/bulk_email/models.py +++ b/lms/djangoapps/bulk_email/models.py @@ -5,14 +5,13 @@ import logging from datetime import datetime -from dateutil.relativedelta import relativedelta import markupsafe from config_models.models import ConfigurationModel +from dateutil.relativedelta import relativedelta +from django.conf import settings from django.contrib.auth import get_user_model from django.db import models -from django.conf import settings - from opaque_keys.edx.django.models import CourseKeyField from common.djangoapps.course_modes.models import CourseMode diff --git a/lms/djangoapps/bulk_email/signals.py b/lms/djangoapps/bulk_email/signals.py index da18a459aeaa..5c56bedb5536 100644 --- a/lms/djangoapps/bulk_email/signals.py +++ b/lms/djangoapps/bulk_email/signals.py @@ -4,12 +4,12 @@ import logging from django.dispatch import receiver +from edx_ace.signals import ACE_MESSAGE_SENT from eventtracking import tracker from common.djangoapps.student.models import CourseEnrollment from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.user_api.accounts.signals import USER_RETIRE_MAILINGS -from edx_ace.signals import ACE_MESSAGE_SENT from .models import Optout diff --git a/lms/djangoapps/bulk_email/tasks.py b/lms/djangoapps/bulk_email/tasks.py index 0e7c10d62227..df0eecdf4bf2 100644 --- a/lms/djangoapps/bulk_email/tasks.py +++ b/lms/djangoapps/bulk_email/tasks.py @@ -37,7 +37,7 @@ from lms.djangoapps.bulk_email.models import CourseEmail, Optout from lms.djangoapps.bulk_email.toggles import ( is_bulk_email_edx_ace_enabled, - is_email_use_course_id_from_for_bulk_enabled + is_email_use_course_id_from_for_bulk_enabled, ) from lms.djangoapps.courseware.courses import get_course from lms.djangoapps.instructor_task.models import InstructorTask @@ -45,7 +45,7 @@ SubtaskStatus, check_subtask_is_valid, queue_subtasks_for_query, - update_subtask_status + update_subtask_status, ) from openedx.core.djangoapps.ace_common.template_context import get_base_template_context from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers diff --git a/lms/djangoapps/bulk_email/tests/test_api.py b/lms/djangoapps/bulk_email/tests/test_api.py index 60962bbee317..28712eed6d6f 100644 --- a/lms/djangoapps/bulk_email/tests/test_api.py +++ b/lms/djangoapps/bulk_email/tests/test_api.py @@ -3,21 +3,20 @@ """ from testfixtures import LogCapture -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory - from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.tests.factories import InstructorFactory from lms.djangoapps.bulk_email.api import ( create_course_email, determine_targets_for_course_email, get_course_email, - update_course_email + update_course_email, ) from lms.djangoapps.bulk_email.data import BulkEmailTargetChoices from lms.djangoapps.bulk_email.models import CourseEmail from openedx.core.djangoapps.course_groups.models import CourseUserGroup from openedx.core.lib.html_to_text import html_to_text +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory LOG_PATH = "lms.djangoapps.bulk_email.api" diff --git a/lms/djangoapps/bulk_email/tests/test_course_optout.py b/lms/djangoapps/bulk_email/tests/test_course_optout.py index fe0f70fbdc3b..9c4b986fe606 100644 --- a/lms/djangoapps/bulk_email/tests/test_course_optout.py +++ b/lms/djangoapps/bulk_email/tests/test_course_optout.py @@ -19,7 +19,9 @@ from lms.djangoapps.bulk_email.api import get_unsubscribed_link from lms.djangoapps.bulk_email.models import BulkEmailFlag from lms.djangoapps.bulk_email.policies import CourseEmailOptout -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/bulk_email/tests/test_email.py b/lms/djangoapps/bulk_email/tests/test_email.py index f68fd9b2499f..2476d2c42bd4 100644 --- a/lms/djangoapps/bulk_email/tests/test_email.py +++ b/lms/djangoapps/bulk_email/tests/test_email.py @@ -21,9 +21,12 @@ from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.roles import CourseStaffRole -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory -from common.djangoapps.student.tests.factories import InstructorFactory -from common.djangoapps.student.tests.factories import StaffFactory +from common.djangoapps.student.tests.factories import ( + CourseEnrollmentFactory, + InstructorFactory, + StaffFactory, + UserFactory, +) from lms.djangoapps.bulk_email.messages import ACEEmail from lms.djangoapps.bulk_email.tasks import _get_course_email_context, _get_source_address from lms.djangoapps.instructor_task.subtasks import update_subtask_status @@ -31,7 +34,9 @@ from openedx.core.djangoapps.course_groups.models import CourseCohort from openedx.core.djangoapps.enrollments.api import update_enrollment from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..models import BulkEmailFlag, Optout diff --git a/lms/djangoapps/bulk_email/tests/test_err_handling.py b/lms/djangoapps/bulk_email/tests/test_err_handling.py index 06e9a1dce40f..5893dfb553d3 100644 --- a/lms/djangoapps/bulk_email/tests/test_err_handling.py +++ b/lms/djangoapps/bulk_email/tests/test_err_handling.py @@ -8,8 +8,8 @@ from smtplib import SMTPConnectError, SMTPDataError, SMTPServerDisconnected from unittest.mock import Mock, patch -import pytest import ddt +import pytest from celery.states import RETRY, SUCCESS from django.conf import settings from django.core.management import call_command @@ -28,9 +28,11 @@ SubtaskStatus, check_subtask_is_valid, initialize_subtask_info, - update_subtask_status + update_subtask_status, +) +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order ) -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/bulk_email/tests/test_forms.py b/lms/djangoapps/bulk_email/tests/test_forms.py index e691ed631428..11a29774e6f4 100644 --- a/lms/djangoapps/bulk_email/tests/test_forms.py +++ b/lms/djangoapps/bulk_email/tests/test_forms.py @@ -8,7 +8,9 @@ from lms.djangoapps.bulk_email.api import is_bulk_email_feature_enabled from lms.djangoapps.bulk_email.forms import CourseAuthorizationAdminForm, CourseEmailTemplateForm from lms.djangoapps.bulk_email.models import BulkEmailFlag, CourseEmailTemplate -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/bulk_email/tests/test_models.py b/lms/djangoapps/bulk_email/tests/test_models.py index 43062492e842..9642486ac4a2 100644 --- a/lms/djangoapps/bulk_email/tests/test_models.py +++ b/lms/djangoapps/bulk_email/tests/test_models.py @@ -3,11 +3,11 @@ """ import datetime -from dateutil.relativedelta import relativedelta from unittest.mock import Mock, patch # lint-amnesty, pylint: disable=wrong-import-order -import pytest import ddt +import pytest +from dateutil.relativedelta import relativedelta from django.core.management import call_command from django.test import TestCase from django.test.utils import override_settings @@ -15,7 +15,7 @@ from pytz import UTC from common.djangoapps.course_modes.models import CourseMode -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory, StaffFactory +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, StaffFactory, UserFactory from lms.djangoapps.bulk_email.api import is_bulk_email_feature_enabled from lms.djangoapps.bulk_email.models import ( SEND_TO_COHORT, @@ -33,7 +33,9 @@ from lms.djangoapps.bulk_email.models_api import is_bulk_email_disabled_for_course from lms.djangoapps.bulk_email.tests.factories import TargetFactory from openedx.core.djangoapps.course_groups.models import CourseCohort -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/bulk_email/tests/test_signals.py b/lms/djangoapps/bulk_email/tests/test_signals.py index 01ad9312da4c..6089f117f819 100644 --- a/lms/djangoapps/bulk_email/tests/test_signals.py +++ b/lms/djangoapps/bulk_email/tests/test_signals.py @@ -9,13 +9,15 @@ from django.core import mail from django.core.management import call_command from django.urls import reverse +from opaque_keys.edx.keys import CourseKey from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory from lms.djangoapps.bulk_email.models import BulkEmailFlag, Optout from lms.djangoapps.bulk_email.signals import force_optout_all -from opaque_keys.edx.keys import CourseKey -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/bulk_email/tests/test_tasks.py b/lms/djangoapps/bulk_email/tests/test_tasks.py index caf71bfdb416..3972dbcc0ca5 100644 --- a/lms/djangoapps/bulk_email/tests/test_tasks.py +++ b/lms/djangoapps/bulk_email/tests/test_tasks.py @@ -15,7 +15,7 @@ SMTPConnectError, SMTPDataError, SMTPSenderRefused, - SMTPServerDisconnected + SMTPServerDisconnected, ) from unittest.mock import Mock, patch # lint-amnesty, pylint: disable=wrong-import-order from uuid import uuid4 # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/bulk_email/tests/test_views.py b/lms/djangoapps/bulk_email/tests/test_views.py index 66b5f3eabc29..78db8730f429 100644 --- a/lms/djangoapps/bulk_email/tests/test_views.py +++ b/lms/djangoapps/bulk_email/tests/test_views.py @@ -14,7 +14,9 @@ from lms.djangoapps.bulk_email.views import opt_out_email_updates from lms.djangoapps.discussion.notification_prefs.views import UsernameCipher from openedx.core.lib.tests import attr -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/bulk_email/toggles.py b/lms/djangoapps/bulk_email/toggles.py index f3da4480f6f0..dcb26e6b47c5 100644 --- a/lms/djangoapps/bulk_email/toggles.py +++ b/lms/djangoapps/bulk_email/toggles.py @@ -4,7 +4,6 @@ from edx_toggles.toggles import SettingToggle - # .. toggle_name: bulk_email.EMAIL_USE_COURSE_ID_FROM_FOR_BULK # .. toggle_implementation: DjangoSetting # .. toggle_default: False diff --git a/lms/djangoapps/bulk_enroll/tests/test_views.py b/lms/djangoapps/bulk_enroll/tests/test_views.py index 337df4da7823..3be98144fe66 100644 --- a/lms/djangoapps/bulk_enroll/tests/test_views.py +++ b/lms/djangoapps/bulk_enroll/tests/test_views.py @@ -18,7 +18,7 @@ ENROLLED_TO_UNENROLLED, UNENROLLED_TO_ENROLLED, CourseEnrollment, - ManualEnrollmentAudit + ManualEnrollmentAudit, ) from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.bulk_enroll.serializers import BulkEnrollmentSerializer @@ -27,7 +27,9 @@ from openedx.core.djangoapps.course_groups.cohorts import get_cohort_id from openedx.core.djangoapps.course_groups.tests.helpers import config_course_cohorts from openedx.core.djangoapps.site_configuration.helpers import get_value as get_site_value -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/bulk_user_retirement/tests/test_views.py b/lms/djangoapps/bulk_user_retirement/tests/test_views.py index ac28c00f47e2..1a27d05adbf2 100644 --- a/lms/djangoapps/bulk_user_retirement/tests/test_views.py +++ b/lms/djangoapps/bulk_user_retirement/tests/test_views.py @@ -3,8 +3,9 @@ """ from django.urls import reverse from rest_framework.test import APIClient, APITestCase -from openedx.core.djangoapps.user_api.models import RetirementState, UserRetirementStatus + from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.user_api.models import RetirementState, UserRetirementStatus class BulkUserRetirementViewTests(APITestCase): diff --git a/lms/djangoapps/bulk_user_retirement/urls.py b/lms/djangoapps/bulk_user_retirement/urls.py index a2602362e663..7a1c5ab39952 100644 --- a/lms/djangoapps/bulk_user_retirement/urls.py +++ b/lms/djangoapps/bulk_user_retirement/urls.py @@ -6,7 +6,6 @@ from .views import BulkUsersRetirementView - urlpatterns = [ path( 'v1/accounts/bulk_retire_users', diff --git a/lms/djangoapps/bulk_user_retirement/views.py b/lms/djangoapps/bulk_user_retirement/views.py index 8207314aec45..28f23651fb65 100644 --- a/lms/djangoapps/bulk_user_retirement/views.py +++ b/lms/djangoapps/bulk_user_retirement/views.py @@ -8,6 +8,7 @@ from rest_framework import permissions, status from rest_framework.response import Response from rest_framework.views import APIView + from openedx.core.djangoapps.user_api.accounts.permissions import CanRetireUser from openedx.core.djangoapps.user_api.accounts.utils import create_retirement_request_and_deactivate_account diff --git a/lms/djangoapps/ccx/api/v0/tests/test_views.py b/lms/djangoapps/ccx/api/v0/tests/test_views.py index a8c9070df038..ce696977a790 100644 --- a/lms/djangoapps/ccx/api/v0/tests/test_views.py +++ b/lms/djangoapps/ccx/api/v0/tests/test_views.py @@ -6,11 +6,12 @@ import json import math import string +import urllib from datetime import timedelta from unittest import mock -import urllib -import pytest + import ddt +import pytest from ccx_keys.locator import CCXLocator from django.conf import settings from django.urls import Resolver404, resolve, reverse diff --git a/lms/djangoapps/ccx/migrations/0004_seed_forum_roles_in_ccx_courses.py b/lms/djangoapps/ccx/migrations/0004_seed_forum_roles_in_ccx_courses.py index ad5093d1b1d7..d6b37b1e65b4 100644 --- a/lms/djangoapps/ccx/migrations/0004_seed_forum_roles_in_ccx_courses.py +++ b/lms/djangoapps/ccx/migrations/0004_seed_forum_roles_in_ccx_courses.py @@ -3,6 +3,7 @@ import six from ccx_keys.locator import CCXLocator from django.db import migrations + from openedx.core.djangoapps.django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, diff --git a/lms/djangoapps/ccx/migrations/0006_set_display_name_as_override.py b/lms/djangoapps/ccx/migrations/0006_set_display_name_as_override.py index f37c9dc3216a..d51afd9ee806 100644 --- a/lms/djangoapps/ccx/migrations/0006_set_display_name_as_override.py +++ b/lms/djangoapps/ccx/migrations/0006_set_display_name_as_override.py @@ -3,6 +3,7 @@ import json import logging + from django.db import migrations from django.http import Http404 diff --git a/lms/djangoapps/ccx/tests/test_ccx_modulestore.py b/lms/djangoapps/ccx/tests/test_ccx_modulestore.py index f5e98a942cde..878df739306f 100644 --- a/lms/djangoapps/ccx/tests/test_ccx_modulestore.py +++ b/lms/djangoapps/ccx/tests/test_ccx_modulestore.py @@ -10,11 +10,11 @@ import pytz from ccx_keys.locator import CCXLocator from six.moves import zip_longest -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory from common.djangoapps.student.tests.factories import AdminFactory, UserFactory from lms.djangoapps.ccx.models import CustomCourseForEdX +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory 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 1e8e71c5d6ae..a73752d25042 100644 --- a/lms/djangoapps/ccx/tests/test_field_override_performance.py +++ b/lms/djangoapps/ccx/tests/test_field_override_performance.py @@ -8,7 +8,6 @@ from unittest import mock import ddt -from openedx.core.djangolib.testing.utils import AUTHZ_TABLES import pytest from ccx_keys.locator import CCXLocator from django.conf import settings @@ -21,9 +20,6 @@ from opaque_keys.edx.keys import CourseKey from pytz import UTC from xblock.core import XBlock -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls, check_sum_of_calls -from xmodule.modulestore.tests.utils import ProceduralCourseTestMixin from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory @@ -33,7 +29,11 @@ from lms.djangoapps.courseware.views.views import progress from openedx.core.djangoapps.content.block_structure.api import get_course_in_cache from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES +from openedx.core.djangolib.testing.utils import AUTHZ_TABLES from openedx.features.content_type_gating.models import ContentTypeGatingConfig +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls, check_sum_of_calls +from xmodule.modulestore.tests.utils import ProceduralCourseTestMixin QUERY_COUNT_TABLE_IGNORELIST = WAFFLE_TABLES + AUTHZ_TABLES diff --git a/lms/djangoapps/ccx/tests/test_models.py b/lms/djangoapps/ccx/tests/test_models.py index 11bd7e43d312..db71b4c57e21 100644 --- a/lms/djangoapps/ccx/tests/test_models.py +++ b/lms/djangoapps/ccx/tests/test_models.py @@ -8,11 +8,11 @@ import ddt from pytz import utc -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls from common.djangoapps.student.roles import CourseCcxCoachRole from common.djangoapps.student.tests.factories import AdminFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls from ..overrides import override_field_for_ccx from .factories import CcxFactory diff --git a/lms/djangoapps/ccx/tests/test_overrides.py b/lms/djangoapps/ccx/tests/test_overrides.py index c6822f9ab76f..c98b5d32190f 100644 --- a/lms/djangoapps/ccx/tests/test_overrides.py +++ b/lms/djangoapps/ccx/tests/test_overrides.py @@ -10,8 +10,6 @@ from ccx_keys.locator import CCXLocator from django.test.utils import override_settings from edx_django_utils.cache import RequestCache -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory from common.djangoapps.student.tests.factories import AdminFactory from lms.djangoapps.ccx.models import CustomCourseForEdX @@ -21,6 +19,8 @@ from lms.djangoapps.courseware.tests.test_field_overrides import inject_field_overrides from lms.djangoapps.courseware.testutils import FieldOverrideTestMixin from openedx.core.lib.courses import get_course_by_id +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory @override_settings( diff --git a/lms/djangoapps/ccx/tests/test_tasks.py b/lms/djangoapps/ccx/tests/test_tasks.py index 12ece91a3c31..51f4f7ad85f5 100644 --- a/lms/djangoapps/ccx/tests/test_tasks.py +++ b/lms/djangoapps/ccx/tests/test_tasks.py @@ -7,15 +7,15 @@ from unittest import mock from ccx_keys.locator import CCXLocator -from xmodule.modulestore.django import SignalHandler -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student.roles import CourseCcxCoachRole from common.djangoapps.student.tests.factories import AdminFactory 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 xmodule.modulestore.django import SignalHandler +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory @contextlib.contextmanager diff --git a/lms/djangoapps/ccx/tests/test_utils.py b/lms/djangoapps/ccx/tests/test_utils.py index c9e65ddd315f..047d8ed448cc 100644 --- a/lms/djangoapps/ccx/tests/test_utils.py +++ b/lms/djangoapps/ccx/tests/test_utils.py @@ -8,9 +8,6 @@ from unittest import mock from ccx_keys.locator import CCXLocator -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentException from common.djangoapps.student.roles import CourseCcxCoachRole, CourseInstructorRole, CourseStaffRole @@ -19,6 +16,9 @@ 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 xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class TestGetCCXFromCCXLocator(ModuleStoreTestCase): diff --git a/lms/djangoapps/ccx/tests/test_views.py b/lms/djangoapps/ccx/tests/test_views.py index a355a3a433c0..33fbd44dd22b 100644 --- a/lms/djangoapps/ccx/tests/test_views.py +++ b/lms/djangoapps/ccx/tests/test_views.py @@ -19,12 +19,8 @@ from edx_django_utils.cache import RequestCache from opaque_keys.edx.keys import CourseKey from pytz import UTC -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, BlockFactory, SampleCourseFactory -from xmodule.x_module import XModuleMixin from xblocks_contrib.problem.capa.tests.response_xml_factory import StringResponseXMLFactory + from common.djangoapps.edxmako.shortcuts import render_to_response from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentAllowed from common.djangoapps.student.roles import CourseCcxCoachRole, CourseInstructorRole, CourseStaffRole @@ -46,6 +42,11 @@ from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_ADMINISTRATOR from openedx.core.djangoapps.django_comment_common.utils import are_permissions_roles_seeded from openedx.core.lib.courses import get_course_by_id +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 BlockFactory, CourseFactory, 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 4f8c34e14c2d..f96e9067a493 100644 --- a/lms/djangoapps/ccx/tests/utils.py +++ b/lms/djangoapps/ccx/tests/utils.py @@ -7,15 +7,15 @@ import pytz from django.conf import settings -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory from common.djangoapps.student.roles import CourseCcxCoachRole, CourseInstructorRole, CourseStaffRole from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.ccx.overrides import override_field_for_ccx from lms.djangoapps.ccx.tests.factories import CcxFactory from openedx.core.djangoapps.ace_common.tests.mixins import EmailTemplateTagMixin +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory class CcxTestCase(EmailTemplateTagMixin, SharedModuleStoreTestCase): diff --git a/lms/djangoapps/ccx/views.py b/lms/djangoapps/ccx/views.py index 7c6a75aaf6d4..31b32f5c209a 100644 --- a/lms/djangoapps/ccx/views.py +++ b/lms/djangoapps/ccx/views.py @@ -31,7 +31,7 @@ bulk_delete_ccx_override_fields, clear_ccx_field_info_from_ccx_map, get_override_for_ccx, - override_field_for_ccx + override_field_for_ccx, ) from lms.djangoapps.ccx.permissions import VIEW_CCX_COACH_DASHBOARD from lms.djangoapps.ccx.utils import ( @@ -44,7 +44,7 @@ get_ccx_for_coach, get_date, get_enrollment_action_and_identifiers, - parse_date + parse_date, ) from lms.djangoapps.courseware.field_overrides import disable_overrides from lms.djangoapps.grades.api import CourseGradeFactory diff --git a/lms/djangoapps/certificates/admin.py b/lms/djangoapps/certificates/admin.py index ffa225321201..0447763d17f2 100644 --- a/lms/djangoapps/certificates/admin.py +++ b/lms/djangoapps/certificates/admin.py @@ -14,8 +14,8 @@ from lms.djangoapps.certificates.models import ( CertificateDateOverride, - CertificateGenerationConfiguration, CertificateGenerationCommandConfiguration, + CertificateGenerationConfiguration, CertificateGenerationCourseSetting, CertificateHtmlViewConfiguration, CertificateTemplate, diff --git a/lms/djangoapps/certificates/apis/v0/tests/test_views.py b/lms/djangoapps/certificates/apis/v0/tests/test_views.py index c8ef620dd2db..64ddbcd7026d 100644 --- a/lms/djangoapps/certificates/apis/v0/tests/test_views.py +++ b/lms/djangoapps/certificates/apis/v0/tests/test_views.py @@ -22,7 +22,9 @@ from openedx.core.djangoapps.user_api.tests.factories import UserPreferenceFactory from openedx.core.djangoapps.user_authn.tests.utils import JWT_AUTH_TYPES, AuthAndScopesTestMixin, AuthType from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/certificates/apis/v0/views.py b/lms/djangoapps/certificates/apis/v0/views.py index aa6512535b84..d5b64a4a724a 100644 --- a/lms/djangoapps/certificates/apis/v0/views.py +++ b/lms/djangoapps/certificates/apis/v0/views.py @@ -17,13 +17,13 @@ from lms.djangoapps.certificates.api import ( certificates_viewable_for_course, get_certificate_for_user, - get_certificates_for_user + get_certificates_for_user, ) from lms.djangoapps.certificates.apis.v0.permissions import IsOwnerOrPublicCertificates from openedx.core.djangoapps.content.course_overviews.api import ( get_course_overview_or_none, get_course_overviews_from_ids, - get_pseudo_course_overview + get_pseudo_course_overview, ) from openedx.core.djangoapps.user_api.accounts.api import visible_fields from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser diff --git a/lms/djangoapps/certificates/data.py b/lms/djangoapps/certificates/data.py index dba44ab18632..f1131ad74886 100644 --- a/lms/djangoapps/certificates/data.py +++ b/lms/djangoapps/certificates/data.py @@ -5,8 +5,9 @@ """ from dataclasses import dataclass -from opaque_keys.edx.keys import CourseKey + from django.contrib.auth import get_user_model +from opaque_keys.edx.keys import CourseKey User = get_user_model() diff --git a/lms/djangoapps/certificates/generation_handler.py b/lms/djangoapps/certificates/generation_handler.py index 8c7641635731..a1e843bead4d 100644 --- a/lms/djangoapps/certificates/generation_handler.py +++ b/lms/djangoapps/certificates/generation_handler.py @@ -7,6 +7,7 @@ """ import logging + from django.conf import settings from openedx_filters.learning.filters import CertificateCreationRequested @@ -14,11 +15,7 @@ from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import CourseEnrollment from lms.djangoapps.certificates.data import CertificateStatuses -from lms.djangoapps.certificates.models import ( - CertificateAllowlist, - CertificateInvalidation, - GeneratedCertificate -) +from lms.djangoapps.certificates.models import CertificateAllowlist, CertificateInvalidation, GeneratedCertificate from lms.djangoapps.certificates.tasks import CERTIFICATE_DELAY_SECONDS, generate_certificate from lms.djangoapps.certificates.utils import has_html_certificates_enabled from lms.djangoapps.grades.api import CourseGradeFactory diff --git a/lms/djangoapps/certificates/management/commands/cert_generation.py b/lms/djangoapps/certificates/management/commands/cert_generation.py index e80d2c413d46..0154f26a5eb0 100644 --- a/lms/djangoapps/certificates/management/commands/cert_generation.py +++ b/lms/djangoapps/certificates/management/commands/cert_generation.py @@ -9,9 +9,8 @@ from django.core.management.base import BaseCommand, CommandError from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey -from lms.djangoapps.certificates.generation_handler import CertificateGenerationNotAllowed -from lms.djangoapps.certificates.generation_handler import generate_certificate_task +from lms.djangoapps.certificates.generation_handler import CertificateGenerationNotAllowed, generate_certificate_task from lms.djangoapps.certificates.models import CertificateGenerationCommandConfiguration User = get_user_model() diff --git a/lms/djangoapps/certificates/management/commands/modify_cert_template.py b/lms/djangoapps/certificates/management/commands/modify_cert_template.py index f4ae5f64d2b6..48be1b5a4746 100644 --- a/lms/djangoapps/certificates/management/commands/modify_cert_template.py +++ b/lms/djangoapps/certificates/management/commands/modify_cert_template.py @@ -5,9 +5,7 @@ from django.core.management.base import BaseCommand, CommandError -from lms.djangoapps.certificates.models import ( - ModifiedCertificateTemplateCommandConfiguration, -) +from lms.djangoapps.certificates.models import ModifiedCertificateTemplateCommandConfiguration from lms.djangoapps.certificates.tasks import handle_modify_cert_template log = logging.getLogger(__name__) diff --git a/lms/djangoapps/certificates/management/commands/tests/test_cert_generation.py b/lms/djangoapps/certificates/management/commands/tests/test_cert_generation.py index 9231b9ba5c24..b2609a2fd801 100644 --- a/lms/djangoapps/certificates/management/commands/tests/test_cert_generation.py +++ b/lms/djangoapps/certificates/management/commands/tests/test_cert_generation.py @@ -9,7 +9,9 @@ from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from lms.djangoapps.certificates.tests.test_generation_handler import ID_VERIFIED_METHOD -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/certificates/management/commands/tests/test_regenerate_noidv_cert.py b/lms/djangoapps/certificates/management/commands/tests/test_regenerate_noidv_cert.py index d8c2402168b5..c42964ef96be 100644 --- a/lms/djangoapps/certificates/management/commands/tests/test_regenerate_noidv_cert.py +++ b/lms/djangoapps/certificates/management/commands/tests/test_regenerate_noidv_cert.py @@ -13,7 +13,9 @@ from lms.djangoapps.certificates.data import CertificateStatuses from lms.djangoapps.certificates.models import GeneratedCertificate from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order ID_VERIFIED_METHOD = 'lms.djangoapps.verify_student.services.IDVerificationService.user_is_verified' diff --git a/lms/djangoapps/certificates/migrations/0016_historicalgeneratedcertificate.py b/lms/djangoapps/certificates/migrations/0016_historicalgeneratedcertificate.py index dea466e256cf..d3e62c9d3d94 100644 --- a/lms/djangoapps/certificates/migrations/0016_historicalgeneratedcertificate.py +++ b/lms/djangoapps/certificates/migrations/0016_historicalgeneratedcertificate.py @@ -1,11 +1,11 @@ # Generated by Django 1.11.26 on 2019-12-10 18:05 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import opaque_keys.edx.django.models import simple_history.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/certificates/migrations/0018_historicalcertificateinvalidation.py b/lms/djangoapps/certificates/migrations/0018_historicalcertificateinvalidation.py index 3bd83e9528de..6dfd51579c55 100644 --- a/lms/djangoapps/certificates/migrations/0018_historicalcertificateinvalidation.py +++ b/lms/djangoapps/certificates/migrations/0018_historicalcertificateinvalidation.py @@ -1,11 +1,11 @@ # Generated by Django 2.2.17 on 2021-01-28 20:33 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields import simple_history.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/certificates/migrations/0019_allowlistgenerationconfiguration.py b/lms/djangoapps/certificates/migrations/0019_allowlistgenerationconfiguration.py index 8d063e6289c8..25ee8dfcf2fd 100644 --- a/lms/djangoapps/certificates/migrations/0019_allowlistgenerationconfiguration.py +++ b/lms/djangoapps/certificates/migrations/0019_allowlistgenerationconfiguration.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.18 on 2021-02-16 20:16 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/lms/djangoapps/certificates/migrations/0023_certificategenerationcommandconfiguration.py b/lms/djangoapps/certificates/migrations/0023_certificategenerationcommandconfiguration.py index c1ac0eb55bf6..050e911593ae 100644 --- a/lms/djangoapps/certificates/migrations/0023_certificategenerationcommandconfiguration.py +++ b/lms/djangoapps/certificates/migrations/0023_certificategenerationcommandconfiguration.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.19 on 2021-03-30 19:37 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/lms/djangoapps/certificates/migrations/0026_certificateallowlist.py b/lms/djangoapps/certificates/migrations/0026_certificateallowlist.py index 899ec700cd4c..cfe520d3fa32 100644 --- a/lms/djangoapps/certificates/migrations/0026_certificateallowlist.py +++ b/lms/djangoapps/certificates/migrations/0026_certificateallowlist.py @@ -1,11 +1,11 @@ # Generated by Django 2.2.20 on 2021-06-01 19:00 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields import opaque_keys.edx.django.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/certificates/migrations/0027_historicalcertificateallowlist.py b/lms/djangoapps/certificates/migrations/0027_historicalcertificateallowlist.py index 8531a5d21491..eec66689e428 100644 --- a/lms/djangoapps/certificates/migrations/0027_historicalcertificateallowlist.py +++ b/lms/djangoapps/certificates/migrations/0027_historicalcertificateallowlist.py @@ -1,12 +1,12 @@ # Generated by Django 2.2.20 on 2021-06-09 19:24 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields import opaque_keys.edx.django.models import simple_history.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/certificates/migrations/0031_certificatedateoverride_historicalcertificatedateoverride.py b/lms/djangoapps/certificates/migrations/0031_certificatedateoverride_historicalcertificatedateoverride.py index b8532a29e770..8a736fa20451 100644 --- a/lms/djangoapps/certificates/migrations/0031_certificatedateoverride_historicalcertificatedateoverride.py +++ b/lms/djangoapps/certificates/migrations/0031_certificatedateoverride_historicalcertificatedateoverride.py @@ -1,11 +1,11 @@ # Generated by Django 2.2.24 on 2021-08-02 17:24 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields import simple_history.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/certificates/migrations/0036_modifiedcertificatetemplatecommandconfiguration.py b/lms/djangoapps/certificates/migrations/0036_modifiedcertificatetemplatecommandconfiguration.py index ebc6cfd95b9a..d454e2b84d09 100644 --- a/lms/djangoapps/certificates/migrations/0036_modifiedcertificatetemplatecommandconfiguration.py +++ b/lms/djangoapps/certificates/migrations/0036_modifiedcertificatetemplatecommandconfiguration.py @@ -1,8 +1,8 @@ # Generated by Django 3.2.23 on 2024-01-16 18:57 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/lms/djangoapps/certificates/migrations/0038_pdf_certificate_purge_data_management.py b/lms/djangoapps/certificates/migrations/0038_pdf_certificate_purge_data_management.py index 6816719975e2..53eabdad0a8a 100644 --- a/lms/djangoapps/certificates/migrations/0038_pdf_certificate_purge_data_management.py +++ b/lms/djangoapps/certificates/migrations/0038_pdf_certificate_purge_data_management.py @@ -1,8 +1,8 @@ # Generated by Django 4.2.18 on 2025-02-20 22:36 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/lms/djangoapps/certificates/models.py b/lms/djangoapps/certificates/models.py index 985e4ea6ea20..7fb982eb0f95 100644 --- a/lms/djangoapps/certificates/models.py +++ b/lms/djangoapps/certificates/models.py @@ -20,6 +20,17 @@ from model_utils import Choices from model_utils.models import TimeStampedModel from opaque_keys.edx.django.models import CourseKeyField +from openedx_events.learning.data import ( # lint-amnesty, pylint: disable=wrong-import-order + CertificateData, + CourseData, + UserData, + UserPersonalData, +) +from openedx_events.learning.signals import ( # lint-amnesty, pylint: disable=wrong-import-order + CERTIFICATE_CHANGED, + CERTIFICATE_CREATED, + CERTIFICATE_REVOKED, +) from simple_history.models import HistoricalRecords from common.djangoapps.student import models_api as student_api @@ -31,9 +42,6 @@ from openedx.core.djangoapps.xmodule_django.models import NoneToEmptyManager from openedx.features.name_affirmation_api.utils import get_name_affirmation_service -from openedx_events.learning.data import CourseData, UserData, UserPersonalData, CertificateData # lint-amnesty, pylint: disable=wrong-import-order -from openedx_events.learning.signals import CERTIFICATE_CHANGED, CERTIFICATE_CREATED, CERTIFICATE_REVOKED # lint-amnesty, pylint: disable=wrong-import-order - log = logging.getLogger(__name__) User = get_user_model() diff --git a/lms/djangoapps/certificates/signals.py b/lms/djangoapps/certificates/signals.py index 39042ff34164..84dcfff2f5b2 100644 --- a/lms/djangoapps/certificates/signals.py +++ b/lms/djangoapps/certificates/signals.py @@ -7,25 +7,23 @@ from django.contrib.auth import get_user_model from django.db.models.signals import post_save from django.dispatch import receiver +from openedx_events.learning.signals import EXAM_ATTEMPT_REJECTED, IDV_ATTEMPT_APPROVED from common.djangoapps.course_modes import api as modes_api from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.signals import ENROLLMENT_TRACK_UPDATED +from lms.djangoapps.certificates.api import auto_certificate_generation_enabled, invalidate_certificate from lms.djangoapps.certificates.generation_handler import ( CertificateGenerationNotAllowed, generate_allowlist_certificate_task, generate_certificate_task, - is_on_certificate_allowlist + is_on_certificate_allowlist, ) from lms.djangoapps.certificates.models import ( CertificateAllowlist, CertificateGenerationCourseSetting, CertificateStatuses, - GeneratedCertificate -) -from lms.djangoapps.certificates.api import ( - auto_certificate_generation_enabled, - invalidate_certificate + GeneratedCertificate, ) from lms.djangoapps.verify_student.services import IDVerificationService from openedx.core.djangoapps.content.course_overviews.signals import COURSE_PACING_CHANGED @@ -35,7 +33,6 @@ LEARNER_SSO_VERIFIED, PHOTO_VERIFICATION_APPROVED, ) -from openedx_events.learning.signals import EXAM_ATTEMPT_REJECTED, IDV_ATTEMPT_APPROVED User = get_user_model() diff --git a/lms/djangoapps/certificates/tests/test_api.py b/lms/djangoapps/certificates/tests/test_api.py index 827e4017c631..1cbe800e8676 100644 --- a/lms/djangoapps/certificates/tests/test_api.py +++ b/lms/djangoapps/certificates/tests/test_api.py @@ -46,8 +46,8 @@ get_certificate_invalidation_entry, get_certificate_url, get_certificates_for_user, - get_course_ids_from_certs_for_user, get_certificates_for_user_by_course_keys, + get_course_ids_from_certs_for_user, has_self_generated_certificates_enabled, is_certificate_invalidated, is_on_allowlist, diff --git a/lms/djangoapps/certificates/tests/test_data.py b/lms/djangoapps/certificates/tests/test_data.py index 828633e812b5..b6e4c20d5e99 100644 --- a/lms/djangoapps/certificates/tests/test_data.py +++ b/lms/djangoapps/certificates/tests/test_data.py @@ -1,5 +1,6 @@ """Tests for the certificates Python Data Class. """ from django.test import TestCase + from lms.djangoapps.certificates.data import CertificateStatuses diff --git a/lms/djangoapps/certificates/tests/test_events.py b/lms/djangoapps/certificates/tests/test_events.py index eb1f215e4953..eafe0c8bf143 100644 --- a/lms/djangoapps/certificates/tests/test_events.py +++ b/lms/djangoapps/certificates/tests/test_events.py @@ -12,13 +12,14 @@ from openedx_events.tests.utils import OpenEdxEventsTestMixin from common.djangoapps.student.tests.factories import UserFactory +from common.test.utils import assert_dict_contains_subset +from lms.djangoapps.certificates.models import CertificateStatuses, GeneratedCertificate from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory -from lms.djangoapps.certificates.models import GeneratedCertificate, CertificateStatuses from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangolib.testing.utils import skip_unless_lms - -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from common.test.utils import assert_dict_contains_subset +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) @skip_unless_lms diff --git a/lms/djangoapps/certificates/tests/test_filters.py b/lms/djangoapps/certificates/tests/test_filters.py index a131a1d52582..7b01d6cb475f 100644 --- a/lms/djangoapps/certificates/tests/test_filters.py +++ b/lms/djangoapps/certificates/tests/test_filters.py @@ -9,8 +9,6 @@ from openedx_filters import PipelineStep from openedx_filters.learning.filters import CertificateCreationRequested from rest_framework import status as status_code -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.roles import SupportStaffRole @@ -18,17 +16,19 @@ from lms.djangoapps.certificates.generation_handler import ( CertificateGenerationNotAllowed, generate_allowlist_certificate_task, - generate_certificate_task + generate_certificate_task, ) from lms.djangoapps.certificates.models import GeneratedCertificate from lms.djangoapps.certificates.signals import ( - _listen_for_enrollment_mode_change, _handle_id_verification_approved, - listen_for_passing_grade + _listen_for_enrollment_mode_change, + listen_for_passing_grade, ) from lms.djangoapps.certificates.tests.factories import CertificateAllowlistFactory from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from openedx.core.djangolib.testing.utils import skip_unless_lms +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class TestCertificatePipelineStep(PipelineStep): diff --git a/lms/djangoapps/certificates/tests/test_generation.py b/lms/djangoapps/certificates/tests/test_generation.py index 6b7f3f1f3f72..51ab8a4906f2 100644 --- a/lms/djangoapps/certificates/tests/test_generation.py +++ b/lms/djangoapps/certificates/tests/test_generation.py @@ -1,10 +1,11 @@ """ Tests for certificate generation """ -import ddt import logging # lint-amnesty, pylint: disable=wrong-import-order from unittest import mock, skipUnless # lint-amnesty, pylint: disable=wrong-import-order +import ddt + from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import UserProfile from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory @@ -14,7 +15,9 @@ from lms.djangoapps.certificates.models import GeneratedCertificate from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory from openedx.features.name_affirmation_api.utils import get_name_affirmation_service -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order log = logging.getLogger(__name__) diff --git a/lms/djangoapps/certificates/tests/test_generation_handler.py b/lms/djangoapps/certificates/tests/test_generation_handler.py index d63cdce2acf7..75ba27656478 100644 --- a/lms/djangoapps/certificates/tests/test_generation_handler.py +++ b/lms/djangoapps/certificates/tests/test_generation_handler.py @@ -20,16 +20,18 @@ _set_regular_cert_status, generate_allowlist_certificate_task, generate_certificate_task, - is_on_certificate_allowlist + is_on_certificate_allowlist, ) from lms.djangoapps.certificates.models import GeneratedCertificate from lms.djangoapps.certificates.tests.factories import ( CertificateAllowlistFactory, CertificateInvalidationFactory, - GeneratedCertificateFactory + GeneratedCertificateFactory, ) from lms.djangoapps.grades.api import CourseGradeFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order log = logging.getLogger(__name__) diff --git a/lms/djangoapps/certificates/tests/test_models.py b/lms/djangoapps/certificates/tests/test_models.py index cd778bb8d8f2..bea9afe73b69 100644 --- a/lms/djangoapps/certificates/tests/test_models.py +++ b/lms/djangoapps/certificates/tests/test_models.py @@ -2,8 +2,8 @@ import json -from unittest.mock import patch from unittest import mock, skipUnless +from unittest.mock import patch import ddt import pytest @@ -28,17 +28,19 @@ CertificateTemplateAsset, ExampleCertificate, ExampleCertificateSet, - GeneratedCertificate + GeneratedCertificate, ) from lms.djangoapps.certificates.tests.factories import ( + CertificateAllowlistFactory, CertificateInvalidationFactory, GeneratedCertificateFactory, - CertificateAllowlistFactory, ) from lms.djangoapps.instructor_task.tests.factories import InstructorTaskFactory from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.features.name_affirmation_api.utils import get_name_affirmation_service -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order ENROLLMENT_METHOD = 'common.djangoapps.student.models.course_enrollment.CourseEnrollment.enrollment_mode_for_user' diff --git a/lms/djangoapps/certificates/tests/test_services.py b/lms/djangoapps/certificates/tests/test_services.py index fad9458c9c95..8ae29a8a1031 100644 --- a/lms/djangoapps/certificates/tests/test_services.py +++ b/lms/djangoapps/certificates/tests/test_services.py @@ -9,7 +9,9 @@ from lms.djangoapps.certificates.services import CertificateService from lms.djangoapps.certificates.tests.factories import CertificateAllowlistFactory, GeneratedCertificateFactory from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/certificates/tests/test_support_views.py b/lms/djangoapps/certificates/tests/test_support_views.py index 89ec8ac7ee51..c5ba36c4a718 100644 --- a/lms/djangoapps/certificates/tests/test_support_views.py +++ b/lms/djangoapps/certificates/tests/test_support_views.py @@ -19,7 +19,9 @@ from lms.djangoapps.certificates.models import CertificateInvalidation, CertificateStatuses, GeneratedCertificate from lms.djangoapps.certificates.tests.factories import CertificateInvalidationFactory, GeneratedCertificateFactory from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order CAN_GENERATE_METHOD = 'lms.djangoapps.certificates.generation_handler._can_generate_regular_certificate' diff --git a/lms/djangoapps/certificates/tests/test_tasks.py b/lms/djangoapps/certificates/tests/test_tasks.py index 2e6c84464936..cbdd28aabc8a 100644 --- a/lms/djangoapps/certificates/tests/test_tasks.py +++ b/lms/djangoapps/certificates/tests/test_tasks.py @@ -14,10 +14,7 @@ from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.certificates.data import CertificateStatuses -from lms.djangoapps.certificates.tasks import ( - generate_certificate, - get_changed_cert_templates, -) +from lms.djangoapps.certificates.tasks import generate_certificate, get_changed_cert_templates from lms.djangoapps.certificates.tests.factories import CertificateTemplateFactory diff --git a/lms/djangoapps/certificates/tests/test_views.py b/lms/djangoapps/certificates/tests/test_views.py index 520baa2a8fb2..6e9727f994b6 100644 --- a/lms/djangoapps/certificates/tests/test_views.py +++ b/lms/djangoapps/certificates/tests/test_views.py @@ -9,15 +9,14 @@ from django.test.utils import override_settings from common.djangoapps.student.tests.factories import UserFactory -from lms.djangoapps.certificates.models import ( - CertificateHtmlViewConfiguration, - CertificateStatuses, -) +from lms.djangoapps.certificates.models import CertificateHtmlViewConfiguration, CertificateStatuses from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory from lms.djangoapps.certificates.utils import get_certificate_url from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration from xmodule.data import CertificatesDisplayBehaviors # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order FEATURES_WITH_CERTS_ENABLED = settings.FEATURES.copy() diff --git a/lms/djangoapps/certificates/tests/test_webview_views.py b/lms/djangoapps/certificates/tests/test_webview_views.py index 1bfcd6ae2e66..e56507585d60 100644 --- a/lms/djangoapps/certificates/tests/test_webview_views.py +++ b/lms/djangoapps/certificates/tests/test_webview_views.py @@ -3,7 +3,7 @@ import datetime from unittest import skipUnless -from unittest.mock import patch, Mock +from unittest.mock import Mock, patch from urllib.parse import urlencode from uuid import uuid4 @@ -27,20 +27,20 @@ CertificateStatuses, CertificateTemplate, CertificateTemplateAsset, - GeneratedCertificate + GeneratedCertificate, ) from lms.djangoapps.certificates.tests.factories import ( CertificateDateOverrideFactory, CertificateHtmlViewConfigurationFactory, GeneratedCertificateFactory, - LinkedInAddToProfileConfigurationFactory + LinkedInAddToProfileConfigurationFactory, ) -from lms.djangoapps.certificates.views.webview import _get_user_certificate from lms.djangoapps.certificates.utils import get_certificate_url +from lms.djangoapps.certificates.views.webview import _get_user_certificate from openedx.core.djangoapps.dark_lang.models import DarkLangConfig from openedx.core.djangoapps.site_configuration.tests.test_util import ( with_site_configuration, - with_site_configuration_context + with_site_configuration_context, ) from openedx.core.djangolib.js_utils import js_escaped_string from openedx.core.djangolib.testing.utils import CacheIsolationTestCase diff --git a/lms/djangoapps/certificates/tests/tests.py b/lms/djangoapps/certificates/tests/tests.py index a6b6362792b8..97d7e267133b 100644 --- a/lms/djangoapps/certificates/tests/tests.py +++ b/lms/djangoapps/certificates/tests/tests.py @@ -15,12 +15,11 @@ from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.util.milestones_helpers import milestones_achieved_by_user, set_prerequisite_courses from lms.djangoapps.certificates.api import certificate_info_for_user, certificate_status_for_student -from lms.djangoapps.certificates.models import ( - CertificateStatuses, - GeneratedCertificate, -) +from lms.djangoapps.certificates.models import CertificateStatuses, GeneratedCertificate from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/certificates/utils.py b/lms/djangoapps/certificates/utils.py index 7ff2a4c97b27..1ea595ff6e61 100644 --- a/lms/djangoapps/certificates/utils.py +++ b/lms/djangoapps/certificates/utils.py @@ -1,8 +1,8 @@ """ Certificates utilities """ -from datetime import datetime import logging +from datetime import datetime from django.conf import settings from django.urls import reverse diff --git a/lms/djangoapps/certificates/views/tests/test_filters.py b/lms/djangoapps/certificates/views/tests/test_filters.py index 90b105f8ce00..d2093994bd2c 100644 --- a/lms/djangoapps/certificates/views/tests/test_filters.py +++ b/lms/djangoapps/certificates/views/tests/test_filters.py @@ -7,13 +7,13 @@ from openedx_filters import PipelineStep from openedx_filters.learning.filters import CertificateRenderStarted from rest_framework import status -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from lms.djangoapps.certificates.models import CertificateTemplate from lms.djangoapps.certificates.tests.test_webview_views import CommonCertificatesTestCase from lms.djangoapps.certificates.utils import get_certificate_url from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration from openedx.core.djangolib.testing.utils import skip_unless_lms +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase FEATURES_WITH_CERTS_ENABLED = settings.FEATURES.copy() FEATURES_WITH_CERTS_ENABLED['CERTIFICATES_HTML_VIEW'] = True diff --git a/lms/djangoapps/certificates/views/webview.py b/lms/djangoapps/certificates/views/webview.py index bee1638342fb..b8ffd68f4517 100644 --- a/lms/djangoapps/certificates/views/webview.py +++ b/lms/djangoapps/certificates/views/webview.py @@ -15,11 +15,11 @@ from django.template import RequestContext from django.utils import translation from django.utils.encoding import smart_str +from edx_django_utils.plugins import pluggable_override from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey from openedx_filters.learning.filters import CertificateRenderStarted from organizations import api as organizations_api -from edx_django_utils.plugins import pluggable_override from common.djangoapps.edxmako.shortcuts import render_to_response from common.djangoapps.edxmako.template import Template @@ -32,27 +32,26 @@ get_active_web_certificate, get_certificate_footer_context, get_certificate_header_context, - get_certificate_template + get_certificate_template, ) from lms.djangoapps.certificates.models import ( CertificateGenerationCourseSetting, CertificateHtmlViewConfiguration, CertificateSocialNetworks, CertificateStatuses, - GeneratedCertificate + GeneratedCertificate, ) from lms.djangoapps.certificates.permissions import PREVIEW_CERTIFICATES from lms.djangoapps.certificates.utils import ( emit_certificate_event, get_certificate_url, - get_preferred_certificate_name + get_preferred_certificate_name, ) from openedx.core.djangoapps.catalog.api import get_course_run_details from openedx.core.djangoapps.content.course_overviews.api import get_course_overview_or_none from openedx.core.djangoapps.lang_pref.api import get_closest_released_language from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers -from openedx.core.lib.courses import course_image_url -from openedx.core.lib.courses import get_course_by_id +from openedx.core.lib.courses import course_image_url, get_course_by_id from xmodule.data import CertificatesDisplayBehaviors # lint-amnesty, pylint: disable=wrong-import-order log = logging.getLogger(__name__) diff --git a/lms/djangoapps/commerce/api/v0/tests/test_views.py b/lms/djangoapps/commerce/api/v0/tests/test_views.py index ef9327fe6f43..eb3b749df50b 100644 --- a/lms/djangoapps/commerce/api/v0/tests/test_views.py +++ b/lms/djangoapps/commerce/api/v0/tests/test_views.py @@ -17,12 +17,16 @@ from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.tests.tests import EnrollmentEventTestMixin # lint-amnesty, pylint: disable=unused-import +from common.djangoapps.student.tests.tests import ( # lint-amnesty, pylint: disable=unused-import + EnrollmentEventTestMixin, +) from openedx.core.djangoapps.embargo.test_utils import restrict_course from openedx.core.djangoapps.enrollments.api import get_enrollment from openedx.core.lib.django_test_client_utils import get_absolute_url from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ....constants import Messages diff --git a/lms/djangoapps/commerce/api/v0/views.py b/lms/djangoapps/commerce/api/v0/views.py index a6cadadb4324..e5fa1867d1ae 100644 --- a/lms/djangoapps/commerce/api/v0/views.py +++ b/lms/djangoapps/commerce/api/v0/views.py @@ -9,7 +9,7 @@ from opaque_keys.edx.keys import CourseKey from requests.exceptions import HTTPError from rest_framework.permissions import IsAuthenticated -from rest_framework.status import HTTP_406_NOT_ACCEPTABLE, HTTP_409_CONFLICT, HTTP_400_BAD_REQUEST, HTTP_403_FORBIDDEN +from rest_framework.status import HTTP_400_BAD_REQUEST, HTTP_403_FORBIDDEN, HTTP_406_NOT_ACCEPTABLE, HTTP_409_CONFLICT from rest_framework.views import APIView from common.djangoapps.course_modes.models import CourseMode diff --git a/lms/djangoapps/commerce/api/v1/tests/test_views.py b/lms/djangoapps/commerce/api/v1/tests/test_views.py index 71b9a4810f19..5893522d30c6 100644 --- a/lms/djangoapps/commerce/api/v1/tests/test_views.py +++ b/lms/djangoapps/commerce/api/v1/tests/test_views.py @@ -17,7 +17,9 @@ from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.verify_student.models import VerificationDeadline -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ....tests.mocks import mock_order_endpoint diff --git a/lms/djangoapps/commerce/management/commands/tests/test_create_orders_for_old_enterprise_course_enrollmnet.py b/lms/djangoapps/commerce/management/commands/tests/test_create_orders_for_old_enterprise_course_enrollmnet.py index 8b2472f21446..6dbc5e3b2a02 100644 --- a/lms/djangoapps/commerce/management/commands/tests/test_create_orders_for_old_enterprise_course_enrollmnet.py +++ b/lms/djangoapps/commerce/management/commands/tests/test_create_orders_for_old_enterprise_course_enrollmnet.py @@ -15,7 +15,7 @@ from openedx.core.djangolib.testing.utils import skip_unless_lms from openedx.features.enterprise_support.tests.factories import ( EnterpriseCourseEnrollmentFactory, - EnterpriseCustomerUserFactory + EnterpriseCustomerUserFactory, ) diff --git a/lms/djangoapps/commerce/models.py b/lms/djangoapps/commerce/models.py index 330d7b805fae..0495d305262e 100644 --- a/lms/djangoapps/commerce/models.py +++ b/lms/djangoapps/commerce/models.py @@ -5,7 +5,6 @@ from config_models.models import ConfigurationModel from django.db import models - from django.utils.translation import gettext_lazy as _ diff --git a/lms/djangoapps/commerce/tests/__init__.py b/lms/djangoapps/commerce/tests/__init__.py index e2acd14f32e7..d41f657d96cc 100644 --- a/lms/djangoapps/commerce/tests/__init__.py +++ b/lms/djangoapps/commerce/tests/__init__.py @@ -1,21 +1,25 @@ """ Commerce app tests package. """ +import os from unittest import mock from urllib.parse import urljoin -import httpretty import ddt -import os +import httpretty import requests from django.conf import settings from django.test import TestCase -from freezegun import freeze_time from edx_rest_api_client.auth import JwtAuth -from openedx.core.djangoapps.commerce.utils import DeprecatedRestApiClient, user_agent +from freezegun import freeze_time from common.djangoapps.student.tests.factories import UserFactory -from openedx.core.djangoapps.commerce.utils import get_ecommerce_api_base_url, get_ecommerce_api_client +from openedx.core.djangoapps.commerce.utils import ( + DeprecatedRestApiClient, + get_ecommerce_api_base_url, + get_ecommerce_api_client, + user_agent, +) from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_for_user __version__ = '5.6.1' diff --git a/lms/djangoapps/commerce/tests/test_signals.py b/lms/djangoapps/commerce/tests/test_signals.py index 29a233639b54..4b7a030d7af2 100644 --- a/lms/djangoapps/commerce/tests/test_signals.py +++ b/lms/djangoapps/commerce/tests/test_signals.py @@ -8,25 +8,25 @@ from unittest import mock from urllib.parse import urljoin -import pytest import ddt import httpretty +import pytest from django.conf import settings from django.contrib.auth.models import AnonymousUser from django.test.utils import override_settings from opaque_keys.edx.keys import CourseKey from requests import Timeout -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.signals import REFUND_ORDER from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory +from common.test.utils import assert_dict_contains_subset +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from ..models import CommerceConfiguration from ..utils import _generate_refund_notification_body, _send_refund_notification, create_zendesk_ticket from . import JSON from .mocks import mock_create_refund, mock_process_refund -from common.test.utils import assert_dict_contains_subset ZENDESK_URL = 'http://zendesk.example.com/' ZENDESK_USER = 'test@example.com' diff --git a/lms/djangoapps/commerce/tests/test_utils.py b/lms/djangoapps/commerce/tests/test_utils.py index 61c02b708cd8..b517008da06f 100644 --- a/lms/djangoapps/commerce/tests/test_utils.py +++ b/lms/djangoapps/commerce/tests/test_utils.py @@ -22,8 +22,9 @@ from lms.djangoapps.commerce.utils import EcommerceService, refund_entitlement, refund_seat from openedx.core.djangolib.testing.utils import skip_unless_lms from openedx.core.lib.log_utils import audit_log -from xmodule.modulestore.tests.django_utils import \ - ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order # Entitlements is not in CMS' INSTALLED_APPS so these imports will error during test collection diff --git a/lms/djangoapps/commerce/tests/test_views.py b/lms/djangoapps/commerce/tests/test_views.py index 410d2520cc35..9024cbf31e5b 100644 --- a/lms/djangoapps/commerce/tests/test_views.py +++ b/lms/djangoapps/commerce/tests/test_views.py @@ -2,7 +2,6 @@ from common.djangoapps.student.tests.factories import UserFactory - TEST_PASSWORD = "Password1234" diff --git a/lms/djangoapps/commerce/utils.py b/lms/djangoapps/commerce/utils.py index 6ecc96f460f1..6bdc48669237 100644 --- a/lms/djangoapps/commerce/utils.py +++ b/lms/djangoapps/commerce/utils.py @@ -11,18 +11,18 @@ from django.contrib.auth import get_user_model from django.urls import reverse from django.utils.translation import gettext as _ +from edx_django_utils.plugins import pluggable_override from common.djangoapps.course_modes.models import CourseMode from openedx.core.djangoapps.commerce.utils import ( get_ecommerce_api_base_url, get_ecommerce_api_client, - is_commerce_service_configured + is_commerce_service_configured, ) from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.theming import helpers as theming_helpers from .models import CommerceConfiguration -from edx_django_utils.plugins import pluggable_override log = logging.getLogger(__name__) diff --git a/lms/djangoapps/course_api/__init__.py b/lms/djangoapps/course_api/__init__.py index e2e1b3045171..5c75ef0eea7b 100644 --- a/lms/djangoapps/course_api/__init__.py +++ b/lms/djangoapps/course_api/__init__.py @@ -3,7 +3,6 @@ from edx_toggles.toggles import WaffleSwitch - WAFFLE_SWITCH_NAMESPACE = 'course_list_api_rate_limit' # .. toggle_name: course_list_api_rate_limit.rate_limit_2 diff --git a/lms/djangoapps/course_api/api.py b/lms/djangoapps/course_api/api.py index 8210396441c7..c1ed1beb986d 100644 --- a/lms/djangoapps/course_api/api.py +++ b/lms/djangoapps/course_api/api.py @@ -20,7 +20,7 @@ from lms.djangoapps.courseware.courses import ( get_course_overview_with_access, get_courses, - get_permission_for_course_about + get_permission_for_course_about, ) from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.content.learning_sequences.api import get_course_outline diff --git a/lms/djangoapps/course_api/blocks/permissions.py b/lms/djangoapps/course_api/blocks/permissions.py index 1fc39e9b524a..9ad206948043 100644 --- a/lms/djangoapps/course_api/blocks/permissions.py +++ b/lms/djangoapps/course_api/blocks/permissions.py @@ -11,8 +11,9 @@ from lms.djangoapps.courseware.access_utils import ACCESS_DENIED, ACCESS_GRANTED, check_public_access from lms.djangoapps.courseware.courses import get_course from lms.djangoapps.courseware.exceptions import CourseRunNotFound -from openedx.core.djangoapps.content.course_overviews.models import \ - CourseOverview # lint-amnesty, pylint: disable=unused-import +from openedx.core.djangoapps.content.course_overviews.models import ( # lint-amnesty, pylint: disable=unused-import + CourseOverview, +) from xmodule.course_block import COURSE_VISIBILITY_PUBLIC # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/course_api/blocks/tests/pacts/views.py b/lms/djangoapps/course_api/blocks/tests/pacts/views.py index 85b5ac7a1a83..224b780b209f 100644 --- a/lms/djangoapps/course_api/blocks/tests/pacts/views.py +++ b/lms/djangoapps/course_api/blocks/tests/pacts/views.py @@ -7,11 +7,11 @@ from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST from opaque_keys.edx.keys import CourseKey -from xmodule.modulestore.tests.django_utils import ModuleStoreIsolationMixin -from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import CourseEnrollmentFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreIsolationMixin +from xmodule.modulestore.tests.factories import CourseFactory class ProviderState(ModuleStoreIsolationMixin): diff --git a/lms/djangoapps/course_api/blocks/tests/test_api.py b/lms/djangoapps/course_api/blocks/tests/test_api.py index 47d0b62fa6e6..d60f8388b887 100644 --- a/lms/djangoapps/course_api/blocks/tests/test_api.py +++ b/lms/djangoapps/course_api/blocks/tests/test_api.py @@ -12,8 +12,13 @@ from openedx.core.djangoapps.content.block_structure.api import clear_course_from_cache from openedx.core.djangolib.testing.utils import AUTHZ_TABLES from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import SampleCourseFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + SampleCourseFactory, + check_mongo_calls, +) from xmodule.modulestore.tests.sample_courses import BlockInfo # lint-amnesty, pylint: disable=wrong-import-order from ..api import get_blocks diff --git a/lms/djangoapps/course_api/blocks/tests/test_forms.py b/lms/djangoapps/course_api/blocks/tests/test_forms.py index 1a45b40292fe..e88bf219b4c3 100644 --- a/lms/djangoapps/course_api/blocks/tests/test_forms.py +++ b/lms/djangoapps/course_api/blocks/tests/test_forms.py @@ -14,7 +14,9 @@ from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from openedx.core.djangoapps.util.test_forms import FormTestMixin -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..forms import BlockListGetForm diff --git a/lms/djangoapps/course_api/blocks/tests/test_serializers.py b/lms/djangoapps/course_api/blocks/tests/test_serializers.py index b1b9f4cfef5a..64f0cc928678 100644 --- a/lms/djangoapps/course_api/blocks/tests/test_serializers.py +++ b/lms/djangoapps/course_api/blocks/tests/test_serializers.py @@ -10,7 +10,9 @@ from lms.djangoapps.course_blocks.api import get_course_block_access_transformers, get_course_blocks from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..serializers import BlockDictSerializer, BlockSerializer diff --git a/lms/djangoapps/course_api/blocks/tests/test_views.py b/lms/djangoapps/course_api/blocks/tests/test_views.py index f577762ad70f..2dba142d6707 100644 --- a/lms/djangoapps/course_api/blocks/tests/test_views.py +++ b/lms/djangoapps/course_api/blocks/tests/test_views.py @@ -18,11 +18,11 @@ from common.djangoapps.student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, Provider from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order - SharedModuleStoreTestCase + SharedModuleStoreTestCase, ) from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order BlockFactory, - ToyCourseFactory + ToyCourseFactory, ) from .helpers import deserialize_usage_key diff --git a/lms/djangoapps/course_api/blocks/transformers/blocks_api.py b/lms/djangoapps/course_api/blocks/transformers/blocks_api.py index cbfc398d8175..7cca2f5f56b6 100644 --- a/lms/djangoapps/course_api/blocks/transformers/blocks_api.py +++ b/lms/djangoapps/course_api/blocks/transformers/blocks_api.py @@ -10,8 +10,8 @@ from .extra_fields import ExtraFieldsTransformer from .navigation import BlockNavigationTransformer from .student_view import StudentViewTransformer -from .video_urls import VideoBlockURLTransformer from .video_stream_priority import VideoBlockStreamPriorityTransformer +from .video_urls import VideoBlockURLTransformer class BlocksAPITransformer(BlockStructureTransformer): diff --git a/lms/djangoapps/course_api/blocks/transformers/tests/test_block_completion.py b/lms/djangoapps/course_api/blocks/transformers/tests/test_block_completion.py index 1bea04b0486c..2b11f6f6572f 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_block_completion.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_block_completion.py @@ -12,7 +12,10 @@ from lms.djangoapps.course_api.blocks.transformers.block_completion import BlockCompletionTransformer from lms.djangoapps.course_blocks.api import get_course_blocks from lms.djangoapps.course_blocks.transformers.tests.helpers import ModuleStoreTestCase, TransformerRegistryTestMixin -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) class StubAggregatorXBlock(XBlock): diff --git a/lms/djangoapps/course_api/blocks/transformers/tests/test_block_counts.py b/lms/djangoapps/course_api/blocks/transformers/tests/test_block_counts.py index 78b3f70b3394..e9bc9789b087 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_block_counts.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_block_counts.py @@ -6,7 +6,9 @@ from openedx.core.djangoapps.content.block_structure.factory import BlockStructureFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import SampleCourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..block_counts import BlockCountsTransformer diff --git a/lms/djangoapps/course_api/blocks/transformers/tests/test_extra_fields.py b/lms/djangoapps/course_api/blocks/transformers/tests/test_extra_fields.py index 620dc5fe74c1..fa6c9fbb2f3c 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_extra_fields.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_extra_fields.py @@ -5,7 +5,9 @@ # pylint: disable=protected-access from openedx.core.djangoapps.content.block_structure.factory import BlockStructureFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import SampleCourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..extra_fields import ExtraFieldsTransformer 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 8ebd2477deef..3e6ea9e82a00 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_milestones.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_milestones.py @@ -6,14 +6,14 @@ from unittest.mock import Mock, patch import ddt +from edx_toggles.toggles.testutils import override_waffle_flag from milestones.tests.utils import MilestonesTestCaseMixin +import openedx.core.djangoapps.content.block_structure.api as bs_api from common.djangoapps.student.tests.factories import CourseEnrollmentFactory -from edx_toggles.toggles.testutils import override_waffle_flag from lms.djangoapps.course_blocks.api import get_course_blocks from lms.djangoapps.course_blocks.transformers.tests.helpers import CourseStructureTestCase from lms.djangoapps.gating import api as lms_gating_api -import openedx.core.djangoapps.content.block_structure.api as bs_api from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers from openedx.core.djangoapps.course_apps.toggles import EXAMS_IDA from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES 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 634743abbd1e..0ad707e92bdc 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_navigation.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_navigation.py @@ -14,7 +14,9 @@ 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 # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import SampleCourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/course_api/blocks/transformers/tests/test_student_view.py b/lms/djangoapps/course_api/blocks/transformers/tests/test_student_view.py index 8fe9075eec4c..da201c6509ad 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_student_view.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_student_view.py @@ -7,7 +7,9 @@ # pylint: disable=protected-access from openedx.core.djangoapps.content.block_structure.factory import BlockStructureFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..student_view import StudentViewTransformer diff --git a/lms/djangoapps/course_api/blocks/transformers/tests/test_video_stream_priority.py b/lms/djangoapps/course_api/blocks/transformers/tests/test_video_stream_priority.py index d0aea73738d1..20d5c1e43304 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_video_stream_priority.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_video_stream_priority.py @@ -6,7 +6,9 @@ from unittest import mock from openedx.core.djangoapps.content.block_structure.factory import BlockStructureFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..student_view import StudentViewTransformer diff --git a/lms/djangoapps/course_api/blocks/transformers/tests/test_video_urls.py b/lms/djangoapps/course_api/blocks/transformers/tests/test_video_urls.py index 8a695ac84ab5..d6004d3d92f4 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_video_urls.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_video_urls.py @@ -6,7 +6,9 @@ from unittest import mock from openedx.core.djangoapps.content.block_structure.factory import BlockStructureFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..student_view import StudentViewTransformer diff --git a/lms/djangoapps/course_api/blocks/utils.py b/lms/djangoapps/course_api/blocks/utils.py index 6f371624b7df..189a293641ec 100644 --- a/lms/djangoapps/course_api/blocks/utils.py +++ b/lms/djangoapps/course_api/blocks/utils.py @@ -3,10 +3,7 @@ """ from rest_framework.utils.serializer_helpers import ReturnList -from openedx.core.djangoapps.discussions.models import ( - DiscussionsConfiguration, - Provider, -) +from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, Provider def filter_discussion_xblocks_from_response(response, course_key): diff --git a/lms/djangoapps/course_api/blocks/views.py b/lms/djangoapps/course_api/blocks/views.py index 96679a562957..c5893c31598b 100644 --- a/lms/djangoapps/course_api/blocks/views.py +++ b/lms/djangoapps/course_api/blocks/views.py @@ -8,14 +8,14 @@ from django.http import Http404 from django.utils.cache import patch_response_headers from django.utils.decorators import method_decorator -from rest_framework.exceptions import PermissionDenied -from lms.djangoapps.courseware.access import has_access from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey, UsageKey +from rest_framework.exceptions import PermissionDenied from rest_framework.generics import ListAPIView from rest_framework.response import Response from lms.djangoapps.course_goals.models import UserActivity +from lms.djangoapps.courseware.access import has_access from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/course_api/forms.py b/lms/djangoapps/course_api/forms.py index 79dba03f45e8..624f00d004ad 100644 --- a/lms/djangoapps/course_api/forms.py +++ b/lms/djangoapps/course_api/forms.py @@ -10,10 +10,7 @@ from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey -from openedx.core.djangoapps.util.forms import ( - ExtendedNullBooleanField, - MultiValueField -) +from openedx.core.djangoapps.util.forms import ExtendedNullBooleanField, MultiValueField class UsernameValidatorMixin: diff --git a/lms/djangoapps/course_api/serializers.py b/lms/djangoapps/course_api/serializers.py index 5fc711376784..cd7339d7c3c1 100644 --- a/lms/djangoapps/course_api/serializers.py +++ b/lms/djangoapps/course_api/serializers.py @@ -5,15 +5,16 @@ import urllib -from common.djangoapps.student.models import CourseEnrollment from django.contrib.auth import get_user_model from django.urls import reverse from edx_django_utils import monitoring as monitoring_utils from rest_framework import serializers +from common.djangoapps.student.models import CourseEnrollment from lms.djangoapps.certificates.api import can_show_certificate_available_date_field -from openedx.core.djangoapps.content.course_overviews.models import \ - CourseOverview # lint-amnesty, pylint: disable=unused-import +from openedx.core.djangoapps.content.course_overviews.models import ( # lint-amnesty, pylint: disable=unused-import + CourseOverview, +) from openedx.core.djangoapps.models.course_details import CourseDetails from openedx.core.lib.api.fields import AbsoluteURLField diff --git a/lms/djangoapps/course_api/tests/mixins.py b/lms/djangoapps/course_api/tests/mixins.py index 46671867b72c..a615d13f2e15 100644 --- a/lms/djangoapps/course_api/tests/mixins.py +++ b/lms/djangoapps/course_api/tests/mixins.py @@ -5,7 +5,7 @@ from datetime import datetime -from common.djangoapps.student.tests.factories import UserFactory, CourseEnrollmentFactory, CourseAccessRoleFactory +from common.djangoapps.student.tests.factories import CourseAccessRoleFactory, CourseEnrollmentFactory, UserFactory from xmodule.modulestore.tests.factories import ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order TEST_PASSWORD = 'Password1234' diff --git a/lms/djangoapps/course_api/tests/test_api.py b/lms/djangoapps/course_api/tests/test_api.py index 8e4d1253f8f7..0a448213dfd5 100644 --- a/lms/djangoapps/course_api/tests/test_api.py +++ b/lms/djangoapps/course_api/tests/test_api.py @@ -17,11 +17,22 @@ from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import BlockFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order + ModuleStoreTestCase, + SharedModuleStoreTestCase, +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + check_mongo_calls, +) from ..api import ( - UNKNOWN_BLOCK_DISPLAY_NAME, course_detail, get_due_dates, list_courses, get_course_members, get_course_run_url, + UNKNOWN_BLOCK_DISPLAY_NAME, + course_detail, + get_course_members, + get_course_run_url, + get_due_dates, + list_courses, ) from ..exceptions import OverEnrollmentLimitException from .mixins import CourseApiFactoryMixin diff --git a/lms/djangoapps/course_api/tests/test_forms.py b/lms/djangoapps/course_api/tests/test_forms.py index 43a4aa104bde..85ce2a938bb7 100644 --- a/lms/djangoapps/course_api/tests/test_forms.py +++ b/lms/djangoapps/course_api/tests/test_forms.py @@ -11,7 +11,9 @@ from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.util.test_forms import FormTestMixin -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..forms import CourseDetailGetForm, CourseIdListGetForm, CourseListGetForm diff --git a/lms/djangoapps/course_api/tests/test_serializers.py b/lms/djangoapps/course_api/tests/test_serializers.py index b6069896aefe..71d99b1a9870 100644 --- a/lms/djangoapps/course_api/tests/test_serializers.py +++ b/lms/djangoapps/course_api/tests/test_serializers.py @@ -10,13 +10,13 @@ from rest_framework.request import Request from rest_framework.test import APIRequestFactory from xblock.core import XBlock -from xmodule.course_block import DEFAULT_START_DATE -from xmodule.modulestore.tests.django_utils import TEST_DATA_ONLY_SPLIT_MODULESTORE_DRAFT_PREFERRED, ModuleStoreTestCase -from xmodule.modulestore.tests.factories import check_mongo_calls from lms.djangoapps.certificates.api import can_show_certificate_available_date_field from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.models.course_details import CourseDetails +from xmodule.course_block import DEFAULT_START_DATE +from xmodule.modulestore.tests.django_utils import TEST_DATA_ONLY_SPLIT_MODULESTORE_DRAFT_PREFERRED, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import check_mongo_calls from ..serializers import CourseDetailSerializer, CourseKeySerializer, 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 2839b21c4cfb..4a7f7f39fffe 100644 --- a/lms/djangoapps/course_api/tests/test_views.py +++ b/lms/djangoapps/course_api/tests/test_views.py @@ -19,8 +19,6 @@ from search.tests.test_course_discovery import DemoCourse from search.tests.tests import TEST_INDEX_NAME from search.tests.utils import SearcherMixin -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory @@ -32,6 +30,8 @@ from openedx.core.lib.api.view_utils import LazySequence from openedx.features.content_type_gating.models import ContentTypeGatingConfig from openedx.features.course_duration_limits.models import CourseDurationLimitConfig +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory from ..views import CourseDetailView, CourseListUserThrottle, LazyPageNumberPagination from .mixins import TEST_PASSWORD, CourseApiFactoryMixin diff --git a/lms/djangoapps/course_blocks/transformers/library_content.py b/lms/djangoapps/course_blocks/transformers/library_content.py index e7f2258483bc..01b573168358 100644 --- a/lms/djangoapps/course_blocks/transformers/library_content.py +++ b/lms/djangoapps/course_blocks/transformers/library_content.py @@ -12,7 +12,7 @@ from lms.djangoapps.courseware.models import StudentModule from openedx.core.djangoapps.content.block_structure.transformer import ( BlockStructureTransformer, - FilteringTransformerMixin + FilteringTransformerMixin, ) from xmodule.library_content_block import LegacyLibraryContentBlock # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/course_blocks/transformers/split_test.py b/lms/djangoapps/course_blocks/transformers/split_test.py index 45fdaa09813d..e09c89b090bb 100644 --- a/lms/djangoapps/course_blocks/transformers/split_test.py +++ b/lms/djangoapps/course_blocks/transformers/split_test.py @@ -5,7 +5,7 @@ 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 0d7165034efe..28a96b04ce2e 100644 --- a/lms/djangoapps/course_blocks/transformers/start_date.py +++ b/lms/djangoapps/course_blocks/transformers/start_date.py @@ -9,7 +9,7 @@ from lms.djangoapps.courseware.access_utils import check_start_date from openedx.core.djangoapps.content.block_structure.transformer import ( BlockStructureTransformer, - FilteringTransformerMixin + FilteringTransformerMixin, ) from xmodule.course_metadata_utils import DEFAULT_START_DATE # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/course_blocks/transformers/tests/helpers.py b/lms/djangoapps/course_blocks/transformers/tests/helpers.py index fb78946280fd..09c3d83a5e2c 100644 --- a/lms/djangoapps/course_blocks/transformers/tests/helpers.py +++ b/lms/djangoapps/course_blocks/transformers/tests/helpers.py @@ -5,16 +5,15 @@ from unittest.mock import patch -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, BlockFactory - from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from lms.djangoapps.courseware.access import has_access 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 xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory 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 f2039a7b1dce..bc20c41ff935 100644 --- a/lms/djangoapps/course_blocks/transformers/tests/test_hidden_content.py +++ b/lms/djangoapps/course_blocks/transformers/tests/test_hidden_content.py @@ -7,7 +7,6 @@ import ddt from django.utils.timezone import now - from edx_when.api import get_dates_for_course, set_date_for_block from edx_when.field_data import DateOverrideTransformer 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 5a4d7a0de11a..367f5329a184 100644 --- a/lms/djangoapps/course_blocks/transformers/tests/test_library_content.py +++ b/lms/djangoapps/course_blocks/transformers/tests/test_library_content.py @@ -4,11 +4,11 @@ from unittest import mock +import openedx.core.djangoapps.content.block_structure.api as bs_api from common.djangoapps.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 -import openedx.core.djangoapps.content.block_structure.api as bs_api from ...api import get_course_blocks from ..library_content import ContentLibraryOrderTransformer, ContentLibraryTransformer from .helpers import CourseStructureTestCase diff --git a/lms/djangoapps/course_blocks/transformers/tests/test_load_override_data.py b/lms/djangoapps/course_blocks/transformers/tests/test_load_override_data.py index d0fef5065b43..8a94facf0f0a 100644 --- a/lms/djangoapps/course_blocks/transformers/tests/test_load_override_data.py +++ b/lms/djangoapps/course_blocks/transformers/tests/test_load_override_data.py @@ -7,14 +7,14 @@ import ddt import pytz -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase -from xmodule.modulestore.tests.factories import ToyCourseFactory from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from lms.djangoapps.course_blocks.transformers.load_override_data import REQUESTED_FIELDS, OverrideDataTransformer from lms.djangoapps.courseware.student_field_overrides import get_override_for_user, override_field_for_user from openedx.core.djangoapps.content.block_structure.factory import BlockStructureFactory +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import ToyCourseFactory expected_overrides = { 'start': datetime.datetime( 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 468cc30c8fbf..5d91623ab2ca 100644 --- a/lms/djangoapps/course_blocks/transformers/tests/test_split_test.py +++ b/lms/djangoapps/course_blocks/transformers/tests/test_split_test.py @@ -10,7 +10,9 @@ from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme from xmodule.modulestore.tests.factories import check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order from xmodule.partitions.partitions import Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions_service import get_user_partition_groups # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.partitions.partitions_service import ( + get_user_partition_groups, # lint-amnesty, pylint: disable=wrong-import-order +) from ...api import get_course_blocks from ..user_partitions import UserPartitionTransformer diff --git a/lms/djangoapps/course_blocks/transformers/user_partitions.py b/lms/djangoapps/course_blocks/transformers/user_partitions.py index 54424eb06fbd..5dd9bb1c47fb 100644 --- a/lms/djangoapps/course_blocks/transformers/user_partitions.py +++ b/lms/djangoapps/course_blocks/transformers/user_partitions.py @@ -5,12 +5,12 @@ from lms.djangoapps.courseware.access import has_access from openedx.core.djangoapps.content.block_structure.transformer import ( # lint-amnesty, pylint: disable=unused-import - BlockStructureTransformer + BlockStructureTransformer, ) from xmodule.partitions.partitions_service import ( # lint-amnesty, pylint: disable=wrong-import-order get_all_partitions_for_course, get_partition_from_id, - get_user_partition_groups + get_user_partition_groups, ) from .split_test import SplitTestTransformer diff --git a/lms/djangoapps/course_blocks/transformers/visibility.py b/lms/djangoapps/course_blocks/transformers/visibility.py index f7dd0da5f0af..3c4a09d9636f 100644 --- a/lms/djangoapps/course_blocks/transformers/visibility.py +++ b/lms/djangoapps/course_blocks/transformers/visibility.py @@ -5,7 +5,7 @@ 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_goals/management/commands/goal_reminder_email.py b/lms/djangoapps/course_goals/management/commands/goal_reminder_email.py index 287c613d895f..0613073c9b6a 100644 --- a/lms/djangoapps/course_goals/management/commands/goal_reminder_email.py +++ b/lms/djangoapps/course_goals/management/commands/goal_reminder_email.py @@ -1,28 +1,28 @@ """ Command to trigger sending reminder emails for learners to achieve their Course Goals """ +import logging import time +import uuid from datetime import date, datetime, timedelta import boto3 -from edx_ace.channel.django_email import DjangoEmailChannel -from edx_ace.channel.mixins import EmailChannelMixin -from eventtracking import tracker -import logging -import uuid - from django.conf import settings from django.contrib.sites.models import Site from django.core.management.base import BaseCommand from edx_ace import ace, presentation +from edx_ace.channel.django_email import DjangoEmailChannel +from edx_ace.channel.mixins import EmailChannelMixin from edx_ace.message import Message from edx_ace.recipient import Recipient from edx_ace.utils.signals import send_ace_message_sent_signal +from eventtracking import tracker + from common.djangoapps.student.models import CourseEnrollment from lms.djangoapps.certificates.api import get_certificate_for_user_id from lms.djangoapps.certificates.data import CertificateStatuses -from lms.djangoapps.courseware.context_processor import get_user_timezone_or_last_seen_timezone_or_utc from lms.djangoapps.course_goals.models import CourseGoal, CourseGoalReminderStatus, UserActivity +from lms.djangoapps.courseware.context_processor import get_user_timezone_or_last_seen_timezone_or_utc from openedx.core.djangoapps.ace_common.template_context import get_base_template_context from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY diff --git a/lms/djangoapps/course_goals/management/commands/tests/test_goal_reminder_email.py b/lms/djangoapps/course_goals/management/commands/tests/test_goal_reminder_email.py index d78031fa48e5..e3b174168e75 100644 --- a/lms/djangoapps/course_goals/management/commands/tests/test_goal_reminder_email.py +++ b/lms/djangoapps/course_goals/management/commands/tests/test_goal_reminder_email.py @@ -1,31 +1,32 @@ """Tests for the goal_reminder_email command""" import uuid from datetime import datetime - -from botocore.exceptions import NoCredentialsError -from django.contrib.sites.models import Site -from edx_ace import Recipient, Message -from pytz import UTC from unittest import mock # lint-amnesty, pylint: disable=wrong-import-order import ddt +from botocore.exceptions import NoCredentialsError from django.conf import settings +from django.contrib.sites.models import Site from django.core.management import call_command from django.test import TestCase from django.test.utils import override_settings +from edx_ace import Message, Recipient from edx_toggles.toggles.testutils import override_waffle_flag from freezegun import freeze_time +from pytz import UTC from waffle import get_waffle_flag_model # pylint: disable=invalid-django-waffle-import from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory -from lms.djangoapps.course_goals.management.commands.goal_reminder_email import send_email_using_ses, send_ace_message +from lms.djangoapps.certificates.data import CertificateStatuses +from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory +from lms.djangoapps.course_goals.management.commands.goal_reminder_email import send_ace_message, send_email_using_ses from lms.djangoapps.course_goals.models import CourseGoalReminderStatus from lms.djangoapps.course_goals.tests.factories import ( - CourseGoalFactory, CourseGoalReminderStatusFactory, UserActivityFactory, + CourseGoalFactory, + CourseGoalReminderStatusFactory, + UserActivityFactory, ) -from lms.djangoapps.certificates.data import CertificateStatuses -from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory from openedx.core.djangoapps.ace_common.template_context import get_base_template_context from openedx.core.djangolib.testing.utils import skip_unless_lms from openedx.core.lib.celery.task_utils import emulate_http_request diff --git a/lms/djangoapps/course_goals/migrations/0001_initial.py b/lms/djangoapps/course_goals/migrations/0001_initial.py index 1dd8905d0172..a4d380a250bb 100644 --- a/lms/djangoapps/course_goals/migrations/0001_initial.py +++ b/lms/djangoapps/course_goals/migrations/0001_initial.py @@ -1,5 +1,5 @@ -from django.db import migrations, models from django.conf import settings +from django.db import migrations, models from opaque_keys.edx.django.models import CourseKeyField diff --git a/lms/djangoapps/course_goals/migrations/0003_historicalcoursegoal.py b/lms/djangoapps/course_goals/migrations/0003_historicalcoursegoal.py index 868477feb75d..8bbb9b62db15 100644 --- a/lms/djangoapps/course_goals/migrations/0003_historicalcoursegoal.py +++ b/lms/djangoapps/course_goals/migrations/0003_historicalcoursegoal.py @@ -1,10 +1,10 @@ # Generated by Django 2.2.20 on 2021-05-14 16:57 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import opaque_keys.edx.django.models import simple_history.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/course_goals/migrations/0005_useractivity.py b/lms/djangoapps/course_goals/migrations/0005_useractivity.py index 7a1efe3c831f..a0af53f53ca4 100644 --- a/lms/djangoapps/course_goals/migrations/0005_useractivity.py +++ b/lms/djangoapps/course_goals/migrations/0005_useractivity.py @@ -1,9 +1,9 @@ # Generated by Django 2.2.24 on 2021-08-13 17:02 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import opaque_keys.edx.django.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/course_goals/migrations/0007_set_unsubscribe_token_default.py b/lms/djangoapps/course_goals/migrations/0007_set_unsubscribe_token_default.py index 6704d96e7fbf..55ed065e03aa 100644 --- a/lms/djangoapps/course_goals/migrations/0007_set_unsubscribe_token_default.py +++ b/lms/djangoapps/course_goals/migrations/0007_set_unsubscribe_token_default.py @@ -1,8 +1,9 @@ # Generated by Django 2.2.24 on 2021-08-20 19:18 -from django.db import migrations, models import uuid +from django.db import migrations, models + class Migration(migrations.Migration): diff --git a/lms/djangoapps/course_goals/migrations/0008_coursegoalreminderstatus.py b/lms/djangoapps/course_goals/migrations/0008_coursegoalreminderstatus.py index 660a7852ef69..a7cd2205cdab 100644 --- a/lms/djangoapps/course_goals/migrations/0008_coursegoalreminderstatus.py +++ b/lms/djangoapps/course_goals/migrations/0008_coursegoalreminderstatus.py @@ -1,9 +1,9 @@ # Generated by Django 2.2.24 on 2021-09-20 16:42 -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/course_goals/models.py b/lms/djangoapps/course_goals/models.py index 616966600040..20ab505f2847 100644 --- a/lms/djangoapps/course_goals/models.py +++ b/lms/djangoapps/course_goals/models.py @@ -2,8 +2,8 @@ Course Goals Models """ -import uuid import logging +import uuid from datetime import datetime, timedelta from django.contrib.auth import get_user_model @@ -14,8 +14,8 @@ from opaque_keys.edx.django.models import CourseKeyField from simple_history.models import HistoricalRecords -from lms.djangoapps.courseware.masquerade import is_masquerading from lms.djangoapps.courseware.context_processor import get_user_timezone_or_last_seen_timezone_or_utc +from lms.djangoapps.courseware.masquerade import is_masquerading from openedx.core.lib.mobile_utils import is_request_from_mobile_app from openedx.features.course_experience import ENABLE_COURSE_GOALS diff --git a/lms/djangoapps/course_goals/tests/test_user_activity.py b/lms/djangoapps/course_goals/tests/test_user_activity.py index 285c538862db..afdefc0599a0 100644 --- a/lms/djangoapps/course_goals/tests/test_user_activity.py +++ b/lms/djangoapps/course_goals/tests/test_user_activity.py @@ -12,8 +12,6 @@ from edx_django_utils.cache import TieredCache from edx_toggles.toggles.testutils import override_waffle_flag from freezegun import freeze_time -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory from common.djangoapps.edxmako.shortcuts import render_to_response from common.djangoapps.student.models import CourseEnrollment @@ -21,6 +19,8 @@ from common.djangoapps.util.testing import UrlResetMixin from lms.djangoapps.course_goals.models import UserActivity from openedx.features.course_experience import ENABLE_COURSE_GOALS +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory User = get_user_model() diff --git a/lms/djangoapps/course_home_api/course_metadata/tests/test_views.py b/lms/djangoapps/course_home_api/course_metadata/tests/test_views.py index c7abfaa5067f..4e1585e3b0ad 100644 --- a/lms/djangoapps/course_home_api/course_metadata/tests/test_views.py +++ b/lms/djangoapps/course_home_api/course_metadata/tests/test_views.py @@ -6,8 +6,8 @@ import ddt from django.db import transaction -from django.urls import reverse from django.test.utils import override_settings +from django.urls import reverse from edx_toggles.toggles.testutils import override_waffle_flag from common.djangoapps.course_modes.models import CourseMode @@ -16,19 +16,19 @@ CourseBetaTesterRole, CourseInstructorRole, CourseLimitedStaffRole, - CourseStaffRole + CourseStaffRole, ) from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.course_home_api.tests.utils import BaseCourseHomeTests from lms.djangoapps.courseware.toggles import ( COURSEWARE_MFE_MILESTONES_STREAK_DISCOUNT, COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES, - COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES_STREAK_CELEBRATION + COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES_STREAK_CELEBRATION, ) from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration from openedx.features.enterprise_support.tests.factories import ( EnterpriseCourseEnrollmentFactory, - EnterpriseCustomerUserFactory + EnterpriseCustomerUserFactory, ) diff --git a/lms/djangoapps/course_home_api/course_metadata/views.py b/lms/djangoapps/course_home_api/course_metadata/views.py index 4f83ccacc3f5..5106fd813859 100644 --- a/lms/djangoapps/course_home_api/course_metadata/views.py +++ b/lms/djangoapps/course_home_api/course_metadata/views.py @@ -4,30 +4,29 @@ from django.db import transaction from django.utils.decorators import method_decorator +from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication +from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser from opaque_keys.edx.keys import CourseKey from rest_framework.exceptions import PermissionDenied from rest_framework.generics import RetrieveAPIView from rest_framework.response import Response -from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication -from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser -from lms.djangoapps.certificates.api import certificates_viewable_for_course -from lms.djangoapps.course_home_api.toggles import new_discussion_sidebar_view_is_enabled -from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser -from openedx.core.djangoapps.courseware_api.utils import get_celebrations_dict - from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.auth import has_course_author_access from common.djangoapps.student.models import CourseEnrollment +from lms.djangoapps.certificates.api import certificates_viewable_for_course from lms.djangoapps.course_api.api import course_detail from lms.djangoapps.course_goals.models import UserActivity from lms.djangoapps.course_home_api.course_metadata.serializers import CourseHomeMetadataSerializer +from lms.djangoapps.course_home_api.toggles import new_discussion_sidebar_view_is_enabled from lms.djangoapps.courseware.access import has_access, has_cms_access from lms.djangoapps.courseware.context_processor import user_timezone_locale_prefs from lms.djangoapps.courseware.courses import check_course_access from lms.djangoapps.courseware.exceptions import CourseAccessRedirect from lms.djangoapps.courseware.masquerade import setup_masquerade from lms.djangoapps.courseware.tabs import get_course_tab_list +from openedx.core.djangoapps.courseware_api.utils import get_celebrations_dict +from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser @method_decorator(transaction.non_atomic_requests, name='dispatch') diff --git a/lms/djangoapps/course_home_api/migrations/0001_initial.py b/lms/djangoapps/course_home_api/migrations/0001_initial.py index 9156e96dbdab..19280e577c93 100644 --- a/lms/djangoapps/course_home_api/migrations/0001_initial.py +++ b/lms/djangoapps/course_home_api/migrations/0001_initial.py @@ -1,8 +1,9 @@ # Generated by Django 2.2.20 on 2021-05-26 17:41 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion + import openedx.core.djangoapps.config_model_utils.models diff --git a/lms/djangoapps/course_home_api/outline/tests/test_goals.py b/lms/djangoapps/course_home_api/outline/tests/test_goals.py index 699531c93d02..ac3c744153f1 100644 --- a/lms/djangoapps/course_home_api/outline/tests/test_goals.py +++ b/lms/djangoapps/course_home_api/outline/tests/test_goals.py @@ -9,15 +9,17 @@ from django.contrib.auth import get_user_model from django.test.utils import override_settings from django.urls import reverse +from edx_toggles.toggles.testutils import override_waffle_flag # lint-amnesty, pylint: disable=wrong-import-order from rest_framework.test import APIClient from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory -from edx_toggles.toggles.testutils import override_waffle_flag # lint-amnesty, pylint: disable=wrong-import-order from lms.djangoapps.course_goals.models import CourseGoal from lms.djangoapps.course_home_api.tests.utils import BaseCourseHomeTests from openedx.features.course_experience import ENABLE_COURSE_GOALS -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order EVENT_NAME_ADDED = 'edx.course.goal.added' diff --git a/lms/djangoapps/course_home_api/outline/tests/test_view.py b/lms/djangoapps/course_home_api/outline/tests/test_view.py index 74e22e5fcc4b..c0252802c80b 100644 --- a/lms/djangoapps/course_home_api/outline/tests/test_view.py +++ b/lms/djangoapps/course_home_api/outline/tests/test_view.py @@ -20,8 +20,8 @@ from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.roles import CourseInstructorRole from common.djangoapps.student.tests.factories import UserFactory -from lms.djangoapps.course_home_api.toggles import COURSE_HOME_SEND_COURSE_PROGRESS_ANALYTICS_FOR_STUDENT from lms.djangoapps.course_home_api.tests.utils import BaseCourseHomeTests +from lms.djangoapps.course_home_api.toggles import COURSE_HOME_SEND_COURSE_PROGRESS_ANALYTICS_FOR_STUDENT from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.content.learning_sequences.api import replace_course_outline @@ -30,19 +30,10 @@ from openedx.core.djangoapps.user_api.preferences.api import set_user_preference from openedx.core.djangoapps.user_api.tests.factories import UserCourseTagFactory from openedx.features.course_duration_limits.models import CourseDurationLimitConfig -from openedx.features.course_experience import ( - COURSE_ENABLE_UNENROLLED_ACCESS_FLAG, - ENABLE_COURSE_GOALS -) +from openedx.features.course_experience import COURSE_ENABLE_UNENROLLED_ACCESS_FLAG, ENABLE_COURSE_GOALS from openedx.features.discounts.applicability import DISCOUNT_APPLICABILITY_FLAG, FIRST_PURCHASE_DISCOUNT_OVERRIDE_FLAG -from xmodule.course_block import ( - COURSE_VISIBILITY_PUBLIC, - COURSE_VISIBILITY_PUBLIC_OUTLINE -) -from xmodule.modulestore.tests.factories import ( - BlockFactory, - CourseFactory -) +from xmodule.course_block import COURSE_VISIBILITY_PUBLIC, COURSE_VISIBILITY_PUBLIC_OUTLINE +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory @ddt.ddt diff --git a/lms/djangoapps/course_home_api/outline/views.py b/lms/djangoapps/course_home_api/outline/views.py index 9d67a01c6021..1e6a2b90270c 100644 --- a/lms/djangoapps/course_home_api/outline/views.py +++ b/lms/djangoapps/course_home_api/outline/views.py @@ -13,30 +13,34 @@ from django.urls import reverse # lint-amnesty, pylint: disable=wrong-import-order from django.utils.translation import gettext as _ # lint-amnesty, pylint: disable=wrong-import-order from edx_django_utils import monitoring as monitoring_utils # lint-amnesty, pylint: disable=wrong-import-order -from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication # lint-amnesty, pylint: disable=wrong-import-order -from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser # lint-amnesty, pylint: disable=wrong-import-order +from edx_rest_framework_extensions.auth.jwt.authentication import ( + JwtAuthentication, # lint-amnesty, pylint: disable=wrong-import-order +) +from edx_rest_framework_extensions.auth.session.authentication import ( + SessionAuthenticationAllowInactiveUser, # lint-amnesty, pylint: disable=wrong-import-order +) from opaque_keys.edx.keys import CourseKey # lint-amnesty, pylint: disable=wrong-import-order -from rest_framework.decorators import api_view, authentication_classes, permission_classes # lint-amnesty, pylint: disable=wrong-import-order +from rest_framework.decorators import ( # lint-amnesty, pylint: disable=wrong-import-order + api_view, + authentication_classes, + permission_classes, +) from rest_framework.exceptions import APIException, ParseError # lint-amnesty, pylint: disable=wrong-import-order from rest_framework.generics import RetrieveAPIView # lint-amnesty, pylint: disable=wrong-import-order from rest_framework.permissions import IsAuthenticated # lint-amnesty, pylint: disable=wrong-import-order from rest_framework.response import Response # lint-amnesty, pylint: disable=wrong-import-order +from xblock.completable import XBlockCompletionMode +from xblock.core import XBlock from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.util.views import expose_header -from lms.djangoapps.course_goals.api import ( - add_course_goal, - get_course_goal, -) +from lms.djangoapps.course_goals.api import add_course_goal, get_course_goal from lms.djangoapps.course_goals.models import CourseGoal -from lms.djangoapps.course_home_api.outline.serializers import ( - CourseBlockSerializer, - OutlineTabSerializer, -) -from lms.djangoapps.course_home_api.utils import get_course_or_403 +from lms.djangoapps.course_home_api.outline.serializers import CourseBlockSerializer, OutlineTabSerializer from lms.djangoapps.course_home_api.tasks import collect_progress_for_user_in_course from lms.djangoapps.course_home_api.toggles import send_course_progress_analytics_for_student_is_enabled +from lms.djangoapps.course_home_api.utils import get_course_or_403 from lms.djangoapps.courseware.access import has_access from lms.djangoapps.courseware.context_processor import user_timezone_locale_prefs from lms.djangoapps.courseware.courses import get_course_date_blocks, get_course_info_section @@ -47,8 +51,8 @@ from lms.djangoapps.courseware.views.views import get_cert_data from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.utils import OptimizelyClient -from openedx.core.djangoapps.content.learning_sequences.api import get_user_course_outline from openedx.core.djangoapps.content.course_overviews.api import get_course_overview_or_404 +from openedx.core.djangoapps.content.learning_sequences.api import get_user_course_outline from openedx.core.djangoapps.course_groups.cohorts import get_cohort from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser from openedx.features.course_duration_limits.access import get_access_expiration_data @@ -56,14 +60,15 @@ from openedx.features.course_experience.course_tools import CourseToolsPluginManager from openedx.features.course_experience.course_updates import ( dismiss_current_update_for_user, - get_current_update_for_user + get_current_update_for_user, ) from openedx.features.course_experience.url_helpers import get_learning_mfe_home_url from openedx.features.course_experience.utils import get_course_outline_block_tree, get_start_block from openedx.features.discounts.utils import generate_offer_data -from xblock.core import XBlock -from xblock.completable import XBlockCompletionMode -from xmodule.course_block import COURSE_VISIBILITY_PUBLIC, COURSE_VISIBILITY_PUBLIC_OUTLINE # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.course_block import ( # lint-amnesty, pylint: disable=wrong-import-order + COURSE_VISIBILITY_PUBLIC, + COURSE_VISIBILITY_PUBLIC_OUTLINE, +) class UnableToDismissWelcomeMessage(APIException): diff --git a/lms/djangoapps/course_home_api/progress/api.py b/lms/djangoapps/course_home_api/progress/api.py index 6f219be9f269..892bdd940a47 100644 --- a/lms/djangoapps/course_home_api/progress/api.py +++ b/lms/djangoapps/course_home_api/progress/api.py @@ -4,14 +4,15 @@ from __future__ import annotations +from dataclasses import dataclass, field +from datetime import datetime, timezone + from django.contrib.auth import get_user_model from opaque_keys.edx.keys import CourseKey -from openedx.core.lib.grade_utils import round_away_from_zero from xblock.scorable import ShowCorrectness -from datetime import datetime, timezone from lms.djangoapps.courseware.courses import get_course_blocks_completion_summary -from dataclasses import dataclass, field +from openedx.core.lib.grade_utils import round_away_from_zero User = get_user_model() diff --git a/lms/djangoapps/course_home_api/progress/serializers.py b/lms/djangoapps/course_home_api/progress/serializers.py index 2aefe40d6a0b..04ddccd22399 100644 --- a/lms/djangoapps/course_home_api/progress/serializers.py +++ b/lms/djangoapps/course_home_api/progress/serializers.py @@ -3,9 +3,9 @@ """ from datetime import datetime +from pytz import UTC from rest_framework import serializers from rest_framework.reverse import reverse -from pytz import UTC from lms.djangoapps.course_home_api.serializers import ReadOnlySerializer, VerifiedModeSerializer diff --git a/lms/djangoapps/course_home_api/progress/tests/test_api.py b/lms/djangoapps/course_home_api/progress/tests/test_api.py index c91b226a0e9d..ed76ce6052b4 100644 --- a/lms/djangoapps/course_home_api/progress/tests/test_api.py +++ b/lms/djangoapps/course_home_api/progress/tests/test_api.py @@ -2,17 +2,17 @@ Tests for the Python APIs exposed by the Progress API of the Course Home API app. """ +from datetime import datetime, timedelta, timezone +from types import SimpleNamespace from unittest.mock import patch from django.test import TestCase from xblock.scorable import ShowCorrectness from lms.djangoapps.course_home_api.progress.api import ( - calculate_progress_for_learner_in_course, aggregate_assignment_type_grade_summary, + calculate_progress_for_learner_in_course, ) -from datetime import datetime, timedelta, timezone -from types import SimpleNamespace def _make_subsection(fmt, earned, possible, show_corr, *, due_delta_days=None, is_included=True): diff --git a/lms/djangoapps/course_home_api/progress/tests/test_views.py b/lms/djangoapps/course_home_api/progress/tests/test_views.py index 79b6bb60da3c..80528510f8ed 100644 --- a/lms/djangoapps/course_home_api/progress/tests/test_views.py +++ b/lms/djangoapps/course_home_api/progress/tests/test_views.py @@ -11,20 +11,19 @@ from django.utils.timezone import now from edx_toggles.toggles.testutils import override_waffle_flag from pytz import UTC -from xmodule.modulestore.tests.factories import BlockFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory -from lms.djangoapps.course_home_api.tests.utils import BaseCourseHomeTests from lms.djangoapps.course_home_api.models import DisableProgressPageStackedConfig +from lms.djangoapps.course_home_api.tests.utils import BaseCourseHomeTests from lms.djangoapps.course_home_api.toggles import COURSE_HOME_MICROFRONTEND_PROGRESS_TAB from lms.djangoapps.grades.api import CourseGradeFactory from lms.djangoapps.grades.constants import GradeOverrideFeatureEnum from lms.djangoapps.grades.models import ( PersistentCourseGrade, PersistentSubsectionGrade, - PersistentSubsectionGradeOverride + PersistentSubsectionGradeOverride, ) from lms.djangoapps.grades.tests.utils import answer_problem from lms.djangoapps.verify_student.models import ManualVerification @@ -34,6 +33,7 @@ from openedx.features.content_type_gating.helpers import CONTENT_GATING_PARTITION_ID, CONTENT_TYPE_GATE_GROUP_IDS from openedx.features.content_type_gating.models import ContentTypeGatingConfig from openedx.features.course_duration_limits.models import CourseDurationLimitConfig +from xmodule.modulestore.tests.factories import BlockFactory @ddt.ddt diff --git a/lms/djangoapps/course_home_api/progress/views.py b/lms/djangoapps/course_home_api/progress/views.py index d814fb836eef..211f81d8ca5a 100644 --- a/lms/djangoapps/course_home_api/progress/views.py +++ b/lms/djangoapps/course_home_api/progress/views.py @@ -13,33 +13,28 @@ from rest_framework.response import Response from xblock.scorable import ShowCorrectness -from xmodule.modulestore.django import modulestore from common.djangoapps.student.models import CourseEnrollment -from lms.djangoapps.course_home_api.progress.serializers import ProgressTabSerializer -from lms.djangoapps.course_home_api.progress.api import aggregate_assignment_type_grade_summary - -from lms.djangoapps.course_home_api.toggles import course_home_mfe_progress_tab_is_active -from lms.djangoapps.courseware.access import has_access, has_ccx_coach_role +from lms.djangoapps.ccx.custom_exception import CCXLocatorValidationException from lms.djangoapps.course_blocks.api import get_course_blocks from lms.djangoapps.course_blocks.transformers import start_date - -from lms.djangoapps.ccx.custom_exception import CCXLocatorValidationException +from lms.djangoapps.course_home_api.progress.api import aggregate_assignment_type_grade_summary +from lms.djangoapps.course_home_api.progress.serializers import ProgressTabSerializer +from lms.djangoapps.course_home_api.toggles import course_home_mfe_progress_tab_is_active from lms.djangoapps.course_home_api.utils import get_course_or_403 -from lms.djangoapps.courseware.courses import ( - get_course_blocks_completion_summary, get_studio_url, -) +from lms.djangoapps.courseware.access import has_access, has_ccx_coach_role +from lms.djangoapps.courseware.courses import get_course_blocks_completion_summary, get_studio_url from lms.djangoapps.courseware.masquerade import setup_masquerade from lms.djangoapps.courseware.views.views import credit_course_requirements, get_cert_data - from lms.djangoapps.grades.api import CourseGradeFactory from lms.djangoapps.verify_student.services import IDVerificationService -from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers from openedx.core.djangoapps.content.block_structure.api import get_block_structure_manager +from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser from openedx.features.content_type_gating.block_transformers import ContentTypeGateTransformer from openedx.features.course_duration_limits.access import get_access_expiration_data from openedx.features.enterprise_support.utils import get_enterprise_learner_generic_name +from xmodule.modulestore.django import modulestore User = get_user_model() diff --git a/lms/djangoapps/course_home_api/tests/test_tasks.py b/lms/djangoapps/course_home_api/tests/test_tasks.py index 385878225244..3c35940818f3 100644 --- a/lms/djangoapps/course_home_api/tests/test_tasks.py +++ b/lms/djangoapps/course_home_api/tests/test_tasks.py @@ -2,18 +2,18 @@ Tests for Celery tasks used by the `course_home_api` app. """ -from unittest.mock import patch, MagicMock +from unittest.mock import MagicMock, patch from opaque_keys.edx.keys import CourseKey from testfixtures import LogCapture -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from lms.djangoapps.course_home_api.tasks import ( COURSE_COMPLETION_FOR_USER_EVENT_NAME, - collect_progress_for_user_in_course + collect_progress_for_user_in_course, ) from openedx.core.djangoapps.catalog.tests.factories import CourseFactory, CourseRunFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase LOG_PATH = 'lms.djangoapps.course_home_api.tasks' diff --git a/lms/djangoapps/course_home_api/tests/test_utils.py b/lms/djangoapps/course_home_api/tests/test_utils.py index 1d665a6b376a..cfd0d0ce3f55 100644 --- a/lms/djangoapps/course_home_api/tests/test_utils.py +++ b/lms/djangoapps/course_home_api/tests/test_utils.py @@ -1,9 +1,10 @@ """ Tests for course home api utils """ from contextlib import contextmanager -from rest_framework.exceptions import PermissionDenied from unittest import mock +from rest_framework.exceptions import PermissionDenied + from lms.djangoapps.course_home_api.utils import get_course_or_403 from lms.djangoapps.courseware.access_response import AccessError from lms.djangoapps.courseware.exceptions import CourseAccessRedirect diff --git a/lms/djangoapps/course_home_api/tests/utils.py b/lms/djangoapps/course_home_api/tests/utils.py index 94e63b49cf33..e2e285d1e3ee 100644 --- a/lms/djangoapps/course_home_api/tests/utils.py +++ b/lms/djangoapps/course_home_api/tests/utils.py @@ -4,9 +4,6 @@ from datetime import datetime -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory - from cms.djangoapps.contentstore.outlines import update_outline_from_modulestore from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory @@ -14,6 +11,8 @@ from lms.djangoapps.verify_student.models import VerificationDeadline from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangolib.testing.utils import skip_unless_lms +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory @skip_unless_lms diff --git a/lms/djangoapps/course_wiki/middleware.py b/lms/djangoapps/course_wiki/middleware.py index 37bef0b74740..9413d02f7f11 100644 --- a/lms/djangoapps/course_wiki/middleware.py +++ b/lms/djangoapps/course_wiki/middleware.py @@ -2,6 +2,7 @@ from urllib.parse import urlparse + from django.conf import settings from django.core.exceptions import PermissionDenied from django.http import Http404 @@ -9,12 +10,11 @@ from django.utils.deprecation import MiddlewareMixin from wiki.models import reverse +from common.djangoapps.student.models import CourseEnrollment from lms.djangoapps.courseware.access import has_access from lms.djangoapps.courseware.courses import get_course_overview_with_access, get_course_with_access from openedx.core.lib.request_utils import course_id_from_url from openedx.features.enterprise_support.api import get_enterprise_consent_url -from common.djangoapps.student.models import CourseEnrollment - from xmodule.modulestore.django import modulestore diff --git a/lms/djangoapps/course_wiki/plugins/course_app.py b/lms/djangoapps/course_wiki/plugins/course_app.py index 1d007c386f9a..10dd97a6b771 100644 --- a/lms/djangoapps/course_wiki/plugins/course_app.py +++ b/lms/djangoapps/course_wiki/plugins/course_app.py @@ -1,5 +1,5 @@ """Module with the course app configuration for the Wiki.""" -from typing import Dict, Optional, TYPE_CHECKING +from typing import TYPE_CHECKING, Dict, Optional from django.conf import settings from django.utils.translation import gettext_noop as _ diff --git a/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_video.py b/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_video.py index a55529355708..fd3dd9ef911c 100755 --- a/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_video.py +++ b/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_video.py @@ -131,7 +131,6 @@ import markdown - version = "0.1.6" diff --git a/lms/djangoapps/course_wiki/tests/test_access.py b/lms/djangoapps/course_wiki/tests/test_access.py index daf51c7c0054..cc6e5dd42b00 100644 --- a/lms/djangoapps/course_wiki/tests/test_access.py +++ b/lms/djangoapps/course_wiki/tests/test_access.py @@ -5,15 +5,13 @@ from django.contrib.auth.models import Group from wiki.models import URLPath -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory -from common.djangoapps.student.tests.factories import InstructorFactory -from common.djangoapps.student.tests.factories import StaffFactory +from common.djangoapps.student.tests.factories import InstructorFactory, StaffFactory, UserFactory from lms.djangoapps.course_wiki import settings from lms.djangoapps.course_wiki.utils import course_wiki_slug, user_is_article_course_staff from lms.djangoapps.course_wiki.views import get_or_create_root -from common.djangoapps.student.tests.factories import UserFactory +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, 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 6325c0231a89..409d11dfcaf0 100644 --- a/lms/djangoapps/course_wiki/tests/test_comprehensive_theming.py +++ b/lms/djangoapps/course_wiki/tests/test_comprehensive_theming.py @@ -11,7 +11,9 @@ from common.djangoapps.student.tests.factories import InstructorFactory from lms.djangoapps.course_wiki.views import get_or_create_root from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/course_wiki/tests/test_middleware.py b/lms/djangoapps/course_wiki/tests/test_middleware.py index 264a24f5a297..6ca8a045046a 100644 --- a/lms/djangoapps/course_wiki/tests/test_middleware.py +++ b/lms/djangoapps/course_wiki/tests/test_middleware.py @@ -5,11 +5,11 @@ from django.test.client import Client from wiki.models import URLPath -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student.tests.factories import InstructorFactory from lms.djangoapps.course_wiki.views import get_or_create_root +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class TestWikiAccessMiddleware(ModuleStoreTestCase): diff --git a/lms/djangoapps/course_wiki/tests/test_tab.py b/lms/djangoapps/course_wiki/tests/test_tab.py index 856f973fa354..ec6dc5f0fd0a 100644 --- a/lms/djangoapps/course_wiki/tests/test_tab.py +++ b/lms/djangoapps/course_wiki/tests/test_tab.py @@ -7,7 +7,9 @@ from common.djangoapps.student.tests.factories import AdminFactory, UserFactory from lms.djangoapps.courseware.tabs import get_course_tab_list -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/course_wiki/tests/tests.py b/lms/djangoapps/course_wiki/tests/tests.py index 7821f659d983..144e0636fd6e 100644 --- a/lms/djangoapps/course_wiki/tests/tests.py +++ b/lms/djangoapps/course_wiki/tests/tests.py @@ -4,12 +4,15 @@ from unittest.mock import patch + from django.urls import reverse from lms.djangoapps.courseware.tests.tests import LoginEnrollmentTestCase from openedx.features.course_experience.url_helpers import make_learning_mfe_courseware_url from openedx.features.enterprise_support.tests.mixins.enterprise import EnterpriseTestConsentRequired -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/courseware/access.py b/lms/djangoapps/courseware/access.py index 4863281d1c73..5b5d173d7917 100644 --- a/lms/djangoapps/courseware/access.py +++ b/lms/djangoapps/courseware/access.py @@ -20,6 +20,29 @@ from opaque_keys.edx.keys import CourseKey, UsageKey from xblock.core import XBlock +from common.djangoapps.student import auth +from common.djangoapps.student.models import CourseEnrollmentAllowed +from common.djangoapps.student.roles import ( + CourseBetaTesterRole, + CourseCcxCoachRole, + CourseInstructorRole, + CourseLimitedStaffRole, + CourseStaffRole, + GlobalStaff, + OrgInstructorRole, + OrgStaffRole, + SupportStaffRole, +) +from common.djangoapps.util import ( # lint-amnesty, pylint: disable=useless-import-alias + milestones_helpers as milestones_helpers, +) +from common.djangoapps.util.milestones_helpers import ( + any_unfulfilled_milestones, + get_pre_requisite_courses_not_completed, + is_prerequisite_courses_enabled, +) +from lms.djangoapps.ccx.custom_exception import CCXLocatorValidationException +from lms.djangoapps.ccx.models import CustomCourseForEdX from lms.djangoapps.courseware.access_response import ( CatalogVisibilityError, IncorrectPartitionGroupError, @@ -27,7 +50,7 @@ MobileAvailabilityError, NoAllowedPartitionGroupsError, OldMongoAccessError, - VisibilityError + VisibilityError, ) from lms.djangoapps.courseware.access_utils import ( ACCESS_DENIED, @@ -37,34 +60,20 @@ debug, ) from lms.djangoapps.courseware.masquerade import get_masquerade_role, is_masquerading_as_student -from lms.djangoapps.ccx.custom_exception import CCXLocatorValidationException -from lms.djangoapps.ccx.models import CustomCourseForEdX -from lms.djangoapps.mobile_api.models import IgnoreMobileAvailableFlagConfig from lms.djangoapps.courseware.toggles import course_is_invitation_only +from lms.djangoapps.mobile_api.models import IgnoreMobileAvailableFlagConfig from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.features.course_duration_limits.access import check_course_expired -from common.djangoapps.student import auth -from common.djangoapps.student.models import CourseEnrollmentAllowed -from common.djangoapps.student.roles import ( - CourseBetaTesterRole, - CourseCcxCoachRole, - CourseInstructorRole, - CourseStaffRole, - GlobalStaff, - OrgInstructorRole, - OrgStaffRole, - SupportStaffRole, - CourseLimitedStaffRole, +from xmodule.course_block import ( # lint-amnesty, pylint: disable=wrong-import-order + CATALOG_VISIBILITY_ABOUT, + CATALOG_VISIBILITY_CATALOG_AND_ABOUT, + CourseBlock, ) -from common.djangoapps.util import milestones_helpers as milestones_helpers # lint-amnesty, pylint: disable=useless-import-alias -from common.djangoapps.util.milestones_helpers import ( - any_unfulfilled_milestones, - get_pre_requisite_courses_not_completed, - is_prerequisite_courses_enabled -) -from xmodule.course_block import CATALOG_VISIBILITY_ABOUT, CATALOG_VISIBILITY_CATALOG_AND_ABOUT, CourseBlock # lint-amnesty, pylint: disable=wrong-import-order from xmodule.error_block import ErrorBlock # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions import NoSuchUserPartitionError, NoSuchUserPartitionGroupError # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.partitions.partitions import ( # lint-amnesty, pylint: disable=wrong-import-order + NoSuchUserPartitionError, + NoSuchUserPartitionGroupError, +) log = logging.getLogger(__name__) diff --git a/lms/djangoapps/courseware/admin.py b/lms/djangoapps/courseware/admin.py index 573286ccc202..e63585f1fd0e 100644 --- a/lms/djangoapps/courseware/admin.py +++ b/lms/djangoapps/courseware/admin.py @@ -8,7 +8,6 @@ from lms.djangoapps.courseware import models - admin.site.register(models.FinancialAssistanceConfiguration, ConfigurationModelAdmin) admin.site.register(models.DynamicUpgradeDeadlineConfiguration, ConfigurationModelAdmin) admin.site.register(models.OfflineComputedGrade) diff --git a/lms/djangoapps/courseware/block_render.py b/lms/djangoapps/courseware/block_render.py index 6a814fb3ef3c..c9a5349da129 100644 --- a/lms/djangoapps/courseware/block_render.py +++ b/lms/djangoapps/courseware/block_render.py @@ -3,12 +3,13 @@ """ from __future__ import annotations + import json import logging import textwrap from collections import OrderedDict - from functools import partial +from typing import TYPE_CHECKING, Callable from completion.services import CompletionService from django.conf import settings @@ -34,78 +35,77 @@ from opaque_keys.edx.keys import CourseKey, UsageKey from rest_framework.decorators import api_view from rest_framework.exceptions import APIException -from typing import Callable, TYPE_CHECKING from web_fragments.fragment import Fragment from xblock.django.request import django_to_webob_request, webob_to_django_response from xblock.exceptions import NoSuchHandlerError, NoSuchViewError, NotFoundError, ProcessingError from xblock.reference.plugins import FSService from xblock.runtime import KvsFieldData - -from lms.djangoapps.teams.services import TeamsService -from openedx.core.djangoapps.video_config.services import VideoConfigService -from openedx.core.djangoapps.discussions.services import DiscussionConfigService -from openedx.core.lib.xblock_services.call_to_action import CallToActionService -from xmodule.contentstore.django import contentstore from xblocks_contrib.video.exceptions import TranscriptNotFoundError -from xmodule.exceptions import NotFoundError as XModuleNotFoundError -from xmodule.library_tools import LegacyLibraryToolsService -from xmodule.modulestore.django import XBlockI18nService, modulestore -from xmodule.modulestore.exceptions import ItemNotFoundError -from xmodule.partitions.partitions_service import PartitionService -from xmodule.util.sandboxing import SandboxService -from xmodule.services import ( - EventPublishingService, - RebindUserService, - SettingsService, - TeamsConfigurationService, - XQueueService -) + +from common.djangoapps.edxmako.services import MakoService from common.djangoapps.static_replace.services import ReplaceURLService from common.djangoapps.static_replace.wrapper import replace_urls_wrapper +from common.djangoapps.student.models import anonymous_id_for_user +from common.djangoapps.student.roles import CourseBetaTesterRole +from common.djangoapps.util import milestones_helpers +from common.djangoapps.util.json_request import JsonResponse +from common.djangoapps.xblock_django.user_service import DjangoXBlockUserService from lms.djangoapps.courseware.access import get_user_role, has_access from lms.djangoapps.courseware.entrance_exams import user_can_skip_entrance_exam, user_has_passed_entrance_exam +from lms.djangoapps.courseware.field_overrides import OverrideFieldData from lms.djangoapps.courseware.masquerade import ( MasqueradingKeyValueStore, filter_displayed_blocks, is_masquerading_as_specific_student, - setup_masquerade + setup_masquerade, ) from lms.djangoapps.courseware.model_data import DjangoKeyValueStore, FieldDataCache -from lms.djangoapps.courseware.field_overrides import OverrideFieldData from lms.djangoapps.courseware.services import UserStateService from lms.djangoapps.grades.api import GradesUtilService from lms.djangoapps.lms_xblock.field_data import LmsFieldData -from lms.djangoapps.lms_xblock.runtime import UserTagsService, lms_wrappers_aside, lms_applicable_aside_types +from lms.djangoapps.lms_xblock.runtime import UserTagsService, lms_applicable_aside_types, lms_wrappers_aside +from lms.djangoapps.teams.services import TeamsService from lms.djangoapps.verify_student.services import XBlockVerificationService from openedx.core.djangoapps.bookmarks.api import BookmarksService from openedx.core.djangoapps.crawlers.models import CrawlersConfig from openedx.core.djangoapps.credit.services import CreditService +from openedx.core.djangoapps.discussions.services import DiscussionConfigService from openedx.core.djangoapps.enrollments.services import EnrollmentsService from openedx.core.djangoapps.util.user_utils import SystemUser +from openedx.core.djangoapps.video_config.services import VideoConfigService from openedx.core.djangolib.markup import HTML from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser from openedx.core.lib.api.view_utils import view_auth_classes +from openedx.core.lib.cache_utils import CacheService from openedx.core.lib.gating.services import GatingService from openedx.core.lib.license import wrap_with_license from openedx.core.lib.url_utils import quote_slashes, unquote_slashes +from openedx.core.lib.xblock_services.call_to_action import CallToActionService from openedx.core.lib.xblock_utils import ( add_staff_markup, get_aside_from_xblock, hash_resource, - is_xblock_aside + is_xblock_aside, + wrap_xblock, ) from openedx.core.lib.xblock_utils import request_token as xblock_request_token -from openedx.core.lib.xblock_utils import wrap_xblock +from openedx.features.content_type_gating.services import ContentTypeGatingService from openedx.features.course_duration_limits.access import course_expiration_wrapper from openedx.features.discounts.utils import offer_banner_wrapper -from openedx.features.content_type_gating.services import ContentTypeGatingService -from common.djangoapps.student.models import anonymous_id_for_user -from common.djangoapps.student.roles import CourseBetaTesterRole -from common.djangoapps.util import milestones_helpers -from common.djangoapps.util.json_request import JsonResponse -from common.djangoapps.edxmako.services import MakoService -from common.djangoapps.xblock_django.user_service import DjangoXBlockUserService -from openedx.core.lib.cache_utils import CacheService +from xmodule.contentstore.django import contentstore +from xmodule.exceptions import NotFoundError as XModuleNotFoundError +from xmodule.library_tools import LegacyLibraryToolsService +from xmodule.modulestore.django import XBlockI18nService, modulestore +from xmodule.modulestore.exceptions import ItemNotFoundError +from xmodule.partitions.partitions_service import PartitionService +from xmodule.services import ( + EventPublishingService, + RebindUserService, + SettingsService, + TeamsConfigurationService, + XQueueService, +) +from xmodule.util.sandboxing import SandboxService if TYPE_CHECKING: from rest_framework.request import Request diff --git a/lms/djangoapps/courseware/context_processor.py b/lms/djangoapps/courseware/context_processor.py index 2832c577ca46..b8e6a870f270 100644 --- a/lms/djangoapps/courseware/context_processor.py +++ b/lms/djangoapps/courseware/context_processor.py @@ -8,17 +8,16 @@ import string from django.utils.translation import get_language +from edx_django_utils.cache import TieredCache from pytz import timezone from pytz.exceptions import UnknownTimeZoneError -from edx_django_utils.cache import TieredCache from lms.djangoapps.courseware.models import LastSeenCoursewareTimezone from openedx.core.djangoapps.site_configuration.helpers import get_value from openedx.core.djangoapps.user_api.errors import UserAPIInternalError, UserNotFound from openedx.core.djangoapps.user_api.preferences.api import get_user_preference, get_user_preferences from openedx.core.lib.cache_utils import get_cache - RETRIEVABLE_PREFERENCES = { 'user_timezone': 'time_zone', 'user_language': 'pref-lang' diff --git a/lms/djangoapps/courseware/courses.py b/lms/djangoapps/courseware/courses.py index 9195fc8c82e2..111f78d76b59 100644 --- a/lms/djangoapps/courseware/courses.py +++ b/lms/djangoapps/courseware/courses.py @@ -8,8 +8,8 @@ from collections import defaultdict, namedtuple from datetime import datetime -import six import pytz +import six from crum import get_current_request from dateutil.parser import parse as parse_date from django.conf import settings @@ -36,8 +36,14 @@ OldMongoAccessError, StartDateError, ) -from lms.djangoapps.courseware.access_utils import check_authentication, check_data_sharing_consent, check_enrollment, \ - check_correct_active_enterprise_customer, is_priority_access_error +from lms.djangoapps.courseware.access_utils import ( + check_authentication, + check_correct_active_enterprise_customer, + check_data_sharing_consent, + check_enrollment, + is_priority_access_error, +) +from lms.djangoapps.courseware.block_render import get_block from lms.djangoapps.courseware.context_processor import get_user_timezone_or_last_seen_timezone_or_utc from lms.djangoapps.courseware.courseware_access_exception import CoursewareAccessException from lms.djangoapps.courseware.date_summary import ( @@ -48,12 +54,11 @@ CourseStartDate, TodaysDate, VerificationDeadlineDate, - VerifiedUpgradeDeadlineDate + VerifiedUpgradeDeadlineDate, ) from lms.djangoapps.courseware.exceptions import CourseAccessRedirect, CourseRunNotFound from lms.djangoapps.courseware.masquerade import check_content_start_date_for_masquerade_user from lms.djangoapps.courseware.model_data import FieldDataCache -from lms.djangoapps.courseware.block_render import get_block from lms.djangoapps.courseware.utils import is_empty_html from lms.djangoapps.grades.api import CourseGradeFactory from lms.djangoapps.survey.utils import SurveyRequiredAccessError, check_survey_required_and_unanswered diff --git a/lms/djangoapps/courseware/date_summary.py b/lms/djangoapps/courseware/date_summary.py index e6bd5ef70597..83d848108c5d 100644 --- a/lms/djangoapps/courseware/date_summary.py +++ b/lms/djangoapps/courseware/date_summary.py @@ -11,21 +11,20 @@ from babel.dates import format_timedelta from django.conf import settings from django.utils.functional import cached_property -from django.utils.translation import get_language, to_locale +from django.utils.translation import get_language, gettext_lazy, to_locale from django.utils.translation import gettext as _ -from django.utils.translation import gettext_lazy from lazy import lazy from pytz import utc from common.djangoapps.course_modes.models import CourseMode -from lms.djangoapps.certificates.api import get_active_web_certificate, can_show_certificate_available_date_field -from lms.djangoapps.courseware.utils import verified_upgrade_deadline_link, can_show_verified_upgrade +from common.djangoapps.student.models import CourseEnrollment +from lms.djangoapps.certificates.api import can_show_certificate_available_date_field, get_active_web_certificate +from lms.djangoapps.courseware.utils import can_show_verified_upgrade, verified_upgrade_deadline_link from lms.djangoapps.verify_student.models import VerificationDeadline from lms.djangoapps.verify_student.services import IDVerificationService from openedx.core.djangolib.markup import HTML from openedx.features.course_duration_limits.access import get_user_course_expiration_date from openedx.features.course_experience import RELATIVE_DATES_FLAG -from common.djangoapps.student.models import CourseEnrollment from .context_processor import user_timezone_locale_prefs diff --git a/lms/djangoapps/courseware/entrance_exams.py b/lms/djangoapps/courseware/entrance_exams.py index 519174994b10..3fd283f349e2 100644 --- a/lms/djangoapps/courseware/entrance_exams.py +++ b/lms/djangoapps/courseware/entrance_exams.py @@ -5,9 +5,9 @@ from opaque_keys.edx.keys import UsageKey -from lms.djangoapps.courseware.access import has_access from common.djangoapps.student.models import EntranceExamConfiguration from common.djangoapps.util.milestones_helpers import get_required_content +from lms.djangoapps.courseware.access import has_access from openedx.core.toggles import ENTRANCE_EXAMS from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/courseware/management/commands/dump_course_ids_with_filter.py b/lms/djangoapps/courseware/management/commands/dump_course_ids_with_filter.py index c4ed14f4314b..ce4f08548bd4 100644 --- a/lms/djangoapps/courseware/management/commands/dump_course_ids_with_filter.py +++ b/lms/djangoapps/courseware/management/commands/dump_course_ids_with_filter.py @@ -7,11 +7,11 @@ """ import datetime - from textwrap import dedent from django.core.management.base import BaseCommand from django.db.models import Q + from openedx.core.djangoapps.content.course_overviews.models import CourseOverview 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 97a20deac993..6797a52120ba 100644 --- a/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py +++ b/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py @@ -13,11 +13,8 @@ from xmodule.modulestore import ModuleStoreEnum 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, BlockFactory +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory from xmodule.modulestore.xml_importer import import_course_from_xml DATA_DIR = settings.COMMON_TEST_DATA_ROOT diff --git a/lms/djangoapps/courseware/masquerade.py b/lms/djangoapps/courseware/masquerade.py index 5ce266c463d6..b2f709bf2cad 100644 --- a/lms/djangoapps/courseware/masquerade.py +++ b/lms/djangoapps/courseware/masquerade.py @@ -20,18 +20,20 @@ from xblock.runtime import KeyValueStore from common.djangoapps.course_modes.models import CourseMode -from openedx.core.djangoapps.util.user_messages import PageLevelMessages -from openedx.core.djangolib.markup import HTML -from openedx.features.content_type_gating.helpers import CONTENT_GATING_PARTITION_ID -from openedx.features.content_type_gating.helpers import FULL_ACCESS -from openedx.features.content_type_gating.helpers import LIMITED_ACCESS from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.role_helpers import has_staff_roles from common.djangoapps.util.json_request import JsonResponse, expect_json +from openedx.core.djangoapps.util.user_messages import PageLevelMessages +from openedx.core.djangolib.markup import HTML +from openedx.features.content_type_gating.helpers import CONTENT_GATING_PARTITION_ID, FULL_ACCESS, LIMITED_ACCESS from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions import NoSuchUserPartitionGroupError # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions_service import get_all_partitions_for_course # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.partitions.partitions import ( + ENROLLMENT_TRACK_PARTITION_ID, # lint-amnesty, pylint: disable=wrong-import-order + NoSuchUserPartitionGroupError, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.partitions.partitions_service import ( + get_all_partitions_for_course, # lint-amnesty, pylint: disable=wrong-import-order +) log = logging.getLogger(__name__) diff --git a/lms/djangoapps/courseware/migrations/0008_move_idde_to_edx_when.py b/lms/djangoapps/courseware/migrations/0008_move_idde_to_edx_when.py index d0b9ea52b56e..ea037779bb85 100644 --- a/lms/djangoapps/courseware/migrations/0008_move_idde_to_edx_when.py +++ b/lms/djangoapps/courseware/migrations/0008_move_idde_to_edx_when.py @@ -8,8 +8,8 @@ def move_overrides_to_edx_when(apps, schema_editor): - from xblock.fields import Date from edx_when import api + from xblock.fields import Date date_field = Date() StudentFieldOverride = apps.get_model('courseware', 'StudentFieldOverride') log = logging.getLogger(__name__) diff --git a/lms/djangoapps/courseware/migrations/0009_auto_20190703_1955.py b/lms/djangoapps/courseware/migrations/0009_auto_20190703_1955.py index ad10ef354424..7e3d781bad5e 100644 --- a/lms/djangoapps/courseware/migrations/0009_auto_20190703_1955.py +++ b/lms/djangoapps/courseware/migrations/0009_auto_20190703_1955.py @@ -1,8 +1,8 @@ # Generated by Django 1.11.22 on 2019-07-03 19:55 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/courseware/migrations/0010_auto_20190709_1559.py b/lms/djangoapps/courseware/migrations/0010_auto_20190709_1559.py index 477ef7dd6434..c9bf5df5e7c9 100644 --- a/lms/djangoapps/courseware/migrations/0010_auto_20190709_1559.py +++ b/lms/djangoapps/courseware/migrations/0010_auto_20190709_1559.py @@ -1,9 +1,9 @@ # Generated by Django 1.11.22 on 2019-07-09 15:59 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/lms/djangoapps/courseware/migrations/0011_csm_id_bigint.py b/lms/djangoapps/courseware/migrations/0011_csm_id_bigint.py index 55e3d845b6a8..1d6482bd4e51 100644 --- a/lms/djangoapps/courseware/migrations/0011_csm_id_bigint.py +++ b/lms/djangoapps/courseware/migrations/0011_csm_id_bigint.py @@ -1,11 +1,12 @@ # Generated by Django 1.11.23 on 2019-08-28 15:50 -import lms.djangoapps.courseware.fields - from django.conf import settings from django.db import migrations, models from django.db.migrations import AlterField +import lms.djangoapps.courseware.fields + + class CsmBigInt(AlterField): ''' Subclass AlterField migration class to split SQL between two different databases diff --git a/lms/djangoapps/courseware/migrations/0012_adjust_fields.py b/lms/djangoapps/courseware/migrations/0012_adjust_fields.py index 9abefa6f5c2f..3304ce147d9b 100644 --- a/lms/djangoapps/courseware/migrations/0012_adjust_fields.py +++ b/lms/djangoapps/courseware/migrations/0012_adjust_fields.py @@ -5,9 +5,9 @@ # ./manage.py lms sqlmigrate courseware 0012_adjust_fields +import opaque_keys.edx.django.models from django.conf import settings from django.db import migrations, models -import opaque_keys.edx.django.models class Migration(migrations.Migration): diff --git a/lms/djangoapps/courseware/migrations/0016_lastseencoursewaretimezone.py b/lms/djangoapps/courseware/migrations/0016_lastseencoursewaretimezone.py index 6532207dd6fb..cd366ae0ac9b 100644 --- a/lms/djangoapps/courseware/migrations/0016_lastseencoursewaretimezone.py +++ b/lms/djangoapps/courseware/migrations/0016_lastseencoursewaretimezone.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.24 on 2021-10-06 17:01 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/lms/djangoapps/courseware/migrations/0017_financialassistanceconfiguration.py b/lms/djangoapps/courseware/migrations/0017_financialassistanceconfiguration.py index 857258f5b9f2..cb05599480e1 100644 --- a/lms/djangoapps/courseware/migrations/0017_financialassistanceconfiguration.py +++ b/lms/djangoapps/courseware/migrations/0017_financialassistanceconfiguration.py @@ -1,8 +1,8 @@ # Generated by Django 3.2.12 on 2022-04-11 19:36 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/lms/djangoapps/courseware/models.py b/lms/djangoapps/courseware/models.py index 500629945141..4fc9474e6039 100644 --- a/lms/djangoapps/courseware/models.py +++ b/lms/djangoapps/courseware/models.py @@ -18,18 +18,17 @@ import logging from config_models.models import ConfigurationModel -from django.contrib.auth import get_user_model from django.conf import settings +from django.contrib.auth import get_user_model from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.db import models from django.db.models.signals import post_save - from django.utils.translation import gettext_lazy as _ from edx_django_utils.cache.utils import RequestCache from model_utils.models import TimeStampedModel from opaque_keys.edx.django.models import BlockTypeKeyField, CourseKeyField, LearningContextKeyField, UsageKeyField -from lms.djangoapps.courseware.fields import UnsignedBigIntAutoField +from lms.djangoapps.courseware.fields import UnsignedBigIntAutoField from openedx.core.djangolib.markup import HTML log = logging.getLogger("edx.courseware") diff --git a/lms/djangoapps/courseware/permissions.py b/lms/djangoapps/courseware/permissions.py index e96644b2a53e..987d525b7546 100644 --- a/lms/djangoapps/courseware/permissions.py +++ b/lms/djangoapps/courseware/permissions.py @@ -3,6 +3,7 @@ """ from bridgekeeper import perms + from .rules import HasAccessRule, HasStaffAccessToContent EDIT_BOOKMARK = 'courseware.edit_bookmark' diff --git a/lms/djangoapps/courseware/plugins.py b/lms/djangoapps/courseware/plugins.py index f890512d2a48..27af557e04b8 100644 --- a/lms/djangoapps/courseware/plugins.py +++ b/lms/djangoapps/courseware/plugins.py @@ -7,13 +7,11 @@ from django.utils.translation import gettext_noop as _ from opaque_keys.edx.keys import CourseKey -from xmodule.modulestore.django import modulestore -from xmodule.tabs import CourseTabList - from openedx.core.djangoapps.content.course_overviews.models import CourseOverview, CourseTab - from openedx.core.djangoapps.course_apps.plugins import CourseApp from openedx.core.lib.courses import get_course_by_id +from xmodule.modulestore.django import modulestore +from xmodule.tabs import CourseTabList User = get_user_model() diff --git a/lms/djangoapps/courseware/rules.py b/lms/djangoapps/courseware/rules.py index 07cbbab9022c..c213a5e5976a 100644 --- a/lms/djangoapps/courseware/rules.py +++ b/lms/djangoapps/courseware/rules.py @@ -15,14 +15,13 @@ from opaque_keys.edx.keys import CourseKey, UsageKey from xblock.core import XBlock -from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from openedx.core.djangoapps.enrollments.api import is_enrollment_valid_for_proctoring from common.djangoapps.student.models import CourseAccessRole from common.djangoapps.student.roles import CourseRole, OrgRole, strict_role_checking +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview +from openedx.core.djangoapps.enrollments.api import is_enrollment_valid_for_proctoring from xmodule.course_block import CourseBlock # lint-amnesty, pylint: disable=wrong-import-order from xmodule.error_block import ErrorBlock # lint-amnesty, pylint: disable=wrong-import-order - from .access import has_access LOG = logging.getLogger(__name__) diff --git a/lms/djangoapps/courseware/services.py b/lms/djangoapps/courseware/services.py index 3fa31a3e00fc..2cf38c7398fd 100644 --- a/lms/djangoapps/courseware/services.py +++ b/lms/djangoapps/courseware/services.py @@ -7,8 +7,8 @@ from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user -from lms.djangoapps.courseware.models import StudentModule from common.djangoapps.student.models import get_user_by_username_or_email +from lms.djangoapps.courseware.models import StudentModule class UserStateService: diff --git a/lms/djangoapps/courseware/tabs.py b/lms/djangoapps/courseware/tabs.py index 56c1ca2e0e44..2af8f148fadc 100644 --- a/lms/djangoapps/courseware/tabs.py +++ b/lms/djangoapps/courseware/tabs.py @@ -7,15 +7,15 @@ from django.conf import settings from django.utils.translation import gettext as _ from django.utils.translation import gettext_noop -from xmodule.tabs import CourseTab, CourseTabList, key_checker +from common.djangoapps.student.models import CourseEnrollment +from lms.djangoapps.course_home_api.toggles import course_home_mfe_progress_tab_is_active from lms.djangoapps.courseware.access import has_access from lms.djangoapps.courseware.entrance_exams import user_can_skip_entrance_exam -from lms.djangoapps.course_home_api.toggles import course_home_mfe_progress_tab_is_active from openedx.core.lib.course_tabs import CourseTabPluginManager from openedx.features.course_experience import default_course_url from openedx.features.course_experience.url_helpers import get_learning_mfe_home_url -from common.djangoapps.student.models import CourseEnrollment +from xmodule.tabs import CourseTab, CourseTabList, key_checker class EnrolledTab(CourseTab): diff --git a/lms/djangoapps/courseware/tests/factories.py b/lms/djangoapps/courseware/tests/factories.py index a7343528df61..4fe8739ca28c 100644 --- a/lms/djangoapps/courseware/tests/factories.py +++ b/lms/djangoapps/courseware/tests/factories.py @@ -14,11 +14,11 @@ from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.courseware.models import ( + FinancialAssistanceConfiguration, StudentModule, XModuleStudentInfoField, XModuleStudentPrefsField, XModuleUserStateSummaryField, - FinancialAssistanceConfiguration ) COURSE_KEY = CourseKey.from_string('edX/test_course/test') diff --git a/lms/djangoapps/courseware/tests/helpers.py b/lms/djangoapps/courseware/tests/helpers.py index 4e325690cccd..6d7cb6e53a6c 100644 --- a/lms/djangoapps/courseware/tests/helpers.py +++ b/lms/djangoapps/courseware/tests/helpers.py @@ -17,20 +17,29 @@ from xblock.field_data import DictFieldData from common.djangoapps.edxmako.shortcuts import render_to_string +from common.djangoapps.student.models import CourseEnrollment, Registration +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory +from common.djangoapps.util.date_utils import strftime_localized_html from lms.djangoapps.courseware.access import has_access +from lms.djangoapps.courseware.masquerade import MasqueradeView, setup_masquerade from lms.djangoapps.courseware.utils import verified_upgrade_deadline_link -from lms.djangoapps.courseware.masquerade import MasqueradeView -from lms.djangoapps.courseware.masquerade import setup_masquerade from lms.djangoapps.lms_xblock.field_data import LmsFieldData from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.lib.url_utils import quote_slashes -from common.djangoapps.student.models import CourseEnrollment, Registration -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory -from common.djangoapps.util.date_utils import strftime_localized_html from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.tests import get_test_descriptor_system, get_test_system, prepare_block_runtime # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order + TEST_DATA_SPLIT_MODULESTORE, + ModuleStoreTestCase, +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) +from xmodule.tests import ( # lint-amnesty, pylint: disable=wrong-import-order + get_test_descriptor_system, + get_test_system, + prepare_block_runtime, +) class BaseTestXmodule(ModuleStoreTestCase): diff --git a/lms/djangoapps/courseware/tests/pacts/views.py b/lms/djangoapps/courseware/tests/pacts/views.py index 11ae2d07f7d9..39ec1fd5ad62 100644 --- a/lms/djangoapps/courseware/tests/pacts/views.py +++ b/lms/djangoapps/courseware/tests/pacts/views.py @@ -7,8 +7,9 @@ from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST from opaque_keys.edx.keys import CourseKey + from xmodule.modulestore.tests.django_utils import ModuleStoreIsolationMixin -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory class ProviderState(ModuleStoreIsolationMixin): diff --git a/lms/djangoapps/courseware/tests/test_about.py b/lms/djangoapps/courseware/tests/test_about.py index 22ec3d49bd2a..067318d797ce 100644 --- a/lms/djangoapps/courseware/tests/test_about.py +++ b/lms/djangoapps/courseware/tests/test_about.py @@ -14,6 +14,14 @@ from django.urls import reverse from edx_toggles.toggles.testutils import override_waffle_flag, override_waffle_switch from milestones.tests.utils import MilestonesTestCaseMixin + +from common.djangoapps.course_modes.models import CourseMode +from common.djangoapps.student.tests.factories import CourseEnrollmentAllowedFactory, UserFactory +from common.djangoapps.track.tests import EventTrackingTestCase +from common.djangoapps.util.milestones_helpers import get_prerequisite_courses_display, set_prerequisite_courses +from openedx.core.djangoapps.models.course_details import CourseDetails +from openedx.features.course_experience import COURSE_ENABLE_UNENROLLED_ACCESS_FLAG, course_home_url +from openedx.features.course_experience.waffle import ENABLE_COURSE_ABOUT_SIDEBAR_HTML from xmodule.course_block import ( CATALOG_VISIBILITY_ABOUT, CATALOG_VISIBILITY_NONE, @@ -22,18 +30,10 @@ COURSE_VISIBILITY_PUBLIC_OUTLINE, ) from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory from xmodule.modulestore.tests.utils import TEST_DATA_DIR from xmodule.modulestore.xml_importer import import_course_from_xml -from common.djangoapps.course_modes.models import CourseMode -from common.djangoapps.student.tests.factories import CourseEnrollmentAllowedFactory, UserFactory -from common.djangoapps.track.tests import EventTrackingTestCase -from common.djangoapps.util.milestones_helpers import get_prerequisite_courses_display, set_prerequisite_courses -from openedx.core.djangoapps.models.course_details import CourseDetails -from openedx.features.course_experience import COURSE_ENABLE_UNENROLLED_ACCESS_FLAG, course_home_url -from openedx.features.course_experience.waffle import ENABLE_COURSE_ABOUT_SIDEBAR_HTML - 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 404794e89857..53fe8dd7a8e4 100644 --- a/lms/djangoapps/courseware/tests/test_access.py +++ b/lms/djangoapps/courseware/tests/test_access.py @@ -5,13 +5,13 @@ import datetime import itertools - from unittest.mock import Mock, patch -from openedx.core.djangolib.testing.utils import AUTHZ_TABLES -import pytest + import ddt +import pytest import pytz from ccx_keys.locator import CCXLocator +from crum import set_current_request from django.conf import settings from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.test import TestCase @@ -19,57 +19,63 @@ from django.test.utils import override_settings from django.urls import reverse from edx_toggles.toggles.testutils import override_waffle_flag +from enterprise.api.v1.serializers import EnterpriseCustomerSerializer from milestones.tests.utils import MilestonesTestCaseMixin from opaque_keys.edx.locator import CourseLocator import lms.djangoapps.courseware.access as access import lms.djangoapps.courseware.access_response as access_response +from common.djangoapps.student.models import CourseEnrollment +from common.djangoapps.student.roles import CourseCcxCoachRole, CourseStaffRole +from common.djangoapps.student.tests.factories import ( + AdminFactory, + AnonymousUserFactory, + BetaTesterFactory, + CourseEnrollmentAllowedFactory, + CourseEnrollmentFactory, + GlobalStaffFactory, + InstructorFactory, + StaffFactory, + UserFactory, +) +from common.djangoapps.util.milestones_helpers import fulfill_course_milestone, set_prerequisite_courses +from lms.djangoapps.ccx.models import CustomCourseForEdX from lms.djangoapps.courseware.masquerade import CourseMasquerade from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase, masquerade_as_group_member from lms.djangoapps.courseware.toggles import course_is_invitation_only -from lms.djangoapps.ccx.models import CustomCourseForEdX from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES +from openedx.core.djangolib.testing.utils import AUTHZ_TABLES from openedx.features.content_type_gating.models import ContentTypeGatingConfig from openedx.features.course_experience import ENFORCE_MASQUERADE_START_DATES -from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.roles import CourseCcxCoachRole, CourseStaffRole -from common.djangoapps.student.tests.factories import ( - AdminFactory, - AnonymousUserFactory, - CourseEnrollmentAllowedFactory, - CourseEnrollmentFactory +from openedx.features.enterprise_support.api import add_enterprise_customer_to_session +from openedx.features.enterprise_support.tests.factories import ( + EnterpriseCourseEnrollmentFactory, + EnterpriseCustomerFactory, + EnterpriseCustomerUserFactory, ) -from common.djangoapps.student.tests.factories import BetaTesterFactory -from common.djangoapps.student.tests.factories import GlobalStaffFactory -from common.djangoapps.student.tests.factories import InstructorFactory -from common.djangoapps.student.tests.factories import StaffFactory -from common.djangoapps.student.tests.factories import UserFactory -from common.djangoapps.util.milestones_helpers import fulfill_course_milestone, set_prerequisite_courses from xmodule.course_block import ( # lint-amnesty, pylint: disable=wrong-import-order CATALOG_VISIBILITY_ABOUT, CATALOG_VISIBILITY_CATALOG_AND_ABOUT, - CATALOG_VISIBILITY_NONE + CATALOG_VISIBILITY_NONE, ) - from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order ModuleStoreTestCase, - SharedModuleStoreTestCase + SharedModuleStoreTestCase, ) -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions import MINIMUM_UNUSED_PARTITION_ID, Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order -from openedx.features.enterprise_support.api import add_enterprise_customer_to_session -from enterprise.api.v1.serializers import EnterpriseCustomerSerializer -from openedx.features.enterprise_support.tests.factories import ( - EnterpriseCourseEnrollmentFactory, - EnterpriseCustomerUserFactory, - EnterpriseCustomerFactory +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) +from xmodule.partitions.partitions import ( # lint-amnesty, pylint: disable=wrong-import-order + MINIMUM_UNUSED_PARTITION_ID, + Group, + UserPartition, ) -from crum import set_current_request QUERY_COUNT_TABLE_IGNORELIST = WAFFLE_TABLES + AUTHZ_TABLES diff --git a/lms/djangoapps/courseware/tests/test_block_render.py b/lms/djangoapps/courseware/tests/test_block_render.py index 7fedd97ed7c8..ab784ab4b2f0 100644 --- a/lms/djangoapps/courseware/tests/test_block_render.py +++ b/lms/djangoapps/courseware/tests/test_block_render.py @@ -3,17 +3,17 @@ """ import json import textwrap +import warnings from datetime import datetime from functools import partial from unittest.mock import MagicMock, Mock, patch -import warnings -import pytest import ddt +import pytest import pytz from bson import ObjectId -from completion.waffle import ENABLE_COMPLETION_TRACKING_SWITCH # lint-amnesty, pylint: disable=wrong-import-order from completion.models import BlockCompletion # lint-amnesty, pylint: disable=wrong-import-order +from completion.waffle import ENABLE_COMPLETION_TRACKING_SWITCH # lint-amnesty, pylint: disable=wrong-import-order from django.conf import settings # lint-amnesty, pylint: disable=wrong-import-order from django.contrib.auth.models import AnonymousUser # lint-amnesty, pylint: disable=wrong-import-order from django.http import Http404, HttpResponse # lint-amnesty, pylint: disable=wrong-import-order @@ -21,9 +21,17 @@ from django.test.client import RequestFactory # lint-amnesty, pylint: disable=wrong-import-order from django.test.utils import override_settings # lint-amnesty, pylint: disable=wrong-import-order from django.urls import reverse # lint-amnesty, pylint: disable=wrong-import-order -from edx_proctoring.api import create_exam, create_exam_attempt, update_attempt_status # lint-amnesty, pylint: disable=wrong-import-order +from edx_proctoring.api import ( # lint-amnesty, pylint: disable=wrong-import-order + create_exam, + create_exam_attempt, + update_attempt_status, +) from edx_proctoring.runtime import set_runtime_service # lint-amnesty, pylint: disable=wrong-import-order -from edx_proctoring.tests.test_services import MockCertificateService, MockCreditService, MockGradesService # lint-amnesty, pylint: disable=wrong-import-order +from edx_proctoring.tests.test_services import ( # lint-amnesty, pylint: disable=wrong-import-order + MockCertificateService, + MockCreditService, + MockGradesService, +) from edx_toggles.toggles.testutils import override_waffle_switch # lint-amnesty, pylint: disable=wrong-import-order from edx_when.field_data import DateLookupFieldData # lint-amnesty, pylint: disable=wrong-import-order from freezegun import freeze_time # lint-amnesty, pylint: disable=wrong-import-order @@ -39,26 +47,12 @@ from xblock.fields import ScopeIds # lint-amnesty, pylint: disable=wrong-import-order from xblock.runtime import DictKeyValueStore, KvsFieldData # lint-amnesty, pylint: disable=wrong-import-order from xblock.test.tools import TestRuntime # lint-amnesty, pylint: disable=wrong-import-order - -from xblocks_contrib.problem.capa.tests.response_xml_factory import OptionResponseXMLFactory # lint-amnesty, pylint: disable=reimported -from xmodule.capa_block import ProblemBlock -from xmodule.contentstore.django import contentstore -from xmodule.html_block import AboutBlock, CourseInfoBlock, HtmlBlock, StaticTabBlock -from xmodule.lti_block import LTIBlock -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.django import XBlockI18nService, modulestore -from xmodule.modulestore.tests.django_utils import ( - TEST_DATA_SPLIT_MODULESTORE, - ModuleStoreTestCase, - SharedModuleStoreTestCase, - upload_file_to_course, +from xblocks_contrib.problem.capa.tests.response_xml_factory import ( + OptionResponseXMLFactory, # lint-amnesty, pylint: disable=reimported ) -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory, ToyCourseFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.test_asides import AsideTestType # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.services import RebindUserServiceError -from xmodule.video_block import VideoBlock # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.x_module import STUDENT_VIEW, ModuleStoreRuntime # lint-amnesty, pylint: disable=wrong-import-order + from common.djangoapps.course_modes.models import CourseMode # lint-amnesty, pylint: disable=reimported +from common.djangoapps.student.models import CourseEnrollment, anonymous_id_for_user from common.djangoapps.student.tests.factories import ( BetaTesterFactory, GlobalStaffFactory, @@ -75,18 +69,20 @@ ATTR_KEY_USER_IS_STAFF, ATTR_KEY_USER_ROLE, ) +from common.djangoapps.xblock_django.models import XBlockConfiguration from lms.djangoapps.courseware import block_render as render from lms.djangoapps.courseware.access_response import AccessResponse +from lms.djangoapps.courseware.block_render import get_block_for_descriptor, hash_resource from lms.djangoapps.courseware.courses import get_course_info_section, get_course_with_access from lms.djangoapps.courseware.field_overrides import OverrideFieldData from lms.djangoapps.courseware.masquerade import CourseMasquerade from lms.djangoapps.courseware.model_data import FieldDataCache from lms.djangoapps.courseware.models import StudentModule -from lms.djangoapps.courseware.block_render import get_block_for_descriptor, hash_resource from lms.djangoapps.courseware.tests.factories import StudentModuleFactory from lms.djangoapps.courseware.tests.test_submitting_problems import TestSubmittingProblems from lms.djangoapps.courseware.tests.tests import LoginEnrollmentTestCase from lms.djangoapps.lms_xblock.field_data import LmsFieldData +from lms.djangoapps.verify_student.tests.factories import SoftwareSecurePhotoVerificationFactory 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.djangoapps.oauth_dispatch.jwt import _create_jwt, create_jwt_for_user @@ -94,10 +90,28 @@ 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 common.djangoapps.student.models import CourseEnrollment, anonymous_id_for_user -from lms.djangoapps.verify_student.tests.factories import SoftwareSecurePhotoVerificationFactory -from common.djangoapps.xblock_django.models import XBlockConfiguration - +from xmodule.capa_block import ProblemBlock +from xmodule.contentstore.django import contentstore +from xmodule.html_block import AboutBlock, CourseInfoBlock, HtmlBlock, StaticTabBlock +from xmodule.lti_block import LTIBlock +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import XBlockI18nService, modulestore +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_SPLIT_MODULESTORE, + ModuleStoreTestCase, + SharedModuleStoreTestCase, + upload_file_to_course, +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, + ToyCourseFactory, + check_mongo_calls, +) +from xmodule.modulestore.tests.test_asides import AsideTestType # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.services import RebindUserServiceError +from xmodule.video_block import VideoBlock # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.x_module import STUDENT_VIEW, ModuleStoreRuntime # lint-amnesty, pylint: disable=wrong-import-order TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT diff --git a/lms/djangoapps/courseware/tests/test_comprehensive_theming.py b/lms/djangoapps/courseware/tests/test_comprehensive_theming.py index 0e3bcf6b16f6..da31cab4cf04 100644 --- a/lms/djangoapps/courseware/tests/test_comprehensive_theming.py +++ b/lms/djangoapps/courseware/tests/test_comprehensive_theming.py @@ -7,9 +7,9 @@ from path import Path from common.djangoapps import edxmako -from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme from openedx.core.djangoapps.theming.helpers import get_themes from openedx.core.djangoapps.theming.helpers_dirs import get_theme_dirs +from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme from openedx.core.lib.tempdir import create_symlink, delete_symlink, mkdtemp_clean diff --git a/lms/djangoapps/courseware/tests/test_context_processor.py b/lms/djangoapps/courseware/tests/test_context_processor.py index e1a65d822fe4..c47e4537a0ff 100644 --- a/lms/djangoapps/courseware/tests/test_context_processor.py +++ b/lms/djangoapps/courseware/tests/test_context_processor.py @@ -2,18 +2,21 @@ Unit tests for courseware context_processor """ -from pytz import timezone from unittest.mock import Mock, patch # lint-amnesty, pylint: disable=wrong-import-order + from django.conf import settings from django.contrib.auth.models import AnonymousUser +from pytz import timezone +from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.courseware.context_processor import ( get_user_timezone_or_last_seen_timezone_or_utc, user_timezone_locale_prefs, ) from openedx.core.djangoapps.user_api.preferences.api import set_user_preference -from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/courseware/tests/test_course_survey.py b/lms/djangoapps/courseware/tests/test_course_survey.py index 25dc37724d98..a2b7db5e8d59 100644 --- a/lms/djangoapps/courseware/tests/test_course_survey.py +++ b/lms/djangoapps/courseware/tests/test_course_survey.py @@ -9,14 +9,14 @@ from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.urls import reverse -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from common.test.utils import XssTestMixin from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase from lms.djangoapps.survey.models import SurveyAnswer, SurveyForm from openedx.features.course_experience import course_home_url from openedx.features.course_experience.url_helpers import make_learning_mfe_courseware_url +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class SurveyViewsTests(LoginEnrollmentTestCase, SharedModuleStoreTestCase, XssTestMixin): diff --git a/lms/djangoapps/courseware/tests/test_course_tools.py b/lms/djangoapps/courseware/tests/test_course_tools.py index e1d3391e2991..c86bb0738efb 100644 --- a/lms/djangoapps/courseware/tests/test_course_tools.py +++ b/lms/djangoapps/courseware/tests/test_course_tools.py @@ -4,19 +4,21 @@ import datetime - from unittest.mock import patch + import crum import pytz from django.test import RequestFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory from lms.djangoapps.courseware.course_tools import FinancialAssistanceTool from lms.djangoapps.courseware.models import DynamicUpgradeDeadlineConfiguration from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/courseware/tests/test_courses.py b/lms/djangoapps/courseware/tests/test_courses.py index 722a884188ba..d61f7617af80 100644 --- a/lms/djangoapps/courseware/tests/test_courses.py +++ b/lms/djangoapps/courseware/tests/test_courses.py @@ -5,10 +5,10 @@ import datetime import itertools - from unittest import mock -import pytest + import ddt +import pytest import pytz from completion.models import BlockCompletion from completion.test_utils import CompletionWaffleTestMixin @@ -19,13 +19,9 @@ from django.urls import reverse from freezegun import freeze_time from opaque_keys.edx.keys import CourseKey -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.django import _get_modulestore_branch_setting, modulestore -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, ToyCourseFactory, BlockFactory, check_mongo_calls -from xmodule.tests.xml import XModuleXmlImportTest -from xmodule.tests.xml import factories as xml +from common.djangoapps.student.tests.factories import UserFactory +from lms.djangoapps.courseware.block_render import get_block_for_descriptor from lms.djangoapps.courseware.courses import ( course_open_for_self_enrollment, get_cms_block_link, @@ -37,15 +33,19 @@ get_course_overview_with_access, get_course_with_access, get_courses, - get_current_child + get_current_child, ) -from lms.djangoapps.courseware.model_data import FieldDataCache -from lms.djangoapps.courseware.block_render import get_block_for_descriptor from lms.djangoapps.courseware.courseware_access_exception import CoursewareAccessException from lms.djangoapps.courseware.exceptions import CourseAccessRedirect +from lms.djangoapps.courseware.model_data import FieldDataCache from openedx.core.djangolib.testing.utils import get_mock_request from openedx.core.lib.courses import course_image_url -from common.djangoapps.student.tests.factories import UserFactory +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import _get_modulestore_branch_setting, modulestore +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory, ToyCourseFactory, check_mongo_calls +from xmodule.tests.xml import XModuleXmlImportTest +from xmodule.tests.xml import factories as xml 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 5c280dc57887..89e9269a4444 100644 --- a/lms/djangoapps/courseware/tests/test_credit_requirements.py +++ b/lms/djangoapps/courseware/tests/test_credit_requirements.py @@ -4,15 +4,18 @@ from unittest.mock import patch + import ddt from django.conf import settings from django.urls import reverse from common.djangoapps.course_modes.models import CourseMode +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from openedx.core.djangoapps.credit import api as credit_api from openedx.core.djangoapps.credit.models import CreditCourse -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/courseware/tests/test_date_summary.py b/lms/djangoapps/courseware/tests/test_date_summary.py index 1762d37bdee0..7d94e917e4b3 100644 --- a/lms/djangoapps/courseware/tests/test_date_summary.py +++ b/lms/djangoapps/courseware/tests/test_date_summary.py @@ -12,9 +12,6 @@ from edx_toggles.toggles.testutils import override_waffle_flag, override_waffle_switch from freezegun import freeze_time from pytz import utc -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory @@ -44,6 +41,9 @@ from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.features.course_duration_limits.models import CourseDurationLimitConfig from openedx.features.course_experience import RELATIVE_DATES_FLAG +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory @ddt.ddt diff --git a/lms/djangoapps/courseware/tests/test_discussion_xblock.py b/lms/djangoapps/courseware/tests/test_discussion_xblock.py index da2a68ec1d77..2a9373c113bb 100644 --- a/lms/djangoapps/courseware/tests/test_discussion_xblock.py +++ b/lms/djangoapps/courseware/tests/test_discussion_xblock.py @@ -9,9 +9,9 @@ import json import uuid - from unittest import mock from unittest.mock import patch + import ddt from django.conf import settings from django.test.utils import override_settings @@ -19,17 +19,17 @@ from opaque_keys.edx.keys import CourseKey from web_fragments.fragment import Fragment from xblock.field_data import DictFieldData -from xmodule.discussion_block import DiscussionXBlock -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import BlockFactory, ToyCourseFactory -from xmodule.tests.helpers import mock_render_template +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from lms.djangoapps.course_api.blocks.tests.helpers import deserialize_usage_key from lms.djangoapps.courseware.block_render import get_block_for_descriptor from lms.djangoapps.courseware.tests.helpers import XModuleRenderingTestBase from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, Provider from openedx.core.djangoapps.discussions.services import DiscussionConfigService -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory +from xmodule.discussion_block import DiscussionXBlock +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, ToyCourseFactory +from xmodule.tests.helpers import mock_render_template @ddt.ddt diff --git a/lms/djangoapps/courseware/tests/test_entrance_exam.py b/lms/djangoapps/courseware/tests/test_entrance_exam.py index 64bba8edfa52..df5c4ff37ec9 100644 --- a/lms/djangoapps/courseware/tests/test_entrance_exam.py +++ b/lms/djangoapps/courseware/tests/test_entrance_exam.py @@ -4,37 +4,41 @@ from unittest.mock import patch + from crum import set_current_request from django.test import override_settings from django.urls import reverse from milestones.tests.utils import MilestonesTestCaseMixin -from lms.djangoapps.courseware.entrance_exams import ( - course_has_entrance_exam, - get_entrance_exam_content, - user_can_skip_entrance_exam, - user_has_passed_entrance_exam -) -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory from xblocks_contrib.problem.capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory -from lms.djangoapps.courseware.model_data import FieldDataCache -from lms.djangoapps.courseware.block_render import get_block, handle_xblock_callback, toc_for_course -from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase -from openedx.core.djangolib.testing.utils import get_mock_request + from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.tests.factories import AnonymousUserFactory -from common.djangoapps.student.tests.factories import InstructorFactory -from common.djangoapps.student.tests.factories import RequestFactoryNoCsrf -from common.djangoapps.student.tests.factories import StaffFactory -from common.djangoapps.student.tests.factories import UserFactory +from common.djangoapps.student.tests.factories import ( + AnonymousUserFactory, + InstructorFactory, + RequestFactoryNoCsrf, + StaffFactory, + UserFactory, +) from common.djangoapps.util.milestones_helpers import ( add_course_content_milestone, add_course_milestone, add_milestone, generate_milestone_namespace, get_milestone_relationship_types, - get_namespace_choices + get_namespace_choices, ) +from lms.djangoapps.courseware.block_render import get_block, handle_xblock_callback, toc_for_course +from lms.djangoapps.courseware.entrance_exams import ( + course_has_entrance_exam, + get_entrance_exam_content, + user_can_skip_entrance_exam, + user_has_passed_entrance_exam, +) +from lms.djangoapps.courseware.model_data import FieldDataCache +from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase +from openedx.core.djangolib.testing.utils import get_mock_request +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory @override_settings(ENTRANCE_EXAMS=True) diff --git a/lms/djangoapps/courseware/tests/test_field_overrides.py b/lms/djangoapps/courseware/tests/test_field_overrides.py index 34efe70686f8..815110ac95b4 100644 --- a/lms/djangoapps/courseware/tests/test_field_overrides.py +++ b/lms/djangoapps/courseware/tests/test_field_overrides.py @@ -2,6 +2,7 @@ Tests for `field_overrides` module. """ import unittest + import pytest from django.test.utils import override_settings from xblock.field_data import DictFieldData @@ -14,7 +15,7 @@ OverrideFieldData, OverrideModulestoreFieldData, disable_overrides, - resolve_dotted + resolve_dotted, ) from ..testutils import FieldOverrideTestMixin diff --git a/lms/djangoapps/courseware/tests/test_filters.py b/lms/djangoapps/courseware/tests/test_filters.py index 069761f3e67e..56c22864a670 100644 --- a/lms/djangoapps/courseware/tests/test_filters.py +++ b/lms/djangoapps/courseware/tests/test_filters.py @@ -7,10 +7,10 @@ from openedx_filters import PipelineStep from openedx_filters.learning.filters import CourseAboutRenderStarted from rest_framework import status -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from openedx.core.djangolib.testing.utils import skip_unless_lms +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class TestRenderInvalidCourseAbout(PipelineStep): diff --git a/lms/djangoapps/courseware/tests/test_group_access.py b/lms/djangoapps/courseware/tests/test_group_access.py index d2718ddabfa6..f3ee0d5f67bd 100644 --- a/lms/djangoapps/courseware/tests/test_group_access.py +++ b/lms/djangoapps/courseware/tests/test_group_access.py @@ -6,15 +6,14 @@ import ddt from stevedore.extension import Extension, ExtensionManager + +import lms.djangoapps.courseware.access as access +from common.djangoapps.student.tests.factories import StaffFactory, UserFactory 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, BlockFactory +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory from xmodule.partitions.partitions import USER_PARTITION_SCHEME_NAMESPACE, Group, UserPartition -from common.djangoapps.student.tests.factories import StaffFactory -from common.djangoapps.student.tests.factories import UserFactory -import lms.djangoapps.courseware.access as access - class MemoryUserPartitionScheme: """ diff --git a/lms/djangoapps/courseware/tests/test_i18n.py b/lms/djangoapps/courseware/tests/test_i18n.py index de131bdc3c3d..e4b12539f678 100644 --- a/lms/djangoapps/courseware/tests/test_i18n.py +++ b/lms/djangoapps/courseware/tests/test_i18n.py @@ -12,10 +12,10 @@ from django.urls import reverse, reverse_lazy from django.utils import translation +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.dark_lang.models import DarkLangConfig from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY from openedx.core.djangolib.testing.utils import CacheIsolationTestCase -from common.djangoapps.student.tests.factories import UserFactory class BaseI18nTestCase(CacheIsolationTestCase): diff --git a/lms/djangoapps/courseware/tests/test_lti_integration.py b/lms/djangoapps/courseware/tests/test_lti_integration.py index bdaf1a13549b..1077ba85c825 100644 --- a/lms/djangoapps/courseware/tests/test_lti_integration.py +++ b/lms/djangoapps/courseware/tests/test_lti_integration.py @@ -4,11 +4,11 @@ import importlib import json import re +import urllib from collections import OrderedDict - from unittest import mock from unittest.mock import patch -import urllib + import oauthlib from django.conf import settings from django.test import override_settings @@ -19,10 +19,15 @@ from lms.djangoapps.courseware.tests.helpers import BaseTestXmodule from lms.djangoapps.courseware.views.views import get_course_lti_endpoints from openedx.core.lib.url_utils import quote_slashes -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.tests.helpers import mock_render_template from xmodule import lti_block +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) +from xmodule.tests.helpers import mock_render_template class _TestLTIBase(BaseTestXmodule): diff --git a/lms/djangoapps/courseware/tests/test_masquerade.py b/lms/djangoapps/courseware/tests/test_masquerade.py index 31fe714e2ae4..ece60e7bb08b 100644 --- a/lms/djangoapps/courseware/tests/test_masquerade.py +++ b/lms/djangoapps/courseware/tests/test_masquerade.py @@ -6,17 +6,20 @@ import pickle from datetime import datetime from importlib import import_module +from operator import itemgetter # lint-amnesty, pylint: disable=wrong-import-order from unittest.mock import patch -import pytest + import ddt -from operator import itemgetter # lint-amnesty, pylint: disable=wrong-import-order +import pytest from django.conf import settings -from django.test import TestCase, RequestFactory +from django.test import RequestFactory, TestCase from django.urls import reverse from pytz import UTC from xblock.runtime import DictKeyValueStore - from xblocks_contrib.problem.capa.tests.response_xml_factory import OptionResponseXMLFactory + +from common.djangoapps.student.models import CourseEnrollment +from common.djangoapps.student.tests.factories import StaffFactory, UserFactory from lms.djangoapps.courseware.masquerade import ( MASQUERADE_SETTINGS_KEY, CourseMasquerade, @@ -24,19 +27,18 @@ get_masquerading_user_group, setup_masquerade, ) - -from lms.djangoapps.courseware.tests.helpers import ( - LoginEnrollmentTestCase, MasqueradeMixin, masquerade_as_group_member -) +from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase, MasqueradeMixin, masquerade_as_group_member from lms.djangoapps.courseware.tests.test_submitting_problems import ProblemSubmissionTestMixin from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY from openedx.core.djangoapps.user_api.preferences.api import get_user_preference, set_user_preference -from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.tests.factories import StaffFactory -from common.djangoapps.student.tests.factories import UserFactory from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) from xmodule.partitions.partitions import Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/courseware/tests/test_middleware.py b/lms/djangoapps/courseware/tests/test_middleware.py index a525c75abc3c..2f62d74a7463 100644 --- a/lms/djangoapps/courseware/tests/test_middleware.py +++ b/lms/djangoapps/courseware/tests/test_middleware.py @@ -8,7 +8,9 @@ from lms.djangoapps.courseware.exceptions import Redirect from lms.djangoapps.courseware.middleware import RedirectMiddleware -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/courseware/tests/test_model_data.py b/lms/djangoapps/courseware/tests/test_model_data.py index 577edf831739..c0d4fb400e2f 100644 --- a/lms/djangoapps/courseware/tests/test_model_data.py +++ b/lms/djangoapps/courseware/tests/test_model_data.py @@ -4,30 +4,32 @@ import json from functools import partial from unittest.mock import Mock, patch -from openedx.core.djangolib.testing.utils import AUTHZ_TABLES, FilteredQueryCountMixin -import pytest -from django.db import connections, DatabaseError +import pytest +from django.db import DatabaseError, connections from django.test import TestCase from xblock.core import XBlock from xblock.exceptions import KeyValueMultiSaveError from xblock.fields import BlockScope, Scope, ScopeIds from common.djangoapps.student.tests.factories import UserFactory -from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES from lms.djangoapps.courseware.model_data import DjangoKeyValueStore, FieldDataCache, InvalidScopeError from lms.djangoapps.courseware.models import ( StudentModule, XModuleStudentInfoField, XModuleStudentPrefsField, - XModuleUserStateSummaryField + XModuleUserStateSummaryField, +) +from lms.djangoapps.courseware.tests.factories import ( + COURSE_KEY, + LOCATION, + StudentInfoFactory, + StudentPrefsFactory, + UserStateSummaryFactory, ) -from lms.djangoapps.courseware.tests.factories import COURSE_KEY -from lms.djangoapps.courseware.tests.factories import LOCATION -from lms.djangoapps.courseware.tests.factories import StudentInfoFactory from lms.djangoapps.courseware.tests.factories import StudentModuleFactory as cmfStudentModuleFactory -from lms.djangoapps.courseware.tests.factories import StudentPrefsFactory -from lms.djangoapps.courseware.tests.factories import UserStateSummaryFactory +from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES +from openedx.core.djangolib.testing.utils import AUTHZ_TABLES, FilteredQueryCountMixin QUERY_COUNT_TABLE_IGNORELIST = WAFFLE_TABLES + AUTHZ_TABLES diff --git a/lms/djangoapps/courseware/tests/test_rules.py b/lms/djangoapps/courseware/tests/test_rules.py index 0928c355d213..2cf2a8d277b5 100644 --- a/lms/djangoapps/courseware/tests/test_rules.py +++ b/lms/djangoapps/courseware/tests/test_rules.py @@ -4,12 +4,15 @@ from unittest.mock import patch + import ddt from common.djangoapps.course_modes.tests.factories import CourseModeFactory from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/courseware/tests/test_self_paced_overrides.py b/lms/djangoapps/courseware/tests/test_self_paced_overrides.py index fef054a4c966..91c2a8234a90 100644 --- a/lms/djangoapps/courseware/tests/test_self_paced_overrides.py +++ b/lms/djangoapps/courseware/tests/test_self_paced_overrides.py @@ -1,18 +1,23 @@ """Tests for self-paced course due date overrides.""" import datetime - from unittest.mock import patch + import pytz from django.test.utils import override_settings from common.djangoapps.student.tests.factories import BetaTesterFactory -from lms.djangoapps.courseware.access import has_access from lms.djangoapps.ccx.tests.test_overrides import inject_field_overrides +from lms.djangoapps.courseware.access import has_access from lms.djangoapps.courseware.field_overrides import OverrideFieldData, OverrideModulestoreFieldData from openedx.core.djangoapps.discussions.utils import get_accessible_discussion_xblocks -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) @override_settings( diff --git a/lms/djangoapps/courseware/tests/test_services.py b/lms/djangoapps/courseware/tests/test_services.py index b3e862142b41..49e8f754d6f4 100644 --- a/lms/djangoapps/courseware/tests/test_services.py +++ b/lms/djangoapps/courseware/tests/test_services.py @@ -11,8 +11,13 @@ from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.courseware.services import UserStateService from lms.djangoapps.courseware.tests.factories import StudentModuleFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) @ddt.ddt diff --git a/lms/djangoapps/courseware/tests/test_sharing_sites.py b/lms/djangoapps/courseware/tests/test_sharing_sites.py index 0fd0fb9c26e7..803cc3595319 100644 --- a/lms/djangoapps/courseware/tests/test_sharing_sites.py +++ b/lms/djangoapps/courseware/tests/test_sharing_sites.py @@ -2,14 +2,16 @@ tests for the sharing sites """ -import ddt from unittest import TestCase from unittest.mock import patch from urllib.parse import parse_qsl + +import ddt + from openedx.core.djangoapps.video_config.sharing_sites import ( - sharing_url, - sharing_sites_info_for_video, SharingSiteConfig, + sharing_sites_info_for_video, + sharing_url, ) TEST_SHARING_SITE_NAME = "test_site_name" diff --git a/lms/djangoapps/courseware/tests/test_split_module.py b/lms/djangoapps/courseware/tests/test_split_module.py index 5026f05ca221..7dfff365e18f 100644 --- a/lms/djangoapps/courseware/tests/test_split_module.py +++ b/lms/djangoapps/courseware/tests/test_split_module.py @@ -4,15 +4,16 @@ from unittest.mock import MagicMock + from django.urls import reverse -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory -from xmodule.partitions.partitions import Group, UserPartition -from lms.djangoapps.courseware.model_data import FieldDataCache +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from lms.djangoapps.courseware.block_render import get_block_for_descriptor +from lms.djangoapps.courseware.model_data import FieldDataCache from openedx.core.djangoapps.user_api.tests.factories import UserCourseTagFactory -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory +from xmodule.partitions.partitions import Group, UserPartition class SplitTestBase(ModuleStoreTestCase): diff --git a/lms/djangoapps/courseware/tests/test_submitting_problems.py b/lms/djangoapps/courseware/tests/test_submitting_problems.py index 1f1e35190050..e0ff0c05cd26 100644 --- a/lms/djangoapps/courseware/tests/test_submitting_problems.py +++ b/lms/djangoapps/courseware/tests/test_submitting_problems.py @@ -21,16 +21,17 @@ from django.urls import reverse from django.utils.timezone import now from submissions import api as submissions_api - from xblocks_contrib.problem.capa.tests.response_xml_factory import ( CodeResponseXMLFactory, CustomResponseXMLFactory, OptionResponseXMLFactory, - SchematicResponseXMLFactory + SchematicResponseXMLFactory, ) from xblocks_contrib.problem.capa.tests.test_util import UseUnsafeCodejail from xblocks_contrib.problem.capa.xqueue_interface import XQueueInterface + from common.djangoapps.course_modes.models import CourseMode +from common.djangoapps.student.models import CourseEnrollment, anonymous_id_for_user from lms.djangoapps.courseware.models import BaseStudentModuleHistory, StudentModule from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase from lms.djangoapps.grades.api import CourseGradeFactory, task_compute_all_grades_for_course @@ -38,9 +39,13 @@ 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 common.djangoapps.student.models import CourseEnrollment, anonymous_id_for_user -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) from xmodule.partitions.partitions import Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/courseware/tests/test_tabs.py b/lms/djangoapps/courseware/tests/test_tabs.py index e332d0de96de..63b0acf8d73f 100644 --- a/lms/djangoapps/courseware/tests/test_tabs.py +++ b/lms/djangoapps/courseware/tests/test_tabs.py @@ -3,6 +3,7 @@ """ from unittest.mock import MagicMock, Mock, patch + import ddt import pytest from crum import set_current_request @@ -13,13 +14,21 @@ from edx_toggles.toggles.testutils import override_waffle_flag from milestones.tests.utils import MilestonesTestCaseMixin +from common.djangoapps.student.models import CourseEnrollment +from common.djangoapps.student.tests.factories import InstructorFactory, StaffFactory, UserFactory +from common.djangoapps.util.milestones_helpers import ( + add_course_content_milestone, + add_course_milestone, + add_milestone, + get_milestone_relationship_types, +) from lms.djangoapps.courseware.tabs import ( CoursewareTab, DatesTab, ExternalDiscussionCourseTab, ExternalLinkCourseTab, ProgressTab, - get_course_tab_list + get_course_tab_list, ) from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase from lms.djangoapps.courseware.views.views import StaticCourseTabView, get_static_tab_fragment @@ -27,23 +36,16 @@ from openedx.core.djangoapps.discussions.url_helpers import get_discussions_mfe_url from openedx.core.djangolib.testing.utils import get_mock_request from openedx.core.lib.courses import get_course_by_id -from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.tests.factories import InstructorFactory -from common.djangoapps.student.tests.factories import StaffFactory -from common.djangoapps.student.tests.factories import UserFactory -from common.djangoapps.util.milestones_helpers import ( - add_course_content_milestone, - add_course_milestone, - add_milestone, - get_milestone_relationship_types -) from xmodule import tabs as xmodule_tabs # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase, - SharedModuleStoreTestCase + SharedModuleStoreTestCase, +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, ) -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.tests.utils import TEST_DATA_DIR # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.xml_importer import import_course_from_xml # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/courseware/tests/test_user_state_client.py b/lms/djangoapps/courseware/tests/test_user_state_client.py index 690a64b8b8c5..63f3b0da1fa2 100644 --- a/lms/djangoapps/courseware/tests/test_user_state_client.py +++ b/lms/djangoapps/courseware/tests/test_user_state_client.py @@ -3,21 +3,24 @@ defined in edx_user_state_client. """ -import pytz -from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator -from xblock.fields import Scope +from collections import defaultdict from datetime import datetime from unittest import TestCase -from collections import defaultdict + +import pytz from django.db import connections +from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator +from xblock.fields import Scope from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.courseware.user_state_client import ( DjangoXBlockUserStateClient, + XBlockUserState, XBlockUserStateClient, - XBlockUserState ) -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) class _UserStateClientTestUtils(TestCase): diff --git a/lms/djangoapps/courseware/tests/test_utils.py b/lms/djangoapps/courseware/tests/test_utils.py index 0fedc273905b..f234d3079a67 100644 --- a/lms/djangoapps/courseware/tests/test_utils.py +++ b/lms/djangoapps/courseware/tests/test_utils.py @@ -14,9 +14,9 @@ from rest_framework import status from common.djangoapps.student.tests.factories import GlobalStaffFactory, UserFactory +from lms.djangoapps.courseware.access_utils import adjust_start_date from lms.djangoapps.courseware.constants import UNEXPECTED_ERROR_IS_ELIGIBLE from lms.djangoapps.courseware.tests.factories import FinancialAssistanceConfigurationFactory -from lms.djangoapps.courseware.access_utils import adjust_start_date from lms.djangoapps.courseware.utils import ( create_financial_assistance_application, get_financial_assistance_application_status, diff --git a/lms/djangoapps/courseware/tests/test_video_handlers.py b/lms/djangoapps/courseware/tests/test_video_handlers.py index b0a9eb3a7a60..42488ce1cae9 100644 --- a/lms/djangoapps/courseware/tests/test_video_handlers.py +++ b/lms/djangoapps/courseware/tests/test_video_handlers.py @@ -7,34 +7,36 @@ import textwrap from datetime import timedelta from unittest.mock import MagicMock, Mock, patch -import pytest + import ddt import freezegun +import pytest from django.conf import settings from django.core.files.base import ContentFile -from django.utils.timezone import now from django.test import RequestFactory +from django.utils.timezone import now from edxval import api -from xblock.django.request import DjangoWebobRequest from webob import Request, Response +from xblock.django.request import DjangoWebobRequest from common.djangoapps.student.tests.factories import UserFactory from common.test.utils import normalize_repr from openedx.core.djangoapps.contentserver.caching import del_cached_content +from openedx.core.djangoapps.video_config.transcripts_utils import ( # lint-amnesty, pylint: disable=wrong-import-order + Transcript, + edxval_api, + get_transcript, + subs_filename, +) from xmodule.contentstore.content import StaticContent # lint-amnesty, pylint: disable=wrong-import-order from xmodule.contentstore.django import contentstore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.exceptions import NotFoundError # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order + # noinspection PyUnresolvedReferences from xmodule.tests.helpers import override_descriptor_system # pylint: disable=unused-import from xmodule.video_block import VideoBlock # lint-amnesty, pylint: disable=wrong-import-order -from openedx.core.djangoapps.video_config.transcripts_utils import ( # lint-amnesty, pylint: disable=wrong-import-order - Transcript, - edxval_api, - get_transcript, - subs_filename, -) from xmodule.x_module import STUDENT_VIEW from .helpers import BaseTestXmodule diff --git a/lms/djangoapps/courseware/tests/test_video_mongo.py b/lms/djangoapps/courseware/tests/test_video_mongo.py index 5e730312fa27..afdfa7d7d137 100644 --- a/lms/djangoapps/courseware/tests/test_video_mongo.py +++ b/lms/djangoapps/courseware/tests/test_video_mongo.py @@ -3,10 +3,10 @@ """ -from contextlib import contextmanager import json import shutil from collections import OrderedDict +from contextlib import contextmanager from tempfile import mkdtemp from unittest.mock import MagicMock, Mock, patch from uuid import uuid4 @@ -36,36 +36,37 @@ from fs.path import combine from lxml import etree from path import Path as path -from xmodule.contentstore.content import StaticContent +from xblocks_contrib.video import bumper_utils + +from common.djangoapps.xblock_django.constants import ATTR_KEY_REQUEST_COUNTRY_CODE +from common.test.utils import assert_dict_contains_subset +from lms.djangoapps.courseware.tests.helpers import get_context_from_dict +from openedx.core.djangoapps.video_config import sharing from openedx.core.djangoapps.video_config.sharing import ( COURSE_VIDEO_SHARING_ALL_VIDEOS, COURSE_VIDEO_SHARING_NONE, - COURSE_VIDEO_SHARING_PER_VIDEO + COURSE_VIDEO_SHARING_PER_VIDEO, ) +from openedx.core.djangoapps.video_config.toggles import PUBLIC_VIDEO_SHARE +from openedx.core.djangoapps.video_config.transcripts_utils import Transcript, save_to_store, subs_filename +from openedx.core.djangoapps.video_pipeline.config.waffle import DEPRECATE_YOUTUBE +from openedx.core.djangoapps.waffle_utils.models import WaffleFlagCourseOverrideModel +from openedx.core.djangolib.testing.utils import CacheIsolationTestCase +from xmodule.contentstore.content import StaticContent from xmodule.exceptions import NotFoundError from xmodule.modulestore.inheritance import own_metadata from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE + # noinspection PyUnresolvedReferences from xmodule.tests.helpers import mock_render_template, override_descriptor_system # pylint: disable=unused-import from xmodule.tests.test_import import DummyModuleStoreRuntime from xmodule.tests.test_video import VideoBlockTestBase from xmodule.video_block import VideoBlock, video_utils -from xblocks_contrib.video import bumper_utils -from openedx.core.djangoapps.video_config.transcripts_utils import Transcript, save_to_store, subs_filename from xmodule.video_block.video_block import EXPORT_IMPORT_COURSE_DIR, EXPORT_IMPORT_STATIC_DIR from xmodule.x_module import PUBLIC_VIEW, STUDENT_VIEW -from common.djangoapps.xblock_django.constants import ATTR_KEY_REQUEST_COUNTRY_CODE -from lms.djangoapps.courseware.tests.helpers import get_context_from_dict -from openedx.core.djangoapps.video_config.toggles import PUBLIC_VIDEO_SHARE -from openedx.core.djangoapps.video_config import sharing -from openedx.core.djangoapps.video_pipeline.config.waffle import DEPRECATE_YOUTUBE -from openedx.core.djangoapps.waffle_utils.models import WaffleFlagCourseOverrideModel -from openedx.core.djangolib.testing.utils import CacheIsolationTestCase - from .test_video_handlers import BaseTestVideoXBlock, TestVideo -from .test_video_xml import SOURCE_XML, PUBLIC_SOURCE_XML -from common.test.utils import assert_dict_contains_subset +from .test_video_xml import PUBLIC_SOURCE_XML, SOURCE_XML TRANSCRIPT_FILE_SRT_DATA = """ 1 diff --git a/lms/djangoapps/courseware/tests/test_video_xml.py b/lms/djangoapps/courseware/tests/test_video_xml.py index 2b454bef639c..22276575b3df 100644 --- a/lms/djangoapps/courseware/tests/test_video_xml.py +++ b/lms/djangoapps/courseware/tests/test_video_xml.py @@ -16,6 +16,7 @@ from django.test import TestCase + from xmodule.video_block import VideoBlock SOURCE_XML = """ diff --git a/lms/djangoapps/courseware/tests/test_view_authentication.py b/lms/djangoapps/courseware/tests/test_view_authentication.py index f9668853b244..8e3df22d56a1 100644 --- a/lms/djangoapps/courseware/tests/test_view_authentication.py +++ b/lms/djangoapps/courseware/tests/test_view_authentication.py @@ -4,24 +4,27 @@ import datetime - from unittest.mock import patch + import pytz from django.urls import reverse -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory - -from common.djangoapps.student.tests.factories import BetaTesterFactory -from common.djangoapps.student.tests.factories import GlobalStaffFactory -from common.djangoapps.student.tests.factories import InstructorFactory -from common.djangoapps.student.tests.factories import OrgInstructorFactory -from common.djangoapps.student.tests.factories import OrgStaffFactory -from common.djangoapps.student.tests.factories import StaffFactory + +from common.djangoapps.student.tests.factories import ( + BetaTesterFactory, + CourseEnrollmentFactory, + GlobalStaffFactory, + InstructorFactory, + OrgInstructorFactory, + OrgStaffFactory, + StaffFactory, + UserFactory, +) from lms.djangoapps.courseware.access import has_access from lms.djangoapps.courseware.tests.helpers import CourseAccessTestMixin, LoginEnrollmentTestCase from openedx.features.enterprise_support.tests.mixins.enterprise import EnterpriseTestConsentRequired -from common.djangoapps.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 BlockFactory, CourseFactory class TestViewAuth(EnterpriseTestConsentRequired, ModuleStoreTestCase, LoginEnrollmentTestCase): diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index d96edb07c674..1e166b055d06 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -2,11 +2,11 @@ Tests courseware views.py """ -from contextlib import contextmanager import html import itertools import json import re +from contextlib import contextmanager from datetime import datetime, timedelta from unittest.mock import MagicMock, PropertyMock, create_autospec, patch from urllib.parse import quote, urlencode @@ -14,20 +14,21 @@ import ddt from completion.test_utils import CompletionWaffleTestMixin +from completion.waffle import ENABLE_COMPLETION_TRACKING_SWITCH from crum import set_current_request from django.conf import settings from django.contrib.auth.models import AnonymousUser from django.http import Http404, HttpResponse, HttpResponseBadRequest from django.http.request import QueryDict -from django.test import override_settings, RequestFactory, TestCase +from django.test import RequestFactory, TestCase, override_settings from django.test.client import Client from django.urls import reverse, reverse_lazy from edx_django_utils.cache.utils import RequestCache from edx_toggles.toggles.testutils import override_waffle_flag, override_waffle_switch +from enterprise.api.v1.serializers import EnterpriseCustomerSerializer from freezegun import freeze_time from opaque_keys.edx.keys import CourseKey, UsageKey from pytz import UTC -from openedx.core.djangoapps.waffle_utils.models import WaffleFlagCourseOverrideModel from rest_framework import status from rest_framework.test import APIClient from web_fragments.fragment import Fragment @@ -35,11 +36,6 @@ from xblock.fields import Scope, String from xblock.scorable import ShowCorrectness from xblocks_contrib.problem.capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory -from xmodule.data import CertificatesDisplayBehaviors -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import CourseUserType, ModuleStoreTestCase, SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory, check_mongo_calls import lms.djangoapps.courseware.views.views as views from common.djangoapps.course_modes.models import CourseMode @@ -51,7 +47,7 @@ CourseEnrollmentFactory, GlobalStaffFactory, RequestFactoryNoCsrf, - UserFactory + UserFactory, ) from common.djangoapps.util.tests.test_date_utils import fake_pgettext, fake_ugettext from common.djangoapps.util.url import reload_django_url_config @@ -61,25 +57,24 @@ from lms.djangoapps.certificates.tests.factories import ( CertificateAllowlistFactory, CertificateInvalidationFactory, - GeneratedCertificateFactory + GeneratedCertificateFactory, ) from lms.djangoapps.commerce.models import CommerceConfiguration from lms.djangoapps.commerce.utils import EcommerceService from lms.djangoapps.courseware.access_utils import check_course_open_for_learner -from lms.djangoapps.courseware.model_data import FieldDataCache, set_score from lms.djangoapps.courseware.block_render import get_block, handle_xblock_callback +from lms.djangoapps.courseware.model_data import FieldDataCache, set_score from lms.djangoapps.courseware.tests.helpers import MasqueradeMixin, get_expiration_banner_text from lms.djangoapps.courseware.testutils import RenderXBlockTestMixin from lms.djangoapps.courseware.toggles import ( COURSEWARE_MICROFRONTEND_SEARCH_ENABLED, COURSEWARE_OPTIMIZED_RENDER_XBLOCK, ) -from completion.waffle import ENABLE_COMPLETION_TRACKING_SWITCH from lms.djangoapps.courseware.user_state_client import DjangoXBlockUserStateClient from lms.djangoapps.courseware.views.views import ( BasePublicVideoXBlockView, - PublicVideoXBlockView, PublicVideoXBlockEmbedView, + PublicVideoXBlockView, ) from lms.djangoapps.instructor.access import allow_access from lms.djangoapps.verify_student.services import IDVerificationService @@ -88,25 +83,27 @@ from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.credit.api import set_credit_requirements from openedx.core.djangoapps.credit.models import CreditCourse, CreditProvider +from openedx.core.djangoapps.video_config.toggles import PUBLIC_VIDEO_SHARE +from openedx.core.djangoapps.waffle_utils.models import WaffleFlagCourseOverrideModel from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES from openedx.core.djangolib.testing.utils import AUTHZ_TABLES, get_mock_request -from openedx.core.djangoapps.video_config.toggles import PUBLIC_VIDEO_SHARE from openedx.core.lib.url_utils import quote_slashes from openedx.features.content_type_gating.models import ContentTypeGatingConfig from openedx.features.course_duration_limits.models import CourseDurationLimitConfig from openedx.features.course_experience.tests.views.helpers import add_course_mode -from openedx.features.course_experience.url_helpers import ( - get_learning_mfe_home_url, - make_learning_mfe_courseware_url -) +from openedx.features.course_experience.url_helpers import get_learning_mfe_home_url, make_learning_mfe_courseware_url +from openedx.features.enterprise_support.api import add_enterprise_customer_to_session from openedx.features.enterprise_support.tests.factories import ( EnterpriseCourseEnrollmentFactory, + EnterpriseCustomerFactory, EnterpriseCustomerUserFactory, - EnterpriseCustomerFactory ) from openedx.features.enterprise_support.tests.mixins.enterprise import EnterpriseTestConsentRequired -from openedx.features.enterprise_support.api import add_enterprise_customer_to_session -from enterprise.api.v1.serializers import EnterpriseCustomerSerializer +from xmodule.data import CertificatesDisplayBehaviors +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import CourseUserType, ModuleStoreTestCase, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory, check_mongo_calls QUERY_COUNT_TABLE_IGNORELIST = WAFFLE_TABLES + AUTHZ_TABLES diff --git a/lms/djangoapps/courseware/tests/test_word_cloud.py b/lms/djangoapps/courseware/tests/test_word_cloud.py index 286ebfcde028..11439ffaeccd 100644 --- a/lms/djangoapps/courseware/tests/test_word_cloud.py +++ b/lms/djangoapps/courseware/tests/test_word_cloud.py @@ -13,9 +13,11 @@ from common.djangoapps.student.tests.factories import RequestFactoryNoCsrf from xmodule import word_cloud_block + # noinspection PyUnresolvedReferences -from xmodule.tests.helpers import override_descriptor_system, mock_render_template # pylint: disable=unused-import +from xmodule.tests.helpers import mock_render_template, override_descriptor_system # pylint: disable=unused-import from xmodule.x_module import STUDENT_VIEW + from .helpers import BaseTestXmodule diff --git a/lms/djangoapps/courseware/tests/tests.py b/lms/djangoapps/courseware/tests/tests.py index 7b9a8962f2dd..6134509d85f3 100644 --- a/lms/djangoapps/courseware/tests/tests.py +++ b/lms/djangoapps/courseware/tests/tests.py @@ -4,9 +4,8 @@ from textwrap import dedent -from unittest import TestCase +from unittest import TestCase, mock -from unittest import mock from django.urls import reverse from opaque_keys.edx.keys import CourseKey @@ -14,7 +13,10 @@ from lms.djangoapps.lms_xblock.field_data import LmsFieldData from xmodule.error_block import ErrorBlock # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order + TEST_DATA_SPLIT_MODULESTORE, + ModuleStoreTestCase, +) from xmodule.modulestore.tests.factories import ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/courseware/testutils.py b/lms/djangoapps/courseware/testutils.py index 5f47b258ae9f..a6be20994ad9 100644 --- a/lms/djangoapps/courseware/testutils.py +++ b/lms/djangoapps/courseware/testutils.py @@ -10,15 +10,20 @@ import ddt -from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from lms.djangoapps.courseware.utils import is_mode_upsellable -from common.djangoapps.student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory - +from common.djangoapps.student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory +from lms.djangoapps.courseware.utils import is_mode_upsellable +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, + check_mongo_calls, +) from .field_overrides import OverrideModulestoreFieldData from .tests.helpers import MasqueradeMixin diff --git a/lms/djangoapps/courseware/user_state_client.py b/lms/djangoapps/courseware/user_state_client.py index b85f20175ce8..c91ec12108d2 100644 --- a/lms/djangoapps/courseware/user_state_client.py +++ b/lms/djangoapps/courseware/user_state_client.py @@ -6,11 +6,10 @@ import itertools import logging -from operator import attrgetter -from time import time - from abc import abstractmethod from collections import namedtuple +from operator import attrgetter +from time import time from django.conf import settings from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user diff --git a/lms/djangoapps/courseware/utils.py b/lms/djangoapps/courseware/utils.py index f9ef351dfdc3..37d4e09fce54 100644 --- a/lms/djangoapps/courseware/utils.py +++ b/lms/djangoapps/courseware/utils.py @@ -4,17 +4,14 @@ import datetime import hashlib import logging -from bs4 import BeautifulSoup +from bs4 import BeautifulSoup from django.conf import settings from django.http import HttpResponse, HttpResponseBadRequest from edx_rest_api_client.client import OAuthAPIClient from oauth2_provider.models import Application from pytz import utc # lint-amnesty, pylint: disable=wrong-import-order from rest_framework import status -from xmodule.partitions.partitions import \ - ENROLLMENT_TRACK_PARTITION_ID # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions_service import PartitionService # lint-amnesty, pylint: disable=wrong-import-order from common.djangoapps.course_modes.models import CourseMode from lms.djangoapps.commerce.utils import EcommerceService @@ -22,10 +19,14 @@ from lms.djangoapps.courseware.constants import ( UNEXPECTED_ERROR_APPLICATION_STATUS, UNEXPECTED_ERROR_CREATE_APPLICATION, - UNEXPECTED_ERROR_IS_ELIGIBLE + UNEXPECTED_ERROR_IS_ELIGIBLE, ) from lms.djangoapps.courseware.models import FinancialAssistanceConfiguration from openedx.core.djangoapps.waffle_utils.models import WaffleFlagCourseOverrideModel +from xmodule.partitions.partitions import ( + ENROLLMENT_TRACK_PARTITION_ID, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.partitions.partitions_service import PartitionService # lint-amnesty, pylint: disable=wrong-import-order log = logging.getLogger(__name__) diff --git a/lms/djangoapps/courseware/views/index.py b/lms/djangoapps/courseware/views/index.py index 1034674b7b41..eeb42bd8ccc9 100644 --- a/lms/djangoapps/courseware/views/index.py +++ b/lms/djangoapps/courseware/views/index.py @@ -9,21 +9,20 @@ from django.contrib.auth.views import redirect_to_login from django.utils.decorators import method_decorator +from django.utils.functional import cached_property from django.views.decorators.cache import cache_control from django.views.decorators.csrf import ensure_csrf_cookie -from django.utils.functional import cached_property from django.views.generic import View - from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey, UsageKey -from xmodule.modulestore.django import modulestore from common.djangoapps.util.views import ensure_valid_course_key from lms.djangoapps.courseware.exceptions import Redirect from lms.djangoapps.courseware.masquerade import setup_masquerade -from openedx.features.course_experience.url_helpers import make_learning_mfe_courseware_url from openedx.features.course_experience import COURSE_ENABLE_UNENROLLED_ACCESS_FLAG +from openedx.features.course_experience.url_helpers import make_learning_mfe_courseware_url from openedx.features.enterprise_support.api import data_sharing_consent_required +from xmodule.modulestore.django import modulestore from ..block_render import get_block_for_descriptor from ..courses import get_course_with_access diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index 590a5f5acef4..ad064296d34c 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -12,14 +12,15 @@ import nh3 import requests +from completion.waffle import ENABLE_COMPLETION_TRACKING_SWITCH from django.conf import settings from django.contrib.auth.decorators import login_required from django.contrib.auth.models import AnonymousUser, User # lint-amnesty, pylint: disable=imported-auth-user from django.core.exceptions import PermissionDenied from django.db import transaction from django.db.models import Q, prefetch_related_objects +from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, JsonResponse from django.shortcuts import redirect -from django.http import JsonResponse, Http404, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden from django.template.context_processors import csrf from django.urls import reverse from django.utils.decorators import method_decorator @@ -34,37 +35,25 @@ from edx_django_utils.monitoring import set_custom_attribute, set_custom_attributes_for_course_key from edx_django_utils.plugins import pluggable_override from ipware.ip import get_client_ip -from xblock.core import XBlock - -from lms.djangoapps.static_template_view.views import render_500 from markupsafe import escape from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey, UsageKey from openedx_filters.learning.filters import CourseAboutRenderStarted, RenderXBlockStarted -from requests.exceptions import ConnectionError, Timeout # pylint: disable=redefined-builtin from pytz import UTC +from requests.exceptions import ConnectionError, Timeout # pylint: disable=redefined-builtin from rest_framework import status from rest_framework.decorators import api_view, throttle_classes +from rest_framework.fields import BooleanField from rest_framework.response import Response from rest_framework.throttling import UserRateThrottle -from rest_framework.fields import BooleanField from web_fragments.fragment import Fragment -from xmodule.course_block import ( - COURSE_VISIBILITY_PUBLIC, - COURSE_VISIBILITY_PUBLIC_OUTLINE, - CATALOG_VISIBILITY_CATALOG_AND_ABOUT, -) -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.exceptions import ItemNotFoundError, NoPathToItem -from xmodule.tabs import CourseTabList -from xmodule.x_module import STUDENT_VIEW +from xblock.core import XBlock from common.djangoapps.course_modes.models import CourseMode, get_course_prices from common.djangoapps.edxmako.shortcuts import marketing_link, render_to_response, render_to_string from common.djangoapps.student import auth -from common.djangoapps.student.roles import CourseStaffRole from common.djangoapps.student.models import CourseEnrollment, UserTestGroup +from common.djangoapps.student.roles import CourseStaffRole from common.djangoapps.util.cache import cache, cache_if_anonymous from common.djangoapps.util.course import course_location_from_key, get_link_for_about_page from common.djangoapps.util.db import outer_atomic @@ -90,7 +79,7 @@ get_permission_for_course_about, get_studio_url, sort_by_announcement, - sort_by_start_date + sort_by_start_date, ) from lms.djangoapps.courseware.date_summary import verified_upgrade_deadline_link from lms.djangoapps.courseware.exceptions import CourseAccessRedirect, Redirect @@ -98,35 +87,32 @@ from lms.djangoapps.courseware.model_data import FieldDataCache from lms.djangoapps.courseware.models import BaseStudentModuleHistory, StudentModule from lms.djangoapps.courseware.permissions import MASQUERADE_AS_STUDENT, VIEW_COURSE_HOME, VIEW_COURSEWARE -from lms.djangoapps.courseware.toggles import ( - course_is_invitation_only, - courseware_mfe_search_is_enabled, -) -from completion.waffle import ENABLE_COMPLETION_TRACKING_SWITCH +from lms.djangoapps.courseware.toggles import course_is_invitation_only, courseware_mfe_search_is_enabled from lms.djangoapps.courseware.user_state_client import DjangoXBlockUserStateClient from lms.djangoapps.courseware.utils import ( _use_new_financial_assistance_flow, create_financial_assistance_application, - is_eligible_for_financial_aid + is_eligible_for_financial_aid, ) from lms.djangoapps.edxnotes.helpers import is_feature_enabled from lms.djangoapps.experiments.utils import get_experiment_user_metadata_context from lms.djangoapps.grades.api import CourseGradeFactory from lms.djangoapps.instructor.enrollment import uses_shib from lms.djangoapps.instructor.views.api import require_global_staff +from lms.djangoapps.static_template_view.views import render_500 from lms.djangoapps.survey import views as survey_views from lms.djangoapps.verify_student.services import IDVerificationService from openedx.core.djangoapps.catalog.utils import ( get_course_data, get_course_uuid_for_course, get_programs, - get_programs_with_type + get_programs_with_type, ) from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.credit.api import ( get_credit_requirement_status, is_credit_course, - is_user_eligible_for_credit + is_user_eligible_for_credit, ) from openedx.core.djangoapps.enrollments.api import add_enrollment from openedx.core.djangoapps.enrollments.permissions import ENROLL_IN_COURSE @@ -135,8 +121,8 @@ from openedx.core.djangoapps.programs.utils import ProgramMarketingDataExtender from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.util.user_messages import PageLevelMessages -from openedx.core.djangoapps.video_config.toggles import PUBLIC_VIDEO_SHARE from openedx.core.djangoapps.video_config.sharing import is_public_sharing_enabled +from openedx.core.djangoapps.video_config.toggles import PUBLIC_VIDEO_SHARE from openedx.core.djangoapps.zendesk_proxy.utils import create_zendesk_ticket from openedx.core.djangolib.markup import HTML, Text from openedx.core.lib.courses import get_course_by_id @@ -147,18 +133,25 @@ from openedx.features.course_experience.url_helpers import ( get_courseware_url, get_learning_mfe_home_url, - is_request_from_learning_mfe + is_request_from_learning_mfe, ) from openedx.features.course_experience.utils import dates_banner_should_display from openedx.features.course_experience.waffle import ENABLE_COURSE_ABOUT_SIDEBAR_HTML from openedx.features.enterprise_support.api import data_sharing_consent_required +from xmodule.course_block import ( + CATALOG_VISIBILITY_CATALOG_AND_ABOUT, + COURSE_VISIBILITY_PUBLIC, + COURSE_VISIBILITY_PUBLIC_OUTLINE, +) +from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.exceptions import ItemNotFoundError, NoPathToItem +from xmodule.tabs import CourseTabList +from xmodule.x_module import STUDENT_VIEW from ..block_render import get_block, get_block_by_usage_id, get_block_for_descriptor from ..tabs import _get_dynamic_tabs -from ..toggles import ( - COURSEWARE_OPTIMIZED_RENDER_XBLOCK, - ENABLE_COURSE_DISCOVERY_DEFAULT_LANGUAGE_FILTER, -) +from ..toggles import COURSEWARE_OPTIMIZED_RENDER_XBLOCK, ENABLE_COURSE_DISCOVERY_DEFAULT_LANGUAGE_FILTER log = logging.getLogger("edx.courseware") diff --git a/lms/djangoapps/coursewarehistoryextended/migrations/0001_initial.py b/lms/djangoapps/coursewarehistoryextended/migrations/0001_initial.py index 12687dd7aa26..a0231c2cb6fa 100644 --- a/lms/djangoapps/coursewarehistoryextended/migrations/0001_initial.py +++ b/lms/djangoapps/coursewarehistoryextended/migrations/0001_initial.py @@ -1,9 +1,11 @@ import datetime -from django.db import migrations, models import django.db.models.deletion -from lms.djangoapps.courseware.fields import UnsignedBigIntAutoField from django.conf import settings +from django.db import migrations, models + +from lms.djangoapps.courseware.fields import UnsignedBigIntAutoField + def bump_pk_start(apps, schema_editor): if not schema_editor.connection.alias == 'student_module_history': diff --git a/lms/djangoapps/coursewarehistoryextended/migrations/0003_rename_studentmodulehistoryextended_student_module_student_module_idx.py b/lms/djangoapps/coursewarehistoryextended/migrations/0003_rename_studentmodulehistoryextended_student_module_student_module_idx.py index 9a860e9206fa..a8dffb520d96 100644 --- a/lms/djangoapps/coursewarehistoryextended/migrations/0003_rename_studentmodulehistoryextended_student_module_student_module_idx.py +++ b/lms/djangoapps/coursewarehistoryextended/migrations/0003_rename_studentmodulehistoryextended_student_module_student_module_idx.py @@ -1,7 +1,7 @@ # Generated by Django 4.2.20 on 2025-05-15 03:30 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/coursewarehistoryextended/models.py b/lms/djangoapps/coursewarehistoryextended/models.py index 0ba1c22e06e8..1f3e9c08d7b7 100644 --- a/lms/djangoapps/coursewarehistoryextended/models.py +++ b/lms/djangoapps/coursewarehistoryextended/models.py @@ -18,8 +18,8 @@ from django.db.models.signals import post_delete, post_save from django.dispatch import receiver -from lms.djangoapps.courseware.models import BaseStudentModuleHistory, StudentModule from lms.djangoapps.courseware.fields import UnsignedBigIntAutoField +from lms.djangoapps.courseware.models import BaseStudentModuleHistory, StudentModule class StudentModuleHistoryExtended(BaseStudentModuleHistory): diff --git a/lms/djangoapps/coursewarehistoryextended/tests.py b/lms/djangoapps/coursewarehistoryextended/tests.py index a97adb96f485..6ce723538834 100644 --- a/lms/djangoapps/coursewarehistoryextended/tests.py +++ b/lms/djangoapps/coursewarehistoryextended/tests.py @@ -15,9 +15,7 @@ from django.test import TestCase from lms.djangoapps.courseware.models import BaseStudentModuleHistory, StudentModule, StudentModuleHistory -from lms.djangoapps.courseware.tests.factories import COURSE_KEY -from lms.djangoapps.courseware.tests.factories import LOCATION -from lms.djangoapps.courseware.tests.factories import StudentModuleFactory +from lms.djangoapps.courseware.tests.factories import COURSE_KEY, LOCATION, StudentModuleFactory @skipUnless(settings.FEATURES["ENABLE_CSMH_EXTENDED"], "CSMH Extended needs to be enabled") diff --git a/lms/djangoapps/discussion/apps.py b/lms/djangoapps/discussion/apps.py index ece56abc1f94..274558c2fae2 100644 --- a/lms/djangoapps/discussion/apps.py +++ b/lms/djangoapps/discussion/apps.py @@ -40,5 +40,5 @@ def ready(self): """ Connect handlers to send notifications about discussions. """ + from .rest_api import tasks # pylint: disable=unused-import from .signals import handlers # pylint: disable=unused-import - from .rest_api import tasks # pylint: disable=unused-import diff --git a/lms/djangoapps/discussion/django_comment_client/base/tests_v2.py b/lms/djangoapps/discussion/django_comment_client/base/tests_v2.py index 1f5ae7805740..3fc2718e2e01 100644 --- a/lms/djangoapps/discussion/django_comment_client/base/tests_v2.py +++ b/lms/djangoapps/discussion/django_comment_client/base/tests_v2.py @@ -1,7 +1,6 @@ # pylint: skip-file """Tests for django comment client views.""" -import pytest import json import logging from contextlib import contextmanager @@ -9,6 +8,7 @@ from unittest.mock import ANY, Mock, patch import ddt +import pytest from django.contrib.auth.models import User from django.core.management import call_command from django.test.client import RequestFactory @@ -16,43 +16,31 @@ from eventtracking.processors.exceptions import EventEmissionExit from opaque_keys.edx.keys import CourseKey from openedx_events.learning.signals import ( + FORUM_RESPONSE_COMMENT_CREATED, FORUM_THREAD_CREATED, FORUM_THREAD_RESPONSE_CREATED, - FORUM_RESPONSE_COMMENT_CREATED, ) from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory from common.djangoapps.student.roles import CourseStaffRole, UserBasedRole -from common.djangoapps.student.tests.factories import ( - CourseAccessRoleFactory, - CourseEnrollmentFactory, - UserFactory, -) +from common.djangoapps.student.tests.factories import CourseAccessRoleFactory, CourseEnrollmentFactory, UserFactory from common.djangoapps.track.middleware import TrackMiddleware from common.djangoapps.track.views import segmentio -from common.djangoapps.track.views.tests.base import ( - SEGMENTIO_TEST_USER_ID, - SegmentIOTrackingTestCaseBase, -) +from common.djangoapps.track.views.tests.base import SEGMENTIO_TEST_USER_ID, SegmentIOTrackingTestCaseBase from common.djangoapps.util.testing import UrlResetMixin -from common.test.utils import MockSignalHandlerMixin, disable_signal, assert_dict_contains_subset +from common.test.utils import MockSignalHandlerMixin, assert_dict_contains_subset, disable_signal from lms.djangoapps.discussion.django_comment_client.base import views from lms.djangoapps.discussion.django_comment_client.tests.group_id import ( CohortedTopicGroupIdTestMixinV2, GroupIdAssertionMixinV2, NonCohortedTopicGroupIdTestMixinV2, ) -from lms.djangoapps.discussion.django_comment_client.tests.unicode import ( - UnicodeTestMixin, -) -from lms.djangoapps.discussion.django_comment_client.tests.utils import ( - CohortedTestCase, -) -from lms.djangoapps.teams.tests.factories import ( - CourseTeamFactory, - CourseTeamMembershipFactory, -) +from lms.djangoapps.discussion.django_comment_client.tests.mixins import MockForumApiMixin +from lms.djangoapps.discussion.django_comment_client.tests.unicode import UnicodeTestMixin +from lms.djangoapps.discussion.django_comment_client.tests.utils import CohortedTestCase +from lms.djangoapps.discussion.tests.utils import make_minimal_cs_comment, make_minimal_cs_thread +from lms.djangoapps.teams.tests.factories import CourseTeamFactory, CourseTeamMembershipFactory from openedx.core.djangoapps.course_groups.cohorts import set_course_cohorted from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory from openedx.core.djangoapps.django_comment_common.comment_client import Thread @@ -62,10 +50,7 @@ Role, assign_role, ) -from openedx.core.djangoapps.django_comment_common.utils import ( - ThreadContext, - seed_permissions_roles, -) +from openedx.core.djangoapps.django_comment_common.utils import ThreadContext, seed_permissions_roles from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES from openedx.core.lib.teams_config import TeamsConfig from xmodule.modulestore import ModuleStoreEnum @@ -75,21 +60,9 @@ ModuleStoreTestCase, SharedModuleStoreTestCase, ) -from xmodule.modulestore.tests.factories import ( - CourseFactory, - BlockFactory, - check_mongo_calls, -) +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory, check_mongo_calls from .event_transformers import ForumThreadViewedEventTransformer -from lms.djangoapps.discussion.django_comment_client.tests.mixins import ( - MockForumApiMixin, -) - -from lms.djangoapps.discussion.tests.utils import ( - make_minimal_cs_thread, - make_minimal_cs_comment, -) QUERY_COUNT_TABLE_IGNORELIST = WAFFLE_TABLES diff --git a/lms/djangoapps/discussion/django_comment_client/base/views.py b/lms/djangoapps/discussion/django_comment_client/base/views.py index e40ee4ef58bb..69feeba891f1 100644 --- a/lms/djangoapps/discussion/django_comment_client/base/views.py +++ b/lms/djangoapps/discussion/django_comment_client/base/views.py @@ -20,22 +20,18 @@ from openedx_events.learning.signals import ( FORUM_RESPONSE_COMMENT_CREATED, FORUM_THREAD_CREATED, - FORUM_THREAD_RESPONSE_CREATED + FORUM_THREAD_RESPONSE_CREATED, ) import lms.djangoapps.discussion.django_comment_client.settings as cc_settings import openedx.core.djangoapps.django_comment_common.comment_client as cc -from openedx.core.djangoapps.django_comment_common.models import has_permission from common.djangoapps.student.roles import GlobalStaff from common.djangoapps.track import contexts from common.djangoapps.util.file import store_uploaded_file from lms.djangoapps.courseware.access import has_access from lms.djangoapps.courseware.courses import get_course_overview_with_access, get_course_with_access from lms.djangoapps.courseware.exceptions import CourseAccessRedirect -from lms.djangoapps.discussion.django_comment_client.permissions import ( - check_permissions_by_view, - get_team -) +from lms.djangoapps.discussion.django_comment_client.permissions import check_permissions_by_view, get_team from lms.djangoapps.discussion.django_comment_client.utils import ( JsonError, JsonResponse, @@ -48,9 +44,10 @@ get_user_group_ids, is_comment_too_deep, prepare_content, - sanitize_body + sanitize_body, ) from lms.djangoapps.discussion.rest_api.utils import send_signal_after_commit +from openedx.core.djangoapps.django_comment_common.models import has_permission from openedx.core.djangoapps.django_comment_common.signals import ( comment_created, comment_deleted, @@ -64,7 +61,7 @@ thread_flagged, thread_followed, thread_unfollowed, - thread_voted + thread_voted, ) from openedx.core.djangoapps.django_comment_common.utils import ThreadContext from openedx.core.lib.courses import get_course_by_id diff --git a/lms/djangoapps/discussion/django_comment_client/permissions.py b/lms/djangoapps/discussion/django_comment_client/permissions.py index 4801a461c608..f9cbfa4fc148 100644 --- a/lms/djangoapps/discussion/django_comment_client/permissions.py +++ b/lms/djangoapps/discussion/django_comment_client/permissions.py @@ -10,13 +10,9 @@ from lms.djangoapps.teams.models import CourseTeam from openedx.core.djangoapps.django_comment_common.comment_client import Thread -from openedx.core.djangoapps.django_comment_common.models import ( - CourseDiscussionSettings, - has_permission -) +from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings, has_permission from openedx.core.lib.cache_utils import request_cached - CONDITIONS = ['is_open', 'is_author', 'is_question_author', 'is_team_member_if_applicable'] diff --git a/lms/djangoapps/discussion/django_comment_client/tests/test_models.py b/lms/djangoapps/discussion/django_comment_client/tests/test_models.py index 098eedf51eda..a81d877c6424 100644 --- a/lms/djangoapps/discussion/django_comment_client/tests/test_models.py +++ b/lms/djangoapps/discussion/django_comment_client/tests/test_models.py @@ -5,13 +5,10 @@ from django.test.testcases import TestCase from opaque_keys.edx.keys import CourseKey -from xmodule.modulestore.tests.django_utils import ( - TEST_DATA_SPLIT_MODULESTORE, - ModuleStoreTestCase -) -from xmodule.modulestore.tests.factories import ToyCourseFactory import openedx.core.djangoapps.django_comment_common.models as models +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import ToyCourseFactory class RoleClassTestCase(ModuleStoreTestCase): diff --git a/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py b/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py index 742eb23bf5dc..acd2a936abfa 100644 --- a/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py +++ b/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py @@ -19,8 +19,12 @@ from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory from common.djangoapps.student.roles import CourseStaffRole -from common.djangoapps.student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory -from common.djangoapps.student.tests.factories import InstructorFactory +from common.djangoapps.student.tests.factories import ( + AdminFactory, + CourseEnrollmentFactory, + InstructorFactory, + UserFactory, +) from lms.djangoapps.courseware.tabs import get_course_tab_list from lms.djangoapps.discussion.django_comment_client.constants import TYPE_ENTRY, TYPE_SUBCATEGORY from lms.djangoapps.discussion.django_comment_client.tests.factories import RoleFactory @@ -37,19 +41,17 @@ get_group_names_by_id, has_required_keys, ) -from openedx.core.djangoapps.django_comment_common.comment_client.utils import ( - CommentClientMaintenanceError, -) +from openedx.core.djangoapps.django_comment_common.comment_client.utils import CommentClientMaintenanceError from openedx.core.djangoapps.django_comment_common.models import ( CourseDiscussionSettings, DiscussionsIdMapping, - assign_role + assign_role, ) from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles from openedx.core.djangoapps.util.testing import ContentGroupTestCase 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, BlockFactory, ToyCourseFactory +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory, ToyCourseFactory class DictionaryTestCase(TestCase): diff --git a/lms/djangoapps/discussion/django_comment_client/tests/utils.py b/lms/djangoapps/discussion/django_comment_client/tests/utils.py index bc3fdffa11d0..801a4554a3aa 100644 --- a/lms/djangoapps/discussion/django_comment_client/tests/utils.py +++ b/lms/djangoapps/discussion/django_comment_client/tests/utils.py @@ -5,17 +5,16 @@ from unittest.mock import patch -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory - from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from common.djangoapps.util.testing import UrlResetMixin from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings, Role from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles from openedx.core.lib.teams_config import TeamsConfig +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 class CohortedTestCase(UrlResetMixin, SharedModuleStoreTestCase): diff --git a/lms/djangoapps/discussion/django_comment_client/utils.py b/lms/djangoapps/discussion/django_comment_client/utils.py index a0bb6b769183..cdf56ab8dea8 100644 --- a/lms/djangoapps/discussion/django_comment_client/utils.py +++ b/lms/djangoapps/discussion/django_comment_client/utils.py @@ -1,14 +1,12 @@ # pylint: skip-file import json import logging - import re -from typing import Set - -import regex from collections import defaultdict from datetime import datetime +from typing import Set +import regex from django.conf import settings from django.contrib.auth.models import User from django.db import connection @@ -18,16 +16,13 @@ from opaque_keys.edx.keys import CourseKey, UsageKey, i4xEncoder from pytz import UTC +import openedx.core.djangoapps.django_comment_common.comment_client as cc from common.djangoapps.student.models import get_user_by_username_or_email from common.djangoapps.student.roles import GlobalStaff from lms.djangoapps.courseware.access import has_access from lms.djangoapps.discussion.django_comment_client.constants import TYPE_ENTRY, TYPE_SUBCATEGORY -from lms.djangoapps.discussion.django_comment_client.permissions import ( - check_permissions_by_view, - get_team -) +from lms.djangoapps.discussion.django_comment_client.permissions import check_permissions_by_view, get_team from lms.djangoapps.discussion.django_comment_client.settings import MAX_COMMENT_DEPTH -from openedx.core.djangoapps.django_comment_common.models import has_permission from openedx.core.djangoapps.course_groups.cohorts import get_cohort_id from openedx.core.djangoapps.discussions.utils import ( get_accessible_discussion_xblocks, @@ -37,14 +32,17 @@ get_group_names_by_id, has_required_keys, ) -import openedx.core.djangoapps.django_comment_common.comment_client as cc from openedx.core.djangoapps.django_comment_common.models import ( + FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, + FORUM_ROLE_GROUP_MODERATOR, + FORUM_ROLE_MODERATOR, FORUM_ROLE_STUDENT, CourseDiscussionSettings, DiscussionsIdMapping, Role, - FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_GROUP_MODERATOR) + has_permission, +) from openedx.core.lib.cache_utils import request_cached from openedx.core.lib.courses import get_course_by_id from xmodule.modulestore.django import modulestore diff --git a/lms/djangoapps/discussion/notification_prefs/tests.py b/lms/djangoapps/discussion/notification_prefs/tests.py index ea775185afdb..d7b01bad4ca4 100644 --- a/lms/djangoapps/discussion/notification_prefs/tests.py +++ b/lms/djangoapps/discussion/notification_prefs/tests.py @@ -18,7 +18,7 @@ ajax_disable, ajax_enable, ajax_status, - set_subscription + set_subscription, ) from openedx.core.djangoapps.user_api.models import UserPreference diff --git a/lms/djangoapps/discussion/plugins.py b/lms/djangoapps/discussion/plugins.py index e7edbf6f4a53..f8078b8e6c25 100644 --- a/lms/djangoapps/discussion/plugins.py +++ b/lms/djangoapps/discussion/plugins.py @@ -7,15 +7,13 @@ from django.urls import reverse from django.utils.translation import gettext_noop - +import lms.djangoapps.discussion.django_comment_client.utils as utils +from lms.djangoapps.courseware.tabs import EnrolledTab from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration from openedx.core.djangoapps.discussions.url_helpers import get_discussions_mfe_url -from xmodule.tabs import TabFragmentViewMixin - -import lms.djangoapps.discussion.django_comment_client.utils as utils -from lms.djangoapps.courseware.tabs import EnrolledTab from openedx.features.lti_course_tab.tab import DiscussionLtiCourseTab +from xmodule.tabs import TabFragmentViewMixin class DiscussionTab(TabFragmentViewMixin, EnrolledTab): diff --git a/lms/djangoapps/discussion/rate_limit.py b/lms/djangoapps/discussion/rate_limit.py index bd810bbca612..7ce28c8269eb 100644 --- a/lms/djangoapps/discussion/rate_limit.py +++ b/lms/djangoapps/discussion/rate_limit.py @@ -2,10 +2,11 @@ Contains all code related to rate limit """ from datetime import timedelta + from django.conf import settings +from django.utils import timezone from django_ratelimit import ALL from django_ratelimit.core import is_ratelimited as _ratelimit -from django.utils import timezone from opaque_keys.edx.keys import CourseKey from common.djangoapps.student.models import CourseAccessRole @@ -15,10 +16,9 @@ FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_GROUP_MODERATOR, FORUM_ROLE_MODERATOR, - Role + Role, ) - CONTENT_CREATION_GROUP = "content_creation" diff --git a/lms/djangoapps/discussion/rest_api/api.py b/lms/djangoapps/discussion/rest_api/api.py index 443f9527acda..2993e9e38db7 100644 --- a/lms/djangoapps/discussion/rest_api/api.py +++ b/lms/djangoapps/discussion/rest_api/api.py @@ -7,11 +7,9 @@ import re from collections import defaultdict from datetime import datetime - from enum import Enum from typing import Dict, Iterable, List, Literal, Optional, Set, Tuple from urllib.parse import urlencode, urlunparse -from pytz import UTC from django.conf import settings from django.contrib.auth import get_user_model @@ -22,38 +20,31 @@ from edx_django_utils.monitoring import function_trace from opaque_keys import InvalidKeyError from opaque_keys.edx.locator import CourseKey +from pytz import UTC from rest_framework import status from rest_framework.exceptions import PermissionDenied from rest_framework.request import Request from rest_framework.response import Response -from common.djangoapps.student.roles import ( - CourseInstructorRole, - CourseStaffRole, -) - +from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole from lms.djangoapps.course_api.blocks.api import get_blocks from lms.djangoapps.courseware.courses import get_course_with_access from lms.djangoapps.courseware.exceptions import CourseAccessRedirect from lms.djangoapps.discussion.rate_limit import is_content_creation_rate_limited from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE, ONLY_VERIFIED_USERS_CAN_POST from lms.djangoapps.discussion.views import is_privileged_user -from openedx.core.djangoapps.discussions.models import ( - DiscussionsConfiguration, - DiscussionTopicLink, - Provider, -) +from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, DiscussionTopicLink, Provider from openedx.core.djangoapps.discussions.utils import get_accessible_discussion_xblocks from openedx.core.djangoapps.django_comment_common import comment_client from openedx.core.djangoapps.django_comment_common.comment_client.comment import Comment from openedx.core.djangoapps.django_comment_common.comment_client.course import ( get_course_commentable_counts, - get_course_user_stats + get_course_user_stats, ) from openedx.core.djangoapps.django_comment_common.comment_client.thread import Thread from openedx.core.djangoapps.django_comment_common.comment_client.utils import ( CommentClient500Error, - CommentClientRequestError + CommentClientRequestError, ) from openedx.core.djangoapps.django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, @@ -61,13 +52,13 @@ FORUM_ROLE_GROUP_MODERATOR, FORUM_ROLE_MODERATOR, CourseDiscussionSettings, - Role + Role, ) from openedx.core.djangoapps.django_comment_common.signals import ( comment_created, comment_deleted, - comment_endorsed, comment_edited, + comment_endorsed, comment_flagged, comment_voted, thread_created, @@ -75,8 +66,8 @@ thread_edited, thread_flagged, thread_followed, + thread_unfollowed, thread_voted, - thread_unfollowed ) from openedx.core.djangoapps.user_api.accounts.api import get_account_settings from openedx.core.lib.exceptions import CourseNotFoundError, DiscussionNotFoundError, PageNotFoundError @@ -88,19 +79,20 @@ from ..django_comment_client.base.views import ( track_comment_created_event, track_comment_deleted_event, + track_discussion_reported_event, + track_discussion_unreported_event, + track_forum_search_event, track_thread_created_event, track_thread_deleted_event, + track_thread_followed_event, track_thread_viewed_event, track_voted_event, - track_discussion_reported_event, - track_discussion_unreported_event, - track_forum_search_event, track_thread_followed_event ) from ..django_comment_client.utils import ( get_group_id_for_user, get_user_role_names, has_discussion_privileges, - is_commentable_divided + is_commentable_divided, ) from .exceptions import CommentNotFoundError, DiscussionBlackOutException, DiscussionDisabledError, ThreadNotFoundError from .forms import CommentActionsForm, ThreadActionsForm, UserOrdering @@ -110,7 +102,7 @@ can_take_action_on_spam, get_editable_fields, get_initializable_comment_fields, - get_initializable_thread_fields + get_initializable_thread_fields, ) from .serializers import ( CommentSerializer, @@ -119,19 +111,21 @@ ThreadSerializer, TopicOrdering, UserStatsSerializer, - get_context + get_context, ) from .utils import ( AttributeDict, add_stats_for_users_with_no_discussion_content, + can_user_notify_all_learners, create_blocks_params, discussion_open_for_user, + get_captcha_site_key_by_platform, get_usernames_for_course, get_usernames_from_search_string, + is_captcha_enabled, + is_posting_allowed, send_signal_after_commit, set_attribute, - is_posting_allowed, - can_user_notify_all_learners, is_captcha_enabled, get_captcha_site_key_by_platform ) User = get_user_model() diff --git a/lms/djangoapps/discussion/rest_api/discussions_notifications.py b/lms/djangoapps/discussion/rest_api/discussions_notifications.py index 3325e0007d6f..9f235cdba745 100644 --- a/lms/djangoapps/discussion/rest_api/discussions_notifications.py +++ b/lms/djangoapps/discussion/rest_api/discussions_notifications.py @@ -1,21 +1,19 @@ """ Discussion notifications sender util. """ -import re import html +import re from bs4 import BeautifulSoup, Tag from django.conf import settings from django.utils.text import Truncator +from django.utils.translation import gettext_lazy as _ +from openedx_events.learning.data import CourseNotificationData, UserNotificationData +from openedx_events.learning.signals import COURSE_NOTIFICATION_REQUESTED, USER_NOTIFICATION_REQUESTED from lms.djangoapps.discussion.django_comment_client.permissions import get_team -from openedx_events.learning.data import UserNotificationData, CourseNotificationData -from openedx_events.learning.signals import USER_NOTIFICATION_REQUESTED, COURSE_NOTIFICATION_REQUESTED - from openedx.core.djangoapps.course_groups.models import CourseCohortsSettings from openedx.core.djangoapps.discussions.utils import get_divided_discussions -from django.utils.translation import gettext_lazy as _ - from openedx.core.djangoapps.django_comment_common.comment_client.comment import Comment from openedx.core.djangoapps.django_comment_common.comment_client.subscriptions import Subscription from openedx.core.djangoapps.django_comment_common.models import ( diff --git a/lms/djangoapps/discussion/rest_api/permissions.py b/lms/djangoapps/discussion/rest_api/permissions.py index cfcea5b32834..10e37d09406a 100644 --- a/lms/djangoapps/discussion/rest_api/permissions.py +++ b/lms/djangoapps/discussion/rest_api/permissions.py @@ -7,19 +7,15 @@ from rest_framework import permissions from common.djangoapps.student.models import CourseAccessRole, CourseEnrollment -from common.djangoapps.student.roles import ( - CourseInstructorRole, - CourseStaffRole, - GlobalStaff, -) -from lms.djangoapps.discussion.django_comment_client.utils import ( - get_user_role_names, - has_discussion_privileges, -) +from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole, GlobalStaff +from lms.djangoapps.discussion.django_comment_client.utils import get_user_role_names, has_discussion_privileges from openedx.core.djangoapps.django_comment_common.comment_client.comment import Comment from openedx.core.djangoapps.django_comment_common.comment_client.thread import Thread from openedx.core.djangoapps.django_comment_common.models import ( - Role, FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_MODERATOR + FORUM_ROLE_ADMINISTRATOR, + FORUM_ROLE_COMMUNITY_TA, + FORUM_ROLE_MODERATOR, + Role, ) diff --git a/lms/djangoapps/discussion/rest_api/render.py b/lms/djangoapps/discussion/rest_api/render.py index 025399d5372f..1f59ff44304f 100644 --- a/lms/djangoapps/discussion/rest_api/render.py +++ b/lms/djangoapps/discussion/rest_api/render.py @@ -4,8 +4,8 @@ Note that this module is designed to imitate the front end behavior as implemented in Markdown.Sanitizer.js. """ -import nh3 import markdown +import nh3 ALLOWED_TAGS = nh3.ALLOWED_TAGS | { 'br', 'dd', 'del', 'dl', 'dt', 'h1', 'h2', 'h3', 'h4', 'hr', 'img', 'kbd', 'p', 'pre', 's', diff --git a/lms/djangoapps/discussion/rest_api/serializers.py b/lms/djangoapps/discussion/rest_api/serializers.py index 9c2668d0b226..007d88d92bb3 100644 --- a/lms/djangoapps/discussion/rest_api/serializers.py +++ b/lms/djangoapps/discussion/rest_api/serializers.py @@ -3,11 +3,10 @@ """ import html import re - -from bs4 import BeautifulSoup from typing import Dict from urllib.parse import urlencode, urlunparse +from bs4 import BeautifulSoup from django.conf import settings from django.contrib.auth import get_user_model from django.core.exceptions import ObjectDoesNotExist, ValidationError @@ -18,8 +17,12 @@ from common.djangoapps.student.models import get_user_by_username_or_email from common.djangoapps.student.roles import GlobalStaff -from lms.djangoapps.discussion.django_comment_client.base.views import track_thread_lock_unlock_event, \ - track_thread_edited_event, track_comment_edited_event, track_forum_response_mark_event +from lms.djangoapps.discussion.django_comment_client.base.views import ( + track_comment_edited_event, + track_forum_response_mark_event, + track_thread_edited_event, + track_thread_lock_unlock_event, +) from lms.djangoapps.discussion.django_comment_client.utils import ( course_discussion_division_enabled, get_group_id_for_user, @@ -35,8 +38,8 @@ from lms.djangoapps.discussion.rest_api.render import render_body from lms.djangoapps.discussion.rest_api.utils import ( get_course_staff_users_list, - get_moderator_users_list, get_course_ta_users_list, + get_moderator_users_list, ) from openedx.core.djangoapps.discussions.models import DiscussionTopicLink from openedx.core.djangoapps.discussions.utils import get_group_names_by_id diff --git a/lms/djangoapps/discussion/rest_api/tasks.py b/lms/djangoapps/discussion/rest_api/tasks.py index ec5c8ca60520..abbf4556be80 100644 --- a/lms/djangoapps/discussion/rest_api/tasks.py +++ b/lms/djangoapps/discussion/rest_api/tasks.py @@ -6,10 +6,10 @@ from celery import shared_task from django.contrib.auth import get_user_model from edx_django_utils.monitoring import set_code_owner_attribute -from opaque_keys.edx.locator import CourseKey from eventtracking import tracker +from opaque_keys.edx.locator import CourseKey -from common.djangoapps.student.roles import CourseStaffRole, CourseInstructorRole +from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole from common.djangoapps.track import segment from lms.djangoapps.courseware.courses import get_course_with_access from lms.djangoapps.discussion.django_comment_client.utils import get_user_role_names @@ -19,7 +19,6 @@ from openedx.core.djangoapps.django_comment_common.comment_client.thread import Thread from openedx.core.djangoapps.notifications.config.waffle import DISABLE_NOTIFICATIONS - User = get_user_model() log = logging.getLogger(__name__) diff --git a/lms/djangoapps/discussion/rest_api/tests/test_api.py b/lms/djangoapps/discussion/rest_api/tests/test_api.py index 480568d115ec..24ca7a1254da 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_api.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_api.py @@ -10,18 +10,12 @@ from django.test.client import RequestFactory from opaque_keys.edx.keys import CourseKey -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory - -from common.djangoapps.student.tests.factories import ( - UserFactory -) +from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.discussion.rest_api.api import get_user_comments -from lms.djangoapps.discussion.rest_api.tests.utils import ( - ForumMockUtilsMixin, - make_minimal_cs_comment, -) +from lms.djangoapps.discussion.rest_api.tests.utils import ForumMockUtilsMixin, make_minimal_cs_comment from openedx.core.lib.exceptions import CourseNotFoundError, PageNotFoundError +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory User = get_user_model() diff --git a/lms/djangoapps/discussion/rest_api/tests/test_api_v2.py b/lms/djangoapps/discussion/rest_api/tests/test_api_v2.py index df4ac947bf0d..76aa080f4501 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_api_v2.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_api_v2.py @@ -16,24 +16,15 @@ import ddt import httpretty import pytest -from django.test import override_settings from django.contrib.auth import get_user_model from django.core.exceptions import ValidationError +from django.test import override_settings from django.test.client import RequestFactory from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import CourseLocator from pytz import UTC from rest_framework.exceptions import PermissionDenied -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, BlockFactory -from xmodule.partitions.partitions import Group, UserPartition - from common.djangoapps.student.tests.factories import ( AdminFactory, BetaTesterFactory, @@ -43,10 +34,6 @@ ) from common.djangoapps.util.testing import UrlResetMixin from common.test.utils import MockSignalHandlerMixin, disable_signal -from lms.djangoapps.discussion.tests.utils import ( - make_minimal_cs_comment, - make_minimal_cs_thread, -) from lms.djangoapps.discussion.rest_api import api from lms.djangoapps.discussion.rest_api.api import ( create_comment, @@ -76,17 +63,16 @@ make_paginated_api_response, parsed_body, ) +from lms.djangoapps.discussion.tests.utils import make_minimal_cs_comment, make_minimal_cs_thread from openedx.core.djangoapps.course_groups.models import CourseUserGroupPartitionGroup from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory from openedx.core.djangoapps.discussions.models import ( DiscussionsConfiguration, DiscussionTopicLink, - Provider, PostingRestriction, + Provider, ) -from openedx.core.djangoapps.discussions.tasks import ( - update_discussions_settings_from_course_task, -) +from openedx.core.djangoapps.discussions.tasks import update_discussions_settings_from_course_task from openedx.core.djangoapps.django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, @@ -96,6 +82,11 @@ Role, ) from openedx.core.lib.exceptions import CourseNotFoundError, PageNotFoundError +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 BlockFactory, CourseFactory +from xmodule.partitions.partitions import Group, UserPartition User = get_user_model() diff --git a/lms/djangoapps/discussion/rest_api/tests/test_discussions_notifications.py b/lms/djangoapps/discussion/rest_api/tests/test_discussions_notifications.py index aaa920a0ff78..3c713ec9ff30 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_discussions_notifications.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_discussions_notifications.py @@ -7,8 +7,10 @@ import pytest -from lms.djangoapps.discussion.rest_api.discussions_notifications import DiscussionNotificationSender, \ - clean_thread_html_body +from lms.djangoapps.discussion.rest_api.discussions_notifications import ( + DiscussionNotificationSender, + clean_thread_html_body, +) @patch('lms.djangoapps.discussion.rest_api.discussions_notifications.DiscussionNotificationSender' diff --git a/lms/djangoapps/discussion/rest_api/tests/test_forms.py b/lms/djangoapps/discussion/rest_api/tests/test_forms.py index 3be65964b6b9..51f53a9a2a44 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_forms.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_forms.py @@ -11,11 +11,7 @@ from django.http import QueryDict from opaque_keys.edx.locator import CourseLocator -from lms.djangoapps.discussion.rest_api.forms import ( - UserCommentListGetForm, - CommentListGetForm, - ThreadListGetForm, -) +from lms.djangoapps.discussion.rest_api.forms import CommentListGetForm, ThreadListGetForm, UserCommentListGetForm from openedx.core.djangoapps.util.test_forms import FormTestMixin diff --git a/lms/djangoapps/discussion/rest_api/tests/test_permissions.py b/lms/djangoapps/discussion/rest_api/tests/test_permissions.py index 405726e2125b..547a6cbb4453 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_permissions.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_permissions.py @@ -6,18 +6,18 @@ import itertools import ddt -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from lms.djangoapps.discussion.rest_api.permissions import ( can_delete, get_editable_fields, get_initializable_comment_fields, - get_initializable_thread_fields + get_initializable_thread_fields, ) from openedx.core.djangoapps.django_comment_common.comment_client.comment import Comment from openedx.core.djangoapps.django_comment_common.comment_client.thread import Thread from openedx.core.djangoapps.django_comment_common.comment_client.user import User +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory def _get_context( diff --git a/lms/djangoapps/discussion/rest_api/tests/test_serializers_v2.py b/lms/djangoapps/discussion/rest_api/tests/test_serializers_v2.py index e45e66280ce2..412501c4fd19 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_serializers_v2.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_serializers_v2.py @@ -9,10 +9,6 @@ import ddt import httpretty from django.test.client import RequestFactory -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.util.testing import UrlResetMixin @@ -32,6 +28,10 @@ FORUM_ROLE_STUDENT, Role, ) +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 @ddt.ddt diff --git a/lms/djangoapps/discussion/rest_api/tests/test_tasks_v2.py b/lms/djangoapps/discussion/rest_api/tests/test_tasks_v2.py index be8b408a26dd..15419c2ce698 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_tasks_v2.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_tasks_v2.py @@ -15,7 +15,7 @@ from lms.djangoapps.discussion.rest_api.tasks import ( send_response_endorsed_notifications, send_response_notifications, - send_thread_created_notification + send_thread_created_notification, ) from lms.djangoapps.discussion.rest_api.tests.utils import ThreadMock, make_minimal_cs_thread from openedx.core.djangoapps.course_groups.models import CohortMembership, CourseCohortsSettings @@ -26,7 +26,7 @@ FORUM_ROLE_GROUP_MODERATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_STUDENT, - CourseDiscussionSettings + CourseDiscussionSettings, ) from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/lms/djangoapps/discussion/rest_api/tests/test_utils.py b/lms/djangoapps/discussion/rest_api/tests/test_utils.py index c6af74d83dc3..b5d769890c92 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_utils.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_utils.py @@ -18,9 +18,9 @@ get_course_staff_users_list, get_course_ta_users_list, get_moderator_users_list, + is_only_student, is_posting_allowed, remove_empty_sequentials, - is_only_student ) from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, PostingRestriction from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase diff --git a/lms/djangoapps/discussion/rest_api/tests/test_views.py b/lms/djangoapps/discussion/rest_api/tests/test_views.py index 619f5c2e7d7b..ac5e5e89463d 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_views.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_views.py @@ -12,20 +12,16 @@ from pytz import UTC from rest_framework import status -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory - from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole, GlobalStaff -from common.djangoapps.student.tests.factories import ( - CourseEnrollmentFactory, - UserFactory -) +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from common.djangoapps.util.testing import UrlResetMixin from lms.djangoapps.discussion.rest_api.tests.utils import ( ForumMockUtilsMixin, make_minimal_cs_comment, make_minimal_cs_thread, ) +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory @ddt.ddt diff --git a/lms/djangoapps/discussion/rest_api/tests/test_views_v2.py b/lms/djangoapps/discussion/rest_api/tests/test_views_v2.py index 10251224ad7d..8168c98e3b96 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_views_v2.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_views_v2.py @@ -24,51 +24,44 @@ from rest_framework.parsers import JSONParser from rest_framework.test import APIClient, APITestCase -from lms.djangoapps.discussion.django_comment_client.tests.utils import ( - config_course_discussions, - topic_name_to_id, +from common.djangoapps.course_modes.models import CourseMode +from common.djangoapps.course_modes.tests.factories import CourseModeFactory +from common.djangoapps.student.models import CourseEnrollment, get_retired_username_by_username +from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole, GlobalStaff +from common.djangoapps.student.tests.factories import ( + AdminFactory, + CourseEnrollmentFactory, + SuperuserFactory, + UserFactory, ) +from common.djangoapps.util.testing import PatchMediaTypeMixin, UrlResetMixin +from common.test.utils import disable_signal +from lms.djangoapps.discussion.django_comment_client.tests.utils import config_course_discussions, topic_name_to_id from lms.djangoapps.discussion.rest_api import api from lms.djangoapps.discussion.rest_api.tests.utils import ( CommentsServiceMockMixin, ForumMockUtilsMixin, ProfileImageTestMixin, - make_paginated_api_response, make_minimal_cs_comment, make_minimal_cs_thread, + make_paginated_api_response, ) from lms.djangoapps.discussion.rest_api.utils import get_usernames_from_search_string from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE -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, BlockFactory, check_mongo_calls - -from common.djangoapps.course_modes.models import CourseMode -from common.djangoapps.course_modes.tests.factories import CourseModeFactory -from common.djangoapps.student.tests.factories import ( - AdminFactory, - CourseEnrollmentFactory, - SuperuserFactory, - UserFactory -) -from common.djangoapps.student.models import get_retired_username_by_username, CourseEnrollment -from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole, GlobalStaff -from common.djangoapps.util.testing import PatchMediaTypeMixin, UrlResetMixin -from common.test.utils import disable_signal - from openedx.core.djangoapps.course_groups.tests.helpers import config_course_cohorts +from openedx.core.djangoapps.discussions.config.waffle import ENABLE_NEW_STRUCTURE_DISCUSSIONS from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, DiscussionTopicLink, Provider from openedx.core.djangoapps.discussions.tasks import update_discussions_settings_from_course_task +from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings, Role +from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_for_user from openedx.core.djangoapps.oauth_dispatch.tests.factories import AccessTokenFactory, ApplicationFactory -from openedx.core.djangoapps.user_api.models import RetirementState, UserRetirementStatus -from openedx.core.djangoapps.django_comment_common.models import ( - CourseDiscussionSettings, Role -) -from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles -from openedx.core.djangoapps.discussions.config.waffle import ENABLE_NEW_STRUCTURE_DISCUSSIONS from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_image_storage +from openedx.core.djangoapps.user_api.models import RetirementState, UserRetirementStatus +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 BlockFactory, CourseFactory, check_mongo_calls class DiscussionAPIViewTestMixin(ForumMockUtilsMixin, UrlResetMixin): diff --git a/lms/djangoapps/discussion/rest_api/utils.py b/lms/djangoapps/discussion/rest_api/utils.py index a2591655adc2..25f7c7bbf09b 100644 --- a/lms/djangoapps/discussion/rest_api/utils.py +++ b/lms/djangoapps/discussion/rest_api/utils.py @@ -14,21 +14,21 @@ from django.db.models.functions import Length from pytz import UTC -from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole from common.djangoapps.student.models import CourseAccessRole -from openedx.core.djangoapps.django_comment_common.comment_client.thread import Thread - +from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole from lms.djangoapps.discussion.config.settings import ENABLE_CAPTCHA_IN_DISCUSSION from lms.djangoapps.discussion.django_comment_client.utils import has_discussion_privileges from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, PostingRestriction +from openedx.core.djangoapps.django_comment_common.comment_client.thread import Thread from openedx.core.djangoapps.django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_GROUP_MODERATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_STUDENT, - Role + Role, ) + from ..django_comment_client.utils import get_user_role_names log = logging.getLogger(__name__) diff --git a/lms/djangoapps/discussion/rest_api/views.py b/lms/djangoapps/discussion/rest_api/views.py index ba9818124e08..992fe91f2d45 100644 --- a/lms/djangoapps/discussion/rest_api/views.py +++ b/lms/djangoapps/discussion/rest_api/views.py @@ -5,7 +5,6 @@ import uuid import edx_api_doc_tools as apidocs - from django.contrib.auth import get_user_model from django.core.exceptions import BadRequest, ValidationError from django.shortcuts import get_object_or_404 @@ -21,31 +20,30 @@ from rest_framework.views import APIView from rest_framework.viewsets import ViewSet -from xmodule.modulestore.django import modulestore - from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.util.file import store_uploaded_file from lms.djangoapps.course_api.blocks.api import get_blocks from lms.djangoapps.course_goals.models import UserActivity +from lms.djangoapps.discussion.django_comment_client import settings as cc_settings +from lms.djangoapps.discussion.django_comment_client.utils import get_group_id_for_comments_service from lms.djangoapps.discussion.rate_limit import is_content_creation_rate_limited from lms.djangoapps.discussion.rest_api.permissions import IsAllowedToBulkDelete from lms.djangoapps.discussion.rest_api.tasks import delete_course_post_for_user from lms.djangoapps.discussion.toggles import ONLY_VERIFIED_USERS_CAN_POST -from lms.djangoapps.discussion.django_comment_client import settings as cc_settings -from lms.djangoapps.discussion.django_comment_client.utils import get_group_id_for_comments_service from lms.djangoapps.instructor.access import update_forum_role from openedx.core.djangoapps.discussions.config.waffle import ENABLE_NEW_STRUCTURE_DISCUSSIONS from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, Provider from openedx.core.djangoapps.discussions.serializers import DiscussionSettingsSerializer from openedx.core.djangoapps.django_comment_common import comment_client -from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings, Role from openedx.core.djangoapps.django_comment_common.comment_client.comment import Comment from openedx.core.djangoapps.django_comment_common.comment_client.thread import Thread +from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings, Role from openedx.core.djangoapps.user_api.accounts.permissions import CanReplaceUsername, CanRetireUser from openedx.core.djangoapps.user_api.models import UserRetirementStatus from openedx.core.lib.api.authentication import BearerAuthentication, BearerAuthenticationAllowInactiveUser 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 from ..rest_api.api import ( create_comment, @@ -57,10 +55,10 @@ get_course_discussion_user_stats, get_course_topics, get_course_topics_v2, + get_learner_active_thread_list, get_response_comments, get_thread, get_thread_list, - get_learner_active_thread_list, get_user_comments, get_v2_course_topics_as_v1, update_comment, @@ -88,10 +86,10 @@ from .utils import ( create_blocks_params, create_topics_v3_structure, - is_captcha_enabled, - verify_recaptcha_token, get_course_id_from_thread_id, + is_captcha_enabled, is_only_student, + verify_recaptcha_token, ) log = logging.getLogger(__name__) diff --git a/lms/djangoapps/discussion/signals/handlers.py b/lms/djangoapps/discussion/signals/handlers.py index ec14cd8281ce..97af9a727f13 100644 --- a/lms/djangoapps/discussion/signals/handlers.py +++ b/lms/djangoapps/discussion/signals/handlers.py @@ -15,7 +15,7 @@ from lms.djangoapps.discussion.rest_api.tasks import ( send_response_endorsed_notifications, send_response_notifications, - send_thread_created_notification + send_thread_created_notification, ) from openedx.core.djangoapps.django_comment_common import signals from openedx.core.djangoapps.site_configuration.models import SiteConfiguration diff --git a/lms/djangoapps/discussion/tasks.py b/lms/djangoapps/discussion/tasks.py index d483388f54ae..e503e6028cfa 100644 --- a/lms/djangoapps/discussion/tasks.py +++ b/lms/djangoapps/discussion/tasks.py @@ -20,23 +20,19 @@ from opaque_keys.edx.keys import CourseKey from six.moves.urllib.parse import urljoin -from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE -from lms.djangoapps.discussion.toggles_utils import reported_content_email_notification_enabled -from openedx.core.djangoapps.discussions.url_helpers import get_discussions_mfe_url -from xmodule.modulestore.django import modulestore - import openedx.core.djangoapps.django_comment_common.comment_client as cc from common.djangoapps.track import segment -from lms.djangoapps.discussion.django_comment_client.utils import ( - permalink, - get_users_with_moderator_roles, -) -from openedx.core.djangoapps.discussions.utils import get_accessible_discussion_xblocks_by_course_id +from lms.djangoapps.discussion.django_comment_client.utils import get_users_with_moderator_roles, permalink +from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE +from lms.djangoapps.discussion.toggles_utils import reported_content_email_notification_enabled from openedx.core.djangoapps.ace_common.message import BaseMessageType from openedx.core.djangoapps.ace_common.template_context import get_base_template_context from openedx.core.djangoapps.content.course_overviews.models import CourseOverview +from openedx.core.djangoapps.discussions.url_helpers import get_discussions_mfe_url +from openedx.core.djangoapps.discussions.utils import get_accessible_discussion_xblocks_by_course_id from openedx.core.djangoapps.django_comment_common.models import DiscussionsIdMapping from openedx.core.lib.celery.task_utils import emulate_http_request +from xmodule.modulestore.django import modulestore log = logging.getLogger(__name__) diff --git a/lms/djangoapps/discussion/tests/test_signals.py b/lms/djangoapps/discussion/tests/test_signals.py index d61b706292cf..ff626396d124 100644 --- a/lms/djangoapps/discussion/tests/test_signals.py +++ b/lms/djangoapps/discussion/tests/test_signals.py @@ -5,15 +5,12 @@ from django.test import TestCase from edx_django_utils.cache import RequestCache -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import ( - CourseFactory, - BlockFactory -) from lms.djangoapps.discussion.signals.handlers import ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY from openedx.core.djangoapps.django_comment_common import models, signals from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory, SiteFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory class SendMessageHandlerTestCase(TestCase): # lint-amnesty, pylint: disable=missing-class-docstring diff --git a/lms/djangoapps/discussion/tests/test_tasks_v2.py b/lms/djangoapps/discussion/tests/test_tasks_v2.py index d5b742dc8582..aee9d3d8d22e 100644 --- a/lms/djangoapps/discussion/tests/test_tasks_v2.py +++ b/lms/djangoapps/discussion/tests/test_tasks_v2.py @@ -12,35 +12,18 @@ from edx_ace.recipient import Recipient from edx_ace.renderers import EmailRenderer from edx_ace.utils import date -from lms.djangoapps.discussion.django_comment_client.tests.mixins import ( - MockForumApiMixin, -) -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase import openedx.core.djangoapps.django_comment_common.comment_client as cc -from common.djangoapps.student.tests.factories import ( - CourseEnrollmentFactory, - UserFactory, -) -from lms.djangoapps.discussion.signals.handlers import ( - ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY, -) -from lms.djangoapps.discussion.tasks import ( - _is_first_comment, - _should_send_message, - _track_notification_sent, -) -from openedx.core.djangoapps.ace_common.template_context import ( - get_base_template_context, -) -from openedx.core.djangoapps.content.course_overviews.tests.factories import ( - CourseOverviewFactory, -) +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory +from lms.djangoapps.discussion.django_comment_client.tests.mixins import MockForumApiMixin +from lms.djangoapps.discussion.signals.handlers import ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY +from lms.djangoapps.discussion.tasks import _is_first_comment, _should_send_message, _track_notification_sent +from openedx.core.djangoapps.ace_common.template_context import get_base_template_context +from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangoapps.django_comment_common.signals import comment_created -from openedx.core.djangoapps.site_configuration.tests.factories import ( - SiteConfigurationFactory, -) +from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory from openedx.core.lib.celery.task_utils import emulate_http_request +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase NOW = datetime.utcnow() ONE_HOUR_AGO = NOW - timedelta(hours=1) diff --git a/lms/djangoapps/discussion/tests/test_views.py b/lms/djangoapps/discussion/tests/test_views.py index 7f575b454fad..a0c1f9fd80e8 100644 --- a/lms/djangoapps/discussion/tests/test_views.py +++ b/lms/djangoapps/discussion/tests/test_views.py @@ -13,14 +13,6 @@ from django.urls import reverse from django.utils import translation from edx_django_utils.cache import RequestCache -from xmodule.modulestore.tests.django_utils import ( - TEST_DATA_SPLIT_MODULESTORE, - ModuleStoreTestCase, -) -from xmodule.modulestore.tests.factories import ( - CourseFactory, - BlockFactory, -) from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory @@ -30,19 +22,16 @@ from lms.djangoapps.discussion import views from lms.djangoapps.discussion.django_comment_client.constants import TYPE_ENTRY, TYPE_SUBCATEGORY from lms.djangoapps.discussion.django_comment_client.permissions import get_team -from lms.djangoapps.discussion.django_comment_client.tests.utils import ( - config_course_discussions, - topic_name_to_id -) +from lms.djangoapps.discussion.django_comment_client.tests.utils import config_course_discussions, topic_name_to_id from lms.djangoapps.discussion.views import _get_discussion_default_topic_id, course_discussions_settings_handler from openedx.core.djangoapps.course_groups.tests.helpers import config_course_cohorts from openedx.core.djangoapps.course_groups.tests.test_views import CohortViewsTestCase from openedx.core.djangoapps.django_comment_common.comment_client.utils import CommentClientPaginatedResult -from openedx.core.djangoapps.django_comment_common.models import ( - CourseDiscussionSettings, -) +from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings from openedx.core.djangoapps.django_comment_common.utils import ThreadContext from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory log = logging.getLogger(__name__) diff --git a/lms/djangoapps/discussion/tests/test_views_v2.py b/lms/djangoapps/discussion/tests/test_views_v2.py index 0f268e93eb32..c5ee301d0357 100644 --- a/lms/djangoapps/discussion/tests/test_views_v2.py +++ b/lms/djangoapps/discussion/tests/test_views_v2.py @@ -19,46 +19,23 @@ from django.utils import translation from edx_django_utils.cache import RequestCache from edx_toggles.toggles.testutils import override_waffle_flag -from lms.djangoapps.discussion.django_comment_client.tests.mixins import ( - MockForumApiMixin, -) -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, - BlockFactory, - check_mongo_calls, -) from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory from common.djangoapps.student.roles import CourseStaffRole, UserBasedRole -from common.djangoapps.student.tests.factories import ( - AdminFactory, - CourseEnrollmentFactory, - UserFactory, -) +from common.djangoapps.student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory from common.djangoapps.util.testing import EventTestMixin, UrlResetMixin from lms.djangoapps.courseware.exceptions import CourseAccessRedirect from lms.djangoapps.discussion import views -from lms.djangoapps.discussion.django_comment_client.constants import ( - TYPE_ENTRY, - TYPE_SUBCATEGORY, -) +from lms.djangoapps.discussion.django_comment_client.constants import TYPE_ENTRY, TYPE_SUBCATEGORY from lms.djangoapps.discussion.django_comment_client.permissions import get_team from lms.djangoapps.discussion.django_comment_client.tests.group_id import ( CohortedTopicGroupIdTestMixinV2, GroupIdAssertionMixinV2, NonCohortedTopicGroupIdTestMixinV2, ) -from lms.djangoapps.discussion.django_comment_client.tests.unicode import ( - UnicodeTestMixin, -) +from lms.djangoapps.discussion.django_comment_client.tests.mixins import MockForumApiMixin +from lms.djangoapps.discussion.django_comment_client.tests.unicode import UnicodeTestMixin from lms.djangoapps.discussion.django_comment_client.tests.utils import ( CohortedTestCase, config_course_discussions, @@ -66,35 +43,27 @@ ) from lms.djangoapps.discussion.django_comment_client.utils import strip_none from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE -from lms.djangoapps.discussion.views import ( - _get_discussion_default_topic_id, - course_discussions_settings_handler, -) -from lms.djangoapps.teams.tests.factories import ( - CourseTeamFactory, - CourseTeamMembershipFactory, -) +from lms.djangoapps.discussion.views import _get_discussion_default_topic_id, course_discussions_settings_handler +from lms.djangoapps.teams.tests.factories import CourseTeamFactory, CourseTeamMembershipFactory from openedx.core.djangoapps.course_groups.models import CourseUserGroup from openedx.core.djangoapps.course_groups.tests.helpers import config_course_cohorts from openedx.core.djangoapps.course_groups.tests.test_views import CohortViewsTestCase -from openedx.core.djangoapps.django_comment_common.comment_client.utils import ( - CommentClientPaginatedResult, -) -from openedx.core.djangoapps.django_comment_common.models import ( - FORUM_ROLE_STUDENT, - CourseDiscussionSettings, -) -from openedx.core.djangoapps.django_comment_common.utils import ( - ThreadContext, - seed_permissions_roles, -) +from openedx.core.djangoapps.django_comment_common.comment_client.utils import CommentClientPaginatedResult +from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_STUDENT, CourseDiscussionSettings +from openedx.core.djangoapps.django_comment_common.utils import ThreadContext, seed_permissions_roles from openedx.core.djangoapps.util.testing import ContentGroupTestCase from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES from openedx.core.lib.teams_config import TeamsConfig from openedx.features.content_type_gating.models import ContentTypeGatingConfig -from openedx.features.enterprise_support.tests.mixins.enterprise import ( - EnterpriseTestConsentRequired, +from openedx.features.enterprise_support.tests.mixins.enterprise import EnterpriseTestConsentRequired +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 BlockFactory, CourseFactory, check_mongo_calls log = logging.getLogger(__name__) diff --git a/lms/djangoapps/discussion/views.py b/lms/djangoapps/discussion/views.py index bca6cb7768de..76bc0f080359 100644 --- a/lms/djangoapps/discussion/views.py +++ b/lms/djangoapps/discussion/views.py @@ -24,11 +24,9 @@ from opaque_keys.edx.keys import CourseKey from rest_framework import status from web_fragments.fragment import Fragment -from xmodule.modulestore.django import modulestore import lms.djangoapps.discussion.django_comment_client.utils as utils import openedx.core.djangoapps.django_comment_common.comment_client as cc -from openedx.core.djangoapps.django_comment_common.models import has_permission from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole, GlobalStaff from common.djangoapps.util.json_request import JsonResponse, expect_json @@ -45,7 +43,7 @@ get_group_id_for_comments_service, get_group_id_for_user, is_commentable_divided, - strip_none + strip_none, ) from lms.djangoapps.discussion.exceptions import TeamDiscussionHiddenFromUserException from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE @@ -55,7 +53,7 @@ available_division_schemes, get_discussion_categories_ids, get_divided_discussions, - get_group_names_by_id + get_group_names_by_id, ) from openedx.core.djangoapps.django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, @@ -63,11 +61,13 @@ FORUM_ROLE_GROUP_MODERATOR, FORUM_ROLE_MODERATOR, CourseDiscussionSettings, - Role + Role, + has_permission, ) from openedx.core.djangoapps.django_comment_common.utils import ThreadContext from openedx.core.djangoapps.plugin_api.views import EdxFragmentView from openedx.features.course_duration_limits.access import generate_course_expired_fragment +from xmodule.modulestore.django import modulestore User = get_user_model() log = logging.getLogger("edx.discussions") diff --git a/lms/djangoapps/edxnotes/decorators.py b/lms/djangoapps/edxnotes/decorators.py index 7c12275aca92..1f6a1a440796 100644 --- a/lms/djangoapps/edxnotes/decorators.py +++ b/lms/djangoapps/edxnotes/decorators.py @@ -22,9 +22,7 @@ def get_html(self, *args, **kwargs): Returns raw html for the component. """ # Import is placed here to avoid model import at project startup. - from .helpers import ( - generate_uid, get_edxnotes_id_token, get_public_endpoint, get_token_url, is_feature_enabled - ) + from .helpers import generate_uid, get_edxnotes_id_token, get_public_endpoint, get_token_url, is_feature_enabled if not settings.FEATURES.get("ENABLE_EDXNOTES"): return original_get_html(self, *args, **kwargs) diff --git a/lms/djangoapps/edxnotes/plugins.py b/lms/djangoapps/edxnotes/plugins.py index 3964ed81dbd9..5269feb08b28 100644 --- a/lms/djangoapps/edxnotes/plugins.py +++ b/lms/djangoapps/edxnotes/plugins.py @@ -7,12 +7,12 @@ from django.contrib.auth import get_user_model from django.utils.translation import gettext_noop as _ from opaque_keys.edx.keys import CourseKey -from xmodule.modulestore.django import modulestore from lms.djangoapps.courseware.tabs import EnrolledTab from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.course_apps.plugins import CourseApp from openedx.core.lib.courses import get_course_by_id +from xmodule.modulestore.django import modulestore from xmodule.tabs import CourseTab, CourseTabList # lint-amnesty, pylint: disable=wrong-import-order User = get_user_model() diff --git a/lms/djangoapps/edxnotes/tests.py b/lms/djangoapps/edxnotes/tests.py index 46920e927ad9..f0711cd9a579 100644 --- a/lms/djangoapps/edxnotes/tests.py +++ b/lms/djangoapps/edxnotes/tests.py @@ -22,16 +22,21 @@ from common.djangoapps.edxmako.shortcuts import render_to_string from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, SuperuserFactory, UserFactory -from lms.djangoapps.courseware.model_data import FieldDataCache from lms.djangoapps.courseware.block_render import get_block_for_descriptor +from lms.djangoapps.courseware.model_data import FieldDataCache from lms.djangoapps.courseware.tabs import get_course_tab_list from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_for_user from openedx.core.djangoapps.oauth_dispatch.tests.factories import ApplicationFactory from openedx.core.djangoapps.user_api.models import RetirementState, UserRetirementStatus from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) from xmodule.tabs import CourseTab # lint-amnesty, pylint: disable=wrong-import-order from xmodule.tests.helpers import StubUserService # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/edxnotes/views.py b/lms/djangoapps/edxnotes/views.py index 3e23ebe9ab47..faf172b67af2 100644 --- a/lms/djangoapps/edxnotes/views.py +++ b/lms/djangoapps/edxnotes/views.py @@ -18,9 +18,9 @@ from common.djangoapps.edxmako.shortcuts import render_to_response from common.djangoapps.util.json_request import JsonResponse, JsonResponseBadRequest +from lms.djangoapps.courseware.block_render import get_block_for_descriptor from lms.djangoapps.courseware.courses import get_course_with_access from lms.djangoapps.courseware.model_data import FieldDataCache -from lms.djangoapps.courseware.block_render import get_block_for_descriptor from lms.djangoapps.edxnotes.exceptions import EdxNotesParseError, EdxNotesServiceUnavailable from lms.djangoapps.edxnotes.helpers import ( DEFAULT_PAGE, @@ -30,7 +30,7 @@ get_course_position, get_edxnotes_id_token, get_notes, - is_feature_enabled + is_feature_enabled, ) from openedx.core.djangoapps.user_api.accounts.permissions import CanRetireUser from openedx.core.djangoapps.user_api.models import RetirementStateError, UserRetirementStatus diff --git a/lms/djangoapps/experiments/flags.py b/lms/djangoapps/experiments/flags.py index 3b45bcee5b5c..5aaade0eefa8 100644 --- a/lms/djangoapps/experiments/flags.py +++ b/lms/djangoapps/experiments/flags.py @@ -183,8 +183,8 @@ def get_bucket(self, course_key=None, track=True): """ # Keep some imports in here, because this class is commonly used at a module level, and we want to avoid # circular imports for any models. - from lms.djangoapps.experiments.models import ExperimentKeyValue from lms.djangoapps.courseware.masquerade import get_specific_masquerading_user + from lms.djangoapps.experiments.models import ExperimentKeyValue request = get_current_request() if not request: diff --git a/lms/djangoapps/experiments/migrations/0001_initial.py b/lms/djangoapps/experiments/migrations/0001_initial.py index 63660c988411..e1917acfc50e 100644 --- a/lms/djangoapps/experiments/migrations/0001_initial.py +++ b/lms/djangoapps/experiments/migrations/0001_initial.py @@ -1,7 +1,7 @@ -from django.db import migrations, models -from django.conf import settings import django.utils.timezone import model_utils.fields +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/experiments/migrations/0002_auto_20170627_1402.py b/lms/djangoapps/experiments/migrations/0002_auto_20170627_1402.py index 6742df419e0d..45ae4192992d 100644 --- a/lms/djangoapps/experiments/migrations/0002_auto_20170627_1402.py +++ b/lms/djangoapps/experiments/migrations/0002_auto_20170627_1402.py @@ -1,6 +1,6 @@ -from django.db import migrations, models import django.utils.timezone import model_utils.fields +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/experiments/tests/test_flags.py b/lms/djangoapps/experiments/tests/test_flags.py index 006efa17770d..66dc4dd6eb9e 100644 --- a/lms/djangoapps/experiments/tests/test_flags.py +++ b/lms/djangoapps/experiments/tests/test_flags.py @@ -20,7 +20,9 @@ from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag from openedx.core.djangoapps.waffle_utils.models import WaffleFlagCourseOverrideModel -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) @ddt.ddt diff --git a/lms/djangoapps/experiments/tests/test_utils.py b/lms/djangoapps/experiments/tests/test_utils.py index b32bea73c320..03bf8a9ae16b 100644 --- a/lms/djangoapps/experiments/tests/test_utils.py +++ b/lms/djangoapps/experiments/tests/test_utils.py @@ -8,8 +8,6 @@ from django.utils.timezone import now from opaque_keys.edx.keys import CourseKey -from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.partitions.partitions import Group from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from lms.djangoapps.course_blocks.transformers.tests.helpers import ModuleStoreTestCase @@ -18,8 +16,10 @@ get_experiment_user_metadata_context, get_program_price_and_skus, get_unenrolled_courses, - is_enrolled_in_course_run + is_enrolled_in_course_run, ) +from xmodule.modulestore.tests.factories import CourseFactory +from xmodule.partitions.partitions import Group class ExperimentUtilsTests(ModuleStoreTestCase, TestCase): diff --git a/lms/djangoapps/experiments/tests/test_views.py b/lms/djangoapps/experiments/tests/test_views.py index 398e199c71ad..7f92f6b8a64d 100644 --- a/lms/djangoapps/experiments/tests/test_views.py +++ b/lms/djangoapps/experiments/tests/test_views.py @@ -2,11 +2,11 @@ Tests for experimentation views """ +from datetime import timedelta from unittest.mock import patch -import six.moves.urllib.parse -from datetime import timedelta import django +import six.moves.urllib.parse from django.conf import settings from django.core.handlers.wsgi import WSGIRequest from django.test.utils import override_settings @@ -15,13 +15,13 @@ from rest_framework.test import APITestCase from common.djangoapps.student.tests.factories import UserFactory +from common.test.utils import assert_dict_contains_subset from lms.djangoapps.course_blocks.transformers.tests.helpers import ModuleStoreTestCase from lms.djangoapps.experiments.factories import ExperimentDataFactory, ExperimentKeyValueFactory from lms.djangoapps.experiments.models import ExperimentData # lint-amnesty, pylint: disable=unused-import from lms.djangoapps.experiments.serializers import ExperimentDataSerializer from openedx.core.djangolib.testing.utils import skip_unless_lms from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order -from common.test.utils import assert_dict_contains_subset CROSS_DOMAIN_REFERER = 'https://ecommerce.edx.org' diff --git a/lms/djangoapps/experiments/utils.py b/lms/djangoapps/experiments/utils.py index 30397c7bbd4a..fdcfd3e24874 100644 --- a/lms/djangoapps/experiments/utils.py +++ b/lms/djangoapps/experiments/utils.py @@ -21,7 +21,10 @@ from openedx.core.djangoapps.django_comment_common.models import Role from openedx.core.djangoapps.schedules.models import Schedule from openedx.features.course_duration_limits.access import get_user_course_duration, get_user_course_expiration_date -from xmodule.partitions.partitions_service import get_all_partitions_for_course, get_user_partition_groups # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.partitions.partitions_service import ( # lint-amnesty, pylint: disable=wrong-import-order + get_all_partitions_for_course, + get_user_partition_groups, +) logger = logging.getLogger(__name__) diff --git a/lms/djangoapps/experiments/views.py b/lms/djangoapps/experiments/views.py index bfb79d6a1156..5a2cc488f838 100644 --- a/lms/djangoapps/experiments/views.py +++ b/lms/djangoapps/experiments/views.py @@ -8,15 +8,13 @@ from django_filters.rest_framework import DjangoFilterBackend from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser -from lms.djangoapps.courseware import courses # lint-amnesty, pylint: disable=unused-import from opaque_keys.edx.keys import CourseKey # lint-amnesty, pylint: disable=wrong-import-order from rest_framework import permissions, viewsets # lint-amnesty, pylint: disable=wrong-import-order from rest_framework.views import APIView # lint-amnesty, pylint: disable=wrong-import-order -from common.djangoapps.util.json_request import JsonResponse from common.djangoapps.student.models import get_user_by_username_or_email from common.djangoapps.util.json_request import JsonResponse # lint-amnesty, pylint: disable=reimported -from lms.djangoapps.courseware import courses # lint-amnesty, pylint: disable=reimported +from lms.djangoapps.courseware import courses # lint-amnesty, pylint: disable=reimported, unused-import from lms.djangoapps.experiments import filters, serializers from lms.djangoapps.experiments.models import ExperimentData, ExperimentKeyValue from lms.djangoapps.experiments.permissions import IsStaffOrOwner, IsStaffOrReadOnly, IsStaffOrReadOnlyForSelf diff --git a/lms/djangoapps/gating/tests/test_api.py b/lms/djangoapps/gating/tests/test_api.py index 326ea9124cf9..c89f232ce8c1 100644 --- a/lms/djangoapps/gating/tests/test_api.py +++ b/lms/djangoapps/gating/tests/test_api.py @@ -12,8 +12,13 @@ from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase from lms.djangoapps.gating.api import evaluate_prerequisite from openedx.core.lib.gating import api as gating_api -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) class GatingTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): diff --git a/lms/djangoapps/gating/tests/test_integration.py b/lms/djangoapps/gating/tests/test_integration.py index 3b399e1b89e0..46c82a8dfe6c 100644 --- a/lms/djangoapps/gating/tests/test_integration.py +++ b/lms/djangoapps/gating/tests/test_integration.py @@ -10,9 +10,6 @@ from edx_toggles.toggles.testutils import override_waffle_switch from milestones import api as milestones_api from milestones.tests.utils import MilestonesTestCaseMixin -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, BlockFactory from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.courseware.access import has_access @@ -20,6 +17,9 @@ 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 xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory @ddt.ddt diff --git a/lms/djangoapps/gating/tests/test_signals.py b/lms/djangoapps/gating/tests/test_signals.py index e3c308663cc7..e68e495bfd73 100644 --- a/lms/djangoapps/gating/tests/test_signals.py +++ b/lms/djangoapps/gating/tests/test_signals.py @@ -8,7 +8,9 @@ from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.gating.signals import evaluate_subsection_gated_milestones from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/grades/admin.py b/lms/djangoapps/grades/admin.py index 7e34daef17f4..3fc90f1f9da7 100644 --- a/lms/djangoapps/grades/admin.py +++ b/lms/djangoapps/grades/admin.py @@ -6,9 +6,6 @@ from config_models.admin import ConfigurationModelAdmin from django.contrib import admin -from lms.djangoapps.grades.config.models import ( - ComputeGradesSetting -) - +from lms.djangoapps.grades.config.models import ComputeGradesSetting admin.site.register(ComputeGradesSetting, ConfigurationModelAdmin) diff --git a/lms/djangoapps/grades/api.py b/lms/djangoapps/grades/api.py index bb1b43fa7ff8..f3a0fd796aec 100644 --- a/lms/djangoapps/grades/api.py +++ b/lms/djangoapps/grades/api.py @@ -11,15 +11,19 @@ from opaque_keys.edx.keys import CourseKey, UsageKey from common.djangoapps.track.event_transaction_utils import create_new_event_transaction_id, set_event_transaction_type + # Public Grades Modules from lms.djangoapps.grades import constants, context, course_data, events + # Grades APIs that should NOT belong within the Grades subsystem # TODO move Gradebook to be an external feature outside of core Grades from lms.djangoapps.grades.config.waffle import gradebook_bulk_management_enabled, is_writable_gradebook_enabled + # Public Grades Factories from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.grades.models_api import * from lms.djangoapps.grades.signals import signals + # TODO exposing functionality from Grades handlers seems fishy. from lms.djangoapps.grades.signals.handlers import disconnect_submissions_signal_receiver from lms.djangoapps.grades.subsection_grade import CreateSubsectionGrade @@ -146,8 +150,9 @@ def _create_subsection_grade(user_id, course_key, usage_key): Given a user_id, course_key, and subsection usage_key, creates a new ``PersistentSubsectionGrade``. """ - from lms.djangoapps.courseware.courses import get_course from django.contrib.auth import get_user_model + + from lms.djangoapps.courseware.courses import get_course course = get_course(course_key, depth=None) subsection = course.get_child(usage_key) if not subsection: diff --git a/lms/djangoapps/grades/course_grade_factory.py b/lms/djangoapps/grades/course_grade_factory.py index a6665bf67b84..8c8da811efd7 100644 --- a/lms/djangoapps/grades/course_grade_factory.py +++ b/lms/djangoapps/grades/course_grade_factory.py @@ -7,8 +7,9 @@ from openedx.core.djangoapps.signals.signals import ( COURSE_GRADE_CHANGED, COURSE_GRADE_NOW_FAILED, - COURSE_GRADE_NOW_PASSED + COURSE_GRADE_NOW_PASSED, ) + from .course_data import CourseData from .course_grade import CourseGrade, ZeroCourseGrade from .models import PersistentCourseGrade diff --git a/lms/djangoapps/grades/events.py b/lms/djangoapps/grades/events.py index 1321b2e51d45..48beb338c026 100644 --- a/lms/djangoapps/grades/events.py +++ b/lms/djangoapps/grades/events.py @@ -12,7 +12,7 @@ CourseData, CoursePassingStatusData, UserData, - UserPersonalData + UserPersonalData, ) from openedx_events.learning.signals import CCX_COURSE_PASSING_STATUS_UPDATED, COURSE_PASSING_STATUS_UPDATED @@ -23,7 +23,7 @@ create_new_event_transaction_id, get_event_transaction_id, get_event_transaction_type, - set_event_transaction_type + set_event_transaction_type, ) from lms.djangoapps.grades.signals.signals import SCHEDULE_FOLLOW_UP_SEGMENT_EVENT_FOR_COURSE_PASSED_FIRST_TIME from openedx.core.djangoapps.content.course_overviews.models import CourseOverview diff --git a/lms/djangoapps/grades/grade_utils.py b/lms/djangoapps/grades/grade_utils.py index 05d2058f37ba..c23b6847b52c 100644 --- a/lms/djangoapps/grades/grade_utils.py +++ b/lms/djangoapps/grades/grade_utils.py @@ -6,8 +6,8 @@ import logging from datetime import timedelta -from django.utils import timezone from django.conf import settings +from django.utils import timezone from openedx.core.djangoapps.content.course_overviews.models import CourseOverview 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 847d25490a0f..2cd63d97299a 100644 --- a/lms/djangoapps/grades/management/commands/tests/test_compute_grades.py +++ b/lms/djangoapps/grades/management/commands/tests/test_compute_grades.py @@ -9,11 +9,13 @@ import pytest from django.core.management import CommandError, call_command -from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.student.models import CourseEnrollment +from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.grades.config.models import ComputeGradesSetting from lms.djangoapps.grades.management.commands import compute_grades -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/grades/management/commands/tests/test_recalculate_learner_grades.py b/lms/djangoapps/grades/management/commands/tests/test_recalculate_learner_grades.py index 3f253951d35c..d4f491238532 100644 --- a/lms/djangoapps/grades/management/commands/tests/test_recalculate_learner_grades.py +++ b/lms/djangoapps/grades/management/commands/tests/test_recalculate_learner_grades.py @@ -9,7 +9,9 @@ from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from lms.djangoapps.grades.management.commands import recalculate_learner_grades from lms.djangoapps.grades.tests.test_tasks import HasCourseWithProblemsMixin -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order DATE_FORMAT = "%Y-%m-%d %H:%M" 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 8f679cd1c6c8..5bf44c01dc81 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 @@ -15,7 +15,9 @@ 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 xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) DATE_FORMAT = "%Y-%m-%d %H:%M" diff --git a/lms/djangoapps/grades/management/commands/tests/test_send_segment_events_for_failed_learners.py b/lms/djangoapps/grades/management/commands/tests/test_send_segment_events_for_failed_learners.py index 4cc707d252a8..f28972058a0a 100644 --- a/lms/djangoapps/grades/management/commands/tests/test_send_segment_events_for_failed_learners.py +++ b/lms/djangoapps/grades/management/commands/tests/test_send_segment_events_for_failed_learners.py @@ -10,18 +10,19 @@ import ddt from django.core.management import call_command from django.utils import timezone -from xmodule.modulestore.tests.django_utils import \ - SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.grades.management.commands import send_segment_events_for_failed_learners from lms.djangoapps.grades.management.commands.send_segment_events_for_failed_learners import ( EVENT_NAME, - PAID_ENROLLMENT_MODES + PAID_ENROLLMENT_MODES, ) from lms.djangoapps.grades.models import PersistentCourseGrade from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) @ddt.ddt diff --git a/lms/djangoapps/grades/migrations/0018_add_waffle_flag_defaults.py b/lms/djangoapps/grades/migrations/0018_add_waffle_flag_defaults.py index 3903fc970bd9..2786674ede2f 100644 --- a/lms/djangoapps/grades/migrations/0018_add_waffle_flag_defaults.py +++ b/lms/djangoapps/grades/migrations/0018_add_waffle_flag_defaults.py @@ -3,7 +3,7 @@ from lms.djangoapps.grades.config.waffle import ( ENFORCE_FREEZE_GRADE_AFTER_COURSE_END, REJECTED_EXAM_OVERRIDES_GRADE, - WRITABLE_GRADEBOOK, + WRITABLE_GRADEBOOK ) diff --git a/lms/djangoapps/grades/models.py b/lms/djangoapps/grades/models.py index 38cfed502c68..3e972c1f4b49 100644 --- a/lms/djangoapps/grades/models.py +++ b/lms/djangoapps/grades/models.py @@ -15,24 +15,23 @@ from hashlib import sha1 from django.apps import apps -from django.db import models, IntegrityError, transaction -from openedx_events.learning.data import CourseData, PersistentCourseGradeData -from openedx_events.learning.signals import PERSISTENT_GRADE_SUMMARY_CHANGED - +from django.db import IntegrityError, models, transaction from django.utils.timezone import now from lazy import lazy from model_utils.models import TimeStampedModel from opaque_keys.edx.django.models import CourseKeyField, UsageKeyField from opaque_keys.edx.keys import CourseKey, UsageKey +from openedx_events.learning.data import CourseData, PersistentCourseGradeData +from openedx_events.learning.signals import PERSISTENT_GRADE_SUMMARY_CHANGED from simple_history.models import HistoricalRecords from lms.djangoapps.courseware.fields import UnsignedBigIntAutoField from lms.djangoapps.grades import events # lint-amnesty, pylint: disable=unused-import -from openedx.core.lib.cache_utils import get_cache from lms.djangoapps.grades.signals.signals import ( COURSE_GRADE_PASSED_FIRST_TIME, - COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY + COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY, ) +from openedx.core.lib.cache_utils import get_cache log = logging.getLogger(__name__) diff --git a/lms/djangoapps/grades/models_api.py b/lms/djangoapps/grades/models_api.py index 0466fb2a56ac..9c38296ead6d 100644 --- a/lms/djangoapps/grades/models_api.py +++ b/lms/djangoapps/grades/models_api.py @@ -3,7 +3,6 @@ """ from django.db import transaction - from opaque_keys.edx.keys import CourseKey, UsageKey from lms.djangoapps.grades.models import PersistentCourseGrade as _PersistentCourseGrade diff --git a/lms/djangoapps/grades/rest_api/v1/gradebook_views.py b/lms/djangoapps/grades/rest_api/v1/gradebook_views.py index c295563da565..95e18631aa6c 100644 --- a/lms/djangoapps/grades/rest_api/v1/gradebook_views.py +++ b/lms/djangoapps/grades/rest_api/v1/gradebook_views.py @@ -27,28 +27,33 @@ create_new_event_transaction_id, get_event_transaction_id, get_event_transaction_type, - set_event_transaction_type + set_event_transaction_type, ) from common.djangoapps.util.date_utils import to_timestamp from lms.djangoapps.course_blocks.api import get_course_blocks -from lms.djangoapps.grades.api import CourseGradeFactory, clear_prefetched_course_and_subsection_grades +from lms.djangoapps.grades.api import ( + CourseGradeFactory, + clear_prefetched_course_and_subsection_grades, + gradebook_bulk_management_enabled, + is_writable_gradebook_enabled, + prefetch_course_and_subsection_grades, +) from lms.djangoapps.grades.api import constants as grades_constants from lms.djangoapps.grades.api import context as grades_context from lms.djangoapps.grades.api import events as grades_events -from lms.djangoapps.grades.api import gradebook_bulk_management_enabled -from lms.djangoapps.grades.api import is_writable_gradebook_enabled, prefetch_course_and_subsection_grades from lms.djangoapps.grades.course_data import CourseData from lms.djangoapps.grades.grade_utils import are_grades_frozen + # TODO these imports break abstraction of the core Grades layer. This code needs # to be refactored so Gradebook views only access public Grades APIs. from lms.djangoapps.grades.models import ( PersistentCourseGrade, PersistentSubsectionGrade, - PersistentSubsectionGradeOverride + PersistentSubsectionGradeOverride, ) from lms.djangoapps.grades.rest_api.serializers import ( StudentGradebookEntrySerializer, - SubsectionGradeResponseSerializer + SubsectionGradeResponseSerializer, ) from lms.djangoapps.grades.rest_api.v1.utils import USER_MODEL, CourseEnrollmentPagination, GradeViewMixin from lms.djangoapps.grades.subsection_grade import CreateSubsectionGrade @@ -63,7 +68,7 @@ PaginatedAPIView, get_course_key, verify_course_exists, - view_auth_classes + view_auth_classes, ) from openedx.core.lib.cache_utils import request_cached from openedx.core.lib.courses import get_course_by_id diff --git a/lms/djangoapps/grades/rest_api/v1/tests/mixins.py b/lms/djangoapps/grades/rest_api/v1/tests/mixins.py index 1d3a6a0b4551..eaea8b9c3e3b 100644 --- a/lms/djangoapps/grades/rest_api/v1/tests/mixins.py +++ b/lms/djangoapps/grades/rest_api/v1/tests/mixins.py @@ -6,13 +6,12 @@ from datetime import datetime from pytz import UTC -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory -from common.djangoapps.student.tests.factories import GlobalStaffFactory +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, GlobalStaffFactory, UserFactory from lms.djangoapps.program_enrollments.tests.factories import ProgramCourseEnrollmentFactory, ProgramEnrollmentFactory from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory class GradeViewTestMixin(SharedModuleStoreTestCase): diff --git a/lms/djangoapps/grades/rest_api/v1/tests/test_gradebook_views.py b/lms/djangoapps/grades/rest_api/v1/tests/test_gradebook_views.py index 2b9f732912c0..ae7a36685232 100644 --- a/lms/djangoapps/grades/rest_api/v1/tests/test_gradebook_views.py +++ b/lms/djangoapps/grades/rest_api/v1/tests/test_gradebook_views.py @@ -8,7 +8,6 @@ from contextlib import contextmanager from datetime import datetime from unittest.mock import MagicMock, patch -from common.djangoapps.student.models.course_enrollment import CourseEnrollment import ddt import pytest @@ -19,26 +18,25 @@ from pytz import UTC from rest_framework import status from rest_framework.test import APITestCase -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory import openedx.core.djangoapps.content.block_structure.api as bs_api from common.djangoapps.course_modes.models import CourseMode +from common.djangoapps.student.models.course_enrollment import CourseEnrollment from common.djangoapps.student.roles import ( CourseBetaTesterRole, CourseCcxCoachRole, CourseDataResearcherRole, CourseInstructorRole, - CourseStaffRole + CourseStaffRole, ) -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory -from common.djangoapps.student.tests.factories import InstructorFactory -from common.djangoapps.student.tests.factories import StaffFactory -from lms.djangoapps.certificates.data import CertificateStatuses -from lms.djangoapps.certificates.api import ( - get_certificate_for_user_id, - create_or_update_eligible_certificate_for_user +from common.djangoapps.student.tests.factories import ( + CourseEnrollmentFactory, + InstructorFactory, + StaffFactory, + UserFactory, ) +from lms.djangoapps.certificates.api import create_or_update_eligible_certificate_for_user, get_certificate_for_user_id +from lms.djangoapps.certificates.data import CertificateStatuses from lms.djangoapps.grades.config.waffle import BULK_MANAGEMENT, WRITABLE_GRADEBOOK from lms.djangoapps.grades.constants import GradeOverrideFeatureEnum from lms.djangoapps.grades.course_data import CourseData @@ -48,13 +46,15 @@ BlockRecordList, PersistentCourseGrade, PersistentSubsectionGrade, - PersistentSubsectionGradeOverride + PersistentSubsectionGradeOverride, ) from lms.djangoapps.grades.rest_api.v1.tests.mixins import GradeViewTestMixin from lms.djangoapps.grades.rest_api.v1.views import CourseEnrollmentPagination from lms.djangoapps.grades.subsection_grade import ReadSubsectionGrade from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory # pylint: disable=unused-variable diff --git a/lms/djangoapps/grades/rest_api/v1/tests/test_grading_policy_view.py b/lms/djangoapps/grades/rest_api/v1/tests/test_grading_policy_view.py index 0b90f7f6ed97..b55395c01dcd 100644 --- a/lms/djangoapps/grades/rest_api/v1/tests/test_grading_policy_view.py +++ b/lms/djangoapps/grades/rest_api/v1/tests/test_grading_policy_view.py @@ -8,14 +8,13 @@ import ddt from django.urls import reverse from pytz import UTC -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory from xblocks_contrib.problem.capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory -from common.djangoapps.student.tests.factories import GlobalStaffFactory -from common.djangoapps.student.tests.factories import StaffFactory -from common.djangoapps.student.tests.factories import UserFactory + +from common.djangoapps.student.tests.factories import GlobalStaffFactory, StaffFactory, UserFactory from openedx.core.djangoapps.oauth_dispatch.tests.factories import AccessTokenFactory, ApplicationFactory +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory @ddt.ddt diff --git a/lms/djangoapps/grades/signals/handlers.py b/lms/djangoapps/grades/signals/handlers.py index 81768ed521dc..79d67b740431 100644 --- a/lms/djangoapps/grades/signals/handlers.py +++ b/lms/djangoapps/grades/signals/handlers.py @@ -6,10 +6,13 @@ from logging import getLogger from django.dispatch import receiver -from opaque_keys.edx.keys import CourseKey, LearningContextKey, UsageKey from opaque_keys import InvalidKeyError -from openedx_events.learning.signals import EXTERNAL_GRADER_SCORE_SUBMITTED -from openedx_events.learning.signals import EXAM_ATTEMPT_REJECTED, EXAM_ATTEMPT_VERIFIED +from opaque_keys.edx.keys import CourseKey, LearningContextKey, UsageKey +from openedx_events.learning.signals import ( + EXAM_ATTEMPT_REJECTED, + EXAM_ATTEMPT_VERIFIED, + EXTERNAL_GRADER_SCORE_SUBMITTED, +) from submissions.models import score_reset, score_set from xblock.scorable import ScorableXBlockMixin, Score @@ -21,12 +24,12 @@ from lms.djangoapps.grades.tasks import ( RECALCULATE_GRADE_DELAY_SECONDS, recalculate_course_and_subsection_grades_for_user, - recalculate_subsection_grade_v3 + recalculate_subsection_grade_v3, ) from openedx.core.djangoapps.course_groups.signals.signals import COHORT_MEMBERSHIP_UPDATED from openedx.core.djangoapps.signals.signals import ( # lint-amnesty, pylint: disable=wrong-import-order COURSE_GRADE_NOW_FAILED, - COURSE_GRADE_NOW_PASSED + COURSE_GRADE_NOW_PASSED, ) from openedx.core.lib.grade_utils import is_score_higher_or_equal from xmodule.modulestore.django import modulestore @@ -41,7 +44,7 @@ PROBLEM_WEIGHTED_SCORE_CHANGED, SCORE_PUBLISHED, SUBSECTION_OVERRIDE_CHANGED, - SUBSECTION_SCORE_CHANGED + SUBSECTION_SCORE_CHANGED, ) log = getLogger(__name__) diff --git a/lms/djangoapps/grades/subsection_grade.py b/lms/djangoapps/grades/subsection_grade.py index 5c6eff18f078..416a8f5d66fe 100644 --- a/lms/djangoapps/grades/subsection_grade.py +++ b/lms/djangoapps/grades/subsection_grade.py @@ -7,6 +7,7 @@ from collections import OrderedDict from datetime import datetime, timezone from logging import getLogger + from lazy import lazy from xblock.scorable import ShowCorrectness diff --git a/lms/djangoapps/grades/tasks.py b/lms/djangoapps/grades/tasks.py index 9ec237274b4f..25c5a8187d90 100644 --- a/lms/djangoapps/grades/tasks.py +++ b/lms/djangoapps/grades/tasks.py @@ -12,7 +12,7 @@ from edx_django_utils.monitoring import ( set_code_owner_attribute, set_custom_attribute, - set_custom_attributes_for_course_key + set_custom_attributes_for_course_key, ) from opaque_keys.edx.keys import CourseKey, UsageKey from opaque_keys.edx.locator import CourseLocator @@ -26,8 +26,9 @@ from lms.djangoapps.grades.config.models import ComputeGradesSetting from openedx.core.djangoapps.content.block_structure.api import clear_course_from_cache from openedx.core.djangoapps.content.block_structure.exceptions import UsageKeyNotInBlockStructure -from openedx.core.djangoapps.content.course_overviews.models import \ - CourseOverview # lint-amnesty, pylint: disable=unused-import +from openedx.core.djangoapps.content.course_overviews.models import ( # lint-amnesty, pylint: disable=unused-import + CourseOverview, +) from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from .config.waffle import DISABLE_REGRADE_ON_POLICY_CHANGE diff --git a/lms/djangoapps/grades/tests/base.py b/lms/djangoapps/grades/tests/base.py index 03641900e1c3..2000ccb1f26b 100644 --- a/lms/djangoapps/grades/tests/base.py +++ b/lms/djangoapps/grades/tests/base.py @@ -4,14 +4,14 @@ from crum import set_current_request -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory - from xblocks_contrib.problem.capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory + from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.course_blocks.api import get_course_blocks from openedx.core.djangolib.testing.utils import get_mock_request +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory from ..course_data import CourseData from ..subsection_grade_factory import SubsectionGradeFactory diff --git a/lms/djangoapps/grades/tests/integration/test_access.py b/lms/djangoapps/grades/tests/integration/test_access.py index 43323728af87..168cf0290114 100644 --- a/lms/djangoapps/grades/tests/integration/test_access.py +++ b/lms/djangoapps/grades/tests/integration/test_access.py @@ -4,8 +4,8 @@ from crum import set_current_request - from xblocks_contrib.problem.capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory + from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.course_blocks.api import get_course_blocks @@ -13,8 +13,13 @@ from openedx.core.djangolib.testing.utils import get_mock_request from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) from ...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 679d84895e8d..6ee9a9e978e8 100644 --- a/lms/djangoapps/grades/tests/integration/test_events.py +++ b/lms/djangoapps/grades/tests/integration/test_events.py @@ -1,14 +1,14 @@ """ Test grading events across apps. """ -import ddt from unittest.mock import call as mock_call from unittest.mock import patch +import ddt from crum import set_current_request +from xblocks_contrib.problem.capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory import openedx.core.djangoapps.content.block_structure.api as bs_api -from xblocks_contrib.problem.capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.courseware.tests.test_submitting_problems import ProblemSubmissionTestMixin @@ -16,8 +16,13 @@ from lms.djangoapps.instructor_task.api import submit_rescore_problem_for_student from openedx.core.djangolib.testing.utils import get_mock_request from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) from ... import events diff --git a/lms/djangoapps/grades/tests/integration/test_problems.py b/lms/djangoapps/grades/tests/integration/test_problems.py index 92a9f3696a43..9a33de4bd3c9 100644 --- a/lms/djangoapps/grades/tests/integration/test_problems.py +++ b/lms/djangoapps/grades/tests/integration/test_problems.py @@ -6,21 +6,24 @@ import pytz from crum import set_current_request from django.test.utils import override_settings +from xblocks_contrib.problem.capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory + +from common.djangoapps.student.models import CourseEnrollment +from common.djangoapps.student.tests.factories import UserFactory +from lms.djangoapps.course_blocks.api import get_course_blocks +from lms.djangoapps.courseware.tests.test_submitting_problems import ProblemSubmissionTestMixin +from openedx.core.djangolib.testing.utils import get_mock_request from xmodule.capa_block import reset_class from xmodule.graders import ProblemScore from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import ( - TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase, SharedModuleStoreTestCase, + TEST_DATA_SPLIT_MODULESTORE, + ModuleStoreTestCase, + SharedModuleStoreTestCase, ) -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory from xmodule.modulestore.tests.utils import TEST_DATA_DIR from xmodule.modulestore.xml_importer import import_course_from_xml -from xblocks_contrib.problem.capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory -from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.tests.factories import UserFactory -from lms.djangoapps.course_blocks.api import get_course_blocks -from lms.djangoapps.courseware.tests.test_submitting_problems import ProblemSubmissionTestMixin -from openedx.core.djangolib.testing.utils import get_mock_request from ...subsection_grade_factory import SubsectionGradeFactory from ..utils import answer_problem, mock_get_submissions_score diff --git a/lms/djangoapps/grades/tests/test_api.py b/lms/djangoapps/grades/tests/test_api.py index e42e9ea56f6d..eb4c20b4b975 100644 --- a/lms/djangoapps/grades/tests/test_api.py +++ b/lms/djangoapps/grades/tests/test_api.py @@ -8,12 +8,17 @@ from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.grades import api from lms.djangoapps.grades.models import ( + PersistentCourseGrade, PersistentSubsectionGrade, PersistentSubsectionGradeOverride, - PersistentCourseGrade ) -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) @ddt.ddt diff --git a/lms/djangoapps/grades/tests/test_course_data.py b/lms/djangoapps/grades/tests/test_course_data.py index d71858312171..3d0319b4e887 100644 --- a/lms/djangoapps/grades/tests/test_course_data.py +++ b/lms/djangoapps/grades/tests/test_course_data.py @@ -9,7 +9,9 @@ from lms.djangoapps.course_blocks.api import get_course_blocks from openedx.core.djangoapps.content.block_structure.api import get_course_in_cache from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..course_data import CourseData diff --git a/lms/djangoapps/grades/tests/test_course_grade.py b/lms/djangoapps/grades/tests/test_course_grade.py index a4afd554facb..2bc9a6dd7c8b 100644 --- a/lms/djangoapps/grades/tests/test_course_grade.py +++ b/lms/djangoapps/grades/tests/test_course_grade.py @@ -3,12 +3,12 @@ import ddt from crum import set_current_request -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangolib.testing.utils import get_mock_request +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory from ..course_data import CourseData from ..course_grade import ZeroCourseGrade diff --git a/lms/djangoapps/grades/tests/test_course_grade_factory.py b/lms/djangoapps/grades/tests/test_course_grade_factory.py index b6865d225fde..a1d827e2b01a 100644 --- a/lms/djangoapps/grades/tests/test_course_grade_factory.py +++ b/lms/djangoapps/grades/tests/test_course_grade_factory.py @@ -8,7 +8,9 @@ from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.courseware.access import has_access from openedx.core.djangoapps.content.block_structure.factory import BlockStructureFactory -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..course_grade import CourseGrade, ZeroCourseGrade diff --git a/lms/djangoapps/grades/tests/test_events.py b/lms/djangoapps/grades/tests/test_events.py index 9ef9abfb59a3..2c47de903ead 100644 --- a/lms/djangoapps/grades/tests/test_events.py +++ b/lms/djangoapps/grades/tests/test_events.py @@ -13,23 +13,23 @@ CoursePassingStatusData, PersistentCourseGradeData, UserData, - UserPersonalData + UserPersonalData, ) from openedx_events.learning.signals import ( CCX_COURSE_PASSING_STATUS_UPDATED, COURSE_PASSING_STATUS_UPDATED, - PERSISTENT_GRADE_SUMMARY_CHANGED + PERSISTENT_GRADE_SUMMARY_CHANGED, ) from openedx_events.tests.utils import OpenEdxEventsTestMixin from common.djangoapps.student.tests.factories import AdminFactory, UserFactory +from common.test.utils import assert_dict_contains_subset from lms.djangoapps.ccx.models import CustomCourseForEdX from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.grades.models import PersistentCourseGrade from lms.djangoapps.grades.tests.utils import mock_passing_grade from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from common.test.utils import assert_dict_contains_subset class PersistentGradeEventsTest(SharedModuleStoreTestCase, OpenEdxEventsTestMixin): diff --git a/lms/djangoapps/grades/tests/test_handlers.py b/lms/djangoapps/grades/tests/test_handlers.py index 72424987b5ab..deddfc28653f 100644 --- a/lms/djangoapps/grades/tests/test_handlers.py +++ b/lms/djangoapps/grades/tests/test_handlers.py @@ -15,8 +15,9 @@ from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.grades.signals.handlers import ( exam_attempt_rejected_event_handler, - exam_attempt_verified_event_handler + exam_attempt_verified_event_handler, ) + from ..constants import GradeOverrideFeatureEnum diff --git a/lms/djangoapps/grades/tests/test_models.py b/lms/djangoapps/grades/tests/test_models.py index acdb20c5f1a7..950d01c3e802 100644 --- a/lms/djangoapps/grades/tests/test_models.py +++ b/lms/djangoapps/grades/tests/test_models.py @@ -30,7 +30,7 @@ PersistentCourseGrade, PersistentSubsectionGrade, PersistentSubsectionGradeOverride, - VisibleBlocks + VisibleBlocks, ) diff --git a/lms/djangoapps/grades/tests/test_score_render.py b/lms/djangoapps/grades/tests/test_score_render.py index 6664459a95f6..bdbadb7b7391 100644 --- a/lms/djangoapps/grades/tests/test_score_render.py +++ b/lms/djangoapps/grades/tests/test_score_render.py @@ -12,7 +12,7 @@ from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.grades.score_render import ( get_block_for_descriptor_without_access_check, - load_xblock_for_external_grader + load_xblock_for_external_grader, ) from lms.djangoapps.grades.signals.handlers import handle_external_grader_score from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase diff --git a/lms/djangoapps/grades/tests/test_scores.py b/lms/djangoapps/grades/tests/test_scores.py index 53aa4801b463..f171a73fa1d5 100644 --- a/lms/djangoapps/grades/tests/test_scores.py +++ b/lms/djangoapps/grades/tests/test_scores.py @@ -5,9 +5,9 @@ # pylint: disable=protected-access import itertools from collections import namedtuple -import pytest import ddt +import pytest from django.test import TestCase from django.utils.timezone import now from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator diff --git a/lms/djangoapps/grades/tests/test_services.py b/lms/djangoapps/grades/tests/test_services.py index 07a77ff13f13..8fc24da059b9 100644 --- a/lms/djangoapps/grades/tests/test_services.py +++ b/lms/djangoapps/grades/tests/test_services.py @@ -14,8 +14,13 @@ from lms.djangoapps.grades.constants import GradeOverrideFeatureEnum from lms.djangoapps.grades.models import PersistentSubsectionGrade, PersistentSubsectionGradeOverride from lms.djangoapps.grades.services import GradesService -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) from ..constants import ScoreDatabaseTableEnum diff --git a/lms/djangoapps/grades/tests/test_signals.py b/lms/djangoapps/grades/tests/test_signals.py index 72a20d406482..912a7ba00f5c 100644 --- a/lms/djangoapps/grades/tests/test_signals.py +++ b/lms/djangoapps/grades/tests/test_signals.py @@ -30,7 +30,7 @@ listen_for_passing_grade, problem_raw_score_changed_handler, submissions_score_reset_handler, - submissions_score_set_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 8adb98302f69..510dd8ab5315 100644 --- a/lms/djangoapps/grades/tests/test_tasks.py +++ b/lms/djangoapps/grades/tests/test_tasks.py @@ -32,7 +32,7 @@ compute_all_grades_for_course, compute_grades_for_course, compute_grades_for_course_v2, - recalculate_subsection_grade_v3 + recalculate_subsection_grade_v3, ) from openedx.core.djangoapps.content.block_structure.exceptions import BlockStructureNotFound from xmodule.modulestore import ModuleStoreEnum diff --git a/lms/djangoapps/grades/tests/test_transformer.py b/lms/djangoapps/grades/tests/test_transformer.py index 7ef13e5b5b7c..b1ddde8e5263 100644 --- a/lms/djangoapps/grades/tests/test_transformer.py +++ b/lms/djangoapps/grades/tests/test_transformer.py @@ -9,15 +9,15 @@ import ddt import pytz -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import check_mongo_calls_range import openedx.core.djangoapps.content.block_structure.api as bs_api from common.djangoapps.student.tests.factories import UserFactory 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 xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import check_mongo_calls_range from ..transformer import GradesTransformer diff --git a/lms/djangoapps/grades/tests/utils.py b/lms/djangoapps/grades/tests/utils.py index 9111820379b4..1f5f9a9dedac 100644 --- a/lms/djangoapps/grades/tests/utils.py +++ b/lms/djangoapps/grades/tests/utils.py @@ -9,8 +9,8 @@ import pytz -from lms.djangoapps.courseware.model_data import FieldDataCache from lms.djangoapps.courseware.block_render import get_block +from lms.djangoapps.courseware.model_data import FieldDataCache from xmodule.graders import ProblemScore # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/instructor/enrollment.py b/lms/djangoapps/instructor/enrollment.py index 85eb5bac1ce8..cce858aa76de 100644 --- a/lms/djangoapps/instructor/enrollment.py +++ b/lms/djangoapps/instructor/enrollment.py @@ -19,19 +19,19 @@ from edx_ace.recipient import Recipient from eventtracking import tracker from submissions import api as sub_api # installed from the edx-submissions repository -from submissions.models import score_set, score_reset +from submissions.models import score_reset, score_set from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import ( # lint-amnesty, pylint: disable=line-too-long CourseEnrollment, CourseEnrollmentAllowed, anonymous_id_for_user, - is_email_retired + is_email_retired, ) from common.djangoapps.track.event_transaction_utils import ( create_new_event_transaction_id, get_event_transaction_id, - set_event_transaction_type + set_event_transaction_type, ) from lms.djangoapps.branding.api import get_logo_url_for_email from lms.djangoapps.courseware.models import StudentModule @@ -46,7 +46,7 @@ AllowedUnenroll, EnrolledUnenroll, EnrollEnrolled, - RemoveBetaTester + RemoveBetaTester, ) from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers diff --git a/lms/djangoapps/instructor/ora.py b/lms/djangoapps/instructor/ora.py index 6198aa4c3b64..8055e5dff22c 100644 --- a/lms/djangoapps/instructor/ora.py +++ b/lms/djangoapps/instructor/ora.py @@ -1,8 +1,7 @@ """Utilities for retrieving Open Response Assessments (ORAs) data for instructor dashboards.""" -from django.utils.translation import gettext as _ from django.conf import settings - +from django.utils.translation import gettext as _ from openassessment.data import OraAggregateData from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/instructor/tests/test_access.py b/lms/djangoapps/instructor/tests/test_access.py index 3ddde49067a9..3273bcf6391d 100644 --- a/lms/djangoapps/instructor/tests/test_access.py +++ b/lms/djangoapps/instructor/tests/test_access.py @@ -9,14 +9,16 @@ from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.instructor.access import ( allow_access, - list_with_level, is_beta_tester, + list_with_level, revoke_access, - update_forum_role + update_forum_role, ) from openedx.core.djangoapps.ace_common.tests.mixins import EmailTemplateTagMixin from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_MODERATOR, Role -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/instructor/tests/test_api.py b/lms/djangoapps/instructor/tests/test_api.py index 1d517fa60774..a6fb9a331d71 100644 --- a/lms/djangoapps/instructor/tests/test_api.py +++ b/lms/djangoapps/instructor/tests/test_api.py @@ -49,13 +49,13 @@ ManualEnrollmentAudit, NonExistentCourseError, get_retired_email_by_email, - get_retired_username_by_username + get_retired_username_by_username, ) from common.djangoapps.student.roles import ( CourseBetaTesterRole, CourseDataResearcherRole, CourseFinanceAdminRole, - CourseInstructorRole + CourseInstructorRole, ) from common.djangoapps.student.tests.factories import ( BetaTesterFactory, @@ -64,9 +64,8 @@ GlobalStaffFactory, InstructorFactory, StaffFactory, - UserFactory + UserFactory, ) - from lms.djangoapps.bulk_email.models import BulkEmailFlag, CourseEmail, CourseEmailTemplate from lms.djangoapps.certificates.data import CertificateStatuses from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory @@ -79,12 +78,12 @@ _split_input_list, common_exceptions_400, generate_unique_password, - require_finance_admin + require_finance_admin, ) from lms.djangoapps.instructor_task.api_helper import ( AlreadyRunningError, QueueConnectionError, - generate_already_running_error_message + generate_already_running_error_message, ) from lms.djangoapps.instructor_task.data import InstructorTaskTypes from lms.djangoapps.instructor_task.models import InstructorTask, InstructorTaskSchedule @@ -107,7 +106,7 @@ from xmodule.modulestore.tests.django_utils import ( TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase, - SharedModuleStoreTestCase + SharedModuleStoreTestCase, ) from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory diff --git a/lms/djangoapps/instructor/tests/test_api_email_localization.py b/lms/djangoapps/instructor/tests/test_api_email_localization.py index a23b94ece021..36d29bb85223 100644 --- a/lms/djangoapps/instructor/tests/test_api_email_localization.py +++ b/lms/djangoapps/instructor/tests/test_api_email_localization.py @@ -8,11 +8,12 @@ from django.urls import reverse from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.tests.factories import InstructorFactory -from common.djangoapps.student.tests.factories import UserFactory +from common.djangoapps.student.tests.factories import InstructorFactory, UserFactory from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY from openedx.core.djangoapps.user_api.preferences.api import delete_user_preference, set_user_preference -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/instructor/tests/test_api_v2.py b/lms/djangoapps/instructor/tests/test_api_v2.py index 7f4055f91037..fb05b9a866c3 100644 --- a/lms/djangoapps/instructor/tests/test_api_v2.py +++ b/lms/djangoapps/instructor/tests/test_api_v2.py @@ -9,14 +9,15 @@ import ddt from django.test import SimpleTestCase, override_settings -from django.urls import NoReverseMatch -from django.urls import reverse +from django.urls import NoReverseMatch, reverse +from edx_when.api import set_date_for_block, set_dates_for_course from opaque_keys import InvalidKeyError from pytz import UTC from rest_framework import status from rest_framework.test import APIClient, APITestCase -from edx_when.api import set_dates_for_course, set_date_for_block +from common.djangoapps.course_modes.tests.factories import CourseModeFactory +from common.djangoapps.student.models.course_enrollment import CourseEnrollment from common.djangoapps.student.roles import CourseBetaTesterRole, CourseDataResearcherRole, CourseInstructorRole from common.djangoapps.student.tests.factories import ( AdminFactory, @@ -25,13 +26,11 @@ StaffFactory, UserFactory, ) -from common.djangoapps.course_modes.tests.factories import CourseModeFactory -from common.djangoapps.student.models.course_enrollment import CourseEnrollment from lms.djangoapps.courseware.models import StudentModule from lms.djangoapps.instructor.views.serializers_v2 import CourseInformationSerializerV2 from lms.djangoapps.instructor_task.tests.factories import InstructorTaskFactory -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase, TEST_DATA_SPLIT_MODULESTORE -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory @ddt.ddt diff --git a/lms/djangoapps/instructor/tests/test_certificates.py b/lms/djangoapps/instructor/tests/test_certificates.py index ce6bdbd98371..2abf7227dcd2 100644 --- a/lms/djangoapps/instructor/tests/test_certificates.py +++ b/lms/djangoapps/instructor/tests/test_certificates.py @@ -16,17 +16,17 @@ from django.urls import reverse from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.tests.factories import GlobalStaffFactory -from common.djangoapps.student.tests.factories import InstructorFactory -from common.djangoapps.student.tests.factories import UserFactory +from common.djangoapps.student.tests.factories import GlobalStaffFactory, InstructorFactory, UserFactory from lms.djangoapps.certificates import api as certs_api from lms.djangoapps.certificates.data import CertificateStatuses from lms.djangoapps.certificates.tests.factories import ( CertificateAllowlistFactory, CertificateInvalidationFactory, - GeneratedCertificateFactory + GeneratedCertificateFactory, +) +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order ) -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/instructor/tests/test_email.py b/lms/djangoapps/instructor/tests/test_email.py index 322c734fa613..07fc9c9410d1 100644 --- a/lms/djangoapps/instructor/tests/test_email.py +++ b/lms/djangoapps/instructor/tests/test_email.py @@ -10,14 +10,18 @@ from opaque_keys.edx.keys import CourseKey from common.djangoapps.student.tests.factories import AdminFactory -from lms.djangoapps.bulk_email.models_api import is_bulk_email_enabled_for_course, is_bulk_email_feature_enabled - from lms.djangoapps.bulk_email.models import BulkEmailFlag, CourseAuthorization, DisabledCourse -from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_MODULESTORE, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from lms.djangoapps.bulk_email.models_api import ( + is_bulk_email_disabled_for_course, + is_bulk_email_enabled_for_course, + is_bulk_email_feature_enabled, +) +from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order + TEST_DATA_MIXED_MODULESTORE, + SharedModuleStoreTestCase, +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order -from lms.djangoapps.bulk_email.models_api import is_bulk_email_disabled_for_course - class TestNewInstructorDashboardEmailViewMongoBacked(SharedModuleStoreTestCase): """ diff --git a/lms/djangoapps/instructor/tests/test_enrollment.py b/lms/djangoapps/instructor/tests/test_enrollment.py index d9615bf49b57..ab784685486f 100644 --- a/lms/djangoapps/instructor/tests/test_enrollment.py +++ b/lms/djangoapps/instructor/tests/test_enrollment.py @@ -16,10 +16,8 @@ from django.utils.translation import override as override_language from opaque_keys.edx.locator import CourseLocator from submissions import api as sub_api - -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory from xblocks_contrib.problem.capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory + from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentAllowed, anonymous_id_for_user from common.djangoapps.student.roles import CourseCcxCoachRole from common.djangoapps.student.tests.factories import AdminFactory, UserFactory @@ -36,12 +34,14 @@ render_message_to_string, reset_student_attempts, send_beta_role_email, - unenroll_email + unenroll_email, ) from lms.djangoapps.teams.models import CourseTeamMembership from lms.djangoapps.teams.tests.factories import CourseTeamFactory from openedx.core.djangoapps.ace_common.tests.mixins import EmailTemplateTagMixin from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, get_mock_request +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory class TestSettableEnrollmentState(CacheIsolationTestCase): diff --git a/lms/djangoapps/instructor/tests/test_enrollment_list_api.py b/lms/djangoapps/instructor/tests/test_enrollment_list_api.py index 1f342ee2b03c..d74142f4dfa3 100644 --- a/lms/djangoapps/instructor/tests/test_enrollment_list_api.py +++ b/lms/djangoapps/instructor/tests/test_enrollment_list_api.py @@ -2,16 +2,14 @@ Unit tests for instructor API enrollment list endpoints with search and pagination. """ import json + from django.urls import reverse + from common.djangoapps.student.roles import CourseBetaTesterRole -from common.djangoapps.student.tests.factories import ( - CourseEnrollmentFactory, - InstructorFactory, - UserFactory -) +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, InstructorFactory, UserFactory +from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase class TestListCourseRoleMembersWithPagination(SharedModuleStoreTestCase, LoginEnrollmentTestCase): diff --git a/lms/djangoapps/instructor/tests/test_filters.py b/lms/djangoapps/instructor/tests/test_filters.py index a676ab92a59c..979ed1fbf729 100644 --- a/lms/djangoapps/instructor/tests/test_filters.py +++ b/lms/djangoapps/instructor/tests/test_filters.py @@ -2,6 +2,7 @@ Test that various filters are fired for models/views in the instructor app. """ import re + from django.http import HttpResponse from django.test import override_settings from django.urls import reverse diff --git a/lms/djangoapps/instructor/tests/test_proctoring.py b/lms/djangoapps/instructor/tests/test_proctoring.py index 6a87538826aa..91ef5d3b7d49 100644 --- a/lms/djangoapps/instructor/tests/test_proctoring.py +++ b/lms/djangoapps/instructor/tests/test_proctoring.py @@ -14,7 +14,9 @@ from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole from common.djangoapps.student.tests.factories import AdminFactory -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/instructor/tests/test_reports_api_v2.py b/lms/djangoapps/instructor/tests/test_reports_api_v2.py index e7904bcbfc08..1fb56f0dd5ca 100644 --- a/lms/djangoapps/instructor/tests/test_reports_api_v2.py +++ b/lms/djangoapps/instructor/tests/test_reports_api_v2.py @@ -9,11 +9,7 @@ from rest_framework.test import APIClient from common.djangoapps.student.roles import CourseDataResearcherRole -from common.djangoapps.student.tests.factories import ( - InstructorFactory, - StaffFactory, - UserFactory, -) +from common.djangoapps.student.tests.factories import InstructorFactory, StaffFactory, UserFactory from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/lms/djangoapps/instructor/tests/test_spoc_gradebook.py b/lms/djangoapps/instructor/tests/test_spoc_gradebook.py index 4c1a691f6018..eeb2ec3107da 100644 --- a/lms/djangoapps/instructor/tests/test_spoc_gradebook.py +++ b/lms/djangoapps/instructor/tests/test_spoc_gradebook.py @@ -2,13 +2,18 @@ Tests of the instructor dashboard spoc gradebook """ from django.urls import reverse - from xblocks_contrib.problem.capa.tests.response_xml_factory import StringResponseXMLFactory + from common.djangoapps.student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory from lms.djangoapps.courseware.tests.factories import StudentModuleFactory from lms.djangoapps.grades.api import task_compute_all_grades_for_course -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) USER_COUNT = 11 diff --git a/lms/djangoapps/instructor/tests/test_tasks.py b/lms/djangoapps/instructor/tests/test_tasks.py index 4c6f9016f4fa..c05ffc3fee1f 100644 --- a/lms/djangoapps/instructor/tests/test_tasks.py +++ b/lms/djangoapps/instructor/tests/test_tasks.py @@ -11,11 +11,12 @@ from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.courseware.models import StudentModule from lms.djangoapps.instructor.tasks import update_exam_completion_task -from xmodule.modulestore.tests.django_utils import \ - SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order BlockFactory, - CourseFactory + CourseFactory, ) from xmodule.partitions.partitions import Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/instructor/tests/test_tools.py b/lms/djangoapps/instructor/tests/test_tools.py index 243f2afec467..fe2656e91219 100644 --- a/lms/djangoapps/instructor/tests/test_tools.py +++ b/lms/djangoapps/instructor/tests/test_tools.py @@ -18,13 +18,15 @@ from opaque_keys.edx.keys import CourseKey from pytz import UTC from xblock.fields import Date -from xmodule.modulestore.tests.django_utils import ( - TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase, SharedModuleStoreTestCase, -) -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from openedx.core.djangoapps.course_date_signals import handlers +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_SPLIT_MODULESTORE, + ModuleStoreTestCase, + SharedModuleStoreTestCase, +) +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory from ..views import tools diff --git a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py index e48098b9ef80..6623f9ec9867 100644 --- a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py +++ b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py @@ -14,16 +14,17 @@ from edx_toggles.toggles.testutils import override_waffle_flag from pyquery import PyQuery as pq from pytz import UTC -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory, check_mongo_calls from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.edxmako.shortcuts import render_to_response from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.tests.factories import AdminFactory, CourseAccessRoleFactory, CourseEnrollmentFactory -from common.djangoapps.student.tests.factories import StaffFactory -from common.djangoapps.student.tests.factories import UserFactory +from common.djangoapps.student.tests.factories import ( + AdminFactory, + CourseAccessRoleFactory, + CourseEnrollmentFactory, + StaffFactory, + UserFactory, +) from common.test.utils import XssTestMixin from lms.djangoapps.courseware.courses import get_studio_url from lms.djangoapps.courseware.masquerade import CourseMasquerade @@ -36,9 +37,12 @@ from openedx.core.djangoapps.course_groups.cohorts import set_course_cohorted from openedx.core.djangoapps.discussions.config.waffle import ( ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND, - OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG + OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG, ) from openedx.core.djangoapps.site_configuration.models import SiteConfiguration +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory, check_mongo_calls def intercept_renderer(path, context): diff --git a/lms/djangoapps/instructor/toggles.py b/lms/djangoapps/instructor/toggles.py index 556ab7fef4c9..340079868722 100644 --- a/lms/djangoapps/instructor/toggles.py +++ b/lms/djangoapps/instructor/toggles.py @@ -4,7 +4,6 @@ from edx_toggles.toggles import WaffleFlag - # Namespace for instructor waffle flags. WAFFLE_FLAG_NAMESPACE = 'instructor' diff --git a/lms/djangoapps/instructor/urls.py b/lms/djangoapps/instructor/urls.py index f312c9b55aac..512251580b53 100644 --- a/lms/djangoapps/instructor/urls.py +++ b/lms/djangoapps/instructor/urls.py @@ -5,6 +5,7 @@ from django.urls import include, path, re_path from openedx.core.constants import COURSE_ID_PATTERN + from .views import api_urls urlpatterns = [ diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index c02e4ff79307..b708a38f66d7 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -10,20 +10,20 @@ import datetime import json import logging -import string import random import re +import string import dateutil -import pytz import edx_api_doc_tools as apidocs +import pytz from django.conf import settings from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist, PermissionDenied, ValidationError from django.core.validators import validate_email from django.db import IntegrityError, transaction from django.db.models import Q -from django.http import QueryDict, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseNotFound +from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseNotFound, QueryDict from django.shortcuts import redirect from django.urls import reverse from django.utils.decorators import method_decorator @@ -37,15 +37,18 @@ from edx_when.api import get_date_for_block from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey, UsageKey -from openedx.core.djangoapps.course_groups.cohorts import get_cohort_by_name -from rest_framework.exceptions import MethodNotAllowed from rest_framework import serializers, status # lint-amnesty, pylint: disable=wrong-import-order -from rest_framework.permissions import IsAdminUser, IsAuthenticated, BasePermission # lint-amnesty, pylint: disable=wrong-import-order +from rest_framework.exceptions import MethodNotAllowed +from rest_framework.permissions import ( # lint-amnesty, pylint: disable=wrong-import-order + BasePermission, + IsAdminUser, + IsAuthenticated, +) from rest_framework.response import Response # lint-amnesty, pylint: disable=wrong-import-order from rest_framework.views import APIView # lint-amnesty, pylint: disable=wrong-import-order -from submissions import api as sub_api # installed from the edx-submissions repository # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order +from submissions import ( + api as sub_api, # installed from the edx-submissions repository # lint-amnesty, pylint: disable=wrong-import-order +) from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student import auth @@ -53,17 +56,17 @@ from common.djangoapps.student.models import ( ALLOWEDTOENROLL_TO_ENROLLED, ALLOWEDTOENROLL_TO_UNENROLLED, - CourseEnrollment, - CourseEnrollmentAllowed, DEFAULT_TRANSITION_STATE, ENROLLED_TO_ENROLLED, ENROLLED_TO_UNENROLLED, - EntranceExamConfiguration, - ManualEnrollmentAudit, - Registration, UNENROLLED_TO_ALLOWEDTOENROLL, UNENROLLED_TO_ENROLLED, UNENROLLED_TO_UNENROLLED, + CourseEnrollment, + CourseEnrollmentAllowed, + EntranceExamConfiguration, + ManualEnrollmentAudit, + Registration, UserProfile, get_user_by_username_or_email, is_email_retired, @@ -76,7 +79,7 @@ ) from common.djangoapps.util.json_request import JsonResponse, JsonResponseBadRequest from common.djangoapps.util.views import require_global_staff # pylint: disable=unused-import -from lms.djangoapps.bulk_email.api import is_bulk_email_feature_enabled, create_course_email +from lms.djangoapps.bulk_email.api import create_course_email, is_bulk_email_feature_enabled from lms.djangoapps.certificates import api as certs_api from lms.djangoapps.course_home_api.toggles import course_home_mfe_progress_tab_is_active from lms.djangoapps.courseware.access import has_access @@ -94,11 +97,6 @@ unenroll_email, ) from lms.djangoapps.instructor.views.instructor_task_helpers import extract_email_features, extract_task_features -from lms.djangoapps.instructor_analytics import basic as instructor_analytics_basic, csvs as instructor_analytics_csvs -from lms.djangoapps.instructor_task import api as task_api -from lms.djangoapps.instructor_task.api_helper import AlreadyRunningError, QueueConnectionError -from lms.djangoapps.instructor_task.data import InstructorTaskTypes -from lms.djangoapps.instructor_task.models import ReportStore from lms.djangoapps.instructor.views.serializer import ( AccessSerializer, BlockDueDateSerializer, @@ -108,35 +106,42 @@ ForumRoleNameSerializer, ListInstructorTaskInputSerializer, ModifyAccessSerializer, + OverrideProblemScoreSerializer, + ProblemResetSerializer, + RescoreEntranceExamSerializer, + ResetEntranceExamAttemptsSerializer, RoleNameSerializer, SendEmailSerializer, - ShowUnitExtensionsSerializer, ShowStudentExtensionSerializer, + ShowUnitExtensionsSerializer, StudentAttemptsSerializer, - UserSerializer, + StudentsUpdateEnrollmentSerializer, UniqueStudentIdentifierSerializer, - ProblemResetSerializer, UpdateForumRoleMembershipSerializer, - RescoreEntranceExamSerializer, - OverrideProblemScoreSerializer, - StudentsUpdateEnrollmentSerializer, - ResetEntranceExamAttemptsSerializer + UserSerializer, ) +from lms.djangoapps.instructor_analytics import basic as instructor_analytics_basic +from lms.djangoapps.instructor_analytics import csvs as instructor_analytics_csvs +from lms.djangoapps.instructor_task import api as task_api +from lms.djangoapps.instructor_task.api_helper import AlreadyRunningError, QueueConnectionError +from lms.djangoapps.instructor_task.data import InstructorTaskTypes +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 add_user_to_cohort, is_course_cohorted +from openedx.core.djangoapps.course_groups.cohorts import add_user_to_cohort, get_cohort_by_name, is_course_cohorted from openedx.core.djangoapps.course_groups.models import CourseUserGroup -from openedx.core.djangoapps.django_comment_common.models import ( - CourseDiscussionSettings, - Role, -) +from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings, Role from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.user_api.preferences.api import get_user_preference from openedx.core.djangolib.markup import HTML, Text from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser +from openedx.core.lib.api.serializers import CourseKeyField from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes from openedx.core.lib.courses import get_course_by_id -from openedx.core.lib.api.serializers import CourseKeyField from openedx.features.course_experience.url_helpers import get_learning_mfe_home_url +from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order + +from .. import permissions from .tools import ( DashboardError, dump_block_extensions, @@ -148,7 +153,6 @@ set_due_date_extension, strip_if_string, ) -from .. import permissions log = logging.getLogger(__name__) diff --git a/lms/djangoapps/instructor/views/api_urls.py b/lms/djangoapps/instructor/views/api_urls.py index f2a19ddef492..12472f7c3f88 100644 --- a/lms/djangoapps/instructor/views/api_urls.py +++ b/lms/djangoapps/instructor/views/api_urls.py @@ -5,7 +5,7 @@ from django.urls import path, re_path -from lms.djangoapps.instructor.views import api, gradebook_api, api_v2 +from lms.djangoapps.instructor.views import api, api_v2, gradebook_api from openedx.core.constants import COURSE_ID_PATTERN # These endpoints are exposing existing views in a way that can be used by MFEs diff --git a/lms/djangoapps/instructor/views/api_v2.py b/lms/djangoapps/instructor/views/api_v2.py index 28966425b56f..6be95187beca 100644 --- a/lms/djangoapps/instructor/views/api_v2.py +++ b/lms/djangoapps/instructor/views/api_v2.py @@ -13,7 +13,6 @@ from datetime import datetime from typing import Optional, Tuple - import edx_api_doc_tools as apidocs from django.conf import settings from django.db import transaction @@ -32,46 +31,40 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.exceptions import ItemNotFoundError from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.roles import CourseBetaTesterRole from common.djangoapps.util.json_request import JsonResponseBadRequest -from openedx.core.djangoapps.course_groups.cohorts import is_course_cohorted -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers - from lms.djangoapps.courseware.tabs import get_course_tab_list from lms.djangoapps.instructor import permissions -from lms.djangoapps.instructor.views.api import _display_unit, get_student_from_identifier -from lms.djangoapps.instructor.views.instructor_task_helpers import extract_task_features -from lms.djangoapps.instructor_task import api as task_api -from lms.djangoapps.instructor_task.api_helper import AlreadyRunningError, QueueConnectionError from lms.djangoapps.instructor.constants import ReportType from lms.djangoapps.instructor.ora import get_open_response_assessment_list, get_ora_summary +from lms.djangoapps.instructor.views.api import _display_unit, get_student_from_identifier +from lms.djangoapps.instructor.views.instructor_task_helpers import extract_task_features from lms.djangoapps.instructor_analytics import basic as instructor_analytics_basic from lms.djangoapps.instructor_analytics import csvs as instructor_analytics_csvs +from lms.djangoapps.instructor_task import api as task_api +from lms.djangoapps.instructor_task.api_helper import AlreadyRunningError, QueueConnectionError from lms.djangoapps.instructor_task.models import ReportStore from lms.djangoapps.instructor_task.tasks_helper.utils import upload_csv_file_to_report_store +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.lib.api.view_utils import DeveloperErrorViewMixin from openedx.core.lib.courses import get_course_by_id +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.exceptions import ItemNotFoundError + from .filters_v2 import CourseEnrollmentFilter from .serializers_v2 import ( - InstructorTaskListSerializer, - CourseInformationSerializerV2, BlockDueDateSerializerV2, CourseEnrollmentSerializerV2, - UnitExtensionSerializer, + CourseInformationSerializerV2, + InstructorTaskListSerializer, ORASerializer, ORASummarySerializer, + UnitExtensionSerializer, ) -from .tools import ( - find_unit, - get_units_with_due_date, - keep_field_private, - set_due_date_extension, - title_or_url, -) +from .tools import find_unit, get_units_with_due_date, keep_field_private, set_due_date_extension, title_or_url log = logging.getLogger(__name__) diff --git a/lms/djangoapps/instructor/views/instructor_dashboard.py b/lms/djangoapps/instructor/views/instructor_dashboard.py index 2cc86c42464b..487e4f136f43 100644 --- a/lms/djangoapps/instructor/views/instructor_dashboard.py +++ b/lms/djangoapps/instructor/views/instructor_dashboard.py @@ -31,7 +31,7 @@ CourseFinanceAdminRole, CourseInstructorRole, CourseSalesAdminRole, - CourseStaffRole + CourseStaffRole, ) from common.djangoapps.util.json_request import JsonResponse from common.djangoapps.util.proctoring import requires_escalation_email @@ -56,9 +56,10 @@ from openedx.core.lib.courses import get_course_by_id from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.tabs import CourseTab # lint-amnesty, pylint: disable=wrong-import-order -from .tools import get_units_with_due_date, title_or_url + from .. import permissions from ..toggles import data_download_v2_is_enabled +from .tools import get_units_with_due_date, title_or_url log = logging.getLogger(__name__) diff --git a/lms/djangoapps/instructor/views/instructor_task_helpers.py b/lms/djangoapps/instructor/views/instructor_task_helpers.py index c3bcb0506d49..e50687da3a77 100644 --- a/lms/djangoapps/instructor/views/instructor_task_helpers.py +++ b/lms/djangoapps/instructor/views/instructor_task_helpers.py @@ -11,8 +11,8 @@ from django.utils.translation import ngettext from lms.djangoapps.bulk_email.models import CourseEmail -from lms.djangoapps.instructor_task.views import get_task_completion_info from lms.djangoapps.instructor_task.models import InstructorTaskSchedule +from lms.djangoapps.instructor_task.views import get_task_completion_info log = logging.getLogger(__name__) diff --git a/lms/djangoapps/instructor/views/serializer.py b/lms/djangoapps/instructor/views/serializer.py index 9e0603be6eb2..e473d97a21a9 100644 --- a/lms/djangoapps/instructor/views/serializer.py +++ b/lms/djangoapps/instructor/views/serializer.py @@ -7,17 +7,14 @@ from rest_framework import serializers from lms.djangoapps.certificates.data import CertificateStatuses +from lms.djangoapps.discussion.django_comment_client.utils import get_group_id_for_user, get_group_name from lms.djangoapps.instructor.access import ROLES from openedx.core.djangoapps.django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_GROUP_MODERATOR, FORUM_ROLE_MODERATOR, - Role -) -from lms.djangoapps.discussion.django_comment_client.utils import ( - get_group_id_for_user, - get_group_name + Role, ) from .tools import get_student_from_identifier diff --git a/lms/djangoapps/instructor/views/serializers_v2.py b/lms/djangoapps/instructor/views/serializers_v2.py index 09d6357bf7bc..9e53bb4d7fba 100644 --- a/lms/djangoapps/instructor/views/serializers_v2.py +++ b/lms/djangoapps/instructor/views/serializers_v2.py @@ -22,9 +22,7 @@ CourseStaffRole, ) from lms.djangoapps.bulk_email.api import is_bulk_email_feature_enabled -from lms.djangoapps.certificates.models import ( - CertificateGenerationConfiguration -) +from lms.djangoapps.certificates.models import CertificateGenerationConfiguration from lms.djangoapps.courseware.access import has_access from lms.djangoapps.courseware.courses import get_studio_url from lms.djangoapps.discussion.django_comment_client.utils import has_forum_access @@ -33,9 +31,7 @@ from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_ADMINISTRATOR from xmodule.modulestore.django import modulestore - -from .tools import get_student_from_identifier, parse_datetime, DashboardError - +from .tools import DashboardError, get_student_from_identifier, parse_datetime log = logging.getLogger(__name__) diff --git a/lms/djangoapps/instructor_analytics/basic.py b/lms/djangoapps/instructor_analytics/basic.py index 5f9dfc8a3203..5ec241ee897e 100644 --- a/lms/djangoapps/instructor_analytics/basic.py +++ b/lms/djangoapps/instructor_analytics/basic.py @@ -19,8 +19,8 @@ import xmodule.graders as xmgraders from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentAllowed -from lms.djangoapps.certificates.data import CertificateStatuses from lms.djangoapps.certificates.api import get_certificates_by_course_and_status +from lms.djangoapps.certificates.data import CertificateStatuses from lms.djangoapps.courseware.models import StudentModule from lms.djangoapps.grades.api import context as grades_context from lms.djangoapps.program_enrollments.api import fetch_program_enrollments_by_students diff --git a/lms/djangoapps/instructor_analytics/tests/test_basic.py b/lms/djangoapps/instructor_analytics/tests/test_basic.py index 9f97e5f901d6..72b387832b64 100644 --- a/lms/djangoapps/instructor_analytics/tests/test_basic.py +++ b/lms/djangoapps/instructor_analytics/tests/test_basic.py @@ -3,16 +3,20 @@ """ -from unittest.mock import MagicMock, Mock, patch - import datetime +import json # lint-amnesty, pylint: disable=wrong-import-order import random +from unittest.mock import MagicMock, Mock, patch + import ddt -import json # lint-amnesty, pylint: disable=wrong-import-order from django.contrib.auth import get_user_model from edx_proctoring.api import create_exam from edx_proctoring.models import ProctoredExamStudentAttempt from opaque_keys.edx.locator import UsageKey + +from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentAllowed +from common.djangoapps.student.tests.factories import InstructorFactory, UserFactory +from lms.djangoapps.certificates.api import create_generated_certificate from lms.djangoapps.instructor_analytics.basic import ( # lint-amnesty, pylint: disable=unused-import AVAILABLE_FEATURES, ENROLLMENT_FEATURES, @@ -20,23 +24,21 @@ PROGRAM_ENROLLMENT_FEATURES, STUDENT_FEATURES, StudentModule, - issued_certificates, enrolled_students_features, get_available_features, get_proctored_exam_results, get_response_state, get_student_features_with_custom, + issued_certificates, list_may_enroll, - list_problem_responses + list_problem_responses, ) from lms.djangoapps.program_enrollments.tests.factories import ProgramEnrollmentFactory -from lms.djangoapps.certificates.api import create_generated_certificate from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory -from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentAllowed -from common.djangoapps.student.tests.factories import InstructorFactory -from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order User = get_user_model() diff --git a/lms/djangoapps/instructor_task/api.py b/lms/djangoapps/instructor_task/api.py index ecf7deaee21b..da0c613aa48b 100644 --- a/lms/djangoapps/instructor_task/api.py +++ b/lms/djangoapps/instructor_task/api.py @@ -25,11 +25,11 @@ encode_entrance_exam_and_student_input, encode_problem_and_student_input, schedule_task, - submit_task, submit_scheduled_task, + submit_task, ) from lms.djangoapps.instructor_task.data import InstructorTaskTypes -from lms.djangoapps.instructor_task.models import InstructorTask, InstructorTaskSchedule, SCHEDULED +from lms.djangoapps.instructor_task.models import SCHEDULED, InstructorTask, InstructorTaskSchedule from lms.djangoapps.instructor_task.tasks import ( calculate_grades_csv, calculate_inactive_enrolled_students_info_csv, @@ -43,13 +43,13 @@ export_ora2_data, export_ora2_submission_files, export_ora2_summary, + generate_anonymous_ids_for_course, generate_certificates, override_problem_score, proctored_exam_results_csv, rescore_problem, reset_problem_attempts, send_bulk_course_email, - generate_anonymous_ids_for_course ) from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/instructor_task/api_helper.py b/lms/djangoapps/instructor_task/api_helper.py index 9e6bd2f6c957..f47d3c27b948 100644 --- a/lms/djangoapps/instructor_task/api_helper.py +++ b/lms/djangoapps/instructor_task/api_helper.py @@ -14,14 +14,13 @@ from celery.states import FAILURE, READY_STATES, REVOKED, SUCCESS from django.utils.translation import gettext as _ from opaque_keys.edx.keys import UsageKey -from xmodule.modulestore.django import modulestore from common.djangoapps.util.db import outer_atomic from lms.djangoapps.courseware.courses import get_problems_in_section from lms.djangoapps.instructor_task.data import InstructorTaskTypes from lms.djangoapps.instructor_task.models import PROGRESS, SCHEDULED, InstructorTask, InstructorTaskSchedule - from lms.djangoapps.instructor_task.tasks import send_bulk_course_email +from xmodule.modulestore.django import modulestore log = logging.getLogger(__name__) diff --git a/lms/djangoapps/instructor_task/config/waffle.py b/lms/djangoapps/instructor_task/config/waffle.py index 224e2d98d6b3..e142e6bd3292 100644 --- a/lms/djangoapps/instructor_task/config/waffle.py +++ b/lms/djangoapps/instructor_task/config/waffle.py @@ -5,7 +5,6 @@ from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag - WAFFLE_NAMESPACE = 'instructor_task' # Course override flags 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 28e611eae64f..a4fe262b656e 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 @@ -4,8 +4,9 @@ from datetime import datetime -import pytest + import ddt +import pytest import pytz from celery.states import FAILURE from django.core.management import call_command diff --git a/lms/djangoapps/instructor_task/migrations/0004_historicalinstructortaskschedule_instructortaskschedule.py b/lms/djangoapps/instructor_task/migrations/0004_historicalinstructortaskschedule_instructortaskschedule.py index 36b6ddb1868c..7cf54ec0fd3b 100644 --- a/lms/djangoapps/instructor_task/migrations/0004_historicalinstructortaskschedule_instructortaskschedule.py +++ b/lms/djangoapps/instructor_task/migrations/0004_historicalinstructortaskschedule_instructortaskschedule.py @@ -1,11 +1,11 @@ # Generated by Django 3.2.12 on 2022-03-22 18:49 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields import simple_history.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/instructor_task/migrations/0005_alter_instructortaskschedule_task.py b/lms/djangoapps/instructor_task/migrations/0005_alter_instructortaskschedule_task.py index d3f7f426e1e1..acc8630026d8 100644 --- a/lms/djangoapps/instructor_task/migrations/0005_alter_instructortaskschedule_task.py +++ b/lms/djangoapps/instructor_task/migrations/0005_alter_instructortaskschedule_task.py @@ -1,7 +1,7 @@ # Generated by Django 3.2.13 on 2022-04-26 13:32 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/instructor_task/models.py b/lms/djangoapps/instructor_task/models.py index fb5eef52a327..b903de9ec57c 100644 --- a/lms/djangoapps/instructor_task/models.py +++ b/lms/djangoapps/instructor_task/models.py @@ -25,7 +25,6 @@ from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.core.files.base import ContentFile from django.db import models, transaction - from django.utils.translation import gettext as _ from model_utils.models import TimeStampedModel from opaque_keys.edx.django.models import CourseKeyField diff --git a/lms/djangoapps/instructor_task/rest_api/urls.py b/lms/djangoapps/instructor_task/rest_api/urls.py index 6387fe6eb189..ceba707ad668 100644 --- a/lms/djangoapps/instructor_task/rest_api/urls.py +++ b/lms/djangoapps/instructor_task/rest_api/urls.py @@ -1,12 +1,10 @@ """ Instructor Task Django app root REST API URLs. """ -from django.urls import include -from django.urls import path +from django.urls import include, path from lms.djangoapps.instructor_task.rest_api.v1 import urls as v1_urls - app_name = "lms.djangoapps.instructor_task" urlpatterns = [ diff --git a/lms/djangoapps/instructor_task/rest_api/v1/tests/test_views.py b/lms/djangoapps/instructor_task/rest_api/v1/tests/test_views.py index bb338f0bf480..a20f22085f2f 100644 --- a/lms/djangoapps/instructor_task/rest_api/v1/tests/test_views.py +++ b/lms/djangoapps/instructor_task/rest_api/v1/tests/test_views.py @@ -4,27 +4,22 @@ import datetime import json from uuid import uuid4 -import pytz -from celery.states import REVOKED import ddt +import pytz +from celery.states import REVOKED from django.contrib.auth import get_user_model from rest_framework.test import APITestCase -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory -from common.djangoapps.student.tests.factories import ( - GlobalStaffFactory, - InstructorFactory, - StaffFactory, - UserFactory, -) +from common.djangoapps.student.tests.factories import GlobalStaffFactory, InstructorFactory, StaffFactory, UserFactory from lms.djangoapps.bulk_email.api import create_course_email, get_course_email from lms.djangoapps.bulk_email.data import BulkEmailTargetChoices from lms.djangoapps.instructor_task.data import InstructorTaskTypes -from lms.djangoapps.instructor_task.models import InstructorTask, InstructorTaskSchedule, PROGRESS, SCHEDULED +from lms.djangoapps.instructor_task.models import PROGRESS, SCHEDULED, InstructorTask, InstructorTaskSchedule from lms.djangoapps.instructor_task.tests.factories import InstructorTaskFactory, InstructorTaskScheduleFactory from openedx.core.lib.html_to_text import html_to_text +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory User = get_user_model() diff --git a/lms/djangoapps/instructor_task/rest_api/v1/urls.py b/lms/djangoapps/instructor_task/rest_api/v1/urls.py index 8b4064204cdd..bb6a4557a07d 100644 --- a/lms/djangoapps/instructor_task/rest_api/v1/urls.py +++ b/lms/djangoapps/instructor_task/rest_api/v1/urls.py @@ -6,10 +6,9 @@ from lms.djangoapps.instructor_task.rest_api.v1.views import ( ListScheduledBulkEmailInstructorTasks, - ModifyScheduledBulkEmailInstructorTask + ModifyScheduledBulkEmailInstructorTask, ) - urlpatterns = [ re_path( fr"schedules/{settings.COURSE_ID_PATTERN}/bulk_email/$", diff --git a/lms/djangoapps/instructor_task/rest_api/v1/views.py b/lms/djangoapps/instructor_task/rest_api/v1/views.py index 812b88e11da3..f9d169d98222 100644 --- a/lms/djangoapps/instructor_task/rest_api/v1/views.py +++ b/lms/djangoapps/instructor_task/rest_api/v1/views.py @@ -4,20 +4,20 @@ import datetime import json import logging -import pytz import dateutil +import pytz from celery.states import REVOKED from django.db import transaction -from rest_framework.response import Response from rest_framework import generics, status +from rest_framework.response import Response from lms.djangoapps.bulk_email.api import update_course_email from lms.djangoapps.instructor_task.data import InstructorTaskTypes -from lms.djangoapps.instructor_task.models import InstructorTask, InstructorTaskSchedule, SCHEDULED +from lms.djangoapps.instructor_task.models import SCHEDULED, InstructorTask, InstructorTaskSchedule from lms.djangoapps.instructor_task.rest_api.v1.exceptions import TaskUpdateException -from lms.djangoapps.instructor_task.rest_api.v1.serializers import ScheduledBulkEmailSerializer from lms.djangoapps.instructor_task.rest_api.v1.permissions import CanViewOrModifyScheduledBulkCourseEmailTasks +from lms.djangoapps.instructor_task.rest_api.v1.serializers import ScheduledBulkEmailSerializer log = logging.getLogger(__name__) diff --git a/lms/djangoapps/instructor_task/subtasks.py b/lms/djangoapps/instructor_task/subtasks.py index db0d2380ea78..8fe1329cd1cf 100644 --- a/lms/djangoapps/instructor_task/subtasks.py +++ b/lms/djangoapps/instructor_task/subtasks.py @@ -15,7 +15,6 @@ from django.core.cache import cache from django.db import DatabaseError, transaction - from common.djangoapps.util.db import outer_atomic from .exceptions import DuplicateTaskException diff --git a/lms/djangoapps/instructor_task/tasks.py b/lms/djangoapps/instructor_task/tasks.py index 7a9dabe3d51c..a17551115a59 100644 --- a/lms/djangoapps/instructor_task/tasks.py +++ b/lms/djangoapps/instructor_task/tasks.py @@ -33,25 +33,24 @@ from lms.djangoapps.instructor_task.tasks_helper.enrollments import ( upload_inactive_enrolled_students_info_csv, upload_may_enroll_csv, - upload_students_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, + generate_anonymous_ids, upload_course_survey_report, upload_ora2_data, upload_ora2_submission_files, upload_ora2_summary, upload_proctored_exam_results_report, - generate_anonymous_ids ) - from lms.djangoapps.instructor_task.tasks_helper.module_state import ( delete_problem_module_state, override_score_module_state, perform_module_state_update, rescore_problem_module_state, - reset_attempts_module_state + reset_attempts_module_state, ) from lms.djangoapps.instructor_task.tasks_helper.runner import run_main_task diff --git a/lms/djangoapps/instructor_task/tasks_helper/certs.py b/lms/djangoapps/instructor_task/tasks_helper/certs.py index 8ea80cce6a9a..98ca18dbf558 100644 --- a/lms/djangoapps/instructor_task/tasks_helper/certs.py +++ b/lms/djangoapps/instructor_task/tasks_helper/certs.py @@ -4,7 +4,6 @@ import logging - from time import time from django.contrib.auth import get_user_model @@ -13,8 +12,8 @@ from common.djangoapps.student.models import CourseEnrollment from lms.djangoapps.certificates.api import ( generate_certificate_task, + get_enrolled_allowlisted_not_passing_users, get_enrolled_allowlisted_users, - get_enrolled_allowlisted_not_passing_users ) from lms.djangoapps.certificates.data import CertificateStatuses diff --git a/lms/djangoapps/instructor_task/tasks_helper/enrollments.py b/lms/djangoapps/instructor_task/tasks_helper/enrollments.py index 468786323b79..4adf20ef1310 100644 --- a/lms/djangoapps/instructor_task/tasks_helper/enrollments.py +++ b/lms/djangoapps/instructor_task/tasks_helper/enrollments.py @@ -6,14 +6,16 @@ import logging from datetime import datetime from time import time + from pytz import UTC + +from common.djangoapps.student.models import CourseEnrollment # lint-amnesty, pylint: disable=unused-import from lms.djangoapps.instructor_analytics.basic import ( enrolled_students_features, list_inactive_enrolled_students, list_may_enroll, ) from lms.djangoapps.instructor_analytics.csvs import format_dictlist -from common.djangoapps.student.models import CourseEnrollment # lint-amnesty, pylint: disable=unused-import from .runner import TaskProgress from .utils import upload_csv_to_report_store # lint-amnesty, pylint: disable=unused-import diff --git a/lms/djangoapps/instructor_task/tasks_helper/grades.py b/lms/djangoapps/instructor_task/tasks_helper/grades.py index edbe6b4f2e80..bd8c2917444b 100644 --- a/lms/djangoapps/instructor_task/tasks_helper/grades.py +++ b/lms/djangoapps/instructor_task/tasks_helper/grades.py @@ -9,7 +9,6 @@ from datetime import datetime from itertools import chain from tempfile import TemporaryFile - from time import time from django.conf import settings @@ -27,9 +26,8 @@ from lms.djangoapps.course_blocks.api import get_course_block_access_transformers, get_course_blocks from lms.djangoapps.course_blocks.transformers import library_content from lms.djangoapps.courseware.user_state_client import DjangoXBlockUserStateClient -from lms.djangoapps.grades.api import CourseGradeFactory +from lms.djangoapps.grades.api import CourseGradeFactory, prefetch_course_and_subsection_grades from lms.djangoapps.grades.api import context as grades_context -from lms.djangoapps.grades.api import prefetch_course_and_subsection_grades from lms.djangoapps.instructor_analytics.basic import list_problem_responses from lms.djangoapps.instructor_analytics.csvs import format_dictlist from lms.djangoapps.instructor_task.config.waffle import ( @@ -51,7 +49,7 @@ from xmodule.split_test_block import get_split_user_partitions # lint-amnesty, pylint: disable=wrong-import-order from .runner import TaskProgress -from .utils import upload_csv_to_report_store, upload_csv_file_to_report_store +from .utils import upload_csv_file_to_report_store, upload_csv_to_report_store TASK_LOG = logging.getLogger('edx.celery.task') diff --git a/lms/djangoapps/instructor_task/tasks_helper/misc.py b/lms/djangoapps/instructor_task/tasks_helper/misc.py index 85a5d4e1361e..86f7ed873014 100644 --- a/lms/djangoapps/instructor_task/tasks_helper/misc.py +++ b/lms/djangoapps/instructor_task/tasks_helper/misc.py @@ -19,7 +19,7 @@ from openassessment.data import OraAggregateData, OraDownloadData from pytz import UTC -from common.djangoapps.student.models import unique_id_for_user, anonymous_id_for_user +from common.djangoapps.student.models import anonymous_id_for_user, unique_id_for_user from lms.djangoapps.instructor_analytics.basic import get_proctored_exam_results from lms.djangoapps.instructor_analytics.csvs import format_dictlist from lms.djangoapps.survey.models import SurveyAnswer @@ -27,13 +27,7 @@ from openedx.core.djangoapps.course_groups.models import CourseUserGroup from .runner import TaskProgress -from .utils import ( - UPDATE_STATUS_FAILED, - UPDATE_STATUS_SUCCEEDED, - upload_csv_to_report_store, - upload_zip_to_report_store, - -) +from .utils import UPDATE_STATUS_FAILED, UPDATE_STATUS_SUCCEEDED, upload_csv_to_report_store, upload_zip_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 9576b95c4b3e..8e27d8930553 100644 --- a/lms/djangoapps/instructor_task/tasks_helper/module_state.py +++ b/lms/djangoapps/instructor_task/tasks_helper/module_state.py @@ -10,16 +10,16 @@ from django.utils.translation import gettext_noop from opaque_keys.edx.keys import UsageKey from xblock.scorable import Score - from xblocks_contrib.problem.capa.responsetypes import LoncapaProblemError, ResponseError, StudentInputError + from common.djangoapps.student.models import get_user_by_username_or_email from common.djangoapps.track.event_transaction_utils import create_new_event_transaction_id, set_event_transaction_type from common.djangoapps.track.views import task_track from common.djangoapps.util.db import outer_atomic +from lms.djangoapps.courseware.block_render import get_block_for_descriptor from lms.djangoapps.courseware.courses import get_problems_in_section from lms.djangoapps.courseware.model_data import FieldDataCache from lms.djangoapps.courseware.models import StudentModule -from lms.djangoapps.courseware.block_render import get_block_for_descriptor from lms.djangoapps.grades.api import events as grades_events from openedx.core.lib.courses import get_course_by_id from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/instructor_task/tests/test_api.py b/lms/djangoapps/instructor_task/tests/test_api.py index beeb9e1c4222..ddd4bf980c5b 100644 --- a/lms/djangoapps/instructor_task/tests/test_api.py +++ b/lms/djangoapps/instructor_task/tests/test_api.py @@ -7,19 +7,18 @@ from unittest.mock import MagicMock, Mock, patch from uuid import uuid4 +import ddt import pytest import pytz -import ddt -from testfixtures import LogCapture from celery.states import FAILURE, SUCCESS -from xmodule.modulestore.exceptions import ItemNotFoundError +from testfixtures import LogCapture from common.djangoapps.student.tests.factories import UserFactory from common.test.utils import normalize_repr from lms.djangoapps.bulk_email.api import create_course_email from lms.djangoapps.bulk_email.data import BulkEmailTargetChoices -from lms.djangoapps.certificates.data import CertificateStatuses from lms.djangoapps.certificates.api import get_certificate_generation_history +from lms.djangoapps.certificates.data import CertificateStatuses from lms.djangoapps.instructor_task.api import ( SpecificStudentIdMissingError, generate_anonymous_ids, @@ -59,8 +58,9 @@ InstructorTaskCourseTestCase, InstructorTaskModuleTestCase, InstructorTaskTestCase, - TestReportMixin + TestReportMixin, ) +from xmodule.modulestore.exceptions import ItemNotFoundError LOG_PATH = 'lms.djangoapps.instructor_task.api' diff --git a/lms/djangoapps/instructor_task/tests/test_api_helper.py b/lms/djangoapps/instructor_task/tests/test_api_helper.py index f1432945013c..a40845291f3b 100644 --- a/lms/djangoapps/instructor_task/tests/test_api_helper.py +++ b/lms/djangoapps/instructor_task/tests/test_api_helper.py @@ -7,8 +7,8 @@ from unittest.mock import patch from uuid import uuid4 -from testfixtures import LogCapture from celery.states import FAILURE +from testfixtures import LogCapture from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.bulk_email.api import create_course_email diff --git a/lms/djangoapps/instructor_task/tests/test_base.py b/lms/djangoapps/instructor_task/tests/test_base.py index 518862bb4242..04b9579c101c 100644 --- a/lms/djangoapps/instructor_task/tests/test_base.py +++ b/lms/djangoapps/instructor_task/tests/test_base.py @@ -5,6 +5,7 @@ import json + # pylint: disable=attribute-defined-outside-init import os import shutil @@ -18,12 +19,8 @@ from django.urls import reverse from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locations import Location - -from xmodule.modulestore import ModuleStoreEnum -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, BlockFactory from xblocks_contrib.problem.capa.tests.response_xml_factory import OptionResponseXMLFactory + from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from lms.djangoapps.courseware.model_data import StudentModule from lms.djangoapps.courseware.tests.tests import LoginEnrollmentTestCase @@ -33,6 +30,10 @@ 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 xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory 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 bc3a229a0ad3..70f649da5233 100644 --- a/lms/djangoapps/instructor_task/tests/test_integration.py +++ b/lms/djangoapps/instructor_task/tests/test_integration.py @@ -13,23 +13,24 @@ from collections import namedtuple from unittest.mock import patch -import pytest import ddt +import pytest from celery.states import FAILURE, SUCCESS from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.test.utils import override_settings from django.urls import reverse - from xblocks_contrib.problem.capa.responsetypes import StudentInputError from xblocks_contrib.problem.capa.tests.response_xml_factory import CodeResponseXMLFactory, CustomResponseXMLFactory from xblocks_contrib.problem.capa.tests.test_util import UseUnsafeCodejail + +from common.test.utils import assert_dict_contains_subset from lms.djangoapps.courseware.model_data import StudentModule from lms.djangoapps.grades.api 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_reset_problem_attempts_for_all_students, ) from lms.djangoapps.instructor_task.data import InstructorTaskTypes from lms.djangoapps.instructor_task.models import InstructorTask @@ -38,13 +39,12 @@ OPTION_1, OPTION_2, InstructorTaskModuleTestCase, - TestReportMixin + TestReportMixin, ) from openedx.core.djangoapps.util.testing import TestConditionalContent from openedx.core.lib.url_utils import quote_slashes from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.tests.factories import BlockFactory # lint-amnesty, pylint: disable=wrong-import-order -from common.test.utils import assert_dict_contains_subset 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 ff8e602b19b5..7e71c33f6cd7 100644 --- a/lms/djangoapps/instructor_task/tests/test_models.py +++ b/lms/djangoapps/instructor_task/tests/test_models.py @@ -6,6 +6,7 @@ import copy import time from io import StringIO + import pytest from django.conf import settings from django.test import SimpleTestCase, TestCase, override_settings diff --git a/lms/djangoapps/instructor_task/tests/test_tasks.py b/lms/djangoapps/instructor_task/tests/test_tasks.py index fe5dca573e98..3da795541a90 100644 --- a/lms/djangoapps/instructor_task/tests/test_tasks.py +++ b/lms/djangoapps/instructor_task/tests/test_tasks.py @@ -9,8 +9,9 @@ import json from unittest.mock import MagicMock, Mock, patch from uuid import uuid4 -import pytest + import ddt +import pytest from celery.states import FAILURE, SUCCESS from django.utils.translation import gettext_noop from opaque_keys.edx.keys import i4xEncoder @@ -28,7 +29,7 @@ generate_certificates, override_problem_score, rescore_problem, - reset_problem_attempts + reset_problem_attempts, ) from lms.djangoapps.instructor_task.tests.factories import InstructorTaskFactory from lms.djangoapps.instructor_task.tests.test_base import InstructorTaskModuleTestCase diff --git a/lms/djangoapps/instructor_task/tests/test_tasks_helper.py b/lms/djangoapps/instructor_task/tests/test_tasks_helper.py index 1447a66e9b87..0df7b0a08d7e 100644 --- a/lms/djangoapps/instructor_task/tests/test_tasks_helper.py +++ b/lms/djangoapps/instructor_task/tests/test_tasks_helper.py @@ -16,7 +16,6 @@ from unittest.mock import ANY, MagicMock, Mock, patch import ddt -from openedx.core.djangolib.testing.utils import AUTHZ_TABLES import pytest import unicodecsv from django.conf import settings @@ -24,16 +23,19 @@ from edx_django_utils.cache import RequestCache from freezegun import freeze_time from pytz import UTC +from xblocks_contrib.problem.capa.tests.response_xml_factory import ( + MultipleChoiceResponseXMLFactory, # lint-amnesty, pylint: disable=wrong-import-order +) -import openedx.core.djangoapps.user_api.course_tag.api as course_tag_api import openedx.core.djangoapps.content.block_structure.api as bs_api -from xblocks_contrib.problem.capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory # lint-amnesty, pylint: disable=wrong-import-order -from lms.djangoapps.course_blocks.transformers import library_content +import openedx.core.djangoapps.user_api.course_tag.api as course_tag_api from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentAllowed from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory +from common.test.utils import assert_dict_contains_subset from lms.djangoapps.certificates.data import CertificateStatuses from lms.djangoapps.certificates.tests.factories import CertificateAllowlistFactory, GeneratedCertificateFactory +from lms.djangoapps.course_blocks.transformers import library_content from lms.djangoapps.courseware.models import StudentModule from lms.djangoapps.grades.course_data import CourseData from lms.djangoapps.grades.models import PersistentCourseGrade, PersistentSubsectionGradeOverride @@ -54,12 +56,12 @@ upload_course_survey_report, upload_ora2_data, upload_ora2_submission_files, - upload_ora2_summary + upload_ora2_summary, ) from lms.djangoapps.instructor_task.tests.test_base import ( InstructorTaskCourseTestCase, InstructorTaskModuleTestCase, - TestReportMixin + TestReportMixin, ) from lms.djangoapps.survey.models import SurveyAnswer, SurveyForm from lms.djangoapps.teams.tests.factories import CourseTeamFactory, CourseTeamMembershipFactory @@ -69,16 +71,23 @@ 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 openedx.core.djangolib.testing.utils import AUTHZ_TABLES from openedx.core.lib.teams_config import TeamsConfig -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, + check_mongo_calls, +) from xmodule.partitions.partitions import Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order + # noinspection PyUnresolvedReferences from xmodule.tests.helpers import override_descriptor_system # pylint: disable=unused-import from ..models import ReportStore from ..tasks_helper.utils import UPDATE_STATUS_FAILED, UPDATE_STATUS_SUCCEEDED -from common.test.utils import assert_dict_contains_subset _TEAMS_CONFIG = TeamsConfig({ 'max_size': 2, diff --git a/lms/djangoapps/instructor_task/tests/test_views.py b/lms/djangoapps/instructor_task/tests/test_views.py index e568b2f062ef..423280c47e04 100644 --- a/lms/djangoapps/instructor_task/tests/test_views.py +++ b/lms/djangoapps/instructor_task/tests/test_views.py @@ -13,7 +13,7 @@ from lms.djangoapps.instructor_task.tests.test_base import ( TEST_FAILURE_EXCEPTION, TEST_FAILURE_MESSAGE, - InstructorTaskTestCase + InstructorTaskTestCase, ) from lms.djangoapps.instructor_task.views import get_task_completion_info, instructor_task_status diff --git a/lms/djangoapps/learner_dashboard/program_views.py b/lms/djangoapps/learner_dashboard/program_views.py index edceace20c50..baeb3ad14321 100644 --- a/lms/djangoapps/learner_dashboard/program_views.py +++ b/lms/djangoapps/learner_dashboard/program_views.py @@ -7,13 +7,15 @@ from rest_framework.authentication import SessionAuthentication from rest_framework.response import Response from rest_framework.views import APIView -from lms.djangoapps.learner_dashboard.utils import masters_program_tab_view_is_enabled, is_enrolled_or_staff + from common.djangoapps.edxmako.shortcuts import render_to_response from lms.djangoapps.learner_dashboard.programs import ( ProgramDetailsFragmentView, ProgramDiscussionLTI, - ProgramsFragmentView, ProgramLiveLTI + ProgramLiveLTI, + ProgramsFragmentView, ) +from lms.djangoapps.learner_dashboard.utils import is_enrolled_or_staff, masters_program_tab_view_is_enabled from lms.djangoapps.program_enrollments.rest_api.v1.utils import ProgramSpecificViewMixin from openedx.core.djangoapps.programs.models import ProgramsApiConfig from openedx.core.lib.api.authentication import BearerAuthentication diff --git a/lms/djangoapps/learner_dashboard/programs.py b/lms/djangoapps/learner_dashboard/programs.py index dc334c0ce34e..c9350a47fc6e 100644 --- a/lms/djangoapps/learner_dashboard/programs.py +++ b/lms/djangoapps/learner_dashboard/programs.py @@ -9,9 +9,8 @@ from django.contrib.sites.shortcuts import get_current_site from django.http import Http404 from django.template.loader import render_to_string -from django.utils.translation import get_language +from django.utils.translation import get_language, to_locale from django.utils.translation import gettext_lazy as _ # lint-amnesty, pylint: disable=unused-import -from django.utils.translation import to_locale from lti_consumer.lti_1p1.contrib.django import lti_embed from web_fragments.fragment import Fragment @@ -23,7 +22,7 @@ from openedx.core.djangoapps.programs.models import ( ProgramDiscussionsConfiguration, ProgramLiveConfiguration, - ProgramsApiConfig + ProgramsApiConfig, ) from openedx.core.djangoapps.programs.utils import ( ProgramProgressMeter, diff --git a/lms/djangoapps/learner_dashboard/tests/test_programs.py b/lms/djangoapps/learner_dashboard/tests/test_programs.py index 0662d09a41ea..8755ad154018 100644 --- a/lms/djangoapps/learner_dashboard/tests/test_programs.py +++ b/lms/djangoapps/learner_dashboard/tests/test_programs.py @@ -14,10 +14,8 @@ from django.test import override_settings from django.urls import reverse, reverse_lazy from edx_toggles.toggles.testutils import override_waffle_flag - from lti_consumer.models import LtiConfiguration -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory as ModuleStoreCourseFactory + from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from lms.djangoapps.learner_dashboard.config.waffle import ENABLE_PROGRAM_TAB_VIEW from lms.djangoapps.program_enrollments.rest_api.v1.tests.test_views import ProgramCacheMixin @@ -27,12 +25,14 @@ CourseFactory, CourseRunFactory, PathwayFactory, - ProgramFactory + ProgramFactory, ) from openedx.core.djangoapps.catalog.tests.mixins import CatalogIntegrationMixin from openedx.core.djangoapps.programs.models import ProgramDiscussionsConfiguration from openedx.core.djangoapps.programs.tests.mixins import ProgramsApiConfigMixin from openedx.core.djangolib.testing.utils import skip_unless_lms +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' PROGRAMS_MODULE = 'lms.djangoapps.learner_dashboard.programs' diff --git a/lms/djangoapps/learner_dashboard/tests/test_views.py b/lms/djangoapps/learner_dashboard/tests/test_views.py index 03f7da1d8c6d..733a7bb06942 100644 --- a/lms/djangoapps/learner_dashboard/tests/test_views.py +++ b/lms/djangoapps/learner_dashboard/tests/test_views.py @@ -3,21 +3,21 @@ """ from uuid import uuid4 -import ddt +import ddt from django.urls import reverse_lazy from edx_toggles.toggles.testutils import override_waffle_flag from lti_consumer.models import LtiConfiguration from markupsafe import Markup -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory as ModuleStoreCourseFactory from common.djangoapps.student.tests.factories import UserFactory -from lms.djangoapps.learner_dashboard.config.waffle import ENABLE_PROGRAM_TAB_VIEW, ENABLE_MASTERS_PROGRAM_TAB_VIEW +from lms.djangoapps.learner_dashboard.config.waffle import ENABLE_MASTERS_PROGRAM_TAB_VIEW, ENABLE_PROGRAM_TAB_VIEW from lms.djangoapps.program_enrollments.rest_api.v1.tests.test_views import ProgramCacheMixin from lms.djangoapps.program_enrollments.tests.factories import ProgramEnrollmentFactory from openedx.core.djangoapps.catalog.tests.factories import CourseFactory, CourseRunFactory, ProgramFactory from openedx.core.djangoapps.programs.models import ProgramDiscussionsConfiguration +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory as ModuleStoreCourseFactory @ddt.ddt diff --git a/lms/djangoapps/learner_dashboard/urls.py b/lms/djangoapps/learner_dashboard/urls.py index bb098cdd35d3..481a814c10c5 100644 --- a/lms/djangoapps/learner_dashboard/urls.py +++ b/lms/djangoapps/learner_dashboard/urls.py @@ -2,7 +2,7 @@ from django.urls import path, re_path -from lms.djangoapps.learner_dashboard import programs, program_views +from lms.djangoapps.learner_dashboard import program_views, programs urlpatterns = [ path('programs/', program_views.program_listing, name='program_listing_view'), diff --git a/lms/djangoapps/learner_dashboard/utils.py b/lms/djangoapps/learner_dashboard/utils.py index 5e9c172fcb78..6f00c1f05710 100644 --- a/lms/djangoapps/learner_dashboard/utils.py +++ b/lms/djangoapps/learner_dashboard/utils.py @@ -6,10 +6,7 @@ from opaque_keys.edx.keys import CourseKey from common.djangoapps.student.roles import GlobalStaff -from lms.djangoapps.learner_dashboard.config.waffle import ( - ENABLE_MASTERS_PROGRAM_TAB_VIEW, - ENABLE_PROGRAM_TAB_VIEW -) +from lms.djangoapps.learner_dashboard.config.waffle import ENABLE_MASTERS_PROGRAM_TAB_VIEW, ENABLE_PROGRAM_TAB_VIEW from lms.djangoapps.program_enrollments.api import get_program_enrollment FAKE_COURSE_KEY = CourseKey.from_string('course-v1:fake+course+run') diff --git a/lms/djangoapps/learner_home/mock/mock_views.py b/lms/djangoapps/learner_home/mock/mock_views.py index 266524115d34..2607aad77a9a 100644 --- a/lms/djangoapps/learner_home/mock/mock_views.py +++ b/lms/djangoapps/learner_home/mock/mock_views.py @@ -7,8 +7,8 @@ import json from os import path -from rest_framework.response import Response from rest_framework.generics import RetrieveAPIView +from rest_framework.response import Response LEARNER_HOME_DIR = "/edx/app/edxapp/edx-platform/lms/djangoapps/learner_home/mock" MOCK_DATA_FILE = "mock_data.json" diff --git a/lms/djangoapps/learner_home/serializers.py b/lms/djangoapps/learner_home/serializers.py index f7eed25d22e9..d1b6b134c63b 100644 --- a/lms/djangoapps/learner_home/serializers.py +++ b/lms/djangoapps/learner_home/serializers.py @@ -9,13 +9,13 @@ from django.urls import reverse from django.utils import timezone from opaque_keys.edx.keys import CourseKey -from rest_framework import serializers from openedx_filters.learning.filters import CourseEnrollmentAPIRenderStarted, CourseRunAPIRenderStarted +from rest_framework import serializers from common.djangoapps.course_modes.models import CourseMode +from lms.djangoapps.learner_home.utils import course_progress_url from openedx.features.course_experience import course_home_url from xmodule.data import CertificatesDisplayBehaviors -from lms.djangoapps.learner_home.utils import course_progress_url class LiteralField(serializers.Field): diff --git a/lms/djangoapps/learner_home/test_serializers.py b/lms/djangoapps/learner_home/test_serializers.py index 7b8268b42c76..ec5ac213b46a 100644 --- a/lms/djangoapps/learner_home/test_serializers.py +++ b/lms/djangoapps/learner_home/test_serializers.py @@ -10,48 +10,36 @@ import ddt from django.conf import settings -from django.urls import reverse from django.test import TestCase +from django.urls import reverse from opaque_keys.edx.keys import CourseKey - from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory from common.djangoapps.entitlements.tests.factories import CourseEntitlementFactory -from common.djangoapps.student.tests.factories import ( - CourseEnrollmentFactory, - UserFactory, -) -from openedx.core.djangoapps.catalog.tests.factories import ( - CourseRunFactory as CatalogCourseRunFactory, - ProgramFactory, -) -from openedx.core.djangoapps.content.course_overviews.tests.factories import ( - CourseOverviewFactory, -) +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from lms.djangoapps.learner_home.serializers import ( CertificateSerializer, CourseProviderSerializer, CourseRunSerializer, CourseSerializer, + CoursewareAccessSerializer, CreditSerializer, EmailConfirmationSerializer, EnrollmentSerializer, EnterpriseDashboardSerializer, EntitlementSerializer, GradeDataSerializer, - CoursewareAccessSerializer, + LearnerDashboardSerializer, LearnerEnrollmentSerializer, PlatformSettingsSerializer, ProgramsSerializer, - LearnerDashboardSerializer, RelatedProgramSerializer, SocialMediaSiteSettingsSerializer, SocialShareSettingsSerializer, SuggestedCourseSerializer, UnfulfilledEntitlementSerializer, ) -from lms.djangoapps.learner_home.utils import course_progress_url from lms.djangoapps.learner_home.test_utils import ( datetime_to_django_format, random_bool, @@ -59,6 +47,10 @@ random_string, random_url, ) +from lms.djangoapps.learner_home.utils import course_progress_url +from openedx.core.djangoapps.catalog.tests.factories import CourseRunFactory as CatalogCourseRunFactory +from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory +from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from xmodule.data import CertificatesDisplayBehaviors from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/lms/djangoapps/learner_home/test_utils.py b/lms/djangoapps/learner_home/test_utils.py index 3533dec22042..9039597b52ed 100644 --- a/lms/djangoapps/learner_home/test_utils.py +++ b/lms/djangoapps/learner_home/test_utils.py @@ -10,9 +10,7 @@ from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory from common.djangoapps.student.tests.factories import CourseEnrollmentFactory -from openedx.core.djangoapps.content.course_overviews.tests.factories import ( - CourseOverviewFactory, -) +from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from xmodule.modulestore.tests.factories import CourseFactory diff --git a/lms/djangoapps/learner_home/test_views.py b/lms/djangoapps/learner_home/test_views.py index 8722629371cc..8057abcd2a01 100644 --- a/lms/djangoapps/learner_home/test_views.py +++ b/lms/djangoapps/learner_home/test_views.py @@ -2,62 +2,47 @@ Test for Learner Home views and related functions """ -from contextlib import contextmanager import json +from contextlib import contextmanager from unittest.mock import Mock, patch from urllib.parse import urlencode from uuid import uuid4 import ddt from django.conf import settings +from django.test import TestCase, override_settings from django.urls import reverse from django.utils import timezone -from django.test import TestCase, override_settings from opaque_keys.edx.keys import CourseKey from rest_framework.test import APITestCase from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.entitlements.tests.factories import CourseEntitlementFactory -from common.djangoapps.student.tests.factories import ( - CourseEnrollmentFactory, - UserFactory, -) +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from common.djangoapps.util.course import get_encoded_course_sharing_utm_params from lms.djangoapps.bulk_email.models import Optout -from lms.djangoapps.learner_home.test_utils import ( - create_test_enrollment, - random_string, - random_url, -) +from lms.djangoapps.learner_home.test_utils import create_test_enrollment, random_string, random_url from lms.djangoapps.learner_home.views import ( get_course_overviews_for_pseudo_sessions, get_course_programs, + get_course_share_urls, get_email_settings_info, get_enrollments, get_enterprise_customer, + get_entitlements, get_platform_settings, + get_social_share_settings, get_suggested_courses, get_user_account_confirmation_info, - get_entitlements, - get_social_share_settings, - get_course_share_urls, -) -from openedx.core.djangoapps.catalog.tests.factories import ( - CourseFactory as CatalogCourseFactory, - CourseRunFactory as CatalogCourseRunFactory, - ProgramFactory, -) -from openedx.core.djangoapps.content.course_overviews.tests.factories import ( - CourseOverviewFactory, ) +from openedx.core.djangoapps.catalog.tests.factories import CourseFactory as CatalogCourseFactory +from openedx.core.djangoapps.catalog.tests.factories import CourseRunFactory as CatalogCourseRunFactory +from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory +from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory -from xmodule.modulestore.tests.django_utils import ( - TEST_DATA_SPLIT_MODULESTORE, - SharedModuleStoreTestCase, -) +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory - ENTERPRISE_ENABLED = "ENABLE_ENTERPRISE_INTEGRATION" diff --git a/lms/djangoapps/learner_home/test_waffle.py b/lms/djangoapps/learner_home/test_waffle.py index 9d3f19f29aa0..2beab790aebc 100644 --- a/lms/djangoapps/learner_home/test_waffle.py +++ b/lms/djangoapps/learner_home/test_waffle.py @@ -3,6 +3,7 @@ """ from unittest.mock import patch + import ddt from common.djangoapps.student.tests.factories import UserFactory diff --git a/lms/djangoapps/learner_home/urls.py b/lms/djangoapps/learner_home/urls.py index c56ccb5971f3..85e4b76db74d 100644 --- a/lms/djangoapps/learner_home/urls.py +++ b/lms/djangoapps/learner_home/urls.py @@ -2,12 +2,11 @@ Learner Home URL routing configuration """ -from django.urls import path -from django.urls import include, re_path +from django.urls import include, path, re_path from lms.djangoapps.learner_home import views -from .rest_api import urls as rest_api_urls +from .rest_api import urls as rest_api_urls app_name = "learner_home" diff --git a/lms/djangoapps/learner_home/utils.py b/lms/djangoapps/learner_home/utils.py index 96af6a64452b..ad873e1dce91 100644 --- a/lms/djangoapps/learner_home/utils.py +++ b/lms/djangoapps/learner_home/utils.py @@ -4,14 +4,12 @@ import logging -from django.urls import reverse from django.contrib.auth import get_user_model from django.core.exceptions import MultipleObjectsReturned -from rest_framework.exceptions import PermissionDenied, NotFound +from django.urls import reverse +from rest_framework.exceptions import NotFound, PermissionDenied -from common.djangoapps.student.models import ( - get_user_by_username_or_email, -) +from common.djangoapps.student.models import get_user_by_username_or_email from lms.djangoapps.course_home_api.toggles import course_home_mfe_progress_tab_is_active from openedx.features.course_experience.url_helpers import get_learning_mfe_home_url diff --git a/lms/djangoapps/learner_home/views.py b/lms/djangoapps/learner_home/views.py index 40962721b339..19151bef46d5 100644 --- a/lms/djangoapps/learner_home/views.py +++ b/lms/djangoapps/learner_home/views.py @@ -12,9 +12,7 @@ from edx_django_utils import monitoring as monitoring_utils from edx_django_utils.monitoring import function_trace from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication -from edx_rest_framework_extensions.auth.session.authentication import ( - SessionAuthenticationAllowInactiveUser, -) +from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser from edx_rest_framework_extensions.permissions import NotJwtRestrictedApplication from opaque_keys.edx.keys import CourseKey from rest_framework.permissions import IsAuthenticated @@ -23,10 +21,7 @@ from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.edxmako.shortcuts import marketing_link -from common.djangoapps.student.helpers import ( - cert_info, - user_has_passing_grade_in_course, -) +from common.djangoapps.student.helpers import cert_info, user_has_passing_grade_in_course from common.djangoapps.student.views.dashboard import ( complete_course_mode_info, credit_statuses, @@ -34,32 +29,21 @@ get_filtered_course_entitlements, get_org_black_and_whitelist_for_site, ) -from common.djangoapps.util.course import ( - get_encoded_course_sharing_utm_params, - get_link_for_about_page, -) -from common.djangoapps.util.milestones_helpers import ( - get_pre_requisite_courses_not_completed, -) +from common.djangoapps.util.course import get_encoded_course_sharing_utm_params, get_link_for_about_page +from common.djangoapps.util.milestones_helpers import get_pre_requisite_courses_not_completed from lms.djangoapps.branding import toggles from lms.djangoapps.bulk_email.models import Optout from lms.djangoapps.bulk_email.models_api import is_bulk_email_feature_enabled from lms.djangoapps.commerce.utils import EcommerceService from lms.djangoapps.courseware.access import administrative_accesses_to_course_for_user from lms.djangoapps.courseware.access_utils import check_course_open_for_learner -from lms.djangoapps.learner_home.serializers import ( - LearnerDashboardSerializer, -) -from lms.djangoapps.learner_home.utils import ( - get_masquerade_user, -) +from lms.djangoapps.learner_home.serializers import LearnerDashboardSerializer +from lms.djangoapps.learner_home.utils import get_masquerade_user from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.programs.utils import ProgramProgressMeter from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser -from openedx.features.course_duration_limits.access import ( - get_user_course_expiration_date, -) +from openedx.features.course_duration_limits.access import get_user_course_expiration_date from openedx.features.enterprise_support.api import ( enterprise_customer_from_session_or_learner_data, get_enterprise_learner_data_from_db, diff --git a/lms/djangoapps/lms_xblock/mixin.py b/lms/djangoapps/lms_xblock/mixin.py index dbaaa5b1fa5a..239bbe9e429b 100644 --- a/lms/djangoapps/lms_xblock/mixin.py +++ b/lms/djangoapps/lms_xblock/mixin.py @@ -13,7 +13,10 @@ from lms.lib.utils import is_unit from xmodule.modulestore.inheritance import UserPartitionList # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions import NoSuchUserPartitionError, NoSuchUserPartitionGroupError # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.partitions.partitions import ( # lint-amnesty, pylint: disable=wrong-import-order + NoSuchUserPartitionError, + NoSuchUserPartitionGroupError, +) # Please do not remove, this is a workaround for Django 1.8. # more information can be found here: https://openedx.atlassian.net/browse/PLAT-902 diff --git a/lms/djangoapps/lms_xblock/test/test_runtime.py b/lms/djangoapps/lms_xblock/test/test_runtime.py index 5d29b37ba60a..af9a043ce9fa 100644 --- a/lms/djangoapps/lms_xblock/test/test_runtime.py +++ b/lms/djangoapps/lms_xblock/test/test_runtime.py @@ -11,8 +11,8 @@ from opaque_keys.edx.locations import BlockUsageLocator, CourseLocator from xblock.fields import ScopeIds -from xmodule.x_module import ModuleStoreRuntime from lms.djangoapps.lms_xblock.runtime import handler_url +from xmodule.x_module import ModuleStoreRuntime class BlockMock(Mock): 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 10e2d0328625..b558d76e17ba 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 @@ -7,13 +7,13 @@ from django.test import TestCase from opaque_keys.edx.keys import CourseKey, UsageKey -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase -from xmodule.modulestore.tests.utils import TEST_DATA_DIR -from xmodule.modulestore.xml_importer import import_course_from_xml from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.lti_provider.management.commands import resend_lti_scores from lms.djangoapps.lti_provider.models import GradedAssignment, LtiConsumer, OutcomeService +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.utils import TEST_DATA_DIR +from xmodule.modulestore.xml_importer import import_course_from_xml class CommandArgsTestCase(TestCase): diff --git a/lms/djangoapps/lti_provider/migrations/0001_initial.py b/lms/djangoapps/lti_provider/migrations/0001_initial.py index a61437e155d4..3650a1ae98ab 100644 --- a/lms/djangoapps/lti_provider/migrations/0001_initial.py +++ b/lms/djangoapps/lti_provider/migrations/0001_initial.py @@ -1,9 +1,9 @@ -from openedx.core.lib.hash_utils import create_hash256, short_token - from django.conf import settings from django.db import migrations, models from opaque_keys.edx.django.models import CourseKeyField, UsageKeyField +from openedx.core.lib.hash_utils import create_hash256, short_token + class Migration(migrations.Migration): diff --git a/lms/djangoapps/lti_provider/migrations/0002_auto_20160325_0407.py b/lms/djangoapps/lti_provider/migrations/0002_auto_20160325_0407.py index ab55f138937b..1f46ce1d6e85 100644 --- a/lms/djangoapps/lti_provider/migrations/0002_auto_20160325_0407.py +++ b/lms/djangoapps/lti_provider/migrations/0002_auto_20160325_0407.py @@ -1,6 +1,7 @@ -from openedx.core.lib.hash_utils import short_token from django.db import migrations, models +from openedx.core.lib.hash_utils import short_token + class Migration(migrations.Migration): diff --git a/lms/djangoapps/lti_provider/migrations/0004_require_user_account.py b/lms/djangoapps/lti_provider/migrations/0004_require_user_account.py index e6238e312da0..aa4d12f141cf 100644 --- a/lms/djangoapps/lti_provider/migrations/0004_require_user_account.py +++ b/lms/djangoapps/lti_provider/migrations/0004_require_user_account.py @@ -1,8 +1,8 @@ # Generated by Django 3.2.22 on 2023-11-06 09:47 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/lms/djangoapps/lti_provider/tests/test_outcomes.py b/lms/djangoapps/lti_provider/tests/test_outcomes.py index 36840689a5f7..869c0128d6a8 100644 --- a/lms/djangoapps/lti_provider/tests/test_outcomes.py +++ b/lms/djangoapps/lti_provider/tests/test_outcomes.py @@ -8,12 +8,12 @@ from django.test import TestCase from lxml import etree from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory import lms.djangoapps.lti_provider.outcomes as outcomes from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.lti_provider.models import GradedAssignment, LtiConsumer, OutcomeService +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory class StoreOutcomeParametersTest(TestCase): diff --git a/lms/djangoapps/lti_provider/tests/test_views.py b/lms/djangoapps/lti_provider/tests/test_views.py index 4bcae9c73207..2332ddc46374 100644 --- a/lms/djangoapps/lti_provider/tests/test_views.py +++ b/lms/djangoapps/lti_provider/tests/test_views.py @@ -9,12 +9,14 @@ from django.test.utils import override_settings from django.urls import reverse from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator -from openedx_events.learning.data import UserData, UserPersonalData, LtiProviderLaunchData, LtiProviderLaunchParamsData +from openedx_events.learning.data import LtiProviderLaunchData, LtiProviderLaunchParamsData, UserData, UserPersonalData from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.courseware.testutils import RenderXBlockTestMixin from lms.djangoapps.lti_provider import models, views -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) LTI_DEFAULT_PARAMS = { 'roles': 'Instructor,urn:lti:instrole:ims/lis/Administrator', diff --git a/lms/djangoapps/lti_provider/users.py b/lms/djangoapps/lti_provider/users.py index b2df1ac02563..fe6bd1bf6099 100644 --- a/lms/djangoapps/lti_provider/users.py +++ b/lms/djangoapps/lti_provider/users.py @@ -4,7 +4,6 @@ """ import logging - import random import string import uuid diff --git a/lms/djangoapps/lti_provider/views.py b/lms/djangoapps/lti_provider/views.py index 4f6f2f9a93d7..69f81fb5613b 100644 --- a/lms/djangoapps/lti_provider/views.py +++ b/lms/djangoapps/lti_provider/views.py @@ -9,12 +9,12 @@ from django.core.exceptions import PermissionDenied from django.http import Http404, HttpResponseBadRequest, HttpResponseForbidden from django.views.decorators.csrf import csrf_exempt -from common.djangoapps.edxmako.shortcuts import render_to_response from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey, UsageKey from openedx_events.learning.data import LtiProviderLaunchData, LtiProviderLaunchParamsData, UserData, UserPersonalData from openedx_events.learning.signals import LTI_PROVIDER_LAUNCH_SUCCESS +from common.djangoapps.edxmako.shortcuts import render_to_response from common.djangoapps.util.views import add_p3p_header from lms.djangoapps.lti_provider.models import LtiConsumer from lms.djangoapps.lti_provider.outcomes import store_outcome_parameters diff --git a/lms/djangoapps/mfe_config_api/tests/test_views.py b/lms/djangoapps/mfe_config_api/tests/test_views.py index 0dfc63e82790..2cdc21143348 100644 --- a/lms/djangoapps/mfe_config_api/tests/test_views.py +++ b/lms/djangoapps/mfe_config_api/tests/test_views.py @@ -5,8 +5,8 @@ from unittest.mock import call, patch import ddt -from django.core.cache import cache from django.conf import settings +from django.core.cache import cache from django.test import override_settings from django.urls import reverse from rest_framework import status diff --git a/lms/djangoapps/mobile_api/course_info/urls.py b/lms/djangoapps/mobile_api/course_info/urls.py index 6b7445d9c75c..c8bb0259b97c 100644 --- a/lms/djangoapps/mobile_api/course_info/urls.py +++ b/lms/djangoapps/mobile_api/course_info/urls.py @@ -11,7 +11,7 @@ CourseEnrollmentDetailsView, CourseGoalsRecordUserActivity, CourseHandoutsList, - CourseUpdatesList + CourseUpdatesList, ) urlpatterns = [ diff --git a/lms/djangoapps/mobile_api/course_info/views.py b/lms/djangoapps/mobile_api/course_info/views.py index fc818c646825..93984babd011 100644 --- a/lms/djangoapps/mobile_api/course_info/views.py +++ b/lms/djangoapps/mobile_api/course_info/views.py @@ -25,7 +25,7 @@ CourseAccessSerializer, CourseDetailSerializer, CourseInfoOverviewSerializer, - MobileCourseEnrollmentSerializer + MobileCourseEnrollmentSerializer, ) from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.video_pipeline.config.waffle import DEPRECATE_YOUTUBE diff --git a/lms/djangoapps/mobile_api/migrations/0004_mobileconfig.py b/lms/djangoapps/mobile_api/migrations/0004_mobileconfig.py index f554a6716f46..f7ecc6ba28df 100644 --- a/lms/djangoapps/mobile_api/migrations/0004_mobileconfig.py +++ b/lms/djangoapps/mobile_api/migrations/0004_mobileconfig.py @@ -1,8 +1,8 @@ # Generated by Django 3.2.15 on 2022-09-23 14:17 -from django.db import migrations, models import django.utils.timezone import model_utils.fields +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/mobile_api/notifications/urls.py b/lms/djangoapps/mobile_api/notifications/urls.py index 120fa39a975a..ac6a4b008f58 100644 --- a/lms/djangoapps/mobile_api/notifications/urls.py +++ b/lms/djangoapps/mobile_api/notifications/urls.py @@ -2,8 +2,8 @@ URLs for the mobile_api.notifications APIs. """ from django.urls import path -from .views import GCMDeviceViewSet +from .views import GCMDeviceViewSet create_gcm_device_post_view = GCMDeviceViewSet.as_view({'post': 'create'}) diff --git a/lms/djangoapps/mobile_api/notifications/views.py b/lms/djangoapps/mobile_api/notifications/views.py index 2621c2a3a2fb..6bb14197f347 100644 --- a/lms/djangoapps/mobile_api/notifications/views.py +++ b/lms/djangoapps/mobile_api/notifications/views.py @@ -2,11 +2,10 @@ This module contains the view for registering a device for push notifications. """ from django.conf import settings +from edx_ace.push_notifications.views import GCMDeviceViewSet as GCMDeviceViewSetBase from rest_framework import status from rest_framework.response import Response -from edx_ace.push_notifications.views import GCMDeviceViewSet as GCMDeviceViewSetBase - from ..decorators import mobile_view diff --git a/lms/djangoapps/mobile_api/tests/test_course_info_views.py b/lms/djangoapps/mobile_api/tests/test_course_info_views.py index efb3f7d9fdbb..91edc665805c 100644 --- a/lms/djangoapps/mobile_api/tests/test_course_info_views.py +++ b/lms/djangoapps/mobile_api/tests/test_course_info_views.py @@ -20,14 +20,15 @@ from lms.djangoapps.course_api.blocks.tests.test_views import TestBlocksInCourseView from lms.djangoapps.mobile_api.course_info.views import BlocksInfoInCourseView from lms.djangoapps.mobile_api.testutils import MobileAPITestCase, MobileAuthTestMixin, MobileCourseAccessTestMixin -from lms.djangoapps.mobile_api.utils import API_V1, API_V05 +from lms.djangoapps.mobile_api.utils import API_V05, API_V1 from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.features.course_experience import ENABLE_COURSE_GOALS from xmodule.html_block import CourseInfoBlock # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import \ - SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.xml_importer import import_course_from_xml # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/mobile_api/tests/test_milestones.py b/lms/djangoapps/mobile_api/tests/test_milestones.py index 2ecd7a0e3870..24294c8abefa 100644 --- a/lms/djangoapps/mobile_api/tests/test_milestones.py +++ b/lms/djangoapps/mobile_api/tests/test_milestones.py @@ -13,7 +13,10 @@ from lms.djangoapps.courseware.access_response import MilestoneAccessError from lms.djangoapps.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 xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) class MobileAPIMilestonesMixin: diff --git a/lms/djangoapps/mobile_api/testutils.py b/lms/djangoapps/mobile_api/testutils.py index f74d4b45a5fd..ab4a029a0fa5 100644 --- a/lms/djangoapps/mobile_api/testutils.py +++ b/lms/djangoapps/mobile_api/testutils.py @@ -22,8 +22,6 @@ from django.utils import timezone from opaque_keys.edx.keys import CourseKey from rest_framework.test import APITestCase -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student import auth from common.djangoapps.student.models import CourseEnrollment @@ -32,6 +30,8 @@ from lms.djangoapps.mobile_api.models import IgnoreMobileAvailableFlagConfig from lms.djangoapps.mobile_api.tests.test_milestones import MobileAPIMilestonesMixin from lms.djangoapps.mobile_api.utils import API_V1 +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/users/serializers.py b/lms/djangoapps/mobile_api/users/serializers.py index 95db34f5ed06..a7ae2707de53 100644 --- a/lms/djangoapps/mobile_api/users/serializers.py +++ b/lms/djangoapps/mobile_api/users/serializers.py @@ -14,9 +14,9 @@ from common.djangoapps.student.models import CourseEnrollment, User from common.djangoapps.util.course import get_encoded_course_sharing_utm_params, get_link_for_about_page from lms.djangoapps.certificates.api import certificate_downloadable_status +from lms.djangoapps.course_home_api.dates.serializers import DateSummarySerializer from lms.djangoapps.courseware.access import has_access from lms.djangoapps.courseware.courses import get_assignments_completions, get_past_and_future_course_assignments -from lms.djangoapps.course_home_api.dates.serializers import DateSummarySerializer from lms.djangoapps.mobile_api.utils import API_V4, get_course_organization_logo from openedx.features.course_duration_limits.access import get_user_course_expiration_date from xmodule.modulestore.django import modulestore diff --git a/lms/djangoapps/mobile_api/users/tests.py b/lms/djangoapps/mobile_api/users/tests.py index 7c4b3e437de5..ae4f7d3c5483 100644 --- a/lms/djangoapps/mobile_api/users/tests.py +++ b/lms/djangoapps/mobile_api/users/tests.py @@ -35,16 +35,19 @@ MobileAPITestCase, MobileAuthTestMixin, MobileAuthUserTestMixin, - MobileCourseAccessTestMixin + MobileCourseAccessTestMixin, ) from lms.djangoapps.mobile_api.users.enums import EnrollmentStatuses -from lms.djangoapps.mobile_api.utils import API_V1, API_V05, API_V2, API_V3, API_V4 -from openedx.core.lib.courses import course_image_url +from lms.djangoapps.mobile_api.utils import API_V05, API_V1, API_V2, API_V3, API_V4 from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration +from openedx.core.lib.courses import course_image_url from openedx.features.course_duration_limits.models import CourseDurationLimitConfig from openedx.features.course_experience.tests.views.helpers import add_course_mode from xmodule.course_block import DEFAULT_START_DATE # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) from .. import errors from .serializers import CourseEnrollmentSerializer, CourseEnrollmentSerializerv05 diff --git a/lms/djangoapps/mobile_api/users/views.py b/lms/djangoapps/mobile_api/users/views.py index 324db83a374c..8956474d46b4 100644 --- a/lms/djangoapps/mobile_api/users/views.py +++ b/lms/djangoapps/mobile_api/users/views.py @@ -18,6 +18,7 @@ from django.shortcuts import get_object_or_404, redirect from django.utils import dateparse from django.utils.decorators import method_decorator +from edx_rest_framework_extensions.paginators import DefaultPagination from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import UsageKey from opaque_keys.edx.locator import CourseLocator @@ -27,19 +28,18 @@ from rest_framework.response import Response from xblock.fields import Scope from xblock.runtime import KeyValueStore -from edx_rest_framework_extensions.paginators import DefaultPagination from common.djangoapps.student.models import CourseEnrollment, User # lint-amnesty, pylint: disable=reimported from lms.djangoapps.courseware.access import is_mobile_available_for_user from lms.djangoapps.courseware.access_utils import ACCESS_GRANTED +from lms.djangoapps.courseware.block_render import get_block_for_descriptor from lms.djangoapps.courseware.context_processor import get_user_timezone_or_last_seen_timezone_or_utc from lms.djangoapps.courseware.courses import get_current_child from lms.djangoapps.courseware.model_data import FieldDataCache -from lms.djangoapps.courseware.block_render import get_block_for_descriptor from lms.djangoapps.courseware.models import StudentModule from lms.djangoapps.courseware.views.index import save_positions_recursively_up from lms.djangoapps.mobile_api.models import MobileConfig -from lms.djangoapps.mobile_api.utils import API_V1, API_V05, API_V2, API_V3, API_V4 +from lms.djangoapps.mobile_api.utils import API_V05, API_V1, API_V2, API_V3, API_V4 from openedx.core.djangoapps.site_configuration.helpers import get_current_site_orgs from openedx.features.course_duration_limits.access import check_course_expired from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/ora_staff_grader/mock/urls.py b/lms/djangoapps/ora_staff_grader/mock/urls.py index b27e704e676d..9701f5679ced 100644 --- a/lms/djangoapps/ora_staff_grader/mock/urls.py +++ b/lms/djangoapps/ora_staff_grader/mock/urls.py @@ -7,13 +7,12 @@ from lms.djangoapps.ora_staff_grader.mock.views import ( InitializeView, - SubmissionStatusFetchView, + SubmissionFetchView, SubmissionLockView, + SubmissionStatusFetchView, UpdateGradeView, - SubmissionFetchView, ) - urlpatterns = [] app_name = "mock-ora-staff-grader" diff --git a/lms/djangoapps/ora_staff_grader/mock/utils.py b/lms/djangoapps/ora_staff_grader/mock/utils.py index 43318becb0d5..6fd2c328c4bf 100644 --- a/lms/djangoapps/ora_staff_grader/mock/utils.py +++ b/lms/djangoapps/ora_staff_grader/mock/utils.py @@ -2,10 +2,8 @@ Mocking/testing utils for ESG """ import json - from os import path - DATA_ROOT = "/edx/app/edxapp/edx-platform/lms/djangoapps/ora_staff_grader/mock/data" diff --git a/lms/djangoapps/ora_staff_grader/mock/views.py b/lms/djangoapps/ora_staff_grader/mock/views.py index ca60f555e3bf..ef5b678a2782 100644 --- a/lms/djangoapps/ora_staff_grader/mock/views.py +++ b/lms/djangoapps/ora_staff_grader/mock/views.py @@ -2,17 +2,18 @@ Mock views for ESG """ +from rest_framework.generics import RetrieveAPIView + # pylint: disable=arguments-differ from rest_framework.response import Response -from rest_framework.generics import RetrieveAPIView from rest_framework.views import APIView from lms.djangoapps.ora_staff_grader.mock.utils import ( + fetch_response, + fetch_submission, get_course_metadata, get_ora_metadata, get_submissions, - fetch_submission, - fetch_response, save_submission_update, ) diff --git a/lms/djangoapps/ora_staff_grader/ora_api.py b/lms/djangoapps/ora_staff_grader/ora_api.py index cfaac2ef6608..d958cd15355b 100644 --- a/lms/djangoapps/ora_staff_grader/ora_api.py +++ b/lms/djangoapps/ora_staff_grader/ora_api.py @@ -16,11 +16,7 @@ from rest_framework.request import Request -from lms.djangoapps.ora_staff_grader.errors import ( - LockContestedError, - XBlockInternalError, -) - +from lms.djangoapps.ora_staff_grader.errors import LockContestedError, XBlockInternalError from lms.djangoapps.ora_staff_grader.utils import call_xblock_json_handler, is_json diff --git a/lms/djangoapps/ora_staff_grader/serializers.py b/lms/djangoapps/ora_staff_grader/serializers.py index 5ba77d5fef65..5f204a95d8e7 100644 --- a/lms/djangoapps/ora_staff_grader/serializers.py +++ b/lms/djangoapps/ora_staff_grader/serializers.py @@ -5,6 +5,7 @@ # pylint: disable=missing-function-docstring from urllib.parse import urljoin + from django.conf import settings from rest_framework import serializers diff --git a/lms/djangoapps/ora_staff_grader/tests/test_serializers.py b/lms/djangoapps/ora_staff_grader/tests/test_serializers.py index e03fd81dec6d..446841e23996 100644 --- a/lms/djangoapps/ora_staff_grader/tests/test_serializers.py +++ b/lms/djangoapps/ora_staff_grader/tests/test_serializers.py @@ -1,13 +1,12 @@ """ Tests for ESG Serializers """ -from unittest.mock import Mock, MagicMock, patch +from unittest.mock import MagicMock, Mock, patch from urllib.parse import urljoin import ddt from django.conf import settings from django.test import TestCase -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from lms.djangoapps.ora_staff_grader.errors import ERR_UNKNOWN, ErrorSerializer from lms.djangoapps.ora_staff_grader.serializers import ( @@ -16,8 +15,8 @@ FileListSerializer, GradeDataSerializer, InitializeSerializer, - LockStatusSerializer, LockStatusField, + LockStatusSerializer, OpenResponseMetadataSerializer, ResponseSerializer, RubricConfigSerializer, @@ -25,14 +24,13 @@ ScoreSerializer, StaffAssessSerializer, SubmissionFetchSerializer, - SubmissionStatusFetchSerializer, SubmissionMetadataSerializer, + SubmissionStatusFetchSerializer, UploadedFileSerializer, ) from lms.djangoapps.ora_staff_grader.tests import test_data -from openedx.core.djangoapps.content.course_overviews.tests.factories import ( - CourseOverviewFactory, -) +from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase class TestErrorSerializer(TestCase): diff --git a/lms/djangoapps/ora_staff_grader/tests/test_views.py b/lms/djangoapps/ora_staff_grader/tests/test_views.py index 2f27a8059077..f457e121eab6 100644 --- a/lms/djangoapps/ora_staff_grader/tests/test_views.py +++ b/lms/djangoapps/ora_staff_grader/tests/test_views.py @@ -9,13 +9,8 @@ from django.http import QueryDict from django.urls import reverse from rest_framework.test import APITestCase -from xmodule.modulestore.tests.django_utils import ( - TEST_DATA_SPLIT_MODULESTORE, - SharedModuleStoreTestCase, -) -from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.tests.factories import BlockFactory +import lms.djangoapps.ora_staff_grader.tests.test_data as test_data from common.djangoapps.student.tests.factories import StaffFactory from lms.djangoapps.ora_staff_grader.constants import ( ERR_BAD_ORA_LOCATION, @@ -27,14 +22,10 @@ PARAM_ORA_LOCATION, PARAM_SUBMISSION_ID, ) -from lms.djangoapps.ora_staff_grader.errors import ( - LockContestedError, - XBlockInternalError, -) -import lms.djangoapps.ora_staff_grader.tests.test_data as test_data -from openedx.core.djangoapps.content.course_overviews.tests.factories import ( - CourseOverviewFactory, -) +from lms.djangoapps.ora_staff_grader.errors import LockContestedError, XBlockInternalError +from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory class BaseViewTest(SharedModuleStoreTestCase, APITestCase): diff --git a/lms/djangoapps/ora_staff_grader/urls.py b/lms/djangoapps/ora_staff_grader/urls.py index 1acfcfa5dcf8..16309f851bcf 100644 --- a/lms/djangoapps/ora_staff_grader/urls.py +++ b/lms/djangoapps/ora_staff_grader/urls.py @@ -1,11 +1,11 @@ """ URLs for Enhanced Staff Grader (ESG) backend-for-frontend (BFF) """ -from django.urls import include -from django.urls import path +from django.urls import include, path from rest_framework.routers import DefaultRouter from lms.djangoapps.ora_staff_grader.views import ( + AssessmentFeedbackView, InitializeView, SubmissionBatchUnlockView, SubmissionFetchView, @@ -13,7 +13,6 @@ SubmissionLockView, SubmissionStatusFetchView, UpdateGradeView, - AssessmentFeedbackView, ) urlpatterns = [] diff --git a/lms/djangoapps/ora_staff_grader/utils.py b/lms/djangoapps/ora_staff_grader/utils.py index 7812a62a83a3..bc930e5207a9 100644 --- a/lms/djangoapps/ora_staff_grader/utils.py +++ b/lms/djangoapps/ora_staff_grader/utils.py @@ -1,8 +1,8 @@ """ Various helpful utilities for ESG """ -from functools import wraps import json +from functools import wraps from opaque_keys.edx.keys import UsageKey from rest_framework.request import clone_request diff --git a/lms/djangoapps/ora_staff_grader/views.py b/lms/djangoapps/ora_staff_grader/views.py index 50a1e0319608..7bcbfc16d87d 100644 --- a/lms/djangoapps/ora_staff_grader/views.py +++ b/lms/djangoapps/ora_staff_grader/views.py @@ -9,25 +9,18 @@ import logging from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication -from edx_rest_framework_extensions.auth.session.authentication import ( - SessionAuthenticationAllowInactiveUser, -) +from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import UsageKey -from openassessment.xblock.config_mixin import WAFFLE_NAMESPACE, ENHANCED_STAFF_GRADER +from openassessment.xblock.config_mixin import ENHANCED_STAFF_GRADER, WAFFLE_NAMESPACE from rest_framework.decorators import action from rest_framework.generics import RetrieveAPIView from rest_framework.permissions import IsAuthenticated from rest_framework.request import Request from rest_framework.response import Response from rest_framework.viewsets import ViewSet -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.exceptions import ItemNotFoundError -from lms.djangoapps.ora_staff_grader.constants import ( - PARAM_ORA_LOCATION, - PARAM_SUBMISSION_ID, -) +from lms.djangoapps.ora_staff_grader.constants import PARAM_ORA_LOCATION, PARAM_SUBMISSION_ID from lms.djangoapps.ora_staff_grader.errors import ( BadOraLocationResponse, GradeContestedResponse, @@ -44,26 +37,26 @@ claim_submission_lock, delete_submission_lock, get_assessment_info, + get_assessments, get_submission_info, get_submissions, - get_assessments, submit_grade, ) from lms.djangoapps.ora_staff_grader.serializers import ( + AssessmentFeedbackSerializer, FileListSerializer, InitializeSerializer, - AssessmentFeedbackSerializer, LockStatusSerializer, StaffAssessSerializer, SubmissionFetchSerializer, SubmissionStatusFetchSerializer, ) from lms.djangoapps.ora_staff_grader.utils import require_params -from openedx.core.djangoapps.content.course_overviews.api import ( - get_course_overview_or_none, -) +from openedx.core.djangoapps.content.course_overviews.api import get_course_overview_or_none from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.exceptions import ItemNotFoundError log = logging.getLogger(__name__) diff --git a/lms/djangoapps/program_enrollments/admin.py b/lms/djangoapps/program_enrollments/admin.py index 2470dc970f18..4e48432f5779 100644 --- a/lms/djangoapps/program_enrollments/admin.py +++ b/lms/djangoapps/program_enrollments/admin.py @@ -8,7 +8,7 @@ from lms.djangoapps.program_enrollments.models import ( CourseAccessRoleAssignment, ProgramCourseEnrollment, - ProgramEnrollment + ProgramEnrollment, ) diff --git a/lms/djangoapps/program_enrollments/api/__init__.py b/lms/djangoapps/program_enrollments/api/__init__.py index 0b19c18d40e8..afd77d397836 100644 --- a/lms/djangoapps/program_enrollments/api/__init__.py +++ b/lms/djangoapps/program_enrollments/api/__init__.py @@ -30,7 +30,7 @@ get_saml_providers_for_organization, get_users_by_external_keys, get_users_by_external_keys_and_org_key, - is_course_staff_enrollment + is_course_staff_enrollment, ) from .writing import ( change_program_course_enrollment_status, @@ -39,5 +39,5 @@ create_program_enrollment, enroll_in_masters_track, write_program_course_enrollments, - write_program_enrollments + write_program_enrollments, ) diff --git a/lms/djangoapps/program_enrollments/api/reading.py b/lms/djangoapps/program_enrollments/api/reading.py index b84b83845df4..a2c7b0c1ffd6 100644 --- a/lms/djangoapps/program_enrollments/api/reading.py +++ b/lms/djangoapps/program_enrollments/api/reading.py @@ -21,7 +21,7 @@ BadOrganizationShortNameException, ProgramDoesNotExistException, ProgramHasNoAuthoringOrganizationException, - ProviderDoesNotExistException + ProviderDoesNotExistException, ) from ..models import ProgramCourseEnrollment, ProgramEnrollment diff --git a/lms/djangoapps/program_enrollments/api/tests/test_linking.py b/lms/djangoapps/program_enrollments/api/tests/test_linking.py index 4939d7122c31..764820956b66 100644 --- a/lms/djangoapps/program_enrollments/api/tests/test_linking.py +++ b/lms/djangoapps/program_enrollments/api/tests/test_linking.py @@ -10,7 +10,6 @@ from edx_django_utils.cache import RequestCache from opaque_keys.edx.keys import CourseKey from testfixtures import LogCapture -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from common.djangoapps.student.api import get_course_access_role from common.djangoapps.student.roles import CourseStaffRole @@ -18,15 +17,16 @@ from lms.djangoapps.program_enrollments.tests.factories import ( CourseAccessRoleAssignmentFactory, ProgramCourseEnrollmentFactory, - ProgramEnrollmentFactory + ProgramEnrollmentFactory, ) from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from ..linking import ( NO_LMS_USER_TEMPLATE, NO_PROGRAM_ENROLLMENT_TEMPLATE, _user_already_linked_message, - link_program_enrollments + link_program_enrollments, ) LOG_PATH = 'lms.djangoapps.program_enrollments.api.linking' diff --git a/lms/djangoapps/program_enrollments/api/tests/test_reading.py b/lms/djangoapps/program_enrollments/api/tests/test_reading.py index d1fe0937b3fa..566a1567765d 100644 --- a/lms/djangoapps/program_enrollments/api/tests/test_reading.py +++ b/lms/djangoapps/program_enrollments/api/tests/test_reading.py @@ -23,13 +23,13 @@ from lms.djangoapps.program_enrollments.exceptions import ( OrganizationDoesNotExistException, ProgramDoesNotExistException, - ProviderDoesNotExistException + ProviderDoesNotExistException, ) from lms.djangoapps.program_enrollments.models import ProgramCourseEnrollment, ProgramEnrollment from lms.djangoapps.program_enrollments.tests.factories import ( CourseAccessRoleAssignmentFactory, ProgramCourseEnrollmentFactory, - ProgramEnrollmentFactory + ProgramEnrollmentFactory, ) from openedx.core.djangoapps.catalog.cache import PROGRAM_CACHE_KEY_TPL from openedx.core.djangoapps.catalog.tests.factories import OrganizationFactory as CatalogOrganizationFactory @@ -46,9 +46,9 @@ get_external_key_by_user_and_course, get_program_course_enrollment, get_program_enrollment, + get_provider_slug, get_users_by_external_keys, is_course_staff_enrollment, - get_provider_slug, ) User = get_user_model() diff --git a/lms/djangoapps/program_enrollments/api/tests/test_writing.py b/lms/djangoapps/program_enrollments/api/tests/test_writing.py index bd722a1bb2a3..9059d229944a 100644 --- a/lms/djangoapps/program_enrollments/api/tests/test_writing.py +++ b/lms/djangoapps/program_enrollments/api/tests/test_writing.py @@ -26,13 +26,12 @@ from lms.djangoapps.program_enrollments.models import ( CourseAccessRoleAssignment, ProgramCourseEnrollment, - ProgramEnrollment + ProgramEnrollment, ) from lms.djangoapps.program_enrollments.tests.factories import ProgramCourseEnrollmentFactory, ProgramEnrollmentFactory from openedx.core.djangoapps.catalog.cache import PROGRAM_CACHE_KEY_TPL -from openedx.core.djangoapps.catalog.tests.factories import CourseFactory, CourseRunFactory +from openedx.core.djangoapps.catalog.tests.factories import CourseFactory, CourseRunFactory, ProgramFactory from openedx.core.djangoapps.catalog.tests.factories import OrganizationFactory as CatalogOrganizationFactory -from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangolib.testing.utils import CacheIsolationTestCase diff --git a/lms/djangoapps/program_enrollments/api/writing.py b/lms/djangoapps/program_enrollments/api/writing.py index 837c319efedf..ea8865092190 100644 --- a/lms/djangoapps/program_enrollments/api/writing.py +++ b/lms/djangoapps/program_enrollments/api/writing.py @@ -16,9 +16,8 @@ from common.djangoapps.student.roles import CourseStaffRole from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from ..constants import ProgramCourseEnrollmentRoles, ProgramCourseEnrollmentStatuses +from ..constants import ProgramCourseEnrollmentRoles, ProgramCourseEnrollmentStatuses, ProgramEnrollmentStatuses from ..constants import ProgramCourseOperationStatuses as ProgramCourseOpStatuses -from ..constants import ProgramEnrollmentStatuses from ..constants import ProgramOperationStatuses as ProgramOpStatuses from ..exceptions import ProviderDoesNotExistException from ..models import CourseAccessRoleAssignment, ProgramCourseEnrollment, ProgramEnrollment diff --git a/lms/djangoapps/program_enrollments/apps.py b/lms/djangoapps/program_enrollments/apps.py index a32ce50ffd2e..232f40f45107 100644 --- a/lms/djangoapps/program_enrollments/apps.py +++ b/lms/djangoapps/program_enrollments/apps.py @@ -29,5 +29,7 @@ def ready(self): """ Connect handlers to signals. """ - from lms.djangoapps.program_enrollments import signals # pylint: disable=unused-import - from lms.djangoapps.program_enrollments import tasks # pylint: disable=unused-import + from lms.djangoapps.program_enrollments import ( # pylint: disable=unused-import + signals, + tasks, + ) diff --git a/lms/djangoapps/program_enrollments/management/commands/tests/test_expire_waiting_enrollments.py b/lms/djangoapps/program_enrollments/management/commands/tests/test_expire_waiting_enrollments.py index a0446aa29f22..b7343de32a55 100644 --- a/lms/djangoapps/program_enrollments/management/commands/tests/test_expire_waiting_enrollments.py +++ b/lms/djangoapps/program_enrollments/management/commands/tests/test_expire_waiting_enrollments.py @@ -3,8 +3,8 @@ """ from unittest.mock import patch -import pytest import ddt +import pytest from django.core.management import call_command from django.test import TestCase diff --git a/lms/djangoapps/program_enrollments/management/commands/tests/test_reset_enrollment_data.py b/lms/djangoapps/program_enrollments/management/commands/tests/test_reset_enrollment_data.py index 26e2bab3a2ed..4b9083445d81 100644 --- a/lms/djangoapps/program_enrollments/management/commands/tests/test_reset_enrollment_data.py +++ b/lms/djangoapps/program_enrollments/management/commands/tests/test_reset_enrollment_data.py @@ -6,6 +6,7 @@ import sys from contextlib import contextmanager from uuid import uuid4 + import pytest from django.core.management import call_command from django.core.management.base import CommandError diff --git a/lms/djangoapps/program_enrollments/models.py b/lms/djangoapps/program_enrollments/models.py index b837c26e59e9..4f75c4c5368a 100644 --- a/lms/djangoapps/program_enrollments/models.py +++ b/lms/djangoapps/program_enrollments/models.py @@ -10,9 +10,9 @@ from model_utils.models import TimeStampedModel from opaque_keys.edx.django.models import CourseKeyField from simple_history.models import HistoricalRecords -from openedx.core.lib import user_util from common.djangoapps.student.models import CourseEnrollment +from openedx.core.lib import user_util from .constants import ProgramCourseEnrollmentRoles, ProgramCourseEnrollmentStatuses, ProgramEnrollmentStatuses diff --git a/lms/djangoapps/program_enrollments/rest_api/v1/tests/test_views.py b/lms/djangoapps/program_enrollments/rest_api/v1/tests/test_views.py index 174d3ad198ff..b1e7c5f5d974 100644 --- a/lms/djangoapps/program_enrollments/rest_api/v1/tests/test_views.py +++ b/lms/djangoapps/program_enrollments/rest_api/v1/tests/test_views.py @@ -20,16 +20,16 @@ from rest_framework import status from rest_framework.test import APITestCase from social_django.models import UserSocialAuth -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory as ModulestoreCourseFactory -from xmodule.modulestore.tests.factories import BlockFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.roles import CourseStaffRole -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory -from common.djangoapps.student.tests.factories import GlobalStaffFactory -from common.djangoapps.student.tests.factories import InstructorFactory +from common.djangoapps.student.tests.factories import ( + CourseEnrollmentFactory, + GlobalStaffFactory, + InstructorFactory, + UserFactory, +) from common.djangoapps.third_party_auth.tests.factories import SAMLProviderConfigFactory from lms.djangoapps.bulk_email.models import BulkEmailFlag, Optout from lms.djangoapps.certificates.data import CertificateStatuses @@ -42,7 +42,7 @@ from lms.djangoapps.program_enrollments.tests.factories import ( CourseAccessRoleAssignmentFactory, ProgramCourseEnrollmentFactory, - ProgramEnrollmentFactory + ProgramEnrollmentFactory, ) from openedx.core.djangoapps.catalog.cache import PROGRAM_CACHE_KEY_TPL, PROGRAMS_BY_ORGANIZATION_CACHE_KEY_TPL from openedx.core.djangoapps.catalog.tests.factories import ( @@ -50,18 +50,21 @@ CourseRunFactory, CurriculumFactory, OrganizationFactory, - ProgramFactory + ProgramFactory, ) from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangolib.testing.utils import CacheIsolationMixin +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory +from xmodule.modulestore.tests.factories import CourseFactory as ModulestoreCourseFactory from .. import views from ..constants import ( ENABLE_ENROLLMENT_RESET_FLAG, MAX_ENROLLMENT_RECORDS, REQUEST_STUDENT_KEY, - CourseRunProgressStatuses + CourseRunProgressStatuses, ) _DJANGOAPP_PATCH_FORMAT = 'lms.djangoapps.program_enrollments.{}' diff --git a/lms/djangoapps/program_enrollments/rest_api/v1/urls.py b/lms/djangoapps/program_enrollments/rest_api/v1/urls.py index 9741dab7beb4..fd74997e4949 100644 --- a/lms/djangoapps/program_enrollments/rest_api/v1/urls.py +++ b/lms/djangoapps/program_enrollments/rest_api/v1/urls.py @@ -14,7 +14,7 @@ ProgramCourseGradesView, ProgramEnrollmentsView, UserProgramCourseEnrollmentView, - UserProgramReadOnlyAccessView + UserProgramReadOnlyAccessView, ) app_name = 'v1' diff --git a/lms/djangoapps/program_enrollments/rest_api/v1/views.py b/lms/djangoapps/program_enrollments/rest_api/v1/views.py index 53883b755834..0eba267168c2 100644 --- a/lms/djangoapps/program_enrollments/rest_api/v1/views.py +++ b/lms/djangoapps/program_enrollments/rest_api/v1/views.py @@ -27,12 +27,12 @@ get_saml_providers_for_organization, iter_program_course_grades, write_program_course_enrollments, - write_program_enrollments + write_program_enrollments, ) from lms.djangoapps.program_enrollments.constants import ( ProgramCourseOperationStatuses, ProgramEnrollmentStatuses, - ProgramOperationStatuses + ProgramOperationStatuses, ) from lms.djangoapps.program_enrollments.exceptions import ProviderDoesNotExistException from openedx.core.apidocs import cursor_paginate_serializer @@ -40,7 +40,7 @@ get_programs, get_programs_by_type, get_programs_for_organization, - normalize_program_type + normalize_program_type, ) from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, PaginatedAPIView @@ -54,7 +54,7 @@ ProgramCourseGradeSerializer, ProgramEnrollmentCreateRequestSerializer, ProgramEnrollmentSerializer, - ProgramEnrollmentUpdateRequestSerializer + ProgramEnrollmentUpdateRequestSerializer, ) from .utils import ( ProgramCourseSpecificViewMixin, @@ -67,7 +67,7 @@ get_enrollments_for_courses_in_program, verify_course_exists_and_in_program, verify_program_exists, - verify_user_enrolled_in_program + verify_user_enrolled_in_program, ) diff --git a/lms/djangoapps/program_enrollments/signals.py b/lms/djangoapps/program_enrollments/signals.py index 572370c248cc..255901da678c 100644 --- a/lms/djangoapps/program_enrollments/signals.py +++ b/lms/djangoapps/program_enrollments/signals.py @@ -6,7 +6,7 @@ import logging from datetime import datetime -from django.db.models.signals import pre_save, post_save +from django.db.models.signals import post_save, pre_save from django.dispatch import receiver from social_django.models import UserSocialAuth diff --git a/lms/djangoapps/program_enrollments/tests/test_models.py b/lms/djangoapps/program_enrollments/tests/test_models.py index 1ff5ab35391a..7b484bca1649 100644 --- a/lms/djangoapps/program_enrollments/tests/test_models.py +++ b/lms/djangoapps/program_enrollments/tests/test_models.py @@ -4,8 +4,9 @@ from uuid import UUID -import pytest + import ddt +import pytest from django.db.utils import IntegrityError from django.test import TestCase from edx_django_utils.cache import RequestCache diff --git a/lms/djangoapps/program_enrollments/tests/test_signals.py b/lms/djangoapps/program_enrollments/tests/test_signals.py index 99ef037b8638..2228e211e55d 100644 --- a/lms/djangoapps/program_enrollments/tests/test_signals.py +++ b/lms/djangoapps/program_enrollments/tests/test_signals.py @@ -13,7 +13,6 @@ from organizations.tests.factories import OrganizationFactory from social_django.models import UserSocialAuth from testfixtures import LogCapture -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import CourseEnrollmentException @@ -29,6 +28,7 @@ from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangoapps.user_api.accounts.tests.retirement_helpers import fake_completed_retirement from openedx.core.djangolib.testing.utils import CacheIsolationTestCase +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase class ProgramEnrollmentRetireSignalTests(ModuleStoreTestCase): diff --git a/lms/djangoapps/rss_proxy/migrations/0001_initial.py b/lms/djangoapps/rss_proxy/migrations/0001_initial.py index e08e6133c279..9ad51ab1eaef 100644 --- a/lms/djangoapps/rss_proxy/migrations/0001_initial.py +++ b/lms/djangoapps/rss_proxy/migrations/0001_initial.py @@ -1,6 +1,6 @@ -from django.db import migrations, models import django.utils.timezone import model_utils.fields +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/rss_proxy/models.py b/lms/djangoapps/rss_proxy/models.py index afa653f6d744..da40f08335d0 100644 --- a/lms/djangoapps/rss_proxy/models.py +++ b/lms/djangoapps/rss_proxy/models.py @@ -2,7 +2,6 @@ Models for the rss_proxy djangoapp. """ from django.db import models - from model_utils.models import TimeStampedModel diff --git a/lms/djangoapps/staticbook/tests.py b/lms/djangoapps/staticbook/tests.py index 919ee16c4fef..8ed30ae0f9a1 100644 --- a/lms/djangoapps/staticbook/tests.py +++ b/lms/djangoapps/staticbook/tests.py @@ -11,7 +11,9 @@ from django.urls import NoReverseMatch, reverse from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order IMAGE_BOOK = ("An Image Textbook", "http://example.com/the_book/") diff --git a/lms/djangoapps/support/admin.py b/lms/djangoapps/support/admin.py index 2fde5d34654b..d993086cc347 100644 --- a/lms/djangoapps/support/admin.py +++ b/lms/djangoapps/support/admin.py @@ -1,7 +1,8 @@ """ Django admins for support models """ from django import forms from django.contrib import admin -from lms.djangoapps.support.models import CourseResetCourseOptIn, CourseResetAudit + +from lms.djangoapps.support.models import CourseResetAudit, CourseResetCourseOptIn from openedx.core.lib.courses import clean_course_id diff --git a/lms/djangoapps/support/migrations/0001_initial.py b/lms/djangoapps/support/migrations/0001_initial.py index 302155a6a3c1..2531992be0d2 100644 --- a/lms/djangoapps/support/migrations/0001_initial.py +++ b/lms/djangoapps/support/migrations/0001_initial.py @@ -1,10 +1,10 @@ # Generated by Django 3.2.13 on 2022-05-17 08:26 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import simple_history.models import social_django.fields +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/support/migrations/0003_course_reset.py b/lms/djangoapps/support/migrations/0003_course_reset.py index b7e80d262fcf..2e0c0efce8b4 100644 --- a/lms/djangoapps/support/migrations/0003_course_reset.py +++ b/lms/djangoapps/support/migrations/0003_course_reset.py @@ -1,11 +1,11 @@ # Generated by Django 3.2.23 on 2024-02-22 14:48 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields import opaque_keys.edx.django.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/support/migrations/0005_unique_course_id.py b/lms/djangoapps/support/migrations/0005_unique_course_id.py index baf89bedc358..ebd6d94f7a7f 100644 --- a/lms/djangoapps/support/migrations/0005_unique_course_id.py +++ b/lms/djangoapps/support/migrations/0005_unique_course_id.py @@ -1,7 +1,7 @@ # Generated by Django 4.2.10 on 2024-03-29 18:56 -from django.db import migrations import opaque_keys.edx.django.models +from django.db import migrations class Migration(migrations.Migration): diff --git a/lms/djangoapps/support/models.py b/lms/djangoapps/support/models.py index 99dca539375f..99706a2f31f8 100644 --- a/lms/djangoapps/support/models.py +++ b/lms/djangoapps/support/models.py @@ -2,9 +2,8 @@ Models used to implement support related models in such as SSO History model """ from django.contrib.auth import get_user_model -from django.db.models import ForeignKey, DO_NOTHING, CASCADE, TextChoices +from django.db.models import CASCADE, DO_NOTHING, ForeignKey, TextChoices from django.db.models.fields import BooleanField, CharField, DateTimeField - from model_utils.models import TimeStampedModel from opaque_keys.edx.django.models import CourseKeyField from simple_history import register diff --git a/lms/djangoapps/support/rest_api/v1/tests/test_views.py b/lms/djangoapps/support/rest_api/v1/tests/test_views.py index 58de5c965ecc..526aa00bd792 100644 --- a/lms/djangoapps/support/rest_api/v1/tests/test_views.py +++ b/lms/djangoapps/support/rest_api/v1/tests/test_views.py @@ -15,7 +15,7 @@ InstructorFactory, StaffFactory, SuperuserFactory, - UserFactory + UserFactory, ) from lms.djangoapps.support.tests.test_views import SupportViewTestCase from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory diff --git a/lms/djangoapps/support/tasks.py b/lms/djangoapps/support/tasks.py index e274f80e0e4d..b30e92a11a8b 100644 --- a/lms/djangoapps/support/tasks.py +++ b/lms/djangoapps/support/tasks.py @@ -1,27 +1,27 @@ """ Celery Tasks for the Instructor App. """ -from datetime import datetime import logging +from datetime import datetime + from celery import shared_task from completion.models import BlockCompletion +from django.contrib.sites.models import Site +from edx_ace import ace +from edx_ace.recipient import Recipient from edx_django_utils.monitoring import set_code_owner_attribute from common.djangoapps.student.models.course_enrollment import CourseEnrollment from common.djangoapps.student.models.user import get_user_by_username_or_email from lms.djangoapps.courseware.courses import get_course from lms.djangoapps.courseware.models import StudentModule +from lms.djangoapps.grades.api import clear_user_course_grades from lms.djangoapps.instructor.enrollment import reset_student_attempts +from lms.djangoapps.support.message_types import WholeCourseReset from lms.djangoapps.support.models import CourseResetAudit -from lms.djangoapps.grades.api import clear_user_course_grades from openedx.core.djangoapps.ace_common.template_context import get_base_template_context - -from edx_ace import ace -from django.contrib.sites.models import Site -from edx_ace.recipient import Recipient -from openedx.core.lib.celery.task_utils import emulate_http_request from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY from openedx.core.djangoapps.user_api.preferences.api import get_user_preference -from lms.djangoapps.support.message_types import WholeCourseReset +from openedx.core.lib.celery.task_utils import emulate_http_request log = logging.getLogger(__name__) diff --git a/lms/djangoapps/support/tests/factories.py b/lms/djangoapps/support/tests/factories.py index 619e669dec25..0ed9ad063cb2 100644 --- a/lms/djangoapps/support/tests/factories.py +++ b/lms/djangoapps/support/tests/factories.py @@ -1,13 +1,9 @@ """ Factories for course reset models """ import factory from factory.django import DjangoModelFactory -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory - -from lms.djangoapps.support.models import ( - CourseResetCourseOptIn, - CourseResetAudit -) +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory +from lms.djangoapps.support.models import CourseResetAudit, CourseResetCourseOptIn class CourseResetCourseOptInFactory(DjangoModelFactory): # lint-amnesty, pylint: disable=missing-class-docstring diff --git a/lms/djangoapps/support/tests/test_tasks.py b/lms/djangoapps/support/tests/test_tasks.py index 65add3079335..9a41c1f794e8 100644 --- a/lms/djangoapps/support/tests/test_tasks.py +++ b/lms/djangoapps/support/tests/test_tasks.py @@ -2,22 +2,22 @@ Unit tests for reset_student_course task """ -from unittest.mock import patch, Mock, call +from unittest.mock import Mock, call, patch from django.conf import settings from django.core import mail -from xmodule.modulestore.tests.factories import BlockFactory -from lms.djangoapps.courseware.tests.test_submitting_problems import TestSubmittingProblems -from lms.djangoapps.courseware.models import StudentModule -from lms.djangoapps.support.tasks import reset_student_course -from lms.djangoapps.support.tests.factories import CourseResetAuditFactory, CourseResetCourseOptInFactory -from lms.djangoapps.support.models import CourseResetAudit from common.djangoapps.student.models.course_enrollment import CourseEnrollment from common.djangoapps.student.roles import SupportStaffRole from common.djangoapps.student.tests.factories import UserFactory -from xmodule.video_block import VideoBlock +from lms.djangoapps.courseware.models import StudentModule +from lms.djangoapps.courseware.tests.test_submitting_problems import TestSubmittingProblems +from lms.djangoapps.support.models import CourseResetAudit +from lms.djangoapps.support.tasks import reset_student_course +from lms.djangoapps.support.tests.factories import CourseResetAuditFactory, CourseResetCourseOptInFactory from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from xmodule.modulestore.tests.factories import BlockFactory +from xmodule.video_block import VideoBlock class ResetStudentCourse(TestSubmittingProblems): diff --git a/lms/djangoapps/support/tests/test_views.py b/lms/djangoapps/support/tests/test_views.py index df713daf0b98..3272a340bdd3 100644 --- a/lms/djangoapps/support/tests/test_views.py +++ b/lms/djangoapps/support/tests/test_views.py @@ -30,10 +30,6 @@ from pytz import UTC from rest_framework import status from social_django.models import UserSocialAuth -from xmodule.modulestore.tests.django_utils import ( - TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase, SharedModuleStoreTestCase, -) -from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory @@ -43,20 +39,20 @@ UNENROLLED_TO_ENROLLED, CourseEnrollment, CourseEnrollmentAttribute, - ManualEnrollmentAudit + ManualEnrollmentAudit, ) from common.djangoapps.student.roles import GlobalStaff, SupportStaffRole from common.djangoapps.student.tests.factories import ( - CourseEnrollmentFactory, CourseEnrollmentAttributeFactory, + CourseEnrollmentFactory, UserFactory, ) from common.djangoapps.third_party_auth.tests.factories import SAMLProviderConfigFactory -from common.test.utils import disable_signal, assert_dict_contains_subset +from common.test.utils import assert_dict_contains_subset, disable_signal from lms.djangoapps.program_enrollments.tests.factories import ProgramCourseEnrollmentFactory, ProgramEnrollmentFactory from lms.djangoapps.support.models import CourseResetAudit from lms.djangoapps.support.serializers import ProgramEnrollmentSerializer -from lms.djangoapps.support.tests.factories import CourseResetCourseOptInFactory, CourseResetAuditFactory +from lms.djangoapps.support.tests.factories import CourseResetAuditFactory, CourseResetCourseOptInFactory from lms.djangoapps.verify_student.models import VerificationDeadline from lms.djangoapps.verify_student.services import IDVerificationService from lms.djangoapps.verify_student.tests.factories import SSOVerificationFactory @@ -67,8 +63,14 @@ from openedx.features.enterprise_support.api import enterprise_is_enabled from openedx.features.enterprise_support.tests.factories import ( EnterpriseCourseEnrollmentFactory, - EnterpriseCustomerUserFactory + EnterpriseCustomerUserFactory, +) +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_SPLIT_MODULESTORE, + ModuleStoreTestCase, + SharedModuleStoreTestCase, ) +from xmodule.modulestore.tests.factories import CourseFactory try: from consent.models import DataSharingConsent diff --git a/lms/djangoapps/support/urls.py b/lms/djangoapps/support/urls.py index 02d8be8519fe..cc0b660b390f 100644 --- a/lms/djangoapps/support/urls.py +++ b/lms/djangoapps/support/urls.py @@ -13,18 +13,15 @@ from .views.feature_based_enrollments import FeatureBasedEnrollmentsSupportView, FeatureBasedEnrollmentSupportAPIView from .views.index import index from .views.manage_user import ManageUserDetailView, ManageUserSupportView +from .views.onboarding_status import OnboardingView from .views.program_enrollments import ( - LinkProgramEnrollmentSupportView, LinkProgramEnrollmentSupportAPIView, + LinkProgramEnrollmentSupportView, + ProgramEnrollmentsInspectorAPIView, ProgramEnrollmentsInspectorView, SAMLProvidersWithOrg, - ProgramEnrollmentsInspectorAPIView, -) -from .views.sso_records import ( - SsoView, ) -from .views.onboarding_status import OnboardingView - +from .views.sso_records import SsoView COURSE_ENTITLEMENTS_VIEW = EntitlementSupportView.as_view() diff --git a/lms/djangoapps/support/views/course_reset.py b/lms/djangoapps/support/views/course_reset.py index c1f57784b797..a23e37dcb0a5 100644 --- a/lms/djangoapps/support/views/course_reset.py +++ b/lms/djangoapps/support/views/course_reset.py @@ -1,20 +1,18 @@ """ Views for the course reset feature """ -from rest_framework.response import Response from django.contrib.auth import get_user_model from django.utils.decorators import method_decorator from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey -from rest_framework.views import APIView from rest_framework.permissions import IsAuthenticated +from rest_framework.response import Response +from rest_framework.views import APIView -from common.djangoapps.student.models import CourseEnrollment, get_user_by_username_or_email from common.djangoapps.student.helpers import user_has_passing_grade_in_course +from common.djangoapps.student.models import CourseEnrollment, get_user_by_username_or_email from lms.djangoapps.support.decorators import require_support_permission -from lms.djangoapps.support.models import ( - CourseResetCourseOptIn, - CourseResetAudit -) +from lms.djangoapps.support.models import CourseResetAudit, CourseResetCourseOptIn + from ..tasks import reset_student_course User = get_user_model() diff --git a/lms/djangoapps/support/views/enrollments.py b/lms/djangoapps/support/views/enrollments.py index 0e469ec8de78..fa30f30295a2 100644 --- a/lms/djangoapps/support/views/enrollments.py +++ b/lms/djangoapps/support/views/enrollments.py @@ -24,24 +24,23 @@ UNENROLLED_TO_ENROLLED, CourseEnrollment, CourseEnrollmentAttribute, - ManualEnrollmentAudit + ManualEnrollmentAudit, ) from common.djangoapps.util.json_request import JsonResponse 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 openedx.core.djangoapps.credit.email_utils import get_credit_provider_attribute_values -from openedx.core.djangoapps.enrollments.api import get_enrollments, get_enrollment_attributes, update_enrollment +from openedx.core.djangoapps.enrollments.api import get_enrollment_attributes, get_enrollments, update_enrollment from openedx.core.djangoapps.enrollments.errors import CourseModeNotFoundError from openedx.core.djangoapps.enrollments.serializers import ModeSerializer from openedx.features.enterprise_support.api import ( enterprise_enabled, get_data_sharing_consents, - get_enterprise_course_enrollments + get_enterprise_course_enrollments, ) from openedx.features.enterprise_support.serializers import EnterpriseCourseEnrollmentSerializer - logger = logging.getLogger(__name__) diff --git a/lms/djangoapps/support/views/feature_based_enrollments.py b/lms/djangoapps/support/views/feature_based_enrollments.py index af5861ac5e27..efb13b458b9f 100644 --- a/lms/djangoapps/support/views/feature_based_enrollments.py +++ b/lms/djangoapps/support/views/feature_based_enrollments.py @@ -4,8 +4,8 @@ from django.utils.decorators import method_decorator from django.views.generic import View -from rest_framework.permissions import IsAuthenticated from rest_framework.generics import GenericAPIView +from rest_framework.permissions import IsAuthenticated from common.djangoapps.edxmako.shortcuts import render_to_response from common.djangoapps.util.json_request import JsonResponse diff --git a/lms/djangoapps/support/views/manage_user.py b/lms/djangoapps/support/views/manage_user.py index df2527fce404..1853e4e34f7d 100644 --- a/lms/djangoapps/support/views/manage_user.py +++ b/lms/djangoapps/support/views/manage_user.py @@ -9,18 +9,17 @@ from django.utils.decorators import method_decorator from django.utils.translation import gettext as _ from django.views.generic import View +from edx_django_utils.user import generate_password # lint-amnesty, pylint: disable=wrong-import-order from rest_framework.generics import GenericAPIView -from common.djangoapps.track import segment from common.djangoapps.edxmako.shortcuts import render_to_response from common.djangoapps.student.models import UserPasswordToggleHistory +from common.djangoapps.track import segment from common.djangoapps.util.json_request import JsonResponse from lms.djangoapps.support.decorators import require_support_permission from openedx.core.djangoapps.user_api.accounts.serializers import AccountUserSerializer from openedx.core.djangolib.oauth2_retirement_utils import retire_dot_oauth2_models -from edx_django_utils.user import generate_password # lint-amnesty, pylint: disable=wrong-import-order - class ManageUserSupportView(View): """ diff --git a/lms/djangoapps/support/views/program_enrollments.py b/lms/djangoapps/support/views/program_enrollments.py index d5b264069b68..45a21c8f6dce 100644 --- a/lms/djangoapps/support/views/program_enrollments.py +++ b/lms/djangoapps/support/views/program_enrollments.py @@ -6,9 +6,9 @@ from django.db.models import Q from django.utils.decorators import method_decorator from django.views.generic import View -from rest_framework.views import APIView -from rest_framework.response import Response from rest_framework.permissions import IsAuthenticated +from rest_framework.response import Response +from rest_framework.views import APIView from social_django.models import UserSocialAuth from common.djangoapps.edxmako.shortcuts import render_to_response @@ -19,12 +19,12 @@ ) from lms.djangoapps.program_enrollments.exceptions import ( BadOrganizationShortNameException, - ProviderDoesNotExistException + ProviderDoesNotExistException, ) from lms.djangoapps.support.decorators import require_support_permission from lms.djangoapps.support.serializers import ProgramEnrollmentSerializer, serialize_user_info -from lms.djangoapps.verify_student.services import IDVerificationService from lms.djangoapps.support.views.utils import validate_and_link_program_enrollments +from lms.djangoapps.verify_student.services import IDVerificationService TEMPLATE_PATH = 'support/link_program_enrollments.html' DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S' diff --git a/lms/djangoapps/support/views/sso_records.py b/lms/djangoapps/support/views/sso_records.py index b7d620a37636..747e6cfd196c 100644 --- a/lms/djangoapps/support/views/sso_records.py +++ b/lms/djangoapps/support/views/sso_records.py @@ -10,9 +10,7 @@ from common.djangoapps.util.json_request import JsonResponse from lms.djangoapps.support.decorators import require_support_permission -from lms.djangoapps.support.serializers import ( - serialize_sso_records, -) +from lms.djangoapps.support.serializers import serialize_sso_records class SsoView(GenericAPIView): diff --git a/lms/djangoapps/support/views/utils.py b/lms/djangoapps/support/views/utils.py index 52092b98a5dc..a44130790848 100644 --- a/lms/djangoapps/support/views/utils.py +++ b/lms/djangoapps/support/views/utils.py @@ -8,12 +8,10 @@ from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey +from lms.djangoapps.program_enrollments.api import link_program_enrollments from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.features.content_type_gating.models import ContentTypeGatingConfig from openedx.features.course_duration_limits.models import CourseDurationLimitConfig -from lms.djangoapps.program_enrollments.api import ( - link_program_enrollments -) def get_course_duration_info(course_key): diff --git a/lms/djangoapps/survey/migrations/0001_initial.py b/lms/djangoapps/survey/migrations/0001_initial.py index 1fc7e579e1a3..5b70e30930bf 100644 --- a/lms/djangoapps/survey/migrations/0001_initial.py +++ b/lms/djangoapps/survey/migrations/0001_initial.py @@ -1,7 +1,7 @@ -from django.db import migrations, models import django.utils.timezone -from django.conf import settings import model_utils.fields +from django.conf import settings +from django.db import migrations, models from opaque_keys.edx.django.models import CourseKeyField diff --git a/lms/djangoapps/survey/models.py b/lms/djangoapps/survey/models.py index fdc02e10652f..cf085635ef8a 100644 --- a/lms/djangoapps/survey/models.py +++ b/lms/djangoapps/survey/models.py @@ -8,7 +8,6 @@ from django.core.exceptions import ValidationError from django.db import models - from lxml import etree from model_utils.models import TimeStampedModel from opaque_keys.edx.django.models import CourseKeyField diff --git a/lms/djangoapps/survey/tests/test_signals.py b/lms/djangoapps/survey/tests/test_signals.py index f1bb12d080a6..7884d5a4184d 100644 --- a/lms/djangoapps/survey/tests/test_signals.py +++ b/lms/djangoapps/survey/tests/test_signals.py @@ -8,7 +8,9 @@ from lms.djangoapps.survey.signals import _listen_for_lms_retire from lms.djangoapps.survey.tests.factories import SurveyAnswerFactory from openedx.core.djangoapps.user_api.accounts.tests.retirement_helpers import fake_completed_retirement -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) class SurveyRetireSignalTests(ModuleStoreTestCase): diff --git a/lms/djangoapps/survey/tests/test_utils.py b/lms/djangoapps/survey/tests/test_utils.py index ce35474d6d28..d9af18bb930b 100644 --- a/lms/djangoapps/survey/tests/test_utils.py +++ b/lms/djangoapps/survey/tests/test_utils.py @@ -10,7 +10,9 @@ from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.survey.models import SurveyForm from lms.djangoapps.survey.utils import check_survey_required_and_unanswered, is_survey_required_for_course -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/survey/tests/test_views.py b/lms/djangoapps/survey/tests/test_views.py index 07ddd34e0576..2160c495dff4 100644 --- a/lms/djangoapps/survey/tests/test_views.py +++ b/lms/djangoapps/survey/tests/test_views.py @@ -11,7 +11,9 @@ from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.survey.models import SurveyAnswer, SurveyForm -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/teams/api_urls.py b/lms/djangoapps/teams/api_urls.py index a210358a6653..cb1e9f73db07 100644 --- a/lms/djangoapps/teams/api_urls.py +++ b/lms/djangoapps/teams/api_urls.py @@ -14,7 +14,7 @@ TeamsDetailView, TeamsListView, TopicDetailView, - TopicListView + TopicListView, ) TEAM_ID_PATTERN = r'(?P[a-z\d_-]+)' diff --git a/lms/djangoapps/teams/csv.py b/lms/djangoapps/teams/csv.py index cbfb754a50bb..4a45b4d74529 100644 --- a/lms/djangoapps/teams/csv.py +++ b/lms/djangoapps/teams/csv.py @@ -14,7 +14,7 @@ ORGANIZATION_PROTECTED_MODES, OrganizationProtectionStatus, user_organization_protection_status, - user_protection_status_matches_team + user_protection_status_matches_team, ) from lms.djangoapps.teams.models import CourseTeam, CourseTeamMembership diff --git a/lms/djangoapps/teams/models.py b/lms/djangoapps/teams/models.py index ff53871f2244..f105fa3ba1ed 100644 --- a/lms/djangoapps/teams/models.py +++ b/lms/djangoapps/teams/models.py @@ -11,7 +11,6 @@ from django.core.exceptions import ObjectDoesNotExist from django.db import models from django.dispatch import receiver - from django.utils.text import slugify from django.utils.translation import gettext_lazy from django_countries.fields import CountryField @@ -32,14 +31,14 @@ thread_edited, thread_followed, thread_unfollowed, - thread_voted + thread_voted, ) from .errors import ( AddToIncompatibleTeamError, AlreadyOnTeamInTeamset, ImmutableMembershipFieldException, - NotEnrolledInCourseForTeam + NotEnrolledInCourseForTeam, ) diff --git a/lms/djangoapps/teams/plugins.py b/lms/djangoapps/teams/plugins.py index 9ef932fe21ec..ae155f32f28d 100644 --- a/lms/djangoapps/teams/plugins.py +++ b/lms/djangoapps/teams/plugins.py @@ -14,8 +14,8 @@ from openedx.core.djangoapps.course_apps.plugins import CourseApp from openedx.core.lib.courses import get_course_by_id from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from . import is_feature_enabled +from . import is_feature_enabled User = get_user_model() diff --git a/lms/djangoapps/teams/team_partition_scheme.py b/lms/djangoapps/teams/team_partition_scheme.py index 7cbdaa37fbea..1eb3cbc700e5 100644 --- a/lms/djangoapps/teams/team_partition_scheme.py +++ b/lms/djangoapps/teams/team_partition_scheme.py @@ -8,19 +8,14 @@ from lms.djangoapps.courseware.masquerade import ( get_course_masquerade, get_masquerading_user_group, - is_masquerading_as_specific_student + is_masquerading_as_specific_student, ) from lms.djangoapps.teams.api import get_teams_in_teamset from lms.djangoapps.teams.models import CourseTeamMembership from openedx.core.lib.teams_config import CONTENT_GROUPS_FOR_TEAMS - -from xmodule.partitions.partitions import ( # lint-amnesty, pylint: disable=wrong-import-order - Group, - UserPartition -) +from xmodule.partitions.partitions import Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order from xmodule.services import TeamsConfigurationService - log = logging.getLogger(__name__) diff --git a/lms/djangoapps/teams/tests/test_api.py b/lms/djangoapps/teams/tests/test_api.py index dceb940ef560..deb6090f9f45 100644 --- a/lms/djangoapps/teams/tests/test_api.py +++ b/lms/djangoapps/teams/tests/test_api.py @@ -16,7 +16,9 @@ from lms.djangoapps.teams.models import CourseTeam from lms.djangoapps.teams.tests.factories import CourseTeamFactory from openedx.core.lib.teams_config import TeamsConfig, TeamsetType -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order COURSE_KEY1 = CourseKey.from_string('course-v1:edx+history+1') diff --git a/lms/djangoapps/teams/tests/test_csv.py b/lms/djangoapps/teams/tests/test_csv.py index c9ad9c1bde75..0e1312461e82 100644 --- a/lms/djangoapps/teams/tests/test_csv.py +++ b/lms/djangoapps/teams/tests/test_csv.py @@ -1,14 +1,17 @@ """ Tests for the functionality in csv """ from csv import DictReader, DictWriter from io import BytesIO, StringIO, TextIOWrapper + from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from common.djangoapps.util.testing import EventTestMixin -from lms.djangoapps.program_enrollments.tests.factories import ProgramEnrollmentFactory, ProgramCourseEnrollmentFactory +from lms.djangoapps.program_enrollments.tests.factories import ProgramCourseEnrollmentFactory, ProgramEnrollmentFactory from lms.djangoapps.teams import csv from lms.djangoapps.teams.models import CourseTeam, CourseTeamMembership from lms.djangoapps.teams.tests.factories import CourseTeamFactory from openedx.core.lib.teams_config import TeamsConfig -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/teams/tests/test_models.py b/lms/djangoapps/teams/tests/test_models.py index 60190076004c..6b4048f234fc 100644 --- a/lms/djangoapps/teams/tests/test_models.py +++ b/lms/djangoapps/teams/tests/test_models.py @@ -29,10 +29,12 @@ thread_created, thread_deleted, thread_edited, - thread_voted + thread_voted, ) from openedx.core.lib.teams_config import TeamsConfig -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order COURSE_KEY1 = CourseKey.from_string('edx/history/1') diff --git a/lms/djangoapps/teams/tests/test_partition_scheme.py b/lms/djangoapps/teams/tests/test_partition_scheme.py index 4ea230c42981..91482990bd26 100644 --- a/lms/djangoapps/teams/tests/test_partition_scheme.py +++ b/lms/djangoapps/teams/tests/test_partition_scheme.py @@ -6,12 +6,14 @@ from unittest.mock import MagicMock, patch from common.djangoapps.student.tests.factories import UserFactory -from lms.djangoapps.teams.tests.factories import CourseTeamFactory from lms.djangoapps.teams.team_partition_scheme import TeamPartitionScheme +from lms.djangoapps.teams.tests.factories import CourseTeamFactory from openedx.core.lib.teams_config import create_team_set_partitions_with_course_id -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import ToyCourseFactory from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ToyCourseFactory from xmodule.partitions.partitions import Group diff --git a/lms/djangoapps/teams/tests/test_serializers.py b/lms/djangoapps/teams/tests/test_serializers.py index 0a6adf6c4f41..52baa1f6a749 100644 --- a/lms/djangoapps/teams/tests/test_serializers.py +++ b/lms/djangoapps/teams/tests/test_serializers.py @@ -13,7 +13,9 @@ from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES from openedx.core.djangolib.testing.utils import AUTHZ_TABLES from openedx.core.lib.teams_config import TeamsConfig -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order QUERY_COUNT_TABLE_IGNORELIST = WAFFLE_TABLES + AUTHZ_TABLES diff --git a/lms/djangoapps/teams/tests/test_services.py b/lms/djangoapps/teams/tests/test_services.py index 22baeefadf64..068f045e53cb 100644 --- a/lms/djangoapps/teams/tests/test_services.py +++ b/lms/djangoapps/teams/tests/test_services.py @@ -7,7 +7,9 @@ from lms.djangoapps.teams.services import TeamsService from lms.djangoapps.teams.tests.factories import CourseTeamFactory from openedx.core.djangoapps.catalog.tests.factories import CourseRunFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) class TeamsServiceTests(ModuleStoreTestCase): diff --git a/lms/djangoapps/teams/tests/test_views.py b/lms/djangoapps/teams/tests/test_views.py index 9c4ca5feab47..69723ae8ea91 100644 --- a/lms/djangoapps/teams/tests/test_views.py +++ b/lms/djangoapps/teams/tests/test_views.py @@ -32,11 +32,17 @@ from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_COMMUNITY_TA, Role from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles from openedx.core.lib.teams_config import TeamsConfig -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order -from .factories import CourseTeamFactory, LAST_ACTIVITY_AT +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) + from ..models import CourseTeamMembership from ..search_indexes import CourseTeam, CourseTeamIndexer, course_team_post_save_callback +from .factories import LAST_ACTIVITY_AT, CourseTeamFactory @ddt.ddt diff --git a/lms/djangoapps/teams/urls.py b/lms/djangoapps/teams/urls.py index 5bdbc56c1389..9bfb8473053d 100644 --- a/lms/djangoapps/teams/urls.py +++ b/lms/djangoapps/teams/urls.py @@ -3,8 +3,8 @@ """ -from django.urls import path from django.contrib.auth.decorators import login_required +from django.urls import path from .views import TeamsDashboardView diff --git a/lms/djangoapps/teams/views.py b/lms/djangoapps/teams/views.py index dcce36382096..d01f7dddd0fb 100644 --- a/lms/djangoapps/teams/views.py +++ b/lms/djangoapps/teams/views.py @@ -33,14 +33,14 @@ from lms.djangoapps.courseware.courses import get_course_with_access, has_access from lms.djangoapps.discussion.django_comment_client.utils import has_discussion_privileges from lms.djangoapps.teams.models import CourseTeam, CourseTeamMembership -from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser, BearerAuthentication +from openedx.core.lib.api.authentication import BearerAuthentication, BearerAuthenticationAllowInactiveUser from openedx.core.lib.api.parsers import MergePatchParser from openedx.core.lib.api.permissions import IsCourseStaffInstructor, IsStaffOrReadOnly from openedx.core.lib.api.view_utils import ( ExpandableFieldViewMixin, RetrievePatchAPIView, add_serializer_errors, - build_api_error + build_api_error, ) from openedx.core.lib.teams_config import TeamsetType from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order @@ -56,7 +56,7 @@ has_specific_team_access, has_specific_teamset_access, has_team_api_access, - user_organization_protection_status + user_organization_protection_status, ) from .csv import TeamMembershipImportManager, load_team_membership_csv from .errors import AlreadyOnTeamInTeamset, ElasticSearchConnectionError, NotEnrolledInCourseForTeam @@ -66,7 +66,7 @@ CourseTeamCreationSerializer, CourseTeamSerializer, MembershipSerializer, - TopicSerializer + TopicSerializer, ) from .toggles import are_team_submissions_enabled from .utils import emit_team_event diff --git a/lms/djangoapps/user_tours/management/commands/tests/test_backpopulate_user_tours.py b/lms/djangoapps/user_tours/management/commands/tests/test_backpopulate_user_tours.py index 3812083999e4..b2c2a9be7868 100644 --- a/lms/djangoapps/user_tours/management/commands/tests/test_backpopulate_user_tours.py +++ b/lms/djangoapps/user_tours/management/commands/tests/test_backpopulate_user_tours.py @@ -6,8 +6,8 @@ from django.test import TestCase from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory -from lms.djangoapps.user_tours.models import UserTour from lms.djangoapps.user_tours.handlers import init_user_tour +from lms.djangoapps.user_tours.models import UserTour from openedx.core.djangolib.testing.utils import skip_unless_lms User = get_user_model() diff --git a/lms/djangoapps/user_tours/migrations/0001_initial.py b/lms/djangoapps/user_tours/migrations/0001_initial.py index b5393473885d..6a6f95b82f96 100644 --- a/lms/djangoapps/user_tours/migrations/0001_initial.py +++ b/lms/djangoapps/user_tours/migrations/0001_initial.py @@ -1,8 +1,8 @@ # Generated by Django 3.2.8 on 2021-11-19 15:58 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/lms/djangoapps/user_tours/migrations/0002_auto_20230110_0905.py b/lms/djangoapps/user_tours/migrations/0002_auto_20230110_0905.py index 27db0c0add12..b3024b5920f8 100644 --- a/lms/djangoapps/user_tours/migrations/0002_auto_20230110_0905.py +++ b/lms/djangoapps/user_tours/migrations/0002_auto_20230110_0905.py @@ -1,8 +1,8 @@ # Generated by Django 3.2.16 on 2023-01-10 09:05 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/lms/djangoapps/user_tours/urls.py b/lms/djangoapps/user_tours/urls.py index 63e2e2e06f0e..6403bd15ea85 100644 --- a/lms/djangoapps/user_tours/urls.py +++ b/lms/djangoapps/user_tours/urls.py @@ -3,8 +3,7 @@ from django.conf import settings from django.urls import re_path -from lms.djangoapps.user_tours.v1.views import UserTourView, UserDiscussionsToursView - +from lms.djangoapps.user_tours.v1.views import UserDiscussionsToursView, UserTourView urlpatterns = [ re_path(fr'^v1/{settings.USERNAME_PATTERN}$', UserTourView.as_view(), name='user-tours'), diff --git a/lms/djangoapps/user_tours/v1/serializers.py b/lms/djangoapps/user_tours/v1/serializers.py index 32bb636571d5..58bafaf5ee5c 100644 --- a/lms/djangoapps/user_tours/v1/serializers.py +++ b/lms/djangoapps/user_tours/v1/serializers.py @@ -2,7 +2,7 @@ from rest_framework import serializers -from lms.djangoapps.user_tours.models import UserTour, UserDiscussionsTours +from lms.djangoapps.user_tours.models import UserDiscussionsTours, UserTour class UserTourSerializer(serializers.ModelSerializer): diff --git a/lms/djangoapps/user_tours/v1/tests/test_views.py b/lms/djangoapps/user_tours/v1/tests/test_views.py index f78586b78dec..912b79701053 100644 --- a/lms/djangoapps/user_tours/v1/tests/test_views.py +++ b/lms/djangoapps/user_tours/v1/tests/test_views.py @@ -10,7 +10,7 @@ from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.user_tours.handlers import init_user_tour -from lms.djangoapps.user_tours.models import UserTour, UserDiscussionsTours +from lms.djangoapps.user_tours.models import UserDiscussionsTours, UserTour from lms.djangoapps.user_tours.toggles import USER_TOURS_DISABLED from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_for_user diff --git a/lms/djangoapps/user_tours/v1/views.py b/lms/djangoapps/user_tours/v1/views.py index 65db60bcacf8..b2f7d960f13a 100644 --- a/lms/djangoapps/user_tours/v1/views.py +++ b/lms/djangoapps/user_tours/v1/views.py @@ -1,17 +1,16 @@ """ API for User Tours. """ from django.conf import settings -from django.db import transaction, IntegrityError +from django.db import IntegrityError, transaction from django.shortcuts import get_object_or_404 +from rest_framework import status from rest_framework.generics import RetrieveUpdateAPIView from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response -from rest_framework import status +from rest_framework.views import APIView -from lms.djangoapps.user_tours.models import UserTour, UserDiscussionsTours +from lms.djangoapps.user_tours.models import UserDiscussionsTours, UserTour from lms.djangoapps.user_tours.toggles import USER_TOURS_DISABLED -from lms.djangoapps.user_tours.v1.serializers import UserTourSerializer, UserDiscussionsToursSerializer - -from rest_framework.views import APIView +from lms.djangoapps.user_tours.v1.serializers import UserDiscussionsToursSerializer, UserTourSerializer class UserTourView(RetrieveUpdateAPIView): diff --git a/lms/djangoapps/utils.py b/lms/djangoapps/utils.py index cabf13b84f1a..d892c8f633f5 100644 --- a/lms/djangoapps/utils.py +++ b/lms/djangoapps/utils.py @@ -7,6 +7,7 @@ except ImportError: BrazeClient = None from django.conf import settings + try: from optimizely import optimizely from optimizely.config_manager import PollingConfigManager diff --git a/lms/djangoapps/verify_student/admin.py b/lms/djangoapps/verify_student/admin.py index 1d3124580ad1..98a852f97370 100644 --- a/lms/djangoapps/verify_student/admin.py +++ b/lms/djangoapps/verify_student/admin.py @@ -9,7 +9,7 @@ SoftwareSecurePhotoVerification, SSOVerification, SSPVerificationRetryConfig, - VerificationAttempt + VerificationAttempt, ) diff --git a/lms/djangoapps/verify_student/api.py b/lms/djangoapps/verify_student/api.py index 7b8310fde030..fc30ff87bb73 100644 --- a/lms/djangoapps/verify_student/api.py +++ b/lms/djangoapps/verify_student/api.py @@ -2,14 +2,13 @@ API module. """ import logging +from datetime import datetime +from typing import Optional from django.conf import settings from django.contrib.auth import get_user_model from django.utils.translation import gettext as _ -from datetime import datetime -from typing import Optional - from lms.djangoapps.verify_student.emails import send_verification_approved_email from lms.djangoapps.verify_student.exceptions import VerificationAttemptInvalidStatus from lms.djangoapps.verify_student.models import VerificationAttempt diff --git a/lms/djangoapps/verify_student/apps.py b/lms/djangoapps/verify_student/apps.py index 1cc499f4972f..71d74e96c4bd 100644 --- a/lms/djangoapps/verify_student/apps.py +++ b/lms/djangoapps/verify_student/apps.py @@ -17,5 +17,5 @@ def ready(self): """ Connect signal handlers. """ + from lms.djangoapps.verify_student import tasks # pylint: disable=unused-import from lms.djangoapps.verify_student.signals import handlers, signals # pylint: disable=unused-import - from lms.djangoapps.verify_student import tasks # pylint: disable=unused-import diff --git a/lms/djangoapps/verify_student/management/commands/approve_id_verifications.py b/lms/djangoapps/verify_student/management/commands/approve_id_verifications.py index 4c45f415cf63..52d9ff12e0ad 100644 --- a/lms/djangoapps/verify_student/management/commands/approve_id_verifications.py +++ b/lms/djangoapps/verify_student/management/commands/approve_id_verifications.py @@ -16,7 +16,6 @@ from lms.djangoapps.verify_student.utils import earliest_allowed_verification_date from openedx.features.name_affirmation_api.utils import get_name_affirmation_service - 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 c8e589a1af7f..a03c2c66df1f 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,9 @@ Django admin commands related to verify_student """ -from datetime import datetime import logging import time +from datetime import datetime from django.core.management.base import BaseCommand diff --git a/lms/djangoapps/verify_student/management/commands/send_verification_expiry_email.py b/lms/djangoapps/verify_student/management/commands/send_verification_expiry_email.py index 5061bbd8da5c..eea94cccd8f2 100644 --- a/lms/djangoapps/verify_student/management/commands/send_verification_expiry_email.py +++ b/lms/djangoapps/verify_student/management/commands/send_verification_expiry_email.py @@ -9,13 +9,14 @@ from django.conf import settings from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user, wrong-import-order -from common.djangoapps.course_modes.models import CourseMode from django.contrib.sites.models import Site # lint-amnesty, pylint: disable=wrong-import-order from django.core.management.base import BaseCommand, CommandError # lint-amnesty, pylint: disable=wrong-import-order from django.db.models import Q # lint-amnesty, pylint: disable=wrong-import-order from django.utils.timezone import now # lint-amnesty, pylint: disable=wrong-import-order from edx_ace import ace # lint-amnesty, pylint: disable=wrong-import-order from edx_ace.recipient import Recipient # lint-amnesty, pylint: disable=wrong-import-order + +from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.util.query import use_read_replica_if_available from lms.djangoapps.verify_student.message_types import VerificationExpiry diff --git a/lms/djangoapps/verify_student/management/commands/tests/test_approve_id_verifications.py b/lms/djangoapps/verify_student/management/commands/tests/test_approve_id_verifications.py index 6eccee194795..c516bcdeeb1e 100644 --- a/lms/djangoapps/verify_student/management/commands/tests/test_approve_id_verifications.py +++ b/lms/djangoapps/verify_student/management/commands/tests/test_approve_id_verifications.py @@ -2,13 +2,13 @@ Tests for django admin commands in the verify_student module """ -import ddt import logging import os import tempfile from unittest import skipUnless from unittest.mock import MagicMock, patch +import ddt import pytest from django.core import mail from django.core.management import CommandError, call_command diff --git a/lms/djangoapps/verify_student/management/commands/tests/test_retry_failed_photo_verifications.py b/lms/djangoapps/verify_student/management/commands/tests/test_retry_failed_photo_verifications.py index 8fa84efe3a85..f46f8a0e6aa1 100644 --- a/lms/djangoapps/verify_student/management/commands/tests/test_retry_failed_photo_verifications.py +++ b/lms/djangoapps/verify_student/management/commands/tests/test_retry_failed_photo_verifications.py @@ -4,21 +4,21 @@ Lots of imports from verify_student's model tests, since they cover similar ground """ -from freezegun import freeze_time -from unittest.mock import call, patch, ANY +from unittest.mock import ANY, call, patch from django.conf import settings from django.core.management import call_command +from django.test.utils import override_settings +from freezegun import freeze_time from testfixtures import LogCapture -from django.test.utils import override_settings from common.test.utils import MockS3Boto3Mixin from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification, SSPVerificationRetryConfig from lms.djangoapps.verify_student.tests import TestVerificationBase from lms.djangoapps.verify_student.tests.test_models import ( FAKE_SETTINGS, mock_software_secure_post, - mock_software_secure_post_error + mock_software_secure_post_error, ) LOGGER_NAME = 'retry_photo_verification' diff --git a/lms/djangoapps/verify_student/management/commands/tests/test_trigger_softwaresecurephotoverifications_post_save_signal.py b/lms/djangoapps/verify_student/management/commands/tests/test_trigger_softwaresecurephotoverifications_post_save_signal.py index c9e98a94dec0..07102a82b322 100644 --- a/lms/djangoapps/verify_student/management/commands/tests/test_trigger_softwaresecurephotoverifications_post_save_signal.py +++ b/lms/djangoapps/verify_student/management/commands/tests/test_trigger_softwaresecurephotoverifications_post_save_signal.py @@ -4,18 +4,15 @@ """ +from unittest.mock import ANY, call, patch # lint-amnesty, pylint: disable=wrong-import-order + from django.conf import settings from django.core.management import call_command - from freezegun import freeze_time -from unittest.mock import call, patch, ANY # lint-amnesty, pylint: disable=wrong-import-order from common.test.utils import MockS3Boto3Mixin from lms.djangoapps.verify_student.tests import TestVerificationBase -from lms.djangoapps.verify_student.tests.test_models import ( - FAKE_SETTINGS, - mock_software_secure_post, -) +from lms.djangoapps.verify_student.tests.test_models import FAKE_SETTINGS, mock_software_secure_post # Lots of patching to stub in our own settings, and HTTP posting diff --git a/lms/djangoapps/verify_student/migrations/0012_sspverificationretryconfig.py b/lms/djangoapps/verify_student/migrations/0012_sspverificationretryconfig.py index b4f042bdaef5..e73b69b77564 100644 --- a/lms/djangoapps/verify_student/migrations/0012_sspverificationretryconfig.py +++ b/lms/djangoapps/verify_student/migrations/0012_sspverificationretryconfig.py @@ -1,9 +1,9 @@ # Generated by Django 1.11.26 on 2019-12-10 11:19 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/lms/djangoapps/verify_student/migrations/0013_add_expiration_date_field.py b/lms/djangoapps/verify_student/migrations/0013_add_expiration_date_field.py index cbacb9bb76e6..e0c39f3558fd 100644 --- a/lms/djangoapps/verify_student/migrations/0013_add_expiration_date_field.py +++ b/lms/djangoapps/verify_student/migrations/0013_add_expiration_date_field.py @@ -1,6 +1,7 @@ # Generated by Django 2.2.16 on 2020-11-06 21:29 from django.db import migrations, models + import lms.djangoapps.verify_student.models diff --git a/lms/djangoapps/verify_student/migrations/0015_verificationattempt.py b/lms/djangoapps/verify_student/migrations/0015_verificationattempt.py index 3f01047f9f51..6d67f61b1be5 100644 --- a/lms/djangoapps/verify_student/migrations/0015_verificationattempt.py +++ b/lms/djangoapps/verify_student/migrations/0015_verificationattempt.py @@ -1,10 +1,10 @@ # Generated by Django 4.2.15 on 2024-08-26 14:05 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/verify_student/migrations/0016_remove_verificationattempt_created_and_more.py b/lms/djangoapps/verify_student/migrations/0016_remove_verificationattempt_created_and_more.py index d972dba3dbbd..c57a187dd83f 100644 --- a/lms/djangoapps/verify_student/migrations/0016_remove_verificationattempt_created_and_more.py +++ b/lms/djangoapps/verify_student/migrations/0016_remove_verificationattempt_created_and_more.py @@ -1,9 +1,10 @@ # Generated by Django 4.2.15 on 2024-09-26 20:08 -from django.db import migrations, models import django.utils.timezone -import lms.djangoapps.verify_student.statuses import model_utils.fields +from django.db import migrations, models + +import lms.djangoapps.verify_student.statuses class Migration(migrations.Migration): diff --git a/lms/djangoapps/verify_student/models.py b/lms/djangoapps/verify_student/models.py index 2c9edf9b6d0c..21ebb1280241 100644 --- a/lms/djangoapps/verify_student/models.py +++ b/lms/djangoapps/verify_student/models.py @@ -15,11 +15,9 @@ import logging import os.path import uuid - from datetime import timedelta from email.utils import formatdate - import requests from config_models.models import ConfigurationModel from django.conf import settings @@ -27,24 +25,23 @@ from django.core.files.base import ContentFile from django.db import models, transaction from django.urls import reverse - from django.utils.functional import cached_property from django.utils.timezone import now from django.utils.translation import gettext_lazy from model_utils import Choices from model_utils.models import StatusModel, TimeStampedModel -from lms.djangoapps.verify_student.statuses import VerificationAttemptStatus from opaque_keys.edx.django.models import CourseKeyField +from common.djangoapps.util.storage import resolve_storage_backend from lms.djangoapps.verify_student.ssencrypt import ( decode_and_decrypt, encrypt_and_encode, generate_signed_message, random_aes_key, rsa_decrypt, - rsa_encrypt + rsa_encrypt, ) -from common.djangoapps.util.storage import resolve_storage_backend +from lms.djangoapps.verify_student.statuses import VerificationAttemptStatus from openedx.core.djangoapps.signals.signals import LEARNER_SSO_VERIFIED, PHOTO_VERIFICATION_APPROVED from .utils import auto_verify_for_testing_enabled, earliest_allowed_verification_date, submit_request_to_ss diff --git a/lms/djangoapps/verify_student/signals/handlers.py b/lms/djangoapps/verify_student/signals/handlers.py index 8a1d7b542b00..daaa59c813b5 100644 --- a/lms/djangoapps/verify_student/signals/handlers.py +++ b/lms/djangoapps/verify_student/signals/handlers.py @@ -6,18 +6,17 @@ from django.core.exceptions import ObjectDoesNotExist from django.db.models.signals import post_save from django.dispatch.dispatcher import receiver -from xmodule.modulestore.django import SignalHandler, modulestore from common.djangoapps.student.models_api import get_name, get_pending_name_change from lms.djangoapps.verify_student.apps import VerifyStudentConfig # pylint: disable=unused-import -from lms.djangoapps.verify_student.signals.signals import idv_update_signal -from openedx.core.djangoapps.user_api.accounts.signals import USER_RETIRE_LMS_CRITICAL, USER_RETIRE_LMS_MISC - from lms.djangoapps.verify_student.models import ( SoftwareSecurePhotoVerification, + VerificationAttempt, VerificationDeadline, - VerificationAttempt ) +from lms.djangoapps.verify_student.signals.signals import idv_update_signal +from openedx.core.djangoapps.user_api.accounts.signals import USER_RETIRE_LMS_CRITICAL, USER_RETIRE_LMS_MISC +from xmodule.modulestore.django import SignalHandler, modulestore log = logging.getLogger(__name__) diff --git a/lms/djangoapps/verify_student/signals/signals.py b/lms/djangoapps/verify_student/signals/signals.py index 9fe47467c983..68b2ff6d8893 100644 --- a/lms/djangoapps/verify_student/signals/signals.py +++ b/lms/djangoapps/verify_student/signals/signals.py @@ -3,13 +3,12 @@ """ from django.dispatch import Signal - from openedx_events.learning.data import UserData, UserPersonalData, VerificationAttemptData from openedx_events.learning.signals import ( - IDV_ATTEMPT_CREATED, - IDV_ATTEMPT_PENDING, IDV_ATTEMPT_APPROVED, + IDV_ATTEMPT_CREATED, IDV_ATTEMPT_DENIED, + IDV_ATTEMPT_PENDING, ) # Signal for emitting IDV submission and review updates diff --git a/lms/djangoapps/verify_student/tests/test_api.py b/lms/djangoapps/verify_student/tests/test_api.py index 2be7b6580905..79d583ee9032 100644 --- a/lms/djangoapps/verify_student/tests/test_api.py +++ b/lms/djangoapps/verify_student/tests/test_api.py @@ -1,9 +1,9 @@ """ Tests of API module. """ +from datetime import datetime, timezone from unittest.mock import patch -from datetime import datetime, timezone import ddt from django.conf import settings from django.core import mail diff --git a/lms/djangoapps/verify_student/tests/test_handlers.py b/lms/djangoapps/verify_student/tests/test_handlers.py index 40d80712f19d..a3d792c1b3c9 100644 --- a/lms/djangoapps/verify_student/tests/test_handlers.py +++ b/lms/djangoapps/verify_student/tests/test_handlers.py @@ -4,28 +4,30 @@ from datetime import timedelta +from unittest.mock import patch # lint-amnesty, pylint: disable=wrong-import-order from django.utils.timezone import now -from unittest.mock import patch # lint-amnesty, pylint: disable=wrong-import-order from common.djangoapps.student.models_api import do_name_change_request from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.verify_student.models import ( SoftwareSecurePhotoVerification, + VerificationAttempt, VerificationDeadline, - VerificationAttempt ) from lms.djangoapps.verify_student.signals.handlers import ( _listen_for_course_publish, _listen_for_lms_retire, - _listen_for_lms_retire_verification_attempts + _listen_for_lms_retire_verification_attempts, ) from lms.djangoapps.verify_student.tests.factories import ( SoftwareSecurePhotoVerificationFactory, - VerificationAttemptFactory + VerificationAttemptFactory, ) from openedx.core.djangoapps.user_api.accounts.tests.retirement_helpers import fake_completed_retirement -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/verify_student/tests/test_integration.py b/lms/djangoapps/verify_student/tests/test_integration.py index cccdf239134e..b0609237ff8e 100644 --- a/lms/djangoapps/verify_student/tests/test_integration.py +++ b/lms/djangoapps/verify_student/tests/test_integration.py @@ -7,7 +7,9 @@ from common.djangoapps.course_modes.tests.factories import CourseModeFactory from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..services import IDVerificationService diff --git a/lms/djangoapps/verify_student/tests/test_models.py b/lms/djangoapps/verify_student/tests/test_models.py index fb94b28a3ce1..70ff9cfe3d40 100644 --- a/lms/djangoapps/verify_student/tests/test_models.py +++ b/lms/djangoapps/verify_student/tests/test_models.py @@ -5,8 +5,8 @@ from unittest import mock from unittest.mock import patch -import pytest import ddt +import pytest import requests.exceptions import simplejson as json from django.conf import settings @@ -21,10 +21,12 @@ SoftwareSecurePhotoVerification, SSOVerification, VerificationAttempt, - VerificationException + VerificationException, ) from lms.djangoapps.verify_student.tests import TestVerificationBase -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) FAKE_SETTINGS = { "SOFTWARE_SECURE": { diff --git a/lms/djangoapps/verify_student/tests/test_services.py b/lms/djangoapps/verify_student/tests/test_services.py index a84a01bf0244..7cf68a66295a 100644 --- a/lms/djangoapps/verify_student/tests/test_services.py +++ b/lms/djangoapps/verify_student/tests/test_services.py @@ -22,12 +22,13 @@ ManualVerification, SoftwareSecurePhotoVerification, SSOVerification, - VerificationAttempt + VerificationAttempt, ) from lms.djangoapps.verify_student.services import IDVerificationService from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers -from xmodule.modulestore.tests.django_utils import \ - ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order FAKE_SETTINGS = { diff --git a/lms/djangoapps/verify_student/tests/test_ssencrypt.py b/lms/djangoapps/verify_student/tests/test_ssencrypt.py index ac0f54c1ab0c..73e0e6d748c4 100644 --- a/lms/djangoapps/verify_student/tests/test_ssencrypt.py +++ b/lms/djangoapps/verify_student/tests/test_ssencrypt.py @@ -12,7 +12,7 @@ decode_and_decrypt, encrypt_and_encode, rsa_decrypt, - rsa_encrypt + rsa_encrypt, ) AES_KEY_BYTES = binascii.unhexlify(b'32fe72aaf2abb44de9e161131b5435c8d37cbdb6f5df242ae860b283115f2dae') diff --git a/lms/djangoapps/verify_student/tests/test_tasks.py b/lms/djangoapps/verify_student/tests/test_tasks.py index ec6c9e6ffa51..8c8f8dc211b8 100644 --- a/lms/djangoapps/verify_student/tests/test_tasks.py +++ b/lms/djangoapps/verify_student/tests/test_tasks.py @@ -9,7 +9,9 @@ from common.test.utils import MockS3Boto3Mixin from lms.djangoapps.verify_student.tests import TestVerificationBase from lms.djangoapps.verify_student.tests.test_models import FAKE_SETTINGS, mock_software_secure_post_unavailable -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) LOGGER_NAME = 'lms.djangoapps.verify_student.tasks' diff --git a/lms/djangoapps/verify_student/tests/test_utils.py b/lms/djangoapps/verify_student/tests/test_utils.py index b2f0edf334cf..f8f6b24d4706 100644 --- a/lms/djangoapps/verify_student/tests/test_utils.py +++ b/lms/djangoapps/verify_student/tests/test_utils.py @@ -18,7 +18,7 @@ from lms.djangoapps.verify_student.utils import ( most_recent_verification, submit_request_to_ss, - verification_for_datetime + verification_for_datetime, ) FAKE_SETTINGS = { diff --git a/lms/djangoapps/verify_student/tests/test_views.py b/lms/djangoapps/verify_student/tests/test_views.py index 0904611ef9f6..5645b0b90b7c 100644 --- a/lms/djangoapps/verify_student/tests/test_views.py +++ b/lms/djangoapps/verify_student/tests/test_views.py @@ -44,7 +44,9 @@ from openedx.core.djangoapps.user_api.accounts.api import get_account_settings from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/djangoapps/verify_student/views.py b/lms/djangoapps/verify_student/views.py index 553ec9e5401f..1655f224c10d 100644 --- a/lms/djangoapps/verify_student/views.py +++ b/lms/djangoapps/verify_student/views.py @@ -26,7 +26,6 @@ from requests.exceptions import RequestException from rest_framework.response import Response from rest_framework.views import APIView -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.edxmako.shortcuts import render_to_response @@ -46,6 +45,7 @@ from openedx.core.djangoapps.embargo import api as embargo_api from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.lib.log_utils import audit_log +from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from .services import IDVerificationService diff --git a/lms/envs/common.py b/lms/envs/common.py index 859d8ca56da7..05771650c65f 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -43,29 +43,30 @@ import os from corsheaders.defaults import default_headers as corsheaders_default_headers -from path import Path as path from django.utils.translation import gettext_lazy as _ +from edx_django_utils.plugins import add_plugins, get_plugin_apps from enterprise.constants import ( + DEFAULT_ENTERPRISE_ENROLLMENT_INTENTIONS_ROLE, ENTERPRISE_ADMIN_ROLE, - ENTERPRISE_LEARNER_ROLE, ENTERPRISE_CATALOG_ADMIN_ROLE, ENTERPRISE_DASHBOARD_ADMIN_ROLE, ENTERPRISE_ENROLLMENT_API_ADMIN_ROLE, ENTERPRISE_FULFILLMENT_OPERATOR_ROLE, + ENTERPRISE_LEARNER_ROLE, + ENTERPRISE_OPERATOR_ROLE, ENTERPRISE_REPORTING_CONFIG_ADMIN_ROLE, ENTERPRISE_SSO_ORCHESTRATOR_OPERATOR_ROLE, - ENTERPRISE_OPERATOR_ROLE, - SYSTEM_ENTERPRISE_PROVISIONING_ADMIN_ROLE, PROVISIONING_ENTERPRISE_CUSTOMER_ADMIN_ROLE, PROVISIONING_PENDING_ENTERPRISE_CUSTOMER_ADMIN_ROLE, - DEFAULT_ENTERPRISE_ENROLLMENT_INTENTIONS_ROLE, + SYSTEM_ENTERPRISE_PROVISIONING_ADMIN_ROLE, ) from openedx_content.settings_api import openedx_content_backcompat_apps_to_install +from path import Path as path +from openedx.core.djangoapps.plugins.constants import ProjectType, SettingsType from openedx.core.lib.derived import Derived -from openedx.envs.common import * # pylint: disable=wildcard-import - from openedx.core.lib.features_setting_proxy import FeaturesProxy +from openedx.envs.common import * # pylint: disable=wildcard-import # A proxy for feature flags stored in the settings namespace FEATURES = FeaturesProxy(globals()) @@ -2940,6 +2941,7 @@ # Note that all settings are actually defined by the plugin # pylint: disable=wrong-import-position from openedx.core.djangoapps.ace_common.settings import common as ace_common_settings + ACE_ROUTING_KEY = ace_common_settings.ACE_ROUTING_KEY ############### Settings for facebook ############################## @@ -2953,8 +2955,6 @@ ############## Plugin Django Apps ######################### -from edx_django_utils.plugins import get_plugin_apps, add_plugins # pylint: disable=wrong-import-position,wrong-import-order -from openedx.core.djangoapps.plugins.constants import ProjectType, SettingsType # pylint: disable=wrong-import-position INSTALLED_APPS.extend(get_plugin_apps(ProjectType.LMS)) add_plugins(__name__, ProjectType.LMS, SettingsType.COMMON) diff --git a/lms/envs/devstack.py b/lms/envs/devstack.py index cca704e06591..5289d5c0b595 100644 --- a/lms/envs/devstack.py +++ b/lms/envs/devstack.py @@ -1,3 +1,4 @@ +# ruff: noqa: I001 - settings file: star-import order is semantically significant """ Specific overrides to the base prod settings to make development easier. """ @@ -13,7 +14,6 @@ from edx_django_utils.plugins import add_plugins from openedx.core.djangoapps.plugins.constants import ProjectType, SettingsType - from openedx.core.lib.features_setting_proxy import FeaturesProxy from .production import * # pylint: disable=wildcard-import, unused-wildcard-import diff --git a/lms/envs/production.py b/lms/envs/production.py index 63246821d954..3eefa7ac4276 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -1,3 +1,4 @@ +# ruff: noqa: I001 - settings file: star-import order is semantically significant """ Override common.py with key-value pairs from YAML (plus some extra defaults & post-processing). @@ -27,13 +28,13 @@ from openedx.core.djangoapps.plugins.constants import ProjectType, SettingsType from openedx.core.lib.derived import derive_settings +from openedx.core.lib.features_setting_proxy import FeaturesProxy from openedx.core.lib.logsettings import get_logger_config -from xmodule.modulestore.modulestore_settings import convert_module_store_setting_if_needed # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.modulestore_settings import \ + convert_module_store_setting_if_needed # lint-amnesty, pylint: disable=wrong-import-order from .common import * -from openedx.core.lib.features_setting_proxy import FeaturesProxy - # A proxy for feature flags stored in the settings namespace FEATURES = FeaturesProxy(globals()) diff --git a/lms/envs/test.py b/lms/envs/test.py index e396549501c1..dcf69f978790 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -13,22 +13,21 @@ # pylint: disable=wildcard-import, unused-wildcard-import -import logging +import logging # noqa: I001 - suppresses linting for this whole block, sort imports manually as needed from collections import OrderedDict from edx_django_utils.plugins import add_plugins from openedx.core.djangoapps.plugins.constants import ProjectType, SettingsType from openedx.core.lib.derived import derive_settings -from openedx.core.lib.tempdir import mkdtemp_clean -from xmodule.modulestore.modulestore_settings import update_module_store_settings # lint-amnesty, pylint: disable=wrong-import-order - from openedx.core.lib.features_setting_proxy import FeaturesProxy +from openedx.core.lib.tempdir import mkdtemp_clean +from xmodule.modulestore.modulestore_settings import ( + update_module_store_settings, # lint-amnesty, pylint: disable=wrong-import-order +) from .common import * - -from openedx.envs.test import * - +from openedx.envs.test import * # must come after .common to override Derived values with literals # A proxy for feature flags stored in the settings namespace FEATURES = FeaturesProxy(globals()) diff --git a/lms/lib/courseware_search/lms_filter_generator.py b/lms/lib/courseware_search/lms_filter_generator.py index 5b2592e4cd19..5c95852028f9 100644 --- a/lms/lib/courseware_search/lms_filter_generator.py +++ b/lms/lib/courseware_search/lms_filter_generator.py @@ -5,10 +5,10 @@ from django.conf import settings from search.filter_generator import SearchFilterGenerator +from common.djangoapps.student.models import CourseEnrollment 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 common.djangoapps.student.models import CourseEnrollment from xmodule.course_block import CATALOG_VISIBILITY_ABOUT, CATALOG_VISIBILITY_NONE INCLUDE_SCHEMES = [CohortPartitionScheme, RandomUserPartitionScheme, ] 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 8afa94f70fbf..549efc658b7e 100644 --- a/lms/lib/courseware_search/test/test_lms_filter_generator.py +++ b/lms/lib/courseware_search/test/test_lms_filter_generator.py @@ -3,12 +3,17 @@ """ from unittest.mock import Mock, patch -from lms.lib.courseware_search.lms_filter_generator import LmsSearchFilterGenerator from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory +from lms.lib.courseware_search.lms_filter_generator import LmsSearchFilterGenerator from xmodule.course_block import CATALOG_VISIBILITY_ABOUT, CATALOG_VISIBILITY_NONE -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) 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 c482ce2ca810..a50bd9798bfd 100644 --- a/lms/lib/courseware_search/test/test_lms_result_processor.py +++ b/lms/lib/courseware_search/test/test_lms_result_processor.py @@ -5,8 +5,13 @@ from common.djangoapps.student.tests.factories import UserFactory from lms.lib.courseware_search.lms_result_processor import LmsSearchResultProcessor -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) class LmsSearchResultProcessorTestCase(ModuleStoreTestCase): diff --git a/lms/lib/tests/test_utils.py b/lms/lib/tests/test_utils.py index ae0aea31d7e3..5d82163ad9c1 100644 --- a/lms/lib/tests/test_utils.py +++ b/lms/lib/tests/test_utils.py @@ -4,8 +4,13 @@ from lms.lib import utils -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) class LmsUtilsTest(ModuleStoreTestCase): diff --git a/lms/lib/xblock/test/test_mixin.py b/lms/lib/xblock/test/test_mixin.py index 248ac234ca6f..ff84b0f4f817 100644 --- a/lms/lib/xblock/test/test_mixin.py +++ b/lms/lib/xblock/test/test_mixin.py @@ -11,11 +11,18 @@ INVALID_USER_PARTITION_GROUP_VALIDATION_UNIT, INVALID_USER_PARTITION_VALIDATION_COMPONENT, INVALID_USER_PARTITION_VALIDATION_UNIT, - NONSENSICAL_ACCESS_RESTRICTION + NONSENSICAL_ACCESS_RESTRICTION, ) from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory, ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order + TEST_DATA_SPLIT_MODULESTORE, + ModuleStoreTestCase, +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, + ToyCourseFactory, +) from xmodule.partitions.partitions import Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order diff --git a/lms/urls.py b/lms/urls.py index 25c5a04f78cd..8f41fd26c771 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -17,13 +17,13 @@ from common.djangoapps.student import views as student_views from common.djangoapps.util import views as util_views from lms.djangoapps.branding import views as branding_views -from lms.djangoapps.courseware.masquerade import MasqueradeView from lms.djangoapps.courseware.block_render import ( handle_xblock_callback, handle_xblock_callback_noauth, xblock_view, - xqueue_callback + xqueue_callback, ) +from lms.djangoapps.courseware.masquerade import MasqueradeView from lms.djangoapps.courseware.views import views as courseware_views from lms.djangoapps.courseware.views.index import CoursewareIndex from lms.djangoapps.courseware.views.views import CourseTabView, EnrollStaffView, StaticCourseTabView diff --git a/lms/wsgi.py b/lms/wsgi.py index 0321c827ccf5..2f399298a367 100644 --- a/lms/wsgi.py +++ b/lms/wsgi.py @@ -10,12 +10,17 @@ # Patch the xml libs from openedx.core.lib.safe_lxml import defuse_xml_libs + defuse_xml_libs() import os # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.envs.aws") # This application object is used by the development server # as well as any WSGI server configured to use this file. -from django.core.wsgi import get_wsgi_application # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position +from django.core.wsgi import ( + get_wsgi_application, # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position +) + application = get_wsgi_application() diff --git a/lms/wsgi_apache_lms.py b/lms/wsgi_apache_lms.py index be74f3dc2580..ef7bba12362a 100644 --- a/lms/wsgi_apache_lms.py +++ b/lms/wsgi_apache_lms.py @@ -7,6 +7,7 @@ # Patch the xml libs before anything else. from openedx.core.lib.safe_lxml import defuse_xml_libs + defuse_xml_libs() import os # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position @@ -15,5 +16,8 @@ # This application object is used by the development server # as well as any WSGI server configured to use this file. -from django.core.wsgi import get_wsgi_application # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position +from django.core.wsgi import ( + get_wsgi_application, # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position +) + application = get_wsgi_application() # pylint: disable=invalid-name diff --git a/manage.py b/manage.py index 90e87b6b1dcc..e852b25adce4 100755 --- a/manage.py +++ b/manage.py @@ -13,10 +13,11 @@ # pylint: disable=wrong-import-order, wrong-import-position from openedx.core.lib.logsettings import log_python_warnings + log_python_warnings() # Patch the xml libs before anything else. -from openedx.core.lib.safe_lxml import defuse_xml_libs # isort:skip +from openedx.core.lib.safe_lxml import defuse_xml_libs # noqa: I001 - must patch xml libs before other imports execute defuse_xml_libs() import os diff --git a/openedx/core/djangoapps/ace_common/policies.py b/openedx/core/djangoapps/ace_common/policies.py index 11dc75b1e6e3..7835a0eed16f 100644 --- a/openedx/core/djangoapps/ace_common/policies.py +++ b/openedx/core/djangoapps/ace_common/policies.py @@ -6,7 +6,6 @@ from edx_ace.channel import ChannelType from edx_ace.policy import Policy, PolicyResult - User = get_user_model() log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/ace_common/template_context.py b/openedx/core/djangoapps/ace_common/template_context.py index 25cfe6c02a6d..43d6d04c2265 100644 --- a/openedx/core/djangoapps/ace_common/template_context.py +++ b/openedx/core/djangoapps/ace_common/template_context.py @@ -5,8 +5,8 @@ from django.conf import settings from django.urls import NoReverseMatch, reverse -from lms.djangoapps.branding.api import get_logo_url_for_email from common.djangoapps.edxmako.shortcuts import marketing_link +from lms.djangoapps.branding.api import get_logo_url_for_email from openedx.core.djangoapps.theming.helpers import get_config_value_from_site_or_settings diff --git a/openedx/core/djangoapps/ace_common/tests/mixins.py b/openedx/core/djangoapps/ace_common/tests/mixins.py index aed566504c4c..398470999351 100644 --- a/openedx/core/djangoapps/ace_common/tests/mixins.py +++ b/openedx/core/djangoapps/ace_common/tests/mixins.py @@ -8,8 +8,8 @@ from django.http import HttpRequest from edx_ace import Message, Recipient -from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory class QueryStringAssertionMixin: diff --git a/openedx/core/djangoapps/ace_common/tests/test_templatetags.py b/openedx/core/djangoapps/ace_common/tests/test_templatetags.py index 6df495060304..d8513bffd6c8 100644 --- a/openedx/core/djangoapps/ace_common/tests/test_templatetags.py +++ b/openedx/core/djangoapps/ace_common/tests/test_templatetags.py @@ -9,7 +9,7 @@ _get_google_analytics_tracking_url, ensure_url_is_absolute, google_analytics_tracking_pixel, - with_link_tracking + with_link_tracking, ) from openedx.core.djangoapps.ace_common.tests.mixins import EmailTemplateTagMixin, QueryStringAssertionMixin from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory diff --git a/openedx/core/djangoapps/ace_common/tests/test_tracking.py b/openedx/core/djangoapps/ace_common/tests/test_tracking.py index b6c0fa1df5b6..c93bd2dd9d10 100644 --- a/openedx/core/djangoapps/ace_common/tests/test_tracking.py +++ b/openedx/core/djangoapps/ace_common/tests/test_tracking.py @@ -10,7 +10,7 @@ DEFAULT_CAMPAIGN_MEDIUM, DEFAULT_CAMPAIGN_SOURCE, CampaignTrackingInfo, - GoogleAnalyticsTrackingPixel + GoogleAnalyticsTrackingPixel, ) from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory from openedx.core.djangolib.testing.utils import CacheIsolationTestCase diff --git a/openedx/core/djangoapps/agreements/api.py b/openedx/core/djangoapps/agreements/api.py index 5c81d4ab10a2..5aab8f4ef7f4 100644 --- a/openedx/core/djangoapps/agreements/api.py +++ b/openedx/core/djangoapps/agreements/api.py @@ -19,8 +19,8 @@ IntegritySignature, LTIPIISignature, LTIPIITool, - UserAgreementRecord, UserAgreement, + UserAgreementRecord, ) log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/agreements/migrations/0001_initial.py b/openedx/core/djangoapps/agreements/migrations/0001_initial.py index 5db5e1429f2f..87df97246bb5 100644 --- a/openedx/core/djangoapps/agreements/migrations/0001_initial.py +++ b/openedx/core/djangoapps/agreements/migrations/0001_initial.py @@ -1,11 +1,11 @@ # Generated by Django 2.2.20 on 2021-05-07 16:53 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields import opaque_keys.edx.django.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/agreements/migrations/0002_ltipiisignature.py b/openedx/core/djangoapps/agreements/migrations/0002_ltipiisignature.py index c72ab0dc8c57..25cc4e391957 100644 --- a/openedx/core/djangoapps/agreements/migrations/0002_ltipiisignature.py +++ b/openedx/core/djangoapps/agreements/migrations/0002_ltipiisignature.py @@ -1,9 +1,9 @@ # Generated by Django 3.2.20 on 2023-08-02 13:59 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import opaque_keys.edx.django.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/agreements/migrations/0002_ltipiitool.py b/openedx/core/djangoapps/agreements/migrations/0002_ltipiitool.py index fde896bc8d71..128288e03002 100644 --- a/openedx/core/djangoapps/agreements/migrations/0002_ltipiitool.py +++ b/openedx/core/djangoapps/agreements/migrations/0002_ltipiitool.py @@ -1,7 +1,7 @@ # Generated by Django 3.2.20 on 2023-08-01 14:06 -from django.db import migrations, models import opaque_keys.edx.django.models +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/agreements/migrations/0004_proctoringpiisignature.py b/openedx/core/djangoapps/agreements/migrations/0004_proctoringpiisignature.py index befe64cd5a5a..fc834a2c9d61 100644 --- a/openedx/core/djangoapps/agreements/migrations/0004_proctoringpiisignature.py +++ b/openedx/core/djangoapps/agreements/migrations/0004_proctoringpiisignature.py @@ -1,9 +1,9 @@ # Generated by Django 3.2.20 on 2023-08-03 16:09 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import opaque_keys.edx.django.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/agreements/migrations/0005_timestampedmodels.py b/openedx/core/djangoapps/agreements/migrations/0005_timestampedmodels.py index 53eb07fc3daa..a8c2bbf82d03 100644 --- a/openedx/core/djangoapps/agreements/migrations/0005_timestampedmodels.py +++ b/openedx/core/djangoapps/agreements/migrations/0005_timestampedmodels.py @@ -1,8 +1,8 @@ # Generated by Django 3.2.22 on 2023-10-25 14:58 -from django.db import migrations import django.utils.timezone import model_utils.fields +from django.db import migrations class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/agreements/migrations/0006_useragreementrecord.py b/openedx/core/djangoapps/agreements/migrations/0006_useragreementrecord.py index dd2b83062d7f..b77e4f4de264 100644 --- a/openedx/core/djangoapps/agreements/migrations/0006_useragreementrecord.py +++ b/openedx/core/djangoapps/agreements/migrations/0006_useragreementrecord.py @@ -1,8 +1,8 @@ # Generated by Django 4.2.16 on 2024-12-06 11:34 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/agreements/serializers.py b/openedx/core/djangoapps/agreements/serializers.py index 6b2b20a94579..26614882902c 100644 --- a/openedx/core/djangoapps/agreements/serializers.py +++ b/openedx/core/djangoapps/agreements/serializers.py @@ -4,9 +4,7 @@ from rest_framework import serializers -from openedx.core.djangoapps.agreements.models import ( - IntegritySignature, LTIPIISignature, UserAgreement, -) +from openedx.core.djangoapps.agreements.models import IntegritySignature, LTIPIISignature, UserAgreement from openedx.core.lib.api.serializers import CourseKeyField diff --git a/openedx/core/djangoapps/agreements/toggles.py b/openedx/core/djangoapps/agreements/toggles.py index 6d71abdf6582..4e69b5fe4530 100644 --- a/openedx/core/djangoapps/agreements/toggles.py +++ b/openedx/core/djangoapps/agreements/toggles.py @@ -3,6 +3,7 @@ """ from opaque_keys.edx.keys import CourseKey + from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag # .. toggle_name: agreements.enable_lti_pii_acknowledgement diff --git a/openedx/core/djangoapps/agreements/urls.py b/openedx/core/djangoapps/agreements/urls.py index a324900b4da7..e94f75e26197 100644 --- a/openedx/core/djangoapps/agreements/urls.py +++ b/openedx/core/djangoapps/agreements/urls.py @@ -3,7 +3,7 @@ """ from django.conf import settings -from django.urls import path, re_path, include +from django.urls import include, path, re_path from rest_framework.routers import DefaultRouter from openedx.core.djangoapps.agreements.views import ( diff --git a/openedx/core/djangoapps/api_admin/api/urls.py b/openedx/core/djangoapps/api_admin/api/urls.py index 81bc98680513..35a0b1882775 100644 --- a/openedx/core/djangoapps/api_admin/api/urls.py +++ b/openedx/core/djangoapps/api_admin/api/urls.py @@ -3,8 +3,7 @@ """ -from django.urls import include -from django.urls import path +from django.urls import include, path app_name = 'api_admin' urlpatterns = [ diff --git a/openedx/core/djangoapps/api_admin/api/v1/tests/test_views.py b/openedx/core/djangoapps/api_admin/api/v1/tests/test_views.py index 922d470f5b76..49a1b179b732 100644 --- a/openedx/core/djangoapps/api_admin/api/v1/tests/test_views.py +++ b/openedx/core/djangoapps/api_admin/api/v1/tests/test_views.py @@ -4,14 +4,13 @@ import json -from rest_framework.reverse import reverse - from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.test import TestCase +from rest_framework.reverse import reverse +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.api_admin.tests import factories from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.tests.factories import UserFactory @skip_unless_lms diff --git a/openedx/core/djangoapps/api_admin/api/v1/urls.py b/openedx/core/djangoapps/api_admin/api/v1/urls.py index 37781d74465b..8c2f0564baeb 100644 --- a/openedx/core/djangoapps/api_admin/api/v1/urls.py +++ b/openedx/core/djangoapps/api_admin/api/v1/urls.py @@ -3,6 +3,7 @@ """ from django.urls import path + from openedx.core.djangoapps.api_admin.api.v1 import views app_name = 'v1' diff --git a/openedx/core/djangoapps/api_admin/api/v1/views.py b/openedx/core/djangoapps/api_admin/api/v1/views.py index 70addba4c292..e4f26b28fd28 100644 --- a/openedx/core/djangoapps/api_admin/api/v1/views.py +++ b/openedx/core/djangoapps/api_admin/api/v1/views.py @@ -3,16 +3,15 @@ """ from django_filters.rest_framework import DjangoFilterBackend - from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication from rest_framework.authentication import SessionAuthentication -from rest_framework.permissions import IsAuthenticated from rest_framework.generics import ListAPIView -from openedx.core.lib.api.authentication import BearerAuthentication +from rest_framework.permissions import IsAuthenticated +from openedx.core.djangoapps.api_admin.api.filters import IsOwnerOrStaffFilterBackend from openedx.core.djangoapps.api_admin.api.v1 import serializers as api_access_serializers from openedx.core.djangoapps.api_admin.models import ApiAccessRequest -from openedx.core.djangoapps.api_admin.api.filters import IsOwnerOrStaffFilterBackend +from openedx.core.lib.api.authentication import BearerAuthentication class ApiAccessRequestView(ListAPIView): diff --git a/openedx/core/djangoapps/api_admin/management/commands/create_api_access_request.py b/openedx/core/djangoapps/api_admin/management/commands/create_api_access_request.py index 9c35a31afa8a..c59e6b438253 100644 --- a/openedx/core/djangoapps/api_admin/management/commands/create_api_access_request.py +++ b/openedx/core/djangoapps/api_admin/management/commands/create_api_access_request.py @@ -13,7 +13,7 @@ ApiAccessConfig, ApiAccessRequest, send_decision_email, - send_request_email + send_request_email, ) logger = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/api_admin/management/commands/tests/test_create_api_access_request.py b/openedx/core/djangoapps/api_admin/management/commands/tests/test_create_api_access_request.py index f633aec1305e..a49d19caa36a 100644 --- a/openedx/core/djangoapps/api_admin/management/commands/tests/test_create_api_access_request.py +++ b/openedx/core/djangoapps/api_admin/management/commands/tests/test_create_api_access_request.py @@ -7,9 +7,10 @@ from django.core.management import call_command from django.core.management.base import CommandError from django.test import TestCase + +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.api_admin.models import ApiAccessConfig, ApiAccessRequest from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.tests.factories import UserFactory @skip_unless_lms diff --git a/openedx/core/djangoapps/api_admin/models.py b/openedx/core/djangoapps/api_admin/models.py index 8d947cd4a7e3..fa6daeebd346 100644 --- a/openedx/core/djangoapps/api_admin/models.py +++ b/openedx/core/djangoapps/api_admin/models.py @@ -16,8 +16,6 @@ from django.urls import reverse from django.utils.translation import gettext as _u from django.utils.translation import gettext_lazy as _ - - from model_utils.models import TimeStampedModel from common.djangoapps.edxmako.shortcuts import render_to_string diff --git a/openedx/core/djangoapps/api_admin/tests/factories.py b/openedx/core/djangoapps/api_admin/tests/factories.py index 4d369e5aaefe..f5ba84b0e803 100644 --- a/openedx/core/djangoapps/api_admin/tests/factories.py +++ b/openedx/core/djangoapps/api_admin/tests/factories.py @@ -6,9 +6,9 @@ from factory.fuzzy import FuzzyInteger, FuzzyText from oauth2_provider.models import get_application_model -from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory -from openedx.core.djangoapps.api_admin.models import ApiAccessRequest, Catalog from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.api_admin.models import ApiAccessRequest, Catalog +from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory Application = get_application_model() # pylint: disable=invalid-name diff --git a/openedx/core/djangoapps/api_admin/tests/test_models.py b/openedx/core/djangoapps/api_admin/tests/test_models.py index 05ca5b18463b..029f8a1f1b5b 100644 --- a/openedx/core/djangoapps/api_admin/tests/test_models.py +++ b/openedx/core/djangoapps/api_admin/tests/test_models.py @@ -4,17 +4,17 @@ from smtplib import SMTPException from unittest import mock -import pytest import ddt +import pytest from django.db import IntegrityError from django.test import TestCase +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.api_admin.models import ApiAccessConfig, ApiAccessRequest from openedx.core.djangoapps.api_admin.models import log as model_log from openedx.core.djangoapps.api_admin.tests.factories import ApiAccessRequestFactory from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.tests.factories import UserFactory @ddt.ddt diff --git a/openedx/core/djangoapps/api_admin/tests/test_views.py b/openedx/core/djangoapps/api_admin/tests/test_views.py index 083286ea0e24..ca0c03c9c8eb 100644 --- a/openedx/core/djangoapps/api_admin/tests/test_views.py +++ b/openedx/core/djangoapps/api_admin/tests/test_views.py @@ -11,15 +11,15 @@ from django.urls import reverse from oauth2_provider.models import get_application_model +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.api_admin.models import ApiAccessConfig, ApiAccessRequest from openedx.core.djangoapps.api_admin.tests.factories import ( ApiAccessRequestFactory, ApplicationFactory, - CatalogFactory + CatalogFactory, ) from openedx.core.djangoapps.api_admin.tests.utils import VALID_DATA from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.tests.factories import UserFactory Application = get_application_model() # pylint: disable=invalid-name diff --git a/openedx/core/djangoapps/api_admin/urls.py b/openedx/core/djangoapps/api_admin/urls.py index 73148b198a46..76ced9cb4e23 100644 --- a/openedx/core/djangoapps/api_admin/urls.py +++ b/openedx/core/djangoapps/api_admin/urls.py @@ -13,7 +13,7 @@ CatalogEditView, CatalogListView, CatalogPreviewView, - CatalogSearchView + CatalogSearchView, ) app_name = 'api_admin' diff --git a/openedx/core/djangoapps/auth_exchange/forms.py b/openedx/core/djangoapps/auth_exchange/forms.py index 0f5cacf07dd8..25cad5e36bff 100644 --- a/openedx/core/djangoapps/auth_exchange/forms.py +++ b/openedx/core/djangoapps/auth_exchange/forms.py @@ -3,9 +3,9 @@ """ from django import forms +from django.conf import settings from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.forms import CharField -from django.conf import settings from django.utils.encoding import smart_str from django.utils.translation import gettext as _ from oauth2_provider.models import Application diff --git a/openedx/core/djangoapps/auth_exchange/tests/test_forms.py b/openedx/core/djangoapps/auth_exchange/tests/test_forms.py index 0facf82fd427..e3a95832227c 100644 --- a/openedx/core/djangoapps/auth_exchange/tests/test_forms.py +++ b/openedx/core/djangoapps/auth_exchange/tests/test_forms.py @@ -13,7 +13,10 @@ from django.test.client import RequestFactory from social_django.models import Partial -from common.djangoapps.third_party_auth.tests.utils import ThirdPartyOAuthTestMixinFacebook, ThirdPartyOAuthTestMixinGoogle # lint-amnesty, pylint: disable=line-too-long +from common.djangoapps.third_party_auth.tests.utils import ( # lint-amnesty, pylint: disable=line-too-long + ThirdPartyOAuthTestMixinFacebook, + ThirdPartyOAuthTestMixinGoogle, +) from ..forms import AccessTokenExchangeForm from .mixins import DOTAdapterMixin diff --git a/openedx/core/djangoapps/auth_exchange/tests/test_views.py b/openedx/core/djangoapps/auth_exchange/tests/test_views.py index f560c5effbb4..6cebc9461aff 100644 --- a/openedx/core/djangoapps/auth_exchange/tests/test_views.py +++ b/openedx/core/djangoapps/auth_exchange/tests/test_views.py @@ -6,8 +6,7 @@ import json import unittest -from datetime import timedelta -from datetime import datetime +from datetime import datetime, timedelta import ddt import httpretty @@ -19,14 +18,14 @@ from rest_framework.test import APIClient from social_django.models import Partial -from openedx.core.djangoapps.oauth_dispatch import jwt as jwt_api -from openedx.core.djangoapps.oauth_dispatch.adapters import DOTAdapter -from openedx.core.djangoapps.oauth_dispatch.tests import factories as dot_factories from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.third_party_auth.tests.utils import ( ThirdPartyOAuthTestMixinFacebook, ThirdPartyOAuthTestMixinGoogle, ) +from openedx.core.djangoapps.oauth_dispatch import jwt as jwt_api +from openedx.core.djangoapps.oauth_dispatch.adapters import DOTAdapter +from openedx.core.djangoapps.oauth_dispatch.tests import factories as dot_factories from openedx.core.djangolib.testing.utils import skip_unless_lms from .mixins import DOTAdapterMixin diff --git a/openedx/core/djangoapps/auth_exchange/views.py b/openedx/core/djangoapps/auth_exchange/views.py index 60470aeba520..1f4a8e5629f9 100644 --- a/openedx/core/djangoapps/auth_exchange/views.py +++ b/openedx/core/djangoapps/auth_exchange/views.py @@ -8,8 +8,8 @@ """ import logging -import jwt import django.contrib.auth as auth +import jwt import social_django.utils as social_utils from django.conf import settings from django.contrib.auth import login @@ -35,7 +35,6 @@ from openedx.core.djangoapps.safe_sessions.middleware import mark_user_change_as_expected from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser - logger = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/authz/constants.py b/openedx/core/djangoapps/authz/constants.py index ae20f37d6287..272089c2169b 100644 --- a/openedx/core/djangoapps/authz/constants.py +++ b/openedx/core/djangoapps/authz/constants.py @@ -1,8 +1,9 @@ """Constants used by the Open edX Authorization (AuthZ) framework.""" -from common.djangoapps.student.auth import has_studio_read_access, has_studio_write_access from enum import Enum +from common.djangoapps.student.auth import has_studio_read_access, has_studio_write_access + class LegacyAuthoringPermission(Enum): READ = "read" diff --git a/openedx/core/djangoapps/authz/decorators.py b/openedx/core/djangoapps/authz/decorators.py index 38b04e92d8e5..b82a2fb69a51 100644 --- a/openedx/core/djangoapps/authz/decorators.py +++ b/openedx/core/djangoapps/authz/decorators.py @@ -1,16 +1,16 @@ """Decorators for AuthZ-based permissions enforcement.""" import logging -from functools import wraps from collections.abc import Callable +from functools import wraps from django.contrib.auth.models import AbstractUser from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey, UsageKey -from openedx.core.djangoapps.authz.constants import LEGACY_PERMISSION_HANDLER_MAP, LegacyAuthoringPermission from openedx_authz import api as authz_api from rest_framework import status from openedx.core import toggles as core_toggles +from openedx.core.djangoapps.authz.constants import LEGACY_PERMISSION_HANDLER_MAP, LegacyAuthoringPermission from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/authz/tests/mixins.py b/openedx/core/djangoapps/authz/tests/mixins.py index a8638b5fe375..39360c49fb29 100644 --- a/openedx/core/djangoapps/authz/tests/mixins.py +++ b/openedx/core/djangoapps/authz/tests/mixins.py @@ -1,17 +1,17 @@ """ Mixins for testing course-scoped AuthZ endpoints. """ +from unittest.mock import patch + import casbin import pkg_resources - -from unittest.mock import patch -from rest_framework.test import APIClient from openedx_authz.api.users import assign_role_to_user_in_scope from openedx_authz.constants.roles import COURSE_STAFF from openedx_authz.engine.enforcer import AuthzEnforcer from openedx_authz.engine.utils import migrate_policy_between_enforcers +from rest_framework.test import APIClient -from openedx.core import toggles as core_toggles from common.djangoapps.student.tests.factories import UserFactory +from openedx.core import toggles as core_toggles class CourseAuthoringAuthzTestMixin: diff --git a/openedx/core/djangoapps/bookmarks/api.py b/openedx/core/djangoapps/bookmarks/api.py index 7a65b0711f82..c65e21f69b2a 100644 --- a/openedx/core/djangoapps/bookmarks/api.py +++ b/openedx/core/djangoapps/bookmarks/api.py @@ -5,11 +5,11 @@ from .api_impl import ( BookmarksLimitReachedError, - get_bookmark, - get_bookmarks, can_create_more, create_bookmark, delete_bookmark, delete_bookmarks, + get_bookmark, + get_bookmarks, ) from .services import BookmarksService diff --git a/openedx/core/djangoapps/bookmarks/migrations/0001_initial.py b/openedx/core/djangoapps/bookmarks/migrations/0001_initial.py index 8a4849f84c80..2d45f38a42a6 100644 --- a/openedx/core/djangoapps/bookmarks/migrations/0001_initial.py +++ b/openedx/core/djangoapps/bookmarks/migrations/0001_initial.py @@ -1,8 +1,8 @@ -from django.db import migrations, models -import model_utils.fields -import jsonfield.fields import django.utils.timezone +import jsonfield.fields +import model_utils.fields from django.conf import settings +from django.db import migrations, models from opaque_keys.edx.django.models import CourseKeyField, UsageKeyField diff --git a/openedx/core/djangoapps/bookmarks/models.py b/openedx/core/djangoapps/bookmarks/models.py index 3236a6494870..d7154d5ceb26 100644 --- a/openedx/core/djangoapps/bookmarks/models.py +++ b/openedx/core/djangoapps/bookmarks/models.py @@ -7,7 +7,6 @@ from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.db import models - from jsonfield.fields import JSONField from model_utils.models import TimeStampedModel from opaque_keys.edx.django.models import CourseKeyField, UsageKeyField diff --git a/openedx/core/djangoapps/bookmarks/serializers.py b/openedx/core/djangoapps/bookmarks/serializers.py index 67ca301b675a..56d5b7e01770 100644 --- a/openedx/core/djangoapps/bookmarks/serializers.py +++ b/openedx/core/djangoapps/bookmarks/serializers.py @@ -8,7 +8,6 @@ from openedx.core.lib.api.serializers import CourseKeyField, UsageKeyField - from . import DEFAULT_FIELDS, OPTIONAL_FIELDS from .models import Bookmark diff --git a/openedx/core/djangoapps/bookmarks/services.py b/openedx/core/djangoapps/bookmarks/services.py index 2e2e25b01bf8..2e21e8759614 100644 --- a/openedx/core/djangoapps/bookmarks/services.py +++ b/openedx/core/djangoapps/bookmarks/services.py @@ -11,7 +11,8 @@ from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError -from . import DEFAULT_FIELDS, api_impl as api +from . import DEFAULT_FIELDS +from . import api_impl as api log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/bookmarks/tests/test_api.py b/openedx/core/djangoapps/bookmarks/tests/test_api.py index 0f5a3405bc43..ed22df8fa6a7 100644 --- a/openedx/core/djangoapps/bookmarks/tests/test_api.py +++ b/openedx/core/djangoapps/bookmarks/tests/test_api.py @@ -3,8 +3,8 @@ """ from unittest.mock import Mock, patch -import pytest import ddt +import pytest from django.conf import settings from django.core.exceptions import ObjectDoesNotExist from opaque_keys.edx.keys import UsageKey diff --git a/openedx/core/djangoapps/bookmarks/tests/test_models.py b/openedx/core/djangoapps/bookmarks/tests/test_models.py index 57a7234bccf8..c40154571fae 100644 --- a/openedx/core/djangoapps/bookmarks/tests/test_models.py +++ b/openedx/core/djangoapps/bookmarks/tests/test_models.py @@ -12,13 +12,13 @@ from freezegun import freeze_time from opaque_keys.edx.keys import UsageKey from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator + +from common.djangoapps.student.tests.factories import AdminFactory, UserFactory +from openedx.core.djangolib.testing.utils import skip_unless_lms 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, BlockFactory, check_mongo_calls - -from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.tests.factories import AdminFactory, UserFactory +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory, check_mongo_calls from .. import DEFAULT_FIELDS, OPTIONAL_FIELDS, PathItem from ..models import Bookmark, XBlockCache, parse_path_data diff --git a/openedx/core/djangoapps/bookmarks/tests/test_views.py b/openedx/core/djangoapps/bookmarks/tests/test_views.py index 592ae4d7b689..f27fde608ea3 100644 --- a/openedx/core/djangoapps/bookmarks/tests/test_views.py +++ b/openedx/core/djangoapps/bookmarks/tests/test_views.py @@ -4,16 +4,16 @@ import json -from urllib.parse import quote from unittest.mock import patch +from urllib.parse import quote import ddt from django.conf import settings from django.urls import reverse from rest_framework.test import APIClient -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE from openedx.core.djangolib.testing.utils import skip_unless_lms +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE from .test_api import BookmarkApiEventTestMixin from .test_models import BookmarksTestsBase diff --git a/openedx/core/djangoapps/bookmarks/views.py b/openedx/core/djangoapps/bookmarks/views.py index f8ab37963e60..2153142fac80 100644 --- a/openedx/core/djangoapps/bookmarks/views.py +++ b/openedx/core/djangoapps/bookmarks/views.py @@ -8,12 +8,12 @@ import logging +import edx_api_doc_tools as apidocs import eventtracking from django.conf import settings from django.core.exceptions import ObjectDoesNotExist from django.utils.translation import gettext as _ from django.utils.translation import gettext_noop -import edx_api_doc_tools as apidocs from edx_rest_framework_extensions.paginators import DefaultPagination from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey, UsageKey @@ -23,8 +23,8 @@ from rest_framework.response import Response from rest_framework.views import APIView -from openedx.core.lib.api.authentication import BearerAuthentication from openedx.core.djangoapps.bookmarks.api import BookmarksLimitReachedError +from openedx.core.lib.api.authentication import BearerAuthentication from openedx.core.lib.api.permissions import IsUserInUrl from openedx.core.lib.url_utils import unquote_slashes from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/core/djangoapps/cache_toolbox/templatetags/cache_toolbox.py b/openedx/core/djangoapps/cache_toolbox/templatetags/cache_toolbox.py index 0b3a81f5bdd5..c086b5c1292f 100644 --- a/openedx/core/djangoapps/cache_toolbox/templatetags/cache_toolbox.py +++ b/openedx/core/djangoapps/cache_toolbox/templatetags/cache_toolbox.py @@ -6,8 +6,12 @@ from django import template from django.core.cache import cache -from django.template import Node, TemplateSyntaxError, Variable -from django.template import resolve_variable # lint-amnesty, pylint: disable=no-name-in-module +from django.template import ( + Node, + TemplateSyntaxError, + Variable, + resolve_variable, # lint-amnesty, pylint: disable=no-name-in-module +) register = template.Library() # pylint: disable=invalid-name diff --git a/openedx/core/djangoapps/catalog/api.py b/openedx/core/djangoapps/catalog/api.py index 4428eb5f32ca..e9b6870d6eea 100644 --- a/openedx/core/djangoapps/catalog/api.py +++ b/openedx/core/djangoapps/catalog/api.py @@ -2,10 +2,10 @@ Python APIs exposed by the catalog app to other in-process apps. """ -from .utils import get_programs_by_type_slug as _get_programs_by_type_slug -from .utils import get_programs as _get_programs from .utils import course_run_keys_for_program as _course_run_keys_for_program from .utils import get_course_run_details as _get_course_run_details +from .utils import get_programs as _get_programs +from .utils import get_programs_by_type_slug as _get_programs_by_type_slug def get_programs_by_type(site, program_type_slug): diff --git a/openedx/core/djangoapps/catalog/management/commands/cache_programs.py b/openedx/core/djangoapps/catalog/management/commands/cache_programs.py index 4af05da89280..0d404749a2eb 100644 --- a/openedx/core/djangoapps/catalog/management/commands/cache_programs.py +++ b/openedx/core/djangoapps/catalog/management/commands/cache_programs.py @@ -20,7 +20,7 @@ PROGRAMS_BY_TYPE_CACHE_KEY_TPL, PROGRAMS_BY_TYPE_SLUG_CACHE_KEY_TPL, SITE_PATHWAY_IDS_CACHE_KEY_TPL, - SITE_PROGRAM_UUIDS_CACHE_KEY_TPL + SITE_PROGRAM_UUIDS_CACHE_KEY_TPL, ) from openedx.core.djangoapps.catalog.models import CatalogIntegration from openedx.core.djangoapps.catalog.utils import ( @@ -28,7 +28,7 @@ course_uuids_for_program, get_catalog_api_base_url, get_catalog_api_client, - normalize_program_type + normalize_program_type, ) logger = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/catalog/management/commands/create_catalog_integrations.py b/openedx/core/djangoapps/catalog/management/commands/create_catalog_integrations.py index 4e6942c37d52..fa95b0705f11 100644 --- a/openedx/core/djangoapps/catalog/management/commands/create_catalog_integrations.py +++ b/openedx/core/djangoapps/catalog/management/commands/create_catalog_integrations.py @@ -2,6 +2,7 @@ from django.core.management import BaseCommand, CommandError + from openedx.core.djangoapps.catalog.models import CatalogIntegration diff --git a/openedx/core/djangoapps/catalog/management/commands/sync_course_runs.py b/openedx/core/djangoapps/catalog/management/commands/sync_course_runs.py index a1bf31bd9577..ef66e52fed91 100644 --- a/openedx/core/djangoapps/catalog/management/commands/sync_course_runs.py +++ b/openedx/core/djangoapps/catalog/management/commands/sync_course_runs.py @@ -2,8 +2,8 @@ Sync course runs from catalog service. """ -from collections import namedtuple import logging +from collections import namedtuple from django.core.management.base import BaseCommand from opaque_keys.edx.keys import CourseKey diff --git a/openedx/core/djangoapps/catalog/management/commands/tests/test_cache_programs.py b/openedx/core/djangoapps/catalog/management/commands/tests/test_cache_programs.py index 1edd52d3c6a5..1c81b052da48 100644 --- a/openedx/core/djangoapps/catalog/management/commands/tests/test_cache_programs.py +++ b/openedx/core/djangoapps/catalog/management/commands/tests/test_cache_programs.py @@ -3,27 +3,28 @@ """ import json -import pytest + import httpretty +import pytest from django.core.cache import cache from django.core.management import call_command +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.catalog.cache import ( COURSE_PROGRAMS_CACHE_KEY_TPL, - PROGRAMS_BY_ORGANIZATION_CACHE_KEY_TPL, PATHWAY_CACHE_KEY_TPL, PROGRAM_CACHE_KEY_TPL, + PROGRAMS_BY_ORGANIZATION_CACHE_KEY_TPL, PROGRAMS_BY_TYPE_CACHE_KEY_TPL, PROGRAMS_BY_TYPE_SLUG_CACHE_KEY_TPL, SITE_PATHWAY_IDS_CACHE_KEY_TPL, - SITE_PROGRAM_UUIDS_CACHE_KEY_TPL + SITE_PROGRAM_UUIDS_CACHE_KEY_TPL, ) -from openedx.core.djangoapps.catalog.utils import normalize_program_type from openedx.core.djangoapps.catalog.tests.factories import OrganizationFactory, PathwayFactory, ProgramFactory from openedx.core.djangoapps.catalog.tests.mixins import CatalogIntegrationMixin +from openedx.core.djangoapps.catalog.utils import normalize_program_type from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms -from common.djangoapps.student.tests.factories import UserFactory @skip_unless_lms diff --git a/openedx/core/djangoapps/catalog/management/commands/tests/test_create_catalog_integrations.py b/openedx/core/djangoapps/catalog/management/commands/tests/test_create_catalog_integrations.py index 72591bf92d57..1738543713df 100644 --- a/openedx/core/djangoapps/catalog/management/commands/tests/test_create_catalog_integrations.py +++ b/openedx/core/djangoapps/catalog/management/commands/tests/test_create_catalog_integrations.py @@ -2,12 +2,11 @@ Test cases for catalog_integrations command. """ import pytest -from django.core.management import call_command, CommandError - -from openedx.core.djangolib.testing.utils import CacheIsolationTestCase +from django.core.management import CommandError, call_command from openedx.core.djangoapps.catalog.models import CatalogIntegration from openedx.core.djangoapps.catalog.tests.mixins import CatalogIntegrationMixin +from openedx.core.djangolib.testing.utils import CacheIsolationTestCase class TestCreateCatalogIntegrations(CatalogIntegrationMixin, CacheIsolationTestCase): diff --git a/openedx/core/djangoapps/catalog/management/commands/tests/test_sync_course_runs.py b/openedx/core/djangoapps/catalog/management/commands/tests/test_sync_course_runs.py index 882488f6c615..501197910d81 100644 --- a/openedx/core/djangoapps/catalog/management/commands/tests/test_sync_course_runs.py +++ b/openedx/core/djangoapps/catalog/management/commands/tests/test_sync_course_runs.py @@ -6,10 +6,12 @@ import ddt from django.core.management import call_command -from openedx.core.djangoapps.catalog.tests.factories import CourseRunFactory from openedx.core.djangoapps.catalog.management.commands.sync_course_runs import Command as sync_command +from openedx.core.djangoapps.catalog.tests.factories import CourseRunFactory from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order COMMAND_MODULE = 'openedx.core.djangoapps.catalog.management.commands.sync_course_runs' diff --git a/openedx/core/djangoapps/catalog/tests/test_models.py b/openedx/core/djangoapps/catalog/tests/test_models.py index 6bcd06d6bb15..acdcde975b6f 100644 --- a/openedx/core/djangoapps/catalog/tests/test_models.py +++ b/openedx/core/djangoapps/catalog/tests/test_models.py @@ -2,7 +2,6 @@ import ddt - from django.test import override_settings from openedx.core.djangoapps.catalog.tests import mixins diff --git a/openedx/core/djangoapps/catalog/urls.py b/openedx/core/djangoapps/catalog/urls.py index edf725ed727d..2b0d190e74e6 100644 --- a/openedx/core/djangoapps/catalog/urls.py +++ b/openedx/core/djangoapps/catalog/urls.py @@ -3,6 +3,7 @@ """ from django.urls import path + from . import views app_name = 'catalog' diff --git a/openedx/core/djangoapps/ccxcon/api.py b/openedx/core/djangoapps/ccxcon/api.py index 5dab1c940fa8..ceaa40ca0472 100644 --- a/openedx/core/djangoapps/ccxcon/api.py +++ b/openedx/core/djangoapps/ccxcon/api.py @@ -13,10 +13,10 @@ from requests_oauthlib import OAuth2Session from rest_framework.status import HTTP_200_OK, HTTP_201_CREATED -from openedx.core.djangoapps.models.course_details import CourseDetails -from openedx.core.lib.courses import get_course_by_id from common.djangoapps.student.models import anonymous_id_for_user from common.djangoapps.student.roles import CourseInstructorRole +from openedx.core.djangoapps.models.course_details import CourseDetails +from openedx.core.lib.courses import get_course_by_id from .models import CCXCon diff --git a/openedx/core/djangoapps/ccxcon/tasks.py b/openedx/core/djangoapps/ccxcon/tasks.py index d5d25f943cc4..58c4787d1095 100644 --- a/openedx/core/djangoapps/ccxcon/tasks.py +++ b/openedx/core/djangoapps/ccxcon/tasks.py @@ -7,7 +7,12 @@ from celery.utils.log import get_task_logger from edx_django_utils.monitoring import set_code_owner_attribute from opaque_keys.edx.keys import CourseKey -from requests.exceptions import ConnectionError, HTTPError, RequestException, TooManyRedirects # lint-amnesty, pylint: disable=redefined-builtin +from requests.exceptions import ( # lint-amnesty, pylint: disable=redefined-builtin + ConnectionError, + HTTPError, + RequestException, + TooManyRedirects, +) from openedx.core.djangoapps.ccxcon import api diff --git a/openedx/core/djangoapps/ccxcon/tests/test_api.py b/openedx/core/djangoapps/ccxcon/tests/test_api.py index d2d133ba20df..a49e02d31c31 100644 --- a/openedx/core/djangoapps/ccxcon/tests/test_api.py +++ b/openedx/core/djangoapps/ccxcon/tests/test_api.py @@ -8,12 +8,12 @@ import pytest from opaque_keys.edx.keys import CourseKey -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory -from openedx.core.djangoapps.ccxcon import api as ccxconapi from common.djangoapps.student.tests.factories import AdminFactory +from openedx.core.djangoapps.ccxcon import api as ccxconapi +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory from .factories import CcxConFactory diff --git a/openedx/core/djangoapps/ccxcon/tests/test_signals.py b/openedx/core/djangoapps/ccxcon/tests/test_signals.py index ec3c61c3fb87..9060ad499242 100644 --- a/openedx/core/djangoapps/ccxcon/tests/test_signals.py +++ b/openedx/core/djangoapps/ccxcon/tests/test_signals.py @@ -4,6 +4,7 @@ from unittest import mock + from django.test import TestCase from opaque_keys.edx.keys import CourseKey diff --git a/openedx/core/djangoapps/ccxcon/tests/test_tasks.py b/openedx/core/djangoapps/ccxcon/tests/test_tasks.py index 309b465bd43a..c31332a2de20 100644 --- a/openedx/core/djangoapps/ccxcon/tests/test_tasks.py +++ b/openedx/core/djangoapps/ccxcon/tests/test_tasks.py @@ -4,6 +4,7 @@ from unittest import mock + from django.test import TestCase from opaque_keys.edx.keys import CourseKey diff --git a/openedx/core/djangoapps/commerce/utils.py b/openedx/core/djangoapps/commerce/utils.py index 1d0c5d0924a6..73905dd802ee 100644 --- a/openedx/core/djangoapps/commerce/utils.py +++ b/openedx/core/djangoapps/commerce/utils.py @@ -1,21 +1,22 @@ """ Commerce API Service. """ -import requests -import slumber import datetime import json import os import socket + +import requests +import slumber from django.conf import settings -from edx_rest_api_client.auth import SuppliedJwtAuth, JwtAuth from edx_django_utils.cache import TieredCache +from edx_django_utils.monitoring import set_custom_attribute +from edx_rest_api_client.auth import JwtAuth, SuppliedJwtAuth from eventtracking import tracker +from requests.auth import AuthBase from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_for_user -from requests.auth import AuthBase from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers -from edx_django_utils.monitoring import set_custom_attribute # When caching tokens, use this value to err on expiring tokens a little early so they are # sure to be valid at the time they are used. diff --git a/openedx/core/djangoapps/common_initialization/apps.py b/openedx/core/djangoapps/common_initialization/apps.py index 53eb1fdaade0..e7711b3748fa 100644 --- a/openedx/core/djangoapps/common_initialization/apps.py +++ b/openedx/core/djangoapps/common_initialization/apps.py @@ -35,7 +35,7 @@ def _add_required_adapters(): :return: """ if 'postgresql' in connection.vendor.lower(): - from opaque_keys.edx.locator import CourseLocator, LibraryLocator, BlockUsageLocator + from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator, LibraryLocator from psycopg2.extensions import QuotedString, register_adapter def adapt_course_locator(course_locator): diff --git a/openedx/core/djangoapps/config_model_utils/admin.py b/openedx/core/djangoapps/config_model_utils/admin.py index cd896f448ffd..faf29aaf75aa 100644 --- a/openedx/core/djangoapps/config_model_utils/admin.py +++ b/openedx/core/djangoapps/config_model_utils/admin.py @@ -7,6 +7,7 @@ from django import forms from django.utils.translation import gettext_lazy as _ from opaque_keys.edx.keys import CourseKey + from openedx.core.djangolib.markup import HTML, Text diff --git a/openedx/core/djangoapps/content/block_structure/block_structure.py b/openedx/core/djangoapps/content/block_structure/block_structure.py index fbd05648e4d9..fa6fc75dabcd 100644 --- a/openedx/core/djangoapps/content/block_structure/block_structure.py +++ b/openedx/core/djangoapps/content/block_structure/block_structure.py @@ -14,9 +14,8 @@ from functools import partial from logging import getLogger -from xmodule.block_metadata_utils import get_datetime_field - from openedx.core.lib.graph_traversals import traverse_post_order, traverse_topologically +from xmodule.block_metadata_utils import get_datetime_field from .exceptions import TransformerException diff --git a/openedx/core/djangoapps/content/block_structure/management/commands/generate_course_blocks.py b/openedx/core/djangoapps/content/block_structure/management/commands/generate_course_blocks.py index 047c945fe406..989f3fe0d0b4 100644 --- a/openedx/core/djangoapps/content/block_structure/management/commands/generate_course_blocks.py +++ b/openedx/core/djangoapps/content/block_structure/management/commands/generate_course_blocks.py @@ -13,7 +13,7 @@ from openedx.core.lib.command_utils import ( get_mutually_exclusive_required_option, parse_course_keys, - validate_dependent_option + validate_dependent_option, ) from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/core/djangoapps/content/block_structure/management/commands/tests/test_generate_course_blocks.py b/openedx/core/djangoapps/content/block_structure/management/commands/tests/test_generate_course_blocks.py index 430f374b07cc..f9df66abcdc3 100644 --- a/openedx/core/djangoapps/content/block_structure/management/commands/tests/test_generate_course_blocks.py +++ b/openedx/core/djangoapps/content/block_structure/management/commands/tests/test_generate_course_blocks.py @@ -2,18 +2,20 @@ Tests for generate_course_blocks management command. """ +import itertools from unittest.mock import patch -import itertools -import pytest import ddt +import pytest from django.core.management.base import CommandError from openedx.core.djangoapps.content.block_structure.tests.helpers import ( is_course_in_block_structure_cache, - is_course_in_block_structure_storage + is_course_in_block_structure_storage, +) +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order ) -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from .. import generate_course_blocks diff --git a/openedx/core/djangoapps/content/block_structure/migrations/0001_config.py b/openedx/core/djangoapps/content/block_structure/migrations/0001_config.py index f25e3d629d8e..77fcba89e790 100644 --- a/openedx/core/djangoapps/content/block_structure/migrations/0001_config.py +++ b/openedx/core/djangoapps/content/block_structure/migrations/0001_config.py @@ -1,6 +1,6 @@ -from django.db import migrations, models import django.db.models.deletion from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content/block_structure/migrations/0002_blockstructuremodel.py b/openedx/core/djangoapps/content/block_structure/migrations/0002_blockstructuremodel.py index 7ff9c9e03640..80f9749a0291 100644 --- a/openedx/core/djangoapps/content/block_structure/migrations/0002_blockstructuremodel.py +++ b/openedx/core/djangoapps/content/block_structure/migrations/0002_blockstructuremodel.py @@ -1,7 +1,8 @@ -from django.db import migrations, models import django.utils.timezone import model_utils.fields +from django.db import migrations, models from opaque_keys.edx.django.models import UsageKeyField + import openedx.core.djangoapps.content.block_structure.models diff --git a/openedx/core/djangoapps/content/block_structure/migrations/0003_blockstructuremodel_storage.py b/openedx/core/djangoapps/content/block_structure/migrations/0003_blockstructuremodel_storage.py index b343dc170608..4a7904b97f3c 100644 --- a/openedx/core/djangoapps/content/block_structure/migrations/0003_blockstructuremodel_storage.py +++ b/openedx/core/djangoapps/content/block_structure/migrations/0003_blockstructuremodel_storage.py @@ -1,4 +1,5 @@ from django.db import migrations, models + import openedx.core.djangoapps.content.block_structure.models diff --git a/openedx/core/djangoapps/content/block_structure/migrations/0004_blockstructuremodel_usagekeywithrun.py b/openedx/core/djangoapps/content/block_structure/migrations/0004_blockstructuremodel_usagekeywithrun.py index 23ee895f3ba5..6d75495bf2a1 100644 --- a/openedx/core/djangoapps/content/block_structure/migrations/0004_blockstructuremodel_usagekeywithrun.py +++ b/openedx/core/djangoapps/content/block_structure/migrations/0004_blockstructuremodel_usagekeywithrun.py @@ -1,4 +1,5 @@ from django.db import migrations, models + import openedx.core.djangoapps.xmodule_django.models diff --git a/openedx/core/djangoapps/content/block_structure/models.py b/openedx/core/djangoapps/content/block_structure/models.py index 9bd75cab22bf..e7d16b2e977f 100644 --- a/openedx/core/djangoapps/content/block_structure/models.py +++ b/openedx/core/djangoapps/content/block_structure/models.py @@ -12,10 +12,9 @@ from django.core.exceptions import SuspiciousOperation from django.core.files.base import ContentFile from django.db import models, transaction - -from common.djangoapps.util.storage import resolve_storage_backend from model_utils.models import TimeStampedModel +from common.djangoapps.util.storage import resolve_storage_backend from openedx.core.djangoapps.xmodule_django.models import UsageKeyWithRunField from . import config diff --git a/openedx/core/djangoapps/content/block_structure/store.py b/openedx/core/djangoapps/content/block_structure/store.py index bb6359b9d3a3..b1db4e1ba120 100644 --- a/openedx/core/djangoapps/content/block_structure/store.py +++ b/openedx/core/djangoapps/content/block_structure/store.py @@ -6,6 +6,7 @@ from logging import getLogger +from edx_django_utils import monitoring from openedx.core.lib.cache_utils import zpickle, zunpickle @@ -16,8 +17,6 @@ from .models import BlockStructureModel from .transformer_registry import TransformerRegistry -from edx_django_utils import monitoring - logger = getLogger(__name__) # pylint: disable=C0103 diff --git a/openedx/core/djangoapps/content/block_structure/tasks.py b/openedx/core/djangoapps/content/block_structure/tasks.py index 01bee1905c89..df2df80632df 100644 --- a/openedx/core/djangoapps/content/block_structure/tasks.py +++ b/openedx/core/djangoapps/content/block_structure/tasks.py @@ -11,8 +11,8 @@ from edxval.api import ValInternalError from lxml.etree import XMLSyntaxError from opaque_keys.edx.keys import CourseKey - from xblocks_contrib.problem.capa.responsetypes import LoncapaProblemError + from openedx.core.djangoapps.content.block_structure import api from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/core/djangoapps/content/block_structure/tests/helpers.py b/openedx/core/djangoapps/content/block_structure/tests/helpers.py index df53b33d7b2e..a2bf6216fb13 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/helpers.py +++ b/openedx/core/djangoapps/content/block_structure/tests/helpers.py @@ -4,8 +4,8 @@ from contextlib import contextmanager -from uuid import uuid4 from unittest.mock import patch +from uuid import uuid4 from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_block_structure.py b/openedx/core/djangoapps/content/block_structure/tests/test_block_structure.py index 3152e762d127..fda52320b76c 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_block_structure.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_block_structure.py @@ -4,6 +4,7 @@ import itertools + # pylint: disable=protected-access from collections import namedtuple from copy import deepcopy diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_factory.py b/openedx/core/djangoapps/content/block_structure/tests/test_factory.py index 92050eef24b8..3fb6db28e7b9 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_factory.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_factory.py @@ -4,15 +4,15 @@ import pytest from django.test import TestCase - from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator + from xmodule.modulestore.exceptions import ItemNotFoundError from ..exceptions import BlockStructureNotFound from ..factory import BlockStructureFactory from ..store import BlockStructureStore -from .helpers import ChildrenMapTestMixin, MockCache, MockModulestoreFactory, MockXBlock, MockModulestore +from .helpers import ChildrenMapTestMixin, MockCache, MockModulestore, MockModulestoreFactory, MockXBlock class TestBlockStructureFactory(TestCase, ChildrenMapTestMixin): diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_manager.py b/openedx/core/djangoapps/content/block_structure/tests/test_manager.py index 1c4060871c97..2e50214456f2 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_manager.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_manager.py @@ -2,9 +2,10 @@ Tests for manager.py """ -import pytest -import ddt from unittest.mock import MagicMock + +import ddt +import pytest from django.test import TestCase from xmodule.modulestore import ModuleStoreEnum @@ -19,7 +20,7 @@ MockModulestoreFactory, MockTransformer, UsageKeyFactoryMixin, - mock_registered_transformers + mock_registered_transformers, ) diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_models.py b/openedx/core/djangoapps/content/block_structure/tests/test_models.py index 39bb68b09412..bea7d561d27a 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_models.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_models.py @@ -4,8 +4,8 @@ # pylint: disable=protected-access import errno from itertools import product -from uuid import uuid4 from unittest.mock import Mock, patch +from uuid import uuid4 import ddt import pytest diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_signals.py b/openedx/core/djangoapps/content/block_structure/tests/test_signals.py index af3587312530..68bf14669fee 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_signals.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_signals.py @@ -3,9 +3,10 @@ """ from unittest.mock import patch -import pytest import ddt +import pytest from opaque_keys.edx.locator import CourseLocator, LibraryLocator + from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_store.py b/openedx/core/djangoapps/content/block_structure/tests/test_store.py index 63a02efa7af8..d3b9f93251b0 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_store.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_store.py @@ -2,8 +2,8 @@ Tests for block_structure/cache.py """ -import pytest import ddt +import pytest from openedx.core.djangolib.testing.utils import CacheIsolationTestCase diff --git a/openedx/core/djangoapps/content/block_structure/transformer.py b/openedx/core/djangoapps/content/block_structure/transformer.py index b2ac620dc9a1..e1b0c9e5481f 100644 --- a/openedx/core/djangoapps/content/block_structure/transformer.py +++ b/openedx/core/djangoapps/content/block_structure/transformer.py @@ -4,8 +4,8 @@ """ -from abc import abstractmethod import functools +from abc import abstractmethod class BlockStructureTransformer: diff --git a/openedx/core/djangoapps/content/course_overviews/api.py b/openedx/core/djangoapps/content/course_overviews/api.py index 972469f83a1a..f800b1c58286 100644 --- a/openedx/core/djangoapps/content/course_overviews/api.py +++ b/openedx/core/djangoapps/content/course_overviews/api.py @@ -7,9 +7,7 @@ from openedx.core.djangoapps.catalog.api import get_course_run_details from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from openedx.core.djangoapps.content.course_overviews.serializers import ( - CourseOverviewBaseSerializer, -) +from openedx.core.djangoapps.content.course_overviews.serializers import CourseOverviewBaseSerializer log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/content/course_overviews/management/commands/backfill_history.py b/openedx/core/djangoapps/content/course_overviews/management/commands/backfill_history.py index cc5c75fbb92c..053932811ac6 100644 --- a/openedx/core/djangoapps/content/course_overviews/management/commands/backfill_history.py +++ b/openedx/core/djangoapps/content/course_overviews/management/commands/backfill_history.py @@ -6,10 +6,10 @@ import logging import os import time + from django.core.management.base import BaseCommand from django.db import connection, transaction - log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/content/course_overviews/management/commands/generate_course_overview.py b/openedx/core/djangoapps/content/course_overviews/management/commands/generate_course_overview.py index c18ceef4782e..a3c2b1ea4694 100644 --- a/openedx/core/djangoapps/content/course_overviews/management/commands/generate_course_overview.py +++ b/openedx/core/djangoapps/content/course_overviews/management/commands/generate_course_overview.py @@ -12,7 +12,7 @@ DEFAULT_ALL_COURSES, DEFAULT_CHUNK_SIZE, DEFAULT_FORCE_UPDATE, - enqueue_async_course_overview_update_tasks + enqueue_async_course_overview_update_tasks, ) log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/content/course_overviews/management/commands/simulate_publish.py b/openedx/core/djangoapps/content/course_overviews/management/commands/simulate_publish.py index efa36e7e227f..6cc26219b3ef 100644 --- a/openedx/core/djangoapps/content/course_overviews/management/commands/simulate_publish.py +++ b/openedx/core/djangoapps/content/course_overviews/management/commands/simulate_publish.py @@ -19,12 +19,13 @@ import textwrap import time -from django.core.management.base import BaseCommand, CommandError from django.conf import settings +from django.core.management.base import BaseCommand, CommandError from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey -from openedx.core.djangoapps.content.course_overviews.models import SimulateCoursePublishConfig + from lms.djangoapps.ccx.tasks import course_published_handler as ccx_receiver_fn +from openedx.core.djangoapps.content.course_overviews.models import SimulateCoursePublishConfig from xmodule.modulestore.django import SignalHandler, modulestore # lint-amnesty, pylint: disable=wrong-import-order log = logging.getLogger('simulate_publish') diff --git a/openedx/core/djangoapps/content/course_overviews/management/commands/tests/test_generate_course_overview.py b/openedx/core/djangoapps/content/course_overviews/management/commands/tests/test_generate_course_overview.py index 87bc5e4323c3..58e8dc411728 100644 --- a/openedx/core/djangoapps/content/course_overviews/management/commands/tests/test_generate_course_overview.py +++ b/openedx/core/djangoapps/content/course_overviews/management/commands/tests/test_generate_course_overview.py @@ -8,7 +8,9 @@ from openedx.core.djangoapps.content.course_overviews.management.commands import generate_course_overview from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/core/djangoapps/content/course_overviews/management/commands/tests/test_simulate_publish.py b/openedx/core/djangoapps/content/course_overviews/management/commands/tests/test_simulate_publish.py index 1235559969c2..f41573fcae97 100644 --- a/openedx/core/djangoapps/content/course_overviews/management/commands/tests/test_simulate_publish.py +++ b/openedx/core/djangoapps/content/course_overviews/management/commands/tests/test_simulate_publish.py @@ -11,7 +11,9 @@ from openedx.core.djangoapps.content.course_overviews.models import CourseOverview, SimulateCoursePublishConfig from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import SwitchedSignal # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order LOGGER_NAME = 'simulate_publish' diff --git a/openedx/core/djangoapps/content/course_overviews/migrations/0001_initial.py b/openedx/core/djangoapps/content/course_overviews/migrations/0001_initial.py index 4b6926999e46..bedf76d1ad27 100644 --- a/openedx/core/djangoapps/content/course_overviews/migrations/0001_initial.py +++ b/openedx/core/djangoapps/content/course_overviews/migrations/0001_initial.py @@ -1,6 +1,6 @@ -from django.db import migrations, models import django.utils.timezone import model_utils.fields +from django.db import migrations, models from opaque_keys.edx.django.models import CourseKeyField, UsageKeyField diff --git a/openedx/core/djangoapps/content/course_overviews/migrations/0003_courseoverviewgeneratedhistory.py b/openedx/core/djangoapps/content/course_overviews/migrations/0003_courseoverviewgeneratedhistory.py index c6c5a001081e..77609054991e 100644 --- a/openedx/core/djangoapps/content/course_overviews/migrations/0003_courseoverviewgeneratedhistory.py +++ b/openedx/core/djangoapps/content/course_overviews/migrations/0003_courseoverviewgeneratedhistory.py @@ -1,6 +1,6 @@ -from django.db import migrations, models import django.utils.timezone import model_utils.fields +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content/course_overviews/migrations/0006_courseoverviewimageset.py b/openedx/core/djangoapps/content/course_overviews/migrations/0006_courseoverviewimageset.py index b8cc1577aaea..ade8bc1c8c3d 100644 --- a/openedx/core/djangoapps/content/course_overviews/migrations/0006_courseoverviewimageset.py +++ b/openedx/core/djangoapps/content/course_overviews/migrations/0006_courseoverviewimageset.py @@ -1,6 +1,6 @@ -from django.db import migrations, models import django.utils.timezone import model_utils.fields +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content/course_overviews/migrations/0007_courseoverviewimageconfig.py b/openedx/core/djangoapps/content/course_overviews/migrations/0007_courseoverviewimageconfig.py index ed69e2ce4d27..63df02140af4 100644 --- a/openedx/core/djangoapps/content/course_overviews/migrations/0007_courseoverviewimageconfig.py +++ b/openedx/core/djangoapps/content/course_overviews/migrations/0007_courseoverviewimageconfig.py @@ -1,6 +1,6 @@ -from django.db import migrations, models import django.db.models.deletion from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content/course_overviews/migrations/0009_readd_facebook_url.py b/openedx/core/djangoapps/content/course_overviews/migrations/0009_readd_facebook_url.py index 37bd76548e9e..533cc732bb98 100644 --- a/openedx/core/djangoapps/content/course_overviews/migrations/0009_readd_facebook_url.py +++ b/openedx/core/djangoapps/content/course_overviews/migrations/0009_readd_facebook_url.py @@ -1,4 +1,5 @@ -from django.db import migrations, models, connection +from django.db import connection, migrations, models + def table_description(): """Handle MySQL/Postgres vs SQLite compatibility for table introspection""" diff --git a/openedx/core/djangoapps/content/course_overviews/migrations/0015_historicalcourseoverview.py b/openedx/core/djangoapps/content/course_overviews/migrations/0015_historicalcourseoverview.py index ef41464fa91f..418de6514a1b 100644 --- a/openedx/core/djangoapps/content/course_overviews/migrations/0015_historicalcourseoverview.py +++ b/openedx/core/djangoapps/content/course_overviews/migrations/0015_historicalcourseoverview.py @@ -1,13 +1,13 @@ # Generated by Django 1.11.20 on 2019-05-30 21:13 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields import opaque_keys.edx.django.models import simple_history.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content/course_overviews/migrations/0016_simulatecoursepublishconfig.py b/openedx/core/djangoapps/content/course_overviews/migrations/0016_simulatecoursepublishconfig.py index ad802b13463f..692307d79f80 100644 --- a/openedx/core/djangoapps/content/course_overviews/migrations/0016_simulatecoursepublishconfig.py +++ b/openedx/core/djangoapps/content/course_overviews/migrations/0016_simulatecoursepublishconfig.py @@ -1,9 +1,9 @@ # Generated by Django 1.11.23 on 2019-09-16 10:45 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content/course_overviews/migrations/0030_backfill_new_catalog_courseruns.py b/openedx/core/djangoapps/content/course_overviews/migrations/0030_backfill_new_catalog_courseruns.py index 26e1e0d976b2..f12a6f2c391d 100644 --- a/openedx/core/djangoapps/content/course_overviews/migrations/0030_backfill_new_catalog_courseruns.py +++ b/openedx/core/djangoapps/content/course_overviews/migrations/0030_backfill_new_catalog_courseruns.py @@ -7,7 +7,8 @@ from django.conf import settings from django.db import migrations -from organizations.api import ensure_organization, exceptions as org_exceptions +from organizations.api import ensure_organization +from organizations.api import exceptions as org_exceptions log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/content/course_overviews/models.py b/openedx/core/djangoapps/content/course_overviews/models.py index 728f8d4398b6..190fc1a3ee0b 100644 --- a/openedx/core/djangoapps/content/course_overviews/models.py +++ b/openedx/core/djangoapps/content/course_overviews/models.py @@ -14,21 +14,20 @@ from django.conf import settings from django.db import models, transaction from django.db.models import Q -from django.db.models.signals import post_save, post_delete +from django.db.models.signals import post_delete, post_save from django.db.utils import IntegrityError from django.template import defaultfilters - from django.utils.functional import cached_property from model_utils.models import TimeStampedModel from opaque_keys.edx.django.models import CourseKeyField, UsageKeyField from simple_history.models import HistoricalRecords +from common.djangoapps.static_replace.models import AssetBaseUrlConfig from lms.djangoapps.courseware.model_data import FieldDataCache from openedx.core.djangoapps.catalog.models import CatalogIntegration from openedx.core.djangoapps.lang_pref.api import get_closest_released_language from openedx.core.djangoapps.models.course_details import CourseDetails -from openedx.core.lib.cache_utils import request_cached, RequestCache -from common.djangoapps.static_replace.models import AssetBaseUrlConfig +from openedx.core.lib.cache_utils import RequestCache, request_cached from xmodule import block_metadata_utils, course_metadata_utils # lint-amnesty, pylint: disable=wrong-import-order from xmodule.course_block import DEFAULT_START_DATE, CourseBlock # lint-amnesty, pylint: disable=wrong-import-order from xmodule.error_block import ErrorBlock # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/core/djangoapps/content/course_overviews/signals.py b/openedx/core/djangoapps/content/course_overviews/signals.py index 2add43c0e4e3..dba273550c8b 100644 --- a/openedx/core/djangoapps/content/course_overviews/signals.py +++ b/openedx/core/djangoapps/content/course_overviews/signals.py @@ -8,9 +8,9 @@ from django.db.models.signals import post_save from django.dispatch import Signal from django.dispatch.dispatcher import receiver - from openedx_catalog import api as catalog_api from openedx_catalog.models_api import CourseRun + from openedx.core.djangoapps.signals.signals import COURSE_CERT_DATE_CHANGE from xmodule.data import CertificatesDisplayBehaviors from xmodule.modulestore.django import SignalHandler diff --git a/openedx/core/djangoapps/content/course_overviews/tests/factories.py b/openedx/core/djangoapps/content/course_overviews/tests/factories.py index b7c1ca1b151a..818ac0e66535 100644 --- a/openedx/core/djangoapps/content/course_overviews/tests/factories.py +++ b/openedx/core/djangoapps/content/course_overviews/tests/factories.py @@ -1,10 +1,10 @@ # lint-amnesty, pylint: disable=missing-module-docstring -from datetime import timedelta import json +from datetime import timedelta -from django.utils import timezone import factory +from django.utils import timezone from factory.django import DjangoModelFactory from opaque_keys.edx.locator import CourseLocator diff --git a/openedx/core/djangoapps/content/course_overviews/tests/test_api.py b/openedx/core/djangoapps/content/course_overviews/tests/test_api.py index 568322f82d98..2a518fa1d7de 100644 --- a/openedx/core/djangoapps/content/course_overviews/tests/test_api.py +++ b/openedx/core/djangoapps/content/course_overviews/tests/test_api.py @@ -7,7 +7,6 @@ from opaque_keys.edx.keys import CourseKey from openedx.core.djangoapps.catalog.tests.factories import CourseRunFactory -from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.content.course_overviews.api import ( get_course_overview_or_404, get_course_overview_or_none, @@ -15,8 +14,11 @@ get_course_overviews_from_ids, get_pseudo_course_overview, ) +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) class TestCourseOverviewsApi(ModuleStoreTestCase): diff --git a/openedx/core/djangoapps/content/course_overviews/tests/test_course_overviews.py b/openedx/core/djangoapps/content/course_overviews/tests/test_course_overviews.py index dd43dcaee88b..86c97c553cfd 100644 --- a/openedx/core/djangoapps/content/course_overviews/tests/test_course_overviews.py +++ b/openedx/core/djangoapps/content/course_overviews/tests/test_course_overviews.py @@ -1,18 +1,17 @@ """ Tests for course_overviews app. """ +import datetime # lint-amnesty, pylint: disable=wrong-import-order +import itertools # lint-amnesty, pylint: disable=wrong-import-order import json +import math # lint-amnesty, pylint: disable=wrong-import-order import os from io import BytesIO from unittest import mock - -import pytest -import datetime # lint-amnesty, pylint: disable=wrong-import-order -import itertools # lint-amnesty, pylint: disable=wrong-import-order -import math # lint-amnesty, pylint: disable=wrong-import-order from zoneinfo import ZoneInfo import ddt +import pytest from django.conf import settings from django.db.utils import IntegrityError from django.test.utils import override_settings @@ -20,27 +19,32 @@ from opaque_keys.edx.keys import CourseKey from PIL import Image +from common.djangoapps.static_replace.models import AssetBaseUrlConfig from lms.djangoapps.certificates.api import get_active_web_certificate from openedx.core.djangoapps.catalog.tests.mixins import CatalogIntegrationMixin from openedx.core.djangoapps.dark_lang.models import DarkLangConfig from openedx.core.djangoapps.models.course_details import CourseDetails from openedx.core.djangolib.testing.utils import CacheIsolationTestCase from openedx.core.lib.courses import course_image_url -from common.djangoapps.static_replace.models import AssetBaseUrlConfig from xmodule.assetstore.assetmgr import AssetManager # lint-amnesty, pylint: disable=wrong-import-order from xmodule.contentstore.content import StaticContent # lint-amnesty, pylint: disable=wrong-import-order from xmodule.contentstore.django import contentstore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.course_metadata_utils import DEFAULT_START_DATE # lint-amnesty, pylint: disable=wrong-import-order from xmodule.course_block import ( # lint-amnesty, pylint: disable=wrong-import-order CATALOG_VISIBILITY_ABOUT, CATALOG_VISIBILITY_CATALOG_AND_ABOUT, - CATALOG_VISIBILITY_NONE + CATALOG_VISIBILITY_NONE, ) +from xmodule.course_metadata_utils import DEFAULT_START_DATE # lint-amnesty, pylint: disable=wrong-import-order from xmodule.error_block import ErrorBlock # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls_range # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + CourseFactory, + check_mongo_calls_range, +) from ..models import CourseOverview, CourseOverviewImageConfig, CourseOverviewImageSet, CourseOverviewTab from .factories import CourseOverviewFactory diff --git a/openedx/core/djangoapps/content/course_overviews/tests/test_signals.py b/openedx/core/djangoapps/content/course_overviews/tests/test_signals.py index ad071acaf9ae..a452009d32f0 100644 --- a/openedx/core/djangoapps/content/course_overviews/tests/test_signals.py +++ b/openedx/core/djangoapps/content/course_overviews/tests/test_signals.py @@ -4,19 +4,19 @@ import datetime -from unittest.mock import patch from collections import namedtuple +from unittest.mock import patch from zoneinfo import ZoneInfo -import pytest import ddt +import pytest from xmodule.data import CertificatesDisplayBehaviors from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import ( TEST_DATA_ONLY_SPLIT_MODULESTORE_DRAFT_PREFERRED, - ModuleStoreTestCase, ImmediateOnCommitMixin, + ModuleStoreTestCase, ) from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls diff --git a/openedx/core/djangoapps/content/course_overviews/tests/test_sync_with_openedx_catalog.py b/openedx/core/djangoapps/content/course_overviews/tests/test_sync_with_openedx_catalog.py index 88b37ecd7072..f6b638c2e3ed 100644 --- a/openedx/core/djangoapps/content/course_overviews/tests/test_sync_with_openedx_catalog.py +++ b/openedx/core/djangoapps/content/course_overviews/tests/test_sync_with_openedx_catalog.py @@ -3,7 +3,6 @@ """ import pytest - from openedx_catalog import api as catalog_api from openedx_catalog.models_api import CatalogCourse, CourseRun @@ -11,8 +10,8 @@ from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import ( TEST_DATA_ONLY_SPLIT_MODULESTORE_DRAFT_PREFERRED, - ModuleStoreTestCase, ImmediateOnCommitMixin, + ModuleStoreTestCase, ) from xmodule.modulestore.tests.factories import CourseFactory diff --git a/openedx/core/djangoapps/content/learning_sequences/admin.py b/openedx/core/djangoapps/content/learning_sequences/admin.py index 58ca0d3e713b..445037e838f9 100644 --- a/openedx/core/djangoapps/content/learning_sequences/admin.py +++ b/openedx/core/djangoapps/content/learning_sequences/admin.py @@ -1,17 +1,18 @@ """ Read-only Django Admin for viewing Learning Sequences and Outline data. """ +import json from datetime import datetime from enum import Enum -import json +import attr from django.contrib import admin from django.utils.html import format_html, format_html_join from django.utils.translation import gettext_lazy as _ from opaque_keys import OpaqueKey -import attr from openedx.core import types + from .api import get_content_errors, get_course_outline from .models import CourseContext, CourseSectionSequence diff --git a/openedx/core/djangoapps/content/learning_sequences/api/outlines.py b/openedx/core/djangoapps/content/learning_sequences/api/outlines.py index cd2b12d03f1c..429927c61ab1 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/outlines.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/outlines.py @@ -15,9 +15,11 @@ from opaque_keys import OpaqueKey from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import LibraryLocator + from openedx.core import types -from openedx.core.djangoapps.content.learning_sequences.api.processors.team_partition_groups \ - import TeamPartitionGroupsOutlineProcessor +from openedx.core.djangoapps.content.learning_sequences.api.processors.team_partition_groups import ( + TeamPartitionGroupsOutlineProcessor, +) from ..data import ( ContentErrorData, @@ -28,7 +30,7 @@ ExamData, UserCourseOutlineData, UserCourseOutlineDetailsData, - VisibilityData + VisibilityData, ) from ..models import ( ContentError, @@ -39,7 +41,7 @@ LearningContext, LearningSequence, PublishReport, - UserPartitionGroup + UserPartitionGroup, ) from .permissions import can_see_all_content from .processors.cohort_partition_groups import CohortPartitionGroupsOutlineProcessor diff --git a/openedx/core/djangoapps/content/learning_sequences/api/processors/base.py b/openedx/core/djangoapps/content/learning_sequences/api/processors/base.py index 72762667bfaf..ce5f543ac70b 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/processors/base.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/processors/base.py @@ -6,6 +6,7 @@ from datetime import datetime from opaque_keys.edx.keys import CourseKey # lint-amnesty, pylint: disable=unused-import + from openedx.core import types from ...data import CourseOutlineData diff --git a/openedx/core/djangoapps/content/learning_sequences/api/processors/content_gating.py b/openedx/core/djangoapps/content/learning_sequences/api/processors/content_gating.py index 9f86406dd971..521833f81cf0 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/processors/content_gating.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/processors/content_gating.py @@ -3,10 +3,10 @@ from datetime import datetime from opaque_keys.edx.keys import CourseKey -from openedx.core import types from common.djangoapps.student.models import EntranceExamConfiguration from common.djangoapps.util import milestones_helpers +from openedx.core import types from .base import OutlineProcessor diff --git a/openedx/core/djangoapps/content/learning_sequences/api/processors/enrollment.py b/openedx/core/djangoapps/content/learning_sequences/api/processors/enrollment.py index f91e5a510d43..b0068e665de0 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/processors/enrollment.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/processors/enrollment.py @@ -1,11 +1,11 @@ """ Simple OutlineProcessor that removes items based on Enrollment and course visibility setting. """ -from openedx.features.course_experience import COURSE_ENABLE_UNENROLLED_ACCESS_FLAG from common.djangoapps.student.models import CourseEnrollment +from openedx.features.course_experience import COURSE_ENABLE_UNENROLLED_ACCESS_FLAG -from .base import OutlineProcessor from ...data import CourseVisibility +from .base import OutlineProcessor class EnrollmentOutlineProcessor(OutlineProcessor): diff --git a/openedx/core/djangoapps/content/learning_sequences/api/processors/enrollment_track_partition_groups.py b/openedx/core/djangoapps/content/learning_sequences/api/processors/enrollment_track_partition_groups.py index b8587e0f71f9..88290c5a71bd 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/processors/enrollment_track_partition_groups.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/processors/enrollment_track_partition_groups.py @@ -4,16 +4,18 @@ from typing import Dict from opaque_keys.edx.keys import CourseKey -from openedx.core import types +from openedx.core import types from xmodule.partitions.enrollment_track_partition_generator import ( # lint-amnesty, pylint: disable=wrong-import-order - create_enrollment_track_partition_with_course_id + create_enrollment_track_partition_with_course_id, ) from xmodule.partitions.partitions import ( # lint-amnesty, pylint: disable=wrong-import-order ENROLLMENT_TRACK_PARTITION_ID, + Group, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.partitions.partitions_service import ( + get_user_partition_groups, # lint-amnesty, pylint: disable=wrong-import-order ) -from xmodule.partitions.partitions_service import get_user_partition_groups # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions import Group # lint-amnesty, pylint: disable=wrong-import-order from .base import OutlineProcessor diff --git a/openedx/core/djangoapps/content/learning_sequences/api/processors/milestones.py b/openedx/core/djangoapps/content/learning_sequences/api/processors/milestones.py index 688ad8125402..2f5eb2c34f6a 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/processors/milestones.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/processors/milestones.py @@ -2,6 +2,7 @@ import logging from django.contrib.auth import get_user_model + from common.djangoapps.util import milestones_helpers from .base import OutlineProcessor diff --git a/openedx/core/djangoapps/content/learning_sequences/api/processors/schedule.py b/openedx/core/djangoapps/content/learning_sequences/api/processors/schedule.py index 7d6e373b43e1..c75eef7028d3 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/processors/schedule.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/processors/schedule.py @@ -6,11 +6,11 @@ from datetime import datetime, timedelta from edx_when.api import get_dates_for_course -from opaque_keys.edx.keys import UsageKey, CourseKey # lint-amnesty, pylint: disable=unused-import -from openedx.core import types +from opaque_keys.edx.keys import CourseKey, UsageKey # lint-amnesty, pylint: disable=unused-import from common.djangoapps.student.auth import user_has_role from common.djangoapps.student.roles import CourseBetaTesterRole +from openedx.core import types from ...data import ScheduleData, ScheduleItemData, UserCourseOutlineData from .base import OutlineProcessor diff --git a/openedx/core/djangoapps/content/learning_sequences/api/processors/special_exams.py b/openedx/core/djangoapps/content/learning_sequences/api/processors/special_exams.py index 124b766a94a8..14f3b1152287 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/processors/special_exams.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/processors/special_exams.py @@ -12,16 +12,16 @@ import logging -from edx_proctoring.api import get_attempt_status_summary -from edx_proctoring.exceptions import ProctoredExamNotFoundException from django.conf import settings from django.contrib.auth import get_user_model from django.utils.translation import gettext as _ +from edx_proctoring.api import get_attempt_status_summary +from edx_proctoring.exceptions import ProctoredExamNotFoundException -from ...data import SpecialExamAttemptData, UserCourseOutlineData -from .base import OutlineProcessor from openedx.core.djangoapps.course_apps.toggles import exams_ida_enabled +from ...data import SpecialExamAttemptData, UserCourseOutlineData +from .base import OutlineProcessor User = get_user_model() log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/content/learning_sequences/api/processors/team_partition_groups.py b/openedx/core/djangoapps/content/learning_sequences/api/processors/team_partition_groups.py index d3a8f0058030..1dbc5d0bce8b 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/processors/team_partition_groups.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/processors/team_partition_groups.py @@ -9,7 +9,7 @@ from openedx.core import types from openedx.core.djangoapps.content.learning_sequences.api.processors.base import OutlineProcessor -from openedx.core.lib.teams_config import create_team_set_partitions_with_course_id, CONTENT_GROUPS_FOR_TEAMS +from openedx.core.lib.teams_config import CONTENT_GROUPS_FOR_TEAMS, create_team_set_partitions_with_course_id from xmodule.partitions.partitions import Group from xmodule.partitions.partitions_service import get_user_partition_groups diff --git a/openedx/core/djangoapps/content/learning_sequences/api/tests/test_data.py b/openedx/core/djangoapps/content/learning_sequences/api/tests/test_data.py index aaf1d2ba78d4..e8910fd87d35 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/tests/test_data.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/tests/test_data.py @@ -2,13 +2,11 @@ from datetime import datetime, timezone from unittest import TestCase +import attr import pytest from opaque_keys.edx.keys import CourseKey -import attr -from ...data import ( - CourseOutlineData, CourseSectionData, CourseLearningSequenceData, VisibilityData, CourseVisibility -) +from ...data import CourseLearningSequenceData, CourseOutlineData, CourseSectionData, CourseVisibility, VisibilityData class TestCourseOutlineData(TestCase): diff --git a/openedx/core/djangoapps/content/learning_sequences/api/tests/test_outlines.py b/openedx/core/djangoapps/content/learning_sequences/api/tests/test_outlines.py index 20effa6b16cd..ade5b32c4de3 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/tests/test_outlines.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/tests/test_outlines.py @@ -2,10 +2,13 @@ Top level API tests. Tests API public contracts only. Do not import/create/mock models for this app. """ -from datetime import datetime, timezone -from unittest.mock import patch, MagicMock import unittest +from datetime import datetime, timezone +from unittest.mock import MagicMock, patch +import attr +import ddt +import pytest from django.conf import settings from django.contrib.auth.models import AnonymousUser from django.db.models import signals @@ -14,25 +17,21 @@ from edx_when.api import set_dates_for_course from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import LibraryLocator -import attr -import ddt + +from common.djangoapps.course_modes.models import CourseMode +from common.djangoapps.course_modes.signals import update_masters_access_course +from common.djangoapps.student.auth import user_has_role +from common.djangoapps.student.roles import CourseBetaTesterRole +from common.djangoapps.student.tests.factories import BetaTesterFactory, UserFactory from lms.djangoapps.teams.tests.factories import CourseTeamFactory from openedx.core.djangoapps.content.learning_sequences.api.processors.team_partition_groups import ( TeamPartitionGroupsOutlineProcessor, ) -from openedx.core.djangolib.testing.utils import skip_unless_lms -import pytest - from openedx.core.djangoapps.course_apps.toggles import EXAMS_IDA from openedx.core.djangoapps.course_groups.models import CourseCohortsSettings, CourseUserGroupPartitionGroup from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory -from openedx.core.djangolib.testing.utils import CacheIsolationTestCase +from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms from openedx.features.course_experience import COURSE_ENABLE_UNENROLLED_ACCESS_FLAG -from common.djangoapps.course_modes.models import CourseMode -from common.djangoapps.course_modes.signals import update_masters_access_course -from common.djangoapps.student.auth import user_has_role -from common.djangoapps.student.roles import CourseBetaTesterRole -from common.djangoapps.student.tests.factories import BetaTesterFactory, UserFactory from xmodule.partitions.partitions import ( # lint-amnesty, pylint: disable=wrong-import-order ENROLLMENT_TRACK_PARTITION_ID, ) @@ -45,7 +44,6 @@ CourseVisibility, ExamData, VisibilityData, - ) from ..outlines import ( get_content_errors, diff --git a/openedx/core/djangoapps/content/learning_sequences/data.py b/openedx/core/djangoapps/content/learning_sequences/data.py index c13b451490ab..78d37707862b 100644 --- a/openedx/core/djangoapps/content/learning_sequences/data.py +++ b/openedx/core/djangoapps/content/learning_sequences/data.py @@ -27,6 +27,7 @@ import attr from opaque_keys.edx.keys import CourseKey, UsageKey + from openedx.core import types log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/content/learning_sequences/migrations/0001_initial.py b/openedx/core/djangoapps/content/learning_sequences/migrations/0001_initial.py index 665a8082d979..1830e06d22f9 100644 --- a/openedx/core/djangoapps/content/learning_sequences/migrations/0001_initial.py +++ b/openedx/core/djangoapps/content/learning_sequences/migrations/0001_initial.py @@ -6,8 +6,7 @@ import django.utils.timezone import model_utils.fields import opaque_keys.edx.django.models -from django.db import connection -from django.db import migrations, models +from django.db import connection, migrations, models def run_before_migrate(migrations, db_engine): diff --git a/openedx/core/djangoapps/content/learning_sequences/migrations/0003_create_course_context_for_course_specific_models.py b/openedx/core/djangoapps/content/learning_sequences/migrations/0003_create_course_context_for_course_specific_models.py index ca7ece7c4220..2287c57c926d 100644 --- a/openedx/core/djangoapps/content/learning_sequences/migrations/0003_create_course_context_for_course_specific_models.py +++ b/openedx/core/djangoapps/content/learning_sequences/migrations/0003_create_course_context_for_course_specific_models.py @@ -1,9 +1,9 @@ # Generated by Django 2.2.14 on 2020-07-22 18:27 -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content/learning_sequences/migrations/0007_coursesequenceexam.py b/openedx/core/djangoapps/content/learning_sequences/migrations/0007_coursesequenceexam.py index a3081bae0aea..c8dde65dca66 100644 --- a/openedx/core/djangoapps/content/learning_sequences/migrations/0007_coursesequenceexam.py +++ b/openedx/core/djangoapps/content/learning_sequences/migrations/0007_coursesequenceexam.py @@ -1,9 +1,9 @@ # Generated by Django 2.2.16 on 2020-09-30 07:14 -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content/learning_sequences/migrations/0009_contenterror_publishreport.py b/openedx/core/djangoapps/content/learning_sequences/migrations/0009_contenterror_publishreport.py index 1c7135a84713..b586bb5aed17 100644 --- a/openedx/core/djangoapps/content/learning_sequences/migrations/0009_contenterror_publishreport.py +++ b/openedx/core/djangoapps/content/learning_sequences/migrations/0009_contenterror_publishreport.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.19 on 2021-03-12 16:31 -from django.db import migrations, models import django.db.models.deletion import opaque_keys.edx.django.models +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content/learning_sequences/migrations/0013_through_model_for_user_partition_groups_1.py b/openedx/core/djangoapps/content/learning_sequences/migrations/0013_through_model_for_user_partition_groups_1.py index 23ad1b0cf381..1c8c8ddd0af5 100644 --- a/openedx/core/djangoapps/content/learning_sequences/migrations/0013_through_model_for_user_partition_groups_1.py +++ b/openedx/core/djangoapps/content/learning_sequences/migrations/0013_through_model_for_user_partition_groups_1.py @@ -1,7 +1,7 @@ # Generated by Django 2.2.24 on 2021-06-14 22:04 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content/learning_sequences/models.py b/openedx/core/djangoapps/content/learning_sequences/models.py index 877ee084a567..c03074b91bf5 100644 --- a/openedx/core/djangoapps/content/learning_sequences/models.py +++ b/openedx/core/djangoapps/content/learning_sequences/models.py @@ -41,10 +41,11 @@ from django.db import models from model_utils.models import TimeStampedModel - from opaque_keys.edx.django.models import ( # lint-amnesty, pylint: disable=unused-import - LearningContextKeyField, UsageKeyField + LearningContextKeyField, + UsageKeyField, ) + from .data import CourseVisibility diff --git a/openedx/core/djangoapps/content/learning_sequences/tests/test_views.py b/openedx/core/djangoapps/content/learning_sequences/tests/test_views.py index 4cd8bf0c7df8..c56bb0474903 100644 --- a/openedx/core/djangoapps/content/learning_sequences/tests/test_views.py +++ b/openedx/core/djangoapps/content/learning_sequences/tests/test_views.py @@ -17,7 +17,7 @@ import ddt from opaque_keys.edx.keys import CourseKey -from rest_framework.test import APITestCase, APIClient +from rest_framework.test import APIClient, APITestCase from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole diff --git a/openedx/core/djangoapps/content/learning_sequences/urls.py b/openedx/core/djangoapps/content/learning_sequences/urls.py index cf55533358b6..b175b2473b05 100644 --- a/openedx/core/djangoapps/content/learning_sequences/urls.py +++ b/openedx/core/djangoapps/content/learning_sequences/urls.py @@ -1,8 +1,8 @@ # lint-amnesty, pylint: disable=missing-module-docstring from django.urls import path -from .views import CourseOutlineView +from .views import CourseOutlineView urlpatterns = [ path('v1/course_outline/', CourseOutlineView.as_view(), diff --git a/openedx/core/djangoapps/content/learning_sequences/views.py b/openedx/core/djangoapps/content/learning_sequences/views.py index 25f078d9f7a8..7bd453ca1d42 100644 --- a/openedx/core/djangoapps/content/learning_sequences/views.py +++ b/openedx/core/djangoapps/content/learning_sequences/views.py @@ -2,8 +2,8 @@ The views.py for this app is intentionally thin, and only exists to translate user input/output to and from the business logic in the `api` package. """ -from datetime import datetime, timezone import logging +from datetime import datetime, timezone from django.conf import settings from django.contrib.auth import get_user_model diff --git a/openedx/core/djangoapps/content/search/api.py b/openedx/core/djangoapps/content/search/api.py index d997b28ed1cb..1d7b01c30d39 100644 --- a/openedx/core/djangoapps/content/search/api.py +++ b/openedx/core/djangoapps/content/search/api.py @@ -20,11 +20,7 @@ from meilisearch.models.task import TaskInfo from opaque_keys import OpaqueKey from opaque_keys.edx.keys import CourseKey, UsageKey -from opaque_keys.edx.locator import ( - LibraryCollectionLocator, - LibraryContainerLocator, - LibraryLocatorV2, -) +from opaque_keys.edx.locator import LibraryCollectionLocator, LibraryContainerLocator, LibraryLocatorV2 from openedx_content import api as content_api from openedx_content import models_api as content_models from rest_framework.request import Request @@ -37,7 +33,7 @@ INDEX_FILTERABLE_ATTRIBUTES, INDEX_RANKING_RULES, INDEX_SEARCHABLE_ATTRIBUTES, - INDEX_SORTABLE_ATTRIBUTES + INDEX_SORTABLE_ATTRIBUTES, ) from openedx.core.djangoapps.content.search.models import IncrementalIndexCompleted, get_access_ids_for_request from openedx.core.djangoapps.content_libraries import api as lib_api @@ -48,13 +44,13 @@ Fields, meili_id_from_opaque_key, searchable_doc_collections, + searchable_doc_containers, searchable_doc_for_collection, searchable_doc_for_container, searchable_doc_for_course_block, - searchable_doc_for_library_block, searchable_doc_for_key, + searchable_doc_for_library_block, searchable_doc_tags, - searchable_doc_containers, ) log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/content/search/documents.py b/openedx/core/djangoapps/content/search/documents.py index 11408f2e6f43..b986966ec42c 100644 --- a/openedx/core/djangoapps/content/search/documents.py +++ b/openedx/core/djangoapps/content/search/documents.py @@ -8,7 +8,7 @@ from django.core.exceptions import ObjectDoesNotExist from django.utils.text import slugify -from opaque_keys.edx.keys import ContainerKey, LearningContextKey, UsageKey, OpaqueKey +from opaque_keys.edx.keys import ContainerKey, LearningContextKey, OpaqueKey, UsageKey from opaque_keys.edx.locator import LibraryCollectionLocator, LibraryContainerLocator from openedx_content import api as content_api from openedx_content.models_api import Collection, Section, Subsection, Unit diff --git a/openedx/core/djangoapps/content/search/index_config.py b/openedx/core/djangoapps/content/search/index_config.py index 8b96adc8b4db..c4fc01e98933 100644 --- a/openedx/core/djangoapps/content/search/index_config.py +++ b/openedx/core/djangoapps/content/search/index_config.py @@ -1,7 +1,6 @@ """Configuration for the search index.""" from .documents import Fields - INDEX_DISTINCT_ATTRIBUTE = "usage_key" # Mark which attributes can be used for filtering/faceted search: diff --git a/openedx/core/djangoapps/content/search/migrations/0002_incrementalindexcompleted.py b/openedx/core/djangoapps/content/search/migrations/0002_incrementalindexcompleted.py index a316c35a7dfe..60266dfd5d21 100644 --- a/openedx/core/djangoapps/content/search/migrations/0002_incrementalindexcompleted.py +++ b/openedx/core/djangoapps/content/search/migrations/0002_incrementalindexcompleted.py @@ -1,7 +1,7 @@ # Generated by Django 4.2.16 on 2024-11-15 12:40 -from django.db import migrations, models import opaque_keys.edx.django.models +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content/search/tests/test_api.py b/openedx/core/djangoapps/content/search/tests/test_api.py index 27a8201330f7..e8f345f9c410 100644 --- a/openedx/core/djangoapps/content/search/tests/test_api.py +++ b/openedx/core/djangoapps/content/search/tests/test_api.py @@ -4,33 +4,31 @@ from __future__ import annotations import copy - from datetime import datetime, timezone from unittest.mock import MagicMock, Mock, call, patch -from opaque_keys.edx.keys import UsageKey -from opaque_keys.edx.locator import LibraryCollectionLocator, LibraryContainerLocator -from openedx_content import models_api as content_models import ddt import pytest from django.test import override_settings from freezegun import freeze_time from meilisearch.errors import MeilisearchApiError +from opaque_keys.edx.keys import UsageKey +from opaque_keys.edx.locator import LibraryCollectionLocator, LibraryContainerLocator from openedx_content import api as content_api +from openedx_content import models_api as content_models from organizations.tests.factories import OrganizationFactory from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.content.course_overviews.api import CourseOverview from openedx.core.djangoapps.content_libraries import api as library_api from openedx.core.djangoapps.content_tagging import api as tagging_api -from openedx.core.djangoapps.content.course_overviews.api import CourseOverview from openedx.core.djangolib.testing.utils import skip_unless_cms from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase - try: # This import errors in the lms because content.search is not an installed app there. from .. import api - from ..models import SearchAccess, IncrementalIndexCompleted + from ..models import IncrementalIndexCompleted, SearchAccess except RuntimeError: SearchAccess = {} diff --git a/openedx/core/djangoapps/content/search/tests/test_documents.py b/openedx/core/djangoapps/content/search/tests/test_documents.py index bd155a3b3b8f..a580adf8ec01 100644 --- a/openedx/core/djangoapps/content/search/tests/test_documents.py +++ b/openedx/core/djangoapps/content/search/tests/test_documents.py @@ -1,10 +1,10 @@ """ Tests for the Studio content search documents (what gets stored in the index) """ -import ddt from dataclasses import replace from datetime import datetime, timezone +import ddt from freezegun import freeze_time from opaque_keys.edx.locator import LibraryCollectionLocator, LibraryContainerLocator from openedx_content import api as content_api diff --git a/openedx/core/djangoapps/content/search/tests/test_handlers.py b/openedx/core/djangoapps/content/search/tests/test_handlers.py index 17f5962f90dd..462d4770cd2f 100644 --- a/openedx/core/djangoapps/content/search/tests/test_handlers.py +++ b/openedx/core/djangoapps/content/search/tests/test_handlers.py @@ -13,11 +13,10 @@ from openedx.core.djangolib.testing.utils import skip_unless_cms from xmodule.modulestore.tests.django_utils import ( TEST_DATA_SPLIT_MODULESTORE, - ModuleStoreTestCase, ImmediateOnCommitMixin, + ModuleStoreTestCase, ) - try: # This import errors in the lms because content.search is not an installed app there. from .. import api diff --git a/openedx/core/djangoapps/content/search/urls.py b/openedx/core/djangoapps/content/search/urls.py index c69be33d5bb0..fe38d83f5ef4 100644 --- a/openedx/core/djangoapps/content/search/urls.py +++ b/openedx/core/djangoapps/content/search/urls.py @@ -5,7 +5,6 @@ from .views import StudioSearchView - urlpatterns = [ path('api/content_search/v2/studio/', StudioSearchView.as_view(), name='studio_content_search') ] diff --git a/openedx/core/djangoapps/content_libraries/api/__init__.py b/openedx/core/djangoapps/content_libraries/api/__init__.py index 5f7db8b17f72..b53e79ecf4de 100644 --- a/openedx/core/djangoapps/content_libraries/api/__init__.py +++ b/openedx/core/djangoapps/content_libraries/api/__init__.py @@ -1,12 +1,12 @@ """ Python API for working with content libraries """ +from . import permissions from .block_metadata import * +from .blocks import * from .collections import * from .container_metadata import * from .containers import * from .courseware_import import * from .exceptions import * from .libraries import * -from .blocks import * -from . import permissions diff --git a/openedx/core/djangoapps/content_libraries/api/block_metadata.py b/openedx/core/djangoapps/content_libraries/api/block_metadata.py index f117d2762949..2595830beeaf 100644 --- a/openedx/core/djangoapps/content_libraries/api/block_metadata.py +++ b/openedx/core/djangoapps/content_libraries/api/block_metadata.py @@ -2,14 +2,13 @@ Content libraries data classes related to XBlocks/Components. """ from __future__ import annotations + from dataclasses import dataclass from django.utils.translation import gettext as _ from opaque_keys.edx.locator import LibraryUsageLocatorV2 -from .libraries import ( - library_component_usage_key, - PublishableItem, -) + +from .libraries import PublishableItem, library_component_usage_key # The public API is only the following symbols: __all__ = [ diff --git a/openedx/core/djangoapps/content_libraries/api/blocks.py b/openedx/core/djangoapps/content_libraries/api/blocks.py index c8a005f94094..8ee865f8f45b 100644 --- a/openedx/core/djangoapps/content_libraries/api/blocks.py +++ b/openedx/core/djangoapps/content_libraries/api/blocks.py @@ -4,6 +4,7 @@ These methods don't enforce permissions (only the REST APIs do). """ from __future__ import annotations + import logging import mimetypes from datetime import datetime, timezone @@ -20,13 +21,15 @@ from django.utils.translation import gettext as _ from lxml import etree from opaque_keys import InvalidKeyError -from opaque_keys.edx.locator import LibraryContainerLocator, LibraryLocatorV2, LibraryUsageLocatorV2 from opaque_keys.edx.keys import LearningContextKey, UsageKeyV2 +from opaque_keys.edx.locator import LibraryContainerLocator, LibraryLocatorV2, LibraryUsageLocatorV2 +from openedx_content import api as content_api +from openedx_content.models_api import Collection, Component, ComponentVersion, Container, LearningPackage, MediaType from openedx_events.content_authoring.data import ( ContentObjectChangedData, LibraryBlockData, LibraryCollectionData, - LibraryContainerData + LibraryContainerData, ) from openedx_events.content_authoring.signals import ( CONTENT_OBJECT_ASSOCIATIONS_CHANGED, @@ -34,42 +37,37 @@ LIBRARY_BLOCK_DELETED, LIBRARY_BLOCK_UPDATED, LIBRARY_COLLECTION_UPDATED, - LIBRARY_CONTAINER_UPDATED -) -from openedx_content import api as content_api -from openedx_content.models_api import ( - Component, ComponentVersion, LearningPackage, MediaType, - Container, Collection + LIBRARY_CONTAINER_UPDATED, ) from xblock.core import XBlock from openedx.core.djangoapps.xblock.api import ( get_component_from_usage_key, get_xblock_app_config, - xblock_type_display_name + xblock_type_display_name, ) from openedx.core.types import User as UserType +from .. import tasks from ..models import ContentLibrary -from .exceptions import ( - BlockLimitReachedError, - ContentLibraryBlockNotFound, - IncompatibleTypesError, - InvalidNameError, - LibraryBlockAlreadyExists, -) from .block_metadata import LibraryXBlockMetadata, LibraryXBlockStaticFile +from .collections import library_collection_locator +from .container_metadata import container_subclass_for_olx_tag from .containers import ( + ContainerMetadata, create_container, get_container, get_containers_contains_item, update_container_children, - ContainerMetadata, ) -from .container_metadata import container_subclass_for_olx_tag -from .collections import library_collection_locator +from .exceptions import ( + BlockLimitReachedError, + ContentLibraryBlockNotFound, + IncompatibleTypesError, + InvalidNameError, + LibraryBlockAlreadyExists, +) from .libraries import PublishableItem -from .. import tasks # This content_libraries API is sometimes imported in the LMS (should we prevent that?), but the content_staging app # cannot be. For now we only need this one type import at module scope, so only import it during type checks. diff --git a/openedx/core/djangoapps/content_libraries/api/collections.py b/openedx/core/djangoapps/content_libraries/api/collections.py index ad441c01dace..9d011bdae363 100644 --- a/openedx/core/djangoapps/content_libraries/api/collections.py +++ b/openedx/core/djangoapps/content_libraries/api/collections.py @@ -6,10 +6,10 @@ from opaque_keys import OpaqueKey from opaque_keys.edx.keys import BlockTypeKey, UsageKeyV2 from opaque_keys.edx.locator import LibraryCollectionLocator, LibraryContainerLocator, LibraryLocatorV2 -from openedx_events.content_authoring.data import LibraryCollectionData -from openedx_events.content_authoring.signals import LIBRARY_COLLECTION_UPDATED from openedx_content import api as content_api from openedx_content.models_api import Collection, Component, PublishableEntity +from openedx_events.content_authoring.data import LibraryCollectionData +from openedx_events.content_authoring.signals import LIBRARY_COLLECTION_UPDATED from ..models import ContentLibrary from .exceptions import ( diff --git a/openedx/core/djangoapps/content_libraries/api/container_metadata.py b/openedx/core/djangoapps/content_libraries/api/container_metadata.py index b0b84a43108a..9ef548c1bbef 100644 --- a/openedx/core/djangoapps/content_libraries/api/container_metadata.py +++ b/openedx/core/djangoapps/content_libraries/api/container_metadata.py @@ -4,20 +4,21 @@ from __future__ import annotations -from dataclasses import dataclass, field as dataclass_field +from dataclasses import dataclass +from dataclasses import field as dataclass_field from enum import Enum -from django.db.models import QuerySet +from django.db.models import QuerySet from opaque_keys.edx.locator import LibraryContainerLocator, LibraryLocatorV2, LibraryUsageLocatorV2 from openedx_content import api as content_api from openedx_content.models_api import ( Component, Container, - Unit, - Subsection, - Section, PublishableEntity, PublishableEntityMixin, + Section, + Subsection, + Unit, ) from openedx.core.djangoapps.content_tagging.api import get_object_tag_counts diff --git a/openedx/core/djangoapps/content_libraries/api/containers.py b/openedx/core/djangoapps/content_libraries/api/containers.py index b756b07842cf..c1618e485d8c 100644 --- a/openedx/core/djangoapps/content_libraries/api/containers.py +++ b/openedx/core/djangoapps/content_libraries/api/containers.py @@ -4,19 +4,17 @@ from __future__ import annotations -from datetime import datetime, timezone import logging -from uuid import uuid4 import typing +from datetime import datetime, timezone +from uuid import uuid4 from django.db import transaction from django.utils.text import slugify from opaque_keys.edx.locator import LibraryContainerLocator, LibraryLocatorV2, LibraryUsageLocatorV2 -from openedx_events.content_authoring.data import ( - ContentObjectChangedData, - LibraryCollectionData, - LibraryContainerData, -) +from openedx_content import api as content_api +from openedx_content.models_api import Container, Unit +from openedx_events.content_authoring.data import ContentObjectChangedData, LibraryCollectionData, LibraryContainerData from openedx_events.content_authoring.signals import ( CONTENT_OBJECT_ASSOCIATIONS_CHANGED, LIBRARY_COLLECTION_UPDATED, @@ -24,24 +22,22 @@ LIBRARY_CONTAINER_DELETED, LIBRARY_CONTAINER_UPDATED, ) -from openedx_content import api as content_api -from openedx_content.models_api import Container, Unit + from openedx.core.djangoapps.content_libraries.api.collections import library_collection_locator from .. import tasks from ..models import ContentLibrary from .block_metadata import LibraryXBlockMetadata from .container_metadata import ( + LIBRARY_ALLOWED_CONTAINER_TYPES, ContainerHierarchy, ContainerMetadata, - library_container_locator, get_container_from_key, get_entity_from_key, - LIBRARY_ALLOWED_CONTAINER_TYPES, + library_container_locator, ) from .serializers import ContainerSerializer - if typing.TYPE_CHECKING: from openedx.core.djangoapps.content_staging.api import UserClipboardData diff --git a/openedx/core/djangoapps/content_libraries/api/courseware_import.py b/openedx/core/djangoapps/content_libraries/api/courseware_import.py index 943f809840c6..f90b2f2cce55 100644 --- a/openedx/core/djangoapps/content_libraries/api/courseware_import.py +++ b/openedx/core/djangoapps/content_libraries/api/courseware_import.py @@ -9,20 +9,17 @@ through RESTful APIs (see :mod:`.views`). """ import abc -import collections import base64 +import collections import hashlib import logging -from django.conf import settings import requests - -from opaque_keys.edx.locator import ( - LibraryUsageLocatorV2, - LibraryLocator as LibraryLocatorV1, -) -from opaque_keys.edx.keys import UsageKey +from django.conf import settings from edx_rest_api_client.client import OAuthAPIClient +from opaque_keys.edx.keys import UsageKey +from opaque_keys.edx.locator import LibraryLocator as LibraryLocatorV1 +from opaque_keys.edx.locator import LibraryUsageLocatorV2 from openedx.core.lib.xblock_serializer.api import serialize_modulestore_block_for_openedx_content from xmodule.modulestore.django import modulestore @@ -33,8 +30,8 @@ LibraryBlockAlreadyExists, add_library_block_static_asset_file, create_library_block, - get_library_block_static_asset_files, get_library_block, + get_library_block_static_asset_files, set_library_block_olx, ) from .libraries import publish_changes diff --git a/openedx/core/djangoapps/content_libraries/api/exceptions.py b/openedx/core/djangoapps/content_libraries/api/exceptions.py index d7196cb875ab..1fb555aaded0 100644 --- a/openedx/core/djangoapps/content_libraries/api/exceptions.py +++ b/openedx/core/djangoapps/content_libraries/api/exceptions.py @@ -2,13 +2,11 @@ Exceptions that can be thrown by the Content Libraries API. """ from django.db import IntegrityError - from openedx_content.models_api import Collection, Container from xblock.exceptions import XBlockNotFoundError from ..models import ContentLibrary - # The public API is only the following symbols: __all__ = [ "ContentLibraryNotFound", diff --git a/openedx/core/djangoapps/content_libraries/api/libraries.py b/openedx/core/djangoapps/content_libraries/api/libraries.py index fce2ce5ec4f6..43a1e9208658 100644 --- a/openedx/core/djangoapps/content_libraries/api/libraries.py +++ b/openedx/core/djangoapps/content_libraries/api/libraries.py @@ -58,14 +58,14 @@ from openedx_authz import api as authz_api from openedx_authz.api import assign_role_to_user_in_scope from openedx_authz.constants import permissions as authz_permissions +from openedx_content import api as content_api +from openedx_content.models_api import Component, LearningPackage from openedx_events.content_authoring.data import ContentLibraryData from openedx_events.content_authoring.signals import ( CONTENT_LIBRARY_CREATED, CONTENT_LIBRARY_DELETED, CONTENT_LIBRARY_UPDATED, ) -from openedx_content import api as content_api -from openedx_content.models_api import Component, LearningPackage from organizations.models import Organization from user_tasks.models import UserTaskArtifact, UserTaskStatus from xblock.core import XBlock diff --git a/openedx/core/djangoapps/content_libraries/api/permissions.py b/openedx/core/djangoapps/content_libraries/api/permissions.py index b3949985cd5c..3bfd09d1d8db 100644 --- a/openedx/core/djangoapps/content_libraries/api/permissions.py +++ b/openedx/core/djangoapps/content_libraries/api/permissions.py @@ -13,7 +13,7 @@ CAN_EDIT_THIS_CONTENT_LIBRARY_TEAM, CAN_LEARN_FROM_THIS_CONTENT_LIBRARY, CAN_VIEW_THIS_CONTENT_LIBRARY, - CAN_VIEW_THIS_CONTENT_LIBRARY_TEAM + CAN_VIEW_THIS_CONTENT_LIBRARY_TEAM, ) LEGACY_LIB_PERMISSIONS = frozenset({ diff --git a/openedx/core/djangoapps/content_libraries/api/serializers.py b/openedx/core/djangoapps/content_libraries/api/serializers.py index 35fe13c26f3c..a4f9b376763e 100644 --- a/openedx/core/djangoapps/content_libraries/api/serializers.py +++ b/openedx/core/djangoapps/content_libraries/api/serializers.py @@ -2,12 +2,11 @@ Serializer classes for containers """ from lxml import etree - from openedx_content import api as content_api +from openedx.core.djangoapps.content_tagging.api import TagValuesByObjectIdDict, get_all_object_tags from openedx.core.djangoapps.xblock import api as xblock_api from openedx.core.lib.xblock_serializer.api import StaticFile, XBlockSerializer -from openedx.core.djangoapps.content_tagging.api import TagValuesByObjectIdDict, get_all_object_tags from . import containers as container_api diff --git a/openedx/core/djangoapps/content_libraries/apps.py b/openedx/core/djangoapps/content_libraries/apps.py index abd9a7ec2bfe..336422705473 100644 --- a/openedx/core/djangoapps/content_libraries/apps.py +++ b/openedx/core/djangoapps/content_libraries/apps.py @@ -5,7 +5,7 @@ from django.apps import AppConfig -from edx_django_utils.plugins import PluginURLs, PluginSettings +from edx_django_utils.plugins import PluginSettings, PluginURLs from openedx.core.djangoapps.plugins.constants import ProjectType diff --git a/openedx/core/djangoapps/content_libraries/auth.py b/openedx/core/djangoapps/content_libraries/auth.py index 1b35350cb396..9532f3d53b76 100644 --- a/openedx/core/djangoapps/content_libraries/auth.py +++ b/openedx/core/djangoapps/content_libraries/auth.py @@ -12,7 +12,6 @@ from .models import LtiProfile - log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/content_libraries/constants.py b/openedx/core/djangoapps/content_libraries/constants.py index a01e0fbdda91..cb25a9db2e35 100644 --- a/openedx/core/djangoapps/content_libraries/constants.py +++ b/openedx/core/djangoapps/content_libraries/constants.py @@ -1,7 +1,6 @@ """ Constants used for the content libraries. """ from django.utils.translation import gettext_lazy as _ - # These are all the licenses we support so far. ALL_RIGHTS_RESERVED = '' CC_4_BY = 'CC:4.0:BY' diff --git a/openedx/core/djangoapps/content_libraries/library_context.py b/openedx/core/djangoapps/content_libraries/library_context.py index 1b693956ccd5..bd91a3f89250 100644 --- a/openedx/core/djangoapps/content_libraries/library_context.py +++ b/openedx/core/djangoapps/content_libraries/library_context.py @@ -4,13 +4,12 @@ import logging from django.core.exceptions import PermissionDenied -from rest_framework.exceptions import NotFound - -from openedx_events.content_authoring.data import LibraryBlockData, LibraryContainerData -from openedx_events.content_authoring.signals import LIBRARY_BLOCK_UPDATED, LIBRARY_CONTAINER_UPDATED from opaque_keys.edx.keys import UsageKeyV2 -from opaque_keys.edx.locator import LibraryUsageLocatorV2, LibraryLocatorV2 +from opaque_keys.edx.locator import LibraryLocatorV2, LibraryUsageLocatorV2 from openedx_content import api as content_api +from openedx_events.content_authoring.data import LibraryBlockData, LibraryContainerData +from openedx_events.content_authoring.signals import LIBRARY_BLOCK_UPDATED, LIBRARY_CONTAINER_UPDATED +from rest_framework.exceptions import NotFound from openedx.core.djangoapps.content_libraries import api, permissions from openedx.core.djangoapps.content_libraries.models import ContentLibrary diff --git a/openedx/core/djangoapps/content_libraries/management/commands/content_libraries_import.py b/openedx/core/djangoapps/content_libraries/management/commands/content_libraries_import.py index 3f8270957f41..cddabdcd687c 100644 --- a/openedx/core/djangoapps/content_libraries/management/commands/content_libraries_import.py +++ b/openedx/core/djangoapps/content_libraries/management/commands/content_libraries_import.py @@ -7,11 +7,10 @@ from django.conf import settings from django.core.management import BaseCommand, CommandError - from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import LibraryLocatorV2 -from openedx.core.djangoapps.content_libraries import api as contentlib_api +from openedx.core.djangoapps.content_libraries import api as contentlib_api log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/content_libraries/migrations/0001_initial.py b/openedx/core/djangoapps/content_libraries/migrations/0001_initial.py index d36a4406c1ae..a5632c9706a9 100644 --- a/openedx/core/djangoapps/content_libraries/migrations/0001_initial.py +++ b/openedx/core/djangoapps/content_libraries/migrations/0001_initial.py @@ -1,9 +1,9 @@ # Generated by Django 1.11.23 on 2019-08-28 20:27 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content_libraries/migrations/0005_contentlibraryblockimporttask.py b/openedx/core/djangoapps/content_libraries/migrations/0005_contentlibraryblockimporttask.py index ab852cf14c7e..f31307ef2322 100644 --- a/openedx/core/djangoapps/content_libraries/migrations/0005_contentlibraryblockimporttask.py +++ b/openedx/core/djangoapps/content_libraries/migrations/0005_contentlibraryblockimporttask.py @@ -1,7 +1,7 @@ # Generated by Django 2.2.24 on 2021-07-16 23:20 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models from opaque_keys.edx.django.models import CourseKeyField diff --git a/openedx/core/djangoapps/content_libraries/migrations/0005_ltigradedresource_ltiprofile.py b/openedx/core/djangoapps/content_libraries/migrations/0005_ltigradedresource_ltiprofile.py index 71aa56683e5a..6066b533a5d8 100644 --- a/openedx/core/djangoapps/content_libraries/migrations/0005_ltigradedresource_ltiprofile.py +++ b/openedx/core/djangoapps/content_libraries/migrations/0005_ltigradedresource_ltiprofile.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.20 on 2021-05-11 15:43 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content_libraries/migrations/0006_auto_20210615_1916.py b/openedx/core/djangoapps/content_libraries/migrations/0006_auto_20210615_1916.py index 672be651d82a..3cb0d68560c8 100644 --- a/openedx/core/djangoapps/content_libraries/migrations/0006_auto_20210615_1916.py +++ b/openedx/core/djangoapps/content_libraries/migrations/0006_auto_20210615_1916.py @@ -1,7 +1,7 @@ # Generated by Django 2.2.20 on 2021-06-15 19:16 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content_libraries/migrations/0008_auto_20210818_2148.py b/openedx/core/djangoapps/content_libraries/migrations/0008_auto_20210818_2148.py index 6c368dec24c4..126e3b0b8267 100644 --- a/openedx/core/djangoapps/content_libraries/migrations/0008_auto_20210818_2148.py +++ b/openedx/core/djangoapps/content_libraries/migrations/0008_auto_20210818_2148.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.24 on 2021-08-18 21:48 -from django.db import migrations, models import django.db.models.deletion import opaque_keys.edx.django.models +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content_libraries/migrations/0010_contentlibrary_learning_package_and_more.py b/openedx/core/djangoapps/content_libraries/migrations/0010_contentlibrary_learning_package_and_more.py index 372f51de310c..84a96467d623 100644 --- a/openedx/core/djangoapps/content_libraries/migrations/0010_contentlibrary_learning_package_and_more.py +++ b/openedx/core/djangoapps/content_libraries/migrations/0010_contentlibrary_learning_package_and_more.py @@ -1,7 +1,7 @@ # Generated by Django 4.2.9 on 2024-02-14 18:26 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content_libraries/models.py b/openedx/core/djangoapps/content_libraries/models.py index c4bd7e6f9a1f..0dd1458d00e0 100644 --- a/openedx/core/djangoapps/content_libraries/models.py +++ b/openedx/core/djangoapps/content_libraries/models.py @@ -43,27 +43,20 @@ from django.contrib.auth import get_user_model from django.contrib.auth.models import Group from django.core.exceptions import ValidationError -from django.db import models -from django.db import transaction +from django.db import models, transaction from django.utils.translation import gettext_lazy as _ - -from opaque_keys.edx.django.models import CourseKeyField +from opaque_keys.edx.django.models import CourseKeyField, UsageKeyField from opaque_keys.edx.locator import LibraryLocatorV2 -from pylti1p3.contrib.django import DjangoDbToolConf -from pylti1p3.contrib.django import DjangoMessageLaunch +from openedx_content.models_api import LearningPackage +from organizations.models import Organization # lint-amnesty, pylint: disable=wrong-import-order +from pylti1p3.contrib.django import DjangoDbToolConf, DjangoMessageLaunch from pylti1p3.contrib.django.lti1p3_tool_config.models import LtiTool from pylti1p3.grade import Grade -from opaque_keys.edx.django.models import UsageKeyField -from openedx.core.djangoapps.content_libraries.constants import ( - LICENSE_OPTIONS, ALL_RIGHTS_RESERVED, -) -from openedx_content.models_api import LearningPackage -from organizations.models import Organization # lint-amnesty, pylint: disable=wrong-import-order +from openedx.core.djangoapps.content_libraries.constants import ALL_RIGHTS_RESERVED, LICENSE_OPTIONS from .apps import ContentLibrariesConfig - log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/content_libraries/permissions.py b/openedx/core/djangoapps/content_libraries/permissions.py index c031e288aa43..1d0c7f9c0544 100644 --- a/openedx/core/djangoapps/content_libraries/permissions.py +++ b/openedx/core/djangoapps/content_libraries/permissions.py @@ -5,10 +5,9 @@ are deprecated in favor of openedx-authz. See https://github.com/openedx/openedx-platform/issues/37409. """ from bridgekeeper import perms, rules -from bridgekeeper.rules import Attribute, ManyRelation, Relation, blanket_rule, in_current_groups, Rule +from bridgekeeper.rules import Attribute, ManyRelation, Relation, Rule, blanket_rule, in_current_groups from django.conf import settings from django.db.models import Q - from openedx_authz import api as authz_api from openedx_authz.constants.permissions import VIEW_LIBRARY diff --git a/openedx/core/djangoapps/content_libraries/rest_api/collections.py b/openedx/core/djangoapps/content_libraries/rest_api/collections.py index 85f082138411..3f67f5e777a8 100644 --- a/openedx/core/djangoapps/content_libraries/rest_api/collections.py +++ b/openedx/core/djangoapps/content_libraries/rest_api/collections.py @@ -3,29 +3,28 @@ """ from __future__ import annotations +from django.db import transaction from django.db.models import QuerySet from django.utils.text import slugify -from django.db import transaction - -from rest_framework.decorators import action -from rest_framework.response import Response -from rest_framework.viewsets import ModelViewSet -from rest_framework.status import HTTP_204_NO_CONTENT - from opaque_keys.edx.locator import LibraryLocatorV2 from openedx_authz.constants import permissions as authz_permissions from openedx_content import api as content_api from openedx_content.models_api import Collection +from rest_framework.decorators import action +from rest_framework.response import Response +from rest_framework.status import HTTP_204_NO_CONTENT +from rest_framework.viewsets import ModelViewSet + +from openedx.core.types.http import RestRequest from .. import api, permissions from ..models import ContentLibrary -from .utils import convert_exceptions from .serializers import ( ContentLibraryCollectionSerializer, ContentLibraryCollectionUpdateSerializer, ContentLibraryItemKeysSerializer, ) -from openedx.core.types.http import RestRequest +from .utils import convert_exceptions class LibraryCollectionsView(ModelViewSet): diff --git a/openedx/core/djangoapps/content_libraries/rest_api/containers.py b/openedx/core/djangoapps/content_libraries/rest_api/containers.py index 991af9c39ca4..04dde384361e 100644 --- a/openedx/core/djangoapps/content_libraries/rest_api/containers.py +++ b/openedx/core/djangoapps/content_libraries/rest_api/containers.py @@ -8,16 +8,15 @@ from django.contrib.auth import get_user_model from django.db.transaction import non_atomic_requests from django.utils.decorators import method_decorator -from drf_yasg.utils import swagger_auto_schema from drf_yasg import openapi - -from opaque_keys.edx.locator import LibraryLocatorV2, LibraryContainerLocator +from drf_yasg.utils import swagger_auto_schema +from opaque_keys.edx.locator import LibraryContainerLocator, LibraryLocatorV2 from openedx_authz.constants import permissions as authz_permissions from openedx_content import api as content_api from openedx_content import models_api as content_models from rest_framework.generics import GenericAPIView from rest_framework.response import Response -from rest_framework.status import HTTP_204_NO_CONTENT, HTTP_200_OK +from rest_framework.status import HTTP_200_OK, HTTP_204_NO_CONTENT from openedx.core.djangoapps.content_libraries import api, permissions from openedx.core.lib.api.view_utils import view_auth_classes diff --git a/openedx/core/djangoapps/content_libraries/rest_api/libraries.py b/openedx/core/djangoapps/content_libraries/rest_api/libraries.py index 3c531d629706..fb8b71fb0b9f 100644 --- a/openedx/core/djangoapps/content_libraries/rest_api/libraries.py +++ b/openedx/core/djangoapps/content_libraries/rest_api/libraries.py @@ -80,8 +80,6 @@ from django.views.decorators.csrf import csrf_exempt from django.views.generic.base import TemplateResponseMixin, View from drf_yasg.utils import swagger_auto_schema -from user_tasks.models import UserTaskStatus - from opaque_keys.edx.locator import LibraryLocatorV2, LibraryUsageLocatorV2 from openedx_authz.constants import permissions as authz_permissions from organizations.api import ensure_organization @@ -95,15 +93,14 @@ from rest_framework.response import Response from rest_framework.views import APIView from rest_framework.viewsets import GenericViewSet +from user_tasks.models import UserTaskStatus import openedx.core.djangoapps.site_configuration.helpers as configuration_helpers +from cms.djangoapps.contentstore.storage import course_import_export_storage from cms.djangoapps.contentstore.views.course import ( get_allowed_organizations_for_libraries, - user_can_create_organizations + user_can_create_organizations, ) -from cms.djangoapps.contentstore.storage import course_import_export_storage -from openedx.core.djangoapps.content_libraries.tasks import restore_library - from openedx.core.djangoapps.content_libraries import api, permissions from openedx.core.djangoapps.content_libraries.api.libraries import get_backup_task_status from openedx.core.djangoapps.content_libraries.rest_api.serializers import ( @@ -123,9 +120,9 @@ LibraryXBlockCreationSerializer, LibraryXBlockMetadataSerializer, LibraryXBlockTypeSerializer, - PublishableItemSerializer + PublishableItemSerializer, ) -from openedx.core.djangoapps.content_libraries.tasks import backup_library +from openedx.core.djangoapps.content_libraries.tasks import backup_library, restore_library from openedx.core.djangoapps.safe_sessions.middleware import mark_user_change_as_expected from openedx.core.djangoapps.xblock import api as xblock_api from openedx.core.lib.api.view_utils import view_auth_classes diff --git a/openedx/core/djangoapps/content_libraries/rest_api/serializers.py b/openedx/core/djangoapps/content_libraries/rest_api/serializers.py index b7c7124fde08..aae0ed9030eb 100644 --- a/openedx/core/djangoapps/content_libraries/rest_api/serializers.py +++ b/openedx/core/djangoapps/content_libraries/rest_api/serializers.py @@ -13,14 +13,14 @@ from rest_framework.exceptions import ValidationError from user_tasks.models import UserTaskStatus -from openedx.core.djangoapps.content_libraries.tasks import LibraryRestoreTask from openedx.core.djangoapps.content_libraries import api from openedx.core.djangoapps.content_libraries.constants import ALL_RIGHTS_RESERVED, LICENSE_OPTIONS from openedx.core.djangoapps.content_libraries.models import ( ContentLibrary, ContentLibraryBlockImportTask, - ContentLibraryPermission + ContentLibraryPermission, ) +from openedx.core.djangoapps.content_libraries.tasks import LibraryRestoreTask from openedx.core.lib.api.serializers import CourseKeyField from .. import permissions diff --git a/openedx/core/djangoapps/content_libraries/rest_api/utils.py b/openedx/core/djangoapps/content_libraries/rest_api/utils.py index 99825fbe75f8..90ba99c0f7f0 100644 --- a/openedx/core/djangoapps/content_libraries/rest_api/utils.py +++ b/openedx/core/djangoapps/content_libraries/rest_api/utils.py @@ -1,8 +1,8 @@ """ REST API utilities for content libraries """ -from functools import wraps import logging +from functools import wraps from opaque_keys import InvalidKeyError from rest_framework.exceptions import NotFound, ValidationError diff --git a/openedx/core/djangoapps/content_libraries/signal_handlers.py b/openedx/core/djangoapps/content_libraries/signal_handlers.py index 3169f447ba7a..e566aeffa404 100644 --- a/openedx/core/djangoapps/content_libraries/signal_handlers.py +++ b/openedx/core/djangoapps/content_libraries/signal_handlers.py @@ -9,15 +9,15 @@ from django.dispatch import receiver from opaque_keys import InvalidKeyError, OpaqueKey from opaque_keys.edx.locator import LibraryLocatorV2, LibraryUsageLocatorV2 +from openedx_content.api import get_components, get_containers +from openedx_content.models_api import Collection, CollectionPublishableEntity, PublishableEntity from openedx_events.content_authoring.data import ContentObjectChangedData, LibraryCollectionData from openedx_events.content_authoring.signals import ( CONTENT_OBJECT_ASSOCIATIONS_CHANGED, LIBRARY_COLLECTION_CREATED, LIBRARY_COLLECTION_DELETED, - LIBRARY_COLLECTION_UPDATED + LIBRARY_COLLECTION_UPDATED, ) -from openedx_content.api import get_components, get_containers -from openedx_content.models_api import Collection, CollectionPublishableEntity, PublishableEntity from lms.djangoapps.grades.api import signals as grades_signals diff --git a/openedx/core/djangoapps/content_libraries/tasks.py b/openedx/core/djangoapps/content_libraries/tasks.py index a28bf1e861dd..aa27f646b1f1 100644 --- a/openedx/core/djangoapps/content_libraries/tasks.py +++ b/openedx/core/djangoapps/content_libraries/tasks.py @@ -16,35 +16,38 @@ """ from __future__ import annotations -from io import StringIO +import json import logging import os -from datetime import datetime -from tempfile import mkdtemp, NamedTemporaryFile -import json import shutil +from datetime import datetime +from io import StringIO +from tempfile import NamedTemporaryFile, mkdtemp -from django.core.files.base import ContentFile -from django.contrib.auth import get_user_model -from django.core.serializers.json import DjangoJSONEncoder -from django.conf import settings from celery import shared_task from celery.utils.log import get_task_logger from celery_utils.logged_task import LoggedTask +from django.conf import settings +from django.contrib.auth import get_user_model from django.core.files import File +from django.core.files.base import ContentFile +from django.core.serializers.json import DjangoJSONEncoder from django.utils.text import slugify from edx_django_utils.monitoring import ( set_code_owner_attribute, set_code_owner_attribute_from_module, - set_custom_attribute + set_custom_attribute, ) from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import ( BlockUsageLocator, LibraryCollectionLocator, LibraryContainerLocator, - LibraryLocatorV2 + LibraryLocatorV2, ) +from openedx_content import api as content_api +from openedx_content.api import create_zip_file as create_lib_zip_file +from openedx_content.models_api import DraftChangeLog, PublishLog from openedx_events.content_authoring.data import LibraryBlockData, LibraryCollectionData, LibraryContainerData from openedx_events.content_authoring.signals import ( LIBRARY_BLOCK_CREATED, @@ -55,16 +58,14 @@ LIBRARY_CONTAINER_CREATED, LIBRARY_CONTAINER_DELETED, LIBRARY_CONTAINER_PUBLISHED, - LIBRARY_CONTAINER_UPDATED + LIBRARY_CONTAINER_UPDATED, ) -from openedx_content import api as content_api -from openedx_content.api import create_zip_file as create_lib_zip_file -from openedx_content.models_api import DraftChangeLog, PublishLog from path import Path from user_tasks.models import UserTaskArtifact from user_tasks.tasks import UserTask, UserTaskStatus from xblock.fields import Scope +from cms.djangoapps.contentstore.storage import course_import_export_storage from openedx.core.lib import ensure_cms from xmodule.capa_block import ProblemBlock from xmodule.library_content_block import ANY_CAPA_TYPE_VALUE, LegacyLibraryContentBlock @@ -73,8 +74,6 @@ from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.modulestore.mixed import MixedModuleStore -from cms.djangoapps.contentstore.storage import course_import_export_storage - from . import api from .models import ContentLibraryBlockImportTask diff --git a/openedx/core/djangoapps/content_libraries/tests/base.py b/openedx/core/djangoapps/content_libraries/tests/base.py index 1ca5c4ed0aea..4be4d8cfb1f0 100644 --- a/openedx/core/djangoapps/content_libraries/tests/base.py +++ b/openedx/core/djangoapps/content_libraries/tests/base.py @@ -1,16 +1,16 @@ """ Tests for openedx_content-based Content Libraries """ -from contextlib import contextmanager import json +from contextlib import contextmanager from io import BytesIO from urllib.parse import urlencode -from organizations.models import Organization -from rest_framework.test import APITransactionTestCase, APIClient from opaque_keys.edx.keys import ContainerKey, UsageKey -from opaque_keys.edx.locator import LibraryLocatorV2, LibraryCollectionLocator +from opaque_keys.edx.locator import LibraryCollectionLocator, LibraryLocatorV2 from openedx_content import models_api as content_models +from organizations.models import Organization +from rest_framework.test import APIClient, APITransactionTestCase from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.util.json_request import JsonResponse as SpecialJsonResponse diff --git a/openedx/core/djangoapps/content_libraries/tests/fields_test_block.py b/openedx/core/djangoapps/content_libraries/tests/fields_test_block.py index 0db5ac28d7a8..8978132f7870 100644 --- a/openedx/core/djangoapps/content_libraries/tests/fields_test_block.py +++ b/openedx/core/djangoapps/content_libraries/tests/fields_test_block.py @@ -3,10 +3,10 @@ """ import json -from webob import Response from web_fragments.fragment import Fragment -from xblock.core import XBlock, Scope +from webob import Response from xblock import fields +from xblock.core import Scope, XBlock class FieldsTestBlock(XBlock): diff --git a/openedx/core/djangoapps/content_libraries/tests/test_api.py b/openedx/core/djangoapps/content_libraries/tests/test_api.py index 31411b0374fa..607179270900 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_api.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_api.py @@ -9,14 +9,12 @@ from django.db import transaction from django.test import TestCase -from user_tasks.models import UserTaskStatus - -from opaque_keys.edx.keys import ( - CourseKey, - UsageKey, - UsageKeyV2, -) +from opaque_keys.edx.keys import CourseKey, UsageKey, UsageKeyV2 from opaque_keys.edx.locator import LibraryContainerLocator, LibraryLocatorV2, LibraryUsageLocatorV2 +from openedx_authz.api.users import get_user_role_assignments_in_scope +from openedx_content import api as content_api +from openedx_content import models_api as content_models +from openedx_content.models_api import Component, Container from openedx_events.content_authoring.data import ( ContentObjectChangedData, LibraryBlockData, @@ -35,12 +33,10 @@ LIBRARY_CONTAINER_DELETED, LIBRARY_CONTAINER_UPDATED, ) -from openedx_content.models_api import Component, Container -from openedx_authz.api.users import get_user_role_assignments_in_scope -from openedx_content import api as content_api -from openedx_content import models_api as content_models +from user_tasks.models import UserTaskStatus from common.djangoapps.student.tests.factories import UserFactory + from .. import api from ..models import ContentLibrary from .base import ContentLibrariesRestApiTest diff --git a/openedx/core/djangoapps/content_libraries/tests/test_auth.py b/openedx/core/djangoapps/content_libraries/tests/test_auth.py index 99d84b7fd7ea..d01c46eba482 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_auth.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_auth.py @@ -5,10 +5,8 @@ from django.test import TestCase - -from ..models import LtiProfile -from ..models import get_user_model from ..auth import LtiAuthenticationBackend +from ..models import LtiProfile, get_user_model class LtiAuthenticationBackendTest(TestCase): diff --git a/openedx/core/djangoapps/content_libraries/tests/test_command_content_libraries_import.py b/openedx/core/djangoapps/content_libraries/tests/test_command_content_libraries_import.py index 0f57b8f2d815..1cbcebfdffe0 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_command_content_libraries_import.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_command_content_libraries_import.py @@ -3,8 +3,8 @@ """ -from unittest import mock from io import StringIO +from unittest import mock from django.core.management import call_command from django.core.management.base import CommandError diff --git a/openedx/core/djangoapps/content_libraries/tests/test_containers.py b/openedx/core/djangoapps/content_libraries/tests/test_containers.py index b5f6326660b3..ef9ecf226255 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_containers.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_containers.py @@ -1,12 +1,11 @@ """ Tests for openedx_content-based Content Libraries """ -from datetime import datetime, timezone import textwrap +from datetime import datetime, timezone import ddt from freezegun import freeze_time - from opaque_keys.edx.locator import LibraryLocatorV2 from common.djangoapps.student.tests.factories import UserFactory diff --git a/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py b/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py index aba221dac821..a4f387f161d0 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py @@ -1,11 +1,11 @@ """ Tests for openedx_content-based Content Libraries """ -from datetime import datetime, timezone import os -import zipfile -import uuid import tempfile +import uuid +import zipfile +from datetime import datetime, timezone from io import StringIO from unittest import skip from unittest.mock import ANY, patch @@ -13,18 +13,22 @@ import ddt import tomlkit from bridgekeeper import perms -from django.core.files.uploadedfile import SimpleUploadedFile from django.contrib.auth.models import Group +from django.core.files.uploadedfile import SimpleUploadedFile from django.db.models import Q from django.test import override_settings from django.test.client import Client from freezegun import freeze_time -from opaque_keys.edx.locator import LibraryLocatorV2, LibraryUsageLocatorV2, LibraryCollectionLocator +from opaque_keys.edx.locator import LibraryCollectionLocator, LibraryLocatorV2, LibraryUsageLocatorV2 +from openedx_authz import api as authz_api +from openedx_authz.constants import roles +from openedx_authz.constants.permissions import VIEW_LIBRARY +from openedx_authz.engine.enforcer import AuthzEnforcer +from openedx_content.models_api import LearningPackage from organizations.models import Organization -from rest_framework.test import APITestCase from rest_framework import status -from openedx_content.models_api import LearningPackage -from user_tasks.models import UserTaskStatus, UserTaskArtifact +from rest_framework.test import APITestCase +from user_tasks.models import UserTaskArtifact, UserTaskStatus from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.content_libraries.constants import CC_4_BY @@ -36,12 +40,8 @@ URL_BLOCK_XBLOCK_HANDLER, ContentLibrariesRestApiTest, ) -from openedx_authz import api as authz_api -from openedx_authz.constants import roles -from openedx_authz.engine.enforcer import AuthzEnforcer from openedx.core.djangoapps.xblock import api as xblock_api from openedx.core.djangolib.testing.utils import skip_unless_cms -from openedx_authz.constants.permissions import VIEW_LIBRARY from ..models import ContentLibrary, ContentLibraryPermission from ..permissions import CAN_VIEW_THIS_CONTENT_LIBRARY, HasPermissionInContentLibraryScope @@ -1785,9 +1785,9 @@ def _seed_database_with_policies(cls): This simulates the one-time database seeding that would happen during application deployment, separate from the runtime policy loading. """ + import casbin import pkg_resources from openedx_authz.engine.utils import migrate_policy_between_enforcers - import casbin global_enforcer = AuthzEnforcer.get_enforcer() global_enforcer.load_policy() diff --git a/openedx/core/djangoapps/content_libraries/tests/test_course_to_library.py b/openedx/core/djangoapps/content_libraries/tests/test_course_to_library.py index 2b57c59e7a35..7bc7da0fc868 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_course_to_library.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_course_to_library.py @@ -4,11 +4,11 @@ import ddt from opaque_keys.edx.locator import LibraryContainerLocator -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import ToyCourseFactory from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.content_libraries.tests.base import ContentLibrariesRestApiTest from openedx.core.djangolib.testing.utils import skip_unless_cms +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import ToyCourseFactory @skip_unless_cms diff --git a/openedx/core/djangoapps/content_libraries/tests/test_embed_block.py b/openedx/core/djangoapps/content_libraries/tests/test_embed_block.py index 214c85e09af1..a1f9272aa661 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_embed_block.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_embed_block.py @@ -6,15 +6,14 @@ import re import ddt +import pytest from django.core.exceptions import ValidationError from django.test.utils import override_settings -import pytest from xblock.core import XBlock -from openedx.core.djangoapps.content_libraries.tests.base import ( - ContentLibrariesRestApiTest -) +from openedx.core.djangoapps.content_libraries.tests.base import ContentLibrariesRestApiTest from openedx.core.djangolib.testing.utils import skip_unless_cms + from .fields_test_block import FieldsTestBlock diff --git a/openedx/core/djangoapps/content_libraries/tests/test_events.py b/openedx/core/djangoapps/content_libraries/tests/test_events.py index dff2dbb47d53..dd5cb2dd3c5d 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_events.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_events.py @@ -8,24 +8,24 @@ LibraryUsageLocatorV2, ) from openedx_events.content_authoring.signals import ( - ContentLibraryData, - LibraryBlockData, - LibraryCollectionData, - LibraryContainerData, CONTENT_LIBRARY_CREATED, CONTENT_LIBRARY_DELETED, CONTENT_LIBRARY_UPDATED, LIBRARY_BLOCK_CREATED, LIBRARY_BLOCK_DELETED, - LIBRARY_BLOCK_UPDATED, LIBRARY_BLOCK_PUBLISHED, + LIBRARY_BLOCK_UPDATED, LIBRARY_COLLECTION_CREATED, LIBRARY_COLLECTION_DELETED, LIBRARY_COLLECTION_UPDATED, LIBRARY_CONTAINER_CREATED, LIBRARY_CONTAINER_DELETED, - LIBRARY_CONTAINER_UPDATED, LIBRARY_CONTAINER_PUBLISHED, + LIBRARY_CONTAINER_UPDATED, + ContentLibraryData, + LibraryBlockData, + LibraryCollectionData, + LibraryContainerData, ) from openedx.core.djangoapps.content_libraries.tests.base import ContentLibrariesRestApiTest diff --git a/openedx/core/djangoapps/content_libraries/tests/test_models.py b/openedx/core/djangoapps/content_libraries/tests/test_models.py index eded47a305d2..04670645e25e 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_models.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_models.py @@ -5,20 +5,13 @@ from unittest import mock -from django.test import TestCase -from django.test import RequestFactory from django.contrib.auth import get_user_model - -from pylti1p3.contrib.django.lti1p3_tool_config.models import LtiToolKey - -from organizations.models import Organization +from django.test import RequestFactory, TestCase from opaque_keys.edx.locator import LibraryLocatorV2, LibraryUsageLocatorV2 +from organizations.models import Organization +from pylti1p3.contrib.django.lti1p3_tool_config.models import LtiToolKey -from ..models import ALL_RIGHTS_RESERVED -from ..models import ContentLibrary -from ..models import LtiGradedResource -from ..models import LtiProfile -from ..models import LtiTool +from ..models import ALL_RIGHTS_RESERVED, ContentLibrary, LtiGradedResource, LtiProfile, LtiTool class ContentLibraryTest(TestCase): diff --git a/openedx/core/djangoapps/content_libraries/tests/test_runtime.py b/openedx/core/djangoapps/content_libraries/tests/test_runtime.py index a4b98c09b133..b67b21498166 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_runtime.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_runtime.py @@ -3,31 +3,31 @@ """ import json +import django.utils.translation from completion.test_utils import CompletionWaffleTestMixin from django.db import connections, transaction from django.test import TestCase, override_settings from django.utils.text import slugify -import django.utils.translation from organizations.models import Organization from rest_framework.test import APIClient from xblock.core import XBlock +from common.djangoapps.student.tests.factories import UserFactory +from common.test.utils import assert_dict_contains_subset from lms.djangoapps.courseware.model_data import get_score from openedx.core.djangoapps.content_libraries import api as library_api +from openedx.core.djangoapps.content_libraries.constants import ALL_RIGHTS_RESERVED from openedx.core.djangoapps.content_libraries.tests.base import ( - URL_BLOCK_RENDER_VIEW, + URL_BLOCK_FIELDS_URL, URL_BLOCK_GET_HANDLER_URL, URL_BLOCK_METADATA_URL, - URL_BLOCK_FIELDS_URL, + URL_BLOCK_RENDER_VIEW, ) from openedx.core.djangoapps.content_libraries.tests.user_state_block import UserStateTestBlock -from openedx.core.djangoapps.content_libraries.constants import ALL_RIGHTS_RESERVED from openedx.core.djangoapps.dark_lang.models import DarkLangConfig from openedx.core.djangoapps.xblock import api as xblock_api -from openedx.core.djangolib.testing.utils import skip_unless_lms, skip_unless_cms +from openedx.core.djangolib.testing.utils import skip_unless_cms, skip_unless_lms from openedx.core.lib.xblock_serializer import api as serializer_api -from common.djangoapps.student.tests.factories import UserFactory -from common.test.utils import assert_dict_contains_subset class ContentLibraryContentTestMixin: diff --git a/openedx/core/djangoapps/content_libraries/tests/test_static_assets.py b/openedx/core/djangoapps/content_libraries/tests/test_static_assets.py index 3859224cfd51..cfa3c61829bf 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_static_assets.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_static_assets.py @@ -6,9 +6,7 @@ from opaque_keys.edx.keys import UsageKey from common.djangoapps.student.tests.factories import UserFactory -from openedx.core.djangoapps.content_libraries.tests.base import ( - ContentLibrariesRestApiTest, -) +from openedx.core.djangoapps.content_libraries.tests.base import ContentLibrariesRestApiTest from openedx.core.djangoapps.xblock.api import get_component_from_usage_key from openedx.core.djangolib.testing.utils import skip_unless_cms diff --git a/openedx/core/djangoapps/content_libraries/tests/test_tasks.py b/openedx/core/djangoapps/content_libraries/tests/test_tasks.py index a200471c00bd..439b4fe9aa4e 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_tasks.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_tasks.py @@ -4,11 +4,12 @@ from unittest import mock from django.test import override_settings -from ..models import ContentLibrary -from .base import ContentLibrariesRestApiTest +from user_tasks.models import UserTaskArtifact from openedx.core.djangoapps.content_libraries.tasks import backup_library -from user_tasks.models import UserTaskArtifact + +from ..models import ContentLibrary +from .base import ContentLibrariesRestApiTest class ContentLibraryBackupTaskTest(ContentLibrariesRestApiTest): diff --git a/openedx/core/djangoapps/content_libraries/tests/test_versioned_apis.py b/openedx/core/djangoapps/content_libraries/tests/test_versioned_apis.py index 20d0b38f0b7c..29498104b536 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_versioned_apis.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_versioned_apis.py @@ -4,10 +4,9 @@ from django.test.utils import override_settings from xblock.core import XBlock -from openedx.core.djangoapps.content_libraries.tests.base import ( - ContentLibrariesRestApiTest -) +from openedx.core.djangoapps.content_libraries.tests.base import ContentLibrariesRestApiTest from openedx.core.djangolib.testing.utils import skip_unless_cms + from .fields_test_block import FieldsTestBlock diff --git a/openedx/core/djangoapps/content_libraries/tests/test_views_collections.py b/openedx/core/djangoapps/content_libraries/tests/test_views_collections.py index edd3084e90de..4ed2a00a86ad 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_views_collections.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_views_collections.py @@ -3,16 +3,16 @@ """ from __future__ import annotations -import ddt -from openedx_content.models_api import Collection +import ddt from opaque_keys.edx.locator import LibraryLocatorV2 +from openedx_content.models_api import Collection -from openedx.core.djangolib.testing.utils import skip_unless_cms +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.content_libraries import api -from openedx.core.djangoapps.content_libraries.tests.base import ContentLibrariesRestApiTest from openedx.core.djangoapps.content_libraries.models import ContentLibrary -from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.content_libraries.tests.base import ContentLibrariesRestApiTest +from openedx.core.djangolib.testing.utils import skip_unless_cms URL_PREFIX = '/api/libraries/v2/{lib_key}/' URL_LIB_COLLECTIONS = URL_PREFIX + 'collections/' diff --git a/openedx/core/djangoapps/content_libraries/tests/test_views_lti.py b/openedx/core/djangoapps/content_libraries/tests/test_views_lti.py index c41b76bb60a6..e9c215899e35 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_views_lti.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_views_lti.py @@ -5,11 +5,7 @@ from django.conf import settings from django.test import TestCase, override_settings -from .base import ( - ContentLibrariesRestApiTest, - URL_LIB_LTI_JWKS, - skip_unless_cms, -) +from .base import URL_LIB_LTI_JWKS, ContentLibrariesRestApiTest, skip_unless_cms def override_features(**kwargs): diff --git a/openedx/core/djangoapps/content_libraries/tests/user_state_block.py b/openedx/core/djangoapps/content_libraries/tests/user_state_block.py index 16329a18ca65..488ecf984353 100644 --- a/openedx/core/djangoapps/content_libraries/tests/user_state_block.py +++ b/openedx/core/djangoapps/content_libraries/tests/user_state_block.py @@ -5,8 +5,8 @@ import json from webob import Response -from xblock.core import XBlock, Scope from xblock import fields +from xblock.core import Scope, XBlock class UserStateTestBlock(XBlock): diff --git a/openedx/core/djangoapps/content_staging/admin.py b/openedx/core/djangoapps/content_staging/admin.py index 2ae6b92ce0e5..c7a8a99d2195 100644 --- a/openedx/core/djangoapps/content_staging/admin.py +++ b/openedx/core/djangoapps/content_staging/admin.py @@ -4,6 +4,7 @@ from django.contrib import admin from django.urls import reverse from django.utils.html import format_html + from .models import StagedContent, StagedContentFile, UserClipboard diff --git a/openedx/core/djangoapps/content_staging/api.py b/openedx/core/djangoapps/content_staging/api.py index b73d550ed8cb..eb7bf94b010f 100644 --- a/openedx/core/djangoapps/content_staging/api.py +++ b/openedx/core/djangoapps/content_staging/api.py @@ -10,7 +10,7 @@ from django.db import transaction from django.http import HttpRequest from opaque_keys import InvalidKeyError -from opaque_keys.edx.keys import AssetKey, UsageKey, ContainerKey +from opaque_keys.edx.keys import AssetKey, ContainerKey, UsageKey from xblock.core import XBlock from openedx.core.djangoapps.content_tagging.api import TagValuesByObjectIdDict @@ -19,21 +19,11 @@ from xmodule.contentstore.content import StaticContent from xmodule.contentstore.django import contentstore -from .data import ( - CLIPBOARD_PURPOSE, - StagedContentData, - StagedContentFileData, - StagedContentStatus, - UserClipboardData, -) -from .models import ( - UserClipboard as _UserClipboard, - StagedContent as _StagedContent, - StagedContentFile as _StagedContentFile, -) -from .serializers import ( - UserClipboardSerializer as _UserClipboardSerializer, -) +from .data import CLIPBOARD_PURPOSE, StagedContentData, StagedContentFileData, StagedContentStatus, UserClipboardData +from .models import StagedContent as _StagedContent +from .models import StagedContentFile as _StagedContentFile +from .models import UserClipboard as _UserClipboard +from .serializers import UserClipboardSerializer as _UserClipboardSerializer from .tasks import delete_expired_clipboards log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/content_staging/data.py b/openedx/core/djangoapps/content_staging/data.py index 95128c7f6870..cf311e081e8f 100644 --- a/openedx/core/djangoapps/content_staging/data.py +++ b/openedx/core/djangoapps/content_staging/data.py @@ -2,12 +2,13 @@ Public python data types for content staging """ from __future__ import annotations -from attrs import field, frozen, validators + from datetime import datetime +from attrs import field, frozen, validators from django.db.models import TextChoices from django.utils.translation import gettext_lazy as _ -from opaque_keys.edx.keys import UsageKey, AssetKey, LearningContextKey, ContainerKey +from opaque_keys.edx.keys import AssetKey, ContainerKey, LearningContextKey, UsageKey from openedx.core.djangoapps.content_tagging.api import TagValuesByObjectIdDict diff --git a/openedx/core/djangoapps/content_staging/migrations/0001_initial.py b/openedx/core/djangoapps/content_staging/migrations/0001_initial.py index fa777a60cccc..97e06c6200ec 100644 --- a/openedx/core/djangoapps/content_staging/migrations/0001_initial.py +++ b/openedx/core/djangoapps/content_staging/migrations/0001_initial.py @@ -1,9 +1,9 @@ # Generated by Django 3.2.18 on 2023-03-16 23:45 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import opaque_keys.edx.django.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content_staging/migrations/0002_stagedcontentfile.py b/openedx/core/djangoapps/content_staging/migrations/0002_stagedcontentfile.py index 5c3501ac0d9d..0215d14b64a1 100644 --- a/openedx/core/djangoapps/content_staging/migrations/0002_stagedcontentfile.py +++ b/openedx/core/djangoapps/content_staging/migrations/0002_stagedcontentfile.py @@ -1,7 +1,7 @@ # Generated by Django 3.2.19 on 2023-06-02 00:47 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content_staging/migrations/0003_olx_unicode.py b/openedx/core/djangoapps/content_staging/migrations/0003_olx_unicode.py index baac395af4e7..2c523a9b4636 100644 --- a/openedx/core/djangoapps/content_staging/migrations/0003_olx_unicode.py +++ b/openedx/core/djangoapps/content_staging/migrations/0003_olx_unicode.py @@ -1,7 +1,7 @@ # Generated by Django 3.2.23 on 2023-12-07 20:10 -from django.db import migrations import openedx_django_lib.fields +from django.db import migrations class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content_staging/serializers.py b/openedx/core/djangoapps/content_staging/serializers.py index 753e040972c1..45b08ee99e1b 100644 --- a/openedx/core/djangoapps/content_staging/serializers.py +++ b/openedx/core/djangoapps/content_staging/serializers.py @@ -6,6 +6,7 @@ from common.djangoapps.student.auth import has_studio_read_access from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError + from .models import StagedContent diff --git a/openedx/core/djangoapps/content_staging/tasks.py b/openedx/core/djangoapps/content_staging/tasks.py index 951a6f0a645d..afa0332dd237 100644 --- a/openedx/core/djangoapps/content_staging/tasks.py +++ b/openedx/core/djangoapps/content_staging/tasks.py @@ -2,6 +2,7 @@ Celery tasks for Content Staging. """ from __future__ import annotations # for list[int] type + import logging from celery import shared_task diff --git a/openedx/core/djangoapps/content_staging/tests/test_clipboard.py b/openedx/core/djangoapps/content_staging/tests/test_clipboard.py index 5d332563a8f2..9be402dd7efa 100644 --- a/openedx/core/djangoapps/content_staging/tests/test_clipboard.py +++ b/openedx/core/djangoapps/content_staging/tests/test_clipboard.py @@ -6,13 +6,12 @@ from xml.etree import ElementTree from rest_framework.test import APIClient + +from openedx.core.djangoapps.content_staging import api as python_api from xmodule.contentstore.django import contentstore from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, upload_file_to_course from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory, ToyCourseFactory -from openedx.core.djangoapps.content_staging import api as python_api - - CLIPBOARD_ENDPOINT = "/api/content-staging/v1/clipboard/" # OLX of the video in the toy course using course_key.make_usage_key("video", "sample_video") diff --git a/openedx/core/djangoapps/content_staging/urls.py b/openedx/core/djangoapps/content_staging/urls.py index 8953d68de35a..c7b5a860e7a0 100644 --- a/openedx/core/djangoapps/content_staging/urls.py +++ b/openedx/core/djangoapps/content_staging/urls.py @@ -1,7 +1,7 @@ """ Studio URL configuration for Content Staging (& Clipboard) """ -from django.urls import path, include +from django.urls import include, path from . import views diff --git a/openedx/core/djangoapps/content_staging/views.py b/openedx/core/djangoapps/content_staging/views.py index 37bfa54d7df2..00b37a28ffcd 100644 --- a/openedx/core/djangoapps/content_staging/views.py +++ b/openedx/core/djangoapps/content_staging/views.py @@ -3,19 +3,19 @@ """ from __future__ import annotations +import edx_api_doc_tools as apidocs from django.db import transaction from django.http import HttpResponse from django.shortcuts import get_object_or_404 from django.utils.decorators import method_decorator -import edx_api_doc_tools as apidocs from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import UsageKey from opaque_keys.edx.locator import CourseLocator, LibraryLocatorV2 from rest_framework.exceptions import NotFound, PermissionDenied, ValidationError from rest_framework.response import Response from rest_framework.views import APIView -from common.djangoapps.student.auth import has_studio_read_access +from common.djangoapps.student.auth import has_studio_read_access from openedx.core.djangoapps.xblock import api as xblock_api from openedx.core.lib.api.view_utils import view_auth_classes from xmodule.modulestore.django import modulestore @@ -24,7 +24,7 @@ from . import api from .data import StagedContentStatus from .models import StagedContent -from .serializers import UserClipboardSerializer, PostToClipboardSerializer +from .serializers import PostToClipboardSerializer, UserClipboardSerializer @view_auth_classes(is_authenticated=True) diff --git a/openedx/core/djangoapps/content_tagging/api.py b/openedx/core/djangoapps/content_tagging/api.py index 13e0d8f8f8b9..9d4fd85a753d 100644 --- a/openedx/core/djangoapps/content_tagging/api.py +++ b/openedx/core/djangoapps/content_tagging/api.py @@ -2,27 +2,24 @@ Content Tagging APIs """ from __future__ import annotations -import io -from itertools import groupby import csv +import io +from itertools import groupby from typing import Iterator -from opaque_keys.edx.keys import CourseKey, CollectionKey, ContainerKey, UsageKey import openedx_tagging.api as oel_tagging from django.db.models import Exists, OuterRef, Q, QuerySet from django.utils.timezone import now +from opaque_keys.edx.keys import CollectionKey, ContainerKey, CourseKey, UsageKey from opaque_keys.edx.locator import LibraryLocatorV2 +from openedx_events.content_authoring.data import ContentObjectChangedData, ContentObjectData +from openedx_events.content_authoring.signals import CONTENT_OBJECT_ASSOCIATIONS_CHANGED, CONTENT_OBJECT_TAGS_CHANGED from openedx_tagging.models import ObjectTag, Taxonomy from openedx_tagging.models.utils import TAGS_CSV_SEPARATOR from organizations.models import Organization -from .helpers.objecttag_export_helpers import build_object_tree_with_objecttags, iterate_with_level -from openedx_events.content_authoring.data import ContentObjectData, ContentObjectChangedData -from openedx_events.content_authoring.signals import ( - CONTENT_OBJECT_ASSOCIATIONS_CHANGED, - CONTENT_OBJECT_TAGS_CHANGED, -) +from .helpers.objecttag_export_helpers import build_object_tree_with_objecttags, iterate_with_level from .models import TaxonomyOrg from .types import ContentKey, TagValuesByObjectIdDict, TagValuesByTaxonomyIdDict, TaxonomyDict from .utils import check_taxonomy_context_key_org, get_content_key_from_string, get_context_key_from_key diff --git a/openedx/core/djangoapps/content_tagging/handlers.py b/openedx/core/djangoapps/content_tagging/handlers.py index 86cbb7167cbe..f271f6d73cd9 100644 --- a/openedx/core/djangoapps/content_tagging/handlers.py +++ b/openedx/core/djangoapps/content_tagging/handlers.py @@ -2,24 +2,19 @@ Automatic tagging of content """ -import crum import logging +import crum from django.dispatch import receiver -from openedx_events.content_authoring.data import ( - CourseData, - DuplicatedXBlockData, - XBlockData, - LibraryBlockData, -) +from openedx_events.content_authoring.data import CourseData, DuplicatedXBlockData, LibraryBlockData, XBlockData from openedx_events.content_authoring.signals import ( COURSE_CREATED, + LIBRARY_BLOCK_CREATED, + LIBRARY_BLOCK_UPDATED, XBLOCK_CREATED, XBLOCK_DELETED, - XBLOCK_UPDATED, XBLOCK_DUPLICATED, - LIBRARY_BLOCK_CREATED, - LIBRARY_BLOCK_UPDATED, + XBLOCK_UPDATED, ) from .api import copy_object_tags @@ -27,8 +22,8 @@ delete_course_tags, delete_xblock_tags, update_course_tags, - update_xblock_tags, update_library_block_tags, + update_xblock_tags, ) from .toggles import CONTENT_TAGGING_AUTO diff --git a/openedx/core/djangoapps/content_tagging/migrations/0001_initial.py b/openedx/core/djangoapps/content_tagging/migrations/0001_initial.py index 7d74d7ab73a0..8e99e89dab5b 100644 --- a/openedx/core/djangoapps/content_tagging/migrations/0001_initial.py +++ b/openedx/core/djangoapps/content_tagging/migrations/0001_initial.py @@ -1,7 +1,7 @@ # Generated by Django 3.2.20 on 2023-07-25 06:17 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content_tagging/migrations/0001_squashed.py b/openedx/core/djangoapps/content_tagging/migrations/0001_squashed.py index fa00df307c64..039fcd23428e 100644 --- a/openedx/core/djangoapps/content_tagging/migrations/0001_squashed.py +++ b/openedx/core/djangoapps/content_tagging/migrations/0001_squashed.py @@ -1,7 +1,7 @@ # Generated by Django 3.2.21 on 2023-10-09 23:12 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/content_tagging/migrations/0002_system_defined_taxonomies.py b/openedx/core/djangoapps/content_tagging/migrations/0002_system_defined_taxonomies.py index 14a3e6ace128..377f077b0694 100644 --- a/openedx/core/djangoapps/content_tagging/migrations/0002_system_defined_taxonomies.py +++ b/openedx/core/djangoapps/content_tagging/migrations/0002_system_defined_taxonomies.py @@ -1,6 +1,7 @@ # Generated by Django 3.2.20 on 2023-07-31 21:07 from django.db import migrations + import openedx.core.djangoapps.content_tagging.models.base diff --git a/openedx/core/djangoapps/content_tagging/models/__init__.py b/openedx/core/djangoapps/content_tagging/models/__init__.py index 4a25224b4bae..4f0729e12e52 100644 --- a/openedx/core/djangoapps/content_tagging/models/__init__.py +++ b/openedx/core/djangoapps/content_tagging/models/__init__.py @@ -1,6 +1,4 @@ """ Content Tagging and System defined models """ -from .base import ( - TaxonomyOrg, -) +from .base import TaxonomyOrg diff --git a/openedx/core/djangoapps/content_tagging/rest_api/urls.py b/openedx/core/djangoapps/content_tagging/rest_api/urls.py index d7f012bb7ba1..2cd82d03b4d9 100644 --- a/openedx/core/djangoapps/content_tagging/rest_api/urls.py +++ b/openedx/core/djangoapps/content_tagging/rest_api/urls.py @@ -2,7 +2,7 @@ Taxonomies API URLs. """ -from django.urls import path, include +from django.urls import include, path from .v1 import urls as v1_urls diff --git a/openedx/core/djangoapps/content_tagging/rest_api/v1/filters.py b/openedx/core/djangoapps/content_tagging/rest_api/v1/filters.py index 88695f1ffd9b..75bbde280e17 100644 --- a/openedx/core/djangoapps/content_tagging/rest_api/v1/filters.py +++ b/openedx/core/djangoapps/content_tagging/rest_api/v1/filters.py @@ -2,13 +2,12 @@ API Filters for content tagging org """ +import openedx_tagging.rules as oel_tagging from django.db.models import Exists, OuterRef, Q from rest_framework.filters import BaseFilterBackend -import openedx_tagging.rules as oel_tagging - -from ...rules import get_admin_orgs, get_user_orgs from ...models import TaxonomyOrg +from ...rules import get_admin_orgs, get_user_orgs class UserOrgFilterBackend(BaseFilterBackend): diff --git a/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py b/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py index 531ad50863e3..e15f04504a3e 100644 --- a/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py +++ b/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py @@ -4,15 +4,13 @@ from __future__ import annotations -from rest_framework import serializers, fields - from openedx_tagging.rest_api.v1.serializers import ( ObjectTagMinimalSerializer, TaxonomyListQueryParamsSerializer, TaxonomySerializer, ) - from organizations.models import Organization +from rest_framework import fields, serializers from ...models import TaxonomyOrg diff --git a/openedx/core/djangoapps/content_tagging/rest_api/v1/tests/test_views.py b/openedx/core/djangoapps/content_tagging/rest_api/v1/tests/test_views.py index 952ed4fbb5ff..480c15fcabdb 100644 --- a/openedx/core/djangoapps/content_tagging/rest_api/v1/tests/test_views.py +++ b/openedx/core/djangoapps/content_tagging/rest_api/v1/tests/test_views.py @@ -22,8 +22,7 @@ from openedx_tagging.rest_api.v1.serializers import TaxonomySerializer from organizations.models import Organization from rest_framework import status -from rest_framework.test import APITestCase, APIClient - +from rest_framework.test import APIClient, APITestCase from common.djangoapps.student.auth import add_users, update_org_role from common.djangoapps.student.roles import ( @@ -32,16 +31,16 @@ OrgContentCreatorRole, OrgInstructorRole, OrgLibraryUserRole, - OrgStaffRole + OrgStaffRole, ) from common.djangoapps.student.tests.factories import StaffFactory, UserFactory from openedx.core.djangoapps.authz.tests.mixins import CourseAuthzTestMixin -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from openedx.core.djangoapps.content_libraries.api import AccessLevel, create_library, set_library_user_permissions from openedx.core.djangoapps.content_tagging import api as tagging_api from openedx.core.djangoapps.content_tagging.models import TaxonomyOrg from openedx.core.djangolib.testing.utils import skip_unless_cms +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory from ....tests.test_objecttag_export_helpers import TaggedCourseMixin diff --git a/openedx/core/djangoapps/content_tagging/rest_api/v1/views.py b/openedx/core/djangoapps/content_tagging/rest_api/v1/views.py index ca817ab402be..854183eef491 100644 --- a/openedx/core/djangoapps/content_tagging/rest_api/v1/views.py +++ b/openedx/core/djangoapps/content_tagging/rest_api/v1/views.py @@ -5,6 +5,8 @@ from django.db.models import Count from django.http import StreamingHttpResponse +from openedx_events.content_authoring.data import ContentObjectChangedData, ContentObjectData +from openedx_events.content_authoring.signals import CONTENT_OBJECT_ASSOCIATIONS_CHANGED, CONTENT_OBJECT_TAGS_CHANGED from openedx_tagging import rules as oel_tagging_rules from openedx_tagging.rest_api.v1.views import ObjectTagView, TaxonomyView from rest_framework import status @@ -12,15 +14,9 @@ from rest_framework.exceptions import PermissionDenied, ValidationError from rest_framework.response import Response from rest_framework.views import APIView -from openedx_events.content_authoring.data import ContentObjectData, ContentObjectChangedData -from openedx_events.content_authoring.signals import ( - CONTENT_OBJECT_ASSOCIATIONS_CHANGED, - CONTENT_OBJECT_TAGS_CHANGED, -) from openedx.core.types.http import RestRequest -from ...auth import has_view_object_tags_access from ...api import ( create_taxonomy, generate_csv_rows, @@ -28,8 +24,9 @@ get_taxonomies_for_org, get_taxonomy, get_unassigned_taxonomies, - set_taxonomy_orgs + set_taxonomy_orgs, ) +from ...auth import has_view_object_tags_access from ...rules import get_admin_orgs from .filters import ObjectTagTaxonomyOrgFilterBackend, UserOrgFilterBackend from .serializers import ( diff --git a/openedx/core/djangoapps/content_tagging/rules.py b/openedx/core/djangoapps/content_tagging/rules.py index 3f798d4053ba..d5b5cd4b1504 100644 --- a/openedx/core/djangoapps/content_tagging/rules.py +++ b/openedx/core/djangoapps/content_tagging/rules.py @@ -17,13 +17,12 @@ OrgContentCreatorRole, OrgInstructorRole, OrgLibraryUserRole, - OrgStaffRole + OrgStaffRole, ) from .models import TaxonomyOrg from .utils import check_taxonomy_context_key_org, get_context_key_from_key_string, rules_cache - UserType = Union[django.contrib.auth.models.User, django.contrib.auth.models.AnonymousUser] diff --git a/openedx/core/djangoapps/content_tagging/tests/test_api.py b/openedx/core/djangoapps/content_tagging/tests/test_api.py index cff8908d0522..1561bdf695b4 100644 --- a/openedx/core/djangoapps/content_tagging/tests/test_api.py +++ b/openedx/core/djangoapps/content_tagging/tests/test_api.py @@ -2,17 +2,18 @@ import io import os import tempfile + import ddt from django.test.testcases import TestCase from fs.osfs import OSFS from opaque_keys.edx.keys import CourseKey, UsageKey -from opaque_keys.edx.locator import LibraryLocatorV2, LibraryCollectionLocator, LibraryContainerLocator +from opaque_keys.edx.locator import LibraryCollectionLocator, LibraryContainerLocator, LibraryLocatorV2 from openedx_tagging.models import ObjectTag from organizations.models import Organization -from .test_objecttag_export_helpers import TestGetAllObjectTagsMixin, TaggedCourseMixin from .. import api from ..utils import rules_cache +from .test_objecttag_export_helpers import TaggedCourseMixin, TestGetAllObjectTagsMixin class TestTaxonomyMixin: diff --git a/openedx/core/djangoapps/content_tagging/tests/test_rules.py b/openedx/core/djangoapps/content_tagging/tests/test_rules.py index 75926d094103..557537848ad1 100644 --- a/openedx/core/djangoapps/content_tagging/tests/test_rules.py +++ b/openedx/core/djangoapps/content_tagging/tests/test_rules.py @@ -4,10 +4,7 @@ from django.contrib.auth import get_user_model from django.test import TestCase from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator -from openedx_tagging.models import ( - Tag, - UserSystemDefinedTaxonomy, -) +from openedx_tagging.models import Tag, UserSystemDefinedTaxonomy from openedx_tagging.rules import ObjectTagPermissionItem from common.djangoapps.student.auth import add_users, update_org_role diff --git a/openedx/core/djangoapps/content_tagging/tests/test_tasks.py b/openedx/core/djangoapps/content_tagging/tests/test_tasks.py index 39689b37a124..80cae53620fd 100644 --- a/openedx/core/djangoapps/content_tagging/tests/test_tasks.py +++ b/openedx/core/djangoapps/content_tagging/tests/test_tasks.py @@ -5,21 +5,24 @@ from unittest.mock import patch -from django.test import override_settings, LiveServerTestCase from django.http import HttpRequest +from django.test import LiveServerTestCase, override_settings from edx_toggles.toggles.testutils import override_waffle_flag -from openedx_tagging.models import Tag, Taxonomy, ObjectTag +from openedx_tagging.models import ObjectTag, Tag, Taxonomy from organizations.models import Organization from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.content_libraries.api import ( + create_library, + create_library_block, + delete_library_block, + restore_library_block, +) from openedx.core.djangolib.testing.utils import skip_unless_cms from xmodule.modulestore.tests.django_utils import ( TEST_DATA_SPLIT_MODULESTORE, - ModuleStoreTestCase, ImmediateOnCommitMixin, -) -from openedx.core.djangoapps.content_libraries.api import ( - create_library, create_library_block, delete_library_block, restore_library_block + ModuleStoreTestCase, ) from .. import api diff --git a/openedx/core/djangoapps/content_tagging/toggles.py b/openedx/core/djangoapps/content_tagging/toggles.py index 3162a529833c..a6b0a4e19afa 100644 --- a/openedx/core/djangoapps/content_tagging/toggles.py +++ b/openedx/core/djangoapps/content_tagging/toggles.py @@ -6,7 +6,6 @@ from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag - # .. toggle_name: content_tagging.auto # .. toggle_implementation: CourseWaffleFlag # .. toggle_default: False diff --git a/openedx/core/djangoapps/content_tagging/types.py b/openedx/core/djangoapps/content_tagging/types.py index 1b839eb1a0c6..ab2f56c53a75 100644 --- a/openedx/core/djangoapps/content_tagging/types.py +++ b/openedx/core/djangoapps/content_tagging/types.py @@ -5,7 +5,7 @@ from typing import Dict, List, Union -from opaque_keys.edx.keys import CourseKey, UsageKey, CollectionKey, ContainerKey +from opaque_keys.edx.keys import CollectionKey, ContainerKey, CourseKey, UsageKey from opaque_keys.edx.locator import LibraryLocatorV2 from openedx_tagging.models import Taxonomy diff --git a/openedx/core/djangoapps/content_tagging/urls.py b/openedx/core/djangoapps/content_tagging/urls.py index b81c01e1b048..fe04e8072aa2 100644 --- a/openedx/core/djangoapps/content_tagging/urls.py +++ b/openedx/core/djangoapps/content_tagging/urls.py @@ -1,7 +1,7 @@ """ Content Tagging URLs """ -from django.urls import path, include +from django.urls import include, path from .rest_api import urls diff --git a/openedx/core/djangoapps/content_tagging/utils.py b/openedx/core/djangoapps/content_tagging/utils.py index 804754a2ffc1..658f23d16b5d 100644 --- a/openedx/core/djangoapps/content_tagging/utils.py +++ b/openedx/core/djangoapps/content_tagging/utils.py @@ -5,7 +5,7 @@ from edx_django_utils.cache import RequestCache from opaque_keys import InvalidKeyError -from opaque_keys.edx.keys import CourseKey, CollectionKey, ContainerKey, UsageKey +from opaque_keys.edx.keys import CollectionKey, ContainerKey, CourseKey, UsageKey from opaque_keys.edx.locator import LibraryLocatorV2 from openedx_tagging.models import Taxonomy from organizations.models import Organization diff --git a/openedx/core/djangoapps/contentserver/migrations/0001_initial.py b/openedx/core/djangoapps/contentserver/migrations/0001_initial.py index c43f49f8ce97..27755b65609f 100644 --- a/openedx/core/djangoapps/contentserver/migrations/0001_initial.py +++ b/openedx/core/djangoapps/contentserver/migrations/0001_initial.py @@ -1,9 +1,9 @@ #pylint: skip-file -from django.db import migrations, models import django.db.models.deletion from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/contentserver/migrations/0002_cdnuseragentsconfig.py b/openedx/core/djangoapps/contentserver/migrations/0002_cdnuseragentsconfig.py index f0d579ff5a1a..14b25c0da126 100644 --- a/openedx/core/djangoapps/contentserver/migrations/0002_cdnuseragentsconfig.py +++ b/openedx/core/djangoapps/contentserver/migrations/0002_cdnuseragentsconfig.py @@ -1,6 +1,6 @@ -from django.db import migrations, models import django.db.models.deletion from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/contentserver/views.py b/openedx/core/djangoapps/contentserver/views.py index cbdb4124fef7..7225c256b024 100644 --- a/openedx/core/djangoapps/contentserver/views.py +++ b/openedx/core/djangoapps/contentserver/views.py @@ -14,7 +14,7 @@ HttpResponseForbidden, HttpResponseNotFound, HttpResponseNotModified, - HttpResponsePermanentRedirect + HttpResponsePermanentRedirect, ) from django.views.decorators.http import require_safe from edx_django_utils.monitoring import set_custom_attribute diff --git a/openedx/core/djangoapps/cors_csrf/middleware.py b/openedx/core/djangoapps/cors_csrf/middleware.py index 8122231e32ef..1bd8accf2709 100644 --- a/openedx/core/djangoapps/cors_csrf/middleware.py +++ b/openedx/core/djangoapps/cors_csrf/middleware.py @@ -52,7 +52,6 @@ from .helpers import is_cross_domain_request_allowed, skip_cross_domain_referer_check - log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/cors_csrf/migrations/0001_initial.py b/openedx/core/djangoapps/cors_csrf/migrations/0001_initial.py index 46c0f759f559..4c09f5e598de 100644 --- a/openedx/core/djangoapps/cors_csrf/migrations/0001_initial.py +++ b/openedx/core/djangoapps/cors_csrf/migrations/0001_initial.py @@ -1,6 +1,6 @@ -from django.db import migrations, models import django.db.models.deletion from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/cors_csrf/models.py b/openedx/core/djangoapps/cors_csrf/models.py index 386bdf228003..11a287b8dfe6 100644 --- a/openedx/core/djangoapps/cors_csrf/models.py +++ b/openedx/core/djangoapps/cors_csrf/models.py @@ -3,7 +3,6 @@ from config_models.models import ConfigurationModel from django.db import models - from django.utils.translation import gettext_lazy as _ diff --git a/openedx/core/djangoapps/cors_csrf/tests/test_authentication.py b/openedx/core/djangoapps/cors_csrf/tests/test_authentication.py index 1de265b0a81d..3baa9b710f50 100644 --- a/openedx/core/djangoapps/cors_csrf/tests/test_authentication.py +++ b/openedx/core/djangoapps/cors_csrf/tests/test_authentication.py @@ -3,12 +3,11 @@ from unittest.mock import patch +from django.conf import settings from django.middleware.csrf import get_token from django.test import TestCase -from django.test.utils import override_settings from django.test.client import RequestFactory -from django.conf import settings - +from django.test.utils import override_settings from rest_framework.exceptions import PermissionDenied from ..authentication import SessionAuthenticationCrossDomainCsrf diff --git a/openedx/core/djangoapps/cors_csrf/tests/test_middleware.py b/openedx/core/djangoapps/cors_csrf/tests/test_middleware.py index 119824607ded..7f7e7869596c 100644 --- a/openedx/core/djangoapps/cors_csrf/tests/test_middleware.py +++ b/openedx/core/djangoapps/cors_csrf/tests/test_middleware.py @@ -3,18 +3,18 @@ """ -from unittest.mock import patch, Mock +from unittest.mock import Mock, patch + import ddt import pytest -from django.test import TestCase -from django.test.utils import override_settings -from django.core.exceptions import MiddlewareNotUsed, ImproperlyConfigured +from django.core.exceptions import ImproperlyConfigured, MiddlewareNotUsed from django.http import HttpResponse from django.middleware.csrf import CsrfViewMiddleware +from django.test import TestCase +from django.test.utils import override_settings from ..middleware import CorsCSRFMiddleware, CsrfCrossDomainCookieMiddleware - SENTINEL = object() diff --git a/openedx/core/djangoapps/cors_csrf/tests/test_views.py b/openedx/core/djangoapps/cors_csrf/tests/test_views.py index a5f7c31b8800..c780a7fd6acc 100644 --- a/openedx/core/djangoapps/cors_csrf/tests/test_views.py +++ b/openedx/core/djangoapps/cors_csrf/tests/test_views.py @@ -3,12 +3,11 @@ import json -from django.conf import settings -from django.urls import NoReverseMatch, reverse -from django.test import TestCase - import ddt from config_models.models import cache +from django.conf import settings +from django.test import TestCase +from django.urls import NoReverseMatch, reverse from openedx.core.djangolib.testing.utils import skip_unless_lms diff --git a/openedx/core/djangoapps/course_apps/api.py b/openedx/core/djangoapps/course_apps/api.py index acd2c8f552be..74fc157c0ebb 100644 --- a/openedx/core/djangoapps/course_apps/api.py +++ b/openedx/core/djangoapps/course_apps/api.py @@ -3,12 +3,12 @@ """ from django.contrib.auth import get_user_model from opaque_keys.edx.keys import CourseKey + from openedx.core.djangoapps.course_apps.models import CourseAppStatus from .plugins import CourseAppsPluginManager from .signals import COURSE_APP_STATUS_INIT - User = get_user_model() diff --git a/openedx/core/djangoapps/course_apps/handlers.py b/openedx/core/djangoapps/course_apps/handlers.py index c116ffce6557..8a93986a20ee 100644 --- a/openedx/core/djangoapps/course_apps/handlers.py +++ b/openedx/core/djangoapps/course_apps/handlers.py @@ -4,6 +4,7 @@ from django.db import transaction from django.dispatch import receiver from opaque_keys.edx.keys import CourseKey + from xmodule.modulestore.django import SignalHandler from .models import CourseAppStatus diff --git a/openedx/core/djangoapps/course_apps/migrations/0001_initial.py b/openedx/core/djangoapps/course_apps/migrations/0001_initial.py index 2376f9dd9d30..95ae30bbd8b3 100644 --- a/openedx/core/djangoapps/course_apps/migrations/0001_initial.py +++ b/openedx/core/djangoapps/course_apps/migrations/0001_initial.py @@ -1,12 +1,12 @@ # Generated by Django 2.2.24 on 2021-07-13 07:48 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields import opaque_keys.edx.django.models import simple_history.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/course_apps/plugins.py b/openedx/core/djangoapps/course_apps/plugins.py index 183c7a2396d6..0249dacb74ad 100644 --- a/openedx/core/djangoapps/course_apps/plugins.py +++ b/openedx/core/djangoapps/course_apps/plugins.py @@ -1,13 +1,12 @@ """ Course Apps plugin base class and plugin manager. """ +from abc import ABC, abstractmethod from typing import Dict, Iterator, Optional -from abc import ABC, abstractmethod from edx_django_utils.plugins import PluginManager from opaque_keys.edx.keys import CourseKey - # Stevedore extension point namespaces COURSE_APPS_PLUGIN_NAMESPACE = "openedx.course_app" diff --git a/openedx/core/djangoapps/course_apps/rest_api/tests/test_views.py b/openedx/core/djangoapps/course_apps/rest_api/tests/test_views.py index 768643a7a204..b2a509a7ead0 100644 --- a/openedx/core/djangoapps/course_apps/rest_api/tests/test_views.py +++ b/openedx/core/djangoapps/course_apps/rest_api/tests/test_views.py @@ -8,13 +8,14 @@ import ddt from django.test import Client from django.urls import reverse -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student.roles import CourseStaffRole from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangolib.testing.utils import skip_unless_cms +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory + from ...tests.utils import make_test_course_app diff --git a/openedx/core/djangoapps/course_apps/rest_api/urls.py b/openedx/core/djangoapps/course_apps/rest_api/urls.py index c4e47b068b41..c93e2d156e3c 100644 --- a/openedx/core/djangoapps/course_apps/rest_api/urls.py +++ b/openedx/core/djangoapps/course_apps/rest_api/urls.py @@ -2,6 +2,7 @@ API urls for course app v1 APIs. """ from django.urls import include, path + from .v1 import urls as v1_apis urlpatterns = [ diff --git a/openedx/core/djangoapps/course_apps/rest_api/v1/urls.py b/openedx/core/djangoapps/course_apps/rest_api/v1/urls.py index 95d5c6e89fac..8f98c9762b02 100644 --- a/openedx/core/djangoapps/course_apps/rest_api/v1/urls.py +++ b/openedx/core/djangoapps/course_apps/rest_api/v1/urls.py @@ -2,6 +2,7 @@ from django.urls import re_path from openedx.core.constants import COURSE_ID_PATTERN + from .views import CourseAppsView app_name = "openedx.core.djangoapps.course_apps" diff --git a/openedx/core/djangoapps/course_apps/rest_api/v1/views.py b/openedx/core/djangoapps/course_apps/rest_api/v1/views.py index 511dd4d956b4..798ad72f81db 100644 --- a/openedx/core/djangoapps/course_apps/rest_api/v1/views.py +++ b/openedx/core/djangoapps/course_apps/rest_api/v1/views.py @@ -18,6 +18,7 @@ from openedx.core.djangoapps.course_apps.models import CourseAppStatus from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, validate_course_key, verify_course_exists + from ...api import is_course_app_enabled, set_course_app_enabled from ...plugins import CourseApp, CourseAppsPluginManager diff --git a/openedx/core/djangoapps/course_apps/tests/test_api.py b/openedx/core/djangoapps/course_apps/tests/test_api.py index a8a72672ea63..44005a26aab2 100644 --- a/openedx/core/djangoapps/course_apps/tests/test_api.py +++ b/openedx/core/djangoapps/course_apps/tests/test_api.py @@ -7,10 +7,11 @@ import ddt from django.test import TestCase from opaque_keys.edx.locator import CourseLocator + from openedx.core.djangoapps.course_apps.models import CourseAppStatus -from .utils import make_test_course_app from ..api import is_course_app_enabled, set_course_app_enabled +from .utils import make_test_course_app @ddt.ddt diff --git a/openedx/core/djangoapps/course_apps/tests/test_notes_app.py b/openedx/core/djangoapps/course_apps/tests/test_notes_app.py index db2d3563b821..f29fe6bd0f38 100644 --- a/openedx/core/djangoapps/course_apps/tests/test_notes_app.py +++ b/openedx/core/djangoapps/course_apps/tests/test_notes_app.py @@ -8,7 +8,9 @@ from lms.djangoapps.edxnotes.plugins import EdxNotesCourseApp from openedx.core.djangoapps.course_apps.tests.utils import TabBasedCourseAppTestMixin from openedx.core.djangolib.testing.utils import skip_unless_cms -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) @skip_unless_cms diff --git a/openedx/core/djangoapps/course_apps/tests/test_proctoring_app.py b/openedx/core/djangoapps/course_apps/tests/test_proctoring_app.py index 55bea1de4089..08ee2bef7107 100644 --- a/openedx/core/djangoapps/course_apps/tests/test_proctoring_app.py +++ b/openedx/core/djangoapps/course_apps/tests/test_proctoring_app.py @@ -8,7 +8,10 @@ from lms.djangoapps.courseware.plugins import ProctoringCourseApp from openedx.core.djangolib.testing.utils import skip_unless_cms -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, CourseUserType # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order + CourseUserType, + ModuleStoreTestCase, +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/core/djangoapps/course_apps/tests/test_wiki_app.py b/openedx/core/djangoapps/course_apps/tests/test_wiki_app.py index 0119f3a79aca..7359c4dfdfab 100644 --- a/openedx/core/djangoapps/course_apps/tests/test_wiki_app.py +++ b/openedx/core/djangoapps/course_apps/tests/test_wiki_app.py @@ -5,7 +5,9 @@ from lms.djangoapps.course_wiki.plugins.course_app import WikiCourseApp from openedx.core.djangoapps.course_apps.tests.utils import TabBasedCourseAppTestMixin from openedx.core.djangolib.testing.utils import skip_unless_cms -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) @skip_unless_cms diff --git a/openedx/core/djangoapps/course_date_signals/admin.py b/openedx/core/djangoapps/course_date_signals/admin.py index b317a1acc718..3e2f9f06aeb9 100644 --- a/openedx/core/djangoapps/course_date_signals/admin.py +++ b/openedx/core/djangoapps/course_date_signals/admin.py @@ -9,5 +9,4 @@ from .models import SelfPacedRelativeDatesConfig - admin.site.register(SelfPacedRelativeDatesConfig, StackedConfigModelAdmin) diff --git a/openedx/core/djangoapps/course_date_signals/handlers.py b/openedx/core/djangoapps/course_date_signals/handlers.py index 6f3f4ed9a713..50001cc82f0f 100644 --- a/openedx/core/djangoapps/course_date_signals/handlers.py +++ b/openedx/core/djangoapps/course_date_signals/handlers.py @@ -1,8 +1,8 @@ """Signal handlers for writing course dates into edx_when.""" -from datetime import timedelta import logging +from datetime import timedelta from django.dispatch import receiver from edx_when.api import FIELDS_TO_EXTRACT, set_dates_for_course diff --git a/openedx/core/djangoapps/course_date_signals/tests.py b/openedx/core/djangoapps/course_date_signals/tests.py index ee1e95b7b5a2..d9e8801923ec 100644 --- a/openedx/core/djangoapps/course_date_signals/tests.py +++ b/openedx/core/djangoapps/course_date_signals/tests.py @@ -3,17 +3,17 @@ from unittest.mock import patch # lint-amnesty, pylint: disable=wrong-import-order from edx_toggles.toggles.testutils import override_waffle_flag -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory from cms.djangoapps.contentstore.config.waffle import CUSTOM_RELATIVE_DATES from openedx.core.djangoapps.course_date_signals.handlers import ( _gather_graded_items, _get_custom_pacing_children, _has_assignment_blocks, - extract_dates_from_course + extract_dates_from_course, ) from openedx.core.djangoapps.course_date_signals.models import SelfPacedRelativeDatesConfig +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory from . import utils diff --git a/openedx/core/djangoapps/course_date_signals/utils.py b/openedx/core/djangoapps/course_date_signals/utils.py index 21789cdcfd7f..7a3db05f5dec 100644 --- a/openedx/core/djangoapps/course_date_signals/utils.py +++ b/openedx/core/djangoapps/course_date_signals/utils.py @@ -7,8 +7,9 @@ from datetime import timedelta from django.conf import settings -from openedx.core.djangoapps.catalog.utils import get_course_run_details + from openedx.core.djangoapps.catalog.models import CatalogIntegration +from openedx.core.djangoapps.catalog.utils import get_course_run_details MIN_DURATION = timedelta(weeks=settings.COURSE_ACCESS_DURATION_MIN_WEEKS) MAX_DURATION = timedelta(weeks=settings.COURSE_ACCESS_DURATION_MAX_WEEKS) diff --git a/openedx/core/djangoapps/course_groups/cohorts.py b/openedx/core/djangoapps/course_groups/cohorts.py index a90ee4cb7b18..4766dd1a9f73 100644 --- a/openedx/core/djangoapps/course_groups/cohorts.py +++ b/openedx/core/djangoapps/course_groups/cohorts.py @@ -18,10 +18,10 @@ from edx_django_utils.cache import RequestCache from eventtracking import tracker +from common.djangoapps.student.models import get_user_by_username_or_email from lms.djangoapps.courseware import courses from openedx.core.lib.cache_utils import request_cached from openedx.core.lib.courses import get_course_by_id -from common.djangoapps.student.models import get_user_by_username_or_email from .models import ( CohortMembership, @@ -29,7 +29,7 @@ CourseCohortsSettings, CourseUserGroup, CourseUserGroupPartitionGroup, - UnregisteredLearnerCohortAssignments + UnregisteredLearnerCohortAssignments, ) from .signals.signals import COHORT_MEMBERSHIP_UPDATED diff --git a/openedx/core/djangoapps/course_groups/migrations/0001_initial.py b/openedx/core/djangoapps/course_groups/migrations/0001_initial.py index 7c76c121d957..06a704e8a0d2 100644 --- a/openedx/core/djangoapps/course_groups/migrations/0001_initial.py +++ b/openedx/core/djangoapps/course_groups/migrations/0001_initial.py @@ -1,5 +1,5 @@ -from django.db import migrations, models from django.conf import settings +from django.db import migrations, models from opaque_keys.edx.django.models import CourseKeyField diff --git a/openedx/core/djangoapps/course_groups/models.py b/openedx/core/djangoapps/course_groups/models.py index b8e91800665a..1e18378fbd27 100644 --- a/openedx/core/djangoapps/course_groups/models.py +++ b/openedx/core/djangoapps/course_groups/models.py @@ -11,15 +11,20 @@ from django.db import models, transaction from django.db.models.signals import pre_delete from django.dispatch import receiver - from opaque_keys.edx.django.models import CourseKeyField +from openedx_events.learning.data import ( # lint-amnesty, pylint: disable=wrong-import-order + CohortData, + CourseData, + UserData, + UserPersonalData, +) +from openedx_events.learning.signals import ( + COHORT_MEMBERSHIP_CHANGED, # lint-amnesty, pylint: disable=wrong-import-order +) from openedx_filters.learning.filters import CohortAssignmentRequested, CohortChangeRequested from openedx.core.djangolib.model_mixins import DeletableByUserValue -from openedx_events.learning.data import CohortData, CourseData, UserData, UserPersonalData # lint-amnesty, pylint: disable=wrong-import-order -from openedx_events.learning.signals import COHORT_MEMBERSHIP_CHANGED # lint-amnesty, pylint: disable=wrong-import-order - log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/course_groups/partition_scheme.py b/openedx/core/djangoapps/course_groups/partition_scheme.py index 60e7c5f915c2..9be2be5bf67d 100644 --- a/openedx/core/djangoapps/course_groups/partition_scheme.py +++ b/openedx/core/djangoapps/course_groups/partition_scheme.py @@ -8,9 +8,11 @@ from lms.djangoapps.courseware.masquerade import ( get_course_masquerade, get_masquerading_user_group, - is_masquerading_as_specific_student + is_masquerading_as_specific_student, +) +from xmodule.partitions.partitions import ( + NoSuchUserPartitionGroupError, # lint-amnesty, pylint: disable=wrong-import-order ) -from xmodule.partitions.partitions import NoSuchUserPartitionGroupError # lint-amnesty, pylint: disable=wrong-import-order from .cohorts import get_cohort, get_group_info_for_cohort diff --git a/openedx/core/djangoapps/course_groups/permissions.py b/openedx/core/djangoapps/course_groups/permissions.py index 7229d6fba4aa..cfc3aefb2f8c 100644 --- a/openedx/core/djangoapps/course_groups/permissions.py +++ b/openedx/core/djangoapps/course_groups/permissions.py @@ -5,11 +5,13 @@ from opaque_keys.edx.keys import CourseKey from rest_framework import permissions +from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole, GlobalStaff +from lms.djangoapps.discussion.django_comment_client.utils import get_user_role_names from openedx.core.djangoapps.django_comment_common.models import ( - FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_MODERATOR + FORUM_ROLE_ADMINISTRATOR, + FORUM_ROLE_COMMUNITY_TA, + FORUM_ROLE_MODERATOR, ) -from common.djangoapps.student.roles import CourseStaffRole, GlobalStaff, CourseInstructorRole -from lms.djangoapps.discussion.django_comment_client.utils import get_user_role_names class IsStaffOrAdmin(permissions.BasePermission): diff --git a/openedx/core/djangoapps/course_groups/rest_api/views.py b/openedx/core/djangoapps/course_groups/rest_api/views.py index 47631a64e2bb..9bf884b6a22d 100644 --- a/openedx/core/djangoapps/course_groups/rest_api/views.py +++ b/openedx/core/djangoapps/course_groups/rest_api/views.py @@ -15,7 +15,7 @@ from openedx.core.djangoapps.course_groups.partition_scheme import get_cohorted_user_partition from openedx.core.djangoapps.course_groups.rest_api.serializers import ( ContentGroupConfigurationSerializer, - ContentGroupsListResponseSerializer + ContentGroupsListResponseSerializer, ) from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin diff --git a/openedx/core/djangoapps/course_groups/tests/test_api_views.py b/openedx/core/djangoapps/course_groups/tests/test_api_views.py index 46d6a3399a0b..fe8b3614f5bc 100644 --- a/openedx/core/djangoapps/course_groups/tests/test_api_views.py +++ b/openedx/core/djangoapps/course_groups/tests/test_api_views.py @@ -8,15 +8,16 @@ import ddt from django.urls import reverse -from openedx.core.djangoapps.oauth_dispatch.tests.factories import ApplicationFactory, AccessTokenFactory -from openedx.core.djangolib.testing.utils import skip_unless_lms from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order - from openedx.core.djangoapps.course_groups import cohorts -from openedx.core.djangoapps.course_groups.views import link_cohort_to_partition_group from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory +from openedx.core.djangoapps.course_groups.views import link_cohort_to_partition_group +from openedx.core.djangoapps.oauth_dispatch.tests.factories import AccessTokenFactory, ApplicationFactory +from openedx.core.djangolib.testing.utils import skip_unless_lms +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order USERNAME = 'honor' USER_MAIL = 'honor@example.com' diff --git a/openedx/core/djangoapps/course_groups/tests/test_cohorts.py b/openedx/core/djangoapps/course_groups/tests/test_cohorts.py index 910eff2b0d01..c18524b38668 100644 --- a/openedx/core/djangoapps/course_groups/tests/test_cohorts.py +++ b/openedx/core/djangoapps/course_groups/tests/test_cohorts.py @@ -4,8 +4,9 @@ # pylint: disable=no-member from unittest.mock import call, patch -import pytest + import ddt +import pytest from django.contrib.auth.models import AnonymousUser, User # lint-amnesty, pylint: disable=imported-auth-user from django.db import IntegrityError from django.http import Http404 @@ -17,7 +18,10 @@ from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order + TEST_DATA_SPLIT_MODULESTORE, + ModuleStoreTestCase, +) from xmodule.modulestore.tests.factories import ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order from .. import cohorts diff --git a/openedx/core/djangoapps/course_groups/tests/test_events.py b/openedx/core/djangoapps/course_groups/tests/test_events.py index f11e95088fd0..055dc94106dd 100644 --- a/openedx/core/djangoapps/course_groups/tests/test_events.py +++ b/openedx/core/djangoapps/course_groups/tests/test_events.py @@ -4,21 +4,28 @@ Classes: CohortEventTest: Test event sent after cohort membership changes. """ -from openedx.core.djangoapps.course_groups.models import CohortMembership from unittest.mock import Mock # lint-amnesty, pylint: disable=wrong-import-order -from openedx_events.learning.data import CohortData, CourseData, UserData, UserPersonalData # lint-amnesty, pylint: disable=wrong-import-order -from openedx_events.learning.signals import COHORT_MEMBERSHIP_CHANGED # lint-amnesty, pylint: disable=wrong-import-order +from openedx_events.learning.data import ( # lint-amnesty, pylint: disable=wrong-import-order + CohortData, + CourseData, + UserData, + UserPersonalData, +) +from openedx_events.learning.signals import ( + COHORT_MEMBERSHIP_CHANGED, # lint-amnesty, pylint: disable=wrong-import-order +) from openedx_events.tests.utils import OpenEdxEventsTestMixin # lint-amnesty, pylint: disable=wrong-import-order from common.djangoapps.student.tests.factories import UserFactory +from common.test.utils import assert_dict_contains_subset from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory -from openedx.core.djangolib.testing.utils import skip_unless_lms - +from openedx.core.djangoapps.course_groups.models import CohortMembership from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory - -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from common.test.utils import assert_dict_contains_subset +from openedx.core.djangolib.testing.utils import skip_unless_lms +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) @skip_unless_lms diff --git a/openedx/core/djangoapps/course_groups/tests/test_filters.py b/openedx/core/djangoapps/course_groups/tests/test_filters.py index f51818d676bf..3ae8ff14c7b6 100755 --- a/openedx/core/djangoapps/course_groups/tests/test_filters.py +++ b/openedx/core/djangoapps/course_groups/tests/test_filters.py @@ -4,7 +4,6 @@ from django.test import override_settings from openedx_filters import PipelineStep from openedx_filters.learning.filters import CohortAssignmentRequested, CohortChangeRequested -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory @@ -15,6 +14,7 @@ ) from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory from openedx.core.djangolib.testing.utils import skip_unless_lms +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase class TestCohortChangeStep(PipelineStep): diff --git a/openedx/core/djangoapps/course_groups/tests/test_partition_scheme.py b/openedx/core/djangoapps/course_groups/tests/test_partition_scheme.py index 1b6a4bdb18ae..dc047ee6b535 100644 --- a/openedx/core/djangoapps/course_groups/tests/test_partition_scheme.py +++ b/openedx/core/djangoapps/course_groups/tests/test_partition_scheme.py @@ -5,16 +5,24 @@ from unittest.mock import patch + import django.test +from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.courseware.tests.test_masquerade import StaffMasqueradeTestCase from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.tests.factories import UserFactory from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order + TEST_DATA_SPLIT_MODULESTORE, + ModuleStoreTestCase, +) from xmodule.modulestore.tests.factories import ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions import Group, UserPartition, UserPartitionError # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.partitions.partitions import ( # lint-amnesty, pylint: disable=wrong-import-order + Group, + UserPartition, + UserPartitionError, +) from ..cohorts import add_user_to_cohort, get_course_cohorts, remove_user_from_cohort from ..models import CourseUserGroupPartitionGroup diff --git a/openedx/core/djangoapps/course_groups/tests/test_views.py b/openedx/core/djangoapps/course_groups/tests/test_views.py index b4eaad513923..7fe2f5fae759 100644 --- a/openedx/core/djangoapps/course_groups/tests/test_views.py +++ b/openedx/core/djangoapps/course_groups/tests/test_views.py @@ -7,18 +7,19 @@ import json from collections import namedtuple + import pytest from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.http import Http404 from django.test.client import RequestFactory from opaque_keys.edx.locator import CourseLocator -from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.tests.factories import InstructorFactory -from common.djangoapps.student.tests.factories import StaffFactory -from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from common.djangoapps.student.tests.factories import InstructorFactory, StaffFactory, UserFactory +from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..cohorts import DEFAULT_COHORT_NAME, get_cohort, get_cohort_by_id, get_cohort_by_name, get_group_info_for_cohort @@ -29,7 +30,7 @@ course_cohort_settings_handler, link_cohort_to_partition_group, remove_user_from_cohort, - users_in_cohort + users_in_cohort, ) from .helpers import CohortFactory, CourseCohortFactory, config_course_cohorts, config_course_cohorts_legacy diff --git a/openedx/core/djangoapps/course_groups/views.py b/openedx/core/djangoapps/course_groups/views.py index 4f63335cb8a6..ad9d973af3da 100644 --- a/openedx/core/djangoapps/course_groups/views.py +++ b/openedx/core/djangoapps/course_groups/views.py @@ -24,8 +24,10 @@ from rest_framework.response import Response from rest_framework.serializers import Serializer -from lms.djangoapps.courseware.courses import get_course, get_course_with_access from common.djangoapps.edxmako.shortcuts import render_to_response +from common.djangoapps.student.auth import has_course_author_access +from common.djangoapps.util.json_request import JsonResponse, expect_json +from lms.djangoapps.courseware.courses import get_course, get_course_with_access from openedx.core.djangoapps.course_groups.models import ( CohortAssignmentNotAllowed, CohortChangeNotAllowed, @@ -34,8 +36,6 @@ from openedx.core.djangoapps.course_groups.permissions import IsStaffOrAdmin from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin -from common.djangoapps.student.auth import has_course_author_access -from common.djangoapps.util.json_request import JsonResponse, expect_json from . import api, cohorts from .models import CourseUserGroup, CourseUserGroupPartitionGroup diff --git a/openedx/core/djangoapps/course_live/migrations/0001_initial.py b/openedx/core/djangoapps/course_live/migrations/0001_initial.py index 7deb99f9f4bf..fceb3ec249d8 100644 --- a/openedx/core/djangoapps/course_live/migrations/0001_initial.py +++ b/openedx/core/djangoapps/course_live/migrations/0001_initial.py @@ -1,12 +1,12 @@ # Generated by Django 3.2.12 on 2022-02-23 08:07 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields import opaque_keys.edx.django.models import simple_history.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/course_live/plugins.py b/openedx/core/djangoapps/course_live/plugins.py index c211e27a61b0..9facb8e6bc4b 100644 --- a/openedx/core/djangoapps/course_live/plugins.py +++ b/openedx/core/djangoapps/course_live/plugins.py @@ -2,8 +2,8 @@ Course app configuration for live. """ from typing import Dict, Optional -from django.conf import settings +from django.conf import settings from django.contrib.auth import get_user_model from django.utils.translation import gettext_noop as _ from lti_consumer.models import LtiConfiguration diff --git a/openedx/core/djangoapps/course_live/providers.py b/openedx/core/djangoapps/course_live/providers.py index 5379ae260b7a..76e8728e19a5 100644 --- a/openedx/core/djangoapps/course_live/providers.py +++ b/openedx/core/djangoapps/course_live/providers.py @@ -2,7 +2,8 @@ LTI Providers for course live module """ from abc import ABC -from typing import List, Dict +from typing import Dict, List + from django.conf import settings diff --git a/openedx/core/djangoapps/course_live/tests/test_views.py b/openedx/core/djangoapps/course_live/tests/test_views.py index 97ed4c9ce194..25063b07b97f 100644 --- a/openedx/core/djangoapps/course_live/tests/test_views.py +++ b/openedx/core/djangoapps/course_live/tests/test_views.py @@ -2,12 +2,14 @@ Test for course live app views """ import json + import ddt from django.test import RequestFactory from django.urls import reverse from lti_consumer.models import CourseAllowPIISharingInLTIFlag, LtiConfiguration from markupsafe import Markup from rest_framework.test import APITestCase + from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import CourseUserType, ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/openedx/core/djangoapps/course_live/urls.py b/openedx/core/djangoapps/course_live/urls.py index e8fa2fc1d500..d39fdc4b445a 100644 --- a/openedx/core/djangoapps/course_live/urls.py +++ b/openedx/core/djangoapps/course_live/urls.py @@ -9,7 +9,7 @@ from openedx.core.djangoapps.course_live.views import ( CourseLiveConfigurationView, CourseLiveIframeView, - CourseLiveProvidersView + CourseLiveProvidersView, ) urlpatterns = [ diff --git a/openedx/core/djangoapps/course_live/views.py b/openedx/core/djangoapps/course_live/views.py index d148e9301897..59e8459134cd 100644 --- a/openedx/core/djangoapps/course_live/views.py +++ b/openedx/core/djangoapps/course_live/views.py @@ -19,9 +19,10 @@ from openedx.core.djangoapps.course_live.permissions import IsEnrolledOrStaff, IsStaffOrInstructor from openedx.core.djangoapps.course_live.tab import CourseLiveTab from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser -from .providers import ProviderManager + from ...lib.api.view_utils import verify_course_exists from .models import CourseLiveConfiguration +from .providers import ProviderManager from .serializers import CourseLiveConfigurationSerializer diff --git a/openedx/core/djangoapps/courseware_api/serializers.py b/openedx/core/djangoapps/courseware_api/serializers.py index c4b6476cb764..dcfc421fde8d 100644 --- a/openedx/core/djangoapps/courseware_api/serializers.py +++ b/openedx/core/djangoapps/courseware_api/serializers.py @@ -4,8 +4,8 @@ from rest_framework import serializers -from lms.djangoapps.course_home_api.progress.serializers import CertificateDataSerializer from lms.djangoapps.course_home_api.outline.serializers import CourseGoalsSerializer +from lms.djangoapps.course_home_api.progress.serializers import CertificateDataSerializer from openedx.core.lib.api.fields import AbsoluteURLField diff --git a/openedx/core/djangoapps/courseware_api/tests/pacts/verify_pact.py b/openedx/core/djangoapps/courseware_api/tests/pacts/verify_pact.py index 10c209d08542..0f0b1e4ef3f5 100644 --- a/openedx/core/djangoapps/courseware_api/tests/pacts/verify_pact.py +++ b/openedx/core/djangoapps/courseware_api/tests/pacts/verify_pact.py @@ -10,7 +10,6 @@ from openedx.features.discounts.applicability import DISCOUNT_APPLICABILITY_FLAG - log = logging.getLogger(__name__) logging.basicConfig(level=logging.DEBUG) diff --git a/openedx/core/djangoapps/courseware_api/tests/pacts/views.py b/openedx/core/djangoapps/courseware_api/tests/pacts/views.py index 11abeac9cc5c..c7a6c2400c0d 100644 --- a/openedx/core/djangoapps/courseware_api/tests/pacts/views.py +++ b/openedx/core/djangoapps/courseware_api/tests/pacts/views.py @@ -8,13 +8,13 @@ from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST from opaque_keys.edx.keys import CourseKey, UsageKey -from xmodule.modulestore.tests.django_utils import ModuleStoreIsolationMixin -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory, ToyCourseFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory from common.djangoapps.student.models import CourseEnrollment from openedx.features.course_duration_limits.models import CourseDurationLimitConfig +from xmodule.modulestore.tests.django_utils import ModuleStoreIsolationMixin +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory, ToyCourseFactory class ProviderState(ModuleStoreIsolationMixin): diff --git a/openedx/core/djangoapps/courseware_api/tests/test_views.py b/openedx/core/djangoapps/courseware_api/tests/test_views.py index 62fd6d557b34..b921d26e8b2a 100644 --- a/openedx/core/djangoapps/courseware_api/tests/test_views.py +++ b/openedx/core/djangoapps/courseware_api/tests/test_views.py @@ -3,9 +3,9 @@ """ from datetime import datetime, timedelta -from urllib.parse import urlencode from typing import Optional from unittest import mock +from urllib.parse import urlencode import ddt from completion.test_utils import CompletionWaffleTestMixin, submit_completions_for_testing @@ -13,39 +13,37 @@ from django.contrib.auth import get_user_model from django.test import override_settings from django.test.client import RequestFactory - from edx_django_utils.cache import TieredCache from edx_toggles.toggles.testutils import override_waffle_flag, override_waffle_switch -from xmodule.data import CertificatesDisplayBehaviors -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import BlockFactory, ToyCourseFactory -from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory +from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentCelebration +from common.djangoapps.student.roles import CourseInstructorRole +from common.djangoapps.student.tests.factories import CourseEnrollmentCelebrationFactory, UserFactory from lms.djangoapps.certificates.api import get_certificate_url from lms.djangoapps.certificates.tests.factories import ( - GeneratedCertificateFactory, LinkedInAddToProfileConfigurationFactory + GeneratedCertificateFactory, + LinkedInAddToProfileConfigurationFactory, ) from lms.djangoapps.courseware.access_utils import ACCESS_DENIED, ACCESS_GRANTED from lms.djangoapps.courseware.models import LastSeenCoursewareTimezone from lms.djangoapps.courseware.tabs import ExternalLinkCourseTab from lms.djangoapps.courseware.tests.helpers import MasqueradeMixin from lms.djangoapps.courseware.toggles import ( + COURSEWARE_MFE_MILESTONES_STREAK_DISCOUNT, COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES, COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES_STREAK_CELEBRATION, ) -from lms.djangoapps.courseware.toggles import COURSEWARE_MFE_MILESTONES_STREAK_DISCOUNT from lms.djangoapps.verify_student.services import IDVerificationService -from common.djangoapps.student.models import ( - CourseEnrollment, CourseEnrollmentCelebration -) -from common.djangoapps.student.roles import CourseInstructorRole -from common.djangoapps.student.tests.factories import CourseEnrollmentCelebrationFactory, UserFactory from openedx.core.djangoapps.agreements.api import create_integrity_signature from openedx.core.djangolib.testing.utils import skip_unless_lms from openedx.features.course_experience.waffle import ENABLE_COURSE_ABOUT_SIDEBAR_HTML +from xmodule.data import CertificatesDisplayBehaviors +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, ToyCourseFactory +from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID User = get_user_model() diff --git a/openedx/core/djangoapps/courseware_api/views.py b/openedx/core/djangoapps/courseware_api/views.py index 3ad5430c774a..e9586930f75c 100644 --- a/openedx/core/djangoapps/courseware_api/views.py +++ b/openedx/core/djangoapps/courseware_api/views.py @@ -19,44 +19,42 @@ from rest_framework.response import Response from rest_framework.views import APIView -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.exceptions import ItemNotFoundError, NoPathToItem -from xmodule.modulestore.search import path_to_location -from xmodule.x_module import PUBLIC_VIEW, STUDENT_VIEW - from common.djangoapps.course_modes.models import CourseMode, get_course_prices +from common.djangoapps.student.models import ( + CourseEnrollment, + CourseEnrollmentCelebration, + LinkedInAddToProfileConfiguration, +) +from common.djangoapps.util.milestones_helpers import get_prerequisite_courses_display from common.djangoapps.util.views import expose_header -from lms.djangoapps.edxnotes.helpers import is_feature_enabled from lms.djangoapps.certificates.api import get_certificate_url, get_eligible_certificate from lms.djangoapps.commerce.utils import EcommerceService from lms.djangoapps.course_api.api import course_detail -from lms.djangoapps.course_goals.models import UserActivity from lms.djangoapps.course_goals.api import get_course_goal +from lms.djangoapps.course_goals.models import UserActivity from lms.djangoapps.courseware.access import has_access from lms.djangoapps.courseware.access_utils import check_public_access +from lms.djangoapps.courseware.block_render import get_block_by_usage_id +from lms.djangoapps.courseware.context_processor import user_timezone_locale_prefs from lms.djangoapps.courseware.courses import ( get_course_about_section, get_course_with_access, get_permission_for_course_about, ) - -from lms.djangoapps.courseware.context_processor import user_timezone_locale_prefs from lms.djangoapps.courseware.entrance_exams import course_has_entrance_exam, user_has_passed_entrance_exam from lms.djangoapps.courseware.masquerade import ( + is_masquerading_as_non_audit_enrollment, is_masquerading_as_specific_student, setup_masquerade, - is_masquerading_as_non_audit_enrollment, ) from lms.djangoapps.courseware.models import LastSeenCoursewareTimezone from lms.djangoapps.courseware.permissions import VIEW_COURSEWARE -from lms.djangoapps.courseware.block_render import get_block_by_usage_id from lms.djangoapps.courseware.toggles import course_exit_page_is_active, course_is_invitation_only from lms.djangoapps.courseware.views.views import get_cert_data +from lms.djangoapps.edxnotes.helpers import is_feature_enabled from lms.djangoapps.gating.api import get_entrance_exam_score, get_entrance_exam_usage_key from lms.djangoapps.grades.api import CourseGradeFactory from lms.djangoapps.instructor.enrollment import uses_shib -from common.djangoapps.util.milestones_helpers import get_prerequisite_courses_display from lms.djangoapps.verify_student.services import IDVerificationService from openedx.core.djangoapps.agreements.api import get_integrity_signature from openedx.core.djangoapps.courseware_api.utils import get_celebrations_dict @@ -66,20 +64,17 @@ from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin from openedx.core.lib.courses import get_course_by_id -from openedx.features.course_experience import ENABLE_COURSE_GOALS -from openedx.features.course_experience.waffle import ENABLE_COURSE_ABOUT_SIDEBAR_HTML from openedx.features.content_type_gating.models import ContentTypeGatingConfig from openedx.features.course_duration_limits.access import get_access_expiration_data +from openedx.features.course_experience import ENABLE_COURSE_GOALS +from openedx.features.course_experience.waffle import ENABLE_COURSE_ABOUT_SIDEBAR_HTML from openedx.features.discounts.utils import generate_offer_data -from common.djangoapps.student.models import ( - CourseEnrollment, - CourseEnrollmentCelebration, - LinkedInAddToProfileConfiguration -) -from xmodule.course_block import ( - COURSE_VISIBILITY_PUBLIC, - COURSE_VISIBILITY_PUBLIC_OUTLINE, -) +from xmodule.course_block import COURSE_VISIBILITY_PUBLIC, COURSE_VISIBILITY_PUBLIC_OUTLINE +from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.exceptions import ItemNotFoundError, NoPathToItem +from xmodule.modulestore.search import path_to_location +from xmodule.x_module import PUBLIC_VIEW, STUDENT_VIEW from .serializers import CourseInfoSerializer diff --git a/openedx/core/djangoapps/crawlers/migrations/0001_initial.py b/openedx/core/djangoapps/crawlers/migrations/0001_initial.py index 336b31e1a8aa..2293e58c2f4c 100644 --- a/openedx/core/djangoapps/crawlers/migrations/0001_initial.py +++ b/openedx/core/djangoapps/crawlers/migrations/0001_initial.py @@ -1,6 +1,6 @@ -from django.db import migrations, models import django.db.models.deletion from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/crawlers/tests/test_models.py b/openedx/core/djangoapps/crawlers/tests/test_models.py index e7813faa467c..e1bd03879c99 100644 --- a/openedx/core/djangoapps/crawlers/tests/test_models.py +++ b/openedx/core/djangoapps/crawlers/tests/test_models.py @@ -4,8 +4,9 @@ import ddt -from django.test import TestCase from django.http import HttpRequest +from django.test import TestCase + from ..models import CrawlersConfig diff --git a/openedx/core/djangoapps/credentials/apps.py b/openedx/core/djangoapps/credentials/apps.py index b70cf0461db9..89fd1c43791b 100644 --- a/openedx/core/djangoapps/credentials/apps.py +++ b/openedx/core/djangoapps/credentials/apps.py @@ -44,4 +44,6 @@ class CredentialsConfig(AppConfig): def ready(self): # Register celery workers - from openedx.core.djangoapps.credentials.tasks.v1 import tasks # lint-amnesty, pylint: disable=unused-import, unused-variable + from openedx.core.djangoapps.credentials.tasks.v1 import ( # lint-amnesty, pylint: disable=unused-import, unused-variable + tasks, + ) diff --git a/openedx/core/djangoapps/credentials/management/commands/create_credentials_api_configuration.py b/openedx/core/djangoapps/credentials/management/commands/create_credentials_api_configuration.py index 95fb0ebbfa9e..8a4102246cab 100644 --- a/openedx/core/djangoapps/credentials/management/commands/create_credentials_api_configuration.py +++ b/openedx/core/djangoapps/credentials/management/commands/create_credentials_api_configuration.py @@ -2,6 +2,7 @@ Django management command used to enable Credentials functionality in this Open edX instance. """ from django.core.management.base import BaseCommand, CommandError + from openedx.core.djangoapps.credentials.models import CredentialsApiConfig diff --git a/openedx/core/djangoapps/credentials/management/commands/notify_credentials.py b/openedx/core/djangoapps/credentials/management/commands/notify_credentials.py index 374975cf3ae7..2c418bb09ec7 100644 --- a/openedx/core/djangoapps/credentials/management/commands/notify_credentials.py +++ b/openedx/core/djangoapps/credentials/management/commands/notify_credentials.py @@ -10,7 +10,6 @@ import logging import shlex - from datetime import datetime, timedelta from zoneinfo import ZoneInfo @@ -20,12 +19,12 @@ from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey -from openedx.core.djangoapps.credentials.models import NotifyCredentialsConfig -from openedx.core.djangoapps.credentials.tasks.v1.tasks import handle_notify_credentials from openedx.core.djangoapps.catalog.api import ( - get_programs_from_cache_by_uuid, get_course_run_key_for_program_from_cache, + get_programs_from_cache_by_uuid, ) +from openedx.core.djangoapps.credentials.models import NotifyCredentialsConfig +from openedx.core.djangoapps.credentials.tasks.v1.tasks import handle_notify_credentials log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/credentials/management/commands/tests/test_create_credentials_api_configuration.py b/openedx/core/djangoapps/credentials/management/commands/tests/test_create_credentials_api_configuration.py index 9aea1e25ea63..60dc873251e2 100644 --- a/openedx/core/djangoapps/credentials/management/commands/tests/test_create_credentials_api_configuration.py +++ b/openedx/core/djangoapps/credentials/management/commands/tests/test_create_credentials_api_configuration.py @@ -2,9 +2,8 @@ Tests for the create_credentials_api_configuration command """ -from unittest import TestCase +from unittest import TestCase, mock -from unittest import mock import pytest from django.core.management import call_command diff --git a/openedx/core/djangoapps/credentials/management/commands/tests/test_notify_credentials.py b/openedx/core/djangoapps/credentials/management/commands/tests/test_notify_credentials.py index f7bed3446aca..0ea139a5e8ce 100644 --- a/openedx/core/djangoapps/credentials/management/commands/tests/test_notify_credentials.py +++ b/openedx/core/djangoapps/credentials/management/commands/tests/test_notify_credentials.py @@ -10,11 +10,11 @@ from django.test import TestCase, override_settings from freezegun import freeze_time -from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory, CourseFactory, CourseRunFactory +from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.catalog.tests.factories import CourseFactory, CourseRunFactory, ProgramFactory from openedx.core.djangoapps.credentials.models import NotifyCredentialsConfig from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.tests.factories import UserFactory from ..notify_credentials import Command diff --git a/openedx/core/djangoapps/credentials/models.py b/openedx/core/djangoapps/credentials/models.py index 716d0e96aeec..760d24d112cb 100644 --- a/openedx/core/djangoapps/credentials/models.py +++ b/openedx/core/djangoapps/credentials/models.py @@ -8,7 +8,6 @@ from config_models.models import ConfigurationModel from django.conf import settings from django.db import models - from django.utils.translation import gettext_lazy as _ from openedx.core.djangoapps.site_configuration import helpers diff --git a/openedx/core/djangoapps/credentials/tasks/v1/tasks.py b/openedx/core/djangoapps/credentials/tasks/v1/tasks.py index 603ab88e9255..953d138cbfc9 100644 --- a/openedx/core/djangoapps/credentials/tasks/v1/tasks.py +++ b/openedx/core/djangoapps/credentials/tasks/v1/tasks.py @@ -16,16 +16,13 @@ from opaque_keys.edx.keys import CourseKey from common.djangoapps.course_modes.models import CourseMode -from lms.djangoapps.certificates.api import ( - get_generated_certificate, - get_recently_modified_certificates -) +from lms.djangoapps.certificates.api import get_generated_certificate, get_recently_modified_certificates from lms.djangoapps.certificates.data import CertificateStatuses from lms.djangoapps.grades.api import CourseGradeFactory, get_recently_modified_grades from openedx.core.djangoapps.catalog.utils import get_programs from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from openedx.core.djangoapps.credentials.helpers import is_learner_records_enabled_for_org from openedx.core.djangoapps.credentials.api import is_credentials_enabled +from openedx.core.djangoapps.credentials.helpers import is_learner_records_enabled_for_org from openedx.core.djangoapps.credentials.utils import get_credentials_api_base_url, get_credentials_api_client from openedx.core.djangoapps.programs.signals import ( handle_course_cert_awarded, diff --git a/openedx/core/djangoapps/credentials/tests/test_signals.py b/openedx/core/djangoapps/credentials/tests/test_signals.py index cd1771fb9204..e24408bfeb65 100644 --- a/openedx/core/djangoapps/credentials/tests/test_signals.py +++ b/openedx/core/djangoapps/credentials/tests/test_signals.py @@ -6,12 +6,16 @@ from django.conf import settings # lint-amnesty, pylint: disable=unused-import from django.test import TestCase, override_settings # lint-amnesty, pylint: disable=unused-import +from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory as XModuleCourseFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( + CourseFactory as XModuleCourseFactory, # lint-amnesty, pylint: disable=wrong-import-order +) SIGNALS_MODULE = 'openedx.core.djangoapps.credentials.signals' diff --git a/openedx/core/djangoapps/credentials/tests/test_tasks.py b/openedx/core/djangoapps/credentials/tests/test_tasks.py index 6fb752302bd1..0f390b4f0f64 100644 --- a/openedx/core/djangoapps/credentials/tests/test_tasks.py +++ b/openedx/core/djangoapps/credentials/tests/test_tasks.py @@ -3,8 +3,8 @@ """ import logging +from datetime import datetime, timedelta, timezone from unittest import mock -from datetime import datetime, timezone, timedelta import ddt import pytest @@ -19,10 +19,10 @@ from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.certificates.api import get_recently_modified_certificates from lms.djangoapps.certificates.data import CertificateStatuses +from lms.djangoapps.certificates.tests.factories import CertificateDateOverrideFactory, GeneratedCertificateFactory from lms.djangoapps.grades.models import PersistentCourseGrade from lms.djangoapps.grades.models_api import get_recently_modified_grades from lms.djangoapps.grades.tests.utils import mock_passing_grade -from lms.djangoapps.certificates.tests.factories import CertificateDateOverrideFactory, GeneratedCertificateFactory from openedx.core.djangoapps.catalog.tests.factories import CourseFactory, CourseRunFactory, ProgramFactory from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangoapps.credentials.helpers import is_learner_records_enabled @@ -31,7 +31,6 @@ from openedx.core.djangolib.testing.utils import skip_unless_lms from xmodule.data import CertificatesDisplayBehaviors - User = get_user_model() LOGGER_NAME = "openedx.core.djangoapps.credentials.tasks.v1.tasks" TASKS_MODULE = 'openedx.core.djangoapps.credentials.tasks.v1.tasks' diff --git a/openedx/core/djangoapps/credentials/tests/test_utils.py b/openedx/core/djangoapps/credentials/tests/test_utils.py index 17ea280537c3..056ab357563b 100644 --- a/openedx/core/djangoapps/credentials/tests/test_utils.py +++ b/openedx/core/djangoapps/credentials/tests/test_utils.py @@ -7,10 +7,7 @@ from openedx.core.djangoapps.credentials.models import CredentialsApiConfig from openedx.core.djangoapps.credentials.tests import factories from openedx.core.djangoapps.credentials.tests.mixins import CredentialsApiConfigMixin -from openedx.core.djangoapps.credentials.utils import ( - get_credentials, - get_credentials_records_url, -) +from openedx.core.djangoapps.credentials.utils import get_credentials, get_credentials_records_url from openedx.core.djangoapps.oauth_dispatch.tests.factories import ApplicationFactory from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms diff --git a/openedx/core/djangoapps/credit/admin.py b/openedx/core/djangoapps/credit/admin.py index 6431fbaaf7b2..06c9f3f9dac8 100644 --- a/openedx/core/djangoapps/credit/admin.py +++ b/openedx/core/djangoapps/credit/admin.py @@ -12,7 +12,7 @@ CreditProvider, CreditRequest, CreditRequirement, - CreditRequirementStatus + CreditRequirementStatus, ) diff --git a/openedx/core/djangoapps/credit/api/eligibility.py b/openedx/core/djangoapps/credit/api/eligibility.py index 79546aa0b4fd..c9645dcf0361 100644 --- a/openedx/core/djangoapps/credit/api/eligibility.py +++ b/openedx/core/djangoapps/credit/api/eligibility.py @@ -9,6 +9,7 @@ from opaque_keys.edx.keys import CourseKey from common.djangoapps.course_modes.models import CourseMode +from common.djangoapps.student.models import CourseEnrollment from openedx.core.djangoapps.credit.email_utils import send_credit_notifications from openedx.core.djangoapps.credit.exceptions import InvalidCreditCourse, InvalidCreditRequirements from openedx.core.djangoapps.credit.models import ( @@ -16,9 +17,8 @@ CreditEligibility, CreditRequest, CreditRequirement, - CreditRequirementStatus + CreditRequirementStatus, ) -from common.djangoapps.student.models import CourseEnrollment # TODO: Cleanup this mess! ECOM-2908 diff --git a/openedx/core/djangoapps/credit/api/provider.py b/openedx/core/djangoapps/credit/api/provider.py index 5628130b37be..d4827397ca94 100644 --- a/openedx/core/djangoapps/credit/api/provider.py +++ b/openedx/core/djangoapps/credit/api/provider.py @@ -6,28 +6,28 @@ import datetime import logging import uuid - from zoneinfo import ZoneInfo + from django.db import transaction from edx_proctoring.api import get_last_exam_completion_date +from common.djangoapps.student.models import CourseEnrollment, User +from common.djangoapps.util.date_utils import to_timestamp +from common.djangoapps.util.json_request import JsonResponse from openedx.core.djangoapps.credit.exceptions import ( CreditProviderNotConfigured, CreditRequestNotFound, InvalidCreditStatus, RequestAlreadyCompleted, - UserIsNotEligible + UserIsNotEligible, ) from openedx.core.djangoapps.credit.models import ( CreditEligibility, CreditProvider, CreditRequest, - CreditRequirementStatus + CreditRequirementStatus, ) from openedx.core.djangoapps.credit.signature import get_shared_secret_key, signature -from common.djangoapps.student.models import CourseEnrollment, User -from common.djangoapps.util.date_utils import to_timestamp -from common.djangoapps.util.json_request import JsonResponse # TODO: Cleanup this mess! ECOM-2908 diff --git a/openedx/core/djangoapps/credit/email_utils.py b/openedx/core/djangoapps/credit/email_utils.py index a190aca852b2..df33f74ae733 100644 --- a/openedx/core/djangoapps/credit/email_utils.py +++ b/openedx/core/djangoapps/credit/email_utils.py @@ -19,8 +19,8 @@ from django.core.mail import EmailMessage, SafeMIMEText from django.urls import reverse from django.utils.translation import gettext as _ +from edx_django_utils.plugins import pluggable_override from eventtracking import tracker -from xmodule.modulestore.django import modulestore from common.djangoapps.edxmako.shortcuts import render_to_string from common.djangoapps.edxmako.template import Template @@ -28,7 +28,7 @@ from openedx.core.djangoapps.credit.models import CreditConfig, CreditProvider from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangolib.markup import HTML -from edx_django_utils.plugins import pluggable_override +from xmodule.modulestore.django import modulestore log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/credit/models.py b/openedx/core/djangoapps/credit/models.py index d6be33828117..b9a4bc9b1f1e 100644 --- a/openedx/core/djangoapps/credit/models.py +++ b/openedx/core/djangoapps/credit/models.py @@ -9,8 +9,8 @@ import datetime import logging from collections import defaultdict - from zoneinfo import ZoneInfo + from config_models.models import ConfigurationModel from django.conf import settings from django.core.cache import cache diff --git a/openedx/core/djangoapps/credit/serializers.py b/openedx/core/djangoapps/credit/serializers.py index 56ffe7a960b2..5e22bcdd3bf1 100644 --- a/openedx/core/djangoapps/credit/serializers.py +++ b/openedx/core/djangoapps/credit/serializers.py @@ -3,16 +3,16 @@ import datetime import logging - from zoneinfo import ZoneInfo + from django.conf import settings from rest_framework import serializers from rest_framework.exceptions import PermissionDenied +from common.djangoapps.util.date_utils import from_timestamp from openedx.core.djangoapps.credit.models import CreditCourse, CreditEligibility, CreditProvider, CreditRequest from openedx.core.djangoapps.credit.signature import get_shared_secret_key, signature from openedx.core.lib.api.serializers import CourseKeyField -from common.djangoapps.util.date_utils import from_timestamp log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/credit/services.py b/openedx/core/djangoapps/credit/services.py index 16ec0c47358c..ee6c347a84eb 100644 --- a/openedx/core/djangoapps/credit/services.py +++ b/openedx/core/djangoapps/credit/services.py @@ -1,8 +1,8 @@ """ Implementation of "credit" XBlock service """ -from datetime import datetime, timedelta import logging +from datetime import datetime, timedelta from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.core.exceptions import ObjectDoesNotExist @@ -11,7 +11,6 @@ from common.djangoapps.student.models import CourseEnrollment from openedx.core.djangoapps.content.course_overviews.models import CourseOverview - log = logging.getLogger(__name__) @@ -40,9 +39,7 @@ def is_credit_course(self, course_key_or_id): # This seems to need to be here otherwise we get # circular references when starting up the app - from openedx.core.djangoapps.credit.api.eligibility import ( - is_credit_course, - ) + from openedx.core.djangoapps.credit.api.eligibility import is_credit_course course_key = _get_course_key(course_key_or_id) @@ -72,10 +69,7 @@ def get_credit_state(self, user_id, course_key_or_id, return_course_info=False): # This seems to need to be here otherwise we get # circular references when starting up the app - from openedx.core.djangoapps.credit.api.eligibility import ( - is_credit_course, - get_credit_requirement_status, - ) + from openedx.core.djangoapps.credit.api.eligibility import get_credit_requirement_status, is_credit_course # since we have to do name matching during various # verifications, User must have a UserProfile @@ -138,9 +132,9 @@ def set_credit_requirement_status(self, user_id, course_key_or_id, req_namespace # This seems to need to be here otherwise we get # circular references when starting up the app + from openedx.core.djangoapps.credit.api.eligibility import is_credit_course from openedx.core.djangoapps.credit.api.eligibility import ( - is_credit_course, - set_credit_requirement_status as api_set_credit_requirement_status + set_credit_requirement_status as api_set_credit_requirement_status, ) course_key = _get_course_key(course_key_or_id) @@ -194,9 +188,9 @@ def remove_credit_requirement_status(self, user_id, course_key_or_id, req_namesp # This seems to need to be here otherwise we get # circular references when starting up the app + from openedx.core.djangoapps.credit.api.eligibility import is_credit_course from openedx.core.djangoapps.credit.api.eligibility import ( - is_credit_course, - remove_credit_requirement_status as api_remove_credit_requirement_status + remove_credit_requirement_status as api_remove_credit_requirement_status, ) course_key = _get_course_key(course_key_or_id) diff --git a/openedx/core/djangoapps/credit/signals/handlers.py b/openedx/core/djangoapps/credit/signals/handlers.py index 3748f1cfba86..db103ced0501 100644 --- a/openedx/core/djangoapps/credit/signals/handlers.py +++ b/openedx/core/djangoapps/credit/signals/handlers.py @@ -15,13 +15,13 @@ EXAM_ATTEMPT_REJECTED, EXAM_ATTEMPT_RESET, EXAM_ATTEMPT_SUBMITTED, - EXAM_ATTEMPT_VERIFIED + EXAM_ATTEMPT_VERIFIED, ) from openedx.core.djangoapps.credit.api.eligibility import ( is_credit_course, remove_credit_requirement_status, - set_credit_requirement_status + set_credit_requirement_status, ) from openedx.core.djangoapps.signals.signals import COURSE_GRADE_CHANGED diff --git a/openedx/core/djangoapps/credit/tests/factories.py b/openedx/core/djangoapps/credit/tests/factories.py index 5489b7bb0668..e2840824c639 100644 --- a/openedx/core/djangoapps/credit/tests/factories.py +++ b/openedx/core/djangoapps/credit/tests/factories.py @@ -4,21 +4,21 @@ import datetime import json import uuid +from zoneinfo import ZoneInfo import factory -from factory.fuzzy import FuzzyText -from zoneinfo import ZoneInfo from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user +from factory.fuzzy import FuzzyText +from common.djangoapps.util.date_utils import to_timestamp from openedx.core.djangoapps.credit.models import ( CreditCourse, CreditEligibility, CreditProvider, CreditRequest, CreditRequirement, - CreditRequirementStatus + CreditRequirementStatus, ) -from common.djangoapps.util.date_utils import to_timestamp class CreditCourseFactory(factory.django.DjangoModelFactory): diff --git a/openedx/core/djangoapps/credit/tests/test_api.py b/openedx/core/djangoapps/credit/tests/test_api.py index 2ec31641dd1d..754d32ef620c 100644 --- a/openedx/core/djangoapps/credit/tests/test_api.py +++ b/openedx/core/djangoapps/credit/tests/test_api.py @@ -6,10 +6,11 @@ import datetime import json from unittest import mock -import pytest +from zoneinfo import ZoneInfo + import ddt import httpretty -from zoneinfo import ZoneInfo +import pytest from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.core import mail from django.db import connection @@ -17,6 +18,9 @@ from opaque_keys.edx.keys import CourseKey from common.djangoapps.course_modes.models import CourseMode +from common.djangoapps.student.models import CourseEnrollment +from common.djangoapps.student.tests.factories import UserFactory +from common.djangoapps.util.date_utils import from_timestamp from lms.djangoapps.commerce.tests import TEST_API_URL from openedx.core.djangoapps.credit import api from openedx.core.djangoapps.credit.email_utils import get_credit_provider_attribute_values, make_providers_strings @@ -26,7 +30,7 @@ InvalidCreditRequirements, InvalidCreditStatus, RequestAlreadyCompleted, - UserIsNotEligible + UserIsNotEligible, ) from openedx.core.djangoapps.credit.models import ( CreditConfig, @@ -35,13 +39,12 @@ CreditProvider, CreditRequest, CreditRequirement, - CreditRequirementStatus + CreditRequirementStatus, ) from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.tests.factories import UserFactory -from common.djangoapps.util.date_utils import from_timestamp -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order TEST_CREDIT_PROVIDER_SECRET_KEY = "931433d583c84ca7ba41784bad3232e6" diff --git a/openedx/core/djangoapps/credit/tests/test_models.py b/openedx/core/djangoapps/credit/tests/test_models.py index 2e3b02692a41..faedaa1edccb 100644 --- a/openedx/core/djangoapps/credit/tests/test_models.py +++ b/openedx/core/djangoapps/credit/tests/test_models.py @@ -7,19 +7,19 @@ from django.test import TestCase from opaque_keys.edx.keys import CourseKey +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.credit.models import ( CreditCourse, CreditProvider, CreditRequest, CreditRequirement, - CreditRequirementStatus + CreditRequirementStatus, ) from openedx.core.djangoapps.user_api.accounts.tests.retirement_helpers import ( # pylint: disable=unused-import RetirementTestCase, - setup_retirement_states + setup_retirement_states, ) from openedx.core.djangoapps.user_api.models import UserRetirementStatus -from common.djangoapps.student.tests.factories import UserFactory def add_credit_course(course_key): diff --git a/openedx/core/djangoapps/credit/tests/test_serializers.py b/openedx/core/djangoapps/credit/tests/test_serializers.py index 18c397b4d48f..a2ddb30389e0 100644 --- a/openedx/core/djangoapps/credit/tests/test_serializers.py +++ b/openedx/core/djangoapps/credit/tests/test_serializers.py @@ -4,9 +4,9 @@ from django.test import TestCase from rest_framework.exceptions import PermissionDenied +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.credit import serializers, signature from openedx.core.djangoapps.credit.tests.factories import CreditEligibilityFactory, CreditProviderFactory -from common.djangoapps.student.tests.factories import UserFactory class CreditProviderSerializerTests(TestCase): diff --git a/openedx/core/djangoapps/credit/tests/test_services.py b/openedx/core/djangoapps/credit/tests/test_services.py index 7f6b38463509..0f2234b18c67 100644 --- a/openedx/core/djangoapps/credit/tests/test_services.py +++ b/openedx/core/djangoapps/credit/tests/test_services.py @@ -3,17 +3,20 @@ """ -from unittest.mock import patch from datetime import datetime +from unittest.mock import patch + import ddt from common.djangoapps.course_modes.models import CourseMode +from common.djangoapps.student.models import CourseEnrollment, UserProfile from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.credit.api.eligibility import set_credit_requirements from openedx.core.djangoapps.credit.models import CreditCourse from openedx.core.djangoapps.credit.services import CreditService -from common.djangoapps.student.models import CourseEnrollment, UserProfile -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/core/djangoapps/credit/tests/test_signals.py b/openedx/core/djangoapps/credit/tests/test_signals.py index 592c042a05b9..33caf5f9035c 100644 --- a/openedx/core/djangoapps/credit/tests/test_signals.py +++ b/openedx/core/djangoapps/credit/tests/test_signals.py @@ -5,9 +5,9 @@ from datetime import datetime, timedelta, timezone from unittest import mock from uuid import uuid4 +from zoneinfo import ZoneInfo import ddt -from zoneinfo import ZoneInfo from django.test.client import RequestFactory from opaque_keys.edx.keys import UsageKey from openedx_events.data import EventsMetadata @@ -17,7 +17,7 @@ EXAM_ATTEMPT_REJECTED, EXAM_ATTEMPT_RESET, EXAM_ATTEMPT_SUBMITTED, - EXAM_ATTEMPT_VERIFIED + EXAM_ATTEMPT_VERIFIED, ) from common.djangoapps.course_modes.models import CourseMode @@ -31,11 +31,12 @@ listen_for_exam_reset, listen_for_exam_submitted, listen_for_exam_verified, - listen_for_grade_calculation + listen_for_grade_calculation, ) from openedx.core.djangolib.testing.utils import skip_unless_lms -from xmodule.modulestore.tests.django_utils import \ - ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/core/djangoapps/credit/tests/test_tasks.py b/openedx/core/djangoapps/credit/tests/test_tasks.py index 47c4b50925e9..fe6bb07a452c 100644 --- a/openedx/core/djangoapps/credit/tests/test_tasks.py +++ b/openedx/core/djangoapps/credit/tests/test_tasks.py @@ -4,16 +4,21 @@ from datetime import datetime - from unittest import mock + from edx_proctoring.api import create_exam from openedx.core.djangoapps.credit.api import get_credit_requirements from openedx.core.djangoapps.credit.exceptions import InvalidCreditRequirements from openedx.core.djangoapps.credit.models import CreditCourse from openedx.core.djangoapps.credit.signals.handlers import on_course_publish -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) class TestTaskExecution(ModuleStoreTestCase): diff --git a/openedx/core/djangoapps/credit/tests/test_views.py b/openedx/core/djangoapps/credit/tests/test_views.py index 02428557ded0..9f74bcf9af21 100644 --- a/openedx/core/djangoapps/credit/tests/test_views.py +++ b/openedx/core/djangoapps/credit/tests/test_views.py @@ -5,21 +5,23 @@ import datetime import json +from zoneinfo import ZoneInfo import ddt -from zoneinfo import ZoneInfo from django.conf import settings from django.test import Client, TestCase from django.test.utils import override_settings from django.urls import reverse from opaque_keys.edx.keys import CourseKey +from common.djangoapps.student.tests.factories import AdminFactory, UserFactory +from common.djangoapps.util.date_utils import to_timestamp from openedx.core.djangoapps.credit.models import ( CreditCourse, CreditProvider, CreditRequest, CreditRequirement, - CreditRequirementStatus + CreditRequirementStatus, ) from openedx.core.djangoapps.credit.serializers import CreditEligibilitySerializer, CreditProviderSerializer from openedx.core.djangoapps.credit.signature import signature @@ -27,13 +29,11 @@ CreditCourseFactory, CreditEligibilityFactory, CreditProviderFactory, - CreditRequestFactory + CreditRequestFactory, ) from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_for_user -from openedx.core.djangoapps.oauth_dispatch.tests.factories import ApplicationFactory, AccessTokenFactory +from openedx.core.djangoapps.oauth_dispatch.tests.factories import AccessTokenFactory, ApplicationFactory from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.tests.factories import AdminFactory, UserFactory -from common.djangoapps.util.date_utils import to_timestamp JSON = 'application/json' diff --git a/openedx/core/djangoapps/credit/views.py b/openedx/core/djangoapps/credit/views.py index d61316b49c26..0e3055714add 100644 --- a/openedx/core/djangoapps/credit/views.py +++ b/openedx/core/djangoapps/credit/views.py @@ -5,8 +5,8 @@ import datetime import logging - from zoneinfo import ZoneInfo + from django.conf import settings from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_exempt @@ -23,20 +23,20 @@ CreditApiBadRequest, InvalidCourseKey, InvalidCreditRequest, - UserNotEligibleException + UserNotEligibleException, ) from openedx.core.djangoapps.credit.models import ( CREDIT_PROVIDER_ID_REGEX, CreditCourse, CreditEligibility, CreditProvider, - CreditRequest + CreditRequest, ) from openedx.core.djangoapps.credit.serializers import ( CreditCourseSerializer, CreditEligibilitySerializer, CreditProviderCallbackSerializer, - CreditProviderSerializer + CreditProviderSerializer, ) from openedx.core.lib.api.authentication import BearerAuthentication from openedx.core.lib.api.mixins import PutAsCreateMixin diff --git a/openedx/core/djangoapps/dark_lang/middleware.py b/openedx/core/djangoapps/dark_lang/middleware.py index 817d544e9ff4..42fd3fa5ccbf 100644 --- a/openedx/core/djangoapps/dark_lang/middleware.py +++ b/openedx/core/djangoapps/dark_lang/middleware.py @@ -10,8 +10,8 @@ from django.conf import settings -from django.utils.translation.trans_real import parse_accept_lang_header from django.utils.deprecation import MiddlewareMixin +from django.utils.translation.trans_real import parse_accept_lang_header from openedx.core.djangoapps.dark_lang import DARK_LANGUAGE_KEY from openedx.core.djangoapps.dark_lang.models import DarkLangConfig diff --git a/openedx/core/djangoapps/dark_lang/migrations/0001_initial.py b/openedx/core/djangoapps/dark_lang/migrations/0001_initial.py index 6c8ab882e876..adf374ca59c9 100644 --- a/openedx/core/djangoapps/dark_lang/migrations/0001_initial.py +++ b/openedx/core/djangoapps/dark_lang/migrations/0001_initial.py @@ -1,6 +1,6 @@ -from django.db import migrations, models import django.db.models.deletion from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/dark_lang/tests.py b/openedx/core/djangoapps/dark_lang/tests.py index 765d2ea3091f..10727a9470be 100644 --- a/openedx/core/djangoapps/dark_lang/tests.py +++ b/openedx/core/djangoapps/dark_lang/tests.py @@ -11,6 +11,7 @@ from django.http import HttpRequest from django.test.client import Client +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.dark_lang.middleware import DarkLangMiddleware from openedx.core.djangoapps.dark_lang.models import DarkLangConfig from openedx.core.djangoapps.site_configuration.tests.test_util import ( @@ -18,7 +19,6 @@ with_site_configuration_context, ) from openedx.core.djangolib.testing.utils import CacheIsolationTestCase -from common.djangoapps.student.tests.factories import UserFactory UNSET = object() diff --git a/openedx/core/djangoapps/dark_lang/urls.py b/openedx/core/djangoapps/dark_lang/urls.py index d824b385a414..46baf51deaa7 100644 --- a/openedx/core/djangoapps/dark_lang/urls.py +++ b/openedx/core/djangoapps/dark_lang/urls.py @@ -3,6 +3,7 @@ """ from django.urls import path + from openedx.core.djangoapps.dark_lang import views app_name = 'dark_lang' diff --git a/openedx/core/djangoapps/discussions/admin.py b/openedx/core/djangoapps/discussions/admin.py index 810f57e95226..ae125d76e187 100644 --- a/openedx/core/djangoapps/discussions/admin.py +++ b/openedx/core/djangoapps/discussions/admin.py @@ -8,8 +8,7 @@ from openedx.core.djangoapps.config_model_utils.admin import StackedConfigModelAdmin -from .models import DiscussionsConfiguration -from .models import ProviderFilter +from .models import DiscussionsConfiguration, ProviderFilter class DiscussionsConfigurationAdmin(SimpleHistoryAdmin): diff --git a/openedx/core/djangoapps/discussions/apps.py b/openedx/core/djangoapps/discussions/apps.py index ba0b66942586..a53a2a75db05 100644 --- a/openedx/core/djangoapps/discussions/apps.py +++ b/openedx/core/djangoapps/discussions/apps.py @@ -2,8 +2,7 @@ Configure the django app """ from django.apps import AppConfig -from edx_django_utils.plugins import PluginSettings -from edx_django_utils.plugins import PluginURLs +from edx_django_utils.plugins import PluginSettings, PluginURLs from openedx.core.djangoapps.plugins.constants import ProjectType diff --git a/openedx/core/djangoapps/discussions/config/waffle_utils.py b/openedx/core/djangoapps/discussions/config/waffle_utils.py index d44b7af5ad8c..0b2c579cb095 100644 --- a/openedx/core/djangoapps/discussions/config/waffle_utils.py +++ b/openedx/core/djangoapps/discussions/config/waffle_utils.py @@ -4,7 +4,7 @@ from openedx.core.djangoapps.discussions.config.waffle import ( ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND, - OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG + OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG, ) diff --git a/openedx/core/djangoapps/discussions/handlers.py b/openedx/core/djangoapps/discussions/handlers.py index cef054b317df..df718bda7cb6 100644 --- a/openedx/core/djangoapps/discussions/handlers.py +++ b/openedx/core/djangoapps/discussions/handlers.py @@ -5,12 +5,12 @@ from uuid import uuid4 from django.db import transaction - from openedx_events.learning.data import CourseDiscussionConfigurationData from openedx_events.learning.signals import COURSE_DISCUSSIONS_CHANGED + from openedx.core.djangoapps.discussions.models import ( - DiscussionTopicLink, DiscussionsConfiguration, + DiscussionTopicLink, get_default_provider_type, ) diff --git a/openedx/core/djangoapps/discussions/migrations/0001_initial.py b/openedx/core/djangoapps/discussions/migrations/0001_initial.py index b42d633998cc..2e9a57e7214b 100644 --- a/openedx/core/djangoapps/discussions/migrations/0001_initial.py +++ b/openedx/core/djangoapps/discussions/migrations/0001_initial.py @@ -1,5 +1,3 @@ -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import jsonfield.encoder @@ -7,6 +5,8 @@ import model_utils.fields import opaque_keys.edx.django.models import simple_history.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/discussions/migrations/0002_add_provider_filter.py b/openedx/core/djangoapps/discussions/migrations/0002_add_provider_filter.py index b8320e580cf3..ed57ed24d026 100644 --- a/openedx/core/djangoapps/discussions/migrations/0002_add_provider_filter.py +++ b/openedx/core/djangoapps/discussions/migrations/0002_add_provider_filter.py @@ -1,9 +1,10 @@ # Generated by Django 2.2.17 on 2021-02-02 06:35 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django_mysql.models +from django.conf import settings +from django.db import migrations, models + import openedx.core.djangoapps.config_model_utils.models diff --git a/openedx/core/djangoapps/discussions/migrations/0003_alter_provider_filter_list.py b/openedx/core/djangoapps/discussions/migrations/0003_alter_provider_filter_list.py index 41edcf461d0c..19bfe01f63a0 100644 --- a/openedx/core/djangoapps/discussions/migrations/0003_alter_provider_filter_list.py +++ b/openedx/core/djangoapps/discussions/migrations/0003_alter_provider_filter_list.py @@ -1,7 +1,7 @@ # Generated by Django 2.2.19 on 2021-03-23 14:46 -from django.db import migrations, models import django_mysql.models +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/discussions/migrations/0004_historicalprogramdiscussionsconfiguration_programdiscussionsconfiguration.py b/openedx/core/djangoapps/discussions/migrations/0004_historicalprogramdiscussionsconfiguration_programdiscussionsconfiguration.py index 872d2887a7e4..8daf1a9f38d2 100644 --- a/openedx/core/djangoapps/discussions/migrations/0004_historicalprogramdiscussionsconfiguration_programdiscussionsconfiguration.py +++ b/openedx/core/djangoapps/discussions/migrations/0004_historicalprogramdiscussionsconfiguration_programdiscussionsconfiguration.py @@ -1,11 +1,11 @@ # Generated by Django 2.2.24 on 2021-08-31 11:18 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields import simple_history.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/discussions/migrations/0005_auto_20210910_0940.py b/openedx/core/djangoapps/discussions/migrations/0005_auto_20210910_0940.py index 7b067f8c34f1..fbe89f86c0df 100644 --- a/openedx/core/djangoapps/discussions/migrations/0005_auto_20210910_0940.py +++ b/openedx/core/djangoapps/discussions/migrations/0005_auto_20210910_0940.py @@ -1,7 +1,7 @@ # Generated by Django 2.2.24 on 2021-09-10 09:40 -from django.db import migrations import jsonfield.fields +from django.db import migrations class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/discussions/migrations/0006_auto_20211006_0441.py b/openedx/core/djangoapps/discussions/migrations/0006_auto_20211006_0441.py index 664a12bcf71c..1b51397df86a 100644 --- a/openedx/core/djangoapps/discussions/migrations/0006_auto_20211006_0441.py +++ b/openedx/core/djangoapps/discussions/migrations/0006_auto_20211006_0441.py @@ -1,7 +1,7 @@ # Generated by Django 2.2.24 on 2021-10-06 04:41 -from django.db import migrations, models import django_mysql.models +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/discussions/migrations/0008_auto_20220119_0746.py b/openedx/core/djangoapps/discussions/migrations/0008_auto_20220119_0746.py index 61797a5b651a..94d09a0158dc 100644 --- a/openedx/core/djangoapps/discussions/migrations/0008_auto_20220119_0746.py +++ b/openedx/core/djangoapps/discussions/migrations/0008_auto_20220119_0746.py @@ -1,11 +1,11 @@ # Generated by Django 3.2.11 on 2022-01-19 07:46 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields import simple_history.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/discussions/migrations/0011_auto_20220510_0716.py b/openedx/core/djangoapps/discussions/migrations/0011_auto_20220510_0716.py index a5d016be9632..cc9221556cd2 100644 --- a/openedx/core/djangoapps/discussions/migrations/0011_auto_20220510_0716.py +++ b/openedx/core/djangoapps/discussions/migrations/0011_auto_20220510_0716.py @@ -1,7 +1,7 @@ # Generated by Django 3.2.13 on 2022-05-10 07:16 -from django.db import migrations, models import django_mysql.models +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/discussions/migrations/0012_auto_20220511_0827.py b/openedx/core/djangoapps/discussions/migrations/0012_auto_20220511_0827.py index 89f2261c64c6..9601b57f4de8 100644 --- a/openedx/core/djangoapps/discussions/migrations/0012_auto_20220511_0827.py +++ b/openedx/core/djangoapps/discussions/migrations/0012_auto_20220511_0827.py @@ -1,7 +1,7 @@ # Generated by Django 3.2.13 on 2022-05-11 08:27 -from django.db import migrations, models import django_mysql.models +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/discussions/migrations/0013_auto_20220802_1154.py b/openedx/core/djangoapps/discussions/migrations/0013_auto_20220802_1154.py index 3108dd27e977..bd1199aea64f 100644 --- a/openedx/core/djangoapps/discussions/migrations/0013_auto_20220802_1154.py +++ b/openedx/core/djangoapps/discussions/migrations/0013_auto_20220802_1154.py @@ -1,6 +1,7 @@ # Generated by Django 3.2.14 on 2022-08-02 11:54 from django.db import migrations, models + import openedx.core.djangoapps.discussions.models diff --git a/openedx/core/djangoapps/discussions/models.py b/openedx/core/djangoapps/discussions/models.py index f47b661c9ad2..3192bceed6a4 100644 --- a/openedx/core/djangoapps/discussions/models.py +++ b/openedx/core/djangoapps/discussions/models.py @@ -5,6 +5,7 @@ import logging from collections import namedtuple +from enum import Enum # lint-amnesty, pylint: disable=wrong-import-order from typing import List, Type, TypeVar from django.conf import settings @@ -12,7 +13,6 @@ from django.db import models from django.utils.translation import gettext_lazy as _ from django_mysql.models import ListCharField -from enum import Enum # lint-amnesty, pylint: disable=wrong-import-order from jsonfield import JSONField from lti_consumer.models import LtiConfiguration from model_utils.models import TimeStampedModel @@ -20,10 +20,10 @@ from opaque_keys.edx.keys import CourseKey from simple_history.models import HistoricalRecords -from openedx.core.djangoapps.discussions.config.waffle import ENABLE_NEW_STRUCTURE_DISCUSSIONS from openedx.core.djangoapps.config_model_utils.models import StackedConfigurationModel from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.course_groups.models import CourseUserGroup +from openedx.core.djangoapps.discussions.config.waffle import ENABLE_NEW_STRUCTURE_DISCUSSIONS from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/discussions/permissions.py b/openedx/core/djangoapps/discussions/permissions.py index 7028defc3e00..b5420247c96b 100644 --- a/openedx/core/djangoapps/discussions/permissions.py +++ b/openedx/core/djangoapps/discussions/permissions.py @@ -4,7 +4,7 @@ from rest_framework.exceptions import PermissionDenied from rest_framework.permissions import BasePermission -from common.djangoapps.student.roles import CourseStaffRole, GlobalStaff, CourseInstructorRole +from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole, GlobalStaff from lms.djangoapps.discussion.django_comment_client.utils import has_discussion_privileges from openedx.core.lib.api.view_utils import validate_course_key diff --git a/openedx/core/djangoapps/discussions/plugins.py b/openedx/core/djangoapps/discussions/plugins.py index f48c31d12b78..b4422b843c97 100644 --- a/openedx/core/djangoapps/discussions/plugins.py +++ b/openedx/core/djangoapps/discussions/plugins.py @@ -9,6 +9,7 @@ from opaque_keys.edx.keys import CourseKey from openedx.core.djangoapps.course_apps.plugins import CourseApp + from .models import DiscussionsConfiguration User = get_user_model() diff --git a/openedx/core/djangoapps/discussions/serializers.py b/openedx/core/djangoapps/discussions/serializers.py index 5e042575a2c7..53b2acfed8fd 100644 --- a/openedx/core/djangoapps/discussions/serializers.py +++ b/openedx/core/djangoapps/discussions/serializers.py @@ -5,14 +5,15 @@ from lti_consumer.api import get_lti_pii_sharing_state_for_course from lti_consumer.models import LtiConfiguration from rest_framework import serializers -from xmodule.modulestore.django import modulestore from openedx.core.djangoapps.discussions.tasks import update_discussions_settings_from_course_task from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings from openedx.core.lib.courses import get_course_by_id +from xmodule.modulestore.django import modulestore + +from ..content.course_overviews.models import CourseOverviewTab from .models import DiscussionsConfiguration, Provider from .utils import available_division_schemes, get_divided_discussions -from ..content.course_overviews.models import CourseOverviewTab class LtiSerializer(serializers.ModelSerializer): diff --git a/openedx/core/djangoapps/discussions/services.py b/openedx/core/djangoapps/discussions/services.py index 6ccee6099bac..db3b774cc638 100644 --- a/openedx/core/djangoapps/discussions/services.py +++ b/openedx/core/djangoapps/discussions/services.py @@ -9,8 +9,9 @@ from django.conf import settings from django.contrib.auth.models import User # pylint: disable=imported-auth-user from opaque_keys.edx.keys import CourseKey -from openedx.core.djangoapps.django_comment_common.models import has_permission + from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, Provider +from openedx.core.djangoapps.django_comment_common.models import has_permission class DiscussionConfigService: diff --git a/openedx/core/djangoapps/discussions/tasks.py b/openedx/core/djangoapps/discussions/tasks.py index 63f95421bb0a..4599f33454d4 100644 --- a/openedx/core/djangoapps/discussions/tasks.py +++ b/openedx/core/djangoapps/discussions/tasks.py @@ -11,9 +11,9 @@ from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore -from .config.waffle import ENABLE_NEW_STRUCTURE_DISCUSSIONS -from .models import DiscussionsConfiguration, Provider, DiscussionTopicLink +from .config.waffle import ENABLE_NEW_STRUCTURE_DISCUSSIONS +from .models import DiscussionsConfiguration, DiscussionTopicLink, Provider from .utils import get_accessible_discussion_xblocks_by_course_id log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/discussions/tests/test_handlers.py b/openedx/core/djangoapps/discussions/tests/test_handlers.py index 107ab643698e..431fe18efefa 100644 --- a/openedx/core/djangoapps/discussions/tests/test_handlers.py +++ b/openedx/core/djangoapps/discussions/tests/test_handlers.py @@ -7,10 +7,10 @@ import ddt from django.test import TestCase from opaque_keys.edx.keys import CourseKey - from openedx_events.learning.data import CourseDiscussionConfigurationData, DiscussionTopicContext + from openedx.core.djangoapps.discussions.handlers import update_course_discussion_config -from openedx.core.djangoapps.discussions.models import DiscussionTopicLink, DiscussionsConfiguration +from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, DiscussionTopicLink @ddt.ddt diff --git a/openedx/core/djangoapps/discussions/tests/test_models.py b/openedx/core/djangoapps/discussions/tests/test_models.py index efa30a0b48db..35fecbc6725c 100644 --- a/openedx/core/djangoapps/discussions/tests/test_models.py +++ b/openedx/core/djangoapps/discussions/tests/test_models.py @@ -6,18 +6,20 @@ import ddt import pytest - from django.test import TestCase from edx_toggles.toggles.testutils import override_waffle_flag from opaque_keys.edx.keys import CourseKey from organizations.models import Organization from ..config.waffle import ENABLE_NEW_STRUCTURE_DISCUSSIONS -from ..models import DEFAULT_CONFIG_ENABLED, Provider, get_default_provider_type -from ..models import DiscussionsConfiguration -from ..models import ProviderFilter -from ..models import PostingRestriction - +from ..models import ( + DEFAULT_CONFIG_ENABLED, + DiscussionsConfiguration, + PostingRestriction, + Provider, + ProviderFilter, + get_default_provider_type, +) SUPPORTED_PROVIDERS = [ 'legacy', diff --git a/openedx/core/djangoapps/discussions/tests/test_tasks.py b/openedx/core/djangoapps/discussions/tests/test_tasks.py index fee840c1905f..f3465eb832f8 100644 --- a/openedx/core/djangoapps/discussions/tests/test_tasks.py +++ b/openedx/core/djangoapps/discussions/tests/test_tasks.py @@ -14,7 +14,7 @@ update_unit_discussion_state_from_discussion_blocks, ) from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory class DiscussionConfigUpdateMixin: diff --git a/openedx/core/djangoapps/discussions/tests/test_transformer.py b/openedx/core/djangoapps/discussions/tests/test_transformer.py index 3768eb1ea92a..cf0cad623dbd 100644 --- a/openedx/core/djangoapps/discussions/tests/test_transformer.py +++ b/openedx/core/djangoapps/discussions/tests/test_transformer.py @@ -2,16 +2,12 @@ Tests for discussions course block transformer """ -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory - from lms.djangoapps.course_blocks.api import get_course_blocks from lms.djangoapps.course_blocks.transformers.tests.helpers import TransformerRegistryTestMixin -from openedx.core.djangoapps.discussions.models import ( - DiscussionTopicLink, - get_default_provider_type, -) +from openedx.core.djangoapps.discussions.models import DiscussionTopicLink, get_default_provider_type from openedx.core.djangoapps.discussions.transformers import DiscussionsTopicLinkTransformer +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory class DiscussionsTopicLinkTransformerTestCase(TransformerRegistryTestMixin, ModuleStoreTestCase): diff --git a/openedx/core/djangoapps/discussions/transformers.py b/openedx/core/djangoapps/discussions/transformers.py index a4d34434ab12..89916c38834e 100644 --- a/openedx/core/djangoapps/discussions/transformers.py +++ b/openedx/core/djangoapps/discussions/transformers.py @@ -3,7 +3,7 @@ """ from openedx.core.djangoapps.content.block_structure.transformer import BlockStructureTransformer -from openedx.core.djangoapps.discussions.models import DiscussionTopicLink, DiscussionsConfiguration +from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, DiscussionTopicLink from openedx.core.djangoapps.discussions.url_helpers import get_discussions_mfe_topic_url diff --git a/openedx/core/djangoapps/discussions/urls.py b/openedx/core/djangoapps/discussions/urls.py index 6b70ca5f984b..f994fa1c91a4 100644 --- a/openedx/core/djangoapps/discussions/urls.py +++ b/openedx/core/djangoapps/discussions/urls.py @@ -8,7 +8,7 @@ CombinedDiscussionsConfigurationView, DiscussionsConfigurationSettingsView, DiscussionsProvidersView, - SyncDiscussionTopicsView + SyncDiscussionTopicsView, ) urlpatterns = [ diff --git a/openedx/core/djangoapps/discussions/utils.py b/openedx/core/djangoapps/discussions/utils.py index 7c26a4e482e6..70da190c0fe4 100644 --- a/openedx/core/djangoapps/discussions/utils.py +++ b/openedx/core/djangoapps/discussions/utils.py @@ -11,11 +11,14 @@ from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings from openedx.core.lib.cache_utils import request_cached from openedx.core.lib.courses import get_course_by_id -from xmodule.discussion_block import DiscussionXBlock from openedx.core.types import User from xmodule.course_block import CourseBlock # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.discussion_block import DiscussionXBlock from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID, Group # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.partitions.partitions import ( # lint-amnesty, pylint: disable=wrong-import-order + ENROLLMENT_TRACK_PARTITION_ID, + Group, +) from xmodule.partitions.partitions_service import PartitionService # lint-amnesty, pylint: disable=wrong-import-order log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/comment.py b/openedx/core/djangoapps/django_comment_common/comment_client/comment.py index 2d1c53f62b4a..30b27dba27c4 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/comment.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/comment.py @@ -3,14 +3,13 @@ import time from bs4 import BeautifulSoup +from forum import api as forum_api +from forum.backends.mongodb.comments import Comment as ForumComment from openedx.core.djangoapps.django_comment_common.comment_client import models, settings from .thread import Thread from .utils import CommentClientRequestError, get_course_key -from forum import api as forum_api -from forum.backends.mongodb.comments import Comment as ForumComment - log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/course.py b/openedx/core/djangoapps/django_comment_common/comment_client/course.py index 1dad0ca159aa..ce8bcdf54e9f 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/course.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/course.py @@ -5,9 +5,8 @@ from typing import Dict, Optional from edx_django_utils.monitoring import function_trace -from opaque_keys.edx.keys import CourseKey - from forum import api as forum_api +from opaque_keys.edx.keys import CourseKey def get_course_commentable_counts(course_key: CourseKey) -> Dict[str, Dict[str, int]]: diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/models.py b/openedx/core/djangoapps/django_comment_common/comment_client/models.py index e788ac5e9ea0..cdcce68afa5c 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/models.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/models.py @@ -3,9 +3,10 @@ import logging -from .utils import CommentClientRequestError, extract, get_course_key from forum import api as forum_api +from .utils import CommentClientRequestError, extract, get_course_key + log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/subscriptions.py b/openedx/core/djangoapps/django_comment_common/comment_client/subscriptions.py index a2e8ff8c2b2b..e3b46a6d5051 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/subscriptions.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/subscriptions.py @@ -3,10 +3,11 @@ """ import logging -from . import models, settings, utils from forum import api as forum_api from forum.backend import get_backend +from . import models, settings, utils + log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/thread.py b/openedx/core/djangoapps/django_comment_common/comment_client/thread.py index ffb9147acab4..d5572452f017 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/thread.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/thread.py @@ -5,13 +5,11 @@ import time from eventtracking import tracker - from forum import api as forum_api from forum.backends.mongodb.threads import CommentThread as ForumThread from . import models, settings, utils - log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/user.py b/openedx/core/djangoapps/django_comment_common/comment_client/user.py index bd208545ce56..7589143778bf 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/user.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/user.py @@ -1,10 +1,11 @@ # pylint: disable=missing-docstring,protected-access """ User model wrapper for comment service""" -from . import models, settings, utils from forum import api as forum_api from forum.utils import ForumV2RequestError, str_to_bool +from . import models, settings, utils + class User(models.Model): diff --git a/openedx/core/djangoapps/django_comment_common/migrations/0006_coursediscussionsettings_discussions_id_map.py b/openedx/core/djangoapps/django_comment_common/migrations/0006_coursediscussionsettings_discussions_id_map.py index bc30ad314f12..c83d72455102 100644 --- a/openedx/core/djangoapps/django_comment_common/migrations/0006_coursediscussionsettings_discussions_id_map.py +++ b/openedx/core/djangoapps/django_comment_common/migrations/0006_coursediscussionsettings_discussions_id_map.py @@ -1,8 +1,8 @@ # Generated by Django 1.11.12 on 2018-04-23 21:09 -from django.db import migrations import jsonfield.fields +from django.db import migrations class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/django_comment_common/migrations/0007_discussionsidmapping.py b/openedx/core/djangoapps/django_comment_common/migrations/0007_discussionsidmapping.py index ba396e025c15..a32c1c703469 100644 --- a/openedx/core/djangoapps/django_comment_common/migrations/0007_discussionsidmapping.py +++ b/openedx/core/djangoapps/django_comment_common/migrations/0007_discussionsidmapping.py @@ -1,9 +1,9 @@ # Generated by Django 1.11.13 on 2018-06-13 12:10 -from django.db import migrations import jsonfield.fields import opaque_keys.edx.django.models +from django.db import migrations class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/django_comment_common/models.py b/openedx/core/djangoapps/django_comment_common/models.py index 51863c42d472..2dd8bf814ad8 100644 --- a/openedx/core/djangoapps/django_comment_common/models.py +++ b/openedx/core/djangoapps/django_comment_common/models.py @@ -10,17 +10,16 @@ from django.db import models from django.db.models.signals import post_save from django.dispatch import receiver - from django.utils.translation import gettext_noop +from edx_django_utils.cache import DEFAULT_REQUEST_CACHE from jsonfield.fields import JSONField from opaque_keys.edx.django.models import CourseKeyField -from edx_django_utils.cache import DEFAULT_REQUEST_CACHE from opaque_keys.edx.keys import CourseKey -from openedx.core.djangoapps.xmodule_django.models import NoneToEmptyManager -from openedx.core.lib.cache_utils import request_cached from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.roles import GlobalStaff +from openedx.core.djangoapps.xmodule_django.models import NoneToEmptyManager +from openedx.core.lib.cache_utils import request_cached from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/core/djangoapps/django_comment_common/tests.py b/openedx/core/djangoapps/django_comment_common/tests.py index e0d87a341371..25087e0b4951 100644 --- a/openedx/core/djangoapps/django_comment_common/tests.py +++ b/openedx/core/djangoapps/django_comment_common/tests.py @@ -5,13 +5,15 @@ from django.test import TestCase from opaque_keys.edx.locator import CourseLocator -from openedx.core.djangoapps.course_groups.cohorts import CourseCohortsSettings -from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings, Role from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.course_groups.cohorts import CourseCohortsSettings +from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings, Role from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/core/djangoapps/django_comment_common/utils.py b/openedx/core/djangoapps/django_comment_common/utils.py index fd3a918bcb28..89d074653ae1 100644 --- a/openedx/core/djangoapps/django_comment_common/utils.py +++ b/openedx/core/djangoapps/django_comment_common/utils.py @@ -8,7 +8,7 @@ FORUM_ROLE_GROUP_MODERATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_STUDENT, - Role + Role, ) diff --git a/openedx/core/djangoapps/embargo/forms.py b/openedx/core/djangoapps/embargo/forms.py index 5faa1ea5fb9e..5f34022af5d8 100644 --- a/openedx/core/djangoapps/embargo/forms.py +++ b/openedx/core/djangoapps/embargo/forms.py @@ -4,6 +4,7 @@ import ipaddress + from django import forms from django.utils.translation import gettext as _ from opaque_keys import InvalidKeyError diff --git a/openedx/core/djangoapps/embargo/middleware.py b/openedx/core/djangoapps/embargo/middleware.py index d35dba11b2fd..b1c7a5c833ff 100644 --- a/openedx/core/djangoapps/embargo/middleware.py +++ b/openedx/core/djangoapps/embargo/middleware.py @@ -32,9 +32,9 @@ from django.conf import settings from django.core.exceptions import MiddlewareNotUsed +from django.shortcuts import redirect from django.urls import reverse from django.utils.deprecation import MiddlewareMixin -from django.shortcuts import redirect from edx_django_utils import ip from rest_framework.request import Request from rest_framework.response import Response diff --git a/openedx/core/djangoapps/embargo/migrations/0001_initial.py b/openedx/core/djangoapps/embargo/migrations/0001_initial.py index ae9f011e1b29..25ac29f68757 100644 --- a/openedx/core/djangoapps/embargo/migrations/0001_initial.py +++ b/openedx/core/djangoapps/embargo/migrations/0001_initial.py @@ -1,7 +1,7 @@ -from django.db import migrations, models -import django_countries.fields import django.db.models.deletion +import django_countries.fields from django.conf import settings +from django.db import migrations, models from opaque_keys.edx.django.models import CourseKeyField diff --git a/openedx/core/djangoapps/embargo/migrations/0003_add_global_restricted_country_model.py b/openedx/core/djangoapps/embargo/migrations/0003_add_global_restricted_country_model.py index d9a422202c48..4b016162e716 100644 --- a/openedx/core/djangoapps/embargo/migrations/0003_add_global_restricted_country_model.py +++ b/openedx/core/djangoapps/embargo/migrations/0003_add_global_restricted_country_model.py @@ -1,7 +1,7 @@ # Generated by Django 4.2.18 on 2025-01-29 08:19 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/embargo/test_utils.py b/openedx/core/djangoapps/embargo/test_utils.py index 86ef3c8e7968..ac8924094088 100644 --- a/openedx/core/djangoapps/embargo/test_utils.py +++ b/openedx/core/djangoapps/embargo/test_utils.py @@ -3,12 +3,11 @@ import contextlib from unittest.mock import MagicMock, patch +import geoip2.database import maxminddb from django.core.cache import cache from django.urls import reverse -import geoip2.database - from .models import Country, CountryAccessRule, RestrictedCourse diff --git a/openedx/core/djangoapps/embargo/tests/factories.py b/openedx/core/djangoapps/embargo/tests/factories.py index ad8c486a3f85..99b09a970cdf 100644 --- a/openedx/core/djangoapps/embargo/tests/factories.py +++ b/openedx/core/djangoapps/embargo/tests/factories.py @@ -2,6 +2,7 @@ import factory from factory.django import DjangoModelFactory + from xmodule.modulestore.tests.factories import CourseFactory from ..models import Country, CountryAccessRule, RestrictedCourse diff --git a/openedx/core/djangoapps/embargo/tests/test_api.py b/openedx/core/djangoapps/embargo/tests/test_api.py index a07edeb2486a..f71ffafd543e 100644 --- a/openedx/core/djangoapps/embargo/tests/test_api.py +++ b/openedx/core/djangoapps/embargo/tests/test_api.py @@ -4,37 +4,37 @@ from contextlib import contextmanager from unittest import mock -from unittest.mock import patch, MagicMock +from unittest.mock import MagicMock, patch +import ddt import geoip2.database import maxminddb -import ddt import pytest - from django.conf import settings from django.core.cache import cache from django.db import connection from django.test.client import RequestFactory from django.test.utils import override_settings -from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, mixed_store_config -from openedx.core.djangolib.testing.utils import AUTHZ_TABLES, skip_unless_lms -from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES -from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.student.roles import ( - GlobalStaff, CourseRole, OrgRole, - CourseStaffRole, CourseInstructorRole, - OrgStaffRole, OrgInstructorRole + CourseInstructorRole, + CourseRole, + CourseStaffRole, + GlobalStaff, + OrgInstructorRole, + OrgRole, + OrgStaffRole, ) +from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.util.testing import UrlResetMixin - -from ..models import ( - RestrictedCourse, Country, CountryAccessRule, -) +from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES +from openedx.core.djangolib.testing.utils import AUTHZ_TABLES, skip_unless_lms +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, mixed_store_config +from xmodule.modulestore.tests.factories import CourseFactory from .. import api as embargo_api from ..exceptions import InvalidAccessPoint +from ..models import Country, CountryAccessRule, RestrictedCourse QUERY_COUNT_TABLE_IGNORELIST = WAFFLE_TABLES + AUTHZ_TABLES diff --git a/openedx/core/djangoapps/embargo/tests/test_middleware.py b/openedx/core/djangoapps/embargo/tests/test_middleware.py index 9fa1f5b87c5f..eaa2ef1bbd88 100644 --- a/openedx/core/djangoapps/embargo/tests/test_middleware.py +++ b/openedx/core/djangoapps/embargo/tests/test_middleware.py @@ -4,17 +4,18 @@ from unittest.mock import patch + import ddt from config_models.models import cache as config_cache from django.conf import settings from django.core.cache import cache as django_cache from django.urls import reverse -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.util.testing import UrlResetMixin from openedx.core.djangolib.testing.utils import skip_unless_lms +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory from ..models import IPFilter, RestrictedCourse from ..test_utils import restrict_course diff --git a/openedx/core/djangoapps/embargo/tests/test_models.py b/openedx/core/djangoapps/embargo/tests/test_models.py index afe8da2423ba..5f65a854eee9 100644 --- a/openedx/core/djangoapps/embargo/tests/test_models.py +++ b/openedx/core/djangoapps/embargo/tests/test_models.py @@ -2,6 +2,7 @@ import json + import pytest from django.db.utils import IntegrityError from django.test import TestCase @@ -16,7 +17,7 @@ EmbargoedCourse, EmbargoedState, IPFilter, - RestrictedCourse + RestrictedCourse, ) diff --git a/openedx/core/djangoapps/embargo/tests/test_views.py b/openedx/core/djangoapps/embargo/tests/test_views.py index 1c8ea7268406..9dd072c6ede6 100644 --- a/openedx/core/djangoapps/embargo/tests/test_views.py +++ b/openedx/core/djangoapps/embargo/tests/test_views.py @@ -1,24 +1,33 @@ """Tests for embargo app views. """ -from unittest.mock import patch, MagicMock +from unittest.mock import MagicMock, patch import ddt -import maxminddb import geoip2.database - -from django.urls import reverse +import maxminddb from django.conf import settings +from django.urls import reverse -from .factories import CountryAccessRuleFactory, RestrictedCourseFactory -from .. import messages -from lms.djangoapps.course_api.tests.mixins import CourseApiFactoryMixin # lint-amnesty, pylint: disable=wrong-import-order -from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms # lint-amnesty, pylint: disable=wrong-import-order -from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme # lint-amnesty, pylint: disable=wrong-import-order from common.djangoapps.student.tests.factories import UserFactory # lint-amnesty, pylint: disable=wrong-import-order from common.djangoapps.util.testing import UrlResetMixin # lint-amnesty, pylint: disable=wrong-import-order +from lms.djangoapps.course_api.tests.mixins import ( + CourseApiFactoryMixin, # lint-amnesty, pylint: disable=wrong-import-order +) +from openedx.core.djangoapps.theming.tests.test_util import ( + with_comprehensive_theme, # lint-amnesty, pylint: disable=wrong-import-order +) +from openedx.core.djangolib.testing.utils import ( # lint-amnesty, pylint: disable=wrong-import-order + CacheIsolationTestCase, + skip_unless_lms, +) +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order + +from .. import messages +from .factories import CountryAccessRuleFactory, RestrictedCourseFactory @skip_unless_lms diff --git a/openedx/core/djangoapps/embargo/urls.py b/openedx/core/djangoapps/embargo/urls.py index d7e7c345c0cb..2372efffe204 100644 --- a/openedx/core/djangoapps/embargo/urls.py +++ b/openedx/core/djangoapps/embargo/urls.py @@ -1,6 +1,7 @@ """URLs served by the embargo app. """ from django.urls import path, re_path + from .views import CheckCourseAccessView, CourseAccessMessageView app_name = 'embargo' diff --git a/openedx/core/djangoapps/enrollments/data.py b/openedx/core/djangoapps/enrollments/data.py index b76042f72c9d..9d6cbc12fb8d 100644 --- a/openedx/core/djangoapps/enrollments/data.py +++ b/openedx/core/djangoapps/enrollments/data.py @@ -10,25 +10,25 @@ from django.db import transaction from opaque_keys.edx.keys import CourseKey +from common.djangoapps.student.models import ( + AlreadyEnrolledError, + CourseEnrollment, + CourseEnrollmentAttribute, + CourseFullError, + EnrollmentClosedError, + NonExistentCourseError, +) +from common.djangoapps.student.role_helpers import get_course_roles from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.enrollments.errors import ( CourseEnrollmentClosedError, CourseEnrollmentExistsError, CourseEnrollmentFullError, InvalidEnrollmentAttribute, - UserNotFoundError + UserNotFoundError, ) from openedx.core.djangoapps.enrollments.serializers import CourseEnrollmentSerializer, CourseSerializer from openedx.core.lib.exceptions import CourseNotFoundError -from common.djangoapps.student.models import ( - AlreadyEnrolledError, - CourseEnrollment, - CourseEnrollmentAttribute, - CourseFullError, - EnrollmentClosedError, - NonExistentCourseError -) -from common.djangoapps.student.role_helpers import get_course_roles log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/enrollments/enrollments_notifications.py b/openedx/core/djangoapps/enrollments/enrollments_notifications.py index e1f92efeecf4..3a0559d2ce4a 100644 --- a/openedx/core/djangoapps/enrollments/enrollments_notifications.py +++ b/openedx/core/djangoapps/enrollments/enrollments_notifications.py @@ -2,9 +2,9 @@ Enrollment notifications sender util. """ from django.conf import settings - from openedx_events.learning.data import UserNotificationData from openedx_events.learning.signals import USER_NOTIFICATION_REQUESTED + from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers diff --git a/openedx/core/djangoapps/enrollments/management/commands/enroll_user_in_course.py b/openedx/core/djangoapps/enrollments/management/commands/enroll_user_in_course.py index 03a3e0884e11..e5ec285dca08 100644 --- a/openedx/core/djangoapps/enrollments/management/commands/enroll_user_in_course.py +++ b/openedx/core/djangoapps/enrollments/management/commands/enroll_user_in_course.py @@ -4,8 +4,9 @@ from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.core.management.base import BaseCommand -from openedx.core.djangoapps.enrollments.data import CourseEnrollmentExistsError + from openedx.core.djangoapps.enrollments.api import add_enrollment +from openedx.core.djangoapps.enrollments.data import CourseEnrollmentExistsError class Command(BaseCommand): diff --git a/openedx/core/djangoapps/enrollments/management/tests/test_enroll_user_in_course.py b/openedx/core/djangoapps/enrollments/management/tests/test_enroll_user_in_course.py index 3d4b6f6e5c22..0863f1412cbe 100644 --- a/openedx/core/djangoapps/enrollments/management/tests/test_enroll_user_in_course.py +++ b/openedx/core/djangoapps/enrollments/management/tests/test_enroll_user_in_course.py @@ -10,8 +10,9 @@ from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.enrollments.api import get_enrollment from openedx.core.djangolib.testing.utils import skip_unless_lms - -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/core/djangoapps/enrollments/permissions.py b/openedx/core/djangoapps/enrollments/permissions.py index b4a6754ecc78..e142ac298dc8 100644 --- a/openedx/core/djangoapps/enrollments/permissions.py +++ b/openedx/core/djangoapps/enrollments/permissions.py @@ -3,6 +3,7 @@ """ from bridgekeeper import perms + from lms.djangoapps.courseware.rules import HasAccessRule ENROLL_IN_COURSE = 'enrollment.enroll_in_course' diff --git a/openedx/core/djangoapps/enrollments/services.py b/openedx/core/djangoapps/enrollments/services.py index 34bdad9d2107..b62f9e98a8ae 100644 --- a/openedx/core/djangoapps/enrollments/services.py +++ b/openedx/core/djangoapps/enrollments/services.py @@ -7,8 +7,8 @@ from django.conf import settings from django.contrib.auth import get_user_model from django.db.models import Q - from opaque_keys.edx.keys import CourseKey + from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import CourseEnrollment from openedx.core.djangoapps.content.course_overviews.api import get_course_overview_or_none diff --git a/openedx/core/djangoapps/enrollments/tests/test_api.py b/openedx/core/djangoapps/enrollments/tests/test_api.py index 0b9dc60d1059..54369ea6ed39 100644 --- a/openedx/core/djangoapps/enrollments/tests/test_api.py +++ b/openedx/core/djangoapps/enrollments/tests/test_api.py @@ -11,7 +11,9 @@ from common.djangoapps.course_modes.models import CourseMode from openedx.core.djangoapps.enrollments import api from openedx.core.djangoapps.enrollments.errors import ( - CourseModeNotFoundError, EnrollmentApiLoadError, EnrollmentNotFoundError, + CourseModeNotFoundError, + EnrollmentApiLoadError, + EnrollmentNotFoundError, ) from openedx.core.djangoapps.enrollments.tests import fake_data_api from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms diff --git a/openedx/core/djangoapps/enrollments/tests/test_data.py b/openedx/core/djangoapps/enrollments/tests/test_data.py index 41bdfff62a50..304748bc5a63 100644 --- a/openedx/core/djangoapps/enrollments/tests/test_data.py +++ b/openedx/core/djangoapps/enrollments/tests/test_data.py @@ -5,27 +5,34 @@ import datetime from unittest.mock import patch +from zoneinfo import ZoneInfo import ddt import pytest -from zoneinfo import ZoneInfo from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory +from common.djangoapps.student.models import ( # lint-amnesty, pylint: disable=line-too-long + AlreadyEnrolledError, + CourseEnrollment, + CourseFullError, + EnrollmentClosedError, +) from common.djangoapps.student.roles import AuthzCompatCourseAccessRole +from common.djangoapps.student.tests.factories import CourseAccessRoleFactory, CourseEnrollmentFactory, UserFactory from openedx.core.djangoapps.enrollments import data from openedx.core.djangoapps.enrollments.errors import ( CourseEnrollmentClosedError, CourseEnrollmentExistsError, CourseEnrollmentFullError, - UserNotFoundError + UserNotFoundError, ) from openedx.core.djangoapps.enrollments.serializers import CourseEnrollmentSerializer from openedx.core.djangolib.testing.utils import skip_unless_lms from openedx.core.lib.exceptions import CourseNotFoundError -from common.djangoapps.student.models import AlreadyEnrolledError, CourseEnrollment, CourseFullError, EnrollmentClosedError # lint-amnesty, pylint: disable=line-too-long -from common.djangoapps.student.tests.factories import CourseAccessRoleFactory, UserFactory, CourseEnrollmentFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/core/djangoapps/enrollments/tests/test_enrollments_notifications.py b/openedx/core/djangoapps/enrollments/tests/test_enrollments_notifications.py index aebbd9670890..0808e52c53ac 100644 --- a/openedx/core/djangoapps/enrollments/tests/test_enrollments_notifications.py +++ b/openedx/core/djangoapps/enrollments/tests/test_enrollments_notifications.py @@ -1,15 +1,15 @@ """ Unit tests for the EnrollmentsNotificationSender class """ -import unittest import datetime +import unittest from unittest.mock import MagicMock, patch -from django.test.utils import override_settings import pytest +from django.test.utils import override_settings +from openedx_events.learning.data import UserNotificationData from openedx.core.djangoapps.enrollments.enrollments_notifications import EnrollmentNotificationSender -from openedx_events.learning.data import UserNotificationData DEFAULT_MFE_URL = "https://learning.default" SITE_CONF_MFE_URL = "https://learning.siteconf" diff --git a/openedx/core/djangoapps/enrollments/tests/test_services.py b/openedx/core/djangoapps/enrollments/tests/test_services.py index 14107ee5163a..47ff09399c03 100644 --- a/openedx/core/djangoapps/enrollments/tests/test_services.py +++ b/openedx/core/djangoapps/enrollments/tests/test_services.py @@ -9,7 +9,9 @@ from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangoapps.enrollments.services import EnrollmentsService -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) @ddt.ddt diff --git a/openedx/core/djangoapps/enrollments/tests/test_views.py b/openedx/core/djangoapps/enrollments/tests/test_views.py index a0f265d603fc..d9e0f55e7a06 100644 --- a/openedx/core/djangoapps/enrollments/tests/test_views.py +++ b/openedx/core/djangoapps/enrollments/tests/test_views.py @@ -8,11 +8,11 @@ import json from unittest.mock import patch from urllib.parse import quote +from zoneinfo import ZoneInfo import ddt import httpretty import pytest -from zoneinfo import ZoneInfo from django.conf import settings from django.core.cache import cache from django.core.exceptions import ImproperlyConfigured diff --git a/openedx/core/djangoapps/enrollments/views.py b/openedx/core/djangoapps/enrollments/views.py index dc3423245e9b..65d567ebdf1c 100644 --- a/openedx/core/djangoapps/enrollments/views.py +++ b/openedx/core/djangoapps/enrollments/views.py @@ -13,12 +13,12 @@ from django.db import IntegrityError # lint-amnesty, pylint: disable=wrong-import-order from django.db.models import Q # lint-amnesty, pylint: disable=wrong-import-order from django.utils.decorators import method_decorator # lint-amnesty, pylint: disable=wrong-import-order -from edx_rest_framework_extensions.auth.jwt.authentication import ( +from edx_rest_framework_extensions.auth.jwt.authentication import ( # lint-amnesty, pylint: disable=wrong-import-order JwtAuthentication, -) # lint-amnesty, pylint: disable=wrong-import-order -from edx_rest_framework_extensions.auth.session.authentication import ( +) +from edx_rest_framework_extensions.auth.session.authentication import ( # lint-amnesty, pylint: disable=wrong-import-order SessionAuthenticationAllowInactiveUser, -) # lint-amnesty, pylint: disable=wrong-import-order +) from opaque_keys import InvalidKeyError # lint-amnesty, pylint: disable=wrong-import-order from opaque_keys.edx.keys import CourseKey # lint-amnesty, pylint: disable=wrong-import-order from rest_framework import permissions, status # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/core/djangoapps/external_user_ids/tests/test_admin_generate_id.py b/openedx/core/djangoapps/external_user_ids/tests/test_admin_generate_id.py index f629581e7892..5ec0c711c7d1 100644 --- a/openedx/core/djangoapps/external_user_ids/tests/test_admin_generate_id.py +++ b/openedx/core/djangoapps/external_user_ids/tests/test_admin_generate_id.py @@ -2,15 +2,14 @@ Test the logic behind the Generate External IDs tools in Admin """ from unittest import mock + from django.contrib.admin.sites import AdminSite from django.test import TestCase -from common.djangoapps.student.tests.factories import UserFactory -from openedx.core.djangoapps.external_user_ids.models import ( - ExternalId, -) -from openedx.core.djangoapps.external_user_ids.tests.factories import ExternalIDTypeFactory +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.external_user_ids.admin import ExternalIdAdmin +from openedx.core.djangoapps.external_user_ids.models import ExternalId +from openedx.core.djangoapps.external_user_ids.tests.factories import ExternalIDTypeFactory class TestGenerateExternalIds(TestCase): diff --git a/openedx/core/djangoapps/external_user_ids/tests/test_batch_generate_id.py b/openedx/core/djangoapps/external_user_ids/tests/test_batch_generate_id.py index 899554599f12..5313aecb82a0 100644 --- a/openedx/core/djangoapps/external_user_ids/tests/test_batch_generate_id.py +++ b/openedx/core/djangoapps/external_user_ids/tests/test_batch_generate_id.py @@ -4,6 +4,7 @@ import django from django.test import TransactionTestCase + from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.external_user_ids.models import ExternalId from openedx.core.djangoapps.external_user_ids.tests.factories import ExternalIDTypeFactory diff --git a/openedx/core/djangoapps/geoinfo/tests/test_middleware.py b/openedx/core/djangoapps/geoinfo/tests/test_middleware.py index 45b3ab2f99fd..d309ead4732a 100644 --- a/openedx/core/djangoapps/geoinfo/tests/test_middleware.py +++ b/openedx/core/djangoapps/geoinfo/tests/test_middleware.py @@ -11,8 +11,8 @@ from django.test import TestCase from django.test.client import RequestFactory -from openedx.core.djangoapps.geoinfo.middleware import CountryMiddleware from common.djangoapps.student.tests.factories import AnonymousUserFactory, UserFactory +from openedx.core.djangoapps.geoinfo.middleware import CountryMiddleware class CountryMiddlewareTests(TestCase): diff --git a/openedx/core/djangoapps/heartbeat/urls.py b/openedx/core/djangoapps/heartbeat/urls.py index 074eab73be9c..5547202dedf4 100644 --- a/openedx/core/djangoapps/heartbeat/urls.py +++ b/openedx/core/djangoapps/heartbeat/urls.py @@ -3,6 +3,7 @@ """ from django.urls import path + from openedx.core.djangoapps.heartbeat.views import heartbeat urlpatterns = [ diff --git a/openedx/core/djangoapps/heartbeat/views.py b/openedx/core/djangoapps/heartbeat/views.py index a3615a269e4f..b31f547fe1f8 100644 --- a/openedx/core/djangoapps/heartbeat/views.py +++ b/openedx/core/djangoapps/heartbeat/views.py @@ -9,7 +9,6 @@ from .runchecks import runchecks - log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/lang_pref/api.py b/openedx/core/djangoapps/lang_pref/api.py index a937e81f8ee6..d2b7bf7082f4 100644 --- a/openedx/core/djangoapps/lang_pref/api.py +++ b/openedx/core/djangoapps/lang_pref/api.py @@ -5,6 +5,7 @@ from django.conf import settings from django.utils.translation import gettext as _ + from openedx.core.djangoapps.dark_lang.models import DarkLangConfig from openedx.core.djangoapps.site_configuration.helpers import get_value diff --git a/openedx/core/djangoapps/lang_pref/tests/test_api.py b/openedx/core/djangoapps/lang_pref/tests/test_api.py index 67f2a8f52dfb..0f82db164ce1 100644 --- a/openedx/core/djangoapps/lang_pref/tests/test_api.py +++ b/openedx/core/djangoapps/lang_pref/tests/test_api.py @@ -5,6 +5,7 @@ from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.test.utils import override_settings from django.utils import translation + from openedx.core.djangoapps.dark_lang.models import DarkLangConfig from openedx.core.djangoapps.lang_pref import api as language_api from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration_context diff --git a/openedx/core/djangoapps/lang_pref/tests/test_middleware.py b/openedx/core/djangoapps/lang_pref/tests/test_middleware.py index c7e2897b0c4d..b71b91605cf9 100644 --- a/openedx/core/djangoapps/lang_pref/tests/test_middleware.py +++ b/openedx/core/djangoapps/lang_pref/tests/test_middleware.py @@ -11,10 +11,10 @@ from django.contrib.sessions.middleware import SessionMiddleware from django.http import HttpResponse from django.test.client import Client, RequestFactory -from openedx.core.lib.api.test_utils import override_settings from django.urls import reverse from django.utils.translation.trans_real import parse_accept_lang_header +from common.djangoapps.student.tests.factories import AnonymousUserFactory, UserFactory from openedx.core.djangoapps.lang_pref import COOKIE_DURATION, LANGUAGE_KEY from openedx.core.djangoapps.lang_pref.middleware import LanguagePreferenceMiddleware from openedx.core.djangoapps.site_configuration.tests.test_util import ( @@ -24,10 +24,10 @@ from openedx.core.djangoapps.user_api.preferences.api import ( delete_user_preference, get_user_preference, - set_user_preference + set_user_preference, ) from openedx.core.djangolib.testing.utils import CacheIsolationTestCase -from common.djangoapps.student.tests.factories import AnonymousUserFactory, UserFactory +from openedx.core.lib.api.test_utils import override_settings @ddt.ddt diff --git a/openedx/core/djangoapps/models/tests/test_course_details.py b/openedx/core/djangoapps/models/tests/test_course_details.py index 769499bf2353..a5ba23df4ad8 100644 --- a/openedx/core/djangoapps/models/tests/test_course_details.py +++ b/openedx/core/djangoapps/models/tests/test_course_details.py @@ -4,18 +4,18 @@ import datetime -from django.test import override_settings -import pytest -import ddt from zoneinfo import ZoneInfo -from xmodule.modulestore import ModuleStoreEnum +import ddt +import pytest +from django.test import override_settings + +from openedx.core.djangoapps.models.course_details import ABOUT_ATTRIBUTES, CourseDetails from xmodule.data import CertificatesDisplayBehaviors +from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from openedx.core.djangoapps.models.course_details import ABOUT_ATTRIBUTES, CourseDetails - EXAMPLE_CERTIFICATE_AVAILABLE_DATE = datetime.date(2020, 1, 1) diff --git a/openedx/core/djangoapps/notifications/audience_filters.py b/openedx/core/djangoapps/notifications/audience_filters.py index a4be0070e7be..af833be93131 100644 --- a/openedx/core/djangoapps/notifications/audience_filters.py +++ b/openedx/core/djangoapps/notifications/audience_filters.py @@ -2,29 +2,27 @@ Audience based filters for notifications and Notification filters """ -from abc import abstractmethod - -from opaque_keys.edx.keys import CourseKey - import logging +from abc import abstractmethod from typing import List from django.utils import timezone +from opaque_keys.edx.keys import CourseKey from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import CourseAccessRole, CourseEnrollment -from openedx.core.djangoapps.course_date_signals.utils import get_expected_duration -from common.djangoapps.student.roles import CourseStaffRole, CourseInstructorRole +from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole from lms.djangoapps.discussion.django_comment_client.utils import get_users_with_roles from lms.djangoapps.teams.models import CourseTeam +from openedx.core.djangoapps.course_date_signals.utils import get_expected_duration from openedx.core.djangoapps.course_groups.models import CourseUserGroup from openedx.core.djangoapps.django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, - FORUM_ROLE_MODERATOR, - FORUM_ROLE_GROUP_MODERATOR, FORUM_ROLE_COMMUNITY_TA, + FORUM_ROLE_GROUP_MODERATOR, + FORUM_ROLE_MODERATOR, FORUM_ROLE_STUDENT, - Role + Role, ) from openedx.core.djangoapps.notifications.base_notification import COURSE_NOTIFICATION_TYPES from openedx.features.course_duration_limits.models import CourseDurationLimitConfig diff --git a/openedx/core/djangoapps/notifications/base_notification.py b/openedx/core/djangoapps/notifications/base_notification.py index 7b35a0ce61dd..89c61dd1ca99 100644 --- a/openedx/core/djangoapps/notifications/base_notification.py +++ b/openedx/core/djangoapps/notifications/base_notification.py @@ -1,17 +1,16 @@ """ Base setup for Notification Apps and Types. """ -from typing import Any, Literal, TypedDict, NotRequired +from typing import Any, Literal, NotRequired, TypedDict from django.utils.translation import gettext_lazy as _ -from .email_notifications import EmailCadence from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole -from .settings_override import get_notification_types_config, get_notification_apps_config - -from ..django_comment_common.models import 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 +from .email_notifications import EmailCadence from .notification_content import get_notification_type_context_function +from .settings_override import get_notification_apps_config, get_notification_types_config FILTER_AUDIT_EXPIRED_USERS_WITH_NO_ROLE = 'filter_audit_expired_users_with_no_role' diff --git a/openedx/core/djangoapps/notifications/email/events.py b/openedx/core/djangoapps/notifications/email/events.py index c5da45b5b6c1..fe8fa9af1ff5 100644 --- a/openedx/core/djangoapps/notifications/email/events.py +++ b/openedx/core/djangoapps/notifications/email/events.py @@ -8,7 +8,6 @@ from common.djangoapps.track import segment from openedx.core.djangoapps.notifications.base_notification import COURSE_NOTIFICATION_APPS - EMAIL_DIGEST_SENT = "edx.notifications.email_digest" diff --git a/openedx/core/djangoapps/notifications/email/tasks.py b/openedx/core/djangoapps/notifications/email/tasks.py index aef57473eac1..1250e4cc92db 100644 --- a/openedx/core/djangoapps/notifications/email/tasks.py +++ b/openedx/core/djangoapps/notifications/email/tasks.py @@ -9,17 +9,18 @@ from django.conf import settings from django.contrib.auth import get_user_model from django.db import transaction -from django.utils.translation import gettext as _, override as translation_override +from django.utils.translation import gettext as _ +from django.utils.translation import override as translation_override from edx_ace import ace from edx_ace.recipient import Recipient from edx_django_utils.monitoring import set_code_owner_attribute from opaque_keys.edx.keys import CourseKey from openedx.core.djangoapps.notifications.email_notifications import EmailCadence -from openedx.core.djangoapps.notifications.models import ( - Notification, - NotificationPreference, -) +from openedx.core.djangoapps.notifications.models import Notification, NotificationPreference + +from ..base_notification import COURSE_NOTIFICATION_APPS +from ..config.waffle import DISABLE_EMAIL_NOTIFICATIONS from .events import send_immediate_email_digest_sent_event, send_user_email_digest_sent_event from .message_type import EmailNotificationMessageType from .utils import ( @@ -33,8 +34,6 @@ get_start_end_date, get_text_for_notification_type, ) -from ..base_notification import COURSE_NOTIFICATION_APPS -from ..config.waffle import DISABLE_EMAIL_NOTIFICATIONS User = get_user_model() logger = get_task_logger(__name__) diff --git a/openedx/core/djangoapps/notifications/email/tests/test_tasks.py b/openedx/core/djangoapps/notifications/email/tests/test_tasks.py index e5ed93b41c9e..7977b2b26e32 100644 --- a/openedx/core/djangoapps/notifications/email/tests/test_tasks.py +++ b/openedx/core/djangoapps/notifications/email/tests/test_tasks.py @@ -22,20 +22,17 @@ send_digest_email_to_all_users, send_digest_email_to_user, send_immediate_cadence_email, - send_immediate_email + send_immediate_email, ) from openedx.core.djangoapps.notifications.email.utils import get_start_end_date from openedx.core.djangoapps.notifications.email_notifications import EmailCadence -from openedx.core.djangoapps.notifications.models import ( - Notification, - NotificationPreference -) +from openedx.core.djangoapps.notifications.models import Notification, NotificationPreference from openedx.core.djangoapps.notifications.tasks import send_notifications from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from .utils import create_notification from ...config.waffle import DISABLE_EMAIL_NOTIFICATIONS +from .utils import create_notification User = get_user_model() diff --git a/openedx/core/djangoapps/notifications/email/tests/test_utils.py b/openedx/core/djangoapps/notifications/email/tests/test_utils.py index 805c82e311e3..f41c18e4c4fc 100644 --- a/openedx/core/djangoapps/notifications/email/tests/test_utils.py +++ b/openedx/core/djangoapps/notifications/email/tests/test_utils.py @@ -2,19 +2,17 @@ Test utils.py """ import datetime +from unittest.mock import patch + import ddt import pytest - -from django.http.response import Http404 from django.conf import settings +from django.http.response import Http404 from django.test.utils import override_settings -from unittest.mock import patch from pytz import utc from common.djangoapps.student.tests.factories import UserFactory - from openedx.core.djangoapps.notifications.email import ONE_CLICK_EMAIL_UNSUB_KEY -from openedx.core.djangoapps.notifications.models import Notification from openedx.core.djangoapps.notifications.email.utils import ( add_additional_attributes_to_notifications, create_app_notifications_dict, @@ -28,6 +26,7 @@ get_unsubscribe_link, update_user_preferences_from_patch, ) +from openedx.core.djangoapps.notifications.models import Notification from openedx.core.djangoapps.user_api.models import UserPreference from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/openedx/core/djangoapps/notifications/email/utils.py b/openedx/core/djangoapps/notifications/email/utils.py index 1fbb47fb406d..8b147991a7cb 100644 --- a/openedx/core/djangoapps/notifications/email/utils.py +++ b/openedx/core/djangoapps/notifications/email/utils.py @@ -16,18 +16,18 @@ from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY from openedx.core.djangoapps.notifications.base_notification import ( COURSE_NOTIFICATION_TYPES, - get_default_values_of_preferences + get_default_values_of_preferences, ) from openedx.core.djangoapps.notifications.email import ONE_CLICK_EMAIL_UNSUB_KEY from openedx.core.djangoapps.notifications.email_notifications import EmailCadence from openedx.core.djangoapps.notifications.events import notification_preference_unsubscribe_event from openedx.core.djangoapps.notifications.models import NotificationPreference -from openedx.core.djangoapps.user_api.models import UserPreference from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.djangoapps.user_api.models import UserPreference from xmodule.modulestore.django import modulestore -from .notification_icons import NotificationTypeIcons from ..utils import create_account_notification_pref_if_not_exists +from .notification_icons import NotificationTypeIcons User = get_user_model() diff --git a/openedx/core/djangoapps/notifications/handlers.py b/openedx/core/djangoapps/notifications/handlers.py index f9989caddf6c..7a7cc06ee64d 100644 --- a/openedx/core/djangoapps/notifications/handlers.py +++ b/openedx/core/djangoapps/notifications/handlers.py @@ -4,13 +4,10 @@ import logging from django.contrib.auth import get_user_model -from django.db import IntegrityError, transaction, ProgrammingError +from django.db import IntegrityError, ProgrammingError, transaction from django.db.models.signals import post_save from django.dispatch import receiver -from openedx_events.learning.signals import ( - COURSE_NOTIFICATION_REQUESTED, - USER_NOTIFICATION_REQUESTED -) +from openedx_events.learning.signals import COURSE_NOTIFICATION_REQUESTED, USER_NOTIFICATION_REQUESTED from common.djangoapps.student.models import CourseEnrollment from openedx.core.djangoapps.notifications.audience_filters import ( @@ -18,7 +15,7 @@ CourseRoleAudienceFilter, EnrollmentAudienceFilter, ForumRoleAudienceFilter, - TeamAudienceFilter + TeamAudienceFilter, ) from openedx.core.djangoapps.notifications.base_notification import COURSE_NOTIFICATION_TYPES from openedx.core.djangoapps.notifications.models import NotificationPreference diff --git a/openedx/core/djangoapps/notifications/management/commands/delete_notifications.py b/openedx/core/djangoapps/notifications/management/commands/delete_notifications.py index 62f2069100c9..62520010e61d 100644 --- a/openedx/core/djangoapps/notifications/management/commands/delete_notifications.py +++ b/openedx/core/djangoapps/notifications/management/commands/delete_notifications.py @@ -6,13 +6,9 @@ from django.core.management.base import BaseCommand -from openedx.core.djangoapps.notifications.base_notification import ( - COURSE_NOTIFICATION_APPS, - COURSE_NOTIFICATION_TYPES -) +from openedx.core.djangoapps.notifications.base_notification import COURSE_NOTIFICATION_APPS, COURSE_NOTIFICATION_TYPES from openedx.core.djangoapps.notifications.tasks import delete_notifications - logger = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/notifications/management/commands/fix_mixed_email_cadence.py b/openedx/core/djangoapps/notifications/management/commands/fix_mixed_email_cadence.py index cf1c5c0c5a7a..3d03c7775266 100644 --- a/openedx/core/djangoapps/notifications/management/commands/fix_mixed_email_cadence.py +++ b/openedx/core/djangoapps/notifications/management/commands/fix_mixed_email_cadence.py @@ -4,6 +4,7 @@ """ import logging + from django.core.management.base import BaseCommand from openedx.core.djangoapps.notifications.models import NotificationPreference diff --git a/openedx/core/djangoapps/notifications/management/commands/send_email_digest.py b/openedx/core/djangoapps/notifications/management/commands/send_email_digest.py index 79857c18cf8a..99e51bd10d35 100644 --- a/openedx/core/djangoapps/notifications/management/commands/send_email_digest.py +++ b/openedx/core/djangoapps/notifications/management/commands/send_email_digest.py @@ -3,8 +3,8 @@ """ from django.core.management.base import BaseCommand -from openedx.core.djangoapps.notifications.email_notifications import EmailCadence from openedx.core.djangoapps.notifications.email.tasks import send_digest_email_to_all_users +from openedx.core.djangoapps.notifications.email_notifications import EmailCadence class Command(BaseCommand): diff --git a/openedx/core/djangoapps/notifications/management/commands/update_notification_preferences.py b/openedx/core/djangoapps/notifications/management/commands/update_notification_preferences.py index 2653e8b1cdad..623427a42f74 100644 --- a/openedx/core/djangoapps/notifications/management/commands/update_notification_preferences.py +++ b/openedx/core/djangoapps/notifications/management/commands/update_notification_preferences.py @@ -6,11 +6,8 @@ from django.core.management.base import BaseCommand, CommandError from django.db import transaction +from openedx.core.djangoapps.notifications.base_notification import COURSE_NOTIFICATION_APPS, COURSE_NOTIFICATION_TYPES from openedx.core.djangoapps.notifications.models import NotificationPreference -from openedx.core.djangoapps.notifications.base_notification import ( - COURSE_NOTIFICATION_APPS, - COURSE_NOTIFICATION_TYPES -) logger = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/notifications/management/tests/test_delete_notifications.py b/openedx/core/djangoapps/notifications/management/tests/test_delete_notifications.py index d4b65fa565c6..c15a06da3f0d 100644 --- a/openedx/core/djangoapps/notifications/management/tests/test_delete_notifications.py +++ b/openedx/core/djangoapps/notifications/management/tests/test_delete_notifications.py @@ -1,10 +1,9 @@ """ Tests delete_notifications management command """ -import ddt - from unittest import mock +import ddt from django.core.management import call_command from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase diff --git a/openedx/core/djangoapps/notifications/migrations/0001_initial.py b/openedx/core/djangoapps/notifications/migrations/0001_initial.py index 510e4b877bf6..812335a26d0a 100644 --- a/openedx/core/djangoapps/notifications/migrations/0001_initial.py +++ b/openedx/core/djangoapps/notifications/migrations/0001_initial.py @@ -1,10 +1,10 @@ # Generated by Django 3.2.18 on 2023-04-12 23:07 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/notifications/migrations/0002_notificationpreference.py b/openedx/core/djangoapps/notifications/migrations/0002_notificationpreference.py index e1b409c17491..06a2f703261b 100644 --- a/openedx/core/djangoapps/notifications/migrations/0002_notificationpreference.py +++ b/openedx/core/djangoapps/notifications/migrations/0002_notificationpreference.py @@ -1,11 +1,11 @@ # Generated by Django 3.2.18 on 2023-05-03 09:05 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields import opaque_keys.edx.django.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/notifications/migrations/0004_auto_20230607_0757.py b/openedx/core/djangoapps/notifications/migrations/0004_auto_20230607_0757.py index ba9ebfb796c3..f894d2fcaea5 100644 --- a/openedx/core/djangoapps/notifications/migrations/0004_auto_20230607_0757.py +++ b/openedx/core/djangoapps/notifications/migrations/0004_auto_20230607_0757.py @@ -1,10 +1,10 @@ # Generated by Django 3.2.19 on 2023-06-07 07:57 -from django.conf import settings -from django.db import migrations, models import django.utils.timezone import model_utils.fields import opaque_keys.edx.django.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/notifications/migrations/0008_notificationpreference.py b/openedx/core/djangoapps/notifications/migrations/0008_notificationpreference.py index 4427906ca4b5..652215d50685 100644 --- a/openedx/core/djangoapps/notifications/migrations/0008_notificationpreference.py +++ b/openedx/core/djangoapps/notifications/migrations/0008_notificationpreference.py @@ -1,10 +1,10 @@ # Generated by Django 4.2.21 on 2025-05-29 08:27 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/notifications/models.py b/openedx/core/djangoapps/notifications/models.py index 5cd76a01d24c..ad9860a6bb77 100644 --- a/openedx/core/djangoapps/notifications/models.py +++ b/openedx/core/djangoapps/notifications/models.py @@ -9,8 +9,9 @@ from opaque_keys.edx.django.models import CourseKeyField from openedx.core.djangoapps.notifications.base_notification import ( + COURSE_NOTIFICATION_TYPES, + get_default_values_of_preferences, get_notification_content, - COURSE_NOTIFICATION_TYPES, get_default_values_of_preferences ) User = get_user_model() diff --git a/openedx/core/djangoapps/notifications/serializers.py b/openedx/core/djangoapps/notifications/serializers.py index 7dc1e24f3c5c..78d0998db99e 100644 --- a/openedx/core/djangoapps/notifications/serializers.py +++ b/openedx/core/djangoapps/notifications/serializers.py @@ -8,7 +8,7 @@ from openedx.core.djangoapps.notifications.models import ( Notification, get_additional_notification_channel_settings, - get_notification_channels + get_notification_channels, ) from .base_notification import COURSE_NOTIFICATION_APPS, COURSE_NOTIFICATION_TYPES, EmailCadence diff --git a/openedx/core/djangoapps/notifications/settings_override.py b/openedx/core/djangoapps/notifications/settings_override.py index 9e20dfff5e68..4ba81060e7b0 100644 --- a/openedx/core/djangoapps/notifications/settings_override.py +++ b/openedx/core/djangoapps/notifications/settings_override.py @@ -5,7 +5,8 @@ via Django settings. """ from copy import deepcopy -from typing import Dict, Set, Any +from typing import Any, Dict, Set + from django.conf import settings diff --git a/openedx/core/djangoapps/notifications/tasks.py b/openedx/core/djangoapps/notifications/tasks.py index 77a23515ad64..ac8f7b16645b 100644 --- a/openedx/core/djangoapps/notifications/tasks.py +++ b/openedx/core/djangoapps/notifications/tasks.py @@ -3,6 +3,7 @@ """ import uuid from datetime import datetime, timedelta +from zoneinfo import ZoneInfo from celery import shared_task from celery.utils.log import get_task_logger @@ -10,34 +11,32 @@ from django.core.exceptions import ValidationError from edx_django_utils.monitoring import set_code_owner_attribute from opaque_keys.edx.keys import CourseKey -from zoneinfo import ZoneInfo from openedx.core.djangoapps.notifications.audience_filters import NotificationFilter from openedx.core.djangoapps.notifications.base_notification import ( COURSE_NOTIFICATION_TYPES, - get_notification_content, get_default_values_of_preferences + get_default_values_of_preferences, + get_notification_content, ) - +from openedx.core.djangoapps.notifications.config.waffle import DISABLE_NOTIFICATIONS, ENABLE_PUSH_NOTIFICATIONS from openedx.core.djangoapps.notifications.email.tasks import send_immediate_cadence_email -from openedx.core.djangoapps.notifications.config.waffle import ( - ENABLE_PUSH_NOTIFICATIONS, DISABLE_NOTIFICATIONS -) from openedx.core.djangoapps.notifications.email_notifications import EmailCadence from openedx.core.djangoapps.notifications.events import notification_generated_event from openedx.core.djangoapps.notifications.grouping_notifications import ( NotificationRegistry, get_user_existing_notifications, - group_user_notifications + group_user_notifications, ) from openedx.core.djangoapps.notifications.models import ( Notification, - NotificationPreference, create_notification_preference, + NotificationPreference, + create_notification_preference, ) from openedx.core.djangoapps.notifications.push.tasks import send_ace_msg_to_push_channel from openedx.core.djangoapps.notifications.utils import ( clean_arguments, + create_account_notification_pref_if_not_exists, get_list_in_batches, - create_account_notification_pref_if_not_exists ) logger = get_task_logger(__name__) diff --git a/openedx/core/djangoapps/notifications/tests/test_filters.py b/openedx/core/djangoapps/notifications/tests/test_filters.py index 4d645438df52..a580788d0e40 100644 --- a/openedx/core/djangoapps/notifications/tests/test_filters.py +++ b/openedx/core/djangoapps/notifications/tests/test_filters.py @@ -11,25 +11,25 @@ from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole -from common.djangoapps.student.tests.factories import UserFactory, CourseEnrollmentFactory +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from lms.djangoapps.teams.tests.factories import CourseTeamFactory, CourseTeamMembershipFactory from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory from openedx.core.djangoapps.django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, - FORUM_ROLE_STUDENT, FORUM_ROLE_GROUP_MODERATOR, FORUM_ROLE_MODERATOR, + FORUM_ROLE_STUDENT, Role, ) from openedx.core.djangoapps.notifications.audience_filters import ( + CohortAudienceFilter, + CourseRoleAudienceFilter, EnrollmentAudienceFilter, ForumRoleAudienceFilter, - CourseRoleAudienceFilter, - CohortAudienceFilter, - TeamAudienceFilter, NotificationFilter, + TeamAudienceFilter, ) from openedx.core.djangoapps.notifications.handlers import calculate_course_wide_notification_audience from openedx.features.course_duration_limits.models import CourseDurationLimitConfig diff --git a/openedx/core/djangoapps/notifications/tests/test_handlers.py b/openedx/core/djangoapps/notifications/tests/test_handlers.py index d349c7a16e1a..a058a4e80d42 100644 --- a/openedx/core/djangoapps/notifications/tests/test_handlers.py +++ b/openedx/core/djangoapps/notifications/tests/test_handlers.py @@ -1,10 +1,11 @@ """ Tests for the notifications handlers. """ -from django.test import TestCase from unittest.mock import patch -from openedx_events.learning.signals import COURSE_NOTIFICATION_REQUESTED + +from django.test import TestCase from openedx_events.learning.data import CourseNotificationData +from openedx_events.learning.signals import COURSE_NOTIFICATION_REQUESTED class CourseNotificationsTest(TestCase): diff --git a/openedx/core/djangoapps/notifications/tests/test_notification_grouping.py b/openedx/core/djangoapps/notifications/tests/test_notification_grouping.py index 7c0def059d7b..4f9219af06fe 100644 --- a/openedx/core/djangoapps/notifications/tests/test_notification_grouping.py +++ b/openedx/core/djangoapps/notifications/tests/test_notification_grouping.py @@ -2,18 +2,22 @@ Tests for notification grouping module """ -import ddt import unittest -from unittest.mock import MagicMock, patch from datetime import datetime +from unittest.mock import MagicMock, patch from zoneinfo import ZoneInfo +import ddt + from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.notifications.grouping_notifications import ( BaseNotificationGrouper, + NewPostGrouper, + NewResponseGrouper, + NewResponseOnFollowedPostGrouper, NotificationRegistry, + get_user_existing_notifications, group_user_notifications, - get_user_existing_notifications, NewPostGrouper, NewResponseGrouper, NewResponseOnFollowedPostGrouper ) from openedx.core.djangoapps.notifications.models import Notification from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase diff --git a/openedx/core/djangoapps/notifications/tests/test_settings_override.py b/openedx/core/djangoapps/notifications/tests/test_settings_override.py index 86776ac69065..9e71f212d869 100644 --- a/openedx/core/djangoapps/notifications/tests/test_settings_override.py +++ b/openedx/core/djangoapps/notifications/tests/test_settings_override.py @@ -5,11 +5,11 @@ from openedx.core.djangoapps.notifications.base_notification import ( _COURSE_NOTIFICATION_APPS, - _COURSE_NOTIFICATION_TYPES + _COURSE_NOTIFICATION_TYPES, ) from openedx.core.djangoapps.notifications.settings_override import ( get_notification_apps_config, - get_notification_types_config + get_notification_types_config, ) diff --git a/openedx/core/djangoapps/notifications/tests/test_tasks_with_account_level_pref.py b/openedx/core/djangoapps/notifications/tests/test_tasks_with_account_level_pref.py index 2de69f79f2ab..6092e460dfca 100644 --- a/openedx/core/djangoapps/notifications/tests/test_tasks_with_account_level_pref.py +++ b/openedx/core/djangoapps/notifications/tests/test_tasks_with_account_level_pref.py @@ -14,13 +14,10 @@ from common.djangoapps.student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from ..config.waffle import DISABLE_NOTIFICATIONS +from ..config.waffle import DISABLE_NOTIFICATIONS from ..models import Notification, NotificationPreference -from ..tasks import ( - delete_notifications, - send_notifications, -) +from ..tasks import delete_notifications, send_notifications from .utils import create_notification diff --git a/openedx/core/djangoapps/notifications/tests/test_views.py b/openedx/core/djangoapps/notifications/tests/test_views.py index aa663e125264..f7656aedf875 100644 --- a/openedx/core/djangoapps/notifications/tests/test_views.py +++ b/openedx/core/djangoapps/notifications/tests/test_views.py @@ -3,6 +3,7 @@ """ from datetime import datetime, timedelta from unittest import mock +from zoneinfo import ZoneInfo import ddt from django.conf import settings @@ -10,33 +11,27 @@ from django.core.cache import cache from django.test.utils import override_settings from django.urls import reverse -from zoneinfo import ZoneInfo from rest_framework import status from rest_framework.test import APIClient, APITestCase from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.roles import CourseStaffRole, CourseInstructorRole +from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.discussion.django_comment_client.tests.factories import RoleFactory from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangoapps.django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, - FORUM_ROLE_MODERATOR + FORUM_ROLE_MODERATOR, ) from openedx.core.djangoapps.notifications.email.utils import encrypt_string -from openedx.core.djangoapps.notifications.models import ( - Notification, - NotificationPreference -) +from openedx.core.djangoapps.notifications.models import Notification, NotificationPreference from openedx.core.djangoapps.notifications.serializers import add_non_editable_in_preference - from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from ..base_notification import COURSE_NOTIFICATION_APPS, COURSE_NOTIFICATION_TYPES, \ - get_default_values_of_preferences -from ..utils import get_notification_types_with_visibility_settings, exclude_inaccessible_preferences +from ..base_notification import COURSE_NOTIFICATION_APPS, COURSE_NOTIFICATION_TYPES, get_default_values_of_preferences +from ..utils import exclude_inaccessible_preferences, get_notification_types_with_visibility_settings User = get_user_model() diff --git a/openedx/core/djangoapps/notifications/urls.py b/openedx/core/djangoapps/notifications/urls.py index 2ac80440f109..760e46db6e79 100644 --- a/openedx/core/djangoapps/notifications/urls.py +++ b/openedx/core/djangoapps/notifications/urls.py @@ -8,9 +8,9 @@ MarkNotificationsSeenAPIView, NotificationCountView, NotificationListAPIView, + NotificationPreferencesViewV3, NotificationReadAPIView, preference_update_from_encrypted_username_view, - NotificationPreferencesViewV3, ) router = routers.DefaultRouter() diff --git a/openedx/core/djangoapps/notifications/utils.py b/openedx/core/djangoapps/notifications/utils.py index 2eae9f4c774a..8a8f9b6bed47 100644 --- a/openedx/core/djangoapps/notifications/utils.py +++ b/openedx/core/djangoapps/notifications/utils.py @@ -6,7 +6,7 @@ from common.djangoapps.student.models import CourseAccessRole from openedx.core.djangoapps.django_comment_common.models import Role from openedx.core.djangoapps.notifications.config.waffle import DISABLE_NOTIFICATIONS -from openedx.core.djangoapps.notifications.models import create_notification_preference, NotificationPreference +from openedx.core.djangoapps.notifications.models import NotificationPreference, create_notification_preference from openedx.core.lib.cache_utils import request_cached diff --git a/openedx/core/djangoapps/notifications/views.py b/openedx/core/djangoapps/notifications/views.py index bb419e46ecc8..4901b42c9931 100644 --- a/openedx/core/djangoapps/notifications/views.py +++ b/openedx/core/djangoapps/notifications/views.py @@ -2,13 +2,13 @@ Views for the notifications API. """ from datetime import datetime, timedelta +from zoneinfo import ZoneInfo from django.conf import settings from django.db.models import Count -from django_ratelimit.core import is_ratelimited from django.shortcuts import get_object_or_404 from django.utils.translation import gettext as _ -from zoneinfo import ZoneInfo +from django_ratelimit.core import is_ratelimited from rest_framework import generics, status from rest_framework.decorators import api_view from rest_framework.generics import UpdateAPIView @@ -24,17 +24,18 @@ notification_preference_update_event, notification_read_event, notification_tray_opened_event, - notifications_app_all_read_event + notifications_app_all_read_event, ) from .models import Notification from .serializers import ( NotificationSerializer, UserNotificationPreferenceUpdateAllSerializer, - add_non_editable_in_preference + add_non_editable_in_preference, ) from .utils import ( + create_account_notification_pref_if_not_exists, + exclude_inaccessible_preferences, get_show_notifications_tray, - exclude_inaccessible_preferences, create_account_notification_pref_if_not_exists ) diff --git a/openedx/core/djangoapps/oauth_dispatch/dot_overrides/validators.py b/openedx/core/djangoapps/oauth_dispatch/dot_overrides/validators.py index 773c344db0af..75921f2f158b 100644 --- a/openedx/core/djangoapps/oauth_dispatch/dot_overrides/validators.py +++ b/openedx/core/djangoapps/oauth_dispatch/dot_overrides/validators.py @@ -4,6 +4,7 @@ from datetime import datetime, timedelta +from zoneinfo import ZoneInfo from django.contrib.auth import authenticate, get_user_model from django.db.models.signals import pre_save @@ -11,9 +12,9 @@ from oauth2_provider.models import AccessToken from oauth2_provider.oauth2_validators import OAuth2Validator from oauth2_provider.scopes import get_scopes_backend -from zoneinfo import ZoneInfo from ..models import RestrictedApplication + # pylint: disable=W0223 diff --git a/openedx/core/djangoapps/oauth_dispatch/management/commands/tests/test_clear_expired_tokens.py b/openedx/core/djangoapps/oauth_dispatch/management/commands/tests/test_clear_expired_tokens.py index 5e428947b5de..657b238aec22 100644 --- a/openedx/core/djangoapps/oauth_dispatch/management/commands/tests/test_clear_expired_tokens.py +++ b/openedx/core/djangoapps/oauth_dispatch/management/commands/tests/test_clear_expired_tokens.py @@ -2,12 +2,12 @@ Tests the ``edx_clear_expired_tokens`` management command. """ +import math from datetime import timedelta from unittest.mock import patch -import math -import pytest import ddt +import pytest from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.core.management import call_command @@ -15,12 +15,12 @@ from django.test import TestCase from django.test.utils import override_settings from django.utils import timezone -from oauth2_provider.models import AccessToken, RefreshToken, Grant +from oauth2_provider.models import AccessToken, Grant, RefreshToken from testfixtures import LogCapture +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.oauth_dispatch.tests import factories from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.tests.factories import UserFactory LOGGER_NAME = 'openedx.core.djangoapps.oauth_dispatch.management.commands.edx_clear_expired_tokens' diff --git a/openedx/core/djangoapps/oauth_dispatch/management/commands/tests/test_create_dot_application.py b/openedx/core/djangoapps/oauth_dispatch/management/commands/tests/test_create_dot_application.py index f30e8bb61498..779d3ead8b12 100644 --- a/openedx/core/djangoapps/oauth_dispatch/management/commands/tests/test_create_dot_application.py +++ b/openedx/core/djangoapps/oauth_dispatch/management/commands/tests/test_create_dot_application.py @@ -1,14 +1,14 @@ """ Tests the ``create_dot_application`` management command. """ -import pytest import ddt +import pytest from django.core.management import call_command from django.test import TestCase from oauth2_provider.models import get_application_model -from openedx.core.djangoapps.oauth_dispatch.models import ApplicationAccess from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.oauth_dispatch.models import ApplicationAccess from ..create_dot_application import Command diff --git a/openedx/core/djangoapps/oauth_dispatch/migrations/0010_noop_migration_to_test_rollback.py b/openedx/core/djangoapps/oauth_dispatch/migrations/0010_noop_migration_to_test_rollback.py index d809c47c82db..da5a7a4f2f67 100644 --- a/openedx/core/djangoapps/oauth_dispatch/migrations/0010_noop_migration_to_test_rollback.py +++ b/openedx/core/djangoapps/oauth_dispatch/migrations/0010_noop_migration_to_test_rollback.py @@ -4,6 +4,7 @@ from django.db import migrations + class Migration(migrations.Migration): dependencies = [ diff --git a/openedx/core/djangoapps/oauth_dispatch/migrations/0011_noop_migration_to_test_rollback.py b/openedx/core/djangoapps/oauth_dispatch/migrations/0011_noop_migration_to_test_rollback.py index 698708b79ff0..8321a7c5fa6e 100644 --- a/openedx/core/djangoapps/oauth_dispatch/migrations/0011_noop_migration_to_test_rollback.py +++ b/openedx/core/djangoapps/oauth_dispatch/migrations/0011_noop_migration_to_test_rollback.py @@ -4,6 +4,7 @@ from django.db import migrations + class Migration(migrations.Migration): dependencies = [ diff --git a/openedx/core/djangoapps/oauth_dispatch/migrations/0012_noop_migration_to_test_rollback.py b/openedx/core/djangoapps/oauth_dispatch/migrations/0012_noop_migration_to_test_rollback.py index 10d6c918214b..0baa8299e120 100644 --- a/openedx/core/djangoapps/oauth_dispatch/migrations/0012_noop_migration_to_test_rollback.py +++ b/openedx/core/djangoapps/oauth_dispatch/migrations/0012_noop_migration_to_test_rollback.py @@ -4,6 +4,7 @@ from django.db import migrations + class Migration(migrations.Migration): dependencies = [ diff --git a/openedx/core/djangoapps/oauth_dispatch/models.py b/openedx/core/djangoapps/oauth_dispatch/models.py index 3869698af4cb..344b3a2133ec 100644 --- a/openedx/core/djangoapps/oauth_dispatch/models.py +++ b/openedx/core/djangoapps/oauth_dispatch/models.py @@ -4,14 +4,13 @@ from datetime import datetime +from zoneinfo import ZoneInfo from django.db import models - from django.utils.translation import gettext_lazy as _ from django_mysql.models import ListCharField from oauth2_provider.settings import oauth2_settings from organizations.models import Organization -from zoneinfo import ZoneInfo from openedx.core.djangolib.markup import HTML from openedx.core.lib.request_utils import get_request_or_stub diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/factories.py b/openedx/core/djangoapps/oauth_dispatch/tests/factories.py index 7d7be8dd7fa6..09209eb280f8 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/factories.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/factories.py @@ -2,15 +2,15 @@ from datetime import datetime, timedelta +from zoneinfo import ZoneInfo import factory -from zoneinfo import ZoneInfo from factory.django import DjangoModelFactory from factory.fuzzy import FuzzyText from oauth2_provider.models import AccessToken, Application, RefreshToken -from openedx.core.djangoapps.oauth_dispatch.models import ApplicationAccess from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.oauth_dispatch.models import ApplicationAccess class ApplicationFactory(DjangoModelFactory): diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/mixins.py b/openedx/core/djangoapps/oauth_dispatch/tests/mixins.py index 407a9aac2b84..84580ed9d66e 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/mixins.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/mixins.py @@ -6,7 +6,7 @@ from django.conf import settings from edx_rest_framework_extensions.auth.jwt.decoder import ( get_verification_jwk_key_set, - verify_jwk_signature_using_keyset + verify_jwk_signature_using_keyset, ) from jwt.exceptions import ExpiredSignatureError diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_api.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_api.py index dd1e3e2cf2c7..501bfd70cea7 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_api.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_api.py @@ -7,7 +7,6 @@ from common.djangoapps.student.tests.factories import UserFactory from common.test.utils import assert_dict_contains_subset - from openedx.core.djangoapps.oauth_dispatch import api from openedx.core.djangoapps.oauth_dispatch.adapters import DOTAdapter from openedx.core.djangoapps.oauth_dispatch.tests.constants import DUMMY_REDIRECT_URL diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_dot_adapter.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_dot_adapter.py index 556c089072cc..0c9f662fb04e 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_dot_adapter.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_dot_adapter.py @@ -3,9 +3,9 @@ """ from datetime import timedelta -import pytest import ddt +import pytest from django.test import TestCase from django.urls import reverse from django.utils.timezone import now @@ -16,8 +16,8 @@ # oauth_dispatch is not in CMS' INSTALLED_APPS so these imports will error during test collection from ..adapters import DOTAdapter -from .constants import DUMMY_REDIRECT_URL, DUMMY_REDIRECT_URL2 from ..models import RestrictedApplication +from .constants import DUMMY_REDIRECT_URL, DUMMY_REDIRECT_URL2 @ddt.ddt diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_dot_overrides.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_dot_overrides.py index 52a79615c29d..d658574eb2c5 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_dot_overrides.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_dot_overrides.py @@ -12,15 +12,14 @@ from django.utils import timezone from common.djangoapps.student.tests.factories import UserFactory -from openedx.core.djangolib.testing.utils import skip_unless_lms from openedx.core.djangoapps.oauth_dispatch.tests.factories import ApplicationAccessFactory +from openedx.core.djangolib.testing.utils import skip_unless_lms # oauth_dispatch is not in CMS' INSTALLED_APPS so these imports will error during test collection if settings.ROOT_URLCONF == 'lms.urls': from oauth2_provider import models as dot_models - from .. import adapters - from .. import models + from .. import adapters, models from ..dot_overrides.validators import EdxOAuth2Validator from .constants import DUMMY_REDIRECT_URL diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_factories.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_factories.py index bb4918c8ff79..874ef5e1822a 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_factories.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_factories.py @@ -4,8 +4,8 @@ from django.test import TestCase from oauth2_provider.models import AccessToken, Application, RefreshToken -from openedx.core.djangoapps.oauth_dispatch.tests import factories from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.oauth_dispatch.tests import factories class TestClientFactory(TestCase): diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_jwt.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_jwt.py index 647da14f6edd..7e756cf0df40 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_jwt.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_jwt.py @@ -7,12 +7,12 @@ from django.test.utils import override_settings from django.utils.timezone import now +from common.djangoapps.student.tests.factories import UserFactory +from common.test.utils import assert_dict_contains_subset from openedx.core.djangoapps.oauth_dispatch import jwt as jwt_api from openedx.core.djangoapps.oauth_dispatch.adapters import DOTAdapter from openedx.core.djangoapps.oauth_dispatch.models import RestrictedApplication from openedx.core.djangoapps.oauth_dispatch.tests.mixins import AccessTokenMixin -from common.djangoapps.student.tests.factories import UserFactory -from common.test.utils import assert_dict_contains_subset @ddt.ddt diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_views.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_views.py index 776920781719..8387cf095f0d 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_views.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_views.py @@ -18,7 +18,10 @@ from common.djangoapps.third_party_auth.tests.utils import ThirdPartyOAuthTestMixin, ThirdPartyOAuthTestMixinGoogle from openedx.core.djangoapps.oauth_dispatch.toggles import DISABLE_JWT_FOR_MOBILE from openedx.core.djangolib.testing.utils import skip_unless_lms + +from .. import adapters, models, views from . import mixins +from .constants import DUMMY_REDIRECT_URL # NOTE (CCB): We use this feature flag in a roundabout way to determine if the oauth_dispatch app is installed # in the current service--LMS or Studio. Normally we would check if settings.ROOT_URLCONF == 'lms.urls'; however, @@ -29,10 +32,6 @@ # these imports conditional except mixins, which doesn't currently import forbidden models, and is needed at test # discovery time. -from .constants import DUMMY_REDIRECT_URL -from .. import adapters -from .. import models -from .. import views class AccessTokenLoginMixin: diff --git a/openedx/core/djangoapps/olx_rest_api/test_views.py b/openedx/core/djangoapps/olx_rest_api/test_views.py index bde877a457ae..603ccbb47364 100644 --- a/openedx/core/djangoapps/olx_rest_api/test_views.py +++ b/openedx/core/djangoapps/olx_rest_api/test_views.py @@ -3,9 +3,9 @@ """ from xml.etree import ElementTree -from openedx.core.djangolib.testing.utils import skip_unless_cms from common.djangoapps.student.roles import CourseStaffRole from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory +from openedx.core.djangolib.testing.utils import skip_unless_cms from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import ToyCourseFactory diff --git a/openedx/core/djangoapps/olx_rest_api/urls.py b/openedx/core/djangoapps/olx_rest_api/urls.py index d25f412bd716..300c70a6795b 100644 --- a/openedx/core/djangoapps/olx_rest_api/urls.py +++ b/openedx/core/djangoapps/olx_rest_api/urls.py @@ -1,7 +1,7 @@ """ Studio URL configuration for openedx-olx-rest-api. """ -from django.urls import path, include +from django.urls import include, path from . import views diff --git a/openedx/core/djangoapps/olx_rest_api/views.py b/openedx/core/djangoapps/olx_rest_api/views.py index 6e86208a4853..c3d3ba528f0c 100644 --- a/openedx/core/djangoapps/olx_rest_api/views.py +++ b/openedx/core/djangoapps/olx_rest_api/views.py @@ -11,9 +11,8 @@ from common.djangoapps.student.auth import has_studio_read_access from openedx.core.lib.api.view_utils import view_auth_classes -from xmodule.modulestore.django import modulestore - from openedx.core.lib.xblock_serializer.api import serialize_modulestore_block_for_openedx_content +from xmodule.modulestore.django import modulestore @api_view(['GET']) diff --git a/openedx/core/djangoapps/password_policy/apps.py b/openedx/core/djangoapps/password_policy/apps.py index ffc8145b0fed..4df895c9efaa 100644 --- a/openedx/core/djangoapps/password_policy/apps.py +++ b/openedx/core/djangoapps/password_policy/apps.py @@ -3,6 +3,7 @@ """ import logging + from dateutil.parser import parse as parse_date from django.apps import AppConfig from django.conf import settings diff --git a/openedx/core/djangoapps/password_policy/compliance.py b/openedx/core/djangoapps/password_policy/compliance.py index fa5d2d8cfb5c..2badc923e563 100644 --- a/openedx/core/djangoapps/password_policy/compliance.py +++ b/openedx/core/djangoapps/password_policy/compliance.py @@ -3,15 +3,15 @@ """ from datetime import datetime - from zoneinfo import ZoneInfo + from django.conf import settings from django.utils.translation import gettext as _ -from openedx.core.djangolib.markup import HTML -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from common.djangoapps.util.date_utils import DEFAULT_SHORT_DATE_FORMAT, strftime_localized from common.djangoapps.util.password_policy_validators import validate_password +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.djangolib.markup import HTML class NonCompliantPasswordException(Exception): diff --git a/openedx/core/djangoapps/password_policy/tests/test_compliance.py b/openedx/core/djangoapps/password_policy/tests/test_compliance.py index 69d57a00cdc6..f46122973bc1 100644 --- a/openedx/core/djangoapps/password_policy/tests/test_compliance.py +++ b/openedx/core/djangoapps/password_policy/tests/test_compliance.py @@ -4,22 +4,22 @@ from datetime import datetime, timedelta from unittest.mock import patch +from zoneinfo import ZoneInfo import pytest -from zoneinfo import ZoneInfo from dateutil.parser import parse as parse_date from django.test import TestCase, override_settings -from openedx.core.djangoapps.password_policy.compliance import (NonCompliantPasswordException, - NonCompliantPasswordWarning, - _check_user_compliance, - _get_compliance_deadline_for_user, - enforce_compliance_on_login, - should_enforce_compliance_on_login) -from common.djangoapps.student.tests.factories import (CourseAccessRoleFactory, - UserFactory) +from common.djangoapps.student.tests.factories import CourseAccessRoleFactory, UserFactory from common.djangoapps.util.password_policy_validators import ValidationError - +from openedx.core.djangoapps.password_policy.compliance import ( + NonCompliantPasswordException, + NonCompliantPasswordWarning, + _check_user_compliance, + _get_compliance_deadline_for_user, + enforce_compliance_on_login, + should_enforce_compliance_on_login, +) date1 = parse_date('2018-01-01 00:00:00+00:00') date2 = parse_date('2018-02-02 00:00:00+00:00') diff --git a/openedx/core/djangoapps/password_policy/tests/test_forms.py b/openedx/core/djangoapps/password_policy/tests/test_forms.py index 4a0e04d39560..8ca574e899c1 100644 --- a/openedx/core/djangoapps/password_policy/tests/test_forms.py +++ b/openedx/core/djangoapps/password_policy/tests/test_forms.py @@ -8,11 +8,12 @@ from django.test import TestCase from django.test.utils import override_settings +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.password_policy.compliance import ( - NonCompliantPasswordException, NonCompliantPasswordWarning + NonCompliantPasswordException, + NonCompliantPasswordWarning, ) from openedx.core.djangoapps.password_policy.forms import PasswordPolicyAwareAdminAuthForm -from common.djangoapps.student.tests.factories import UserFactory class PasswordPolicyAwareAdminAuthFormTests(TestCase): diff --git a/openedx/core/djangoapps/plugins/apps.py b/openedx/core/djangoapps/plugins/apps.py index 625a82966bd3..a10359e60373 100644 --- a/openedx/core/djangoapps/plugins/apps.py +++ b/openedx/core/djangoapps/plugins/apps.py @@ -7,10 +7,9 @@ from django.apps import AppConfig from django.conf import settings -from edx_django_utils.plugins import connect_plugin_receivers +from edx_django_utils.plugins import PluginSettings, connect_plugin_receivers from openedx.core.djangoapps.plugins.constants import ProjectType, SettingsType -from edx_django_utils.plugins import PluginSettings class PluginsConfig(AppConfig): diff --git a/openedx/core/djangoapps/plugins/constants.py b/openedx/core/djangoapps/plugins/constants.py index a4dceee83fe5..0464ece54d32 100644 --- a/openedx/core/djangoapps/plugins/constants.py +++ b/openedx/core/djangoapps/plugins/constants.py @@ -4,10 +4,10 @@ # expose constants from edx-django-utils so plugins using these continue to work from edx_django_utils.plugins import ( # lint-amnesty, pylint: disable=unused-import - PluginSettings, # pylint: disable=unused-import - PluginURLs, # pylint: disable=unused-import - PluginSignals, # pylint: disable=unused-import - PluginContexts, # pylint: disable=unused-import + PluginContexts, + PluginSettings, + PluginSignals, + PluginURLs, ) diff --git a/openedx/core/djangoapps/plugins/i18n_api.py b/openedx/core/djangoapps/plugins/i18n_api.py index ae8bb5628628..eb70fccd0caf 100644 --- a/openedx/core/djangoapps/plugins/i18n_api.py +++ b/openedx/core/djangoapps/plugins/i18n_api.py @@ -2,11 +2,11 @@ edx-platform specific i18n helpers for edx-django-utils plugins. """ -from dataclasses import dataclass, asdict -from collections import defaultdict import os -from pathlib import Path import subprocess +from collections import defaultdict +from dataclasses import asdict, dataclass +from pathlib import Path from django.core.management import BaseCommand, CommandError from importlib_metadata import entry_points diff --git a/openedx/core/djangoapps/plugins/management/commands/compile_plugin_translations.py b/openedx/core/djangoapps/plugins/management/commands/compile_plugin_translations.py index 56322f104b1c..4ee9d13127eb 100644 --- a/openedx/core/djangoapps/plugins/management/commands/compile_plugin_translations.py +++ b/openedx/core/djangoapps/plugins/management/commands/compile_plugin_translations.py @@ -2,13 +2,11 @@ Compile the translation files for the edx_django_utils.plugins. """ -from django.core.management.base import BaseCommand from django.conf import settings - - -from ...constants import plugins_locale_root +from django.core.management.base import BaseCommand from ... import i18n_api +from ...constants import plugins_locale_root class Command(BaseCommand): diff --git a/openedx/core/djangoapps/plugins/management/commands/pull_plugin_translations.py b/openedx/core/djangoapps/plugins/management/commands/pull_plugin_translations.py index 7ca4f443d079..26753aab26f6 100644 --- a/openedx/core/djangoapps/plugins/management/commands/pull_plugin_translations.py +++ b/openedx/core/djangoapps/plugins/management/commands/pull_plugin_translations.py @@ -9,10 +9,7 @@ from openedx.core.djangoapps.plugins.i18n_api import BaseAtlasPullCommand from ...constants import plugins_locale_root - -from ...i18n_api import ( - plugin_translations_atlas_pull, -) +from ...i18n_api import plugin_translations_atlas_pull class Command(BaseAtlasPullCommand): diff --git a/openedx/core/djangoapps/profile_images/tests/helpers.py b/openedx/core/djangoapps/profile_images/tests/helpers.py index cbb6e76ac957..779ee3e79f30 100644 --- a/openedx/core/djangoapps/profile_images/tests/helpers.py +++ b/openedx/core/djangoapps/profile_images/tests/helpers.py @@ -2,12 +2,12 @@ Helper methods for use in profile image tests. """ -from contextlib import contextmanager import os +from contextlib import contextmanager from tempfile import NamedTemporaryFile -from django.core.files.uploadedfile import UploadedFile import piexif +from django.core.files.uploadedfile import UploadedFile from PIL import Image diff --git a/openedx/core/djangoapps/profile_images/tests/test_images.py b/openedx/core/djangoapps/profile_images/tests/test_images.py index d46a89175a83..c0ada2c82b63 100644 --- a/openedx/core/djangoapps/profile_images/tests/test_images.py +++ b/openedx/core/djangoapps/profile_images/tests/test_images.py @@ -1,30 +1,30 @@ """ Test cases for image processing functions in the profile image package. """ +import os # lint-amnesty, pylint: disable=wrong-import-order from contextlib import closing -from unittest import mock - -import pytest from itertools import product # lint-amnesty, pylint: disable=wrong-import-order -import os # lint-amnesty, pylint: disable=wrong-import-order from tempfile import NamedTemporaryFile # lint-amnesty, pylint: disable=wrong-import-order +from unittest import mock +import ddt +import piexif +import pytest from django.core.files.uploadedfile import UploadedFile from django.test import TestCase from django.test.utils import override_settings -import ddt -import piexif from PIL import Image from openedx.core.djangolib.testing.utils import skip_unless_lms + from ..exceptions import ImageValidationError from ..images import ( + _get_exif_orientation, + _get_valid_file_types, + _update_exif_orientation, create_profile_images, remove_profile_images, validate_uploaded_image, - _get_exif_orientation, - _get_valid_file_types, - _update_exif_orientation ) from .helpers import make_image_file, make_uploaded_file diff --git a/openedx/core/djangoapps/profile_images/tests/test_views.py b/openedx/core/djangoapps/profile_images/tests/test_views.py index 963c0956c28a..50835da450be 100644 --- a/openedx/core/djangoapps/profile_images/tests/test_views.py +++ b/openedx/core/djangoapps/profile_images/tests/test_views.py @@ -1,31 +1,29 @@ """ Test cases for the HTTP endpoints of the profile image api. """ +import datetime # lint-amnesty, pylint: disable=wrong-import-order from contextlib import closing from unittest import mock from unittest.mock import patch - -import pytest -import datetime # lint-amnesty, pylint: disable=wrong-import-order from zoneinfo import ZoneInfo -from django.urls import reverse -from django.http import HttpResponse - import ddt +import pytest +from django.http import HttpResponse +from django.urls import reverse from PIL import Image -from rest_framework.test import APITestCase, APIClient +from rest_framework.test import APIClient, APITestCase from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.student.tests.tests import UserSettingsEventTestMixin from openedx.core.djangoapps.user_api.accounts.image_helpers import ( - set_has_profile_image, get_profile_image_names, get_profile_image_storage, + set_has_profile_image, ) from openedx.core.djangolib.testing.utils import skip_unless_lms -from ..images import create_profile_images, ImageValidationError +from ..images import ImageValidationError, create_profile_images from ..views import LOG_MESSAGE_CREATE, LOG_MESSAGE_DELETE from .helpers import make_image_file diff --git a/openedx/core/djangoapps/profile_images/views.py b/openedx/core/djangoapps/profile_images/views.py index 1c9d4fcf3bf7..72fef1da9fc7 100644 --- a/openedx/core/djangoapps/profile_images/views.py +++ b/openedx/core/djangoapps/profile_images/views.py @@ -7,11 +7,11 @@ import itertools import logging from contextlib import closing +from zoneinfo import ZoneInfo from django.utils.translation import gettext as _ from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser -from zoneinfo import ZoneInfo from rest_framework import permissions, status from rest_framework.parsers import FormParser, MultiPartParser from rest_framework.response import Response diff --git a/openedx/core/djangoapps/programs/admin.py b/openedx/core/djangoapps/programs/admin.py index 6f0949b424a0..ef003ae2c540 100644 --- a/openedx/core/djangoapps/programs/admin.py +++ b/openedx/core/djangoapps/programs/admin.py @@ -8,8 +8,11 @@ from simple_history.admin import SimpleHistoryAdmin from openedx.core.djangoapps.programs.forms import ProgramDiscussionsConfigurationForm, ProgramLiveConfigurationForm -from openedx.core.djangoapps.programs.models import ProgramsApiConfig, ProgramDiscussionsConfiguration, \ - ProgramLiveConfiguration +from openedx.core.djangoapps.programs.models import ( + ProgramDiscussionsConfiguration, + ProgramLiveConfiguration, + ProgramsApiConfig, +) class ProgramsApiConfigAdmin(ConfigurationModelAdmin): diff --git a/openedx/core/djangoapps/programs/migrations/0013_customprogramsconfig.py b/openedx/core/djangoapps/programs/migrations/0013_customprogramsconfig.py index e162f5339316..cd66bcbe2f4d 100644 --- a/openedx/core/djangoapps/programs/migrations/0013_customprogramsconfig.py +++ b/openedx/core/djangoapps/programs/migrations/0013_customprogramsconfig.py @@ -1,9 +1,9 @@ # Generated by Django 1.11.26 on 2019-12-13 07:44 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/programs/migrations/0015_historicalprogramdiscussionsconfiguration_historicalprogramliveconfiguration_programdiscussionsconfi.py b/openedx/core/djangoapps/programs/migrations/0015_historicalprogramdiscussionsconfiguration_historicalprogramliveconfiguration_programdiscussionsconfi.py index 59ad6186f9fb..37f7b0a1b2f4 100644 --- a/openedx/core/djangoapps/programs/migrations/0015_historicalprogramdiscussionsconfiguration_historicalprogramliveconfiguration_programdiscussionsconfi.py +++ b/openedx/core/djangoapps/programs/migrations/0015_historicalprogramdiscussionsconfiguration_historicalprogramliveconfiguration_programdiscussionsconfi.py @@ -1,11 +1,11 @@ # Generated by Django 3.2.11 on 2022-02-03 21:34 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields import simple_history.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/programs/models.py b/openedx/core/djangoapps/programs/models.py index e708066813b8..7a997ced2cfb 100644 --- a/openedx/core/djangoapps/programs/models.py +++ b/openedx/core/djangoapps/programs/models.py @@ -2,9 +2,9 @@ from config_models.models import ConfigurationModel from django.db import models from django.utils.translation import gettext_lazy as _ -from simple_history.models import HistoricalRecords from lti_consumer.models import LtiConfiguration from model_utils.models import TimeStampedModel +from simple_history.models import HistoricalRecords class ProgramsApiConfig(ConfigurationModel): diff --git a/openedx/core/djangoapps/programs/rest_api/urls.py b/openedx/core/djangoapps/programs/rest_api/urls.py index 6533f709b85d..11b7ef431be1 100644 --- a/openedx/core/djangoapps/programs/rest_api/urls.py +++ b/openedx/core/djangoapps/programs/rest_api/urls.py @@ -10,9 +10,7 @@ from django.urls import include, path -from openedx.core.djangoapps.programs.rest_api.v1 import ( - urls as v1_programs_rest_api_urls, -) +from openedx.core.djangoapps.programs.rest_api.v1 import urls as v1_programs_rest_api_urls app_name = "openedx.core.djangoapps.programs" diff --git a/openedx/core/djangoapps/programs/rest_api/v1/tests/test_views.py b/openedx/core/djangoapps/programs/rest_api/v1/tests/test_views.py index 11428591db74..0f670cd2f80d 100644 --- a/openedx/core/djangoapps/programs/rest_api/v1/tests/test_views.py +++ b/openedx/core/djangoapps/programs/rest_api/v1/tests/test_views.py @@ -11,13 +11,8 @@ from enterprise.models import EnterpriseCourseEnrollment from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.tests.factories import ( - CourseEnrollmentFactory, - UserFactory, -) -from lms.djangoapps.program_enrollments.rest_api.v1.tests.test_views import ( - ProgramCacheMixin, -) +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory +from lms.djangoapps.program_enrollments.rest_api.v1.tests.test_views import ProgramCacheMixin from lms.djangoapps.program_enrollments.tests.factories import ProgramEnrollmentFactory from openedx.core.djangoapps.catalog.cache import SITE_PROGRAM_UUIDS_CACHE_KEY_TPL from openedx.core.djangoapps.catalog.constants import PathwayType @@ -29,9 +24,7 @@ ) from openedx.core.djangoapps.programs.tests.mixins import ProgramsApiConfigMixin from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory -from openedx.core.djangoapps.site_configuration.tests.test_util import ( - with_site_configuration, -) +from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration from openedx.core.djangolib.testing.utils import skip_unless_lms from openedx.features.enterprise_support.api import enterprise_is_enabled from openedx.features.enterprise_support.tests.factories import ( @@ -40,9 +33,7 @@ EnterpriseCustomerUserFactory, ) from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import ( - CourseFactory as ModuleStoreCourseFactory, -) +from xmodule.modulestore.tests.factories import CourseFactory as ModuleStoreCourseFactory PROGRAMS_UTILS_MODULE = "openedx.core.djangoapps.programs.utils" diff --git a/openedx/core/djangoapps/programs/rest_api/v1/urls.py b/openedx/core/djangoapps/programs/rest_api/v1/urls.py index f6ee9628cfb4..88c299a9acce 100644 --- a/openedx/core/djangoapps/programs/rest_api/v1/urls.py +++ b/openedx/core/djangoapps/programs/rest_api/v1/urls.py @@ -4,10 +4,7 @@ from django.urls import re_path -from openedx.core.djangoapps.programs.rest_api.v1.views import ( - ProgramProgressDetailView, - Programs, -) +from openedx.core.djangoapps.programs.rest_api.v1.views import ProgramProgressDetailView, Programs ENTERPRISE_UUID_PATTERN = r"[0-9a-fA-F]{8}-?[0-9a-fA-F]{4}-?4[0-9a-fA-F]{3}-?[89abAB][0-9a-fA-F]{3}-?[0-9a-fA-F]{12}" PROGRAM_UUID_PATTERN = r"[0-9a-f-]+" diff --git a/openedx/core/djangoapps/programs/rest_api/v1/views.py b/openedx/core/djangoapps/programs/rest_api/v1/views.py index 77c5a171fd7f..41024837ff69 100644 --- a/openedx/core/djangoapps/programs/rest_api/v1/views.py +++ b/openedx/core/djangoapps/programs/rest_api/v1/views.py @@ -1,7 +1,7 @@ """Views for the Programs REST API v1.""" -from typing import Any, TYPE_CHECKING import logging +from typing import TYPE_CHECKING, Any from django.db.models.query import EmptyQuerySet from rest_framework.permissions import IsAuthenticated @@ -16,13 +16,14 @@ get_program_and_course_data, get_program_urls, ) -from openedx.features.enterprise_support.api import get_enterprise_course_enrollments, enterprise_is_enabled +from openedx.features.enterprise_support.api import enterprise_is_enabled, get_enterprise_course_enrollments if TYPE_CHECKING: - from django.http import HttpRequest, HttpResponse from django.contrib.auth.models import AnonymousUser, User # pylint: disable=imported-auth-user from django.contrib.sites.models import Site from django.db.models.query import QuerySet + from django.http import HttpRequest, HttpResponse + from common.djangoapps.student.models import CourseEnrollment logger = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/programs/tasks.py b/openedx/core/djangoapps/programs/tasks.py index 2829cf20752e..2cb7e48c7cd0 100644 --- a/openedx/core/djangoapps/programs/tasks.py +++ b/openedx/core/djangoapps/programs/tasks.py @@ -19,8 +19,8 @@ from requests.exceptions import HTTPError from common.djangoapps.course_modes.models import CourseMode -from lms.djangoapps.certificates.data import GeneratedCertificateData from lms.djangoapps.certificates.api import get_eligible_certificate +from lms.djangoapps.certificates.data import GeneratedCertificateData from openedx.core.djangoapps.content.course_overviews.api import get_course_overview_or_none from openedx.core.djangoapps.credentials.api import is_credentials_enabled from openedx.core.djangoapps.credentials.utils import ( diff --git a/openedx/core/djangoapps/programs/tests/test_tasks.py b/openedx/core/djangoapps/programs/tests/test_tasks.py index 943c8c0dd444..64f67de84334 100644 --- a/openedx/core/djangoapps/programs/tests/test_tasks.py +++ b/openedx/core/djangoapps/programs/tests/test_tasks.py @@ -6,11 +6,11 @@ import logging from datetime import datetime, timedelta from unittest import mock +from zoneinfo import ZoneInfo import ddt import httpretty import pytest -from zoneinfo import ZoneInfo import requests from celery.exceptions import MaxRetriesExceededError from django.conf import settings diff --git a/openedx/core/djangoapps/programs/tests/test_utils.py b/openedx/core/djangoapps/programs/tests/test_utils.py index 18058c827a52..de09dc2e5175 100644 --- a/openedx/core/djangoapps/programs/tests/test_utils.py +++ b/openedx/core/djangoapps/programs/tests/test_utils.py @@ -6,6 +6,7 @@ from collections import namedtuple from copy import deepcopy from unittest import mock +from zoneinfo import ZoneInfo import ddt import httpretty @@ -15,7 +16,6 @@ from django.urls import reverse from edx_toggles.toggles.testutils import override_waffle_switch from opaque_keys.edx.keys import CourseKey # lint-amnesty, pylint: disable=wrong-import-order -from zoneinfo import ZoneInfo from testfixtures import LogCapture from common.djangoapps.course_modes.models import CourseMode @@ -33,7 +33,7 @@ EntitlementFactory, ProgramFactory, SeatFactory, - generate_course_run_key + generate_course_run_key, ) from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.programs import ALWAYS_CALCULATE_PROGRAM_PRICE_AS_ANONYMOUS_USER @@ -45,7 +45,7 @@ ProgramProgressMeter, get_certificates, get_logged_in_program_certificate_url, - is_user_enrolled_in_program_type + is_user_enrolled_in_program_type, ) from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory from openedx.core.djangolib.testing.utils import skip_unless_lms diff --git a/openedx/core/djangoapps/programs/utils.py b/openedx/core/djangoapps/programs/utils.py index b385d8284c36..c3993f93071e 100644 --- a/openedx/core/djangoapps/programs/utils.py +++ b/openedx/core/djangoapps/programs/utils.py @@ -6,6 +6,7 @@ from copy import deepcopy from itertools import chain from urllib.parse import urljoin, urlparse, urlunparse +from zoneinfo import ZoneInfo from dateutil.parser import parse from django.conf import settings @@ -14,7 +15,6 @@ from django.urls import reverse from django.utils.functional import cached_property from opaque_keys.edx.keys import CourseKey -from zoneinfo import ZoneInfo from requests.exceptions import RequestException from common.djangoapps.course_modes.api import get_paid_modes_for_course diff --git a/openedx/core/djangoapps/safe_sessions/testing.py b/openedx/core/djangoapps/safe_sessions/testing.py index 1c56c9f07f3c..98a0bf0f6b0a 100644 --- a/openedx/core/djangoapps/safe_sessions/testing.py +++ b/openedx/core/djangoapps/safe_sessions/testing.py @@ -37,6 +37,7 @@ def login_with_safe_session(self, **credentials): """ from django.conf import settings from django.contrib.auth import SESSION_KEY + from .middleware import SafeSessionMiddleware if not patched_client_login(self, **credentials): @@ -58,9 +59,11 @@ def get_safe_session(self): access the session_id before it's actually converted, we use a try-except clause here to check both cases. """ + from importlib import import_module + from django.apps import apps from django.conf import settings - from importlib import import_module + from .middleware import SafeCookieData, SafeCookieError, SafeSessionMiddleware if apps.is_installed('django.contrib.sessions'): diff --git a/openedx/core/djangoapps/safe_sessions/tests/test_middleware.py b/openedx/core/djangoapps/safe_sessions/tests/test_middleware.py index ad5629fab167..ff47f7b0e5c4 100644 --- a/openedx/core/djangoapps/safe_sessions/tests/test_middleware.py +++ b/openedx/core/djangoapps/safe_sessions/tests/test_middleware.py @@ -2,7 +2,7 @@ Unit tests for SafeSessionMiddleware """ import uuid -from unittest.mock import call, patch, MagicMock +from unittest.mock import MagicMock, call, patch import ddt from crum import set_current_request @@ -17,10 +17,10 @@ from edx_rest_framework_extensions.auth.jwt import cookies as jwt_cookies from common.djangoapps.student.models import PendingEmailChange -from openedx.core.djangolib.testing.utils import get_mock_request, CacheIsolationTestCase, skip_unless_lms -from openedx.core.djangoapps.user_authn.tests.utils import setup_login_oauth_client -from openedx.core.djangoapps.user_authn.cookies import ALL_LOGGED_IN_COOKIE_NAMES from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.user_authn.cookies import ALL_LOGGED_IN_COOKIE_NAMES +from openedx.core.djangoapps.user_authn.tests.utils import setup_login_oauth_client +from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, get_mock_request, skip_unless_lms from ..middleware import ( EmailChangeMiddleware, @@ -28,7 +28,7 @@ SafeSessionMiddleware, mark_user_change_as_expected, obscure_token, - track_request_user_changes + track_request_user_changes, ) from .test_utils import TestSafeSessionsLogMixin diff --git a/openedx/core/djangoapps/safe_sessions/tests/test_safe_cookie_data.py b/openedx/core/djangoapps/safe_sessions/tests/test_safe_cookie_data.py index 650a8d157baf..3ec863095fda 100644 --- a/openedx/core/djangoapps/safe_sessions/tests/test_safe_cookie_data.py +++ b/openedx/core/djangoapps/safe_sessions/tests/test_safe_cookie_data.py @@ -8,9 +8,9 @@ from time import time from unittest.mock import patch -import pytest import ddt import django +import pytest from django.test import TestCase from ..middleware import SafeCookieData, SafeCookieError diff --git a/openedx/core/djangoapps/safe_sessions/tests/test_utils.py b/openedx/core/djangoapps/safe_sessions/tests/test_utils.py index 9fc32555cb83..54bf9ceb302c 100644 --- a/openedx/core/djangoapps/safe_sessions/tests/test_utils.py +++ b/openedx/core/djangoapps/safe_sessions/tests/test_utils.py @@ -1,10 +1,11 @@ """ Shared test utilities for Safe Sessions tests """ -import pytest from contextlib import contextmanager # lint-amnesty, pylint: disable=wrong-import-order from unittest.mock import patch # lint-amnesty, pylint: disable=wrong-import-order +import pytest + class TestSafeSessionsLogMixin: """ diff --git a/openedx/core/djangoapps/schedules/content_highlights.py b/openedx/core/djangoapps/schedules/content_highlights.py index d0104bd23e04..d6c330fdcef3 100644 --- a/openedx/core/djangoapps/schedules/content_highlights.py +++ b/openedx/core/djangoapps/schedules/content_highlights.py @@ -131,8 +131,8 @@ def _get_course_block(course_descriptor, user): # Adding courseware imports here to insulate other apps (e.g. schedules) to # avoid import errors. # TODO remove the LMS dependency https://github.com/openedx/edx-platform/issues/37659 - from lms.djangoapps.courseware.model_data import FieldDataCache from lms.djangoapps.courseware.block_render import get_block_for_descriptor + from lms.djangoapps.courseware.model_data import FieldDataCache # Fake a request to fool parts of the courseware that want to inspect it. request = get_request_or_stub() diff --git a/openedx/core/djangoapps/schedules/management/commands/__init__.py b/openedx/core/djangoapps/schedules/management/commands/__init__.py index 16484ef367ea..a8ccf39b38b6 100644 --- a/openedx/core/djangoapps/schedules/management/commands/__init__.py +++ b/openedx/core/djangoapps/schedules/management/commands/__init__.py @@ -4,8 +4,8 @@ import datetime - from zoneinfo import ZoneInfo + from django.contrib.sites.models import Site from django.core.management.base import BaseCommand diff --git a/openedx/core/djangoapps/schedules/management/commands/schedules_data_migration.py b/openedx/core/djangoapps/schedules/management/commands/schedules_data_migration.py index 84dd5cd10023..79f6bc1e278f 100644 --- a/openedx/core/djangoapps/schedules/management/commands/schedules_data_migration.py +++ b/openedx/core/djangoapps/schedules/management/commands/schedules_data_migration.py @@ -5,6 +5,7 @@ from django.core.management.base import BaseCommand from django.db import transaction + from openedx.core.djangoapps.schedules.models import Schedule diff --git a/openedx/core/djangoapps/schedules/management/commands/send_course_next_section_update.py b/openedx/core/djangoapps/schedules/management/commands/send_course_next_section_update.py index 6faa92308840..61d0f84ac7e7 100644 --- a/openedx/core/djangoapps/schedules/management/commands/send_course_next_section_update.py +++ b/openedx/core/djangoapps/schedules/management/commands/send_course_next_section_update.py @@ -3,8 +3,8 @@ """ import datetime -from zoneinfo import ZoneInfo from textwrap import dedent # lint-amnesty, pylint: disable=wrong-import-order +from zoneinfo import ZoneInfo from django.contrib.sites.models import Site diff --git a/openedx/core/djangoapps/schedules/management/commands/send_course_update.py b/openedx/core/djangoapps/schedules/management/commands/send_course_update.py index e15f53178755..25ed0efbf8e3 100644 --- a/openedx/core/djangoapps/schedules/management/commands/send_course_update.py +++ b/openedx/core/djangoapps/schedules/management/commands/send_course_update.py @@ -5,7 +5,6 @@ from textwrap import dedent - from openedx.core.djangoapps.schedules.management.commands import SendEmailBaseCommand from openedx.core.djangoapps.schedules.tasks import ScheduleCourseUpdate diff --git a/openedx/core/djangoapps/schedules/management/commands/setup_models_to_send_test_emails.py b/openedx/core/djangoapps/schedules/management/commands/setup_models_to_send_test_emails.py index 587271fc599c..5f6880b8bf1a 100644 --- a/openedx/core/djangoapps/schedules/management/commands/setup_models_to_send_test_emails.py +++ b/openedx/core/djangoapps/schedules/management/commands/setup_models_to_send_test_emails.py @@ -5,9 +5,9 @@ import datetime from textwrap import dedent +from zoneinfo import ZoneInfo import factory -from zoneinfo import ZoneInfo from django.contrib.sites.models import Site from django.core.management.base import BaseCommand @@ -16,10 +16,13 @@ from openedx.core.djangoapps.schedules.tests.factories import ( ScheduleConfigFactory, ScheduleExperienceFactory, - ScheduleFactory + ScheduleFactory, ) from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import XMODULE_FACTORY_LOCK, CourseFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + XMODULE_FACTORY_LOCK, + CourseFactory, +) class ThreeDayNudgeSchedule(ScheduleFactory): diff --git a/openedx/core/djangoapps/schedules/management/commands/tests/send_email_base.py b/openedx/core/djangoapps/schedules/management/commands/tests/send_email_base.py index c0a63954644d..20966c524207 100644 --- a/openedx/core/djangoapps/schedules/management/commands/tests/send_email_base.py +++ b/openedx/core/djangoapps/schedules/management/commands/tests/send_email_base.py @@ -8,10 +8,10 @@ from collections import namedtuple from copy import deepcopy from unittest.mock import Mock, patch +from zoneinfo import ZoneInfo import attr import ddt -from zoneinfo import ZoneInfo from django.conf import settings from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.db.models import Max @@ -23,8 +23,10 @@ from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory -from lms.djangoapps.courseware.models import DynamicUpgradeDeadlineConfiguration +from common.djangoapps.student.models import CourseEnrollment +from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.commerce.models import CommerceConfiguration +from lms.djangoapps.courseware.models import DynamicUpgradeDeadlineConfiguration from openedx.core.djangoapps.schedules import resolvers, tasks from openedx.core.djangoapps.schedules.resolvers import _get_datetime_beginning_of_day from openedx.core.djangoapps.schedules.tests.factories import ScheduleConfigFactory, ScheduleFactory @@ -32,8 +34,6 @@ from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES from openedx.core.djangolib.testing.utils import FilteredQueryCountMixin -from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.tests.factories import UserFactory SITE_QUERY = 1 # django_site SITE_CONFIG_QUERY = 1 # site_configuration_siteconfiguration diff --git a/openedx/core/djangoapps/schedules/management/commands/tests/test_send_course_update.py b/openedx/core/djangoapps/schedules/management/commands/tests/test_send_course_update.py index 72e68b042012..4df4df3a72a0 100644 --- a/openedx/core/djangoapps/schedules/management/commands/tests/test_send_course_update.py +++ b/openedx/core/djangoapps/schedules/management/commands/tests/test_send_course_update.py @@ -11,18 +11,23 @@ from django.core import mail from edx_ace.utils.date import serialize +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory from openedx.core.djangoapps.schedules import resolvers, tasks from openedx.core.djangoapps.schedules.management.commands import send_course_update as nudge from openedx.core.djangoapps.schedules.management.commands.tests.send_email_base import ( ExperienceTest, - ScheduleSendEmailTestMixin + ScheduleSendEmailTestMixin, ) from openedx.core.djangoapps.schedules.management.commands.tests.upsell_base import ScheduleUpsellTestMixin from openedx.core.djangoapps.schedules.models import ScheduleExperience from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) @ddt.ddt diff --git a/openedx/core/djangoapps/schedules/management/commands/tests/test_send_email_base_command.py b/openedx/core/djangoapps/schedules/management/commands/tests/test_send_email_base_command.py index eb1f7fe40f71..a048d642b3e3 100644 --- a/openedx/core/djangoapps/schedules/management/commands/tests/test_send_email_base_command.py +++ b/openedx/core/djangoapps/schedules/management/commands/tests/test_send_email_base_command.py @@ -6,9 +6,9 @@ import datetime from unittest import skipUnless from unittest.mock import DEFAULT, Mock, patch +from zoneinfo import ZoneInfo import ddt -from zoneinfo import ZoneInfo from django.conf import settings from django.contrib.sites.models import Site diff --git a/openedx/core/djangoapps/schedules/management/commands/tests/test_send_recurring_nudge.py b/openedx/core/djangoapps/schedules/management/commands/tests/test_send_recurring_nudge.py index 2f6edea486d6..3b47b85f26fa 100644 --- a/openedx/core/djangoapps/schedules/management/commands/tests/test_send_recurring_nudge.py +++ b/openedx/core/djangoapps/schedules/management/commands/tests/test_send_recurring_nudge.py @@ -12,7 +12,7 @@ from openedx.core.djangoapps.schedules.management.commands import send_recurring_nudge as nudge from openedx.core.djangoapps.schedules.management.commands.tests.send_email_base import ( ExperienceTest, - ScheduleSendEmailTestMixin + ScheduleSendEmailTestMixin, ) from openedx.core.djangoapps.schedules.management.commands.tests.upsell_base import ScheduleUpsellTestMixin from openedx.core.djangoapps.schedules.models import ScheduleExperience diff --git a/openedx/core/djangoapps/schedules/management/commands/tests/test_send_upgrade_reminder.py b/openedx/core/djangoapps/schedules/management/commands/tests/test_send_upgrade_reminder.py index 86e782a13283..9dc2dfb3ec70 100644 --- a/openedx/core/djangoapps/schedules/management/commands/tests/test_send_upgrade_reminder.py +++ b/openedx/core/djangoapps/schedules/management/commands/tests/test_send_upgrade_reminder.py @@ -14,15 +14,15 @@ from opaque_keys.edx.locator import CourseLocator from common.djangoapps.course_modes.models import CourseMode +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.schedules import resolvers, tasks from openedx.core.djangoapps.schedules.management.commands import send_upgrade_reminder as reminder from openedx.core.djangoapps.schedules.management.commands.tests.send_email_base import ( ExperienceTest, - ScheduleSendEmailTestMixin + ScheduleSendEmailTestMixin, ) from openedx.core.djangoapps.schedules.models import ScheduleExperience from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms -from common.djangoapps.student.tests.factories import UserFactory LOG = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/schedules/resolvers.py b/openedx/core/djangoapps/schedules/resolvers.py index b3dce6f054a7..24ec08be8ed5 100644 --- a/openedx/core/djangoapps/schedules/resolvers.py +++ b/openedx/core/djangoapps/schedules/resolvers.py @@ -8,22 +8,23 @@ import attr from django.conf import settings from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user -from django.templatetags.static import static from django.db.models import Exists, F, OuterRef, Q +from django.templatetags.static import static from django.urls import reverse from edx_ace.recipient import Recipient from edx_ace.recipient_resolver import RecipientResolver from edx_django_utils.monitoring import function_trace, set_custom_attribute from openedx_filters.learning.filters import ScheduleQuerySetRequested -from lms.djangoapps.courseware.utils import verified_upgrade_deadline_link, can_show_verified_upgrade +from lms.djangoapps.courseware.utils import can_show_verified_upgrade, verified_upgrade_deadline_link from lms.djangoapps.discussion.notification_prefs.views import UsernameCipher from openedx.core.djangoapps.ace_common.template_context import get_base_template_context from openedx.core.djangoapps.course_date_signals.utils import get_expected_duration from openedx.core.djangoapps.schedules.config import ( - COURSE_UPDATE_SHOW_UNSUBSCRIBE_WAFFLE_SWITCH, query_external_updates + COURSE_UPDATE_SHOW_UNSUBSCRIBE_WAFFLE_SWITCH, + query_external_updates, ) -from openedx.core.djangoapps.schedules.content_highlights import get_week_highlights, get_next_section_highlights +from openedx.core.djangoapps.schedules.content_highlights import get_next_section_highlights, get_week_highlights from openedx.core.djangoapps.schedules.exceptions import CourseUpdateDoesNotExist from openedx.core.djangoapps.schedules.message_types import CourseUpdate, InstructorLedCourseUpdate from openedx.core.djangoapps.schedules.models import Schedule, ScheduleExperience diff --git a/openedx/core/djangoapps/schedules/signals.py b/openedx/core/djangoapps/schedules/signals.py index c88119d83f34..772a966d1d94 100644 --- a/openedx/core/djangoapps/schedules/signals.py +++ b/openedx/core/djangoapps/schedules/signals.py @@ -10,17 +10,18 @@ from edx_ace.utils import date from common.djangoapps.course_modes.models import CourseMode +from common.djangoapps.student.models import CourseEnrollment +from common.djangoapps.student.signals import ENROLLMENT_TRACK_UPDATED # lint-amnesty, pylint: disable=unused-import from lms.djangoapps.courseware.models import ( CourseDynamicUpgradeDeadlineConfiguration, DynamicUpgradeDeadlineConfiguration, - OrgDynamicUpgradeDeadlineConfiguration + OrgDynamicUpgradeDeadlineConfiguration, ) from openedx.core.djangoapps.content.course_overviews.signals import COURSE_START_DATE_CHANGED from openedx.core.djangoapps.schedules.content_highlights import course_has_highlights_from_store from openedx.core.djangoapps.schedules.models import ScheduleExperience from openedx.core.djangoapps.schedules.utils import reset_self_paced_schedule -from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.signals import ENROLLMENT_TRACK_UPDATED # lint-amnesty, pylint: disable=unused-import + from .models import Schedule from .tasks import update_course_schedules diff --git a/openedx/core/djangoapps/schedules/tasks.py b/openedx/core/djangoapps/schedules/tasks.py index d4685a1e46b5..71c8b12be76f 100644 --- a/openedx/core/djangoapps/schedules/tasks.py +++ b/openedx/core/djangoapps/schedules/tasks.py @@ -2,8 +2,9 @@ import datetime import logging +from importlib import import_module -from celery import shared_task, current_app +from celery import current_app, shared_task from celery_utils.logged_task import LoggedTask from celery_utils.persist_on_failure import LoggedPersistOnFailureTask from django.conf import settings @@ -17,17 +18,16 @@ from edx_django_utils.monitoring import ( set_code_owner_attribute, set_code_owner_attribute_from_module, - set_custom_attribute + set_custom_attribute, ) from eventtracking import tracker -from importlib import import_module from opaque_keys.edx.keys import CourseKey +from common.djangoapps.track import segment from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.schedules import message_types, resolvers from openedx.core.djangoapps.schedules.models import Schedule, ScheduleConfig from openedx.core.lib.celery.task_utils import emulate_http_request -from common.djangoapps.track import segment LOG = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/schedules/tests/factories.py b/openedx/core/djangoapps/schedules/tests/factories.py index c3ffcad246ed..eba5466cdd03 100644 --- a/openedx/core/djangoapps/schedules/tests/factories.py +++ b/openedx/core/djangoapps/schedules/tests/factories.py @@ -3,12 +3,13 @@ """ -import factory from zoneinfo import ZoneInfo +import factory + +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory from openedx.core.djangoapps.schedules import models from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory class ScheduleExperienceFactory(factory.django.DjangoModelFactory): diff --git a/openedx/core/djangoapps/schedules/tests/test_config.py b/openedx/core/djangoapps/schedules/tests/test_config.py index 03d507312cc3..9bd83e49a861 100644 --- a/openedx/core/djangoapps/schedules/tests/test_config.py +++ b/openedx/core/djangoapps/schedules/tests/test_config.py @@ -12,7 +12,9 @@ from lms.djangoapps.experiments.models import ExperimentData from lms.djangoapps.experiments.testutils import override_experiment_waffle_flag from openedx.core.djangoapps.schedules.config import ( - _EXTERNAL_COURSE_UPDATES_FLAG, query_external_updates, set_up_external_updates_for_enrollment + _EXTERNAL_COURSE_UPDATES_FLAG, + query_external_updates, + set_up_external_updates_for_enrollment, ) from openedx.core.djangolib.testing.utils import skip_unless_lms diff --git a/openedx/core/djangoapps/schedules/tests/test_content_highlights.py b/openedx/core/djangoapps/schedules/tests/test_content_highlights.py index ece49fc50f0d..4f0f31038c59 100644 --- a/openedx/core/djangoapps/schedules/tests/test_content_highlights.py +++ b/openedx/core/djangoapps/schedules/tests/test_content_highlights.py @@ -3,19 +3,19 @@ from unittest.mock import patch import pytest -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory +from common.djangoapps.student.models import CourseEnrollment +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.schedules.content_highlights import ( course_has_highlights_from_store, get_all_course_highlights, get_next_section_highlights, - get_week_highlights + get_week_highlights, ) from openedx.core.djangoapps.schedules.exceptions import CourseUpdateDoesNotExist from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.tests.factories import UserFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory @skip_unless_lms diff --git a/openedx/core/djangoapps/schedules/tests/test_resolvers.py b/openedx/core/djangoapps/schedules/tests/test_resolvers.py index 9608769f2c49..ffe75a1b9b61 100644 --- a/openedx/core/djangoapps/schedules/tests/test_resolvers.py +++ b/openedx/core/djangoapps/schedules/tests/test_resolvers.py @@ -5,17 +5,15 @@ import datetime from unittest.mock import Mock +from zoneinfo import ZoneInfo import crum import ddt -from zoneinfo import ZoneInfo from django.test import TestCase from django.test.client import RequestFactory from django.test.utils import override_settings from edx_toggles.toggles.testutils import override_waffle_switch from testfixtures import LogCapture -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory @@ -36,6 +34,8 @@ from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory, SiteFactory from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES from openedx.core.djangolib.testing.utils import CacheIsolationMixin, skip_unless_lms +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory QUERY_COUNT_TABLE_IGNORELIST = WAFFLE_TABLES diff --git a/openedx/core/djangoapps/schedules/tests/test_signals.py b/openedx/core/djangoapps/schedules/tests/test_signals.py index b862f8e00e26..b4fb763883a5 100644 --- a/openedx/core/djangoapps/schedules/tests/test_signals.py +++ b/openedx/core/djangoapps/schedules/tests/test_signals.py @@ -5,22 +5,25 @@ import datetime from unittest.mock import patch +from zoneinfo import ZoneInfo import ddt import pytest -from zoneinfo import ZoneInfo from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory +from common.djangoapps.student.models import CourseEnrollment +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory from lms.djangoapps.courseware.models import DynamicUpgradeDeadlineConfiguration from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.schedules.models import ScheduleExperience from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order + ModuleStoreTestCase, + SharedModuleStoreTestCase, +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..models import Schedule diff --git a/openedx/core/djangoapps/schedules/tests/test_utils.py b/openedx/core/djangoapps/schedules/tests/test_utils.py index 2b48550b421d..2e0ee0b441c4 100644 --- a/openedx/core/djangoapps/schedules/tests/test_utils.py +++ b/openedx/core/djangoapps/schedules/tests/test_utils.py @@ -3,18 +3,18 @@ """ import datetime +from zoneinfo import ZoneInfo import ddt -from zoneinfo import ZoneInfo -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.course_modes.models import CourseMode +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory from openedx.core.djangoapps.schedules.models import Schedule from openedx.core.djangoapps.schedules.tests.factories import ScheduleConfigFactory from openedx.core.djangoapps.schedules.utils import reset_self_paced_schedule from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory @ddt.ddt diff --git a/openedx/core/djangoapps/schedules/utils.py b/openedx/core/djangoapps/schedules/utils.py index 344e7566b1e3..107e0179d145 100644 --- a/openedx/core/djangoapps/schedules/utils.py +++ b/openedx/core/djangoapps/schedules/utils.py @@ -2,8 +2,8 @@ import datetime import logging - from zoneinfo import ZoneInfo + from django.db import transaction from openedx.core.djangoapps.schedules.models import Schedule diff --git a/openedx/core/djangoapps/service_status/urls.py b/openedx/core/djangoapps/service_status/urls.py index ccbed2c22af4..ad3cff8104a6 100644 --- a/openedx/core/djangoapps/service_status/urls.py +++ b/openedx/core/djangoapps/service_status/urls.py @@ -2,6 +2,7 @@ Django URLs for service status app """ from django.urls import path + from openedx.core.djangoapps.service_status.views import celery_ping, celery_status, index urlpatterns = [ diff --git a/openedx/core/djangoapps/service_status/views.py b/openedx/core/djangoapps/service_status/views.py index fa14d32226d2..b23115bf3676 100644 --- a/openedx/core/djangoapps/service_status/views.py +++ b/openedx/core/djangoapps/service_status/views.py @@ -6,9 +6,10 @@ import json import time +from celery import current_app as celery from celery.exceptions import TimeoutError # lint-amnesty, pylint: disable=redefined-builtin from django.http import HttpResponse -from celery import current_app as celery + from openedx.core.djangoapps.service_status.tasks import delayed_ping diff --git a/openedx/core/djangoapps/session_inactivity_timeout/middleware.py b/openedx/core/djangoapps/session_inactivity_timeout/middleware.py index a84abc9e8ab3..9e02892378fd 100644 --- a/openedx/core/djangoapps/session_inactivity_timeout/middleware.py +++ b/openedx/core/djangoapps/session_inactivity_timeout/middleware.py @@ -13,15 +13,14 @@ """ -from datetime import datetime, timedelta import logging +from datetime import datetime, timedelta from django.conf import settings from django.contrib import auth from django.utils.deprecation import MiddlewareMixin from edx_django_utils import monitoring as monitoring_utils - log = logging.getLogger(__name__) LAST_TOUCH_KEYNAME = 'SessionInactivityTimeout:last_touch_str' diff --git a/openedx/core/djangoapps/session_inactivity_timeout/tests/test_middleware.py b/openedx/core/djangoapps/session_inactivity_timeout/tests/test_middleware.py index c47505a9836a..43f1def794b6 100644 --- a/openedx/core/djangoapps/session_inactivity_timeout/tests/test_middleware.py +++ b/openedx/core/djangoapps/session_inactivity_timeout/tests/test_middleware.py @@ -3,7 +3,7 @@ """ from datetime import datetime, timedelta -from unittest.mock import patch, call, ANY +from unittest.mock import ANY, call, patch import ddt from django.contrib.auth.models import AnonymousUser @@ -11,13 +11,9 @@ from django.test import TestCase, override_settings from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.session_inactivity_timeout.middleware import LAST_TOUCH_KEYNAME, SessionInactivityTimeout from openedx.core.djangolib.testing.utils import get_mock_request -from openedx.core.djangoapps.session_inactivity_timeout.middleware import ( - SessionInactivityTimeout, - LAST_TOUCH_KEYNAME, -) - @ddt.ddt class SessionInactivityTimeoutTestCase(TestCase): diff --git a/openedx/core/djangoapps/site_configuration/context_processors.py b/openedx/core/djangoapps/site_configuration/context_processors.py index bbd9e4ee365b..20a1bddf2f46 100644 --- a/openedx/core/djangoapps/site_configuration/context_processors.py +++ b/openedx/core/djangoapps/site_configuration/context_processors.py @@ -3,9 +3,10 @@ """ -from django.conf import settings from urllib.parse import quote_plus # lint-amnesty, pylint: disable=wrong-import-order +from django.conf import settings + from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers diff --git a/openedx/core/djangoapps/site_configuration/helpers.py b/openedx/core/djangoapps/site_configuration/helpers.py index bee1d825ca32..ff219de4681d 100644 --- a/openedx/core/djangoapps/site_configuration/helpers.py +++ b/openedx/core/djangoapps/site_configuration/helpers.py @@ -4,6 +4,7 @@ from django.conf import settings + from openedx.core.lib.cache_utils import request_cached diff --git a/openedx/core/djangoapps/site_configuration/management/commands/tests/test_create_or_update_site_configuration.py b/openedx/core/djangoapps/site_configuration/management/commands/tests/test_create_or_update_site_configuration.py index e572c3631f70..87a356de9dc1 100644 --- a/openedx/core/djangoapps/site_configuration/management/commands/tests/test_create_or_update_site_configuration.py +++ b/openedx/core/djangoapps/site_configuration/management/commands/tests/test_create_or_update_site_configuration.py @@ -4,10 +4,11 @@ import codecs import json -import pytest + import ddt +import pytest from django.contrib.sites.models import Site -from django.core.management import call_command, CommandError +from django.core.management import CommandError, call_command from django.test import TestCase from path import Path diff --git a/openedx/core/djangoapps/site_configuration/migrations/0001_initial.py b/openedx/core/djangoapps/site_configuration/migrations/0001_initial.py index f6b14a25ec10..e5e1b4a205ce 100644 --- a/openedx/core/djangoapps/site_configuration/migrations/0001_initial.py +++ b/openedx/core/djangoapps/site_configuration/migrations/0001_initial.py @@ -1,7 +1,7 @@ -from django.db import migrations, models import django.utils.timezone import jsonfield.fields import model_utils.fields +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/site_configuration/migrations/0008_auto_20210910_0940.py b/openedx/core/djangoapps/site_configuration/migrations/0008_auto_20210910_0940.py index efcc616d8f24..4dc4ff9b32a4 100644 --- a/openedx/core/djangoapps/site_configuration/migrations/0008_auto_20210910_0940.py +++ b/openedx/core/djangoapps/site_configuration/migrations/0008_auto_20210910_0940.py @@ -1,8 +1,9 @@ # Generated by Django 2.2.24 on 2021-09-10 09:40 import collections -from django.db import migrations + import jsonfield.fields +from django.db import migrations class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/site_configuration/models.py b/openedx/core/djangoapps/site_configuration/models.py index c084b8ce4839..17ad37879110 100644 --- a/openedx/core/djangoapps/site_configuration/models.py +++ b/openedx/core/djangoapps/site_configuration/models.py @@ -10,7 +10,6 @@ from django.db import models from django.db.models.signals import post_save from django.dispatch import receiver - from jsonfield.fields import JSONField from model_utils.models import TimeStampedModel diff --git a/openedx/core/djangoapps/site_configuration/templatetags/configuration.py b/openedx/core/djangoapps/site_configuration/templatetags/configuration.py index 9de10d3bb07b..1d6a444d2ce2 100644 --- a/openedx/core/djangoapps/site_configuration/templatetags/configuration.py +++ b/openedx/core/djangoapps/site_configuration/templatetags/configuration.py @@ -9,8 +9,8 @@ from django.templatetags.static import static from lms.djangoapps.branding.api import get_favicon_url -from openedx.core.djangoapps.theming import helpers as theming_helpers from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.djangoapps.theming import helpers as theming_helpers from openedx.core.djangolib.markup import HTML register = template.Library() # pylint: disable=invalid-name diff --git a/openedx/core/djangoapps/site_configuration/tests/factories.py b/openedx/core/djangoapps/site_configuration/tests/factories.py index df7d1eef706a..88c74cd49962 100644 --- a/openedx/core/djangoapps/site_configuration/tests/factories.py +++ b/openedx/core/djangoapps/site_configuration/tests/factories.py @@ -4,8 +4,8 @@ from django.contrib.sites.models import Site +from factory import SelfAttribute, Sequence, SubFactory, lazy_attribute from factory.django import DjangoModelFactory -from factory import SubFactory, Sequence, SelfAttribute, lazy_attribute from openedx.core.djangoapps.site_configuration.models import SiteConfiguration diff --git a/openedx/core/djangoapps/site_configuration/tests/test_context_processors.py b/openedx/core/djangoapps/site_configuration/tests/test_context_processors.py index 6c451d12c434..6e016b3ea47b 100644 --- a/openedx/core/djangoapps/site_configuration/tests/test_context_processors.py +++ b/openedx/core/djangoapps/site_configuration/tests/test_context_processors.py @@ -8,9 +8,8 @@ from django.test.utils import override_settings from openedx.core.djangoapps.site_configuration.context_processors import configuration_context -from openedx.core.djangoapps.site_configuration.tests.test_util import ( - with_site_configuration, -) +from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration + PLATFORM_NAME = 'Test Platform' diff --git a/openedx/core/djangoapps/site_configuration/tests/test_models.py b/openedx/core/djangoapps/site_configuration/tests/test_models.py index 22b82b63f578..2b0c44db70be 100644 --- a/openedx/core/djangoapps/site_configuration/tests/test_models.py +++ b/openedx/core/djangoapps/site_configuration/tests/test_models.py @@ -2,14 +2,16 @@ Tests for site configuration's django models. """ from unittest.mock import patch + import pytest from django.contrib.sites.models import Site from django.db import IntegrityError, transaction from django.test import TestCase + from openedx.core.djangoapps.site_configuration.models import ( SiteConfiguration, SiteConfigurationHistory, - save_siteconfig_without_historical_record + save_siteconfig_without_historical_record, ) from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory diff --git a/openedx/core/djangoapps/site_configuration/tests/test_util.py b/openedx/core/djangoapps/site_configuration/tests/test_util.py index 489beca82a88..ba595f3669f9 100644 --- a/openedx/core/djangoapps/site_configuration/tests/test_util.py +++ b/openedx/core/djangoapps/site_configuration/tests/test_util.py @@ -3,9 +3,8 @@ """ -from functools import wraps import contextlib - +from functools import wraps from unittest.mock import patch from django.contrib.sites.models import Site diff --git a/openedx/core/djangoapps/system_wide_roles/migrations/0001_SystemWideRole_SystemWideRoleAssignment.py b/openedx/core/djangoapps/system_wide_roles/migrations/0001_SystemWideRole_SystemWideRoleAssignment.py index 3d051a624c75..e1fcfab2b658 100644 --- a/openedx/core/djangoapps/system_wide_roles/migrations/0001_SystemWideRole_SystemWideRoleAssignment.py +++ b/openedx/core/djangoapps/system_wide_roles/migrations/0001_SystemWideRole_SystemWideRoleAssignment.py @@ -1,11 +1,11 @@ # Generated by Django 1.11.22 on 2019-07-02 09:33 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/system_wide_roles/tests/test_models.py b/openedx/core/djangoapps/system_wide_roles/tests/test_models.py index eb77325fa99b..fd74d4ff2121 100644 --- a/openedx/core/djangoapps/system_wide_roles/tests/test_models.py +++ b/openedx/core/djangoapps/system_wide_roles/tests/test_models.py @@ -4,8 +4,8 @@ from django.test import TestCase -from common.djangoapps.student.tests.factories import UserFactory +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.system_wide_roles.models import SystemWideRole, SystemWideRoleAssignment diff --git a/openedx/core/djangoapps/theming/helpers.py b/openedx/core/djangoapps/theming/helpers.py index b88bbdca4382..0652dd8639e5 100644 --- a/openedx/core/djangoapps/theming/helpers.py +++ b/openedx/core/djangoapps/theming/helpers.py @@ -8,22 +8,22 @@ import os import re +from functools import lru_cache from logging import getLogger import crum from django.conf import settings - from edx_toggles.toggles import SettingToggle + from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.theming.helpers_dirs import ( Theme, get_project_root_name_from_settings, get_theme_base_dirs_from_settings, get_theme_dirs, - get_themes_unchecked + get_themes_unchecked, ) from openedx.core.lib.cache_utils import request_cached -from functools import lru_cache logger = getLogger(__name__) # pylint: disable=invalid-name diff --git a/openedx/core/djangoapps/theming/helpers_dirs.py b/openedx/core/djangoapps/theming/helpers_dirs.py index 9e40749e50c0..3f7fc22c185d 100644 --- a/openedx/core/djangoapps/theming/helpers_dirs.py +++ b/openedx/core/djangoapps/theming/helpers_dirs.py @@ -5,9 +5,9 @@ import os +from functools import lru_cache from path import Path -from functools import lru_cache def get_theme_base_dirs_from_settings(theme_base_dirs=None): diff --git a/openedx/core/djangoapps/theming/management/commands/create_sites_and_configurations.py b/openedx/core/djangoapps/theming/management/commands/create_sites_and_configurations.py index 9f9e7661395b..4805c5f6246f 100644 --- a/openedx/core/djangoapps/theming/management/commands/create_sites_and_configurations.py +++ b/openedx/core/djangoapps/theming/management/commands/create_sites_and_configurations.py @@ -14,11 +14,11 @@ from django.core.management.base import BaseCommand from oauth2_provider.models import Application +from common.djangoapps.student.models import UserProfile from lms.djangoapps.commerce.models import CommerceConfiguration from openedx.core.djangoapps.oauth_dispatch.models import ApplicationAccess from openedx.core.djangoapps.site_configuration.models import SiteConfiguration from openedx.core.djangoapps.theming.models import SiteTheme -from common.djangoapps.student.models import UserProfile LOG = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/theming/management/commands/tests/test_create_sites_and_configurations.py b/openedx/core/djangoapps/theming/management/commands/tests/test_create_sites_and_configurations.py index 601aa6cc0c0f..044bfc41a38c 100644 --- a/openedx/core/djangoapps/theming/management/commands/tests/test_create_sites_and_configurations.py +++ b/openedx/core/djangoapps/theming/management/commands/tests/test_create_sites_and_configurations.py @@ -3,16 +3,17 @@ """ from unittest import mock + import pytest from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.contrib.sites.models import Site from django.core.management import CommandError, call_command from django.test import TestCase - from oauth2_provider.models import Application + +from common.djangoapps.student.models import UserProfile from openedx.core.djangoapps.oauth_dispatch.models import ApplicationAccess from openedx.core.djangoapps.theming.models import SiteTheme -from common.djangoapps.student.models import UserProfile SITES = ["site_a", "site_b"] MANAGEMENT_COMMAND_PATH = "openedx.core.djangoapps.theming.management.commands.create_sites_and_configurations." diff --git a/openedx/core/djangoapps/theming/storage.py b/openedx/core/djangoapps/theming/storage.py index 4a48cbb6e0a5..1f92066d21d5 100644 --- a/openedx/core/djangoapps/theming/storage.py +++ b/openedx/core/djangoapps/theming/storage.py @@ -7,8 +7,8 @@ import os.path import posixpath import re - from urllib.parse import unquote, urldefrag, urlsplit # pylint: disable=import-error + from django.conf import settings from django.contrib.staticfiles.finders import find from django.contrib.staticfiles.storage import ManifestFilesMixin, StaticFilesStorage @@ -20,7 +20,7 @@ get_project_root_name, get_theme_base_dir, get_themes, - is_comprehensive_theming_enabled + is_comprehensive_theming_enabled, ) diff --git a/openedx/core/djangoapps/theming/tests/test_helpers.py b/openedx/core/djangoapps/theming/tests/test_helpers.py index 95829a16b416..461acd98bfb0 100644 --- a/openedx/core/djangoapps/theming/tests/test_helpers.py +++ b/openedx/core/djangoapps/theming/tests/test_helpers.py @@ -4,6 +4,7 @@ from unittest.mock import Mock, patch + from django.conf import settings from django.test import TestCase, override_settings @@ -14,7 +15,7 @@ get_template_path_with_theme, get_theme_base_dir, get_themes, - strip_site_theme_templates_path + strip_site_theme_templates_path, ) from openedx.core.djangoapps.theming.helpers_dirs import get_theme_dirs from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme diff --git a/openedx/core/djangoapps/theming/tests/test_middleware.py b/openedx/core/djangoapps/theming/tests/test_middleware.py index 2f69a6cc72be..25202c395c8d 100644 --- a/openedx/core/djangoapps/theming/tests/test_middleware.py +++ b/openedx/core/djangoapps/theming/tests/test_middleware.py @@ -7,8 +7,8 @@ from django.contrib.sites.models import Site from django.test import RequestFactory, TestCase, override_settings -from openedx.core.djangoapps.theming.middleware import CurrentSiteThemeMiddleware from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.theming.middleware import CurrentSiteThemeMiddleware from ..views import set_user_preview_site_theme diff --git a/openedx/core/djangoapps/theming/tests/test_theme_style_overrides.py b/openedx/core/djangoapps/theming/tests/test_theme_style_overrides.py index 41f91c7d1eb5..44d51b5426bd 100644 --- a/openedx/core/djangoapps/theming/tests/test_theme_style_overrides.py +++ b/openedx/core/djangoapps/theming/tests/test_theme_style_overrides.py @@ -8,9 +8,9 @@ from django.test import TestCase from django.urls import reverse +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme from openedx.core.djangolib.testing.utils import skip_unless_lms # lint-amnesty, pylint: disable=unused-import -from common.djangoapps.student.tests.factories import UserFactory @skip_unless_lms diff --git a/openedx/core/djangoapps/theming/urls.py b/openedx/core/djangoapps/theming/urls.py index 375c3621e534..d9a45a5fb4aa 100644 --- a/openedx/core/djangoapps/theming/urls.py +++ b/openedx/core/djangoapps/theming/urls.py @@ -3,8 +3,7 @@ """ from django.urls import path -from . import helpers -from . import views +from . import helpers, views app_name = "openedx.core.djangoapps.theming" diff --git a/openedx/core/djangoapps/theming/views.py b/openedx/core/djangoapps/theming/views.py index 966f37eca0db..463318e5278c 100644 --- a/openedx/core/djangoapps/theming/views.py +++ b/openedx/core/djangoapps/theming/views.py @@ -12,14 +12,14 @@ from django.utils.translation import gettext as _ from web_fragments.fragment import Fragment +from common.djangoapps.student.roles import GlobalStaff from openedx.core.djangoapps.plugin_api.views import EdxFragmentView from openedx.core.djangoapps.user_api.preferences.api import ( delete_user_preference, get_user_preference, - set_user_preference + set_user_preference, ) from openedx.core.djangoapps.util.user_messages import PageLevelMessages -from common.djangoapps.student.roles import GlobalStaff from .helpers import theme_exists from .helpers_static import get_static_file_url diff --git a/openedx/core/djangoapps/user_api/accounts/api.py b/openedx/core/djangoapps/user_api/accounts/api.py index c3fd805a3166..70200c850adb 100644 --- a/openedx/core/djangoapps/user_api/accounts/api.py +++ b/openedx/core/djangoapps/user_api/accounts/api.py @@ -5,6 +5,7 @@ import datetime import re +from zoneinfo import ZoneInfo from django.conf import settings from django.core.exceptions import ObjectDoesNotExist @@ -12,7 +13,6 @@ from django.utils.translation import gettext as _ from django.utils.translation import override as override_language from eventtracking import tracker -from zoneinfo import ZoneInfo from common.djangoapps.student import views as student_views from common.djangoapps.student.models import ( @@ -20,7 +20,7 @@ User, UserProfile, email_exists_or_retired, - username_exists_or_retired + username_exists_or_retired, ) from common.djangoapps.util.model_utils import emit_settings_changed_event from common.djangoapps.util.password_policy_validators import validate_password @@ -32,7 +32,7 @@ from openedx.core.djangoapps.user_api.errors import ( AccountUpdateError, AccountValidationError, - PreferenceValidationError + PreferenceValidationError, ) from openedx.core.djangoapps.user_api.preferences.api import update_user_preferences from openedx.core.djangoapps.user_authn.utils import check_pwned_password diff --git a/openedx/core/djangoapps/user_api/accounts/serializers.py b/openedx/core/djangoapps/user_api/accounts/serializers.py index b200cd1b8609..29ec436d03e8 100644 --- a/openedx/core/djangoapps/user_api/accounts/serializers.py +++ b/openedx/core/djangoapps/user_api/accounts/serializers.py @@ -13,13 +13,12 @@ from django.urls import reverse from rest_framework import serializers - from common.djangoapps.student.models import ( LanguageProficiency, PendingNameChange, SocialLink, UserPasswordToggleHistory, - UserProfile + UserProfile, ) from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.user_api import errors @@ -36,7 +35,7 @@ CUSTOM_VISIBILITY, NAME_MIN_LENGTH, PRIVATE_VISIBILITY, - VISIBILITY_PREFIX + VISIBILITY_PREFIX, ) from .image_helpers import get_profile_image_urls_for_user from .utils import format_social_link, validate_social_link diff --git a/openedx/core/djangoapps/user_api/accounts/tests/factories.py b/openedx/core/djangoapps/user_api/accounts/tests/factories.py index a3a3bad92b12..4cb96587700e 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/factories.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/factories.py @@ -3,8 +3,9 @@ """ from factory import SubFactory from factory.django import DjangoModelFactory -from openedx.core.djangoapps.user_api.models import UserRetirementStatus, RetirementState + from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.user_api.models import RetirementState, UserRetirementStatus class RetirementStateFactory(DjangoModelFactory): diff --git a/openedx/core/djangoapps/user_api/accounts/tests/retirement_helpers.py b/openedx/core/djangoapps/user_api/accounts/tests/retirement_helpers.py index d91ba37399d4..6c6581c5a2e2 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/retirement_helpers.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/retirement_helpers.py @@ -4,16 +4,16 @@ import datetime +from zoneinfo import ZoneInfo import pytest -from zoneinfo import ZoneInfo from django.test import TestCase from social_django.models import UserSocialAuth -from openedx.core.djangoapps.enrollments import api -from openedx.core.djangoapps.user_api.models import RetirementState, UserRetirementStatus from common.djangoapps.student.models import get_retired_email_by_email, get_retired_username_by_username from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.enrollments import api +from openedx.core.djangoapps.user_api.models import RetirementState, UserRetirementStatus from ..views import AccountRetirementView diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_api.py b/openedx/core/djangoapps/user_api/accounts/tests/test_api.py index dccbd87ab2a1..8c6e09d34c5a 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_api.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_api.py @@ -7,6 +7,7 @@ import itertools import unicodedata from unittest.mock import Mock, patch +from zoneinfo import ZoneInfo import ddt import pytest @@ -17,14 +18,13 @@ from django.test import TestCase from django.test.client import RequestFactory from django.urls import reverse -from zoneinfo import ZoneInfo from social_django.models import UserSocialAuth from common.djangoapps.student.models import ( AccountRecovery, PendingEmailChange, PendingSecondaryEmailChange, - UserProfile + UserProfile, ) from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.student.tests.tests import UserSettingsEventTestMixin @@ -36,18 +36,18 @@ from openedx.core.djangoapps.user_api.accounts.api import ( get_account_settings, get_name_validation_error, - update_account_settings + update_account_settings, ) from openedx.core.djangoapps.user_api.accounts.tests.retirement_helpers import ( # pylint: disable=unused-import RetirementTestCase, fake_requested_retirement, - setup_retirement_states + setup_retirement_states, ) from openedx.core.djangoapps.user_api.errors import ( AccountUpdateError, AccountValidationError, UserNotAuthorized, - UserNotFound + UserNotFound, ) from openedx.core.djangolib.testing.utils import skip_unless_lms from openedx.features.enterprise_support.tests.factories import EnterpriseCustomerUserFactory diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_image_helpers.py b/openedx/core/djangoapps/user_api/accounts/tests/test_image_helpers.py index c02069ab7b16..a1c244a4115b 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_image_helpers.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_image_helpers.py @@ -6,12 +6,12 @@ import datetime import hashlib from unittest.mock import patch +from zoneinfo import ZoneInfo from django.test import TestCase -from zoneinfo import ZoneInfo -from openedx.core.djangolib.testing.utils import skip_unless_lms from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangolib.testing.utils import skip_unless_lms from ..image_helpers import get_profile_image_urls_for_user diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_models.py b/openedx/core/djangoapps/user_api/accounts/tests/test_models.py index c216a0ac55ae..ffd5716b526e 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_models.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_models.py @@ -5,14 +5,14 @@ import pytest +from common.djangoapps.student.models import get_retired_email_by_email, get_retired_username_by_username +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.user_api.models import ( RetirementState, RetirementStateError, UserRetirementRequest, - UserRetirementStatus + UserRetirementStatus, ) -from common.djangoapps.student.models import get_retired_email_by_email, get_retired_username_by_username -from common.djangoapps.student.tests.factories import UserFactory from .retirement_helpers import setup_retirement_states # pylint: disable=unused-import diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_permissions.py b/openedx/core/djangoapps/user_api/accounts/tests/test_permissions.py index 017255b74d59..424a820f2dcc 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_permissions.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_permissions.py @@ -10,12 +10,12 @@ ContentTypeFactory, PermissionFactory, SuperuserFactory, - UserFactory + UserFactory, ) from openedx.core.djangoapps.user_api.accounts.permissions import ( CanCancelUserRetirement, CanDeactivateUser, - CanRetireUser + CanRetireUser, ) diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_retirement_views.py b/openedx/core/djangoapps/user_api/accounts/tests/test_retirement_views.py index 262483152cef..74f85ae2a09a 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_retirement_views.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_retirement_views.py @@ -5,9 +5,9 @@ import datetime import json from unittest import mock +from zoneinfo import ZoneInfo import ddt -from zoneinfo import ZoneInfo from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.contrib.sites.models import Site from django.core import mail @@ -33,7 +33,7 @@ SocialLink, UserProfile, get_retired_email_by_email, - get_retired_username_by_username + get_retired_username_by_username, ) from common.djangoapps.student.tests.factories import ( AccountRecoveryFactory, @@ -42,7 +42,7 @@ PendingEmailChangeFactory, PermissionFactory, SuperuserFactory, - UserFactory + UserFactory, ) from lms.djangoapps.certificates.api import get_certificate_for_user_id from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory @@ -53,19 +53,19 @@ CreditProvider, CreditRequest, CreditRequirement, - CreditRequirementStatus + CreditRequirementStatus, ) from openedx.core.djangoapps.external_user_ids.models import ExternalIdType from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_for_user +from openedx.core.djangoapps.oauth_dispatch.tests.factories import AccessTokenFactory, ApplicationFactory from openedx.core.djangoapps.user_api.accounts.views import AccountRetirementPartnerReportView from openedx.core.djangoapps.user_api.models import ( RetirementState, UserOrgTag, UserRetirementPartnerReportingStatus, - UserRetirementStatus + UserRetirementStatus, ) from openedx.core.djangolib.testing.utils import skip_unless_lms -from openedx.core.djangoapps.oauth_dispatch.tests.factories import ApplicationFactory, AccessTokenFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory @@ -75,7 +75,7 @@ RetirementTestCase, create_retirement_status, fake_completed_retirement, - setup_retirement_states + setup_retirement_states, ) diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_serializers.py b/openedx/core/djangoapps/user_api/accounts/tests/test_serializers.py index 34b4cb0b0e0a..d77ef74c234d 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_serializers.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_serializers.py @@ -9,9 +9,9 @@ from django.test.client import RequestFactory from testfixtures import LogCapture -from openedx.core.djangoapps.user_api.accounts.serializers import UserReadOnlySerializer from common.djangoapps.student.models import UserProfile from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.user_api.accounts.serializers import UserReadOnlySerializer LOGGER_NAME = "openedx.core.djangoapps.user_api.accounts.serializers" diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_utils.py b/openedx/core/djangoapps/user_api/accounts/tests/test_utils.py index 9593dda0569a..10b0ff83e96d 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_utils.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_utils.py @@ -7,12 +7,17 @@ from django.test import TestCase from django.test.utils import override_settings -from openedx.core.djangoapps.user_api.accounts.utils import retrieve_last_sitewide_block_completed -from openedx.core.djangolib.testing.utils import skip_unless_lms from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from openedx.core.djangoapps.user_api.accounts.utils import retrieve_last_sitewide_block_completed +from openedx.core.djangolib.testing.utils import skip_unless_lms +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) from ..utils import format_social_link, validate_social_link diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_views.py b/openedx/core/djangoapps/user_api/accounts/tests/test_views.py index e73d8c7decd2..a11f14891ac4 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_views.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_views.py @@ -8,9 +8,9 @@ from copy import deepcopy from unittest import mock from urllib.parse import quote +from zoneinfo import ZoneInfo import ddt -from zoneinfo import ZoneInfo from django.conf import settings from django.core.files.storage import FileSystemStorage from django.test.testcases import TransactionTestCase @@ -27,15 +27,15 @@ ContentTypeFactory, PermissionFactory, RegistrationFactory, - UserFactory + UserFactory, ) from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_for_user from openedx.core.djangoapps.user_api.accounts import ACCOUNT_VISIBILITY_PREF_KEY +from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_image_storage from openedx.core.djangoapps.user_api.accounts.tests.factories import ( RetirementStateFactory, - UserRetirementStatusFactory + UserRetirementStatusFactory, ) -from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_image_storage from openedx.core.djangoapps.user_api.models import UserPreference, UserRetirementStatus from openedx.core.djangoapps.user_api.preferences.api import set_user_preference from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES diff --git a/openedx/core/djangoapps/user_api/accounts/tests/testutils.py b/openedx/core/djangoapps/user_api/accounts/tests/testutils.py index 24f7c16f24eb..8dde4dc79ea4 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/testutils.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/testutils.py @@ -3,8 +3,8 @@ """ -from openedx.core.djangoapps.user_api.accounts import EMAIL_MAX_LENGTH, USERNAME_MAX_LENGTH, USERNAME_MIN_LENGTH from common.djangoapps.util.password_policy_validators import DEFAULT_MAX_PASSWORD_LENGTH +from openedx.core.djangoapps.user_api.accounts import EMAIL_MAX_LENGTH, USERNAME_MAX_LENGTH, USERNAME_MIN_LENGTH INVALID_NAMES = [ None, diff --git a/openedx/core/djangoapps/user_api/accounts/views.py b/openedx/core/djangoapps/user_api/accounts/views.py index a1d18c29a698..37d467a6493b 100644 --- a/openedx/core/djangoapps/user_api/accounts/views.py +++ b/openedx/core/djangoapps/user_api/accounts/views.py @@ -8,8 +8,8 @@ import datetime import logging from functools import wraps - from zoneinfo import ZoneInfo + from django.apps import apps from django.conf import settings from django.contrib.auth import authenticate, get_user_model, logout @@ -35,7 +35,6 @@ from wiki.models import ArticleRevision from wiki.models.pluginbase import RevisionPluginRevision -from common.djangoapps.track import segment from common.djangoapps.entitlements.models import CourseEntitlement from common.djangoapps.student.models import ( # lint-amnesty, pylint: disable=unused-import CourseEnrollmentAllowed, @@ -52,6 +51,7 @@ is_username_retired, ) from common.djangoapps.student.models_api import confirm_name_change, do_name_change_request, get_pending_name_change +from common.djangoapps.track import segment from lms.djangoapps.certificates.api import clear_pii_from_certificate_records_for_user from openedx.core.djangoapps.ace_common.template_context import get_base_template_context from openedx.core.djangoapps.api_admin.models import ApiAccessRequest diff --git a/openedx/core/djangoapps/user_api/admin.py b/openedx/core/djangoapps/user_api/admin.py index 228a9a5bc451..91d2e6f871cd 100644 --- a/openedx/core/djangoapps/user_api/admin.py +++ b/openedx/core/djangoapps/user_api/admin.py @@ -16,7 +16,7 @@ RetirementState, UserRetirementPartnerReportingStatus, UserRetirementRequest, - UserRetirementStatus + UserRetirementStatus, ) diff --git a/openedx/core/djangoapps/user_api/course_tag/tests/test_api.py b/openedx/core/djangoapps/user_api/course_tag/tests/test_api.py index ab336d6f3f1d..e424fdec9150 100644 --- a/openedx/core/djangoapps/user_api/course_tag/tests/test_api.py +++ b/openedx/core/djangoapps/user_api/course_tag/tests/test_api.py @@ -6,8 +6,8 @@ from django.test import TestCase from opaque_keys.edx.locator import CourseLocator -from openedx.core.djangoapps.user_api.course_tag import api as course_tag_api from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.user_api.course_tag import api as course_tag_api class TestCourseTagAPI(TestCase): diff --git a/openedx/core/djangoapps/user_api/legacy_urls.py b/openedx/core/djangoapps/user_api/legacy_urls.py index 0333489a5cf9..f2ec67c9cefb 100644 --- a/openedx/core/djangoapps/user_api/legacy_urls.py +++ b/openedx/core/djangoapps/user_api/legacy_urls.py @@ -2,7 +2,7 @@ Defines the URL routes for this app. """ from django.conf import settings -from django.urls import path, re_path, include +from django.urls import include, path, re_path from django.views.generic import RedirectView from rest_framework import routers diff --git a/openedx/core/djangoapps/user_api/management/commands/create_user_gdpr_testing.py b/openedx/core/djangoapps/user_api/management/commands/create_user_gdpr_testing.py index fd574cb83fa1..22acad5a336a 100644 --- a/openedx/core/djangoapps/user_api/management/commands/create_user_gdpr_testing.py +++ b/openedx/core/djangoapps/user_api/management/commands/create_user_gdpr_testing.py @@ -8,6 +8,7 @@ from datetime import datetime from textwrap import dedent from uuid import uuid4 +from zoneinfo import ZoneInfo from consent.models import DataSharingConsent from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user @@ -16,18 +17,17 @@ EnterpriseCourseEnrollment, EnterpriseCustomer, EnterpriseCustomerUser, - PendingEnterpriseCustomerUser + PendingEnterpriseCustomerUser, ) from integrated_channels.sap_success_factors.models import SapSuccessFactorsLearnerDataTransmissionAudit from opaque_keys.edx.keys import CourseKey -from zoneinfo import ZoneInfo from common.djangoapps.entitlements.models import CourseEntitlement, CourseEntitlementSupportDetail +from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentAllowed, PendingEmailChange, UserProfile from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification from openedx.core.djangoapps.course_groups.models import CourseUserGroup, UnregisteredLearnerCohortAssignments from openedx.core.djangoapps.profile_images.images import create_profile_images from openedx.core.djangoapps.profile_images.tests.helpers import make_image_file -from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentAllowed, PendingEmailChange, UserProfile from ...models import UserOrgTag diff --git a/openedx/core/djangoapps/user_api/management/commands/email_opt_in_list.py b/openedx/core/djangoapps/user_api/management/commands/email_opt_in_list.py index e7a7ac16e485..8b98193b6c54 100644 --- a/openedx/core/djangoapps/user_api/management/commands/email_opt_in_list.py +++ b/openedx/core/djangoapps/user_api/management/commands/email_opt_in_list.py @@ -23,10 +23,11 @@ import contextlib import csv -from datetime import datetime, timezone as dt_timezone import logging import os.path import time +from datetime import datetime +from datetime import timezone as dt_timezone from django.conf import settings from django.core.management.base import BaseCommand, CommandError diff --git a/openedx/core/djangoapps/user_api/management/commands/populate_enterprise_learner_current_job.py b/openedx/core/djangoapps/user_api/management/commands/populate_enterprise_learner_current_job.py index 6593556ab871..a1323cb32d5f 100644 --- a/openedx/core/djangoapps/user_api/management/commands/populate_enterprise_learner_current_job.py +++ b/openedx/core/djangoapps/user_api/management/commands/populate_enterprise_learner_current_job.py @@ -1,13 +1,12 @@ """ Management command for populaing current job of learners in learner profile. """ import logging - -from edx_rest_api_client.client import OAuthAPIClient from urllib.parse import urljoin -from django.core.exceptions import ObjectDoesNotExist from django.conf import settings +from django.core.exceptions import ObjectDoesNotExist from django.core.management.base import BaseCommand +from edx_rest_api_client.client import OAuthAPIClient from common.djangoapps.student.models import User, UserProfile from openedx.core.djangoapps.user_api import errors diff --git a/openedx/core/djangoapps/user_api/management/tests/test_bulk_user_org_email_optout.py b/openedx/core/djangoapps/user_api/management/tests/test_bulk_user_org_email_optout.py index 9fbd8fcc053e..342afc69c425 100644 --- a/openedx/core/djangoapps/user_api/management/tests/test_bulk_user_org_email_optout.py +++ b/openedx/core/djangoapps/user_api/management/tests/test_bulk_user_org_email_optout.py @@ -7,8 +7,8 @@ import os import tempfile from contextlib import contextmanager - from unittest import mock + import pytest from django.core.management import call_command diff --git a/openedx/core/djangoapps/user_api/management/tests/test_cancel_retirement.py b/openedx/core/djangoapps/user_api/management/tests/test_cancel_retirement.py index ad9071b2b0e1..7a441888d966 100644 --- a/openedx/core/djangoapps/user_api/management/tests/test_cancel_retirement.py +++ b/openedx/core/djangoapps/user_api/management/tests/test_cancel_retirement.py @@ -8,12 +8,12 @@ from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.core.management import CommandError, call_command +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.user_api.accounts.tests.retirement_helpers import ( # pylint: disable=unused-import logged_out_retirement_request, - setup_retirement_states + setup_retirement_states, ) from openedx.core.djangoapps.user_api.models import RetirementState, UserRetirementRequest, UserRetirementStatus -from common.djangoapps.student.tests.factories import UserFactory pytestmark = pytest.mark.django_db diff --git a/openedx/core/djangoapps/user_api/management/tests/test_email_opt_in_list.py b/openedx/core/djangoapps/user_api/management/tests/test_email_opt_in_list.py index b32a8f723d5e..93842a6e919c 100644 --- a/openedx/core/djangoapps/user_api/management/tests/test_email_opt_in_list.py +++ b/openedx/core/djangoapps/user_api/management/tests/test_email_opt_in_list.py @@ -12,13 +12,15 @@ from django.core.management import call_command from django.core.management.base import CommandError +from common.djangoapps.student.models import CourseEnrollment +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from openedx.core.djangoapps.user_api.management.commands import email_opt_in_list from openedx.core.djangoapps.user_api.models import UserOrgTag from openedx.core.djangoapps.user_api.preferences.api import update_email_opt_in from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/core/djangoapps/user_api/management/tests/test_populate_retirement_states.py b/openedx/core/djangoapps/user_api/management/tests/test_populate_retirement_states.py index e43ebd54f9a7..36075e764133 100644 --- a/openedx/core/djangoapps/user_api/management/tests/test_populate_retirement_states.py +++ b/openedx/core/djangoapps/user_api/management/tests/test_populate_retirement_states.py @@ -8,9 +8,9 @@ import pytest from django.core.management import CommandError, call_command +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.user_api.management.commands.populate_retirement_states import START_STATE from openedx.core.djangoapps.user_api.models import RetirementState, UserRetirementStatus -from common.djangoapps.student.tests.factories import UserFactory pytestmark = pytest.mark.django_db diff --git a/openedx/core/djangoapps/user_api/management/tests/test_retire_user.py b/openedx/core/djangoapps/user_api/management/tests/test_retire_user.py index 023efb54f4d7..0cec6fff7302 100644 --- a/openedx/core/djangoapps/user_api/management/tests/test_retire_user.py +++ b/openedx/core/djangoapps/user_api/management/tests/test_retire_user.py @@ -3,18 +3,20 @@ """ +import csv +import os + import pytest from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.core.management import CommandError, call_command -from ...models import UserRetirementStatus +from common.djangoapps.student.tests.factories import UserFactory # lint-amnesty, pylint: disable=wrong-import-order from openedx.core.djangoapps.user_api.accounts.tests.retirement_helpers import ( # lint-amnesty, pylint: disable=unused-import, wrong-import-order - setup_retirement_states + setup_retirement_states, ) from openedx.core.djangolib.testing.utils import skip_unless_lms # lint-amnesty, pylint: disable=wrong-import-order -from common.djangoapps.student.tests.factories import UserFactory # lint-amnesty, pylint: disable=wrong-import-order -import csv -import os + +from ...models import UserRetirementStatus pytestmark = pytest.mark.django_db user_file = 'userfile.csv' diff --git a/openedx/core/djangoapps/user_api/management/tests/test_sync_hubspot_contacts.py b/openedx/core/djangoapps/user_api/management/tests/test_sync_hubspot_contacts.py index 4956554b1ef5..2dd09d07408d 100644 --- a/openedx/core/djangoapps/user_api/management/tests/test_sync_hubspot_contacts.py +++ b/openedx/core/djangoapps/user_api/management/tests/test_sync_hubspot_contacts.py @@ -12,11 +12,11 @@ from django.test import TestCase from django.utils import timezone +from common.djangoapps.student.models import UserAttribute, UserProfile +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory from openedx.core.djangoapps.user_api.management.commands.sync_hubspot_contacts import Command as sync_command from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.models import UserAttribute, UserProfile -from common.djangoapps.student.tests.factories import UserFactory @skip_unless_lms diff --git a/openedx/core/djangoapps/user_api/middleware.py b/openedx/core/djangoapps/user_api/middleware.py index 95bb3d568db6..ef33b27ab4a2 100644 --- a/openedx/core/djangoapps/user_api/middleware.py +++ b/openedx/core/djangoapps/user_api/middleware.py @@ -4,7 +4,6 @@ """ from django.utils.deprecation import MiddlewareMixin - from eventtracking import tracker from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey diff --git a/openedx/core/djangoapps/user_api/migrations/0005_bulkuserretirementconfig.py b/openedx/core/djangoapps/user_api/migrations/0005_bulkuserretirementconfig.py index af2508dea6a9..b312af831fa6 100644 --- a/openedx/core/djangoapps/user_api/migrations/0005_bulkuserretirementconfig.py +++ b/openedx/core/djangoapps/user_api/migrations/0005_bulkuserretirementconfig.py @@ -1,9 +1,9 @@ # Generated by Django 3.2.18 on 2023-03-22 10:34 -from django.conf import settings import django.core.validators -from django.db import migrations, models import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/user_api/models.py b/openedx/core/djangoapps/user_api/models.py index 2086ebecf3c6..3aec9f060d37 100644 --- a/openedx/core/djangoapps/user_api/models.py +++ b/openedx/core/djangoapps/user_api/models.py @@ -3,18 +3,22 @@ """ +from config_models.models import ConfigurationModel from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.core.validators import FileExtensionValidator, RegexValidator from django.db import models from django.db.models.signals import post_delete, post_save, pre_save from django.dispatch import receiver from django.utils.translation import gettext_lazy as _ - -from config_models.models import ConfigurationModel - from model_utils.models import TimeStampedModel from opaque_keys.edx.django.models import CourseKeyField +# pylint: disable=unused-import +from common.djangoapps.student.models import get_retired_email_by_email, get_retired_username_by_username +from common.djangoapps.util.model_utils import emit_settings_changed_event, get_changed_fields_dict +from openedx.core.djangolib.model_mixins import DeletableByUserValue +from openedx.core.lib.cache_utils import request_cached + # Currently, the "student" app is responsible for # accounts, profiles, enrollments, and the student dashboard. # We are trying to move some of this functionality into separate apps, @@ -22,18 +26,6 @@ # certain models. For now we will leave the models in "student" and # create an alias in "user_api". -from openedx.core.djangolib.model_mixins import DeletableByUserValue -from openedx.core.lib.cache_utils import request_cached -# pylint: disable=unused-import -from common.djangoapps.student.models import ( - get_retired_email_by_email, - get_retired_username_by_username -) -from common.djangoapps.util.model_utils import ( - emit_settings_changed_event, - get_changed_fields_dict, - -) class RetirementStateError(Exception): diff --git a/openedx/core/djangoapps/user_api/partition_schemes.py b/openedx/core/djangoapps/user_api/partition_schemes.py index caa305387ac5..3473ea1ca86d 100644 --- a/openedx/core/djangoapps/user_api/partition_schemes.py +++ b/openedx/core/djangoapps/user_api/partition_schemes.py @@ -9,7 +9,10 @@ from eventtracking import tracker import openedx.core.djangoapps.user_api.course_tag.api as course_tag_api -from xmodule.partitions.partitions import NoSuchUserPartitionGroupError, UserPartitionError # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.partitions.partitions import ( # lint-amnesty, pylint: disable=wrong-import-order + NoSuchUserPartitionGroupError, + UserPartitionError, +) log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/user_api/preferences/api.py b/openedx/core/djangoapps/user_api/preferences/api.py index e0a6797ebe25..c70b40c9ba77 100644 --- a/openedx/core/djangoapps/user_api/preferences/api.py +++ b/openedx/core/djangoapps/user_api/preferences/api.py @@ -13,9 +13,9 @@ from django_countries import countries from pytz import common_timezones, common_timezones_set, country_timezones -from openedx.core.lib.time_zone_utils import get_display_time_zone from common.djangoapps.student.models import User, UserProfile from common.djangoapps.track import segment +from openedx.core.lib.time_zone_utils import get_display_time_zone from ..errors import ( # lint-amnesty, pylint: disable=unused-import CountryCodeError, @@ -24,7 +24,7 @@ UserAPIInternalError, UserAPIRequestError, UserNotAuthorized, - UserNotFound + UserNotFound, ) from ..helpers import intercept_errors, serializer_is_dirty from ..models import UserOrgTag, UserPreference diff --git a/openedx/core/djangoapps/user_api/preferences/tests/test_api.py b/openedx/core/djangoapps/user_api/preferences/tests/test_api.py index 34295801801b..80c56824a2ba 100644 --- a/openedx/core/djangoapps/user_api/preferences/tests/test_api.py +++ b/openedx/core/djangoapps/user_api/preferences/tests/test_api.py @@ -5,19 +5,22 @@ import datetime from unittest.mock import patch -import pytest + import ddt +import pytest from dateutil.parser import parse as parse_datetime from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.test.utils import override_settings from django.urls import reverse from pytz import common_timezones, utc -from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms -from openedx.core.lib.time_zone_utils import get_display_time_zone from common.djangoapps.student.models import UserProfile from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms +from openedx.core.lib.time_zone_utils import get_display_time_zone +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ...errors import ( # lint-amnesty, pylint: disable=unused-import @@ -25,7 +28,7 @@ PreferenceUpdateError, PreferenceValidationError, UserNotAuthorized, - UserNotFound + UserNotFound, ) from ...models import UserOrgTag from ...preferences.api import ( @@ -35,7 +38,7 @@ get_user_preferences, set_user_preference, update_email_opt_in, - update_user_preferences + update_user_preferences, ) diff --git a/openedx/core/djangoapps/user_api/preferences/tests/test_views.py b/openedx/core/djangoapps/user_api/preferences/tests/test_views.py index 361c449103df..a554434c3395 100644 --- a/openedx/core/djangoapps/user_api/preferences/tests/test_views.py +++ b/openedx/core/djangoapps/user_api/preferences/tests/test_views.py @@ -11,8 +11,8 @@ from django.urls import reverse from rest_framework.test import APIClient -from openedx.core.djangolib.testing.utils import skip_unless_lms from common.djangoapps.student.tests.factories import TEST_PASSWORD, UserFactory +from openedx.core.djangolib.testing.utils import skip_unless_lms from ...accounts.tests.test_views import UserAPITestCase from ..api import set_user_preference diff --git a/openedx/core/djangoapps/user_api/preferences/views.py b/openedx/core/djangoapps/user_api/preferences/views.py index 6f983a13afe2..6f7cdae47a99 100644 --- a/openedx/core/djangoapps/user_api/preferences/views.py +++ b/openedx/core/djangoapps/user_api/preferences/views.py @@ -24,7 +24,7 @@ get_user_preference, get_user_preferences, set_user_preference, - update_user_preferences + update_user_preferences, ) diff --git a/openedx/core/djangoapps/user_api/serializers.py b/openedx/core/djangoapps/user_api/serializers.py index 437a9a61cf51..e411dd0e1c3a 100644 --- a/openedx/core/djangoapps/user_api/serializers.py +++ b/openedx/core/djangoapps/user_api/serializers.py @@ -6,10 +6,7 @@ from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from rest_framework import serializers -from lms.djangoapps.verify_student.models import ( - ManualVerification, - SoftwareSecurePhotoVerification -) +from lms.djangoapps.verify_student.models import ManualVerification, SoftwareSecurePhotoVerification from .models import UserPreference diff --git a/openedx/core/djangoapps/user_api/tests/factories.py b/openedx/core/djangoapps/user_api/tests/factories.py index 9b6302ae3a1e..12e0cb737b61 100644 --- a/openedx/core/djangoapps/user_api/tests/factories.py +++ b/openedx/core/djangoapps/user_api/tests/factories.py @@ -6,7 +6,6 @@ from opaque_keys.edx.locator import CourseLocator from common.djangoapps.student.tests.factories import UserFactory - from openedx.core.djangoapps.user_api.models import ( RetirementState, UserCourseTag, diff --git a/openedx/core/djangoapps/user_api/tests/test_api.py b/openedx/core/djangoapps/user_api/tests/test_api.py index a929d1b8c643..66e5b1c143e1 100644 --- a/openedx/core/djangoapps/user_api/tests/test_api.py +++ b/openedx/core/djangoapps/user_api/tests/test_api.py @@ -7,11 +7,7 @@ from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.user_api.api import get_retired_user_ids -from openedx.core.djangoapps.user_api.models import ( - RetirementState, - UserRetirementRequest, - UserRetirementStatus, -) +from openedx.core.djangoapps.user_api.models import RetirementState, UserRetirementRequest, UserRetirementStatus from openedx.core.djangoapps.user_api.tests.factories import ( RetirementStateFactory, UserRetirementRequestFactory, diff --git a/openedx/core/djangoapps/user_api/tests/test_middleware.py b/openedx/core/djangoapps/user_api/tests/test_middleware.py index 04b5b4104971..071c1adfdf7d 100644 --- a/openedx/core/djangoapps/user_api/tests/test_middleware.py +++ b/openedx/core/djangoapps/user_api/tests/test_middleware.py @@ -2,6 +2,7 @@ from unittest.mock import Mock, patch + from django.http import HttpResponse from django.test import TestCase from django.test.client import RequestFactory diff --git a/openedx/core/djangoapps/user_api/tests/test_models.py b/openedx/core/djangoapps/user_api/tests/test_models.py index dfa84bd50d91..6a1c70f0452c 100644 --- a/openedx/core/djangoapps/user_api/tests/test_models.py +++ b/openedx/core/djangoapps/user_api/tests/test_models.py @@ -8,7 +8,9 @@ from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.student.tests.tests import UserSettingsEventTestMixin -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..models import UserOrgTag, UserPreference diff --git a/openedx/core/djangoapps/user_api/tests/test_partition_schemes.py b/openedx/core/djangoapps/user_api/tests/test_partition_schemes.py index afa6ab7939db..979a8e4d10a7 100644 --- a/openedx/core/djangoapps/user_api/tests/test_partition_schemes.py +++ b/openedx/core/djangoapps/user_api/tests/test_partition_schemes.py @@ -9,10 +9,12 @@ import pytest from django.test import TestCase -from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme, UserPartitionError from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme, UserPartitionError from xmodule.partitions.partitions import Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.tests.test_partitions import PartitionTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.partitions.tests.test_partitions import ( + PartitionTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) class MemoryCourseTagAPI: diff --git a/openedx/core/djangoapps/user_api/tests/test_views.py b/openedx/core/djangoapps/user_api/tests/test_views.py index 446ade442c1d..a6eec77d8bf3 100644 --- a/openedx/core/djangoapps/user_api/tests/test_views.py +++ b/openedx/core/djangoapps/user_api/tests/test_views.py @@ -1,18 +1,20 @@ """Tests for the user API at the HTTP request level. """ -import pytest import ddt +import pytest from django.test.utils import override_settings from django.urls import reverse from opaque_keys.edx.keys import CourseKey -from pytz import common_timezones_set, common_timezones, country_timezones +from pytz import common_timezones, common_timezones_set, country_timezones +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.django_comment_common import models from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms from openedx.core.lib.api.test_utils import TEST_API_KEY, ApiTestCase from openedx.core.lib.time_zone_utils import get_display_time_zone -from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..accounts.tests.retirement_helpers import ( # pylint: disable=unused-import diff --git a/openedx/core/djangoapps/user_api/urls.py b/openedx/core/djangoapps/user_api/urls.py index b4bf1b3b2bbe..5928a1d4f422 100644 --- a/openedx/core/djangoapps/user_api/urls.py +++ b/openedx/core/djangoapps/user_api/urls.py @@ -8,24 +8,22 @@ from rest_framework import routers from ..profile_images.views import ProfileImageView +from . import views as user_api_views from .accounts.views import ( AccountDeactivationView, AccountRetirementPartnerReportView, AccountRetirementStatusView, AccountRetirementView, AccountViewSet, + CancelAccountRetirementStatusView, DeactivateLogoutView, LMSAccountRetirementView, NameChangeView, - UsernameReplacementView, CancelAccountRetirementStatusView + UsernameReplacementView, ) -from . import views as user_api_views from .models import UserPreference from .preferences.views import PreferencesDetailView, PreferencesView -from .verification_api.views import ( - IDVerificationStatusView, - IDVerificationStatusDetailsView, -) +from .verification_api.views import IDVerificationStatusDetailsView, IDVerificationStatusView ME = AccountViewSet.as_view({ 'get': 'get', diff --git a/openedx/core/djangoapps/user_authn/api/form_fields.py b/openedx/core/djangoapps/user_authn/api/form_fields.py index ca001ba3f1b5..f700a2298091 100644 --- a/openedx/core/djangoapps/user_authn/api/form_fields.py +++ b/openedx/core/djangoapps/user_authn/api/form_fields.py @@ -2,6 +2,7 @@ Field Descriptions """ import logging + from django import forms from django.conf import settings from django.utils.translation import gettext as _ diff --git a/openedx/core/djangoapps/user_authn/api/helper.py b/openedx/core/djangoapps/user_authn/api/helper.py index 21bd7c278d70..156b964db7a6 100644 --- a/openedx/core/djangoapps/user_authn/api/helper.py +++ b/openedx/core/djangoapps/user_authn/api/helper.py @@ -6,10 +6,10 @@ from django.conf import settings from rest_framework.views import APIView +from common.djangoapps.student.models import UserProfile from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.user_authn.api import form_fields from openedx.core.djangoapps.user_authn.views.registration_form import get_registration_extension_form -from common.djangoapps.student.models import UserProfile class RegistrationFieldsContext(APIView): diff --git a/openedx/core/djangoapps/user_authn/api/tests/test_views.py b/openedx/core/djangoapps/user_authn/api/tests/test_views.py index d6720c46fc58..78db3d81de1c 100644 --- a/openedx/core/djangoapps/user_authn/api/tests/test_views.py +++ b/openedx/core/djangoapps/user_authn/api/tests/test_views.py @@ -1,15 +1,16 @@ """ Logistration API View Tests """ -import ddt import socket +from unittest.mock import patch +from urllib.parse import urlencode + +import ddt from django.conf import settings from django.test.utils import override_settings from django.urls import reverse from rest_framework import status from rest_framework.test import APITestCase -from unittest.mock import patch -from urllib.parse import urlencode from common.djangoapps.student.models import Registration from common.djangoapps.student.tests.factories import UserFactory diff --git a/openedx/core/djangoapps/user_authn/api/urls.py b/openedx/core/djangoapps/user_authn/api/urls.py index 212249d1c8b3..32782b9704bc 100644 --- a/openedx/core/djangoapps/user_authn/api/urls.py +++ b/openedx/core/djangoapps/user_authn/api/urls.py @@ -2,10 +2,9 @@ Authn API urls """ from django.urls import path -from openedx.core.djangoapps.user_authn.api.views import ( - MFEContextView, - SendAccountActivationEmail, -) + +from openedx.core.djangoapps.user_authn.api.views import MFEContextView, SendAccountActivationEmail + urlpatterns = [ path('third_party_auth_context', MFEContextView.as_view(), name='third_party_auth_context'), path('mfe_context', MFEContextView.as_view(), name='mfe_context'), diff --git a/openedx/core/djangoapps/user_authn/api/views.py b/openedx/core/djangoapps/user_authn/api/views.py index f5811412232b..3499512f8ec5 100644 --- a/openedx/core/djangoapps/user_authn/api/views.py +++ b/openedx/core/djangoapps/user_authn/api/views.py @@ -3,13 +3,12 @@ """ from django.conf import settings - +from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser from rest_framework import status +from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.throttling import AnonRateThrottle from rest_framework.views import APIView -from rest_framework.permissions import IsAuthenticated -from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser from common.djangoapps.student.helpers import get_next_url_for_login_page from common.djangoapps.student.views import compose_and_send_activation_email diff --git a/openedx/core/djangoapps/user_authn/cookies.py b/openedx/core/djangoapps/user_authn/cookies.py index ac050ea68730..f6db33181619 100644 --- a/openedx/core/djangoapps/user_authn/cookies.py +++ b/openedx/core/djangoapps/user_authn/cookies.py @@ -16,17 +16,16 @@ from edx_rest_framework_extensions.auth.jwt import cookies as jwt_cookies from edx_rest_framework_extensions.auth.jwt.constants import JWT_DELIMITER from oauth2_provider.models import Application -from common.djangoapps.student.models import UserProfile +from common.djangoapps.student.models import UserProfile +from common.djangoapps.util.json_request import JsonResponse from openedx.core.djangoapps.oauth_dispatch.adapters import DOTAdapter from openedx.core.djangoapps.oauth_dispatch.api import create_dot_access_token from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_from_token -from openedx.core.djangoapps.user_api.accounts.utils import retrieve_last_sitewide_block_completed -from openedx.core.djangoapps.user_authn.exceptions import AuthFailedError from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers -from common.djangoapps.util.json_request import JsonResponse from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_image_urls_for_user - +from openedx.core.djangoapps.user_api.accounts.utils import retrieve_last_sitewide_block_completed +from openedx.core.djangoapps.user_authn.exceptions import AuthFailedError log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/user_authn/tests/test_cookies.py b/openedx/core/djangoapps/user_authn/tests/test_cookies.py index e39faf384b10..3e0a88a88728 100644 --- a/openedx/core/djangoapps/user_authn/tests/test_cookies.py +++ b/openedx/core/djangoapps/user_authn/tests/test_cookies.py @@ -1,28 +1,30 @@ # pylint: disable=missing-docstring -from datetime import date, datetime import json -from pytz import UTC +from datetime import date, datetime from unittest.mock import MagicMock, patch from urllib.parse import urljoin + from django.conf import settings from django.http import HttpResponse from django.test import RequestFactory, TestCase, override_settings from django.urls import reverse from edx_rest_framework_extensions.auth.jwt.decoder import jwt_decode_handler from edx_rest_framework_extensions.auth.jwt.middleware import JwtAuthCookieMiddleware +from pytz import UTC +from common.djangoapps.student.tests.factories import AnonymousUserFactory, UserFactory, UserProfileFactory +from openedx.core.djangoapps.profile_images.images import create_profile_images +from openedx.core.djangoapps.profile_images.tests.helpers import make_image_file +from openedx.core.djangoapps.user_api.accounts.image_helpers import ( + get_profile_image_names, + get_profile_image_urls_for_user, +) from openedx.core.djangoapps.user_api.accounts.utils import retrieve_last_sitewide_block_completed from openedx.core.djangoapps.user_authn import cookies as cookies_api from openedx.core.djangoapps.user_authn.tests.utils import setup_login_oauth_client from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.tests.factories import AnonymousUserFactory, UserFactory, UserProfileFactory -from openedx.core.djangoapps.profile_images.tests.helpers import make_image_file -from openedx.core.djangoapps.profile_images.images import create_profile_images -from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_image_names -from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_image_urls_for_user - TEST_PROFILE_IMAGE_UPLOAD_DT = datetime(2002, 1, 9, 15, 43, 1, tzinfo=UTC) diff --git a/openedx/core/djangoapps/user_authn/tests/test_signals.py b/openedx/core/djangoapps/user_authn/tests/test_signals.py index e87ffc55847e..8e03a57f477c 100644 --- a/openedx/core/djangoapps/user_authn/tests/test_signals.py +++ b/openedx/core/djangoapps/user_authn/tests/test_signals.py @@ -1,6 +1,7 @@ """Tests for user_authn signals""" from unittest.mock import patch + from django.test import TestCase from common.djangoapps.student.tests.factories import UserFactory, UserProfileFactory diff --git a/openedx/core/djangoapps/user_authn/tests/test_tasks.py b/openedx/core/djangoapps/user_authn/tests/test_tasks.py index 5103343a0879..d2cd13f8d563 100644 --- a/openedx/core/djangoapps/user_authn/tests/test_tasks.py +++ b/openedx/core/djangoapps/user_authn/tests/test_tasks.py @@ -3,10 +3,11 @@ """ +from unittest import mock # lint-amnesty, pylint: disable=wrong-import-order + from django.conf import settings from django.test import TestCase from edx_ace.errors import ChannelError, RecoverableChannelDeliveryError -from unittest import mock # lint-amnesty, pylint: disable=wrong-import-order from common.djangoapps.student.models import Registration from common.djangoapps.student.views.management import compose_activation_email, compose_and_send_activation_email diff --git a/openedx/core/djangoapps/user_authn/tests/test_utils.py b/openedx/core/djangoapps/user_authn/tests/test_utils.py index 34578a661df9..377c75b1b905 100644 --- a/openedx/core/djangoapps/user_authn/tests/test_utils.py +++ b/openedx/core/djangoapps/user_authn/tests/test_utils.py @@ -3,6 +3,7 @@ from collections import namedtuple from urllib.parse import urlencode # pylint: disable=import-error + import ddt from django.test import TestCase from django.test.client import RequestFactory @@ -10,8 +11,8 @@ from openedx.core.djangoapps.oauth_dispatch.tests.factories import ApplicationFactory from openedx.core.djangoapps.user_authn.utils import ( - is_safe_login_or_logout_redirect, generate_username_suggestions, + is_safe_login_or_logout_redirect, remove_special_characters_from_name, ) diff --git a/openedx/core/djangoapps/user_authn/tests/utils.py b/openedx/core/djangoapps/user_authn/tests/utils.py index 31b4be7c400a..c387e9cde2c4 100644 --- a/openedx/core/djangoapps/user_authn/tests/utils.py +++ b/openedx/core/djangoapps/user_authn/tests/utils.py @@ -4,16 +4,16 @@ from datetime import datetime, timedelta from enum import Enum from unittest.mock import patch +from zoneinfo import ZoneInfo import ddt -from zoneinfo import ZoneInfo from django.conf import settings from oauth2_provider import models as dot_models from rest_framework import status +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.oauth_dispatch.adapters.dot import DOTAdapter from openedx.core.djangoapps.oauth_dispatch.jwt import _create_jwt -from common.djangoapps.student.tests.factories import UserFactory class AuthType(Enum): diff --git a/openedx/core/djangoapps/user_authn/views/auth.py b/openedx/core/djangoapps/user_authn/views/auth.py index 673b2230ddeb..09768950d040 100644 --- a/openedx/core/djangoapps/user_authn/views/auth.py +++ b/openedx/core/djangoapps/user_authn/views/auth.py @@ -1,9 +1,11 @@ """ Views related to auth. """ import json -from common.djangoapps.util.json_request import JsonResponse + from django.conf import settings +from common.djangoapps.util.json_request import JsonResponse + def get_public_signing_jwks(request): """ diff --git a/openedx/core/djangoapps/user_authn/views/auto_auth.py b/openedx/core/djangoapps/user_authn/views/auto_auth.py index 324a0c1959d4..6cd81638c9c7 100644 --- a/openedx/core/djangoapps/user_authn/views/auto_auth.py +++ b/openedx/core/djangoapps/user_authn/views/auto_auth.py @@ -14,17 +14,14 @@ from django.template.context_processors import csrf from django.urls import NoReverseMatch, reverse from django.utils.translation import gettext as _ +from edx_django_utils.user import generate_password # lint-amnesty, pylint: disable=wrong-import-order from opaque_keys.edx.locator import CourseLocator -from lms.djangoapps.verify_student.models import ManualVerification -from openedx.core.djangoapps.django_comment_common.models import assign_role -from openedx.core.djangoapps.user_authn.views.registration_form import AccountCreationForm -from openedx.features.course_experience import course_home_url from common.djangoapps.student.helpers import ( AccountValidationError, authenticate_new_user, create_or_set_user_attribute_created_on_site, - do_create_account + do_create_account, ) from common.djangoapps.student.models import ( CourseAccessRole, @@ -32,11 +29,13 @@ Registration, UserProfile, anonymous_id_for_user, - create_comments_service_user + create_comments_service_user, ) from common.djangoapps.util.json_request import JsonResponse - -from edx_django_utils.user import generate_password # lint-amnesty, pylint: disable=wrong-import-order +from lms.djangoapps.verify_student.models import ManualVerification +from openedx.core.djangoapps.django_comment_common.models import assign_role +from openedx.core.djangoapps.user_authn.views.registration_form import AccountCreationForm +from openedx.features.course_experience import course_home_url def auto_auth(request): # pylint: disable=too-many-statements diff --git a/openedx/core/djangoapps/user_authn/views/login_form.py b/openedx/core/djangoapps/user_authn/views/login_form.py index bb78a9df1a3c..ac3788cb1ad7 100644 --- a/openedx/core/djangoapps/user_authn/views/login_form.py +++ b/openedx/core/djangoapps/user_authn/views/login_form.py @@ -16,28 +16,28 @@ from common.djangoapps import third_party_auth from common.djangoapps.edxmako.shortcuts import render_to_response +from common.djangoapps.student.helpers import get_next_url_for_login_page +from common.djangoapps.third_party_auth import pipeline +from common.djangoapps.third_party_auth.decorators import xframe_allow_whitelisted +from common.djangoapps.util.password_policy_validators import DEFAULT_MAX_PASSWORD_LENGTH from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.user_api import accounts -from openedx.core.djangoapps.user_api.accounts.utils import ( - is_secondary_email_feature_enabled -) +from openedx.core.djangoapps.user_api.accounts.utils import is_secondary_email_feature_enabled from openedx.core.djangoapps.user_api.helpers import FormDescription from openedx.core.djangoapps.user_authn.cookies import set_logged_in_cookies -from openedx.core.djangoapps.user_authn.toggles import should_redirect_to_authn_microfrontend +from openedx.core.djangoapps.user_authn.toggles import ( + is_require_third_party_auth_enabled, + should_redirect_to_authn_microfrontend, +) from openedx.core.djangoapps.user_authn.views.password_reset import get_password_reset_form from openedx.core.djangoapps.user_authn.views.registration_form import RegistrationFormFactory from openedx.core.djangoapps.user_authn.views.utils import third_party_auth_context -from openedx.core.djangoapps.user_authn.toggles import is_require_third_party_auth_enabled from openedx.features.enterprise_support.api import enterprise_customer_for_request, enterprise_enabled from openedx.features.enterprise_support.utils import ( get_enterprise_slug_login_url, handle_enterprise_cookies_for_logistration, - update_logistration_context_for_enterprise + update_logistration_context_for_enterprise, ) -from common.djangoapps.student.helpers import get_next_url_for_login_page -from common.djangoapps.third_party_auth import pipeline -from common.djangoapps.third_party_auth.decorators import xframe_allow_whitelisted -from common.djangoapps.util.password_policy_validators import DEFAULT_MAX_PASSWORD_LENGTH log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/user_authn/views/logout.py b/openedx/core/djangoapps/user_authn/views/logout.py index 083e8d4ccb0d..20cc70287142 100644 --- a/openedx/core/djangoapps/user_authn/views/logout.py +++ b/openedx/core/djangoapps/user_authn/views/logout.py @@ -12,10 +12,10 @@ from django.views.generic import TemplateView from oauth2_provider.models import Application +from common.djangoapps.third_party_auth import pipeline as tpa_pipeline from openedx.core.djangoapps.safe_sessions.middleware import mark_user_change_as_expected from openedx.core.djangoapps.user_authn.cookies import delete_logged_in_cookies from openedx.core.djangoapps.user_authn.utils import is_safe_login_or_logout_redirect -from common.djangoapps.third_party_auth import pipeline as tpa_pipeline class LogoutView(TemplateView): diff --git a/openedx/core/djangoapps/user_authn/views/password_reset.py b/openedx/core/djangoapps/user_authn/views/password_reset.py index 321101fb9a18..1fb72c0e2928 100644 --- a/openedx/core/djangoapps/user_authn/views/password_reset.py +++ b/openedx/core/djangoapps/user_authn/views/password_reset.py @@ -21,33 +21,33 @@ from django.utils.translation import gettext_lazy as _ from django.views.decorators.csrf import csrf_exempt, ensure_csrf_cookie from django.views.decorators.http import require_POST +from django_ratelimit.decorators import ratelimit from edx_ace import ace from edx_ace.recipient import Recipient from eventtracking import tracker -from django_ratelimit.decorators import ratelimit from rest_framework.response import Response from rest_framework.throttling import AnonRateThrottle from rest_framework.views import APIView from common.djangoapps.edxmako.shortcuts import render_to_string +from common.djangoapps.student.forms import send_account_recovery_email_for_user +from common.djangoapps.student.models import AccountRecovery, LoginFailures +from common.djangoapps.util.json_request import JsonResponse +from common.djangoapps.util.password_policy_validators import normalize_password, validate_password from openedx.core.djangoapps.ace_common.template_context import get_base_template_context from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY from openedx.core.djangoapps.oauth_dispatch.api import destroy_oauth_tokens from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.theming.helpers import get_current_request, get_current_site from openedx.core.djangoapps.user_api import accounts, errors, helpers -from openedx.core.djangoapps.user_authn.toggles import should_redirect_to_authn_microfrontend from openedx.core.djangoapps.user_api.accounts.utils import is_secondary_email_feature_enabled from openedx.core.djangoapps.user_api.helpers import FormDescription from openedx.core.djangoapps.user_api.models import UserRetirementRequest from openedx.core.djangoapps.user_api.preferences.api import get_user_preference from openedx.core.djangoapps.user_authn.message_types import PasswordReset, PasswordResetSuccess +from openedx.core.djangoapps.user_authn.toggles import should_redirect_to_authn_microfrontend from openedx.core.djangoapps.user_authn.utils import check_pwned_password from openedx.core.djangolib.markup import HTML -from common.djangoapps.student.forms import send_account_recovery_email_for_user -from common.djangoapps.student.models import AccountRecovery, LoginFailures -from common.djangoapps.util.json_request import JsonResponse -from common.djangoapps.util.password_policy_validators import normalize_password, validate_password POST_EMAIL_KEY = 'openedx.core.djangoapps.util.ratelimit.request_post_email' REAL_IP_KEY = 'openedx.core.djangoapps.util.ratelimit.real_ip' diff --git a/openedx/core/djangoapps/user_authn/views/register.py b/openedx/core/djangoapps/user_authn/views/register.py index 2fc0818a3ab9..38f470c5ae0f 100644 --- a/openedx/core/djangoapps/user_authn/views/register.py +++ b/openedx/core/djangoapps/user_authn/views/register.py @@ -6,6 +6,7 @@ import datetime import json import logging +from zoneinfo import ZoneInfo from django.conf import settings from django.contrib.auth import login as django_login @@ -22,12 +23,12 @@ from django.views.decorators.csrf import csrf_exempt, ensure_csrf_cookie from django.views.decorators.debug import sensitive_post_parameters from django_countries import countries +from django_ratelimit.decorators import ratelimit from edx_django_utils.monitoring import set_custom_attribute +from edx_django_utils.user import generate_password # lint-amnesty, pylint: disable=wrong-import-order from openedx_events.learning.data import UserData, UserPersonalData from openedx_events.learning.signals import STUDENT_REGISTRATION_COMPLETED from openedx_filters.learning.filters import StudentRegistrationRequested -from zoneinfo import ZoneInfo -from django_ratelimit.decorators import ratelimit from requests import HTTPError from rest_framework.response import Response from rest_framework.views import APIView @@ -35,9 +36,30 @@ from social_django import utils as social_utils from common.djangoapps import third_party_auth + # Note that this lives in LMS, so this dependency should be refactored. # TODO Have the discussions code subscribe to the REGISTER_USER signal instead. -from common.djangoapps.student.helpers import get_next_url_for_login_page, get_redirect_url_with_host +from common.djangoapps.student.helpers import ( + AccountValidationError, + authenticate_new_user, + create_or_set_user_attribute_created_on_site, + do_create_account, + get_next_url_for_login_page, + get_redirect_url_with_host, +) +from common.djangoapps.student.models import ( + RegistrationCookieConfiguration, + UserAttribute, + create_comments_service_user, + email_exists_or_retired, + username_exists_or_retired, +) +from common.djangoapps.student.views import compose_and_send_activation_email +from common.djangoapps.third_party_auth import pipeline, provider +from common.djangoapps.third_party_auth.saml import SAP_SUCCESSFACTORS_SAML_KEY +from common.djangoapps.track import segment +from common.djangoapps.util.db import outer_atomic +from common.djangoapps.util.json_request import JsonResponse from lms.djangoapps.discussion.notification_prefs.views import enable_notifications from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY from openedx.core.djangoapps.safe_sessions.middleware import mark_user_change_as_expected @@ -51,45 +73,22 @@ get_name_validation_error, get_password_validation_error, get_username_existence_validation_error, - get_username_validation_error + get_username_validation_error, ) from openedx.core.djangoapps.user_api.preferences import api as preferences_api from openedx.core.djangoapps.user_authn.cookies import set_logged_in_cookies -from openedx.core.djangoapps.user_authn.utils import ( - generate_username_suggestions, is_registration_api_v1 +from openedx.core.djangoapps.user_authn.tasks import check_pwned_password_and_send_track_event +from openedx.core.djangoapps.user_authn.toggles import ( + is_auto_generated_username_enabled, + is_require_third_party_auth_enabled, ) +from openedx.core.djangoapps.user_authn.utils import generate_username_suggestions, is_registration_api_v1 from openedx.core.djangoapps.user_authn.views.registration_form import ( AccountCreationForm, RegistrationFormFactory, - get_registration_extension_form + get_registration_extension_form, ) from openedx.core.djangoapps.user_authn.views.utils import get_auto_generated_username -from openedx.core.djangoapps.user_authn.tasks import check_pwned_password_and_send_track_event -from openedx.core.djangoapps.user_authn.toggles import ( - is_require_third_party_auth_enabled, - is_auto_generated_username_enabled -) -from common.djangoapps.student.helpers import ( - AccountValidationError, - authenticate_new_user, - create_or_set_user_attribute_created_on_site, - do_create_account -) -from common.djangoapps.student.models import ( - RegistrationCookieConfiguration, - UserAttribute, - create_comments_service_user, - email_exists_or_retired, - username_exists_or_retired -) -from common.djangoapps.student.views import compose_and_send_activation_email -from common.djangoapps.third_party_auth import pipeline, provider -from common.djangoapps.third_party_auth.saml import SAP_SUCCESSFACTORS_SAML_KEY -from common.djangoapps.track import segment -from common.djangoapps.util.db import outer_atomic -from common.djangoapps.util.json_request import JsonResponse - -from edx_django_utils.user import generate_password # lint-amnesty, pylint: disable=wrong-import-order log = logging.getLogger("edx.student") AUDIT_LOG = logging.getLogger("audit") diff --git a/openedx/core/djangoapps/user_authn/views/registration_form.py b/openedx/core/djangoapps/user_authn/views/registration_form.py index 338c6889fe72..114da4ef61b8 100644 --- a/openedx/core/djangoapps/user_authn/views/registration_form.py +++ b/openedx/core/djangoapps/user_authn/views/registration_form.py @@ -19,13 +19,13 @@ from eventtracking import tracker from common.djangoapps import third_party_auth -from common.djangoapps.third_party_auth.models import SAMLProviderConfig from common.djangoapps.edxmako.shortcuts import marketing_link from common.djangoapps.student.models import CourseEnrollmentAllowed, UserProfile, email_exists_or_retired +from common.djangoapps.third_party_auth.models import SAMLProviderConfig from common.djangoapps.util.password_policy_validators import ( password_validators_instruction_texts, password_validators_restrictions, - validate_password + validate_password, ) from openedx.core.djangoapps.embargo.models import GlobalRestrictedCountry from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers @@ -37,7 +37,6 @@ from openedx.core.djangolib.markup import HTML, Text from openedx.features.enterprise_support.api import enterprise_customer_for_request - log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_auth.py b/openedx/core/djangoapps/user_authn/views/tests/test_auth.py index 7ca8bc96fbaf..29a0c709d1bf 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_auth.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_auth.py @@ -2,11 +2,13 @@ import json -from django.test import TestCase +from unittest import mock + from django.conf import settings +from django.test import TestCase from django.urls import reverse + from openedx.core.djangolib.testing.utils import skip_unless_lms -from unittest import mock @skip_unless_lms diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py b/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py index b68774903092..7191232cc6a9 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py @@ -13,15 +13,17 @@ from common.djangoapps.student.models import CourseAccessRole, CourseEnrollment, UserProfile, anonymous_id_for_user from common.djangoapps.util.testing import UrlResetMixin +from common.test.utils import assert_dict_contains_subset from openedx.core.djangoapps.django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_STUDENT, - Role + Role, ) from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from common.test.utils import assert_dict_contains_subset +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) class AutoAuthTestCase(UrlResetMixin, TestCase): diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_events.py b/openedx/core/djangoapps/user_authn/views/tests/test_events.py index 7efd4e4cf5c0..5393a24adccc 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_events.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_events.py @@ -16,9 +16,9 @@ from openedx_events.tests.utils import OpenEdxEventsTestMixin from common.djangoapps.student.tests.factories import UserFactory, UserProfileFactory +from common.test.utils import assert_dict_contains_subset from openedx.core.djangoapps.user_api.tests.test_views import UserAPITestCase from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.test.utils import assert_dict_contains_subset @skip_unless_lms diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_login.py b/openedx/core/djangoapps/user_authn/views/tests/test_login.py index c8bfa082900b..8397d03a8914 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_login.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_login.py @@ -21,30 +21,30 @@ from django.urls import NoReverseMatch, reverse from edx_toggles.toggles.testutils import override_waffle_switch from freezegun import freeze_time -from common.djangoapps.student.tests.factories import RegistrationFactory, UserFactory, UserProfileFactory from openedx_events.tests.utils import OpenEdxEventsTestMixin # lint-amnesty, pylint: disable=wrong-import-order +from common.djangoapps.student.models import LoginFailures +from common.djangoapps.student.tests.factories import RegistrationFactory, UserFactory, UserProfileFactory +from common.djangoapps.util.password_policy_validators import DEFAULT_MAX_PASSWORD_LENGTH +from common.test.utils import assert_dict_contains_subset from openedx.core.djangoapps.password_policy.compliance import ( NonCompliantPasswordException, - NonCompliantPasswordWarning + NonCompliantPasswordWarning, ) from openedx.core.djangoapps.password_policy.hibp import PwnedPasswordsAPI -from openedx.core.djangoapps.user_api.accounts import EMAIL_MIN_LENGTH, EMAIL_MAX_LENGTH +from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin +from openedx.core.djangoapps.user_api.accounts import EMAIL_MAX_LENGTH, EMAIL_MIN_LENGTH from openedx.core.djangoapps.user_authn.config.waffle import ENABLE_PWNED_PASSWORD_API from openedx.core.djangoapps.user_authn.cookies import jwt_cookies from openedx.core.djangoapps.user_authn.tests.utils import setup_login_oauth_client from openedx.core.djangoapps.user_authn.views.login import ( ENABLE_LOGIN_USING_THIRDPARTY_AUTH_ONLY, AllowedAuthUser, - _check_user_auth_flow + _check_user_auth_flow, ) from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms -from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin from openedx.core.lib.api.test_utils import ApiTestCase from openedx.features.enterprise_support.tests.factories import EnterpriseCustomerUserFactory -from common.djangoapps.student.models import LoginFailures -from common.djangoapps.util.password_policy_validators import DEFAULT_MAX_PASSWORD_LENGTH -from common.test.utils import assert_dict_contains_subset @ddt.ddt diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_logistration.py b/openedx/core/djangoapps/user_authn/views/tests/test_logistration.py index 3f67191ae982..9dcc21a84aa1 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_logistration.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_logistration.py @@ -2,8 +2,8 @@ from http.cookies import SimpleCookie -from urllib.parse import urlencode from unittest import mock +from urllib.parse import urlencode import ddt from django.conf import settings @@ -19,6 +19,8 @@ from django.utils.translation import gettext as _ from common.djangoapps.course_modes.models import CourseMode +from common.djangoapps.third_party_auth.tests.testutil import ThirdPartyAuthTestMixin, simulate_running_pipeline +from common.djangoapps.util.testing import UrlResetMixin from lms.djangoapps.branding.api import get_privacy_url from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme_context @@ -28,9 +30,9 @@ from openedx.core.djangolib.js_utils import dump_js_escaped_json from openedx.core.djangolib.markup import HTML, Text from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.third_party_auth.tests.testutil import ThirdPartyAuthTestMixin, simulate_running_pipeline -from common.djangoapps.util.testing import UrlResetMixin -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) @skip_unless_lms diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_logout.py b/openedx/core/djangoapps/user_authn/views/tests/test_logout.py index a81d11c42cf4..e29a8d6e292b 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_logout.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_logout.py @@ -4,6 +4,7 @@ import urllib from unittest import mock + import ddt import nh3 from django.conf import settings @@ -11,10 +12,10 @@ from django.test.utils import override_settings from django.urls import reverse -from openedx.core.djangoapps.oauth_dispatch.tests.factories import ApplicationFactory -from openedx.core.djangolib.testing.utils import skip_unless_lms from common.djangoapps.student.tests.factories import UserFactory from common.test.utils import assert_dict_contains_subset +from openedx.core.djangoapps.oauth_dispatch.tests.factories import ApplicationFactory +from openedx.core.djangolib.testing.utils import skip_unless_lms @skip_unless_lms diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_password.py b/openedx/core/djangoapps/user_authn/views/tests/test_password.py index 57a988c0b354..930be723c406 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_password.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_password.py @@ -6,9 +6,10 @@ import re from datetime import datetime, timedelta from unittest.mock import Mock, patch +from zoneinfo import ZoneInfo -import pytest import ddt +import pytest from django.conf import settings from django.contrib.auth import get_user_model from django.core import mail @@ -19,16 +20,15 @@ from freezegun import freeze_time from oauth2_provider.models import AccessToken as dot_access_token from oauth2_provider.models import RefreshToken as dot_refresh_token -from zoneinfo import ZoneInfo from testfixtures import LogCapture +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.oauth_dispatch.tests import factories as dot_factories from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory from openedx.core.djangoapps.user_api.accounts.tests.test_api import CreateAccountMixin from openedx.core.djangoapps.user_api.errors import UserAPIInternalError, UserNotFound from openedx.core.djangoapps.user_authn.views.password_reset import request_password_change from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms -from common.djangoapps.student.tests.factories import UserFactory LOGGER_NAME = 'audit' User = get_user_model() # pylint:disable=invalid-name diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_register.py b/openedx/core/djangoapps/user_authn/views/tests/test_register.py index e79b8ae6daa2..039090a0bdb4 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_register.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_register.py @@ -4,6 +4,7 @@ from datetime import datetime from unittest import mock, skipIf, skipUnless from unittest.mock import patch +from zoneinfo import ZoneInfo import ddt import httpretty @@ -16,7 +17,6 @@ from django.test.utils import override_settings from django.urls import reverse from openedx_events.tests.utils import OpenEdxEventsTestMixin -from zoneinfo import ZoneInfo from social_django.models import Partial, UserSocialAuth from testfixtures import LogCapture @@ -26,13 +26,13 @@ from common.djangoapps.third_party_auth.tests.utils import ( ThirdPartyOAuthTestMixin, ThirdPartyOAuthTestMixinFacebook, - ThirdPartyOAuthTestMixinGoogle + ThirdPartyOAuthTestMixinGoogle, ) from common.djangoapps.util.password_policy_validators import ( DEFAULT_MAX_PASSWORD_LENGTH, create_validator_config, password_validators_instruction_texts, - password_validators_restrictions + password_validators_restrictions, ) from openedx.core.djangoapps.embargo.models import Country, GlobalRestrictedCountry from openedx.core.djangoapps.site_configuration.helpers import get_value @@ -52,14 +52,14 @@ USERNAME_INVALID_CHARS_ASCII, USERNAME_INVALID_CHARS_UNICODE, USERNAME_MAX_LENGTH, - USERNAME_MIN_LENGTH + USERNAME_MIN_LENGTH, ) from openedx.core.djangoapps.user_api.accounts.api import get_account_settings from openedx.core.djangoapps.user_api.accounts.tests import testutils from openedx.core.djangoapps.user_api.accounts.tests.retirement_helpers import ( # pylint: disable=unused-import RetirementTestCase, fake_requested_retirement, - setup_retirement_states + setup_retirement_states, ) from openedx.core.djangoapps.user_api.tests.test_constants import SORTED_COUNTRIES from openedx.core.djangoapps.user_api.tests.test_helpers import TestCaseForm diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_reset_password.py b/openedx/core/djangoapps/user_authn/views/tests/test_reset_password.py index aed040a8a21c..19b03959ce65 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_reset_password.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_reset_password.py @@ -7,6 +7,7 @@ import unicodedata from datetime import datetime, timedelta from unittest.mock import Mock, patch +from zoneinfo import ZoneInfo import ddt from django.conf import settings @@ -24,25 +25,27 @@ from django.utils.http import int_to_base36 from freezegun import freeze_time from oauth2_provider import models as dot_models -from zoneinfo import ZoneInfo -from openedx.core.djangoapps.oauth_dispatch.tests import factories as dot_factories -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers -from openedx.core.djangolib.testing.utils import skip_unless_lms -from openedx.core.djangoapps.user_api.models import UserRetirementRequest -from openedx.core.djangoapps.user_api.tests.test_views import UserAPITestCase -from openedx.core.djangoapps.user_api.accounts import EMAIL_MAX_LENGTH, EMAIL_MIN_LENGTH -from openedx.core.djangoapps.user_authn.views.password_reset import ( - SETTING_CHANGE_INITIATED, PASSWORD_RESET_INITIATED, password_reset, LogistrationPasswordResetView, - PasswordResetConfirmWrapper, password_change_request_handler) -from openedx.core.djangolib.testing.utils import CacheIsolationTestCase +from common.djangoapps.student.models import AccountRecovery, LoginFailures from common.djangoapps.student.tests.factories import TEST_PASSWORD, UserFactory from common.djangoapps.student.tests.test_configuration_overrides import fake_get_value from common.djangoapps.student.tests.test_email import mock_render_to_string -from common.djangoapps.student.models import AccountRecovery, LoginFailures - from common.djangoapps.util.password_policy_validators import create_validator_config from common.djangoapps.util.testing import EventTestMixin +from openedx.core.djangoapps.oauth_dispatch.tests import factories as dot_factories +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.djangoapps.user_api.accounts import EMAIL_MAX_LENGTH, EMAIL_MIN_LENGTH +from openedx.core.djangoapps.user_api.models import UserRetirementRequest +from openedx.core.djangoapps.user_api.tests.test_views import UserAPITestCase +from openedx.core.djangoapps.user_authn.views.password_reset import ( + PASSWORD_RESET_INITIATED, + SETTING_CHANGE_INITIATED, + LogistrationPasswordResetView, + PasswordResetConfirmWrapper, + password_change_request_handler, + password_reset, +) +from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms ENABLE_AUTHN_MICROFRONTEND = settings.FEATURES.copy() ENABLE_AUTHN_MICROFRONTEND['ENABLE_AUTHN_MICROFRONTEND'] = True diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_saml_optional_checkboxes.py b/openedx/core/djangoapps/user_authn/views/tests/test_saml_optional_checkboxes.py index bb0e66a69697..bf269b9769c8 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_saml_optional_checkboxes.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_saml_optional_checkboxes.py @@ -29,6 +29,7 @@ def setUp(self): def _create_request(self): """Create a test request with session support.""" from importlib import import_module + from django.conf import settings request = self.factory.get('/register') diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_utils.py b/openedx/core/djangoapps/user_authn/views/tests/test_utils.py index 397448005f85..ffb2e62f7d1e 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_utils.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_utils.py @@ -1,12 +1,14 @@ """ Tests for user utils functionality. """ -from django.test import TestCase from datetime import datetime -from openedx.core.djangoapps.user_authn.views.utils import get_auto_generated_username, _get_username_prefix -import ddt from unittest.mock import patch +import ddt +from django.test import TestCase + +from openedx.core.djangoapps.user_authn.views.utils import _get_username_prefix, get_auto_generated_username + @ddt.ddt class TestGenerateUsername(TestCase): diff --git a/openedx/core/djangoapps/user_authn/views/utils.py b/openedx/core/djangoapps/user_authn/views/utils.py index 0b86d7c941ac..f0a0f385cf0f 100644 --- a/openedx/core/djangoapps/user_authn/views/utils.py +++ b/openedx/core/djangoapps/user_authn/views/utils.py @@ -2,7 +2,10 @@ User Auth Views Utils """ import logging +import random import re +import string +from datetime import datetime from typing import Dict from django.conf import settings @@ -15,11 +18,8 @@ from common.djangoapps.third_party_auth import pipeline from common.djangoapps.third_party_auth.models import clean_username from openedx.core.djangoapps.embargo.models import GlobalRestrictedCountry -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.geoinfo.api import country_code_from_ip -import random -import string -from datetime import datetime +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers log = logging.getLogger(__name__) API_V1 = 'v1' diff --git a/openedx/core/djangoapps/util/apps.py b/openedx/core/djangoapps/util/apps.py index e194fd7b5110..993021c0146f 100644 --- a/openedx/core/djangoapps/util/apps.py +++ b/openedx/core/djangoapps/util/apps.py @@ -18,5 +18,5 @@ def ready(self): """ Registers signal handlers at startup. """ - import openedx.core.djangoapps.util.signals # pylint: disable=unused-import, unused-variable import openedx.core.djangoapps.util.checks # pylint: disable=unused-import, unused-variable + import openedx.core.djangoapps.util.signals # pylint: disable=unused-import, unused-variable diff --git a/openedx/core/djangoapps/util/checks.py b/openedx/core/djangoapps/util/checks.py index 9d06dd58b9cf..4376831f6a0e 100644 --- a/openedx/core/djangoapps/util/checks.py +++ b/openedx/core/djangoapps/util/checks.py @@ -4,7 +4,6 @@ from django.conf import settings from django.core import checks - _DEVSTACK_SETTINGS_MODULES = [ "lms.envs.devstack", "cms.envs.devstack", diff --git a/openedx/core/djangoapps/util/management/commands/reset_db.py b/openedx/core/djangoapps/util/management/commands/reset_db.py index 23f100925b41..7f1f6a026e9f 100644 --- a/openedx/core/djangoapps/util/management/commands/reset_db.py +++ b/openedx/core/djangoapps/util/management/commands/reset_db.py @@ -13,9 +13,9 @@ """ +import configparser import logging -import configparser import django from django.conf import settings from django.core.management.base import BaseCommand, CommandError diff --git a/openedx/core/djangoapps/util/testing.py b/openedx/core/djangoapps/util/testing.py index 4686bdc6e75d..315ac7ddee3d 100644 --- a/openedx/core/djangoapps/util/testing.py +++ b/openedx/core/djangoapps/util/testing.py @@ -2,18 +2,22 @@ from datetime import datetime - from zoneinfo import ZoneInfo +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from openedx.core.djangoapps.course_groups.models import CourseUserGroupPartitionGroup from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory from openedx.core.djangoapps.django_comment_common.models import Role from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles from openedx.core.djangoapps.user_api.tests.factories import UserCourseTagFactory from openedx.core.lib.teams_config import TeamsConfig -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) from xmodule.partitions.partitions import Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/core/djangoapps/util/tests/test_dump_settings.py b/openedx/core/djangoapps/util/tests/test_dump_settings.py index 90171eb48c95..830d2c0be280 100644 --- a/openedx/core/djangoapps/util/tests/test_dump_settings.py +++ b/openedx/core/djangoapps/util/tests/test_dump_settings.py @@ -10,7 +10,7 @@ from django.core.management import call_command -from openedx.core.djangolib.testing.utils import skip_unless_lms, skip_unless_cms +from openedx.core.djangolib.testing.utils import skip_unless_cms, skip_unless_lms @skip_unless_lms diff --git a/openedx/core/djangoapps/util/tests/test_signals.py b/openedx/core/djangoapps/util/tests/test_signals.py index 168476fbfba6..cc2711bc1ab1 100644 --- a/openedx/core/djangoapps/util/tests/test_signals.py +++ b/openedx/core/djangoapps/util/tests/test_signals.py @@ -2,11 +2,11 @@ from unittest import TestCase -from pytest import mark from celery import shared_task from django.test.utils import override_settings from edx_django_utils.cache import RequestCache +from pytest import mark @mark.django_db diff --git a/openedx/core/djangoapps/util/tests/test_user_messages.py b/openedx/core/djangoapps/util/tests/test_user_messages.py index 4aebf1fbac21..fbc9f196b9b9 100644 --- a/openedx/core/djangoapps/util/tests/test_user_messages.py +++ b/openedx/core/djangoapps/util/tests/test_user_messages.py @@ -9,9 +9,9 @@ from django.contrib.messages.middleware import MessageMiddleware from django.test import RequestFactory, TestCase +from common.djangoapps.student.tests.factories import UserFactory from common.test.utils import normalize_repr from openedx.core.djangolib.markup import HTML, Text -from common.djangoapps.student.tests.factories import UserFactory from ..user_messages import PageLevelMessages, UserMessageType diff --git a/openedx/core/djangoapps/verified_track_content/partition_scheme.py b/openedx/core/djangoapps/verified_track_content/partition_scheme.py index e0472ce10ebc..f1e9312ad484 100644 --- a/openedx/core/djangoapps/verified_track_content/partition_scheme.py +++ b/openedx/core/djangoapps/verified_track_content/partition_scheme.py @@ -9,12 +9,12 @@ from opaque_keys.edx.keys import CourseKey from common.djangoapps.course_modes.models import CourseMode +from common.djangoapps.student.models import CourseEnrollment from lms.djangoapps.courseware.masquerade import ( get_course_masquerade, get_masquerading_user_group, - is_masquerading_as_specific_student + is_masquerading_as_specific_student, ) -from common.djangoapps.student.models import CourseEnrollment from xmodule.partitions.partitions import Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order LOGGER = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/verified_track_content/tests/test_partition_scheme.py b/openedx/core/djangoapps/verified_track_content/tests/test_partition_scheme.py index b30eea70d439..aad472dbf16d 100644 --- a/openedx/core/djangoapps/verified_track_content/tests/test_partition_scheme.py +++ b/openedx/core/djangoapps/verified_track_content/tests/test_partition_scheme.py @@ -4,15 +4,22 @@ from datetime import datetime, timedelta - from zoneinfo import ZoneInfo + import pytest + from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions import MINIMUM_UNUSED_PARTITION_ID, UserPartition, ReadOnlyUserPartitionError # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.partitions.partitions import ( # lint-amnesty, pylint: disable=wrong-import-order + MINIMUM_UNUSED_PARTITION_ID, + ReadOnlyUserPartitionError, + UserPartition, +) from ..partition_scheme import ENROLLMENT_GROUP_IDS, EnrollmentTrackPartitionScheme, EnrollmentTrackUserPartition diff --git a/openedx/core/djangoapps/video_config/admin.py b/openedx/core/djangoapps/video_config/admin.py index f58277ec9a20..9e06eaa24299 100644 --- a/openedx/core/djangoapps/video_config/admin.py +++ b/openedx/core/djangoapps/video_config/admin.py @@ -8,15 +8,19 @@ from openedx.core.djangoapps.video_config.forms import ( CourseHLSPlaybackFlagAdminForm, - CourseYoutubeBlockedFlagAdminForm, CourseVideoTranscriptFlagAdminForm, + CourseYoutubeBlockedFlagAdminForm, ) from openedx.core.djangoapps.video_config.models import ( - CourseHLSPlaybackEnabledFlag, HLSPlaybackEnabledFlag, + CourseHLSPlaybackEnabledFlag, + CourseVideoTranscriptEnabledFlag, CourseYoutubeBlockedFlag, - CourseVideoTranscriptEnabledFlag, VideoTranscriptEnabledFlag, - TranscriptMigrationSetting, MigrationEnqueuedCourse, - VideoThumbnailSetting, UpdatedCourseVideos, + HLSPlaybackEnabledFlag, + MigrationEnqueuedCourse, + TranscriptMigrationSetting, + UpdatedCourseVideos, + VideoThumbnailSetting, + VideoTranscriptEnabledFlag, ) diff --git a/openedx/core/djangoapps/video_config/forms.py b/openedx/core/djangoapps/video_config/forms.py index 7caec4e8afb9..856b9e58de8e 100644 --- a/openedx/core/djangoapps/video_config/forms.py +++ b/openedx/core/djangoapps/video_config/forms.py @@ -8,8 +8,8 @@ from openedx.core.djangoapps.video_config.models import ( CourseHLSPlaybackEnabledFlag, - CourseYoutubeBlockedFlag, CourseVideoTranscriptEnabledFlag, + CourseYoutubeBlockedFlag, ) from openedx.core.lib.courses import clean_course_id diff --git a/openedx/core/djangoapps/video_config/migrations/0001_initial.py b/openedx/core/djangoapps/video_config/migrations/0001_initial.py index 1ed36c753d81..10db5c407404 100644 --- a/openedx/core/djangoapps/video_config/migrations/0001_initial.py +++ b/openedx/core/djangoapps/video_config/migrations/0001_initial.py @@ -1,6 +1,6 @@ -from django.db import migrations, models -from django.conf import settings import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models from opaque_keys.edx.django.models import CourseKeyField diff --git a/openedx/core/djangoapps/video_config/migrations/0002_coursevideotranscriptenabledflag_videotranscriptenabledflag.py b/openedx/core/djangoapps/video_config/migrations/0002_coursevideotranscriptenabledflag_videotranscriptenabledflag.py index 8b68ddff0dc9..6d0d403b01e3 100644 --- a/openedx/core/djangoapps/video_config/migrations/0002_coursevideotranscriptenabledflag_videotranscriptenabledflag.py +++ b/openedx/core/djangoapps/video_config/migrations/0002_coursevideotranscriptenabledflag_videotranscriptenabledflag.py @@ -1,6 +1,6 @@ -from django.db import migrations, models -from django.conf import settings import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models from opaque_keys.edx.django.models import CourseKeyField diff --git a/openedx/core/djangoapps/video_config/migrations/0003_transcriptmigrationsetting.py b/openedx/core/djangoapps/video_config/migrations/0003_transcriptmigrationsetting.py index 50f398eee56f..67e8f8a05b8a 100644 --- a/openedx/core/djangoapps/video_config/migrations/0003_transcriptmigrationsetting.py +++ b/openedx/core/djangoapps/video_config/migrations/0003_transcriptmigrationsetting.py @@ -1,6 +1,6 @@ -from django.db import migrations, models import django.db.models.deletion from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/video_config/migrations/0005_auto_20180719_0752.py b/openedx/core/djangoapps/video_config/migrations/0005_auto_20180719_0752.py index d6baf0109746..87289b50bf4c 100644 --- a/openedx/core/djangoapps/video_config/migrations/0005_auto_20180719_0752.py +++ b/openedx/core/djangoapps/video_config/migrations/0005_auto_20180719_0752.py @@ -1,10 +1,10 @@ # Generated by Django 1.11.14 on 2018-07-19 07:52 -from django.db import migrations, models import django.utils.timezone import model_utils.fields import opaque_keys.edx.django.models +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/video_config/migrations/0006_videothumbnailetting_updatedcoursevideos.py b/openedx/core/djangoapps/video_config/migrations/0006_videothumbnailetting_updatedcoursevideos.py index 9856bc5024d7..2dc0f66d6080 100644 --- a/openedx/core/djangoapps/video_config/migrations/0006_videothumbnailetting_updatedcoursevideos.py +++ b/openedx/core/djangoapps/video_config/migrations/0006_videothumbnailetting_updatedcoursevideos.py @@ -1,12 +1,12 @@ # Generated by Django 1.11.15 on 2018-08-15 19:13 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone import model_utils.fields import opaque_keys.edx.django.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/video_config/migrations/0008_courseyoutubeblockedflag.py b/openedx/core/djangoapps/video_config/migrations/0008_courseyoutubeblockedflag.py index 4632bb044a48..b10f1148bfa4 100644 --- a/openedx/core/djangoapps/video_config/migrations/0008_courseyoutubeblockedflag.py +++ b/openedx/core/djangoapps/video_config/migrations/0008_courseyoutubeblockedflag.py @@ -1,10 +1,10 @@ # Generated by Django 1.11.23 on 2019-08-25 16:11 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import opaque_keys.edx.django.models +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/video_config/services.py b/openedx/core/djangoapps/video_config/services.py index 5e72f8babb9e..cf79cec5e1f0 100644 --- a/openedx/core/djangoapps/video_config/services.py +++ b/openedx/core/djangoapps/video_config/services.py @@ -10,36 +10,32 @@ from typing import Any from django.conf import settings -from opaque_keys.edx.keys import CourseKey, UsageKey -from opaque_keys.edx.locator import LibraryLocatorV2 -from xblocks_contrib.video.exceptions import TranscriptNotFoundError - -from openedx.core.djangoapps.video_config import sharing from django.core.files import File from django.core.files.base import ContentFile from edxval.api import create_external_video, create_or_update_video_transcript, delete_video_transcript +from opaque_keys.edx.keys import CourseKey, UsageKey +from opaque_keys.edx.locator import LibraryLocatorV2 from organizations.api import get_course_organization -from openedx.core.djangoapps.video_config.models import ( - CourseYoutubeBlockedFlag, - HLSPlaybackEnabledFlag, -) -from openedx.core.djangoapps.video_config.toggles import TRANSCRIPT_FEEDBACK -from openedx.core.djangoapps.video_pipeline.config.waffle import DEPRECATE_YOUTUBE +from xblocks_contrib.video.exceptions import TranscriptNotFoundError + from openedx.core.djangoapps.content_libraries.api import ( add_library_block_static_asset_file, delete_library_block_static_asset_file, ) +from openedx.core.djangoapps.video_config import sharing +from openedx.core.djangoapps.video_config.models import CourseYoutubeBlockedFlag, HLSPlaybackEnabledFlag from openedx.core.djangoapps.video_config.sharing_sites import sharing_sites_info_for_video +from openedx.core.djangoapps.video_config.toggles import TRANSCRIPT_FEEDBACK from openedx.core.djangoapps.video_config.transcripts_utils import ( Transcript, clean_video_id, get_html5_ids, + get_transcript, + get_transcript_for_video, manage_video_subtitles_save, remove_subs_from_store, - get_transcript_for_video, - get_transcript, ) - +from openedx.core.djangoapps.video_pipeline.config.waffle import DEPRECATE_YOUTUBE from xmodule.exceptions import NotFoundError from xmodule.modulestore.inheritance import own_metadata diff --git a/openedx/core/djangoapps/video_config/sharing_sites.py b/openedx/core/djangoapps/video_config/sharing_sites.py index 189c316760a9..880c51d1ff05 100644 --- a/openedx/core/djangoapps/video_config/sharing_sites.py +++ b/openedx/core/djangoapps/video_config/sharing_sites.py @@ -2,9 +2,10 @@ Defines the sharing sites for different social media platforms """ from collections import namedtuple +from urllib.parse import urlencode + from django.conf import settings from django.utils.translation import gettext_lazy as _ -from urllib.parse import urlencode SharingSiteConfig = namedtuple( 'SharingSiteConfig', diff --git a/openedx/core/djangoapps/video_config/tests/test_models.py b/openedx/core/djangoapps/video_config/tests/test_models.py index 3a971a252486..7b714e3bc763 100644 --- a/openedx/core/djangoapps/video_config/tests/test_models.py +++ b/openedx/core/djangoapps/video_config/tests/test_models.py @@ -2,17 +2,18 @@ Tests for the models that configures HLS Playback feature. """ -import ddt import itertools # lint-amnesty, pylint: disable=wrong-import-order - from contextlib import contextmanager # lint-amnesty, pylint: disable=wrong-import-order +import ddt from django.test import TestCase - from opaque_keys.edx.locator import CourseLocator + from openedx.core.djangoapps.video_config.models import ( - CourseHLSPlaybackEnabledFlag, HLSPlaybackEnabledFlag, - CourseVideoTranscriptEnabledFlag, VideoTranscriptEnabledFlag, + CourseHLSPlaybackEnabledFlag, + CourseVideoTranscriptEnabledFlag, + HLSPlaybackEnabledFlag, + VideoTranscriptEnabledFlag, ) diff --git a/openedx/core/djangoapps/video_config/tests/test_transcripts_utils.py b/openedx/core/djangoapps/video_config/tests/test_transcripts_utils.py index 273d31444f01..a7c65efda8bb 100644 --- a/openedx/core/djangoapps/video_config/tests/test_transcripts_utils.py +++ b/openedx/core/djangoapps/video_config/tests/test_transcripts_utils.py @@ -7,7 +7,7 @@ - among the fields found in a track descriptor is a caption URL (aka caption link) - use this link to obtain the track's caption data ''' -from unittest import mock, TestCase +from unittest import TestCase, mock import ddt diff --git a/openedx/core/djangoapps/video_config/transcripts_utils.py b/openedx/core/djangoapps/video_config/transcripts_utils.py index 7cf8cbd46d43..e6f747537fa8 100644 --- a/openedx/core/djangoapps/video_config/transcripts_utils.py +++ b/openedx/core/djangoapps/video_config/transcripts_utils.py @@ -19,19 +19,17 @@ from django.utils.translation import get_language_info from lxml import etree from opaque_keys.edx.keys import UsageKeyV2 +from opaque_keys.edx.locator import LibraryLocatorV2 from pysrt import SubRipFile, SubRipItem, SubRipTime from pysrt.srtexc import Error -from opaque_keys.edx.locator import LibraryLocatorV2 +from xblocks_contrib.video.bumper_utils import get_bumper_settings +from xblocks_contrib.video.exceptions import TranscriptsGenerationException from openedx.core.djangoapps.xblock.api import get_component_from_usage_key from xmodule.contentstore.content import StaticContent from xmodule.contentstore.django import contentstore from xmodule.exceptions import NotFoundError -from xblocks_contrib.video.bumper_utils import get_bumper_settings -from xblocks_contrib.video.exceptions import TranscriptsGenerationException - - try: from edxval import api as edxval_api except ImportError: diff --git a/openedx/core/djangoapps/video_pipeline/admin.py b/openedx/core/djangoapps/video_pipeline/admin.py index 26f354205a2d..bad3131284ff 100644 --- a/openedx/core/djangoapps/video_pipeline/admin.py +++ b/openedx/core/djangoapps/video_pipeline/admin.py @@ -2,18 +2,18 @@ Django admin for Video Pipeline models. """ +from config_models.admin import ConfigurationModelAdmin from django.contrib import admin -from config_models.admin import ConfigurationModelAdmin from openedx.core.djangoapps.video_config.admin import CourseSpecificEnabledFlagBaseAdmin from openedx.core.djangoapps.video_pipeline.forms import ( CourseVideoUploadsEnabledByDefaultAdminForm, - VEMPipelineIntegrationAdminForm + VEMPipelineIntegrationAdminForm, ) from openedx.core.djangoapps.video_pipeline.models import ( CourseVideoUploadsEnabledByDefault, VEMPipelineIntegration, - VideoUploadsEnabledByDefault + VideoUploadsEnabledByDefault, ) diff --git a/openedx/core/djangoapps/video_pipeline/forms.py b/openedx/core/djangoapps/video_pipeline/forms.py index f763746331e3..80eb041012d9 100644 --- a/openedx/core/djangoapps/video_pipeline/forms.py +++ b/openedx/core/djangoapps/video_pipeline/forms.py @@ -4,10 +4,7 @@ from django import forms from openedx.core.djangoapps.video_config.forms import CourseSpecificFlagAdminBaseForm -from openedx.core.djangoapps.video_pipeline.models import ( - CourseVideoUploadsEnabledByDefault, - VEMPipelineIntegration, -) +from openedx.core.djangoapps.video_pipeline.models import CourseVideoUploadsEnabledByDefault, VEMPipelineIntegration class CourseVideoUploadsEnabledByDefaultAdminForm(CourseSpecificFlagAdminBaseForm): diff --git a/openedx/core/djangoapps/video_pipeline/migrations/0001_initial.py b/openedx/core/djangoapps/video_pipeline/migrations/0001_initial.py index 0eef050c20eb..1de114a4af39 100644 --- a/openedx/core/djangoapps/video_pipeline/migrations/0001_initial.py +++ b/openedx/core/djangoapps/video_pipeline/migrations/0001_initial.py @@ -1,6 +1,6 @@ -from django.db import migrations, models import django.db.models.deletion from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/video_pipeline/migrations/0003_coursevideouploadsenabledbydefault_videouploadsenabledbydefault.py b/openedx/core/djangoapps/video_pipeline/migrations/0003_coursevideouploadsenabledbydefault_videouploadsenabledbydefault.py index 72a54f806bbd..fa7c1220e78a 100644 --- a/openedx/core/djangoapps/video_pipeline/migrations/0003_coursevideouploadsenabledbydefault_videouploadsenabledbydefault.py +++ b/openedx/core/djangoapps/video_pipeline/migrations/0003_coursevideouploadsenabledbydefault_videouploadsenabledbydefault.py @@ -1,6 +1,6 @@ -from django.db import migrations, models -from django.conf import settings import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models from opaque_keys.edx.django.models import CourseKeyField diff --git a/openedx/core/djangoapps/video_pipeline/migrations/0004_vempipelineintegration.py b/openedx/core/djangoapps/video_pipeline/migrations/0004_vempipelineintegration.py index 1655ddcbb144..d7d3f65ae612 100644 --- a/openedx/core/djangoapps/video_pipeline/migrations/0004_vempipelineintegration.py +++ b/openedx/core/djangoapps/video_pipeline/migrations/0004_vempipelineintegration.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.12 on 2020-05-29 12:15 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/video_pipeline/models.py b/openedx/core/djangoapps/video_pipeline/models.py index 1e21c19feef3..df118297f892 100644 --- a/openedx/core/djangoapps/video_pipeline/models.py +++ b/openedx/core/djangoapps/video_pipeline/models.py @@ -5,7 +5,6 @@ from config_models.models import ConfigurationModel from django.contrib.auth import get_user_model from django.db import models - from django.utils.translation import gettext_lazy as _ from opaque_keys.edx.django.models import CourseKeyField diff --git a/openedx/core/djangoapps/video_pipeline/tests/test_models.py b/openedx/core/djangoapps/video_pipeline/tests/test_models.py index 7120b75ba33c..70bdf7adeef2 100644 --- a/openedx/core/djangoapps/video_pipeline/tests/test_models.py +++ b/openedx/core/djangoapps/video_pipeline/tests/test_models.py @@ -2,13 +2,15 @@ Tests for the models that configures 'VideoUploadsEnabledByDefault' feature. """ -import ddt import itertools # lint-amnesty, pylint: disable=wrong-import-order +import ddt from django.test import TestCase + from openedx.core.djangoapps.video_config.tests.test_models import FeatureFlagTestMixin from openedx.core.djangoapps.video_pipeline.models import ( - CourseVideoUploadsEnabledByDefault, VideoUploadsEnabledByDefault, + CourseVideoUploadsEnabledByDefault, + VideoUploadsEnabledByDefault, ) diff --git a/openedx/core/djangoapps/video_pipeline/utils.py b/openedx/core/djangoapps/video_pipeline/utils.py index b76026927b6e..541200b1e800 100644 --- a/openedx/core/djangoapps/video_pipeline/utils.py +++ b/openedx/core/djangoapps/video_pipeline/utils.py @@ -2,7 +2,6 @@ Utils for video_pipeline app. """ from django.conf import settings - from edx_rest_api_client.client import OAuthAPIClient diff --git a/openedx/core/djangoapps/waffle_utils/admin.py b/openedx/core/djangoapps/waffle_utils/admin.py index bd905a7c9e78..93f1be13aeac 100644 --- a/openedx/core/djangoapps/waffle_utils/admin.py +++ b/openedx/core/djangoapps/waffle_utils/admin.py @@ -2,10 +2,8 @@ Django admin page for waffle utils models """ -from django.contrib import admin - from config_models.admin import KeyedConfigurationModelAdmin - +from django.contrib import admin from .forms import WaffleFlagCourseOverrideAdminForm, WaffleFlagOrgOverrideAdminForm from .models import WaffleFlagCourseOverrideModel, WaffleFlagOrgOverrideModel diff --git a/openedx/core/djangoapps/waffle_utils/migrations/0003_add_org_level_waffle_override.py b/openedx/core/djangoapps/waffle_utils/migrations/0003_add_org_level_waffle_override.py index 2f9c7a67ad0d..4319482cd935 100644 --- a/openedx/core/djangoapps/waffle_utils/migrations/0003_add_org_level_waffle_override.py +++ b/openedx/core/djangoapps/waffle_utils/migrations/0003_add_org_level_waffle_override.py @@ -1,8 +1,8 @@ # Generated by Django 3.2.11 on 2022-01-13 18:42 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/waffle_utils/models.py b/openedx/core/djangoapps/waffle_utils/models.py index a89201ef3a9f..9a49ca8c432a 100644 --- a/openedx/core/djangoapps/waffle_utils/models.py +++ b/openedx/core/djangoapps/waffle_utils/models.py @@ -2,12 +2,12 @@ Models for configuring waffle utils. """ -from django.db.models import CharField, TextField, Index +from config_models.models import ConfigurationModel +from django.db.models import CharField, Index, TextField from django.utils.translation import gettext_lazy as _ from model_utils import Choices from opaque_keys.edx.django.models import CourseKeyField -from config_models.models import ConfigurationModel from openedx.core.lib.cache_utils import request_cached diff --git a/openedx/core/djangoapps/waffle_utils/urls.py b/openedx/core/djangoapps/waffle_utils/urls.py index 7f93ac341eb2..e026ff1fa19a 100644 --- a/openedx/core/djangoapps/waffle_utils/urls.py +++ b/openedx/core/djangoapps/waffle_utils/urls.py @@ -1,5 +1,6 @@ """ URL definitions for waffle utils. """ from django.urls import path + from openedx.core.djangoapps.waffle_utils.views import ToggleStateView urlpatterns = [ diff --git a/openedx/core/djangoapps/xblock/api.py b/openedx/core/djangoapps/xblock/api.py index 5b6ac8b4c668..9a9ee2bcbb68 100644 --- a/openedx/core/djangoapps/xblock/api.py +++ b/openedx/core/djangoapps/xblock/api.py @@ -7,43 +7,40 @@ Note that these views are only for interacting with existing blocks. Other Studio APIs cover use cases like adding/deleting/editing blocks. """ +import logging +import threading # pylint: disable=unused-import +from datetime import datetime # pylint: disable=unused-import + # pylint: disable=unused-import from enum import Enum -from datetime import datetime -import logging -import threading from django.core.exceptions import PermissionDenied from django.urls import reverse from django.utils.translation import gettext as _ -from openedx_content import api as content_api -from openedx_content.models_api import Component, ComponentVersion from opaque_keys.edx.keys import UsageKeyV2 from opaque_keys.edx.locator import LibraryUsageLocatorV2 +from openedx_content import api as content_api +from openedx_content.models_api import Component, ComponentVersion from rest_framework.exceptions import NotFound from xblock.core import XBlock from xblock.exceptions import NoSuchUsage, NoSuchViewError from xblock.plugin import PluginMissingError -from openedx.core.types import User as UserType from openedx.core.djangoapps.xblock.apps import get_xblock_app_config + +# Made available as part of this package's public API: +from openedx.core.djangoapps.xblock.learning_context import LearningContext from openedx.core.djangoapps.xblock.learning_context.manager import get_learning_context_impl from openedx.core.djangoapps.xblock.runtime.openedx_content_runtime import ( OpenedXContentFieldData, OpenedXContentRuntime, ) +from openedx.core.types import User as UserType + from .data import CheckPerm, LatestVersion from .rest_api.url_converters import VersionConverter -from .utils import ( - get_secure_token_for_xblock_handler, - get_xblock_id_for_anonymous_user, - get_auto_latest_version, -) - from .runtime.openedx_content_runtime import OpenedXContentRuntime - -# Made available as part of this package's public API: -from openedx.core.djangoapps.xblock.learning_context import LearningContext +from .utils import get_auto_latest_version, get_secure_token_for_xblock_handler, get_xblock_id_for_anonymous_user # Implementation: diff --git a/openedx/core/djangoapps/xblock/apps.py b/openedx/core/djangoapps/xblock/apps.py index e0fb3b81b18d..aba2c1aa48f7 100644 --- a/openedx/core/djangoapps/xblock/apps.py +++ b/openedx/core/djangoapps/xblock/apps.py @@ -5,7 +5,8 @@ from django.conf import settings from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers -from .data import StudentDataMode, AuthoredDataMode + +from .data import AuthoredDataMode, StudentDataMode class XBlockAppConfig(AppConfig): diff --git a/openedx/core/djangoapps/xblock/learning_context/learning_context.py b/openedx/core/djangoapps/xblock/learning_context/learning_context.py index dc7a21f1c397..d3b4c8643a2f 100644 --- a/openedx/core/djangoapps/xblock/learning_context/learning_context.py +++ b/openedx/core/djangoapps/xblock/learning_context/learning_context.py @@ -2,9 +2,10 @@ A "Learning Context" is a course, a library, a program, or some other collection of content where learning happens. """ -from openedx.core.types import User as UserType from opaque_keys.edx.keys import UsageKeyV2 +from openedx.core.types import User as UserType + class LearningContext: """ diff --git a/openedx/core/djangoapps/xblock/rest_api/urls.py b/openedx/core/djangoapps/xblock/rest_api/urls.py index a83d5104e570..ed76f5638f94 100644 --- a/openedx/core/djangoapps/xblock/rest_api/urls.py +++ b/openedx/core/djangoapps/xblock/rest_api/urls.py @@ -2,8 +2,8 @@ URL configuration for the new XBlock API """ from django.urls import include, path, re_path, register_converter -from . import url_converters -from . import views + +from . import url_converters, views # Note that the exact same API URLs are used in Studio and the LMS, but the API # may act a bit differently in each (e.g. Studio stores user state ephemerally). diff --git a/openedx/core/djangoapps/xblock/rest_api/views.py b/openedx/core/djangoapps/xblock/rest_api/views.py index 4135fcbf6cdb..484336861eee 100644 --- a/openedx/core/djangoapps/xblock/rest_api/views.py +++ b/openedx/core/djangoapps/xblock/rest_api/views.py @@ -4,7 +4,7 @@ import json from pathlib import Path -from common.djangoapps.util.json_request import JsonResponse +import openassessment from corsheaders.signals import check_request_enabled from django.conf import settings from django.contrib.auth import get_user_model @@ -16,31 +16,25 @@ from opaque_keys.edx.keys import UsageKeyV2 from rest_framework import permissions, serializers from rest_framework.decorators import api_view, permission_classes # lint-amnesty, pylint: disable=unused-import -from rest_framework.exceptions import PermissionDenied, AuthenticationFailed, NotFound -from rest_framework.response import Response +from rest_framework.exceptions import AuthenticationFailed, NotFound, PermissionDenied from rest_framework.fields import BooleanField +from rest_framework.response import Response from rest_framework.views import APIView from xblock.django.request import DjangoWebobRequest, webob_to_django_response from xblock.exceptions import NoSuchUsage from xblock.fields import Scope -import openassessment import openedx.core.djangoapps.site_configuration.helpers as configuration_helpers +from common.djangoapps.util.json_request import JsonResponse from openedx.core.djangoapps.xblock.learning_context.manager import get_learning_context_impl from openedx.core.lib.api.view_utils import view_auth_classes -from ..api import ( - CheckPerm, - LatestVersion, - get_block_metadata, - get_block_display_name, - get_handler_url as _get_handler_url, - load_block, - render_block_view as _render_block_view, - get_block_olx, -) + +from ..api import CheckPerm, LatestVersion, get_block_display_name, get_block_metadata, get_block_olx, load_block +from ..api import get_handler_url as _get_handler_url +from ..api import render_block_view as _render_block_view from ..utils import validate_secure_token_for_xblock_handler -from .url_converters import VersionConverter from .serializers import XBlockOlxSerializer +from .url_converters import VersionConverter User = get_user_model() diff --git a/openedx/core/djangoapps/xblock/runtime/ephemeral_field_data.py b/openedx/core/djangoapps/xblock/runtime/ephemeral_field_data.py index d4ff23960103..ba84fa9579ff 100644 --- a/openedx/core/djangoapps/xblock/runtime/ephemeral_field_data.py +++ b/openedx/core/djangoapps/xblock/runtime/ephemeral_field_data.py @@ -21,7 +21,6 @@ from django.core.cache import caches from xblock.runtime import KeyValueStore - FIELD_DATA_TIMEOUT = None # keep in cache indefinitely, until cache needs pruning diff --git a/openedx/core/djangoapps/xblock/runtime/mixin.py b/openedx/core/djangoapps/xblock/runtime/mixin.py index 5e413ce5ebe5..384591f64c4d 100644 --- a/openedx/core/djangoapps/xblock/runtime/mixin.py +++ b/openedx/core/djangoapps/xblock/runtime/mixin.py @@ -5,9 +5,9 @@ from django.utils.translation import gettext as _ +from web_fragments.fragment import Fragment from xblock.core import XBlock, XBlockMixin from xblock.exceptions import JsonHandlerError -from web_fragments.fragment import Fragment from openedx.core.djangolib.markup import HTML diff --git a/openedx/core/djangoapps/xblock/runtime/openedx_content_runtime.py b/openedx/core/djangoapps/xblock/runtime/openedx_content_runtime.py index e7fa2d0a7b82..1d7f95e150f5 100644 --- a/openedx/core/djangoapps/xblock/runtime/openedx_content_runtime.py +++ b/openedx/core/djangoapps/xblock/runtime/openedx_content_runtime.py @@ -11,25 +11,22 @@ from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.db.transaction import atomic from django.urls import reverse - -from openedx_content import api as content_api - from lxml import etree - +from openedx_content import api as content_api from xblock.core import XBlock from xblock.exceptions import NoSuchUsage -from xblock.fields import Field, Scope, ScopeIds from xblock.field_data import FieldData +from xblock.fields import Field, Scope, ScopeIds from openedx.core.djangoapps.xblock.api import get_xblock_app_config from openedx.core.lib.xblock_serializer.api import serialize_modulestore_block_for_openedx_content from openedx.core.lib.xblock_serializer.data import StaticFile + from ..data import AuthoredDataMode, LatestVersion -from ..utils import get_auto_latest_version from ..learning_context.manager import get_learning_context_impl +from ..utils import get_auto_latest_version from .runtime import XBlockRuntime - log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/xblock/runtime/runtime.py b/openedx/core/djangoapps/xblock/runtime/runtime.py index 61213d2c451a..caa789a34dd6 100644 --- a/openedx/core/djangoapps/xblock/runtime/runtime.py +++ b/openedx/core/djangoapps/xblock/runtime/runtime.py @@ -6,15 +6,14 @@ from urllib.parse import urljoin # pylint: disable=import-error import crum -from common.djangoapps.student.models import anonymous_id_for_user -from completion.waffle import ENABLE_COMPLETION_TRACKING_SWITCH from completion.models import BlockCompletion from completion.services import CompletionService +from completion.waffle import ENABLE_COMPLETION_TRACKING_SWITCH from django.contrib.auth import get_user_model from django.core.cache import cache from django.core.exceptions import PermissionDenied from eventtracking import tracker -from opaque_keys.edx.keys import UsageKeyV2, LearningContextKey +from opaque_keys.edx.keys import LearningContextKey, UsageKeyV2 from web_fragments.fragment import Fragment from xblock.core import XBlock from xblock.exceptions import NoSuchServiceError @@ -22,27 +21,28 @@ from xblock.fields import Scope, ScopeIds from xblock.runtime import IdReader, KvsFieldData, MemoryIdManager, Runtime -from xmodule.errortracker import make_error_tracker -from xmodule.contentstore.django import contentstore -from xmodule.modulestore.django import XBlockI18nService -from xmodule.services import EventPublishingService, RebindUserService, XQueueService -from xmodule.util.sandboxing import SandboxService from common.djangoapps.edxmako.services import MakoService from common.djangoapps.static_replace.services import ReplaceURLService +from common.djangoapps.student.models import anonymous_id_for_user from common.djangoapps.track import contexts as track_contexts from common.djangoapps.track import views as track_views from common.djangoapps.xblock_django.user_service import DjangoXBlockUserService from lms.djangoapps.courseware.model_data import DjangoKeyValueStore, FieldDataCache from lms.djangoapps.grades.api import signals as grades_signals -from openedx.core.types import User as UserType from openedx.core.djangoapps.enrollments.services import EnrollmentsService from openedx.core.djangoapps.xblock.apps import get_xblock_app_config -from openedx.core.djangoapps.xblock.data import AuthoredDataMode, StudentDataMode, LatestVersion +from openedx.core.djangoapps.xblock.data import AuthoredDataMode, LatestVersion, StudentDataMode from openedx.core.djangoapps.xblock.runtime.ephemeral_field_data import EphemeralKeyValueStore from openedx.core.djangoapps.xblock.runtime.mixin import LmsBlockMixin from openedx.core.djangoapps.xblock.utils import get_xblock_id_for_anonymous_user from openedx.core.lib.cache_utils import CacheService -from openedx.core.lib.xblock_utils import wrap_fragment, xblock_local_resource_url, request_token +from openedx.core.lib.xblock_utils import request_token, wrap_fragment, xblock_local_resource_url +from openedx.core.types import User as UserType +from xmodule.contentstore.django import contentstore +from xmodule.errortracker import make_error_tracker +from xmodule.modulestore.django import XBlockI18nService +from xmodule.services import EventPublishingService, RebindUserService, XQueueService +from xmodule.util.sandboxing import SandboxService from .id_managers import OpaqueKeyReader from .shims import RuntimeShim, XBlockShim diff --git a/openedx/core/djangoapps/xblock/runtime/shims.py b/openedx/core/djangoapps/xblock/runtime/shims.py index 01e64c3bc508..8d1e22c64c01 100644 --- a/openedx/core/djangoapps/xblock/runtime/shims.py +++ b/openedx/core/djangoapps/xblock/runtime/shims.py @@ -4,6 +4,7 @@ # pylint: disable=no-member import warnings + from django.conf import settings from django.core.cache import cache from django.template import TemplateDoesNotExist diff --git a/openedx/core/djangoapps/xblock/tests/test_utils.py b/openedx/core/djangoapps/xblock/tests/test_utils.py index 229406e1bca1..d38b8b943ec6 100644 --- a/openedx/core/djangoapps/xblock/tests/test_utils.py +++ b/openedx/core/djangoapps/xblock/tests/test_utils.py @@ -8,9 +8,9 @@ from freezegun import freeze_time from openedx.core.djangoapps.xblock.utils import ( # lint-amnesty, pylint: disable=reimported - get_secure_token_for_xblock_handler, _get_secure_token_for_xblock_handler, - validate_secure_token_for_xblock_handler + get_secure_token_for_xblock_handler, + validate_secure_token_for_xblock_handler, ) REFERENCE_PARAMS = { diff --git a/openedx/core/djangoapps/zendesk_proxy/apps.py b/openedx/core/djangoapps/zendesk_proxy/apps.py index e2d6f8a57a4f..88a661a10fe9 100644 --- a/openedx/core/djangoapps/zendesk_proxy/apps.py +++ b/openedx/core/djangoapps/zendesk_proxy/apps.py @@ -5,7 +5,7 @@ from django.apps import AppConfig -from edx_django_utils.plugins import PluginURLs, PluginSettings +from edx_django_utils.plugins import PluginSettings, PluginURLs from openedx.core.djangoapps.plugins.constants import ProjectType, SettingsType diff --git a/openedx/core/djangoapps/zendesk_proxy/tests/test_utils.py b/openedx/core/djangoapps/zendesk_proxy/tests/test_utils.py index 628f8302b464..49ed109300a3 100644 --- a/openedx/core/djangoapps/zendesk_proxy/tests/test_utils.py +++ b/openedx/core/djangoapps/zendesk_proxy/tests/test_utils.py @@ -5,11 +5,11 @@ import json from collections import OrderedDict - from unittest.mock import MagicMock, patch -from django.test.utils import override_settings import ddt +from django.test.utils import override_settings + from openedx.core.djangoapps.zendesk_proxy.utils import create_zendesk_ticket from openedx.core.lib.api.test_utils import ApiTestCase diff --git a/openedx/core/djangoapps/zendesk_proxy/tests/test_v0_views.py b/openedx/core/djangoapps/zendesk_proxy/tests/test_v0_views.py index bf3a7cc24e22..5bb0d5fc19f7 100644 --- a/openedx/core/djangoapps/zendesk_proxy/tests/test_v0_views.py +++ b/openedx/core/djangoapps/zendesk_proxy/tests/test_v0_views.py @@ -1,13 +1,13 @@ """Tests for zendesk_proxy views.""" -from copy import deepcopy import json - +from copy import deepcopy from unittest.mock import MagicMock, patch + import ddt -from django.urls import reverse from django.test.utils import override_settings +from django.urls import reverse from openedx.core.djangoapps.zendesk_proxy.v0.views import ZENDESK_REQUESTS_PER_HOUR from openedx.core.lib.api.test_utils import ApiTestCase diff --git a/openedx/core/djangoapps/zendesk_proxy/tests/test_v1_views.py b/openedx/core/djangoapps/zendesk_proxy/tests/test_v1_views.py index 8259013e098f..ed3a6cb2597b 100644 --- a/openedx/core/djangoapps/zendesk_proxy/tests/test_v1_views.py +++ b/openedx/core/djangoapps/zendesk_proxy/tests/test_v1_views.py @@ -1,13 +1,13 @@ """Tests for zendesk_proxy views.""" -from copy import deepcopy import json +from copy import deepcopy from unittest.mock import MagicMock, patch import ddt -from django.urls import reverse from django.test.utils import override_settings +from django.urls import reverse from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.zendesk_proxy.v1.views import ZendeskProxyThrottle diff --git a/openedx/core/djangoapps/zendesk_proxy/urls.py b/openedx/core/djangoapps/zendesk_proxy/urls.py index 9881b72664fd..12477772a766 100644 --- a/openedx/core/djangoapps/zendesk_proxy/urls.py +++ b/openedx/core/djangoapps/zendesk_proxy/urls.py @@ -3,6 +3,7 @@ """ from django.urls import path + from openedx.core.djangoapps.zendesk_proxy.v0.views import ZendeskPassthroughView as v0_view from openedx.core.djangoapps.zendesk_proxy.v1.views import ZendeskPassthroughView as v1_view diff --git a/openedx/core/djangolib/oauth2_retirement_utils.py b/openedx/core/djangolib/oauth2_retirement_utils.py index 90e69f9e91d3..23d18eb02ba7 100644 --- a/openedx/core/djangolib/oauth2_retirement_utils.py +++ b/openedx/core/djangolib/oauth2_retirement_utils.py @@ -3,12 +3,10 @@ """ -from oauth2_provider.models import ( - AccessToken as DOTAccessToken, - Application as DOTApplication, - Grant as DOTGrant, - RefreshToken as DOTRefreshToken, -) +from oauth2_provider.models import AccessToken as DOTAccessToken +from oauth2_provider.models import Application as DOTApplication +from oauth2_provider.models import Grant as DOTGrant +from oauth2_provider.models import RefreshToken as DOTRefreshToken class ModelRetirer: diff --git a/openedx/core/djangolib/testing/tests/test_utils.py b/openedx/core/djangolib/testing/tests/test_utils.py index b81b25a78134..dda6c1864cc4 100644 --- a/openedx/core/djangolib/testing/tests/test_utils.py +++ b/openedx/core/djangolib/testing/tests/test_utils.py @@ -3,7 +3,6 @@ """ from crum import set_current_request - from django.contrib.auth import get_user_model from django.contrib.auth.models import AnonymousUser from django.http.request import HttpRequest @@ -11,7 +10,6 @@ from ..utils import get_mock_request - USER_MODEL = get_user_model() diff --git a/openedx/core/djangolib/tests/test_js_utils.py b/openedx/core/djangolib/tests/test_js_utils.py index ee2afbebc43b..e528ac35f206 100644 --- a/openedx/core/djangolib/tests/test_js_utils.py +++ b/openedx/core/djangolib/tests/test_js_utils.py @@ -3,9 +3,9 @@ Tests for js_utils.py """ +import html import json import re -import html from unittest import TestCase from mako.template import Template diff --git a/openedx/core/djangolib/tests/test_oauth2_retirement_utils.py b/openedx/core/djangolib/tests/test_oauth2_retirement_utils.py index e5465aa1d109..b6ab493350c6 100644 --- a/openedx/core/djangolib/tests/test_oauth2_retirement_utils.py +++ b/openedx/core/djangolib/tests/test_oauth2_retirement_utils.py @@ -11,8 +11,8 @@ from oauth2_provider.models import Grant as DOTGrant from oauth2_provider.models import RefreshToken as DOTRefreshToken -from openedx.core.djangoapps.oauth_dispatch.tests import factories from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.oauth_dispatch.tests import factories from ..oauth2_retirement_utils import retire_dot_oauth2_models diff --git a/openedx/core/djangolib/tests/test_translation_utils.py b/openedx/core/djangolib/tests/test_translation_utils.py index 655504c3bb15..4b8e6ed07fa6 100644 --- a/openedx/core/djangolib/tests/test_translation_utils.py +++ b/openedx/core/djangolib/tests/test_translation_utils.py @@ -3,9 +3,9 @@ """ +import datetime import unittest -import datetime import ddt from openedx.core.djangolib.translation_utils import translate_date diff --git a/openedx/core/djangolib/translation_utils.py b/openedx/core/djangolib/translation_utils.py index 9bd5ea37773b..fc9ccfe7ca19 100644 --- a/openedx/core/djangolib/translation_utils.py +++ b/openedx/core/djangolib/translation_utils.py @@ -3,8 +3,8 @@ """ -from django.utils.translation import override from django.utils.formats import dateformat, get_format +from django.utils.translation import override def translate_date(date, language, date_format='DATE_FORMAT'): diff --git a/openedx/core/lib/__init__.py b/openedx/core/lib/__init__.py index b394a735a6cd..f0281b1f04e0 100644 --- a/openedx/core/lib/__init__.py +++ b/openedx/core/lib/__init__.py @@ -9,7 +9,6 @@ from django.conf import settings from django.core.exceptions import ImproperlyConfigured - _LMS_URLCONF = 'lms.urls' _CMS_URLCONF = 'cms.urls' diff --git a/openedx/core/lib/api/authentication.py b/openedx/core/lib/api/authentication.py index a762d398b378..04c6c53ba93c 100644 --- a/openedx/core/lib/api/authentication.py +++ b/openedx/core/lib/api/authentication.py @@ -3,10 +3,10 @@ import logging import django.utils.timezone +from edx_django_utils.monitoring import set_custom_attribute from oauth2_provider import models as dot_models -from rest_framework.exceptions import AuthenticationFailed from rest_framework.authentication import BaseAuthentication, get_authorization_header -from edx_django_utils.monitoring import set_custom_attribute +from rest_framework.exceptions import AuthenticationFailed OAUTH2_TOKEN_ERROR = 'token_error' OAUTH2_TOKEN_ERROR_EXPIRED = 'token_expired' diff --git a/openedx/core/lib/api/permissions.py b/openedx/core/lib/api/permissions.py index 7c5458684786..be999647532d 100644 --- a/openedx/core/lib/api/permissions.py +++ b/openedx/core/lib/api/permissions.py @@ -6,13 +6,13 @@ from django.conf import settings from django.http import Http404 from edx_django_utils.monitoring import set_custom_attribute +from edx_rest_framework_extensions.permissions import IsStaff, IsUserInUrl from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey from rest_framework import permissions -from edx_rest_framework_extensions.permissions import IsStaff, IsUserInUrl -from openedx.core.lib.log_utils import audit_log from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole +from openedx.core.lib.log_utils import audit_log class ApiKeyHeaderPermission(permissions.BasePermission): diff --git a/openedx/core/lib/api/tests/mixins.py b/openedx/core/lib/api/tests/mixins.py index 21da4509ec2a..e75701a771a4 100644 --- a/openedx/core/lib/api/tests/mixins.py +++ b/openedx/core/lib/api/tests/mixins.py @@ -4,9 +4,8 @@ from time import time -from django.conf import settings import jwt - +from django.conf import settings JWT_AUTH = 'JWT_AUTH' diff --git a/openedx/core/lib/api/tests/test_authentication.py b/openedx/core/lib/api/tests/test_authentication.py index 881f850cfd70..6934fb96aa8c 100644 --- a/openedx/core/lib/api/tests/test_authentication.py +++ b/openedx/core/lib/api/tests/test_authentication.py @@ -12,9 +12,9 @@ from django.http import HttpResponse from django.test import TestCase from django.test.utils import override_settings +from django.urls import path from django.utils.http import urlencode from django.utils.timezone import now -from django.urls import path from oauth2_provider import models as dot_models from rest_framework import status from rest_framework.permissions import IsAuthenticated diff --git a/openedx/core/lib/api/tests/test_view_utils.py b/openedx/core/lib/api/tests/test_view_utils.py index 2886dd806354..57c1eb79a84e 100644 --- a/openedx/core/lib/api/tests/test_view_utils.py +++ b/openedx/core/lib/api/tests/test_view_utils.py @@ -9,7 +9,9 @@ from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..view_utils import DeveloperErrorViewMixin, verify_course_exists diff --git a/openedx/core/lib/cache_utils.py b/openedx/core/lib/cache_utils.py index a889da6130ee..dd80ceb9ccd1 100644 --- a/openedx/core/lib/cache_utils.py +++ b/openedx/core/lib/cache_utils.py @@ -6,13 +6,12 @@ import collections import functools import itertools -import zlib import pickle +import zlib import wrapt -from django.db.models.signals import post_save, post_delete +from django.db.models.signals import post_delete, post_save from django.utils.encoding import force_str - from edx_django_utils.cache import RequestCache, TieredCache diff --git a/openedx/core/lib/celery/routers.py b/openedx/core/lib/celery/routers.py index 3f61bf65bf09..cf13d1bbf7b0 100644 --- a/openedx/core/lib/celery/routers.py +++ b/openedx/core/lib/celery/routers.py @@ -8,7 +8,6 @@ from django.conf import settings - log = logging.getLogger(__name__) diff --git a/openedx/core/lib/celery/task_utils.py b/openedx/core/lib/celery/task_utils.py index 10a3809fa651..845b10c76af2 100644 --- a/openedx/core/lib/celery/task_utils.py +++ b/openedx/core/lib/celery/task_utils.py @@ -6,6 +6,7 @@ from crum import CurrentRequestUserMiddleware from django.http import HttpResponse + from openedx.core.djangoapps.theming.middleware import CurrentSiteThemeMiddleware from openedx.core.lib.request_utils import get_request_or_stub diff --git a/openedx/core/lib/course_tabs.py b/openedx/core/lib/course_tabs.py index bfb9de749bc9..027e28859052 100644 --- a/openedx/core/lib/course_tabs.py +++ b/openedx/core/lib/course_tabs.py @@ -2,9 +2,9 @@ Tabs for courseware. """ -from edx_django_utils.plugins import PluginManager from functools import cmp_to_key # lint-amnesty, pylint: disable=wrong-import-order +from edx_django_utils.plugins import PluginManager # Stevedore extension point namespaces COURSE_TAB_NAMESPACE = 'openedx.course_tab' diff --git a/openedx/core/lib/courses.py b/openedx/core/lib/courses.py index 98321abfef77..df806711e9fa 100644 --- a/openedx/core/lib/courses.py +++ b/openedx/core/lib/courses.py @@ -5,10 +5,10 @@ from django import forms from django.conf import settings from django.http import Http404 - from opaque_keys import InvalidKeyError from opaque_keys.edx.locator import CourseKey from organizations.models import Organization + from xmodule.assetstore.assetmgr import AssetManager from xmodule.contentstore.content import StaticContent from xmodule.contentstore.django import contentstore diff --git a/openedx/core/lib/derived.py b/openedx/core/lib/derived.py index 745d6f1262f8..45ea0e218689 100644 --- a/openedx/core/lib/derived.py +++ b/openedx/core/lib/derived.py @@ -11,7 +11,6 @@ import types import typing as t - Settings: t.TypeAlias = types.ModuleType diff --git a/openedx/core/lib/extract_archive.py b/openedx/core/lib/extract_archive.py index 4706e0caffb7..e0175141d662 100644 --- a/openedx/core/lib/extract_archive.py +++ b/openedx/core/lib/extract_archive.py @@ -7,12 +7,11 @@ """ import logging -from os.path import abspath, dirname +from os.path import abspath, dirname, realpath from os.path import join as joinpath -from os.path import realpath +from tarfile import TarFile, TarInfo from typing import List, Union from zipfile import ZipFile, ZipInfo -from tarfile import TarFile, TarInfo from django.conf import settings from django.core.exceptions import SuspiciousOperation diff --git a/openedx/core/lib/features_setting_proxy.py b/openedx/core/lib/features_setting_proxy.py index 9de2b3c44d93..eb38ad7f9100 100644 --- a/openedx/core/lib/features_setting_proxy.py +++ b/openedx/core/lib/features_setting_proxy.py @@ -2,8 +2,7 @@ Features Proxy Implementation """ import warnings - -from collections.abc import MutableMapping, Mapping +from collections.abc import Mapping, MutableMapping class FeaturesProxy(MutableMapping): diff --git a/openedx/core/lib/gating/api.py b/openedx/core/lib/gating/api.py index 4cd53598c017..24524ced3d30 100644 --- a/openedx/core/lib/gating/api.py +++ b/openedx/core/lib/gating/api.py @@ -13,11 +13,11 @@ from opaque_keys.edx.keys import UsageKey from xblock.completable import XBlockCompletionMode as CompletionMode +from common.djangoapps.util import milestones_helpers from lms.djangoapps.course_blocks.api import get_course_blocks from lms.djangoapps.courseware.access import _has_access_to_course from lms.djangoapps.grades.api import SubsectionGradeFactory from openedx.core.lib.gating.exceptions import GatingValidationError -from common.djangoapps.util import milestones_helpers from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/core/lib/gating/tests/test_api.py b/openedx/core/lib/gating/tests/test_api.py index 58f3e4b67e32..3afe84a06a87 100644 --- a/openedx/core/lib/gating/tests/test_api.py +++ b/openedx/core/lib/gating/tests/test_api.py @@ -9,18 +9,18 @@ from ddt import data, ddt, unpack from milestones import api as milestones_api from milestones.tests.utils import MilestonesTestCaseMixin -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory from common.djangoapps.student.tests.factories import UserFactory -from openedx.core.djangolib.testing.utils import skip_unless_lms from lms.djangoapps.gating import api as lms_gating_api from lms.djangoapps.grades.constants import GradeOverrideFeatureEnum from lms.djangoapps.grades.models import PersistentSubsectionGrade, PersistentSubsectionGradeOverride from lms.djangoapps.grades.tests.base import GradeTestBase from lms.djangoapps.grades.tests.utils import mock_get_score +from openedx.core.djangolib.testing.utils import skip_unless_lms from openedx.core.lib.gating import api as gating_api from openedx.core.lib.gating.exceptions import GatingValidationError +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory @ddt diff --git a/openedx/core/lib/hash_utils.py b/openedx/core/lib/hash_utils.py index 2c7956345819..d0c283013d53 100644 --- a/openedx/core/lib/hash_utils.py +++ b/openedx/core/lib/hash_utils.py @@ -6,9 +6,10 @@ random tokens """ import hashlib -from django.utils.encoding import force_bytes -from django.utils.crypto import get_random_string + from django.conf import settings +from django.utils.crypto import get_random_string +from django.utils.encoding import force_bytes def create_hash256(max_length=None): diff --git a/openedx/core/lib/json_utils.py b/openedx/core/lib/json_utils.py index 5befd82e9d88..928c2105c770 100644 --- a/openedx/core/lib/json_utils.py +++ b/openedx/core/lib/json_utils.py @@ -4,6 +4,7 @@ import datetime + from django.core.serializers.json import DjangoJSONEncoder from opaque_keys.edx.keys import CourseKey, UsageKey diff --git a/openedx/core/lib/jwt.py b/openedx/core/lib/jwt.py index 199c6fead8c2..4223a9bd0b18 100644 --- a/openedx/core/lib/jwt.py +++ b/openedx/core/lib/jwt.py @@ -2,9 +2,9 @@ JWT Token handling and signing functions. """ -import jwt from time import time +import jwt from django.conf import settings from jwt.api_jwk import PyJWK, PyJWKSet from jwt.exceptions import ExpiredSignatureError, InvalidSignatureError, MissingRequiredClaimError diff --git a/openedx/core/lib/safe_lxml/__init__.py b/openedx/core/lib/safe_lxml/__init__.py index d7d5239c5102..6976e10d4102 100644 --- a/openedx/core/lib/safe_lxml/__init__.py +++ b/openedx/core/lib/safe_lxml/__init__.py @@ -10,6 +10,7 @@ def defuse_xml_libs(): import lxml import lxml.etree + from . import etree as safe_etree lxml.etree = safe_etree diff --git a/openedx/core/lib/safe_lxml/conftest.py b/openedx/core/lib/safe_lxml/conftest.py index afddae8356b8..c1d7878e084b 100644 --- a/openedx/core/lib/safe_lxml/conftest.py +++ b/openedx/core/lib/safe_lxml/conftest.py @@ -3,5 +3,4 @@ """ from openedx.core.lib.safe_lxml import defuse_xml_libs - defuse_xml_libs() diff --git a/openedx/core/lib/safe_lxml/etree.py b/openedx/core/lib/safe_lxml/etree.py index 9b685ac66162..d6809403e3a6 100644 --- a/openedx/core/lib/safe_lxml/etree.py +++ b/openedx/core/lib/safe_lxml/etree.py @@ -1,3 +1,4 @@ +# ruff: noqa: I001 """ Safer version of lxml.etree. @@ -5,8 +6,6 @@ It also includes a safer XMLParser. For processing xml always prefer this over using lxml.etree directly. - -isort:skip_file """ # Names are imported into this module so that it can be a stand-in for diff --git a/openedx/core/lib/safe_lxml/tests.py b/openedx/core/lib/safe_lxml/tests.py index 23e16d24d420..bd20452c29d5 100644 --- a/openedx/core/lib/safe_lxml/tests.py +++ b/openedx/core/lib/safe_lxml/tests.py @@ -3,11 +3,11 @@ """ -from lxml import etree +import pytest from defusedxml.common import EntitiesForbidden -from .xmlparser import fromstring +from lxml import etree -import pytest +from .xmlparser import fromstring def test_entities_arent_resolved_exception(): diff --git a/openedx/core/lib/teams_config.py b/openedx/core/lib/teams_config.py index 7210eed0f02f..3dac37ccd904 100644 --- a/openedx/core/lib/teams_config.py +++ b/openedx/core/lib/teams_config.py @@ -7,9 +7,10 @@ from django.utils.functional import cached_property from django.utils.translation import gettext_lazy as _ -from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag +from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag from xmodule.partitions.partitions import UserPartition, UserPartitionError + log = logging.getLogger(__name__) # "Arbitrarily large" but still limited diff --git a/openedx/core/lib/tests/test_cache_utils.py b/openedx/core/lib/tests/test_cache_utils.py index e417a72dace5..064ac6e33c4a 100644 --- a/openedx/core/lib/tests/test_cache_utils.py +++ b/openedx/core/lib/tests/test_cache_utils.py @@ -6,9 +6,9 @@ from unittest.mock import Mock import ddt -from edx_django_utils.cache import RequestCache from django.core.cache import cache from django.test.utils import override_settings +from edx_django_utils.cache import RequestCache from openedx.core.lib.cache_utils import CacheService, request_cached diff --git a/openedx/core/lib/tests/test_derived.py b/openedx/core/lib/tests/test_derived.py index 7d3f70fa6ab1..07cfd0c8c432 100644 --- a/openedx/core/lib/tests/test_derived.py +++ b/openedx/core/lib/tests/test_derived.py @@ -5,6 +5,7 @@ import sys from unittest import TestCase + from openedx.core.lib.derived import Derived, derive_settings diff --git a/openedx/core/lib/tests/test_jwt.py b/openedx/core/lib/tests/test_jwt.py index da1f047e4877..ad2dd24d4328 100644 --- a/openedx/core/lib/tests/test_jwt.py +++ b/openedx/core/lib/tests/test_jwt.py @@ -7,8 +7,7 @@ from jwt.exceptions import ExpiredSignatureError, InvalidSignatureError, MissingRequiredClaimError from openedx.core.djangolib.testing.utils import skip_unless_lms -from openedx.core.lib.jwt import _encode_and_sign, create_jwt, unpack_jwt, unpack_and_verify - +from openedx.core.lib.jwt import _encode_and_sign, create_jwt, unpack_and_verify, unpack_jwt test_user_id = 121 invalid_test_user_id = 120 diff --git a/openedx/core/lib/tests/test_request_utils.py b/openedx/core/lib/tests/test_request_utils.py index 3eedea756bde..331031719dd3 100644 --- a/openedx/core/lib/tests/test_request_utils.py +++ b/openedx/core/lib/tests/test_request_utils.py @@ -16,8 +16,8 @@ _get_ignored_error_settings_dict, clear_cached_ignored_error_settings, course_id_from_url, - ignored_error_exception_handler, get_request_or_stub, + ignored_error_exception_handler, safe_get_host, ) diff --git a/openedx/core/lib/tests/test_teams_config.py b/openedx/core/lib/tests/test_teams_config.py index c983e841c50c..e82894b963b3 100644 --- a/openedx/core/lib/tests/test_teams_config.py +++ b/openedx/core/lib/tests/test_teams_config.py @@ -6,7 +6,7 @@ import ddt from django.test import TestCase -from ..teams_config import TeamsConfig, TeamsetConfig, MANAGED_TEAM_MAX_TEAM_SIZE, DEFAULT_COURSE_RUN_MAX_TEAM_SIZE +from ..teams_config import DEFAULT_COURSE_RUN_MAX_TEAM_SIZE, MANAGED_TEAM_MAX_TEAM_SIZE, TeamsConfig, TeamsetConfig @ddt.ddt diff --git a/openedx/core/lib/tests/test_time_zone_utils.py b/openedx/core/lib/tests/test_time_zone_utils.py index c876f68be2b0..f10d08921e88 100644 --- a/openedx/core/lib/tests/test_time_zone_utils.py +++ b/openedx/core/lib/tests/test_time_zone_utils.py @@ -5,8 +5,8 @@ from freezegun import freeze_time from pytz import timezone -from openedx.core.lib.time_zone_utils import get_display_time_zone, get_time_zone_abbr, get_time_zone_offset from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.lib.time_zone_utils import get_display_time_zone, get_time_zone_abbr, get_time_zone_offset class TestTimeZoneUtils(TestCase): diff --git a/openedx/core/lib/tests/test_user_util.py b/openedx/core/lib/tests/test_user_util.py index 48d7941aa022..5292a4120d22 100644 --- a/openedx/core/lib/tests/test_user_util.py +++ b/openedx/core/lib/tests/test_user_util.py @@ -2,9 +2,10 @@ """Tests for `user_util` package.""" -import pytest from types import GeneratorType +import pytest + from openedx.core.lib import user_util VALID_SALT_LIST_ONE_SALT = ['gsw@&2p)$^p2hdk&ou0e%c=ou80o=%!+tv7(u(ircv@+96jl6$'] diff --git a/openedx/core/lib/tests/test_xblock_utils.py b/openedx/core/lib/tests/test_xblock_utils.py index 7b817f3fe6fd..60237038f35c 100644 --- a/openedx/core/lib/tests/test_xblock_utils.py +++ b/openedx/core/lib/tests/test_xblock_utils.py @@ -12,21 +12,22 @@ from opaque_keys.edx.asides import AsideUsageKeyV1, AsideUsageKeyV2 from web_fragments.fragment import Fragment from xblock.core import XBlockAside -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory -from xmodule.modulestore.tests.test_asides import AsideTestType from openedx.core.lib.url_utils import quote_slashes -from openedx.core.lib.xblock_utils import get_css_dependencies, get_js_dependencies from openedx.core.lib.xblock_utils import ( get_aside_from_xblock, + get_css_dependencies, + get_js_dependencies, is_xblock_aside, request_token, sanitize_html_id, wrap_fragment, - wrap_xblock + wrap_xblock, ) +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory +from xmodule.modulestore.tests.test_asides import AsideTestType @ddt.ddt diff --git a/openedx/core/lib/user_util.py b/openedx/core/lib/user_util.py index c15a2bac1437..76c74bb0c1a4 100644 --- a/openedx/core/lib/user_util.py +++ b/openedx/core/lib/user_util.py @@ -1,7 +1,6 @@ """Main module.""" import hashlib - RETIRED_USERNAME_DEFAULT_FMT = 'retired_username_{}' RETIRED_EMAIL_DEFAULT_FMT = 'retired_email_{}@retired.edx.org' RETIRED_EXTERNAL_KEY_DEFAULT_FMT = 'retired_external_key_{}' diff --git a/openedx/core/lib/xblock_pipeline/finder.py b/openedx/core/lib/xblock_pipeline/finder.py index 6c6791f708d4..31b9b9c501fc 100644 --- a/openedx/core/lib/xblock_pipeline/finder.py +++ b/openedx/core/lib/xblock_pipeline/finder.py @@ -2,9 +2,9 @@ Django pipeline finder for handling static assets required by XBlocks. """ +import importlib.resources as resources import os from datetime import datetime, timezone -import importlib.resources as resources from django.contrib.staticfiles import utils from django.contrib.staticfiles.finders import BaseFinder diff --git a/openedx/core/lib/xblock_serializer/block_serializer.py b/openedx/core/lib/xblock_serializer/block_serializer.py index 117f584d598a..fdfb8aeaefc2 100644 --- a/openedx/core/lib/xblock_serializer/block_serializer.py +++ b/openedx/core/lib/xblock_serializer/block_serializer.py @@ -2,17 +2,18 @@ Code for serializing a modulestore XBlock to OLX. """ from __future__ import annotations + import logging import os from lxml import etree from opaque_keys.edx.locator import LibraryLocatorV2 -from openedx.core.djangoapps.content_tagging.api import get_all_object_tags, TagValuesByObjectIdDict +from openedx.core.djangoapps.content_tagging.api import TagValuesByObjectIdDict, get_all_object_tags from xmodule.xml_block import serialize_field -from .data import StaticFile from . import utils +from .data import StaticFile log = logging.getLogger(__name__) diff --git a/openedx/core/lib/xblock_serializer/data.py b/openedx/core/lib/xblock_serializer/data.py index 141fff7dfd57..f5b50aeb18d8 100644 --- a/openedx/core/lib/xblock_serializer/data.py +++ b/openedx/core/lib/xblock_serializer/data.py @@ -2,6 +2,7 @@ Simple data structures used for XBlock serialization """ from __future__ import annotations + from typing import NamedTuple diff --git a/openedx/core/lib/xblock_serializer/test_api.py b/openedx/core/lib/xblock_serializer/test_api.py index 935700cead41..dac154d736da 100644 --- a/openedx/core/lib/xblock_serializer/test_api.py +++ b/openedx/core/lib/xblock_serializer/test_api.py @@ -3,19 +3,19 @@ """ from xml.etree import ElementTree +from openedx_tagging.models import Tag + +from openedx.core.djangoapps.content_tagging import api as tagging_api +from openedx.core.djangoapps.content_tagging.models import TaxonomyOrg from openedx.core.djangolib.testing.utils import skip_unless_cms from xmodule.modulestore.django import contentstore, modulestore from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase, upload_file_to_course -from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory, ToyCourseFactory, LibraryFactory +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory, LibraryFactory, ToyCourseFactory from xmodule.util.sandboxing import DEFAULT_PYTHON_LIB_FILENAME -from openedx_tagging.models import Tag -from openedx.core.djangoapps.content_tagging.models import TaxonomyOrg -from openedx.core.djangoapps.content_tagging import api as tagging_api from . import api from .block_serializer import XBlockSerializer - # The expected OLX string for the 'Toy_Videos' sequential in the toy course EXPECTED_SEQUENTIAL_OLX = """ diff --git a/openedx/core/lib/xblock_serializer/test_utils.py b/openedx/core/lib/xblock_serializer/test_utils.py index 7b011bf064a6..ddff66be3134 100644 --- a/openedx/core/lib/xblock_serializer/test_utils.py +++ b/openedx/core/lib/xblock_serializer/test_utils.py @@ -2,6 +2,7 @@ Test the OLX serialization utils """ from __future__ import annotations + import unittest import ddt diff --git a/openedx/core/lib/xblock_utils/__init__.py b/openedx/core/lib/xblock_utils/__init__.py index d398a159f998..b5bd76ff142a 100644 --- a/openedx/core/lib/xblock_utils/__init__.py +++ b/openedx/core/lib/xblock_utils/__init__.py @@ -9,6 +9,7 @@ import logging import re import uuid +from zoneinfo import ZoneInfo import markupsafe from django.conf import settings @@ -19,7 +20,6 @@ from edx_django_utils.plugins import pluggable_override from lxml import etree, html from opaque_keys.edx.asides import AsideUsageKeyV1, AsideUsageKeyV2 -from zoneinfo import ZoneInfo from web_fragments.fragment import Fragment from xblock.core import XBlock from xblock.exceptions import InvalidScopeError @@ -33,7 +33,7 @@ PREVIEW_VIEWS, STUDENT_VIEW, STUDIO_VIEW, - shim_xmodule_js + shim_xmodule_js, ) log = logging.getLogger(__name__) diff --git a/openedx/core/pytest_hooks.py b/openedx/core/pytest_hooks.py index 49911c92f87e..18acdbd9f11b 100644 --- a/openedx/core/pytest_hooks.py +++ b/openedx/core/pytest_hooks.py @@ -1,9 +1,9 @@ """ Module to put all pytest hooks that modify pytest behaviour """ -import os import io # lint-amnesty, pylint: disable=unused-import import json +import os def pytest_json_modifyreport(json_report): diff --git a/openedx/core/storage.py b/openedx/core/storage.py index 5dd0873d2724..b1a0d0831111 100644 --- a/openedx/core/storage.py +++ b/openedx/core/storage.py @@ -3,17 +3,18 @@ """ +from functools import lru_cache + from django.conf import settings from django.contrib.staticfiles.storage import StaticFilesStorage from django.core.files.storage import FileSystemStorage from django.utils.deconstruct import deconstructible from django.utils.module_loading import import_string -from functools import lru_cache from pipeline.storage import NonPackagingMixin from require.storage import OptimizedFilesMixin from storages.backends.s3boto3 import S3Boto3Storage -from openedx.core.djangoapps.theming.storage import ThemeManifestFilesMixin, ThemePipelineMixin, ThemeMixin +from openedx.core.djangoapps.theming.storage import ThemeManifestFilesMixin, ThemeMixin, ThemePipelineMixin class PipelineForgivingMixin: diff --git a/openedx/core/tests/test_admin_view.py b/openedx/core/tests/test_admin_view.py index 1eafb9f0debe..87a5531b26ec 100644 --- a/openedx/core/tests/test_admin_view.py +++ b/openedx/core/tests/test_admin_view.py @@ -7,8 +7,8 @@ from django.test import Client, TestCase from django.urls import reverse from edx_toggles.toggles.testutils import override_waffle_switch -from common.djangoapps.student.tests.factories import UserFactory, TEST_PASSWORD +from common.djangoapps.student.tests.factories import TEST_PASSWORD, UserFactory from openedx.core.djangoapps.user_authn.views.login import ENABLE_LOGIN_USING_THIRDPARTY_AUTH_ONLY diff --git a/openedx/core/tests/test_storage.py b/openedx/core/tests/test_storage.py index 1a15786ba58e..f826fc7bd61a 100644 --- a/openedx/core/tests/test_storage.py +++ b/openedx/core/tests/test_storage.py @@ -2,8 +2,8 @@ Tests for the get_storage utility function. """ -from django.test import TestCase, override_settings from django.core.files.storage import FileSystemStorage +from django.test import TestCase, override_settings from openedx.core.storage import get_storage diff --git a/openedx/core/toggles.py b/openedx/core/toggles.py index fd966a95cf80..a5491566448f 100644 --- a/openedx/core/toggles.py +++ b/openedx/core/toggles.py @@ -3,8 +3,8 @@ for them. Generally speaking, they should be added to the most appropriate app or repo. """ from edx_toggles.toggles import SettingToggle -from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag +from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag # .. toggle_name: ENTRANCE_EXAMS # .. toggle_implementation: SettingToggle diff --git a/openedx/core/types/__init__.py b/openedx/core/types/__init__.py index a4a4dc7e77ae..d6a4fbe420da 100644 --- a/openedx/core/types/__init__.py +++ b/openedx/core/types/__init__.py @@ -2,4 +2,5 @@ Add here typing utilities API functions and classes. """ from django.contrib.admin import display as admin_display + from .user import User diff --git a/openedx/core/write_to_html.py b/openedx/core/write_to_html.py index 8c211e113825..7b00ad6a693e 100644 --- a/openedx/core/write_to_html.py +++ b/openedx/core/write_to_html.py @@ -2,6 +2,7 @@ Class used to write pytest warning data into html format """ import textwrap + import six # lint-amnesty, pylint: disable=unused-import diff --git a/openedx/envs/common.py b/openedx/envs/common.py index 62669644d681..1b422391b8d5 100644 --- a/openedx/envs/common.py +++ b/openedx/envs/common.py @@ -25,34 +25,30 @@ def center_with_hashes(text: str, width: int = 76): print(f"{f' {text} ':#^{width}}") ``` """ -import os import importlib.util -from path import Path as path +import os from django.utils.translation import gettext_lazy as _ +from path import Path as path -from openedx.core.lib.derived import Derived -from openedx.core.release import doc_version -from openedx.core.djangoapps.theming.helpers_dirs import ( - get_themes_unchecked, - get_theme_base_dirs_from_settings -) +from lms.djangoapps.lms_xblock.mixin import LmsBlockMixin # We have legacy components that reference these constants via the settings module. # New code should import them directly from `openedx.core.constants` instead. from openedx.core.constants import ( # pylint: disable=unused-import ASSET_KEY_PATTERN, - COURSE_KEY_REGEX, - COURSE_KEY_PATTERN, COURSE_ID_PATTERN, - USAGE_KEY_PATTERN, + COURSE_KEY_PATTERN, + COURSE_KEY_REGEX, USAGE_ID_PATTERN, + USAGE_KEY_PATTERN, ) - +from openedx.core.djangoapps.theming.helpers_dirs import get_theme_base_dirs_from_settings, get_themes_unchecked +from openedx.core.lib.derived import Derived +from openedx.core.release import doc_version from xmodule.modulestore.edit_info import EditInfoMixin from xmodule.modulestore.inheritance import InheritanceMixin from xmodule.x_module import XModuleMixin -from lms.djangoapps.lms_xblock.mixin import LmsBlockMixin ################ Shared Functions for Derived Configuration ################ diff --git a/openedx/envs/test.py b/openedx/envs/test.py index 66558c2c8e26..8c0fafe6c372 100644 --- a/openedx/envs/test.py +++ b/openedx/envs/test.py @@ -1,3 +1,4 @@ +# ruff: noqa: I001 - settings file: star-import order is semantically significant """ Common test related Django settings for Open edX services. @@ -5,15 +6,13 @@ rather than duplicated or imported accross services. """ import os -from path import Path as path from uuid import uuid4 from django.utils.translation import gettext_lazy - -from openedx.core.lib.derived import Derived +from path import Path as path from common.djangoapps.util.testing import patch_sessions, patch_testcase - +from openedx.core.lib.derived import Derived # This patch disables the commit_on_success decorator during tests # in TestCase subclasses. diff --git a/openedx/features/calendar_sync/ics.py b/openedx/features/calendar_sync/ics.py index c6d3a03a1ccf..c06a7f180ad0 100644 --- a/openedx/features/calendar_sync/ics.py +++ b/openedx/features/calendar_sync/ics.py @@ -1,8 +1,8 @@ """ Generate .ics files from a user schedule """ from datetime import datetime, timedelta - from zoneinfo import ZoneInfo + from django.conf import settings from django.utils.translation import gettext as _ from icalendar import Calendar, Event, vCalAddress, vText diff --git a/openedx/features/calendar_sync/plugins.py b/openedx/features/calendar_sync/plugins.py index 75178a1ace7f..792216d053e7 100644 --- a/openedx/features/calendar_sync/plugins.py +++ b/openedx/features/calendar_sync/plugins.py @@ -6,11 +6,11 @@ from django.urls import reverse from django.utils.translation import gettext as _ +from common.djangoapps.student.models import CourseEnrollment from openedx.features.calendar_sync.api import SUBSCRIBE, UNSUBSCRIBE from openedx.features.calendar_sync.models import UserCalendarSyncConfig from openedx.features.course_experience import CALENDAR_SYNC_FLAG, RELATIVE_DATES_FLAG from openedx.features.course_experience.course_tools import CourseTool, HttpMethod -from common.djangoapps.student.models import CourseEnrollment class CalendarSyncToggleTool(CourseTool): diff --git a/openedx/features/calendar_sync/tests/test_api.py b/openedx/features/calendar_sync/tests/test_api.py index 331aa2b9ba8d..feb2899d882d 100644 --- a/openedx/features/calendar_sync/tests/test_api.py +++ b/openedx/features/calendar_sync/tests/test_api.py @@ -4,7 +4,9 @@ from common.djangoapps.student.tests.factories import UserFactory from openedx.features.calendar_sync.api import subscribe_user_to_calendar, unsubscribe_user_to_calendar from openedx.features.calendar_sync.models import UserCalendarSyncConfig -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order TEST_PASSWORD = 'test' diff --git a/openedx/features/calendar_sync/tests/test_ics.py b/openedx/features/calendar_sync/tests/test_ics.py index 73327b09a964..a343d6e3e0fe 100644 --- a/openedx/features/calendar_sync/tests/test_ics.py +++ b/openedx/features/calendar_sync/tests/test_ics.py @@ -2,8 +2,8 @@ from datetime import datetime, timedelta from unittest.mock import patch - from zoneinfo import ZoneInfo + from django.test import RequestFactory, TestCase from freezegun import freeze_time diff --git a/openedx/features/calendar_sync/tests/test_models.py b/openedx/features/calendar_sync/tests/test_models.py index e64ef5bd3752..459856c58952 100644 --- a/openedx/features/calendar_sync/tests/test_models.py +++ b/openedx/features/calendar_sync/tests/test_models.py @@ -3,7 +3,9 @@ from common.djangoapps.student.tests.factories import UserFactory from openedx.features.calendar_sync.models import UserCalendarSyncConfig -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order TEST_PASSWORD = 'test' diff --git a/openedx/features/calendar_sync/tests/test_plugins.py b/openedx/features/calendar_sync/tests/test_plugins.py index 2f2fba4045d1..93ef09f25ef1 100644 --- a/openedx/features/calendar_sync/tests/test_plugins.py +++ b/openedx/features/calendar_sync/tests/test_plugins.py @@ -10,7 +10,10 @@ from openedx.features.calendar_sync.plugins import CalendarSyncToggleTool from openedx.features.course_experience import CALENDAR_SYNC_FLAG, RELATIVE_DATES_FLAG -from xmodule.modulestore.tests.django_utils import CourseUserType, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order + CourseUserType, + SharedModuleStoreTestCase, +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/features/calendar_sync/tests/test_views.py b/openedx/features/calendar_sync/tests/test_views.py index 0b566aeb1a64..af7f51d771e1 100644 --- a/openedx/features/calendar_sync/tests/test_views.py +++ b/openedx/features/calendar_sync/tests/test_views.py @@ -8,7 +8,9 @@ from django.urls import reverse from openedx.features.calendar_sync.api import SUBSCRIBE, UNSUBSCRIBE -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order TEST_PASSWORD = 'test' diff --git a/openedx/features/calendar_sync/urls.py b/openedx/features/calendar_sync/urls.py index 22367f3a961c..b3fff2d34210 100644 --- a/openedx/features/calendar_sync/urls.py +++ b/openedx/features/calendar_sync/urls.py @@ -3,6 +3,7 @@ """ from django.urls import path + from .views.calendar_sync import CalendarSyncView urlpatterns = [ diff --git a/openedx/features/calendar_sync/utils.py b/openedx/features/calendar_sync/utils.py index ff6f6a662e12..7d26449d6046 100644 --- a/openedx/features/calendar_sync/utils.py +++ b/openedx/features/calendar_sync/utils.py @@ -1,13 +1,14 @@ # lint-amnesty, pylint: disable=missing-module-docstring import logging +import os # lint-amnesty, pylint: disable=wrong-import-order from email.mime.application import MIMEApplication from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText + +import boto3 from django.conf import settings from django.utils.html import format_html from django.utils.translation import gettext_lazy as _ -import os # lint-amnesty, pylint: disable=wrong-import-order -import boto3 logger = logging.getLogger(__name__) diff --git a/openedx/features/calendar_sync/views/calendar_sync.py b/openedx/features/calendar_sync/views/calendar_sync.py index 20f182daffd2..3e86525d3f2c 100644 --- a/openedx/features/calendar_sync/views/calendar_sync.py +++ b/openedx/features/calendar_sync/views/calendar_sync.py @@ -19,7 +19,7 @@ SUBSCRIBE, UNSUBSCRIBE, subscribe_user_to_calendar, - unsubscribe_user_to_calendar + unsubscribe_user_to_calendar, ) from openedx.features.course_experience import course_home_url diff --git a/openedx/features/content_type_gating/admin.py b/openedx/features/content_type_gating/admin.py index 3f4f58d2585f..ce69e62cc568 100644 --- a/openedx/features/content_type_gating/admin.py +++ b/openedx/features/content_type_gating/admin.py @@ -9,5 +9,4 @@ from .models import ContentTypeGatingConfig - admin.site.register(ContentTypeGatingConfig, StackedConfigModelAdmin) diff --git a/openedx/features/content_type_gating/helpers.py b/openedx/features/content_type_gating/helpers.py index 05323d7c57f8..85f18e49080a 100644 --- a/openedx/features/content_type_gating/helpers.py +++ b/openedx/features/content_type_gating/helpers.py @@ -7,9 +7,9 @@ from django.utils import timezone from common.djangoapps.course_modes.models import CourseMode -from openedx.core.djangoapps.config_model_utils.utils import is_in_holdback from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.role_helpers import has_staff_roles +from openedx.core.djangoapps.config_model_utils.utils import is_in_holdback from xmodule.partitions.partitions import Group # lint-amnesty, pylint: disable=wrong-import-order # Studio generates partition IDs starting at 100. There is already a manually generated @@ -80,8 +80,11 @@ def has_full_access_role_in_masquerade(user, course_key): """ # The masquerade module imports from us, so avoid a circular dependency here from lms.djangoapps.courseware.masquerade import ( - get_course_masquerade, is_masquerading_as_full_access, is_masquerading_as_non_audit_enrollment, - is_masquerading_as_specific_student, is_masquerading_as_staff, + get_course_masquerade, + is_masquerading_as_full_access, + is_masquerading_as_non_audit_enrollment, + is_masquerading_as_specific_student, + is_masquerading_as_staff, ) course_masquerade = get_course_masquerade(user, course_key) diff --git a/openedx/features/content_type_gating/models.py b/openedx/features/content_type_gating/models.py index 2756322db6e1..2594143c2a4c 100644 --- a/openedx/features/content_type_gating/models.py +++ b/openedx/features/content_type_gating/models.py @@ -5,7 +5,6 @@ from django.core.exceptions import ValidationError from django.db import models from django.utils import timezone - from django.utils.translation import gettext_lazy as _ from openedx.core.djangoapps.config_model_utils.models import StackedConfigurationModel diff --git a/openedx/features/content_type_gating/partitions.py b/openedx/features/content_type_gating/partitions.py index a5e833f60bc5..ec8698a46f8f 100644 --- a/openedx/features/content_type_gating/partitions.py +++ b/openedx/features/content_type_gating/partitions.py @@ -8,9 +8,9 @@ import datetime import logging +from zoneinfo import ZoneInfo import crum -from zoneinfo import ZoneInfo from django.template.loader import render_to_string from django.utils.translation import gettext_lazy as _ from web_fragments.fragment import Fragment @@ -22,7 +22,10 @@ from openedx.features.content_type_gating.helpers import CONTENT_GATING_PARTITION_ID, FULL_ACCESS, LIMITED_ACCESS from openedx.features.content_type_gating.models import ContentTypeGatingConfig from openedx.features.discounts.utils import format_strikeout_price -from xmodule.partitions.partitions import UserPartition, UserPartitionError # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.partitions.partitions import ( # lint-amnesty, pylint: disable=wrong-import-order + UserPartition, + UserPartitionError, +) LOG = logging.getLogger(__name__) diff --git a/openedx/features/content_type_gating/services.py b/openedx/features/content_type_gating/services.py index 363fd8168876..8cee754a7e8c 100644 --- a/openedx/features/content_type_gating/services.py +++ b/openedx/features/content_type_gating/services.py @@ -4,9 +4,7 @@ import crum from lms.djangoapps.courseware.access import has_access -from lms.djangoapps.courseware.masquerade import ( - is_masquerading_as_limited_access, is_masquerading_as_audit_enrollment, -) +from lms.djangoapps.courseware.masquerade import is_masquerading_as_audit_enrollment, is_masquerading_as_limited_access from openedx.core.lib.graph_traversals import get_children, leaf_filter, traverse_pre_order from openedx.features.content_type_gating.models import ContentTypeGatingConfig diff --git a/openedx/features/content_type_gating/tests/test_access.py b/openedx/features/content_type_gating/tests/test_access.py index 3e3dae129801..04a79f9edff4 100644 --- a/openedx/features/content_type_gating/tests/test_access.py +++ b/openedx/features/content_type_gating/tests/test_access.py @@ -2,30 +2,32 @@ Test audit user's access to various content based on content-gating features. """ from datetime import datetime, timedelta -from unittest.mock import patch, Mock +from unittest.mock import Mock, patch import ddt from django.conf import settings -from django.test.client import RequestFactory, Client +from django.contrib.auth import get_user_model +from django.test.client import Client, RequestFactory from django.test.utils import override_settings from django.urls import reverse from django.utils import timezone -from django.contrib.auth import get_user_model from pyquery import PyQuery as pq -from xmodule.modulestore.tests.django_utils import ( - TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase, SharedModuleStoreTestCase, -) -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory -from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID -from lms.djangoapps.course_api.blocks.api import get_blocks from common.djangoapps.course_modes.tests.factories import CourseModeFactory -from common.djangoapps.student.tests.factories import BetaTesterFactory -from common.djangoapps.student.tests.factories import GlobalStaffFactory -from common.djangoapps.student.tests.factories import InstructorFactory -from common.djangoapps.student.tests.factories import OrgInstructorFactory -from common.djangoapps.student.tests.factories import OrgStaffFactory -from common.djangoapps.student.tests.factories import StaffFactory +from common.djangoapps.student.models import CourseEnrollment, FBEEnrollmentExclusion +from common.djangoapps.student.roles import CourseInstructorRole +from common.djangoapps.student.tests.factories import ( + TEST_PASSWORD, + BetaTesterFactory, + CourseEnrollmentFactory, + GlobalStaffFactory, + InstructorFactory, + OrgInstructorFactory, + OrgStaffFactory, + StaffFactory, + UserFactory, +) +from lms.djangoapps.course_api.blocks.api import get_blocks from lms.djangoapps.courseware.block_render import load_single_xblock from lms.djangoapps.courseware.tests.helpers import MasqueradeMixin from lms.djangoapps.discussion.django_comment_client.tests.factories import RoleFactory @@ -33,7 +35,7 @@ FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_GROUP_MODERATOR, - FORUM_ROLE_MODERATOR + FORUM_ROLE_MODERATOR, ) from openedx.core.djangoapps.user_api.tests.factories import UserCourseTagFactory from openedx.core.djangoapps.util.testing import TestConditionalContent @@ -43,9 +45,13 @@ from openedx.features.content_type_gating.models import ContentTypeGatingConfig from openedx.features.content_type_gating.partitions import ContentTypeGatingPartition from openedx.features.content_type_gating.services import ContentTypeGatingService -from common.djangoapps.student.models import CourseEnrollment, FBEEnrollmentExclusion -from common.djangoapps.student.roles import CourseInstructorRole -from common.djangoapps.student.tests.factories import TEST_PASSWORD, CourseEnrollmentFactory, UserFactory +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_SPLIT_MODULESTORE, + ModuleStoreTestCase, + SharedModuleStoreTestCase, +) +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory +from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID METADATA = { 'group_access': { diff --git a/openedx/features/content_type_gating/tests/test_models.py b/openedx/features/content_type_gating/tests/test_models.py index 53d94439fd6c..14022d451657 100644 --- a/openedx/features/content_type_gating/tests/test_models.py +++ b/openedx/features/content_type_gating/tests/test_models.py @@ -1,25 +1,23 @@ # pylint: disable=missing-module-docstring -import pytest - - import itertools # lint-amnesty, pylint: disable=wrong-import-order from datetime import datetime, timedelta # lint-amnesty, pylint: disable=wrong-import-order +from unittest.mock import Mock # lint-amnesty, pylint: disable=wrong-import-order +from zoneinfo import ZoneInfo import ddt -from zoneinfo import ZoneInfo +import pytest from django.utils import timezone from edx_django_utils.cache import RequestCache -from unittest.mock import Mock # lint-amnesty, pylint: disable=wrong-import-order from opaque_keys.edx.locator import CourseLocator from common.djangoapps.course_modes.tests.factories import CourseModeFactory +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from openedx.core.djangoapps.config_model_utils.models import Provenance from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES from openedx.core.djangolib.testing.utils import AUTHZ_TABLES, CacheIsolationTestCase, FilteredQueryCountMixin from openedx.features.content_type_gating.models import ContentTypeGatingConfig -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory QUERY_COUNT_TABLE_IGNORELIST = WAFFLE_TABLES + AUTHZ_TABLES diff --git a/openedx/features/content_type_gating/tests/test_partitions.py b/openedx/features/content_type_gating/tests/test_partitions.py index aba6914a566f..ebd02980b8bd 100644 --- a/openedx/features/content_type_gating/tests/test_partitions.py +++ b/openedx/features/content_type_gating/tests/test_partitions.py @@ -1,16 +1,17 @@ # pylint: disable=missing-module-docstring from datetime import datetime -from django.test import RequestFactory from unittest.mock import Mock, patch # lint-amnesty, pylint: disable=wrong-import-order + +from django.test import RequestFactory from opaque_keys.edx.keys import CourseKey from common.djangoapps.course_modes.tests.factories import CourseModeFactory from common.djangoapps.student.tests.factories import GlobalStaffFactory +from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangolib.testing.utils import CacheIsolationTestCase from openedx.features.content_type_gating.helpers import CONTENT_GATING_PARTITION_ID, FULL_ACCESS, LIMITED_ACCESS from openedx.features.content_type_gating.models import ContentTypeGatingConfig from openedx.features.content_type_gating.partitions import create_content_gating_partition -from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from xmodule.partitions.partitions import UserPartitionError # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/features/course_bookmarks/plugins.py b/openedx/features/course_bookmarks/plugins.py index 895a7df26719..ac2a5654e87d 100644 --- a/openedx/features/course_bookmarks/plugins.py +++ b/openedx/features/course_bookmarks/plugins.py @@ -6,9 +6,9 @@ from django.urls import reverse from django.utils.translation import gettext as _ +from common.djangoapps.student.models import CourseEnrollment from lms.djangoapps.courseware.permissions import EDIT_BOOKMARK from openedx.features.course_experience.course_tools import CourseTool -from common.djangoapps.student.models import CourseEnrollment class CourseBookmarksTool(CourseTool): diff --git a/openedx/features/course_bookmarks/tests/test_course_bookmarks.py b/openedx/features/course_bookmarks/tests/test_course_bookmarks.py index 313ea3d3b15a..d6d90d72ff3c 100644 --- a/openedx/features/course_bookmarks/tests/test_course_bookmarks.py +++ b/openedx/features/course_bookmarks/tests/test_course_bookmarks.py @@ -8,7 +8,7 @@ from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import CourseUserType, SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory from ..plugins import CourseBookmarksTool diff --git a/openedx/features/course_bookmarks/urls.py b/openedx/features/course_bookmarks/urls.py index 441d2b0d10d8..d19055793531 100644 --- a/openedx/features/course_bookmarks/urls.py +++ b/openedx/features/course_bookmarks/urls.py @@ -3,6 +3,7 @@ """ from django.urls import path + from .views.course_bookmarks import CourseBookmarksFragmentView, CourseBookmarksView urlpatterns = [ diff --git a/openedx/features/course_bookmarks/views/course_bookmarks.py b/openedx/features/course_bookmarks/views/course_bookmarks.py index 7cdab73fc381..7fc4f41ea2cd 100644 --- a/openedx/features/course_bookmarks/views/course_bookmarks.py +++ b/openedx/features/course_bookmarks/views/course_bookmarks.py @@ -16,11 +16,11 @@ from opaque_keys.edx.keys import CourseKey from web_fragments.fragment import Fragment +from common.djangoapps.util.views import ensure_valid_course_key from lms.djangoapps.courseware.courses import get_course_with_access from openedx.core.djangoapps.plugin_api.views import EdxFragmentView from openedx.core.djangoapps.user_api.models import UserPreference from openedx.features.course_experience import default_course_url -from common.djangoapps.util.views import ensure_valid_course_key class CourseBookmarksView(View): diff --git a/openedx/features/course_duration_limits/access.py b/openedx/features/course_duration_limits/access.py index 8f73ae2266ea..90948da46816 100644 --- a/openedx/features/course_duration_limits/access.py +++ b/openedx/features/course_duration_limits/access.py @@ -13,8 +13,8 @@ from common.djangoapps.util.date_utils import strftime_localized, strftime_localized_html from lms.djangoapps.courseware.access_response import AccessError from lms.djangoapps.courseware.access_utils import ACCESS_GRANTED -from lms.djangoapps.courseware.utils import verified_upgrade_deadline_link from lms.djangoapps.courseware.masquerade import get_course_masquerade, is_masquerading_as_specific_student +from lms.djangoapps.courseware.utils import verified_upgrade_deadline_link from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.course_date_signals.utils import get_expected_duration from openedx.core.djangolib.markup import HTML diff --git a/openedx/features/course_duration_limits/models.py b/openedx/features/course_duration_limits/models.py index fc80adb48125..fbb4fc1bacd5 100644 --- a/openedx/features/course_duration_limits/models.py +++ b/openedx/features/course_duration_limits/models.py @@ -5,7 +5,6 @@ from django.core.exceptions import ValidationError from django.db import models from django.utils import timezone - from django.utils.translation import gettext_lazy as _ from openedx.core.djangoapps.config_model_utils.models import StackedConfigurationModel diff --git a/openedx/features/course_duration_limits/tests/test_access.py b/openedx/features/course_duration_limits/tests/test_access.py index f948324b48b3..51894aa4d883 100644 --- a/openedx/features/course_duration_limits/tests/test_access.py +++ b/openedx/features/course_duration_limits/tests/test_access.py @@ -3,13 +3,12 @@ import itertools from datetime import datetime, timedelta +from zoneinfo import ZoneInfo import ddt from crum import set_current_request from django.test import RequestFactory from django.utils import timezone -from zoneinfo import ZoneInfo -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory @@ -23,9 +22,10 @@ generate_course_expired_message, get_access_expiration_data, get_user_course_duration, - get_user_course_expiration_date + get_user_course_expiration_date, ) from openedx.features.course_duration_limits.models import CourseDurationLimitConfig +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase @ddt.ddt diff --git a/openedx/features/course_duration_limits/tests/test_course_expiration.py b/openedx/features/course_duration_limits/tests/test_course_expiration.py index de7c1d20d768..cee436f4b38b 100644 --- a/openedx/features/course_duration_limits/tests/test_course_expiration.py +++ b/openedx/features/course_duration_limits/tests/test_course_expiration.py @@ -10,20 +10,21 @@ from django.conf import settings from django.urls import reverse from django.utils.timezone import now -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory -from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import CourseEnrollment, FBEEnrollmentExclusion from common.djangoapps.student.roles import CourseInstructorRole -from common.djangoapps.student.tests.factories import BetaTesterFactory -from common.djangoapps.student.tests.factories import TEST_PASSWORD, CourseEnrollmentFactory, UserFactory -from common.djangoapps.student.tests.factories import GlobalStaffFactory -from common.djangoapps.student.tests.factories import InstructorFactory -from common.djangoapps.student.tests.factories import OrgInstructorFactory -from common.djangoapps.student.tests.factories import OrgStaffFactory -from common.djangoapps.student.tests.factories import StaffFactory +from common.djangoapps.student.tests.factories import ( + TEST_PASSWORD, + BetaTesterFactory, + CourseEnrollmentFactory, + GlobalStaffFactory, + InstructorFactory, + OrgInstructorFactory, + OrgStaffFactory, + StaffFactory, + UserFactory, +) from lms.djangoapps.courseware.tests.helpers import MasqueradeMixin from lms.djangoapps.discussion.django_comment_client.tests.factories import RoleFactory from openedx.core.djangoapps.content.course_overviews.models import CourseOverview @@ -32,13 +33,16 @@ FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_GROUP_MODERATOR, - FORUM_ROLE_MODERATOR + FORUM_ROLE_MODERATOR, ) from openedx.core.djangoapps.schedules.models import Schedule from openedx.features.content_type_gating.helpers import CONTENT_GATING_PARTITION_ID, CONTENT_TYPE_GATE_GROUP_IDS from openedx.features.course_duration_limits.access import get_user_course_expiration_date from openedx.features.course_duration_limits.models import CourseDurationLimitConfig from openedx.features.course_experience.tests.views.helpers import add_course_mode +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory +from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID # pylint: disable=no-member diff --git a/openedx/features/course_duration_limits/tests/test_models.py b/openedx/features/course_duration_limits/tests/test_models.py index 5fdbc08d5b70..f6f1a8027597 100644 --- a/openedx/features/course_duration_limits/tests/test_models.py +++ b/openedx/features/course_duration_limits/tests/test_models.py @@ -5,10 +5,10 @@ import itertools from datetime import datetime, timedelta from unittest.mock import Mock +from zoneinfo import ZoneInfo import ddt import pytest -from zoneinfo import ZoneInfo from django.utils import timezone from edx_django_utils.cache import RequestCache from opaque_keys.edx.locator import CourseLocator diff --git a/openedx/features/course_experience/__init__.py b/openedx/features/course_experience/__init__.py index 1305879f1cb8..ccc84772fb75 100644 --- a/openedx/features/course_experience/__init__.py +++ b/openedx/features/course_experience/__init__.py @@ -5,10 +5,10 @@ from django.urls import reverse from django.utils.translation import gettext as _ from edx_toggles.toggles import WaffleFlag -from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag from openedx_filters.exceptions import OpenEdxFilterException from openedx_filters.learning.filters import CourseHomeUrlCreationStarted +from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag # Namespace for course experience waffle flags. WAFFLE_FLAG_NAMESPACE = 'course_experience' diff --git a/openedx/features/course_experience/api/v1/serializers.py b/openedx/features/course_experience/api/v1/serializers.py index 10f2a785d1b0..40fb42eb040b 100644 --- a/openedx/features/course_experience/api/v1/serializers.py +++ b/openedx/features/course_experience/api/v1/serializers.py @@ -1,9 +1,8 @@ """ Serializer for Course Deadlines (Mobile) """ -from rest_framework import serializers - from opaque_keys.edx.keys import CourseKey +from rest_framework import serializers from lms.djangoapps.course_home_api.serializers import DatesBannerSerializer from openedx.core.djangoapps.content.course_overviews.models import CourseOverview diff --git a/openedx/features/course_experience/api/v1/tests/test_utils.py b/openedx/features/course_experience/api/v1/tests/test_utils.py index 741a2d7658f1..45355650539e 100644 --- a/openedx/features/course_experience/api/v1/tests/test_utils.py +++ b/openedx/features/course_experience/api/v1/tests/test_utils.py @@ -14,9 +14,9 @@ from lms.djangoapps.courseware.tests.helpers import MasqueradeMixin from openedx.core.djangoapps.schedules.models import Schedule from openedx.features.course_experience.api.v1.utils import ( - reset_deadlines_for_course, + reset_bulk_course_deadlines, reset_course_deadlines_for_user, - reset_bulk_course_deadlines + reset_deadlines_for_course, ) from xmodule.modulestore.tests.factories import CourseFactory diff --git a/openedx/features/course_experience/api/v1/urls.py b/openedx/features/course_experience/api/v1/urls.py index 2c84af437f70..22c2f5c4373a 100644 --- a/openedx/features/course_experience/api/v1/urls.py +++ b/openedx/features/course_experience/api/v1/urls.py @@ -4,12 +4,12 @@ from django.conf import settings -from django.urls import re_path, path +from django.urls import path, re_path from openedx.features.course_experience.api.v1.views import ( - reset_course_deadlines, - reset_all_course_deadlines, CourseDeadlinesMobileView, + reset_all_course_deadlines, + reset_course_deadlines, ) urlpatterns = [] diff --git a/openedx/features/course_experience/api/v1/utils.py b/openedx/features/course_experience/api/v1/utils.py index 8f9205b0f113..2da78a0c499f 100644 --- a/openedx/features/course_experience/api/v1/utils.py +++ b/openedx/features/course_experience/api/v1/utils.py @@ -3,15 +3,15 @@ Course Experience API utilities. """ import logging + from eventtracking import tracker +from lms.djangoapps.course_api.api import course_detail from lms.djangoapps.courseware.access import has_access from lms.djangoapps.courseware.masquerade import is_masquerading, setup_masquerade -from lms.djangoapps.course_api.api import course_detail from openedx.core.djangoapps.schedules.utils import reset_self_paced_schedule from openedx.features.course_experience.utils import dates_banner_should_display - logger = logging.getLogger(__name__) diff --git a/openedx/features/course_experience/api/v1/views.py b/openedx/features/course_experience/api/v1/views.py index d822fdd65c67..978fa1ed3868 100644 --- a/openedx/features/course_experience/api/v1/views.py +++ b/openedx/features/course_experience/api/v1/views.py @@ -5,25 +5,22 @@ from django.utils.html import format_html from django.utils.translation import gettext as _ - +from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication +from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser +from opaque_keys.edx.keys import CourseKey from rest_framework.decorators import api_view, authentication_classes, permission_classes from rest_framework.exceptions import APIException, ParseError +from rest_framework.generics import RetrieveAPIView from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response -from rest_framework.generics import RetrieveAPIView - -from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication -from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser -from opaque_keys.edx.keys import CourseKey from common.djangoapps.student.models import CourseEnrollment from lms.djangoapps.course_goals.models import UserActivity from lms.djangoapps.courseware.courses import get_course_with_access - from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser from openedx.features.course_experience.api.v1.serializers import CourseDeadlinesMobileSerializer +from openedx.features.course_experience.api.v1.utils import reset_bulk_course_deadlines, reset_deadlines_for_course from openedx.features.course_experience.url_helpers import get_learning_mfe_home_url -from openedx.features.course_experience.api.v1.utils import reset_deadlines_for_course, reset_bulk_course_deadlines log = logging.getLogger(__name__) diff --git a/openedx/features/course_experience/tests/__init__.py b/openedx/features/course_experience/tests/__init__.py index 9581c095a446..2a59791e1b03 100644 --- a/openedx/features/course_experience/tests/__init__.py +++ b/openedx/features/course_experience/tests/__init__.py @@ -8,8 +8,13 @@ from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) class BaseCourseUpdatesTestCase(SharedModuleStoreTestCase): diff --git a/openedx/features/course_experience/tests/test_course_updates.py b/openedx/features/course_experience/tests/test_course_updates.py index accad1734f0c..4117d4b5da1e 100644 --- a/openedx/features/course_experience/tests/test_course_updates.py +++ b/openedx/features/course_experience/tests/test_course_updates.py @@ -6,7 +6,9 @@ from openedx.core.djangoapps.user_api.course_tag.api import get_course_tag, set_course_tag from openedx.features.course_experience.course_updates import ( - dismiss_current_update_for_user, get_current_update_for_user, get_ordered_updates, + dismiss_current_update_for_user, + get_current_update_for_user, + get_ordered_updates, ) from openedx.features.course_experience.tests import BaseCourseUpdatesTestCase diff --git a/openedx/features/course_experience/tests/test_url_helpers.py b/openedx/features/course_experience/tests/test_url_helpers.py index 96baaeb2a55d..edab9610823d 100644 --- a/openedx/features/course_experience/tests/test_url_helpers.py +++ b/openedx/features/course_experience/tests/test_url_helpers.py @@ -1,14 +1,15 @@ """ Test some of the functions in url_helpers """ +from unittest.mock import patch + import ddt from django.test import TestCase from django.test.client import RequestFactory from django.test.utils import override_settings -from unittest.mock import patch from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory from .. import url_helpers diff --git a/openedx/features/course_experience/tests/views/test_course_updates.py b/openedx/features/course_experience/tests/views/test_course_updates.py index aff8700bc44e..68f8620474d3 100644 --- a/openedx/features/course_experience/tests/views/test_course_updates.py +++ b/openedx/features/course_experience/tests/views/test_course_updates.py @@ -3,9 +3,9 @@ """ from datetime import datetime +from zoneinfo import ZoneInfo from django.urls import reverse -from zoneinfo import ZoneInfo from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES from openedx.core.djangolib.testing.utils import AUTHZ_TABLES diff --git a/openedx/features/course_experience/tests/views/test_masquerade.py b/openedx/features/course_experience/tests/views/test_masquerade.py index f0c110d8e9aa..4269f4e60c2e 100644 --- a/openedx/features/course_experience/tests/views/test_masquerade.py +++ b/openedx/features/course_experience/tests/views/test_masquerade.py @@ -2,12 +2,16 @@ Tests for masquerading functionality on course_experience """ -from lms.djangoapps.courseware.tests.helpers import MasqueradeMixin from common.djangoapps.student.roles import CourseStaffRole from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from lms.djangoapps.courseware.tests.helpers import MasqueradeMixin +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.partitions.partitions import ( + ENROLLMENT_TRACK_PARTITION_ID, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.partitions.partitions_service import PartitionService # lint-amnesty, pylint: disable=wrong-import-order from .helpers import add_course_mode diff --git a/openedx/features/course_experience/url_helpers.py b/openedx/features/course_experience/url_helpers.py index e70019dbe25b..ce86d6605490 100644 --- a/openedx/features/course_experience/url_helpers.py +++ b/openedx/features/course_experience/url_helpers.py @@ -5,20 +5,19 @@ because the Studio course outline may need these utilities. """ from typing import Optional +from urllib.parse import urlparse from django.conf import settings from django.contrib.auth import get_user_model from django.http import HttpRequest from django.http.request import QueryDict from opaque_keys.edx.keys import CourseKey, UsageKey -from urllib.parse import urlparse +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.search import path_to_location # lint-amnesty, pylint: disable=wrong-import-order -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers - User = get_user_model() diff --git a/openedx/features/course_experience/urls.py b/openedx/features/course_experience/urls.py index ac560d43f9f1..8edb0f75ffdf 100644 --- a/openedx/features/course_experience/urls.py +++ b/openedx/features/course_experience/urls.py @@ -3,6 +3,7 @@ """ from django.urls import path + from .views.course_home import outline_tab from .views.course_updates import CourseUpdatesView diff --git a/openedx/features/course_experience/utils.py b/openedx/features/course_experience/utils.py index c20b7f077136..ab1a58bee16d 100644 --- a/openedx/features/course_experience/utils.py +++ b/openedx/features/course_experience/utils.py @@ -5,12 +5,12 @@ from django.utils import timezone from opaque_keys.edx.keys import CourseKey +from common.djangoapps.student.models import CourseEnrollment from lms.djangoapps.course_api.blocks.api import get_blocks from lms.djangoapps.course_blocks.api import get_course_blocks from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.lib.cache_utils import request_cached from openedx.features.course_experience import RELATIVE_DATES_DISABLE_RESET_FLAG, RELATIVE_DATES_FLAG -from common.djangoapps.student.models import CourseEnrollment from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/features/course_experience/views/course_dates.py b/openedx/features/course_experience/views/course_dates.py index e9f1a8d574b6..5713a7410a06 100644 --- a/openedx/features/course_experience/views/course_dates.py +++ b/openedx/features/course_experience/views/course_dates.py @@ -9,8 +9,8 @@ from lms.djangoapps.courseware.courses import get_course_date_blocks, get_course_with_access from lms.djangoapps.courseware.tabs import DatesTab -from openedx.features.course_experience.url_helpers import get_learning_mfe_home_url from openedx.core.djangoapps.plugin_api.views import EdxFragmentView +from openedx.features.course_experience.url_helpers import get_learning_mfe_home_url class CourseDatesFragmentView(EdxFragmentView): diff --git a/openedx/features/discounts/applicability.py b/openedx/features/discounts/applicability.py index c930ae2da878..89ddc1d59b71 100644 --- a/openedx/features/discounts/applicability.py +++ b/openedx/features/discounts/applicability.py @@ -10,8 +10,8 @@ from datetime import datetime, timedelta - from zoneinfo import ZoneInfo + from crum import get_current_request, impersonate from django.conf import settings from django.utils import timezone @@ -20,14 +20,13 @@ from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.entitlements.models import CourseEntitlement -from lms.djangoapps.courseware.utils import is_mode_upsellable +from common.djangoapps.student.models import CourseEnrollment +from common.djangoapps.track import segment from lms.djangoapps.courseware.toggles import COURSEWARE_MFE_MILESTONES_STREAK_DISCOUNT +from lms.djangoapps.courseware.utils import is_mode_upsellable from lms.djangoapps.experiments.models import ExperimentData from lms.djangoapps.experiments.stable_bucketing import stable_bucketing_hash_group from openedx.features.discounts.models import DiscountPercentageConfig, DiscountRestrictionConfig -from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.track import segment - # .. toggle_name: discounts.enable_first_purchase_discount_override # .. toggle_implementation: WaffleFlag @@ -127,6 +126,7 @@ def can_show_streak_discount_coupon(user, course): # We can't import this at Django load time within the openedx tests settings context from openedx.features.enterprise_support.utils import is_enterprise_learner + # Don't give discount to enterprise users if is_enterprise_learner(user): return False @@ -181,6 +181,7 @@ def can_receive_discount(user, course, discount_expiration_date=None): # We can't import this at Django load time within the openedx tests settings context from openedx.features.enterprise_support.utils import is_enterprise_learner + # Don't give discount to enterprise users if is_enterprise_learner(user): return False diff --git a/openedx/features/discounts/migrations/0002_auto_20191022_1720.py b/openedx/features/discounts/migrations/0002_auto_20191022_1720.py index 022a9e635f1a..7b432ca9dfe7 100644 --- a/openedx/features/discounts/migrations/0002_auto_20191022_1720.py +++ b/openedx/features/discounts/migrations/0002_auto_20191022_1720.py @@ -1,9 +1,10 @@ # Generated by Django 1.11.25 on 2019-10-22 17:20 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion + import openedx.core.djangoapps.config_model_utils.models diff --git a/openedx/features/discounts/models.py b/openedx/features/discounts/models.py index 8c7c5ff53ea0..535c055c4491 100644 --- a/openedx/features/discounts/models.py +++ b/openedx/features/discounts/models.py @@ -6,7 +6,6 @@ from django.db import models - from django.utils.translation import gettext_lazy as _ from openedx.core.djangoapps.config_model_utils.models import StackedConfigurationModel diff --git a/openedx/features/discounts/tests/test_applicability.py b/openedx/features/discounts/tests/test_applicability.py index 472120b38705..51fb56460611 100644 --- a/openedx/features/discounts/tests/test_applicability.py +++ b/openedx/features/discounts/tests/test_applicability.py @@ -3,10 +3,10 @@ from datetime import datetime, timedelta from unittest.mock import Mock, patch +from zoneinfo import ZoneInfo import ddt import pytest -from zoneinfo import ZoneInfo from django.contrib.sites.models import Site from django.utils.timezone import now from edx_toggles.toggles.testutils import override_waffle_flag @@ -20,7 +20,9 @@ from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.features.discounts.models import DiscountRestrictionConfig from openedx.features.discounts.utils import REV1008_EXPERIMENT_ID -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..applicability import DISCOUNT_APPLICABILITY_FLAG, _is_in_holdback_and_bucket, can_receive_discount diff --git a/openedx/features/discounts/tests/test_discount_restriction_models.py b/openedx/features/discounts/tests/test_discount_restriction_models.py index 38815a660f70..92c434959536 100644 --- a/openedx/features/discounts/tests/test_discount_restriction_models.py +++ b/openedx/features/discounts/tests/test_discount_restriction_models.py @@ -7,11 +7,11 @@ import ddt +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory from openedx.core.djangolib.testing.utils import CacheIsolationTestCase from openedx.features.discounts.models import DiscountRestrictionConfig -from common.djangoapps.student.tests.factories import UserFactory @ddt.ddt diff --git a/openedx/features/discounts/tests/test_utils.py b/openedx/features/discounts/tests/test_utils.py index 6bd9d1cd1593..d32d40e48a93 100644 --- a/openedx/features/discounts/tests/test_utils.py +++ b/openedx/features/discounts/tests/test_utils.py @@ -1,7 +1,7 @@ """ Tests of the openedx.features.discounts.utils module. """ -from unittest.mock import patch, Mock +from unittest.mock import Mock, patch import ddt from django.contrib.auth.models import AnonymousUser @@ -17,7 +17,7 @@ from openedx.features.discounts.applicability import ( DISCOUNT_APPLICABILITY_FLAG, FIRST_PURCHASE_DISCOUNT_OVERRIDE_FLAG, - get_discount_expiration_date + get_discount_expiration_date, ) from .. import utils diff --git a/openedx/features/discounts/tests/test_views.py b/openedx/features/discounts/tests/test_views.py index 0ab286535863..879bbeb1ce5a 100644 --- a/openedx/features/discounts/tests/test_views.py +++ b/openedx/features/discounts/tests/test_views.py @@ -6,7 +6,9 @@ from django.urls import reverse from common.djangoapps.student.tests.factories import TEST_PASSWORD, UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/features/discounts/utils.py b/openedx/features/discounts/utils.py index 00b60f6cadfd..2c7f4d7f552a 100644 --- a/openedx/features/discounts/utils.py +++ b/openedx/features/discounts/utils.py @@ -3,23 +3,23 @@ """ from datetime import datetime - from zoneinfo import ZoneInfo + from django.conf import settings from django.utils.translation import get_language from django.utils.translation import gettext as _ from edx_django_utils.plugins import pluggable_override from common.djangoapps.course_modes.models import format_course_price, get_course_prices -from lms.djangoapps.experiments.models import ExperimentData from lms.djangoapps.courseware.utils import verified_upgrade_deadline_link +from lms.djangoapps.experiments.models import ExperimentData from openedx.core.djangolib.markup import HTML from openedx.features.discounts.applicability import ( FIRST_PURCHASE_DISCOUNT_OVERRIDE_FLAG, REV1008_EXPERIMENT_ID, can_receive_discount, discount_percentage, - get_discount_expiration_date + get_discount_expiration_date, ) diff --git a/openedx/features/discounts/views.py b/openedx/features/discounts/views.py index c91c5cb06f10..f06b9a99fe5b 100644 --- a/openedx/features/discounts/views.py +++ b/openedx/features/discounts/views.py @@ -24,7 +24,7 @@ from openedx.core.lib.api.permissions import ApiKeyHeaderPermissionIsAuthenticated from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin -from .applicability import can_receive_discount, discount_percentage, REV1008_EXPERIMENT_ID +from .applicability import REV1008_EXPERIMENT_ID, can_receive_discount, discount_percentage log = logging.getLogger(__name__) diff --git a/openedx/features/effort_estimation/tests/test_block_transformers.py b/openedx/features/effort_estimation/tests/test_block_transformers.py index ae70eff26126..4b1f3c911023 100644 --- a/openedx/features/effort_estimation/tests/test_block_transformers.py +++ b/openedx/features/effort_estimation/tests/test_block_transformers.py @@ -8,14 +8,15 @@ from edxval.api import create_video, remove_video_for_course from openedx.core.djangoapps.content.block_structure.factory import BlockStructureFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import SampleCourseFactory # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.tests.sample_courses import BlockInfo # lint-amnesty, pylint: disable=wrong-import-order from ..block_transformers import EffortEstimationTransformer from ..toggles import EFFORT_ESTIMATION_DISABLED_FLAG - # Copied here, rather than used directly from class, just to catch any accidental changes DISABLE_ESTIMATION = 'disable_estimation' EFFORT_ACTIVITIES = 'effort_activities' diff --git a/openedx/features/effort_estimation/toggles.py b/openedx/features/effort_estimation/toggles.py index ad83c1fef239..184ed78479b4 100644 --- a/openedx/features/effort_estimation/toggles.py +++ b/openedx/features/effort_estimation/toggles.py @@ -4,7 +4,6 @@ from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag - WAFFLE_FLAG_NAMESPACE = 'effort_estimation' # .. toggle_name: effort_estimation.disabled diff --git a/openedx/features/enterprise_support/admin/views.py b/openedx/features/enterprise_support/admin/views.py index 37fedcc69b88..f377f7c668ce 100644 --- a/openedx/features/enterprise_support/admin/views.py +++ b/openedx/features/enterprise_support/admin/views.py @@ -8,8 +8,8 @@ from django.views.generic.edit import FormView from enterprise.models import EnterpriseCourseEnrollment -from openedx.features.enterprise_support.admin.forms import CSVImportForm from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentAttribute +from openedx.features.enterprise_support.admin.forms import CSVImportForm class EnrollmentAttributeOverrideView(FormView): diff --git a/openedx/features/enterprise_support/api.py b/openedx/features/enterprise_support/api.py index c110fe526305..b6177291c9f2 100644 --- a/openedx/features/enterprise_support/api.py +++ b/openedx/features/enterprise_support/api.py @@ -34,14 +34,14 @@ from consent.models import DataSharingConsent, DataSharingConsentTextOverrides from enterprise.api.v1.serializers import ( EnterpriseCustomerUserReadOnlySerializer, - EnterpriseCustomerUserWriteSerializer + EnterpriseCustomerUserWriteSerializer, ) from enterprise.models import ( EnterpriseCourseEnrollment, EnterpriseCustomer, EnterpriseCustomerIdentityProvider, EnterpriseCustomerUser, - PendingEnterpriseCustomerUser + PendingEnterpriseCustomerUser, ) except ImportError: # pragma: no cover pass diff --git a/openedx/features/enterprise_support/enrollments/tests/test_utils.py b/openedx/features/enterprise_support/enrollments/tests/test_utils.py index f9233c3724c8..4bfc23da4e87 100644 --- a/openedx/features/enterprise_support/enrollments/tests/test_utils.py +++ b/openedx/features/enterprise_support/enrollments/tests/test_utils.py @@ -8,14 +8,11 @@ from opaque_keys.edx.keys import CourseKey from openedx.core.djangoapps.course_groups.cohorts import CourseUserGroup -from openedx.core.djangoapps.enrollments.errors import ( - CourseEnrollmentError, - CourseEnrollmentExistsError, -) +from openedx.core.djangoapps.enrollments.errors import CourseEnrollmentError, CourseEnrollmentExistsError from openedx.core.djangolib.testing.utils import skip_unless_lms from openedx.features.enterprise_support.enrollments.exceptions import ( CourseIdMissingException, - UserDoesNotExistException + UserDoesNotExistException, ) from openedx.features.enterprise_support.enrollments.utils import lms_update_or_create_enrollment diff --git a/openedx/features/enterprise_support/enrollments/utils.py b/openedx/features/enterprise_support/enrollments/utils.py index e0d5f65aedde..5bed623f6dc3 100644 --- a/openedx/features/enterprise_support/enrollments/utils.py +++ b/openedx/features/enterprise_support/enrollments/utils.py @@ -16,7 +16,7 @@ from openedx.core.lib.log_utils import audit_log from openedx.features.enterprise_support.enrollments.exceptions import ( CourseIdMissingException, - UserDoesNotExistException + UserDoesNotExistException, ) log = logging.getLogger(__name__) diff --git a/openedx/features/enterprise_support/serializers.py b/openedx/features/enterprise_support/serializers.py index 54171de513fa..030d4160c098 100644 --- a/openedx/features/enterprise_support/serializers.py +++ b/openedx/features/enterprise_support/serializers.py @@ -6,8 +6,9 @@ from rest_framework import serializers try: - from enterprise.api.v1.serializers import \ - EnterpriseCourseEnrollmentReadOnlySerializer as BaseEnterpriseCourseEnrollmentSerializer + from enterprise.api.v1.serializers import ( + EnterpriseCourseEnrollmentReadOnlySerializer as BaseEnterpriseCourseEnrollmentSerializer, + ) from enterprise.models import EnterpriseCourseEnrollment except ImportError: # pragma: no cover pass diff --git a/openedx/features/enterprise_support/signals.py b/openedx/features/enterprise_support/signals.py index c8122e2102ca..1524453a246f 100644 --- a/openedx/features/enterprise_support/signals.py +++ b/openedx/features/enterprise_support/signals.py @@ -12,7 +12,7 @@ from enterprise.models import EnterpriseCourseEnrollment, EnterpriseCustomer from integrated_channels.integrated_channel.tasks import ( transmit_single_learner_data, - transmit_single_subsection_learner_data + transmit_single_subsection_learner_data, ) from slumber.exceptions import HttpClientError diff --git a/openedx/features/enterprise_support/tasks.py b/openedx/features/enterprise_support/tasks.py index c3fa4c054dbc..b6e7cb40245a 100644 --- a/openedx/features/enterprise_support/tasks.py +++ b/openedx/features/enterprise_support/tasks.py @@ -7,8 +7,8 @@ from celery import shared_task from edx_django_utils.monitoring import set_code_owner_attribute - from enterprise.models import EnterpriseCourseEnrollment + from openedx.features.enterprise_support.utils import clear_data_consent_share_cache log = logging.getLogger('edx.celery.task') diff --git a/openedx/features/enterprise_support/tests/factories.py b/openedx/features/enterprise_support/tests/factories.py index a0244f2bcc8e..f0a2887ae998 100644 --- a/openedx/features/enterprise_support/tests/factories.py +++ b/openedx/features/enterprise_support/tests/factories.py @@ -6,8 +6,6 @@ from uuid import UUID import factory -from faker import Factory as FakerFactory - from enterprise.models import ( EnterpriseCourseEnrollment, EnterpriseCustomer, @@ -15,6 +13,8 @@ EnterpriseCustomerIdentityProvider, EnterpriseCustomerUser, ) +from faker import Factory as FakerFactory + from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory FAKER = FakerFactory.create() diff --git a/openedx/features/enterprise_support/tests/mixins/enterprise.py b/openedx/features/enterprise_support/tests/mixins/enterprise.py index 8b8f420dddfb..164a006c63f4 100644 --- a/openedx/features/enterprise_support/tests/mixins/enterprise.py +++ b/openedx/features/enterprise_support/tests/mixins/enterprise.py @@ -4,7 +4,6 @@ import json - from unittest import mock import httpretty @@ -12,6 +11,7 @@ from django.core.cache import cache from django.test import SimpleTestCase from django.urls import reverse + from openedx.features.enterprise_support.tests import FAKE_ENTERPRISE_CUSTOMER diff --git a/openedx/features/enterprise_support/tests/test_admin.py b/openedx/features/enterprise_support/tests/test_admin.py index b5495670d18e..2080db6d5040 100644 --- a/openedx/features/enterprise_support/tests/test_admin.py +++ b/openedx/features/enterprise_support/tests/test_admin.py @@ -10,11 +10,13 @@ from django.test import Client from django.urls import reverse -from openedx.core.djangoapps.catalog.tests.factories import CourseRunFactory -from openedx.features.enterprise_support.admin.forms import CSVImportForm from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentAttribute from common.djangoapps.student.tests.factories import TEST_PASSWORD, AdminFactory, CourseEnrollmentFactory, UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from openedx.core.djangoapps.catalog.tests.factories import CourseRunFactory +from openedx.features.enterprise_support.admin.forms import CSVImportForm +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) class EnrollmentAttributeOverrideViewTest(ModuleStoreTestCase): diff --git a/openedx/features/enterprise_support/tests/test_api.py b/openedx/features/enterprise_support/tests/test_api.py index 40f2c834e6b0..6ec0aeb6e90b 100644 --- a/openedx/features/enterprise_support/tests/test_api.py +++ b/openedx/features/enterprise_support/tests/test_api.py @@ -6,7 +6,6 @@ import ddt import httpretty import pytest -from testfixtures import LogCapture from consent.models import DataSharingConsent from django.conf import settings from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user @@ -14,10 +13,11 @@ from django.http import HttpResponseRedirect from django.test.utils import override_settings from django.urls import reverse -from edx_django_utils.cache import get_cache_key, TieredCache +from edx_django_utils.cache import TieredCache, get_cache_key from enterprise.models import EnterpriseCustomerUser # lint-amnesty, pylint: disable=wrong-import-order from requests.exceptions import HTTPError from six.moves.urllib.parse import parse_qs +from testfixtures import LogCapture from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory diff --git a/openedx/features/enterprise_support/tests/test_context.py b/openedx/features/enterprise_support/tests/test_context.py index d775859b1b24..07f10a63017a 100644 --- a/openedx/features/enterprise_support/tests/test_context.py +++ b/openedx/features/enterprise_support/tests/test_context.py @@ -4,13 +4,13 @@ from django.conf import settings from django.test.utils import override_settings -from common.djangoapps.student.tests.factories import UserFactory, CourseEnrollmentFactory +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms from openedx.features.enterprise_support.context import get_enterprise_event_context from openedx.features.enterprise_support.tests import FEATURES_WITH_ENTERPRISE_ENABLED from openedx.features.enterprise_support.tests.factories import ( + EnterpriseCourseEnrollmentFactory, EnterpriseCustomerUserFactory, - EnterpriseCourseEnrollmentFactory ) from openedx.features.enterprise_support.tests.mixins.enterprise import EnterpriseServiceMockMixin diff --git a/openedx/features/enterprise_support/tests/test_logout.py b/openedx/features/enterprise_support/tests/test_logout.py index cbec23397795..ee915fe8eb50 100644 --- a/openedx/features/enterprise_support/tests/test_logout.py +++ b/openedx/features/enterprise_support/tests/test_logout.py @@ -11,15 +11,15 @@ from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.util.testing import UrlResetMixin +from common.test.utils import assert_dict_contains_subset from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms from openedx.features.enterprise_support.api import enterprise_enabled from openedx.features.enterprise_support.tests import ( FAKE_ENTERPRISE_CUSTOMER, FEATURES_WITH_ENTERPRISE_ENABLED, - factories + factories, ) from openedx.features.enterprise_support.tests.mixins.enterprise import EnterpriseServiceMockMixin -from common.test.utils import assert_dict_contains_subset @ddt.ddt diff --git a/openedx/features/enterprise_support/tests/test_serializers.py b/openedx/features/enterprise_support/tests/test_serializers.py index 1f1b73bae664..65ae0dcd644c 100644 --- a/openedx/features/enterprise_support/tests/test_serializers.py +++ b/openedx/features/enterprise_support/tests/test_serializers.py @@ -9,7 +9,7 @@ from openedx.features.enterprise_support.serializers import EnterpriseCourseEnrollmentSerializer from openedx.features.enterprise_support.tests.factories import ( EnterpriseCourseEnrollmentFactory, - EnterpriseCustomerUserFactory + EnterpriseCustomerUserFactory, ) diff --git a/openedx/features/enterprise_support/tests/test_signals.py b/openedx/features/enterprise_support/tests/test_signals.py index 3207aeb024f3..0fa1bff42809 100644 --- a/openedx/features/enterprise_support/tests/test_signals.py +++ b/openedx/features/enterprise_support/tests/test_signals.py @@ -11,6 +11,7 @@ from edx_django_utils.cache import TieredCache from opaque_keys.edx.keys import CourseKey from slumber.exceptions import HttpClientError, HttpServerError + # from requests.exceptions import HTTPError from testfixtures import LogCapture @@ -25,10 +26,12 @@ from openedx.features.enterprise_support.tests.factories import ( EnterpriseCourseEnrollmentFactory, EnterpriseCustomerFactory, - EnterpriseCustomerUserFactory + EnterpriseCustomerUserFactory, ) from openedx.features.enterprise_support.utils import get_data_consent_share_cache_key -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order log = logging.getLogger(__name__) diff --git a/openedx/features/enterprise_support/tests/test_utils.py b/openedx/features/enterprise_support/tests/test_utils.py index 48a331083f41..fc28d3aad8a0 100644 --- a/openedx/features/enterprise_support/tests/test_utils.py +++ b/openedx/features/enterprise_support/tests/test_utils.py @@ -25,7 +25,7 @@ from openedx.features.enterprise_support.tests.factories import ( EnterpriseCustomerBrandingConfigurationFactory, EnterpriseCustomerFactory, - EnterpriseCustomerUserFactory + EnterpriseCustomerUserFactory, ) from openedx.features.enterprise_support.utils import ( ENTERPRISE_HEADER_LINKS, @@ -45,10 +45,15 @@ is_enterprise_learner, update_account_settings_context_for_enterprise, update_logistration_context_for_enterprise, - update_third_party_auth_context_for_enterprise + update_third_party_auth_context_for_enterprise, +) +from xmodule.modulestore.tests.django_utils import ( + SharedModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, ) -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order TEST_PASSWORD = 'test' diff --git a/openedx/features/enterprise_support/utils.py b/openedx/features/enterprise_support/utils.py index 9e99bf599267..37b2aaa96c13 100644 --- a/openedx/features/enterprise_support/utils.py +++ b/openedx/features/enterprise_support/utils.py @@ -326,7 +326,7 @@ def get_enterprise_learner_portal(request): Caches and returns result in/from the user's request session if provided. """ # Prevent a circular import. - from openedx.features.enterprise_support.api import enterprise_enabled, enterprise_customer_uuid_for_request + from openedx.features.enterprise_support.api import enterprise_customer_uuid_for_request, enterprise_enabled user = request.user # Only cache this if a learner is authenticated (AnonymousUser exists and should not be tracked) diff --git a/openedx/features/lti_course_tab/tab.py b/openedx/features/lti_course_tab/tab.py index 924dbe27f798..b869741b59f6 100644 --- a/openedx/features/lti_course_tab/tab.py +++ b/openedx/features/lti_course_tab/tab.py @@ -14,11 +14,11 @@ from opaque_keys.edx.keys import CourseKey from web_fragments.fragment import Fragment +from common.djangoapps.student.models import anonymous_id_for_user from lms.djangoapps.courseware.access import get_user_role from lms.djangoapps.courseware.tabs import EnrolledTab from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration from openedx.core.djangolib.markup import HTML -from common.djangoapps.student.models import anonymous_id_for_user from xmodule.course_block import CourseBlock # lint-amnesty, pylint: disable=wrong-import-order from xmodule.tabs import TabFragmentViewMixin, key_checker # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/features/personalized_learner_schedules/call_to_action.py b/openedx/features/personalized_learner_schedules/call_to_action.py index 634c425b38bd..cb9bf91f76b8 100644 --- a/openedx/features/personalized_learner_schedules/call_to_action.py +++ b/openedx/features/personalized_learner_schedules/call_to_action.py @@ -5,17 +5,17 @@ import logging from crum import get_current_request - from django.conf import settings from django.urls import reverse -from django.utils.translation import gettext as _, ngettext +from django.utils.translation import gettext as _ +from django.utils.translation import ngettext -from xmodule.util.misc import is_xblock_an_assignment from openedx.core.djangolib.markup import HTML, Text from openedx.core.lib.mobile_utils import is_request_from_mobile_app from openedx.features.course_experience import RELATIVE_DATES_DISABLE_RESET_FLAG from openedx.features.course_experience.url_helpers import is_request_from_learning_mfe from openedx.features.course_experience.utils import dates_banner_should_display +from xmodule.util.misc import is_xblock_an_assignment log = logging.getLogger(__name__) diff --git a/openedx/features/personalized_learner_schedules/show_answer/tests/test_show_answer_override.py b/openedx/features/personalized_learner_schedules/show_answer/tests/test_show_answer_override.py index 0a0c03725545..fafbea1533fc 100644 --- a/openedx/features/personalized_learner_schedules/show_answer/tests/test_show_answer_override.py +++ b/openedx/features/personalized_learner_schedules/show_answer/tests/test_show_answer_override.py @@ -3,15 +3,16 @@ import ddt from django.test import RequestFactory from django.test.utils import override_settings - from edx_toggles.toggles.testutils import override_waffle_flag from lms.djangoapps.ccx.tests.test_overrides import inject_field_overrides -from lms.djangoapps.courseware.model_data import FieldDataCache from lms.djangoapps.courseware.block_render import get_block +from lms.djangoapps.courseware.model_data import FieldDataCache from openedx.features.course_experience import RELATIVE_DATES_FLAG from xmodule.capa_block import SHOWANSWER # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/features/survey_report/admin.py b/openedx/features/survey_report/admin.py index a5719d966a93..3d40c5efc05c 100644 --- a/openedx/features/survey_report/admin.py +++ b/openedx/features/survey_report/admin.py @@ -3,10 +3,11 @@ """ -from django.contrib import admin from django.conf import settings -from .models import SurveyReport +from django.contrib import admin + from .api import send_report_to_external_api +from .models import SurveyReport class SurveyReportAdmin(admin.ModelAdmin): diff --git a/openedx/features/survey_report/api.py b/openedx/features/survey_report/api.py index cb8eadc29f1e..1340038e896a 100644 --- a/openedx/features/survey_report/api.py +++ b/openedx/features/survey_report/api.py @@ -2,23 +2,22 @@ Contains the logic to manage survey report model. """ import requests - from django.conf import settings from django.forms.models import model_to_dict from openedx.features.survey_report.models import ( + SURVEY_REPORT_ERROR, + SURVEY_REPORT_GENERATED, SurveyReport, - SurveyReportUpload, SurveyReportAnonymousSiteID, - SURVEY_REPORT_ERROR, - SURVEY_REPORT_GENERATED + SurveyReportUpload, ) from openedx.features.survey_report.queries import ( get_course_enrollments, - get_recently_active_users, get_generated_certificates, + get_recently_active_users, get_registered_learners, - get_unique_courses_offered + get_unique_courses_offered, ) MAX_WEEKS_SINCE_LAST_LOGIN: int = 4 diff --git a/openedx/features/survey_report/context_processors.py b/openedx/features/survey_report/context_processors.py index f2e8892d84bc..47a355e7b95d 100644 --- a/openedx/features/survey_report/context_processors.py +++ b/openedx/features/survey_report/context_processors.py @@ -26,10 +26,12 @@ It enhances the admin interface by providing dynamic context for displaying a survey report banner based on defined conditions and settings. """ -from django.conf import settings -from django.urls import reverse from datetime import datetime + from dateutil.relativedelta import relativedelta +from django.conf import settings +from django.urls import reverse + from .models import SurveyReport diff --git a/openedx/features/survey_report/migrations/0001_initial.py b/openedx/features/survey_report/migrations/0001_initial.py index 46d816a363cc..77377aac625b 100644 --- a/openedx/features/survey_report/migrations/0001_initial.py +++ b/openedx/features/survey_report/migrations/0001_initial.py @@ -1,7 +1,7 @@ # Generated by Django 3.2.16 on 2022-11-03 20:07 -from django.db import migrations, models import jsonfield.fields +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/features/survey_report/migrations/0002_auto_20221130_1533.py b/openedx/features/survey_report/migrations/0002_auto_20221130_1533.py index ebb79a08fd69..e5a686b18ac9 100644 --- a/openedx/features/survey_report/migrations/0002_auto_20221130_1533.py +++ b/openedx/features/survey_report/migrations/0002_auto_20221130_1533.py @@ -1,7 +1,7 @@ # Generated by Django 3.2.16 on 2022-11-30 15:33 -from django.db import migrations, models import jsonfield.fields +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/features/survey_report/migrations/0004_surveyreportupload.py b/openedx/features/survey_report/migrations/0004_surveyreportupload.py index cc77eaef71bb..02bd313c5ac3 100644 --- a/openedx/features/survey_report/migrations/0004_surveyreportupload.py +++ b/openedx/features/survey_report/migrations/0004_surveyreportupload.py @@ -1,7 +1,7 @@ # Generated by Django 3.2.16 on 2023-02-01 15:16 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/features/survey_report/migrations/0005_surveyreportanonymoussiteid.py b/openedx/features/survey_report/migrations/0005_surveyreportanonymoussiteid.py index ccf7d059a2d2..a18a102d4f82 100644 --- a/openedx/features/survey_report/migrations/0005_surveyreportanonymoussiteid.py +++ b/openedx/features/survey_report/migrations/0005_surveyreportanonymoussiteid.py @@ -1,8 +1,9 @@ # Generated by Django 3.2.16 on 2023-02-10 15:45 -from django.db import migrations, models import uuid +from django.db import migrations, models + class Migration(migrations.Migration): diff --git a/openedx/features/survey_report/queries.py b/openedx/features/survey_report/queries.py index 011a0d5b4790..0447a7e1c459 100644 --- a/openedx/features/survey_report/queries.py +++ b/openedx/features/survey_report/queries.py @@ -8,8 +8,8 @@ from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.db.models import Count, OuterRef, Q, Subquery -from common.djangoapps.util.query import read_replica_or_default from common.djangoapps.student.models import CourseEnrollment +from common.djangoapps.util.query import read_replica_or_default from lms.djangoapps.grades.models import PersistentCourseGrade from openedx.core.djangoapps.content.course_overviews.models import CourseOverview diff --git a/openedx/features/survey_report/tests/test_query_methods.py b/openedx/features/survey_report/tests/test_query_methods.py index 9a4b6431ed59..8a82f594665c 100644 --- a/openedx/features/survey_report/tests/test_query_methods.py +++ b/openedx/features/survey_report/tests/test_query_methods.py @@ -9,12 +9,11 @@ from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.features.survey_report.queries import ( get_course_enrollments, - get_recently_active_users, get_generated_certificates, + get_recently_active_users, get_registered_learners, - get_unique_courses_offered + get_unique_courses_offered, ) - from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order diff --git a/openedx/features/survey_report/urls.py b/openedx/features/survey_report/urls.py index dc7d2e29074a..9512168f0de6 100644 --- a/openedx/features/survey_report/urls.py +++ b/openedx/features/survey_report/urls.py @@ -3,6 +3,7 @@ """ from django.urls import path + from .views import SurveyReportView urlpatterns = [ diff --git a/openedx/features/survey_report/views.py b/openedx/features/survey_report/views.py index d8487e8cd4a4..ebc755426e4c 100644 --- a/openedx/features/survey_report/views.py +++ b/openedx/features/survey_report/views.py @@ -8,6 +8,7 @@ from django.utils.decorators import method_decorator from django.views.decorators.csrf import ensure_csrf_cookie from django.views.generic import View + from .tasks import generate_survey_report diff --git a/openedx/testing/coverage_context_listener/urls.py b/openedx/testing/coverage_context_listener/urls.py index 25208d683a90..0e7ce0379b3f 100644 --- a/openedx/testing/coverage_context_listener/urls.py +++ b/openedx/testing/coverage_context_listener/urls.py @@ -2,6 +2,7 @@ Coverage Context Listener URLs. """ from django.urls import path + from .views import update_context urlpatterns = [ diff --git a/openedx/testing/coverage_context_listener/views.py b/openedx/testing/coverage_context_listener/views.py index a139a4d8d87f..8c2a05bb5b73 100644 --- a/openedx/testing/coverage_context_listener/views.py +++ b/openedx/testing/coverage_context_listener/views.py @@ -4,8 +4,8 @@ import coverage from django.http import HttpResponse -from django.views.decorators.http import require_POST from django.views.decorators.csrf import csrf_exempt +from django.views.decorators.http import require_POST @require_POST diff --git a/openedx/tests/completion_integration/test_handlers.py b/openedx/tests/completion_integration/test_handlers.py index 4522768739ad..38bf74ff2ab4 100644 --- a/openedx/tests/completion_integration/test_handlers.py +++ b/openedx/tests/completion_integration/test_handlers.py @@ -4,6 +4,7 @@ from datetime import datetime from unittest.mock import patch +from zoneinfo import ZoneInfo import ddt import pytest @@ -11,7 +12,6 @@ from completion.models import BlockCompletion from completion.test_utils import CompletionSetUpMixin from django.test import TestCase -from zoneinfo import ZoneInfo from xblock.completable import XBlockCompletionMode from xblock.core import XBlock diff --git a/openedx/tests/completion_integration/test_services.py b/openedx/tests/completion_integration/test_services.py index 7a6fad8ece12..482c70da05a9 100644 --- a/openedx/tests/completion_integration/test_services.py +++ b/openedx/tests/completion_integration/test_services.py @@ -10,14 +10,14 @@ from django.conf import settings from django.test import override_settings from opaque_keys.edx.keys import CourseKey + +from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangolib.testing.utils import skip_unless_lms from xmodule.library_tools import LegacyLibraryToolsService from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory, LibraryFactory +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory, LibraryFactory from xmodule.tests import prepare_block_runtime -from openedx.core.djangolib.testing.utils import skip_unless_lms -from common.djangoapps.student.tests.factories import UserFactory - @ddt.ddt @skip_unless_lms diff --git a/openedx/tests/completion_integration/test_views.py b/openedx/tests/completion_integration/test_views.py index e9e866224ec4..cbb2e7490381 100644 --- a/openedx/tests/completion_integration/test_views.py +++ b/openedx/tests/completion_integration/test_views.py @@ -10,11 +10,16 @@ from edx_toggles.toggles.testutils import override_waffle_switch from rest_framework.test import APIClient -from openedx.core.djangolib.testing.utils import skip_unless_lms from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory +from openedx.core.djangolib.testing.utils import skip_unless_lms from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, # lint-amnesty, pylint: disable=wrong-import-order +) +from xmodule.modulestore.tests.factories import ( # lint-amnesty, pylint: disable=wrong-import-order + BlockFactory, + CourseFactory, +) @ddt.ddt diff --git a/openedx/tests/xblock_integration/test_crowdsource_hinter.py b/openedx/tests/xblock_integration/test_crowdsource_hinter.py index ecd3c09dd650..bb8d663a5025 100644 --- a/openedx/tests/xblock_integration/test_crowdsource_hinter.py +++ b/openedx/tests/xblock_integration/test_crowdsource_hinter.py @@ -8,12 +8,12 @@ import simplejson as json from django.conf import settings from django.urls import reverse -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory from common.djangoapps.student.tests.factories import GlobalStaffFactory from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase from openedx.core.lib.url_utils import quote_slashes +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory class TestCrowdsourceHinter(SharedModuleStoreTestCase, LoginEnrollmentTestCase): diff --git a/openedx/tests/xblock_integration/test_recommender.py b/openedx/tests/xblock_integration/test_recommender.py index ae06b09db162..694b28497530 100644 --- a/openedx/tests/xblock_integration/test_recommender.py +++ b/openedx/tests/xblock_integration/test_recommender.py @@ -14,12 +14,12 @@ from ddt import data, ddt from django.conf import settings from django.urls import reverse -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory from common.djangoapps.student.tests.factories import GlobalStaffFactory from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase from openedx.core.lib.url_utils import quote_slashes +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory class TestRecommender(SharedModuleStoreTestCase, LoginEnrollmentTestCase): diff --git a/openedx/tests/xblock_integration/xblock_testcase.py b/openedx/tests/xblock_integration/xblock_testcase.py index af2a3410b75f..8e55b131f03b 100644 --- a/openedx/tests/xblock_integration/xblock_testcase.py +++ b/openedx/tests/xblock_integration/xblock_testcase.py @@ -37,24 +37,23 @@ import collections +import html import json import sys import unittest from datetime import datetime, timedelta -import html - from unittest import mock from zoneinfo import ZoneInfo + from bs4 import BeautifulSoup from django.conf import settings from django.urls import reverse from xblock.plugin import Plugin import xmodule.services -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory - from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory class XBlockEventTestMixin: diff --git a/pyproject.toml b/pyproject.toml index 85757eed7a74..64ff48abafec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -213,7 +213,7 @@ exclude = [ ] [tool.ruff.lint] -select = ["E", "W"] +select = ["E", "W", "I"] ignore = [ "E402", # module level import not at top of file "E501", # line too long (pylint enforces this at 120 chars while ignoring trailing comments) @@ -226,12 +226,6 @@ ignore = [ "E721", # use `isinstance()` for type comparisons ] -[tool.isort] -indent = " " -line_length = 120 -multi_line_output = 3 -skip = ["envs", "migrations"] - [tool.importlinter] root_packages = ["lms", "cms", "openedx", "openedx_content", "openedx_catalog"] include_external_packages = true diff --git a/requirements/edx/testing.in b/requirements/edx/testing.in index 275460512f97..9784cb6cc946 100644 --- a/requirements/edx/testing.in +++ b/requirements/edx/testing.in @@ -27,7 +27,6 @@ factory-boy # Library for creating test fixtures, used in many tes freezegun # Allows tests to mock the output of assorted datetime module functions httpretty # Library for mocking HTTP requests, used in many tests import-linter # Tool for making assertions about which modules can import which others -isort # For checking and fixing the order of imports mock # Deprecated alias to standard library `unittest.mock` ruff # Fast Python linter and formatter polib # Library for manipulating gettext translation files, used to test paver i18n commands diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index e233d0d051a0..5ce8448d174b 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -865,9 +865,7 @@ isodate==0.7.2 # -r requirements/edx/base.txt # python3-saml isort==8.0.1 - # via - # -r requirements/edx/testing.in - # pylint + # via pylint jinja2==3.1.6 # via # -r requirements/edx/base.txt diff --git a/scripts/compile_sass.py b/scripts/compile_sass.py index 70d49d21cce8..3aece9fb72e1 100755 --- a/scripts/compile_sass.py +++ b/scripts/compile_sass.py @@ -49,7 +49,6 @@ import click - # Accept both long- and short-forms of these words, but normalize to long form. # We accept both because edx-platform asset build scripts historically use the short form, # but NODE_ENV uses the long form, so to make them integrate more seamlessly we accept both. diff --git a/scripts/jwk-precompute-params.py b/scripts/jwk-precompute-params.py index c75d86f6c739..20e427cb8ae7 100755 --- a/scripts/jwk-precompute-params.py +++ b/scripts/jwk-precompute-params.py @@ -14,7 +14,6 @@ from jwt.algorithms import RSAAlgorithm - print("Paste the key's JSON, followed by a new line and Ctrl-D:\n", file=sys.stderr) old_jwk_data = json.loads(sys.stdin.read()) diff --git a/scripts/stable_bucketer b/scripts/stable_bucketer index 58fbc4386b0e..b2c9853b54cb 100755 --- a/scripts/stable_bucketer +++ b/scripts/stable_bucketer @@ -5,6 +5,7 @@ import hashlib import random import re import string + ##### diff --git a/scripts/structures_pruning/structures.py b/scripts/structures_pruning/structures.py index 6b3f99182f78..69a4aa958c8e 100644 --- a/scripts/structures_pruning/structures.py +++ b/scripts/structures_pruning/structures.py @@ -6,8 +6,8 @@ """ import logging -from os import path import sys +from os import path import click import click_log @@ -15,7 +15,7 @@ # Add top-level project path to sys.path before importing scripts code sys.path.append(path.abspath(path.join(path.dirname(__file__), '../..'))) -from scripts.structures_pruning.utils.splitmongo import SplitMongoBackend, ChangePlan +from scripts.structures_pruning.utils.splitmongo import ChangePlan, SplitMongoBackend # Add top-level module path to sys.path before importing tubular code. # sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) diff --git a/scripts/structures_pruning/tests/test_splitmongo.py b/scripts/structures_pruning/tests/test_splitmongo.py index 706afd800778..575af947f7a3 100644 --- a/scripts/structures_pruning/tests/test_splitmongo.py +++ b/scripts/structures_pruning/tests/test_splitmongo.py @@ -23,7 +23,11 @@ sys.path.append(path.abspath(path.join(path.dirname(__file__), '../..'))) from scripts.structures_pruning.utils.splitmongo import ( - ActiveVersionBranch, ChangePlan, Structure, SplitMongoBackend, StructuresGraph + ActiveVersionBranch, + ChangePlan, + SplitMongoBackend, + Structure, + StructuresGraph, ) diff --git a/scripts/structures_pruning/utils/splitmongo.py b/scripts/structures_pruning/utils/splitmongo.py index 69e1caf29185..9696f612c84f 100644 --- a/scripts/structures_pruning/utils/splitmongo.py +++ b/scripts/structures_pruning/utils/splitmongo.py @@ -39,17 +39,17 @@ means that it will work for databases with up to about 10 million Structures before RAM usage starts to become a problem. """ -from collections import deque, namedtuple -from itertools import count, takewhile import json import logging import os import sys import time +from collections import deque, namedtuple +from itertools import count, takewhile from bson.objectid import ObjectId -from pymongo import MongoClient, UpdateOne from opaque_keys.edx.locator import CourseLocator, LibraryLocator +from pymongo import MongoClient, UpdateOne LOG = logging.getLogger('structures') diff --git a/scripts/user_retirement/replace_usernames.py b/scripts/user_retirement/replace_usernames.py index 2034fce0e6a3..7b2b2206d50c 100644 --- a/scripts/user_retirement/replace_usernames.py +++ b/scripts/user_retirement/replace_usernames.py @@ -25,7 +25,7 @@ CredentialsApi, DiscoveryApi, EcommerceApi, - LmsApi + LmsApi, ) logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) diff --git a/scripts/user_retirement/retire_one_learner.py b/scripts/user_retirement/retire_one_learner.py index b8c40364e643..0344526b5e6e 100755 --- a/scripts/user_retirement/retire_one_learner.py +++ b/scripts/user_retirement/retire_one_learner.py @@ -32,6 +32,7 @@ sys.path.append(path.abspath(path.join(path.dirname(__file__), '../..'))) from scripts.user_retirement.utils.exception import HttpDoesNotExistException + # pylint: disable=wrong-import-position from scripts.user_retirement.utils.helpers import ( _config_or_exit, @@ -39,7 +40,7 @@ _fail_exception, _get_error_str_from_exception, _log, - _setup_all_apis_or_exit + _setup_all_apis_or_exit, ) # Return codes for various fail cases diff --git a/scripts/user_retirement/retirement_partner_report.py b/scripts/user_retirement/retirement_partner_report.py index 53bcfa685660..f6f4378d6d1a 100755 --- a/scripts/user_retirement/retirement_partner_report.py +++ b/scripts/user_retirement/retirement_partner_report.py @@ -20,15 +20,15 @@ # Add top-level project path to sys.path before importing scripts code sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))) -from scripts.user_retirement.utils.thirdparty_apis.google_api import DriveApi # pylint: disable=wrong-import-position # pylint: disable=wrong-import-position from scripts.user_retirement.utils.helpers import ( _config_with_drive_or_exit, _fail, _fail_exception, _log, - _setup_lms_api_or_exit + _setup_lms_api_or_exit, ) +from scripts.user_retirement.utils.thirdparty_apis.google_api import DriveApi # pylint: disable=wrong-import-position # Return codes for various fail cases ERR_SETUP_FAILED = -1 diff --git a/scripts/user_retirement/tests/test_get_learners_to_retire.py b/scripts/user_retirement/tests/test_get_learners_to_retire.py index 557398a2720f..42d823bb10af 100644 --- a/scripts/user_retirement/tests/test_get_learners_to_retire.py +++ b/scripts/user_retirement/tests/test_get_learners_to_retire.py @@ -1,9 +1,8 @@ """ Test the get_learners_to_retire.py script """ -from unittest.mock import DEFAULT, patch - import os +from unittest.mock import DEFAULT, patch from click.testing import CliRunner from requests.exceptions import HTTPError diff --git a/scripts/user_retirement/tests/test_retire_one_learner.py b/scripts/user_retirement/tests/test_retire_one_learner.py index 844325ea3ed0..1c8eb149acfc 100644 --- a/scripts/user_retirement/tests/test_retire_one_learner.py +++ b/scripts/user_retirement/tests/test_retire_one_learner.py @@ -13,7 +13,7 @@ ERR_UNKNOWN_STATE, ERR_USER_AT_END_STATE, ERR_USER_IN_WORKING_STATE, - retire_learner + retire_learner, ) from scripts.user_retirement.tests.retirement_helpers import fake_config_file, get_fake_user_retirement from scripts.user_retirement.utils.exception import HttpDoesNotExistException diff --git a/scripts/user_retirement/tests/test_retirement_archive_and_cleanup.py b/scripts/user_retirement/tests/test_retirement_archive_and_cleanup.py index 12c48dda9ff1..a7405d02192b 100644 --- a/scripts/user_retirement/tests/test_retirement_archive_and_cleanup.py +++ b/scripts/user_retirement/tests/test_retirement_archive_and_cleanup.py @@ -21,7 +21,7 @@ ERR_NO_CONFIG, ERR_SETUP_FAILED, _upload_to_s3, - archive_and_cleanup + archive_and_cleanup, ) from scripts.user_retirement.tests.retirement_helpers import fake_config_file, get_fake_user_retirement diff --git a/scripts/user_retirement/tests/test_retirement_bulk_status_update.py b/scripts/user_retirement/tests/test_retirement_bulk_status_update.py index 0cfbeeef3d7a..409a66a38fef 100644 --- a/scripts/user_retirement/tests/test_retirement_bulk_status_update.py +++ b/scripts/user_retirement/tests/test_retirement_bulk_status_update.py @@ -11,7 +11,7 @@ ERR_NO_CONFIG, ERR_SETUP_FAILED, ERR_UPDATING, - update_statuses + update_statuses, ) from scripts.user_retirement.tests.retirement_helpers import fake_config_file, get_fake_user_retirement diff --git a/scripts/user_retirement/tests/test_retirement_partner_report.py b/scripts/user_retirement/tests/test_retirement_partner_report.py index 886f2d9e4073..db2673b614a8 100644 --- a/scripts/user_retirement/tests/test_retirement_partner_report.py +++ b/scripts/user_retirement/tests/test_retirement_partner_report.py @@ -13,10 +13,6 @@ from click.testing import CliRunner from six import PY2, itervalues -from scripts.user_retirement.retirement_partner_report import \ - _generate_report_files_or_exit # pylint: disable=protected-access -from scripts.user_retirement.retirement_partner_report import \ - _get_orgs_and_learners_or_exit # pylint: disable=protected-access from scripts.user_retirement.retirement_partner_report import ( DEFAULT_FIELD_HEADINGS, ERR_BAD_CONFIG, @@ -39,14 +35,16 @@ ORGS_KEY, REPORTING_FILENAME_PREFIX, SETUP_LMS_OR_EXIT, - generate_report + _generate_report_files_or_exit, # pylint: disable=protected-access + _get_orgs_and_learners_or_exit, # pylint: disable=protected-access + generate_report, ) from scripts.user_retirement.tests.retirement_helpers import ( FAKE_ORGS, TEST_PLATFORM_NAME, fake_config_file, fake_google_secrets_file, - flatten_partner_list + flatten_partner_list, ) TEST_CONFIG_YML_NAME = 'test_config.yml' diff --git a/scripts/user_retirement/tests/utils/thirdparty_apis/test_amplitude.py b/scripts/user_retirement/tests/utils/thirdparty_apis/test_amplitude.py index 253834e19cb8..dfc9688eee75 100644 --- a/scripts/user_retirement/tests/utils/thirdparty_apis/test_amplitude.py +++ b/scripts/user_retirement/tests/utils/thirdparty_apis/test_amplitude.py @@ -13,7 +13,7 @@ from scripts.user_retirement.utils.thirdparty_apis.amplitude_api import ( AmplitudeApi, AmplitudeException, - AmplitudeRecoverableException + AmplitudeRecoverableException, ) diff --git a/scripts/user_retirement/tests/utils/thirdparty_apis/test_hubspot.py b/scripts/user_retirement/tests/utils/thirdparty_apis/test_hubspot.py index 85e58b3d953e..ea96e76be7f2 100644 --- a/scripts/user_retirement/tests/utils/thirdparty_apis/test_hubspot.py +++ b/scripts/user_retirement/tests/utils/thirdparty_apis/test_hubspot.py @@ -11,6 +11,7 @@ # This module is imported separately solely so it can be re-loaded below. from scripts.user_retirement.utils.thirdparty_apis import hubspot_api + # This HubspotAPI class will be used without being re-loaded. from scripts.user_retirement.utils.thirdparty_apis.hubspot_api import HubspotAPI diff --git a/scripts/user_retirement/utils/helpers.py b/scripts/user_retirement/utils/helpers.py index 804852833436..ce40323786e7 100644 --- a/scripts/user_retirement/utils/helpers.py +++ b/scripts/user_retirement/utils/helpers.py @@ -17,17 +17,25 @@ import yaml from six import text_type -from scripts.user_retirement.utils.edx_api import LmsApi # pylint: disable=wrong-import-position -from scripts.user_retirement.utils.edx_api import CredentialsApi, EcommerceApi, LicenseManagerApi -from scripts.user_retirement.utils.thirdparty_apis.amplitude_api import \ - AmplitudeApi # pylint: disable=wrong-import-position +from scripts.user_retirement.utils.edx_api import ( + CredentialsApi, + EcommerceApi, + LicenseManagerApi, + LmsApi, # pylint: disable=wrong-import-position +) +from scripts.user_retirement.utils.thirdparty_apis.amplitude_api import ( + AmplitudeApi, # pylint: disable=wrong-import-position +) from scripts.user_retirement.utils.thirdparty_apis.braze_api import BrazeApi # pylint: disable=wrong-import-position -from scripts.user_retirement.utils.thirdparty_apis.hubspot_api import \ - HubspotAPI # pylint: disable=wrong-import-position -from scripts.user_retirement.utils.thirdparty_apis.salesforce_api import \ - SalesforceApi # pylint: disable=wrong-import-position -from scripts.user_retirement.utils.thirdparty_apis.segment_api import \ - SegmentApi # pylint: disable=wrong-import-position +from scripts.user_retirement.utils.thirdparty_apis.hubspot_api import ( + HubspotAPI, # pylint: disable=wrong-import-position +) +from scripts.user_retirement.utils.thirdparty_apis.salesforce_api import ( + SalesforceApi, # pylint: disable=wrong-import-position +) +from scripts.user_retirement.utils.thirdparty_apis.segment_api import ( + SegmentApi, # pylint: disable=wrong-import-position +) def _log(kind, message): diff --git a/scripts/user_retirement/utils/thirdparty_apis/google_api.py b/scripts/user_retirement/utils/thirdparty_apis/google_api.py index e43670c01caf..8ec36a099686 100644 --- a/scripts/user_retirement/utils/thirdparty_apis/google_api.py +++ b/scripts/user_retirement/utils/thirdparty_apis/google_api.py @@ -19,6 +19,7 @@ from google.oauth2.credentials import Credentials from googleapiclient.discovery import build from googleapiclient.errors import HttpError + # I'm not super happy about this since the function is protected with a leading # underscore, but the next best thing is literally copying this ~40 line # function verbatim. diff --git a/scripts/xsslint/tests/test_linters.py b/scripts/xsslint/tests/test_linters.py index 2aba52ed78d7..4bd78520dbfb 100644 --- a/scripts/xsslint/tests/test_linters.py +++ b/scripts/xsslint/tests/test_linters.py @@ -7,11 +7,12 @@ from unittest import TestCase from ddt import data, ddt - from xsslint.linters import ( - JavaScriptLinter, MakoTemplateLinter, - PythonLinter, UnderscoreTemplateLinter, - DjangoTemplateLinter + DjangoTemplateLinter, + JavaScriptLinter, + MakoTemplateLinter, + PythonLinter, + UnderscoreTemplateLinter, ) from xsslint.reporting import FileResults from xsslint.utils import ParseString diff --git a/scripts/xsslint/tests/test_main.py b/scripts/xsslint/tests/test_main.py index 050eb3bdd56e..5a7c2449e2ac 100644 --- a/scripts/xsslint/tests/test_main.py +++ b/scripts/xsslint/tests/test_main.py @@ -6,9 +6,7 @@ import json import re from io import StringIO -from unittest import TestCase - -from unittest import mock +from unittest import TestCase, mock from xsslint.linters import JavaScriptLinter, MakoTemplateLinter, PythonLinter, UnderscoreTemplateLinter from xsslint.main import _build_ruleset, _lint diff --git a/scripts/xsslint/tests/test_utils.py b/scripts/xsslint/tests/test_utils.py index bbf2badcb5a1..842355832cf6 100644 --- a/scripts/xsslint/tests/test_utils.py +++ b/scripts/xsslint/tests/test_utils.py @@ -1,7 +1,6 @@ from unittest import TestCase from ddt import data, ddt - from xsslint.utils import StringLines diff --git a/scripts/xsslint/xss_linter.py b/scripts/xsslint/xss_linter.py index 76de199f0962..ad58685e41b1 100755 --- a/scripts/xsslint/xss_linter.py +++ b/scripts/xsslint/xss_linter.py @@ -10,9 +10,9 @@ import os import re import sys - from functools import reduce from io import StringIO + from xsslint.reporting import SummaryResults from xsslint.rules import RuleSet from xsslint.utils import is_skip_dir diff --git a/scripts/xsslint/xsslint/default_config.py b/scripts/xsslint/xsslint/default_config.py index e5075785e157..52ffb1ebd0fc 100644 --- a/scripts/xsslint/xsslint/default_config.py +++ b/scripts/xsslint/xsslint/default_config.py @@ -2,9 +2,11 @@ from xsslint.linters import ( - JavaScriptLinter, MakoTemplateLinter, - PythonLinter, UnderscoreTemplateLinter, - DjangoTemplateLinter + DjangoTemplateLinter, + JavaScriptLinter, + MakoTemplateLinter, + PythonLinter, + UnderscoreTemplateLinter, ) # Define the directories that should be ignored by the script. diff --git a/scripts/xsslint/xsslint/django_linter.py b/scripts/xsslint/xsslint/django_linter.py index ea909a612819..5e683b71900f 100644 --- a/scripts/xsslint/xsslint/django_linter.py +++ b/scripts/xsslint/xsslint/django_linter.py @@ -2,8 +2,9 @@ Classes for Django Template Linting. """ import re -from xsslint.utils import Expression, StringLines + from xsslint.reporting import ExpressionRuleViolation +from xsslint.utils import Expression, StringLines class TransExpression(Expression): diff --git a/scripts/xsslint/xsslint/linters.py b/scripts/xsslint/xsslint/linters.py index 541abd5811b6..fac93ddc7d11 100644 --- a/scripts/xsslint/xsslint/linters.py +++ b/scripts/xsslint/xsslint/linters.py @@ -10,10 +10,10 @@ import textwrap from xsslint import visitors +from xsslint.django_linter import BlockTransExpression, HtmlInterpolateExpression, TransExpression from xsslint.reporting import ExpressionRuleViolation, FileResults, RuleViolation from xsslint.rules import RuleSet from xsslint.utils import Expression, ParseString, StringLines, is_skip_dir -from xsslint.django_linter import TransExpression, BlockTransExpression, HtmlInterpolateExpression class BaseLinter: diff --git a/scripts/xsslint/xsslint/reporting.py b/scripts/xsslint/xsslint/reporting.py index 8d85de76c562..9180e32f8a75 100644 --- a/scripts/xsslint/xsslint/reporting.py +++ b/scripts/xsslint/xsslint/reporting.py @@ -7,7 +7,6 @@ import os import re - from xsslint.utils import StringLines diff --git a/scripts/xsslint_config.py b/scripts/xsslint_config.py index 2f463a49dffb..ad8028bc0dc7 100644 --- a/scripts/xsslint_config.py +++ b/scripts/xsslint_config.py @@ -11,9 +11,11 @@ sys.path.append(os.path.join(scripts_dir, 'xsslint')) # pylint: disable=import-error,wrong-import-position from xsslint.linters import ( - JavaScriptLinter, MakoTemplateLinter, - PythonLinter, UnderscoreTemplateLinter, - DjangoTemplateLinter + DjangoTemplateLinter, + JavaScriptLinter, + MakoTemplateLinter, + PythonLinter, + UnderscoreTemplateLinter, ) # Define the directories that should be ignored by the script. diff --git a/xmodule/annotatable_block.py b/xmodule/annotatable_block.py index 6954b66527df..bbc1380b5640 100644 --- a/xmodule/annotatable_block.py +++ b/xmodule/annotatable_block.py @@ -14,13 +14,8 @@ from openedx.core.djangolib.markup import HTML, Text from xmodule.editing_block import EditingMixin from xmodule.raw_block import RawMixin -from xmodule.util.builtin_assets import add_webpack_js_to_fragment, add_css_to_fragment -from xmodule.x_module import ( - ResourceTemplates, - shim_xmodule_js, - XModuleMixin, - XModuleToXBlockMixin, -) +from xmodule.util.builtin_assets import add_css_to_fragment, add_webpack_js_to_fragment +from xmodule.x_module import ResourceTemplates, XModuleMixin, XModuleToXBlockMixin, shim_xmodule_js from xmodule.xml_block import XmlMixin log = logging.getLogger(__name__) diff --git a/xmodule/block_metadata_utils.py b/xmodule/block_metadata_utils.py index 7ab0545480a0..2bb3e50a353a 100644 --- a/xmodule/block_metadata_utils.py +++ b/xmodule/block_metadata_utils.py @@ -8,9 +8,9 @@ from datetime import datetime from logging import getLogger -from markupsafe import Markup from dateutil.tz import tzlocal +from markupsafe import Markup logger = getLogger(__name__) # pylint: disable=invalid-name diff --git a/xmodule/capa_block.py b/xmodule/capa_block.py index 55c593f4772f..3ec75e9a43d2 100644 --- a/xmodule/capa_block.py +++ b/xmodule/capa_block.py @@ -44,6 +44,11 @@ from xblock.progress import Progress from xblock.scorable import ScorableXBlockMixin, Score, ShowCorrectness from xblocks_contrib.problem import ProblemBlock as _ExtractedProblemBlock +from xblocks_contrib.problem.capa import responsetypes +from xblocks_contrib.problem.capa.capa_problem import LoncapaProblem, LoncapaSystem +from xblocks_contrib.problem.capa.inputtypes import Status +from xblocks_contrib.problem.capa.responsetypes import LoncapaProblemError, ResponseError, StudentInputError +from xblocks_contrib.problem.capa.util import convert_files_to_filenames, get_inner_html_from_xpath from common.djangoapps.xblock_django.constants import ( ATTR_KEY_DEPRECATED_ANONYMOUS_USER_ID, @@ -51,11 +56,6 @@ ATTR_KEY_USER_IS_STAFF, ) from openedx.core.djangolib.markup import HTML, Text -from xblocks_contrib.problem.capa import responsetypes -from xblocks_contrib.problem.capa.capa_problem import LoncapaProblem, LoncapaSystem -from xblocks_contrib.problem.capa.inputtypes import Status -from xblocks_contrib.problem.capa.responsetypes import LoncapaProblemError, ResponseError, StudentInputError -from xblocks_contrib.problem.capa.util import convert_files_to_filenames, get_inner_html_from_xpath from xmodule.raw_block import RawMixin from xmodule.util.builtin_assets import add_css_to_fragment, add_webpack_js_to_fragment from xmodule.x_module import XModuleMixin, XModuleToXBlockMixin, shim_xmodule_js diff --git a/xmodule/conditional_block.py b/xmodule/conditional_block.py index 78a5b8c1c1c9..003513c97a6a 100644 --- a/xmodule/conditional_block.py +++ b/xmodule/conditional_block.py @@ -20,15 +20,8 @@ from xmodule.studio_editable import StudioEditableBlock from xmodule.util.builtin_assets import add_webpack_js_to_fragment from xmodule.validation import StudioValidation, StudioValidationMessage +from xmodule.x_module import STUDENT_VIEW, ResourceTemplates, XModuleMixin, XModuleToXBlockMixin, shim_xmodule_js from xmodule.xml_block import XmlMixin -from xmodule.x_module import ( - ResourceTemplates, - shim_xmodule_js, - STUDENT_VIEW, - XModuleMixin, - XModuleToXBlockMixin, -) - log = logging.getLogger('edx.' + __name__) diff --git a/xmodule/contentstore/mongo.py b/xmodule/contentstore/mongo.py index 3e36c5509131..a252975b4a2c 100644 --- a/xmodule/contentstore/mongo.py +++ b/xmodule/contentstore/mongo.py @@ -11,7 +11,7 @@ import pymongo from bson.son import SON from fs.osfs import OSFS -from gridfs.errors import NoFile, FileExists +from gridfs.errors import FileExists, NoFile from opaque_keys.edx.keys import AssetKey from xmodule.contentstore.content import XASSET_LOCATION_TAG diff --git a/xmodule/course_block.py b/xmodule/course_block.py index 17dc4d877be7..93402924637b 100644 --- a/xmodule/course_block.py +++ b/xmodule/course_block.py @@ -17,12 +17,13 @@ from lxml import etree from path import Path as path from xblock.fields import Boolean, Date, Dict, Float, Integer, List, Scope, String -from openedx.core.djangoapps.video_pipeline.models import VideoUploadsEnabledByDefault + from openedx.core.djangoapps.video_config.sharing import ( COURSE_VIDEO_SHARING_ALL_VIDEOS, COURSE_VIDEO_SHARING_NONE, COURSE_VIDEO_SHARING_PER_VIDEO, ) +from openedx.core.djangoapps.video_pipeline.models import VideoUploadsEnabledByDefault from openedx.core.lib.license import LicenseMixin from openedx.core.lib.teams_config import TeamsConfig # lint-amnesty, pylint: disable=unused-import from xmodule import course_metadata_utils diff --git a/xmodule/course_metadata_utils.py b/xmodule/course_metadata_utils.py index e0320e6043e7..ea6c15cc803c 100644 --- a/xmodule/course_metadata_utils.py +++ b/xmodule/course_metadata_utils.py @@ -7,13 +7,12 @@ """ -import dateutil.parser - from base64 import b32encode from datetime import datetime, timedelta from math import exp from zoneinfo import ZoneInfo +import dateutil.parser DEFAULT_START_DATE = datetime(2030, 1, 1, tzinfo=ZoneInfo("UTC")) diff --git a/xmodule/discussion_block.py b/xmodule/discussion_block.py index 97bb724930c5..aac709755520 100644 --- a/xmodule/discussion_block.py +++ b/xmodule/discussion_block.py @@ -4,6 +4,7 @@ import logging import urllib + from django.conf import settings from django.contrib.staticfiles.storage import staticfiles_storage from django.template.loader import render_to_string diff --git a/xmodule/error_block.py b/xmodule/error_block.py index 51c895a3e864..e3c5d775e4ec 100644 --- a/xmodule/error_block.py +++ b/xmodule/error_block.py @@ -17,11 +17,7 @@ from xmodule.errortracker import exc_info_to_str from xmodule.modulestore import EdxJSONEncoder -from xmodule.x_module import ( - ResourceTemplates, - XModuleMixin, - XModuleToXBlockMixin, -) +from xmodule.x_module import ResourceTemplates, XModuleMixin, XModuleToXBlockMixin log = logging.getLogger(__name__) diff --git a/xmodule/graders.py b/xmodule/graders.py index 0a559e470aa2..91478d666810 100644 --- a/xmodule/graders.py +++ b/xmodule/graders.py @@ -14,7 +14,6 @@ from xmodule.util.misc import get_short_labeler - log = logging.getLogger("edx.courseware") diff --git a/xmodule/hidden_block.py b/xmodule/hidden_block.py index 0d5c288d75c3..efcaa41d0cc8 100644 --- a/xmodule/hidden_block.py +++ b/xmodule/hidden_block.py @@ -4,12 +4,10 @@ from web_fragments.fragment import Fragment from xblock.core import XBlock + from xmodule.raw_block import RawMixin +from xmodule.x_module import XModuleMixin, XModuleToXBlockMixin from xmodule.xml_block import XmlMixin -from xmodule.x_module import ( - XModuleMixin, - XModuleToXBlockMixin, -) @XBlock.needs("i18n") diff --git a/xmodule/html_block.py b/xmodule/html_block.py index 27a2b51e4a31..bd1276f2d920 100644 --- a/xmodule/html_block.py +++ b/xmodule/html_block.py @@ -25,14 +25,9 @@ from xmodule.edxnotes_utils import edxnotes from xmodule.html_checker import check_html from xmodule.stringify import stringify_children -from xmodule.util.builtin_assets import add_webpack_js_to_fragment, add_css_to_fragment +from xmodule.util.builtin_assets import add_css_to_fragment, add_webpack_js_to_fragment from xmodule.util.misc import escape_html_characters -from xmodule.x_module import ( - ResourceTemplates, - shim_xmodule_js, - XModuleMixin, - XModuleToXBlockMixin, -) +from xmodule.x_module import ResourceTemplates, XModuleMixin, XModuleToXBlockMixin, shim_xmodule_js from xmodule.xml_block import XmlMixin, name_to_pathname log = logging.getLogger("edx.courseware") diff --git a/xmodule/item_bank_block.py b/xmodule/item_bank_block.py index b28412d9b920..5a5ab0400815 100644 --- a/xmodule/item_bank_block.py +++ b/xmodule/item_bank_block.py @@ -25,12 +25,7 @@ from xmodule.studio_editable import StudioEditableBlock from xmodule.util.builtin_assets import add_webpack_js_to_fragment from xmodule.validation import StudioValidation, StudioValidationMessage -from xmodule.x_module import ( - STUDENT_VIEW, - ResourceTemplates, - XModuleMixin, - shim_xmodule_js, -) +from xmodule.x_module import STUDENT_VIEW, ResourceTemplates, XModuleMixin, shim_xmodule_js from xmodule.xml_block import XmlMixin _ = lambda text: text diff --git a/xmodule/library_content_block.py b/xmodule/library_content_block.py index 801533885bce..2ff86fd3abe4 100644 --- a/xmodule/library_content_block.py +++ b/xmodule/library_content_block.py @@ -22,8 +22,8 @@ from webob import Response from xblock.core import XBlock from xblock.fields import Boolean, Scope, String - from xblocks_contrib.problem.capa.responsetypes import registry + from xmodule.item_bank_block import ItemBankMixin from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError diff --git a/xmodule/library_root_xblock.py b/xmodule/library_root_xblock.py index cfe2ba6276af..5189ac4b66bc 100644 --- a/xmodule/library_root_xblock.py +++ b/xmodule/library_root_xblock.py @@ -8,6 +8,7 @@ from web_fragments.fragment import Fragment from xblock.core import XBlock from xblock.fields import Boolean, List, Scope, String + from xmodule.studio_editable import StudioEditableBlock log = logging.getLogger(__name__) diff --git a/xmodule/library_tools.py b/xmodule/library_tools.py index eca227dd47f4..c179a2d82c8b 100644 --- a/xmodule/library_tools.py +++ b/xmodule/library_tools.py @@ -8,8 +8,8 @@ from opaque_keys.edx.locator import LibraryLocator from user_tasks.models import UserTaskStatus -from openedx.core.lib import ensure_cms from openedx.core.djangoapps.content_libraries import tasks as library_tasks +from openedx.core.lib import ensure_cms from xmodule.library_content_block import LegacyLibraryContentBlock from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.exceptions import ItemNotFoundError diff --git a/xmodule/lti_block.py b/xmodule/lti_block.py index 2984cb09d88a..622ab6e8cd0b 100644 --- a/xmodule/lti_block.py +++ b/xmodule/lti_block.py @@ -77,22 +77,14 @@ from xblock.fields import Boolean, Float from xblocks_contrib.lti import LTIBlock as _ExtractedLTIBlock -from common.djangoapps.xblock_django.constants import ( - ATTR_KEY_ANONYMOUS_USER_ID, - ATTR_KEY_USER_ROLE, -) +from common.djangoapps.xblock_django.constants import ATTR_KEY_ANONYMOUS_USER_ID, ATTR_KEY_USER_ROLE from openedx.core.djangolib.markup import HTML, Text from xmodule.editing_block import EditingMixin from xmodule.lti_2_util import LTI20BlockMixin, LTIError from xmodule.mako_block import MakoTemplateBlockBase from xmodule.raw_block import EmptyDataRawMixin -from xmodule.util.builtin_assets import add_webpack_js_to_fragment, add_css_to_fragment -from xmodule.x_module import ( - ResourceTemplates, - shim_xmodule_js, - XModuleMixin, - XModuleToXBlockMixin, -) +from xmodule.util.builtin_assets import add_css_to_fragment, add_webpack_js_to_fragment +from xmodule.x_module import ResourceTemplates, XModuleMixin, XModuleToXBlockMixin, shim_xmodule_js from xmodule.xml_block import XmlMixin log = logging.getLogger(__name__) diff --git a/xmodule/modulestore/django.py b/xmodule/modulestore/django.py index c15f03a4e33d..7ac4c4d7d704 100644 --- a/xmodule/modulestore/django.py +++ b/xmodule/modulestore/django.py @@ -4,13 +4,12 @@ Passes settings.MODULESTORE as kwargs to MongoModuleStore """ -from contextlib import contextmanager -from importlib import import_module -import importlib.resources as resources import gettext +import importlib.resources as resources import logging - import re # lint-amnesty, pylint: disable=wrong-import-order +from contextlib import contextmanager +from importlib import import_module from django.conf import settings @@ -19,17 +18,23 @@ if not settings.configured: settings.configure() -from django.contrib.staticfiles.storage import staticfiles_storage # lint-amnesty, pylint: disable=wrong-import-position -from django.core.cache import caches, InvalidCacheBackendError # lint-amnesty, pylint: disable=wrong-import-position import django.dispatch # lint-amnesty, pylint: disable=wrong-import-position import django.utils # lint-amnesty, pylint: disable=wrong-import-position +from django.contrib.staticfiles.storage import ( # lint-amnesty, pylint: disable=wrong-import-position + staticfiles_storage, +) +from django.core.cache import InvalidCacheBackendError, caches # lint-amnesty, pylint: disable=wrong-import-position from django.utils.translation import get_language, to_locale # lint-amnesty, pylint: disable=wrong-import-position from edx_django_utils.cache import DEFAULT_REQUEST_CACHE # lint-amnesty, pylint: disable=wrong-import-position from xmodule.contentstore.django import contentstore # lint-amnesty, pylint: disable=wrong-import-position -from xmodule.modulestore.draft_and_published import BranchSettingMixin # lint-amnesty, pylint: disable=wrong-import-position +from xmodule.modulestore.draft_and_published import ( # lint-amnesty, pylint: disable=wrong-import-position + BranchSettingMixin, +) from xmodule.modulestore.mixed import MixedModuleStore # lint-amnesty, pylint: disable=wrong-import-position -from xmodule.util.xmodule_django import get_current_request_hostname # lint-amnesty, pylint: disable=wrong-import-position +from xmodule.util.xmodule_django import ( # lint-amnesty, pylint: disable=wrong-import-position + get_current_request_hostname, +) from .api import ( # lint-amnesty, pylint: disable=wrong-import-position get_javascript_i18n_file_name, @@ -40,9 +45,10 @@ # We also may not always have the current request user (crum) module available try: - from common.djangoapps.xblock_django.user_service import DjangoXBlockUserService from crum import get_current_user + from common.djangoapps.xblock_django.user_service import DjangoXBlockUserService + HAS_USER_SERVICE = True except ImportError: HAS_USER_SERVICE = False diff --git a/xmodule/modulestore/inheritance.py b/xmodule/modulestore/inheritance.py index a41bf84d99d8..faa050fc5e2d 100644 --- a/xmodule/modulestore/inheritance.py +++ b/xmodule/modulestore/inheritance.py @@ -4,6 +4,7 @@ import warnings + from django.utils import timezone from xblock.core import XBlockMixin from xblock.fields import Boolean, Date, Dict, Float, Integer, List, Scope, String, Timedelta diff --git a/xmodule/modulestore/mixed.py b/xmodule/modulestore/mixed.py index b196eb2ea417..869edf8467ad 100644 --- a/xmodule/modulestore/mixed.py +++ b/xmodule/modulestore/mixed.py @@ -7,8 +7,8 @@ import functools import itertools import logging -from datetime import datetime, timezone from contextlib import contextmanager +from datetime import datetime, timezone from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey @@ -19,7 +19,7 @@ XBLOCK_CREATED, XBLOCK_DELETED, XBLOCK_PUBLISHED, - XBLOCK_UPDATED + XBLOCK_UPDATED, ) from xmodule.assetstore import AssetMetadata diff --git a/xmodule/modulestore/mongo/__init__.py b/xmodule/modulestore/mongo/__init__.py index 4fc645a4ca72..6bbbb0dd9f24 100644 --- a/xmodule/modulestore/mongo/__init__.py +++ b/xmodule/modulestore/mongo/__init__.py @@ -4,6 +4,7 @@ from xmodule.modulestore.mongo.base import MongoKeyValueStore, MongoModuleStore + # Backwards compatibility for prod systems that refererence # xmodule.modulestore.mongo.DraftMongoModuleStore from xmodule.modulestore.mongo.draft import DraftModuleStore as DraftMongoModuleStore diff --git a/xmodule/modulestore/mongo/draft.py b/xmodule/modulestore/mongo/draft.py index 78031d04cf2a..c9cd50c3fa5a 100644 --- a/xmodule/modulestore/mongo/draft.py +++ b/xmodule/modulestore/mongo/draft.py @@ -13,16 +13,13 @@ from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.draft_and_published import DIRECT_ONLY_CATEGORIES, UnsupportedRevisionError -from xmodule.modulestore.exceptions import ( - InvalidBranchSetting, - ItemNotFoundError -) +from xmodule.modulestore.exceptions import InvalidBranchSetting, ItemNotFoundError from xmodule.modulestore.mongo.base import ( SORT_REVISION_FAVOR_DRAFT, MongoModuleStore, MongoRevisionKey, as_draft, - as_published + as_published, ) log = logging.getLogger(__name__) diff --git a/xmodule/modulestore/mongoengine_fields.py b/xmodule/modulestore/mongoengine_fields.py index 532d5f3a00c3..dcfb75c84947 100644 --- a/xmodule/modulestore/mongoengine_fields.py +++ b/xmodule/modulestore/mongoengine_fields.py @@ -4,7 +4,6 @@ import mongoengine - from opaque_keys.edx.keys import CourseKey, UsageKey from opaque_keys.edx.locations import Location diff --git a/xmodule/modulestore/search.py b/xmodule/modulestore/search.py index fc065078968b..262e8d53880e 100644 --- a/xmodule/modulestore/search.py +++ b/xmodule/modulestore/search.py @@ -3,10 +3,10 @@ from logging import getLogger - +from common.djangoapps.student.roles import GlobalStaff # lint-amnesty, pylint: disable=unused-import from lms.djangoapps.courseware.access import has_access from lms.djangoapps.courseware.masquerade import MASQUERADE_SETTINGS_KEY -from common.djangoapps.student.roles import GlobalStaff # lint-amnesty, pylint: disable=unused-import + from .exceptions import ItemNotFoundError, NoPathToItem LOGGER = getLogger(__name__) diff --git a/xmodule/modulestore/split_mongo/mongo_connection.py b/xmodule/modulestore/split_mongo/mongo_connection.py index c123faf68b6d..80569e004d3d 100644 --- a/xmodule/modulestore/split_mongo/mongo_connection.py +++ b/xmodule/modulestore/split_mongo/mongo_connection.py @@ -13,24 +13,25 @@ from time import time from zoneinfo import ZoneInfo +import pymongo from ccx_keys.locator import CCXLocator -from django.core.cache import caches, InvalidCacheBackendError +from django.core.cache import InvalidCacheBackendError, caches from django.db.models import F from django.db.models.functions import Lower from django.db.models.lookups import Exact from django.db.transaction import TransactionManagementError -import pymongo -# Import this just to export it -from pymongo.errors import DuplicateKeyError # pylint: disable=unused-import from edx_django_utils import monitoring from edx_django_utils.cache import RequestCache +# Import this just to export it +from pymongo.errors import DuplicateKeyError # pylint: disable=unused-import + from common.djangoapps.split_modulestore_django.models import SplitModulestoreCourseIndex +from openedx.core.lib.cache_utils import request_cached from xmodule.exceptions import HeartbeatFailure from xmodule.modulestore import BlockData from xmodule.modulestore.split_mongo import BlockKey from xmodule.mongo_utils import connect_to_mongodb, create_collection_index -from openedx.core.lib.cache_utils import request_cached log = logging.getLogger(__name__) diff --git a/xmodule/modulestore/split_mongo/runtime.py b/xmodule/modulestore/split_mongo/runtime.py index 2ebd6fe805d4..1b78255ce2ed 100644 --- a/xmodule/modulestore/split_mongo/runtime.py +++ b/xmodule/modulestore/split_mongo/runtime.py @@ -23,7 +23,7 @@ from xmodule.modulestore.split_mongo.id_manager import SplitMongoIdManager from xmodule.modulestore.split_mongo.split_mongo_kvs import SplitMongoKVS from xmodule.util.misc import get_library_or_course_attribute -from xmodule.x_module import XModuleMixin, ModuleStoreRuntime +from xmodule.x_module import ModuleStoreRuntime, XModuleMixin log = logging.getLogger(__name__) diff --git a/xmodule/modulestore/split_mongo/split.py b/xmodule/modulestore/split_mongo/split.py index aeacac25333e..2a8eebabdc5e 100644 --- a/xmodule/modulestore/split_mongo/split.py +++ b/xmodule/modulestore/split_mongo/split.py @@ -65,13 +65,7 @@ from bson.objectid import ObjectId from ccx_keys.locator import CCXBlockUsageLocator, CCXLocator from opaque_keys.edx.keys import CourseKey -from opaque_keys.edx.locator import ( - BlockUsageLocator, - CourseLocator, - DefinitionLocator, - LibraryLocator, - LocalId, -) +from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator, DefinitionLocator, LibraryLocator, LocalId from path import Path as path from xblock.core import XBlock from xblock.fields import Reference, ReferenceList, ReferenceValueDict, Scope @@ -88,7 +82,7 @@ ModuleStoreEnum, ModuleStoreWriteBase, SortedAssetList, - inheritance + inheritance, ) from xmodule.modulestore.exceptions import ( DuplicateCourseError, @@ -96,14 +90,14 @@ InsufficientSpecificationError, MultipleCourseBlocksFound, MultipleLibraryBlocksFound, - VersionConflictError + VersionConflictError, ) from xmodule.modulestore.split_mongo import CourseEnvelope -from xmodule.modulestore.split_mongo.mongo_connection import DuplicateKeyError, DjangoFlexPersistenceBackend +from xmodule.modulestore.split_mongo.mongo_connection import DjangoFlexPersistenceBackend, DuplicateKeyError from xmodule.modulestore.store_utilities import DETACHED_XBLOCK_TYPES from xmodule.partitions.partitions_service import PartitionService -from xmodule.util.misc import get_library_or_course_attribute from xmodule.util.keys import BlockKey, derive_key +from xmodule.util.misc import get_library_or_course_attribute from ..exceptions import ItemNotFoundError from .runtime import SplitModuleStoreRuntime diff --git a/xmodule/modulestore/split_mongo/split_draft.py b/xmodule/modulestore/split_mongo/split_draft.py index 62ee4166df9d..25320e6bd62f 100644 --- a/xmodule/modulestore/split_mongo/split_draft.py +++ b/xmodule/modulestore/split_mongo/split_draft.py @@ -9,7 +9,7 @@ from xmodule.modulestore.draft_and_published import ( DIRECT_ONLY_CATEGORIES, ModuleStoreDraftAndPublished, - UnsupportedRevisionError + UnsupportedRevisionError, ) from xmodule.modulestore.exceptions import InsufficientSpecificationError, ItemNotFoundError from xmodule.modulestore.split_mongo import BlockKey diff --git a/xmodule/modulestore/store_utilities.py b/xmodule/modulestore/store_utilities.py index c177104be5ad..ae4379f204ac 100644 --- a/xmodule/modulestore/store_utilities.py +++ b/xmodule/modulestore/store_utilities.py @@ -6,7 +6,6 @@ from xblock.core import XBlock - DETACHED_XBLOCK_TYPES = {name for name, __ in XBlock.load_tagged_classes("detached")} diff --git a/xmodule/modulestore/tests/conftest.py b/xmodule/modulestore/tests/conftest.py index 3743512aba47..fe72eed5bca5 100644 --- a/xmodule/modulestore/tests/conftest.py +++ b/xmodule/modulestore/tests/conftest.py @@ -7,9 +7,8 @@ from unittest.mock import Mock, patch import pytest -from path import Path - from django.test.utils import override_settings +from path import Path from xmodule.modulestore.api import get_python_locale_root diff --git a/xmodule/modulestore/tests/django_utils.py b/xmodule/modulestore/tests/django_utils.py index f20aaa3a56d3..29b978c9b790 100644 --- a/xmodule/modulestore/tests/django_utils.py +++ b/xmodule/modulestore/tests/django_utils.py @@ -16,6 +16,13 @@ from django.db import connections, transaction from django.test import TestCase from django.test.utils import override_settings + +from common.djangoapps.split_modulestore_django.models import SplitModulestoreCourseIndex +from common.djangoapps.student.models import CourseEnrollment +from common.djangoapps.student.tests.factories import AdminFactory, InstructorFactory, StaffFactory, UserFactory +from lms.djangoapps.courseware.field_overrides import OverrideFieldData +from openedx.core.djangolib.testing.utils import CacheIsolationMixin, CacheIsolationTestCase, FilteredQueryCountMixin +from openedx.core.lib.tempdir import mkdtemp_clean from xmodule.contentstore.content import StaticContent from xmodule.contentstore.django import _CONTENTSTORE from xmodule.modulestore import ModuleStoreEnum @@ -23,14 +30,6 @@ from xmodule.modulestore.tests.factories import XMODULE_FACTORY_LOCK from xmodule.modulestore.tests.mongo_connection import MONGO_HOST, MONGO_PORT_NUM -from lms.djangoapps.courseware.field_overrides import OverrideFieldData -from openedx.core.djangolib.testing.utils import CacheIsolationMixin, CacheIsolationTestCase, FilteredQueryCountMixin -from openedx.core.lib.tempdir import mkdtemp_clean -from common.djangoapps.split_modulestore_django.models import SplitModulestoreCourseIndex -from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.tests.factories import AdminFactory, UserFactory, InstructorFactory -from common.djangoapps.student.tests.factories import StaffFactory - class CourseUserType(Enum): """ diff --git a/xmodule/modulestore/tests/factories.py b/xmodule/modulestore/tests/factories.py index ca2f838238b0..2bca883018f0 100644 --- a/xmodule/modulestore/tests/factories.py +++ b/xmodule/modulestore/tests/factories.py @@ -10,8 +10,8 @@ import traceback from collections import defaultdict from contextlib import contextmanager -from uuid import uuid4 from unittest.mock import patch +from uuid import uuid4 from zoneinfo import ZoneInfo import pymongo.message @@ -27,7 +27,6 @@ from xmodule.modulestore.tests.sample_courses import TOY_BLOCK_INFO_TREE, default_block_info_tree from xmodule.tabs import CourseTab - LOG = logging.getLogger(__name__) diff --git a/xmodule/modulestore/tests/test_abstraction.py b/xmodule/modulestore/tests/test_abstraction.py index d8dfbceeea7e..b806c9786013 100644 --- a/xmodule/modulestore/tests/test_abstraction.py +++ b/xmodule/modulestore/tests/test_abstraction.py @@ -4,6 +4,7 @@ from unittest import TestCase + import pytest from xmodule.modulestore import ModuleStoreRead, ModuleStoreWrite diff --git a/xmodule/modulestore/tests/test_api.py b/xmodule/modulestore/tests/test_api.py index caef59a68e16..afaf4273790c 100644 --- a/xmodule/modulestore/tests/test_api.py +++ b/xmodule/modulestore/tests/test_api.py @@ -4,14 +4,12 @@ from unittest.mock import Mock from django.conf import settings - -from lti_consumer.lti_xblock import LtiConsumerXBlock from done import DoneXBlock +from lti_consumer.lti_xblock import LtiConsumerXBlock from xblock.field_data import DictFieldData - -from xblock.test.tools import TestRuntime from xblock.test.test_runtime import TestSimpleMixin -from xmodule.video_block import VideoBlock +from xblock.test.tools import TestRuntime + from xmodule.modulestore.api import ( get_javascript_i18n_file_name, get_javascript_i18n_file_path, @@ -19,6 +17,7 @@ get_root_module_name, get_xblock_root_module_name, ) +from xmodule.video_block import VideoBlock def test_get_root_module_name(): diff --git a/xmodule/modulestore/tests/test_assetstore.py b/xmodule/modulestore/tests/test_assetstore.py index 50a8008b62a3..a43e4b2caa39 100644 --- a/xmodule/modulestore/tests/test_assetstore.py +++ b/xmodule/modulestore/tests/test_assetstore.py @@ -6,10 +6,10 @@ import unittest from datetime import datetime, timedelta -import pytest -import ddt from zoneinfo import ZoneInfo +import ddt +import pytest from django.test import TestCase from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import CourseLocator @@ -19,11 +19,7 @@ from xmodule.modulestore import IncorrectlySortedList, ModuleStoreEnum, SortedAssetList from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.tests.utils import ( - SPLIT_MODULESTORE_SETUP, - MixedModulestoreBuilder, - XmlModulestoreBuilder -) +from xmodule.modulestore.tests.utils import SPLIT_MODULESTORE_SETUP, MixedModulestoreBuilder, XmlModulestoreBuilder class AssetStoreTestData: diff --git a/xmodule/modulestore/tests/test_contentstore.py b/xmodule/modulestore/tests/test_contentstore.py index b5d755a8bea1..cb12221bb10d 100644 --- a/xmodule/modulestore/tests/test_contentstore.py +++ b/xmodule/modulestore/tests/test_contentstore.py @@ -10,9 +10,9 @@ from tempfile import mkdtemp from uuid import uuid4 -import pytest import ddt import path +import pytest from opaque_keys.edx.keys import AssetKey from opaque_keys.edx.locator import AssetLocator, CourseLocator diff --git a/xmodule/modulestore/tests/test_libraries.py b/xmodule/modulestore/tests/test_libraries.py index 2a82db889b5f..58cb6cefad14 100644 --- a/xmodule/modulestore/tests/test_libraries.py +++ b/xmodule/modulestore/tests/test_libraries.py @@ -4,8 +4,8 @@ Higher-level tests are in `cms/djangoapps/contentstore`. """ -import pytest import ddt +import pytest from bson.objectid import ObjectId from opaque_keys.edx.locator import LibraryLocator diff --git a/xmodule/modulestore/tests/test_mixed_modulestore.py b/xmodule/modulestore/tests/test_mixed_modulestore.py index 8c74419a0b7b..5a413a7b303b 100644 --- a/xmodule/modulestore/tests/test_mixed_modulestore.py +++ b/xmodule/modulestore/tests/test_mixed_modulestore.py @@ -11,45 +11,43 @@ from contextlib import contextmanager from shutil import rmtree from tempfile import mkdtemp -from uuid import uuid4 from unittest.mock import Mock, call, patch +from uuid import uuid4 from zoneinfo import ZoneInfo import ddt -from openedx_events.content_authoring.data import CourseData, XBlockData -from openedx_events.content_authoring.signals import ( - COURSE_CREATED, - XBLOCK_CREATED, - XBLOCK_DELETED, - XBLOCK_PUBLISHED, - XBLOCK_UPDATED -) -from openedx_events.tests.utils import OpenEdxEventsTestMixin import pymongo import pytest + # Mixed modulestore depends on django, so we'll manually configure some django settings # before importing the module # TODO remove this import and the configuration -- xmodule should not depend on django! from django.conf import settings from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator, LibraryLocator # pylint: disable=unused-import +from openedx_events.content_authoring.data import CourseData, XBlockData +from openedx_events.content_authoring.signals import ( + COURSE_CREATED, + XBLOCK_CREATED, + XBLOCK_DELETED, + XBLOCK_PUBLISHED, + XBLOCK_UPDATED, +) +from openedx_events.tests.utils import OpenEdxEventsTestMixin from web_fragments.fragment import Fragment from xblock.core import XBlockAside from xblock.fields import Scope, ScopeIds, String from xblock.runtime import DictKeyValueStore, KvsFieldData from xblock.test.tools import TestRuntime +from common.test.utils import assert_dict_contains_subset from openedx.core.lib.tests import attr from xmodule.contentstore.content import StaticContent from xmodule.exceptions import InvalidVersionError from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.draft_and_published import DIRECT_ONLY_CATEGORIES, UnsupportedRevisionError from xmodule.modulestore.edit_info import EditInfoMixin -from xmodule.modulestore.exceptions import ( - DuplicateCourseError, - ItemNotFoundError, - NoPathToItem, -) +from xmodule.modulestore.exceptions import DuplicateCourseError, ItemNotFoundError, NoPathToItem from xmodule.modulestore.inheritance import InheritanceMixin from xmodule.modulestore.mixed import MixedModuleStore from xmodule.modulestore.search import navigation_index, path_to_location @@ -63,7 +61,6 @@ from xmodule.modulestore.xml_importer import LocationMixin, import_course_from_xml from xmodule.tests import DATA_DIR, CourseComparisonTest from xmodule.x_module import XModuleMixin -from common.test.utils import assert_dict_contains_subset if not settings.configured: settings.configure() diff --git a/xmodule/modulestore/tests/test_modulestore_settings.py b/xmodule/modulestore/tests/test_modulestore_settings.py index 9ff6efb0fa54..ec2fa1fb7c5e 100644 --- a/xmodule/modulestore/tests/test_modulestore_settings.py +++ b/xmodule/modulestore/tests/test_modulestore_settings.py @@ -6,14 +6,14 @@ import copy from unittest import TestCase -import pytest import ddt +import pytest from openedx.core.lib.tempdir import mkdtemp_clean from xmodule.modulestore.modulestore_settings import ( convert_module_store_setting_if_needed, get_mixed_stores, - update_module_store_settings + update_module_store_settings, ) diff --git a/xmodule/modulestore/tests/test_mongo.py b/xmodule/modulestore/tests/test_mongo.py index 101d8a880aae..2151e6c87baf 100644 --- a/xmodule/modulestore/tests/test_mongo.py +++ b/xmodule/modulestore/tests/test_mongo.py @@ -10,6 +10,7 @@ # pylint: disable=protected-access from django.test import TestCase + # pylint: enable=E0611 from opaque_keys.edx.keys import CourseKey from xblock.exceptions import InvalidScopeError diff --git a/xmodule/modulestore/tests/test_mongo_call_count.py b/xmodule/modulestore/tests/test_mongo_call_count.py index 341c3b35e580..f0f132380601 100644 --- a/xmodule/modulestore/tests/test_mongo_call_count.py +++ b/xmodule/modulestore/tests/test_mongo_call_count.py @@ -17,7 +17,7 @@ TEST_DATA_DIR, MemoryCache, MixedModulestoreBuilder, - VersioningModulestoreBuilder + VersioningModulestoreBuilder, ) from xmodule.modulestore.xml_exporter import export_course_to_xml from xmodule.modulestore.xml_importer import import_course_from_xml diff --git a/xmodule/modulestore/tests/test_publish.py b/xmodule/modulestore/tests/test_publish.py index e07f98579081..79a9e05c8ce7 100644 --- a/xmodule/modulestore/tests/test_publish.py +++ b/xmodule/modulestore/tests/test_publish.py @@ -13,17 +13,14 @@ from shutil import rmtree from tempfile import mkdtemp -import pytest import ddt +import pytest from xmodule.exceptions import InvalidVersionError from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.exceptions import ItemNotFoundError -from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory -from xmodule.modulestore.tests.utils import ( - SPLIT_MODULESTORE_SETUP, - MongoContentstoreBuilder, -) +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory +from xmodule.modulestore.tests.utils import SPLIT_MODULESTORE_SETUP, MongoContentstoreBuilder from xmodule.modulestore.xml_exporter import export_course_to_xml diff --git a/xmodule/modulestore/tests/test_semantics.py b/xmodule/modulestore/tests/test_semantics.py index 34e3a2e543a7..9b5899ac00d5 100644 --- a/xmodule/modulestore/tests/test_semantics.py +++ b/xmodule/modulestore/tests/test_semantics.py @@ -7,8 +7,8 @@ from collections import namedtuple from unittest.mock import patch -import pytest import ddt +import pytest from xblock.core import XBlock, XBlockAside from xblock.fields import Scope, String from xblock.runtime import DictKeyValueStore, KvsFieldData @@ -18,8 +18,8 @@ from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.draft_and_published import DIRECT_ONLY_CATEGORIES from xmodule.modulestore.exceptions import ItemNotFoundError -from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory DETACHED_BLOCK_TYPES = dict(XBlock.load_tagged_classes('detached')) diff --git a/xmodule/modulestore/tests/test_split_modulestore.py b/xmodule/modulestore/tests/test_split_modulestore.py index 09278ff5e8f0..0a523d93dcfe 100644 --- a/xmodule/modulestore/tests/test_split_modulestore.py +++ b/xmodule/modulestore/tests/test_split_modulestore.py @@ -11,8 +11,8 @@ from importlib import import_module from unittest.mock import patch -import pytest import ddt +import pytest from ccx_keys.locator import CCXBlockUsageLocator from django.core.cache import InvalidCacheBackendError, caches from opaque_keys.edx.locator import BlockUsageLocator, CourseKey, CourseLocator, LocalId @@ -29,7 +29,7 @@ DuplicateItemError, InsufficientSpecificationError, ItemNotFoundError, - VersionConflictError + VersionConflictError, ) from xmodule.modulestore.inheritance import InheritanceMixin from xmodule.modulestore.split_mongo import BlockKey diff --git a/xmodule/modulestore/tests/test_xml_importer.py b/xmodule/modulestore/tests/test_xml_importer.py index 9568686d98fa..fd13d3a0ce6e 100644 --- a/xmodule/modulestore/tests/test_xml_importer.py +++ b/xmodule/modulestore/tests/test_xml_importer.py @@ -6,8 +6,8 @@ import importlib import os import unittest -from uuid import uuid4 from unittest import mock +from uuid import uuid4 from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator diff --git a/xmodule/modulestore/tests/utils.py b/xmodule/modulestore/tests/utils.py index 8cac4bf72831..7113c5b3ad84 100644 --- a/xmodule/modulestore/tests/utils.py +++ b/xmodule/modulestore/tests/utils.py @@ -2,7 +2,7 @@ Helper classes and methods for running modulestore tests without Django. """ import os -from contextlib import contextmanager, ExitStack +from contextlib import ExitStack, contextmanager from importlib import import_module from shutil import rmtree from tempfile import mkdtemp @@ -17,7 +17,7 @@ from xmodule.modulestore.mongo.base import ModuleStoreEnum from xmodule.modulestore.mongo.draft import DraftModuleStore from xmodule.modulestore.split_mongo.split_draft import DraftVersioningModuleStore -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, TEST_DATA_ONLY_SPLIT_MODULESTORE_DRAFT_PREFERRED +from xmodule.modulestore.tests.django_utils import TEST_DATA_ONLY_SPLIT_MODULESTORE_DRAFT_PREFERRED, ModuleStoreTestCase from xmodule.modulestore.tests.factories import BlockFactory from xmodule.modulestore.tests.mongo_connection import MONGO_HOST, MONGO_PORT_NUM from xmodule.modulestore.xml import XMLModuleStore diff --git a/xmodule/modulestore/xml.py b/xmodule/modulestore/xml.py index 679612fde679..bd550a6735e0 100644 --- a/xmodule/modulestore/xml.py +++ b/xmodule/modulestore/xml.py @@ -7,8 +7,8 @@ import logging import os import re -import warnings import sys +import warnings from collections import defaultdict from contextlib import contextmanager from importlib import import_module @@ -20,12 +20,7 @@ from path import Path as path from xblock.core import XBlockAside from xblock.field_data import DictFieldData -from xblock.fields import ( - Reference, - ReferenceList, - ReferenceValueDict, - ScopeIds, -) +from xblock.fields import Reference, ReferenceList, ReferenceValueDict, ScopeIds from xblock.runtime import DictKeyValueStore from common.djangoapps.util.monitoring import monitor_import_failure @@ -34,12 +29,7 @@ from xmodule.modulestore import COURSE_ROOT, LIBRARY_ROOT, ModuleStoreEnum, ModuleStoreReadBase from xmodule.modulestore.xml_exporter import DEFAULT_CONTENT_FIELDS from xmodule.tabs import CourseTabList -from xmodule.x_module import ( - AsideKeyGenerator, - OpaqueKeyReader, - ModuleStoreRuntime, - policy_key -) +from xmodule.x_module import AsideKeyGenerator, ModuleStoreRuntime, OpaqueKeyReader, policy_key from .exceptions import ItemNotFoundError from .inheritance import compute_inherited_metadata, inheriting_field_data diff --git a/xmodule/modulestore/xml_exporter.py b/xmodule/modulestore/xml_exporter.py index eb6341defad0..1421292c0d98 100644 --- a/xmodule/modulestore/xml_exporter.py +++ b/xmodule/modulestore/xml_exporter.py @@ -13,11 +13,8 @@ from fs.osfs import OSFS from opaque_keys.edx.locator import CourseLocator, LibraryLocator from xblock.fields import Reference, ReferenceList, ReferenceValueDict, Scope -from openedx.core.djangoapps.content_tagging.api import ( - export_tags_in_csv_file, - get_object_tag_counts -) +from openedx.core.djangoapps.content_tagging.api import export_tags_in_csv_file, get_object_tag_counts from xmodule.assetstore import AssetMetadata from xmodule.contentstore.content import StaticContent from xmodule.exceptions import NotFoundError diff --git a/xmodule/modulestore/xml_importer.py b/xmodule/modulestore/xml_importer.py index 8ee98a8b7c43..def2c2c80012 100644 --- a/xmodule/modulestore/xml_importer.py +++ b/xmodule/modulestore/xml_importer.py @@ -52,7 +52,7 @@ from xmodule.modulestore.exceptions import DuplicateCourseError from xmodule.modulestore.mongo.base import MongoRevisionKey from xmodule.modulestore.store_utilities import draft_node_constructor, get_draft_subtree_roots -from xmodule.modulestore.xml import XMLImportingModuleStoreRuntime, LibraryXMLModuleStore, XMLModuleStore +from xmodule.modulestore.xml import LibraryXMLModuleStore, XMLImportingModuleStoreRuntime, XMLModuleStore from xmodule.tabs import CourseTabList from xmodule.util.misc import escape_invalid_characters from xmodule.x_module import XModuleMixin diff --git a/xmodule/mongo_utils.py b/xmodule/mongo_utils.py index 78538d530a9d..ccc34172cd24 100644 --- a/xmodule/mongo_utils.py +++ b/xmodule/mongo_utils.py @@ -7,12 +7,11 @@ import pymongo from pymongo.read_preferences import ( # lint-amnesty, pylint: disable=unused-import - ReadPreference, + _MODES, _MONGOS_MODES, - _MODES + ReadPreference, ) - logger = logging.getLogger(__name__) # pylint: disable=invalid-name # This will yeld a map of all available Mongo modes and their name diff --git a/xmodule/partitions/enrollment_track_partition_generator.py b/xmodule/partitions/enrollment_track_partition_generator.py index ac1f61f5cf15..181f8fdfc3c3 100644 --- a/xmodule/partitions/enrollment_track_partition_generator.py +++ b/xmodule/partitions/enrollment_track_partition_generator.py @@ -8,10 +8,10 @@ from django.utils.translation import gettext_lazy as _ from xmodule.partitions.partitions import ( - get_partition_from_id, ENROLLMENT_TRACK_PARTITION_ID, UserPartition, - UserPartitionError + UserPartitionError, + get_partition_from_id, ) log = logging.getLogger(__name__) diff --git a/xmodule/partitions/partitions_service.py b/xmodule/partitions/partitions_service.py index ddd37d5212f5..0ab0ef924031 100644 --- a/xmodule/partitions/partitions_service.py +++ b/xmodule/partitions/partitions_service.py @@ -9,11 +9,12 @@ from django.conf import settings from django.contrib.auth import get_user_model from opaque_keys.edx.keys import CourseKey + from openedx.core.lib.cache_utils import request_cached from openedx.core.lib.dynamic_partitions_generators import DynamicPartitionGeneratorsPluginManager - from xmodule.modulestore.django import modulestore from xmodule.partitions.partitions import get_partition_from_id + from .partitions import Group User = get_user_model() diff --git a/xmodule/partitions/tests/test_partitions.py b/xmodule/partitions/tests/test_partitions.py index 41f26b14db52..c719a1b172aa 100644 --- a/xmodule/partitions/tests/test_partitions.py +++ b/xmodule/partitions/tests/test_partitions.py @@ -18,7 +18,7 @@ Group, NoSuchUserPartitionGroupError, UserPartition, - UserPartitionError + UserPartitionError, ) from xmodule.partitions.partitions_service import FEATURES, PartitionService, get_all_partitions_for_course diff --git a/xmodule/poll_block.py b/xmodule/poll_block.py index 004572faf7d1..ee5bda3cd253 100644 --- a/xmodule/poll_block.py +++ b/xmodule/poll_block.py @@ -10,9 +10,9 @@ import json import logging import warnings +from collections import OrderedDict from copy import deepcopy -from collections import OrderedDict from django.conf import settings from lxml import etree from web_fragments.fragment import Fragment @@ -20,16 +20,11 @@ from xblock.fields import Boolean, Dict, List, Scope, String # lint-amnesty, pylint: disable=wrong-import-order from xblocks_contrib.poll import PollBlock as _ExtractedPollBlock -from openedx.core.djangolib.markup import Text, HTML +from openedx.core.djangolib.markup import HTML, Text from xmodule.mako_block import MakoTemplateBlockBase from xmodule.stringify import stringify_children -from xmodule.util.builtin_assets import add_webpack_js_to_fragment, add_css_to_fragment -from xmodule.x_module import ( - ResourceTemplates, - shim_xmodule_js, - XModuleMixin, - XModuleToXBlockMixin, -) +from xmodule.util.builtin_assets import add_css_to_fragment, add_webpack_js_to_fragment +from xmodule.x_module import ResourceTemplates, XModuleMixin, XModuleToXBlockMixin, shim_xmodule_js from xmodule.xml_block import XmlMixin log = logging.getLogger(__name__) diff --git a/xmodule/randomize_block.py b/xmodule/randomize_block.py index b8a1432ff311..bec305a3467e 100644 --- a/xmodule/randomize_block.py +++ b/xmodule/randomize_block.py @@ -7,15 +7,11 @@ from lxml import etree from web_fragments.fragment import Fragment from xblock.fields import Integer, Scope + from xmodule.mako_block import MakoTemplateBlockBase from xmodule.seq_block import SequenceMixin +from xmodule.x_module import STUDENT_VIEW, ResourceTemplates, XModuleMixin, XModuleToXBlockMixin from xmodule.xml_block import XmlMixin -from xmodule.x_module import ( - ResourceTemplates, - STUDENT_VIEW, - XModuleMixin, - XModuleToXBlockMixin, -) log = logging.getLogger('edx.' + __name__) diff --git a/xmodule/seq_block.py b/xmodule/seq_block.py index 5c353161024e..ba482a285571 100644 --- a/xmodule/seq_block.py +++ b/xmodule/seq_block.py @@ -10,10 +10,11 @@ import logging from datetime import datetime from functools import reduce -from django.conf import settings from zoneinfo import ZoneInfo +from django.conf import settings from edx_django_utils.monitoring import set_custom_attribute +from edx_toggles.toggles import SettingToggle, WaffleFlag from lxml import etree from opaque_keys.edx.keys import UsageKey from web_fragments.fragment import Fragment @@ -23,17 +24,9 @@ from xblock.fields import Boolean, Date, Integer, List, Scope, String from xblock.progress import Progress -from edx_toggles.toggles import WaffleFlag, SettingToggle -from xmodule.util.builtin_assets import add_webpack_js_to_fragment, add_css_to_fragment -from xmodule.x_module import ( - ResourceTemplates, - shim_xmodule_js, - STUDENT_VIEW, - XModuleMixin, - XModuleToXBlockMixin, -) - from common.djangoapps.xblock_django.constants import ATTR_KEY_USER_ID, ATTR_KEY_USER_IS_STAFF +from xmodule.util.builtin_assets import add_css_to_fragment, add_webpack_js_to_fragment +from xmodule.x_module import STUDENT_VIEW, ResourceTemplates, XModuleMixin, XModuleToXBlockMixin, shim_xmodule_js from .exceptions import NotFoundError from .mako_block import MakoTemplateBlockBase diff --git a/xmodule/services.py b/xmodule/services.py index 0269698627cb..d07e95611ee8 100644 --- a/xmodule/services.py +++ b/xmodule/services.py @@ -11,24 +11,22 @@ from config_models.models import ConfigurationModel from django.conf import settings from django.urls import reverse -from eventtracking import tracker from edx_when.field_data import DateLookupFieldData +from eventtracking import tracker from requests.auth import HTTPBasicAuth from xblock.reference.plugins import Service from xblock.runtime import KvsFieldData +from xblocks_contrib.problem.capa.xqueue_interface import XQueueInterface from common.djangoapps.track import contexts -from lms.djangoapps.courseware.masquerade import is_masquerading_as_specific_student -from xmodule.modulestore.django import modulestore - from lms.djangoapps.courseware.field_overrides import OverrideFieldData +from lms.djangoapps.courseware.masquerade import is_masquerading_as_specific_student from lms.djangoapps.courseware.model_data import DjangoKeyValueStore, FieldDataCache +from lms.djangoapps.grades.api import signals as grades_signals from lms.djangoapps.lms_xblock.field_data import LmsFieldData from lms.djangoapps.lms_xblock.models import XBlockAsidesConfig from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag -from xblocks_contrib.problem.capa.xqueue_interface import XQueueInterface - -from lms.djangoapps.grades.api import signals as grades_signals +from xmodule.modulestore.django import modulestore if TYPE_CHECKING: from xmodule.capa_block import ProblemBlock diff --git a/xmodule/split_test_block.py b/xmodule/split_test_block.py index f259ef40e7bb..0ee635cca93e 100644 --- a/xmodule/split_test_block.py +++ b/xmodule/split_test_block.py @@ -18,20 +18,15 @@ from xblock.exceptions import NoSuchServiceError from xblock.fields import Integer, ReferenceValueDict, Scope, String from xblock.progress import Progress + from xmodule.mako_block import MakoTemplateBlockBase from xmodule.modulestore.inheritance import UserPartitionList from xmodule.seq_block import ProctoringFields, SequenceMixin from xmodule.studio_editable import StudioEditableBlock from xmodule.util.builtin_assets import add_webpack_js_to_fragment from xmodule.validation import StudioValidation, StudioValidationMessage +from xmodule.x_module import STUDENT_VIEW, ResourceTemplates, XModuleMixin, XModuleToXBlockMixin, shim_xmodule_js from xmodule.xml_block import XmlMixin -from xmodule.x_module import ( - ResourceTemplates, - shim_xmodule_js, - STUDENT_VIEW, - XModuleMixin, - XModuleToXBlockMixin, -) log = logging.getLogger('edx.' + __name__) diff --git a/xmodule/tabs.py b/xmodule/tabs.py index 7e42d7524773..027a8ec77ea6 100644 --- a/xmodule/tabs.py +++ b/xmodule/tabs.py @@ -7,9 +7,8 @@ from abc import ABCMeta from django.utils.module_loading import import_string -from xblock.fields import List - from edx_django_utils.plugins import PluginError +from xblock.fields import List log = logging.getLogger("edx.courseware") diff --git a/xmodule/tests/__init__.py b/xmodule/tests/__init__.py index 4833c4cf0c24..ceed6d75048e 100644 --- a/xmodule/tests/__init__.py +++ b/xmodule/tests/__init__.py @@ -14,13 +14,15 @@ from unittest.mock import Mock from django.test import TransactionTestCase - from opaque_keys.edx.keys import CourseKey from path import Path as path from xblock.core import XBlock from xblock.field_data import DictFieldData from xblock.fields import Reference, ReferenceList, ReferenceValueDict, ScopeIds +from openedx.core.djangoapps.discussions.services import DiscussionConfigService +from openedx.core.djangoapps.video_config.services import VideoConfigService +from openedx.core.lib.cache_utils import CacheService from xmodule.assetstore import AssetMetadata from xmodule.contentstore.django import contentstore from xmodule.modulestore import ModuleStoreEnum @@ -28,12 +30,9 @@ from xmodule.modulestore.inheritance import InheritanceMixin from xmodule.modulestore.xml import CourseLocationManager from xmodule.services import XQueueService -from xmodule.tests.helpers import StubReplaceURLService, mock_render_template, StubMakoService, StubUserService +from xmodule.tests.helpers import StubMakoService, StubReplaceURLService, StubUserService, mock_render_template from xmodule.util.sandboxing import SandboxService -from xmodule.x_module import DoNothingCache, XModuleMixin, ModuleStoreRuntime -from openedx.core.djangoapps.video_config.services import VideoConfigService -from openedx.core.lib.cache_utils import CacheService -from openedx.core.djangoapps.discussions.services import DiscussionConfigService +from xmodule.x_module import DoNothingCache, ModuleStoreRuntime, XModuleMixin MODULE_DIR = path(__file__).dirname() # Location of common test DATA directory diff --git a/xmodule/tests/helpers.py b/xmodule/tests/helpers.py index c69c810d4aa2..b02aa46a0070 100644 --- a/xmodule/tests/helpers.py +++ b/xmodule/tests/helpers.py @@ -9,6 +9,7 @@ import pytest from path import Path as path from xblock.reference.user_service import UserService, XBlockUser + from xmodule.x_module import ModuleStoreRuntime diff --git a/xmodule/tests/test_capa_block.py b/xmodule/tests/test_capa_block.py index 61c66eefe467..e17ed4c1aeae 100644 --- a/xmodule/tests/test_capa_block.py +++ b/xmodule/tests/test_capa_block.py @@ -26,19 +26,16 @@ from xblock.field_data import DictFieldData from xblock.fields import ScopeIds from xblock.scorable import Score - -from lms.djangoapps.courseware.user_state_client import XBlockUserState -from openedx.core.djangolib.testing.utils import skip_unless_lms from xblocks_contrib.problem.capa import responsetypes from xblocks_contrib.problem.capa.correctmap import CorrectMap -from xblocks_contrib.problem.capa.responsetypes import ( - LoncapaProblemError, - ResponseError, - StudentInputError, -) +from xblocks_contrib.problem.capa.responsetypes import LoncapaProblemError, ResponseError, StudentInputError from xblocks_contrib.problem.capa.tests.test_util import UseUnsafeCodejail from xblocks_contrib.problem.capa.xqueue_interface import XQueueInterface -from xmodule.capa_block import ComplexEncoder, _BuiltInProblemBlock as ProblemBlock + +from lms.djangoapps.courseware.user_state_client import XBlockUserState +from openedx.core.djangolib.testing.utils import skip_unless_lms +from xmodule.capa_block import ComplexEncoder +from xmodule.capa_block import _BuiltInProblemBlock as ProblemBlock from xmodule.tests import DATA_DIR from ..capa_block import RANDOMIZATION, SHOWANSWER diff --git a/xmodule/tests/test_course_block.py b/xmodule/tests/test_course_block.py index a7ef4181a24d..de11f3adbbc1 100644 --- a/xmodule/tests/test_course_block.py +++ b/xmodule/tests/test_course_block.py @@ -2,27 +2,27 @@ import itertools +import sys import unittest from datetime import datetime, timedelta -import sys from unittest.mock import Mock, patch from zoneinfo import ZoneInfo import ddt +import pytest from dateutil import parser from django.conf import settings from django.test import override_settings from fs.memoryfs import MemoryFS from opaque_keys.edx.keys import CourseKey -import pytest from xblock.runtime import DictKeyValueStore, KvsFieldData -from openedx.core.lib.teams_config import TeamsConfig, DEFAULT_COURSE_RUN_MAX_TEAM_SIZE import xmodule.course_block +from openedx.core.lib.teams_config import DEFAULT_COURSE_RUN_MAX_TEAM_SIZE, TeamsConfig from xmodule.course_metadata_utils import DEFAULT_START_DATE from xmodule.data import CertificatesDisplayBehaviors -from xmodule.modulestore.xml import XMLImportingModuleStoreRuntime, XMLModuleStore from xmodule.modulestore.exceptions import InvalidProctoringProvider +from xmodule.modulestore.xml import XMLImportingModuleStoreRuntime, XMLModuleStore ORG = 'test_org' COURSE = 'test_course' diff --git a/xmodule/tests/test_course_metadata_utils.py b/xmodule/tests/test_course_metadata_utils.py index 68e7aaf1bcda..5bae449840e3 100644 --- a/xmodule/tests/test_course_metadata_utils.py +++ b/xmodule/tests/test_course_metadata_utils.py @@ -9,10 +9,8 @@ from zoneinfo import ZoneInfo import pytest -from xmodule.block_metadata_utils import ( - display_name_with_default, - display_name_with_default_escaped, -) + +from xmodule.block_metadata_utils import display_name_with_default, display_name_with_default_escaped from xmodule.course_metadata_utils import ( DEFAULT_START_DATE, clean_course_key, @@ -20,12 +18,12 @@ has_course_ended, has_course_started, is_enrollment_open, - number_for_course_location + number_for_course_location, ) from xmodule.modulestore.tests.utils import ( MixedModulestoreBuilder, MongoModulestoreBuilder, - VersioningModulestoreBuilder + VersioningModulestoreBuilder, ) _TODAY = datetime.now(ZoneInfo("UTC")) diff --git a/xmodule/tests/test_export.py b/xmodule/tests/test_export.py index 7e201d4c1d97..6365a9da3f53 100644 --- a/xmodule/tests/test_export.py +++ b/xmodule/tests/test_export.py @@ -11,9 +11,9 @@ from unittest import mock from zoneinfo import ZoneInfo -import pytest import ddt import lxml.etree +import pytest from django.utils.translation import gettext_lazy from fs.osfs import OSFS from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator diff --git a/xmodule/tests/test_graders.py b/xmodule/tests/test_graders.py index ef37234a2d3d..8c6c01c0a488 100644 --- a/xmodule/tests/test_graders.py +++ b/xmodule/tests/test_graders.py @@ -5,8 +5,9 @@ import unittest from datetime import datetime -import pytest + import ddt +import pytest from lms.djangoapps.grades.scores import compute_percent from xmodule import graders diff --git a/xmodule/tests/test_import.py b/xmodule/tests/test_import.py index 546a5537ce2d..70ee2860fe60 100644 --- a/xmodule/tests/test_import.py +++ b/xmodule/tests/test_import.py @@ -17,7 +17,7 @@ from xblock.runtime import DictKeyValueStore, KvsFieldData from xmodule.modulestore.inheritance import InheritanceMixin, compute_inherited_metadata -from xmodule.modulestore.xml import XMLImportingModuleStoreRuntime, LibraryXMLModuleStore, XMLModuleStore +from xmodule.modulestore.xml import LibraryXMLModuleStore, XMLImportingModuleStoreRuntime, XMLModuleStore from xmodule.tests import DATA_DIR from xmodule.x_module import XModuleMixin from xmodule.xml_block import is_pointer_tag diff --git a/xmodule/tests/test_import_static.py b/xmodule/tests/test_import_static.py index b8d3e387c76c..f6861604259b 100644 --- a/xmodule/tests/test_import_static.py +++ b/xmodule/tests/test_import_static.py @@ -12,7 +12,7 @@ DOT_FILES_DICT, TILDA_FILES_DICT, add_temp_files_from_dict, - remove_temp_files_from_list + remove_temp_files_from_list, ) from xmodule.modulestore.xml_importer import StaticContentImporter from xmodule.tests import DATA_DIR diff --git a/xmodule/tests/test_item_bank.py b/xmodule/tests/test_item_bank.py index f29e4b847874..eb2ea6f431ff 100644 --- a/xmodule/tests/test_item_bank.py +++ b/xmodule/tests/test_item_bank.py @@ -1,8 +1,8 @@ """ Unit tests for ItemBankBlock. """ -from unittest.mock import MagicMock, Mock, patch from random import Random +from unittest.mock import MagicMock, Mock, patch import ddt from fs.memoryfs import MemoryFS @@ -11,14 +11,14 @@ from web_fragments.fragment import Fragment from xblock.runtime import Runtime as VanillaRuntime -from openedx.core.djangolib.testing.utils import skip_unless_lms, skip_unless_cms +from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangolib.testing.utils import skip_unless_cms, skip_unless_lms +from xmodule.capa_block import ProblemBlock from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.utils import MixedSplitTestCase from xmodule.tests import prepare_block_runtime from xmodule.validation import StudioValidationMessage from xmodule.x_module import AUTHOR_VIEW -from xmodule.capa_block import ProblemBlock -from common.djangoapps.student.tests.factories import UserFactory from ..item_bank_block import ItemBankBlock from .test_course_block import DummyModuleStoreRuntime diff --git a/xmodule/tests/test_library_root.py b/xmodule/tests/test_library_root.py index bcc2b6af7174..caf3e52a533e 100644 --- a/xmodule/tests/test_library_root.py +++ b/xmodule/tests/test_library_root.py @@ -4,6 +4,7 @@ from unittest.mock import patch + from web_fragments.fragment import Fragment from xblock.runtime import Runtime as VanillaRuntime diff --git a/xmodule/tests/test_library_tools.py b/xmodule/tests/test_library_tools.py index 30b007c3d963..1388797bf94b 100644 --- a/xmodule/tests/test_library_tools.py +++ b/xmodule/tests/test_library_tools.py @@ -12,8 +12,8 @@ from opaque_keys.edx.locator import LibraryLocator from common.djangoapps.student.tests.factories import UserFactory -from openedx.core.djangolib.testing.utils import skip_unless_cms from openedx.core.djangoapps.content_libraries.tests.base import ContentLibrariesRestApiTest +from openedx.core.djangolib.testing.utils import skip_unless_cms from xmodule.library_tools import LegacyLibraryToolsService from xmodule.modulestore.tests.factories import CourseFactory, LibraryFactory from xmodule.modulestore.tests.utils import MixedSplitTestCase diff --git a/xmodule/tests/test_lti20_unit.py b/xmodule/tests/test_lti20_unit.py index 1734b938c453..516035c8a54c 100644 --- a/xmodule/tests/test_lti20_unit.py +++ b/xmodule/tests/test_lti20_unit.py @@ -3,23 +3,21 @@ import datetime import textwrap -from django.conf import settings -from django.test import TestCase, override_settings from unittest.mock import Mock from zoneinfo import ZoneInfo +from django.conf import settings +from django.test import TestCase, override_settings from xblock.field_data import DictFieldData +from xblocks_contrib.lti.lti_2_util import LTIError as ExtractedLTIError from xmodule import lti_block +from xmodule.lti_2_util import LTIError as BuiltInLTIError from xmodule.tests.helpers import StubUserService from . import get_test_system -from xmodule.lti_2_util import LTIError as BuiltInLTIError -from xblocks_contrib.lti.lti_2_util import LTIError as ExtractedLTIError - - class _LTI20RESTResultServiceTestBase(TestCase): """Logic tests for LTI block. LTI2.0 REST ResultService""" diff --git a/xmodule/tests/test_lti_unit.py b/xmodule/tests/test_lti_unit.py index 695d3b59e28d..e4d26c74dba1 100644 --- a/xmodule/tests/test_lti_unit.py +++ b/xmodule/tests/test_lti_unit.py @@ -8,7 +8,6 @@ from urllib import parse from zoneinfo import ZoneInfo - import pytest from django.conf import settings from django.test import TestCase, override_settings @@ -18,17 +17,15 @@ from webob.request import Request from xblock.field_data import DictFieldData from xblock.fields import ScopeIds, Timedelta - +from xblocks_contrib.lti.lti_2_util import LTIError as ExtractedLTIError from common.djangoapps.xblock_django.constants import ATTR_KEY_ANONYMOUS_USER_ID from xmodule import lti_block +from xmodule.lti_2_util import LTIError as BuiltInLTIError from xmodule.tests.helpers import StubUserService from . import get_test_system -from xmodule.lti_2_util import LTIError as BuiltInLTIError -from xblocks_contrib.lti.lti_2_util import LTIError as ExtractedLTIError - @override_settings(LMS_BASE="edx.org") class _TestLTIBase(TestCase): diff --git a/xmodule/tests/test_poll.py b/xmodule/tests/test_poll.py index 6880bdc89766..05f9135ad526 100644 --- a/xmodule/tests/test_poll.py +++ b/xmodule/tests/test_poll.py @@ -2,14 +2,14 @@ import json +from django.test import TestCase, override_settings from opaque_keys.edx.keys import CourseKey from xblock.field_data import DictFieldData from xblock.fields import ScopeIds -from django.test import override_settings -from django.test import TestCase from openedx.core.lib.safe_lxml import etree from xmodule import poll_block + from . import get_test_system from .test_import import DummyModuleStoreRuntime diff --git a/xmodule/tests/test_resource_templates.py b/xmodule/tests/test_resource_templates.py index 470be9551489..948f3ae76a1a 100644 --- a/xmodule/tests/test_resource_templates.py +++ b/xmodule/tests/test_resource_templates.py @@ -5,6 +5,7 @@ import unittest from django.test import override_settings + from xmodule.x_module import ResourceTemplates CUSTOM_RESOURCE_TEMPLATES_DIRECTORY = pathlib.Path(__file__).parent.parent / "templates/" diff --git a/xmodule/tests/test_sequence.py b/xmodule/tests/test_sequence.py index c299f7bed0d7..252665ec6fc2 100644 --- a/xmodule/tests/test_sequence.py +++ b/xmodule/tests/test_sequence.py @@ -13,10 +13,10 @@ from django.test import RequestFactory from django.test.utils import override_settings from django.utils.timezone import now +from edx_toggles.toggles.testutils import override_waffle_flag from freezegun import freeze_time from web_fragments.fragment import Fragment -from edx_toggles.toggles.testutils import override_waffle_flag from openedx.features.content_type_gating.models import ContentTypeGatingConfig from xmodule.seq_block import TIMED_EXAM_GATING_WAFFLE_FLAG, SequenceBlock from xmodule.tests import get_test_system, prepare_block_runtime diff --git a/xmodule/tests/test_services.py b/xmodule/tests/test_services.py index 33c5450bd25e..322f0ca0b85a 100644 --- a/xmodule/tests/test_services.py +++ b/xmodule/tests/test_services.py @@ -13,10 +13,10 @@ from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator from xblock.fields import ScopeIds from xblock.runtime import Mixologist +from xblocks_contrib.problem.capa.xqueue_interface import XQueueInterface from openedx.core.djangolib.testing.utils import skip_unless_lms from openedx.core.lib.teams_config import TeamsConfig -from xblocks_contrib.problem.capa.xqueue_interface import XQueueInterface from xmodule.services import ConfigurationService, SettingsService, TeamsConfigurationService, XQueueService diff --git a/xmodule/tests/test_split_test_block.py b/xmodule/tests/test_split_test_block.py index 7acbaa25f6ba..1f58b056034c 100644 --- a/xmodule/tests/test_split_test_block.py +++ b/xmodule/tests/test_split_test_block.py @@ -12,12 +12,7 @@ from xmodule.modulestore.tests.utils import MixedSplitTestCase from xmodule.partitions.partitions import MINIMUM_UNUSED_PARTITION_ID, Group, UserPartition from xmodule.partitions.tests.test_partitions import MockPartitionService, MockUserPartitionScheme, PartitionTestCase -from xmodule.split_test_block import ( - SplitTestBlock, - SplitTestFields, - get_split_user_partitions, - user_partition_values, -) +from xmodule.split_test_block import SplitTestBlock, SplitTestFields, get_split_user_partitions, user_partition_values from xmodule.tests import prepare_block_runtime from xmodule.tests.test_course_block import DummyModuleStoreRuntime from xmodule.tests.xml import XModuleXmlImportTest diff --git a/xmodule/tests/test_tabs.py b/xmodule/tests/test_tabs.py index b38292d659fe..805f0eaacffc 100644 --- a/xmodule/tests/test_tabs.py +++ b/xmodule/tests/test_tabs.py @@ -2,6 +2,7 @@ Tests for CourseTabsListTestCase. """ from unittest import TestCase + import ddt from xmodule.tabs import CourseTabList, InvalidTabsException diff --git a/xmodule/tests/test_unit_block.py b/xmodule/tests/test_unit_block.py index a87c49aa9256..c13650477c24 100644 --- a/xmodule/tests/test_unit_block.py +++ b/xmodule/tests/test_unit_block.py @@ -7,8 +7,8 @@ from xml.etree import ElementTree from web_fragments.fragment import Fragment -from xblock.core import XBlock from xblock.completable import XBlockCompletionMode +from xblock.core import XBlock from xblock.test.test_parsing import XmlTest from xmodule.unit_block import UnitBlock diff --git a/xmodule/tests/test_video.py b/xmodule/tests/test_video.py index 94cd346272e9..7657d289060f 100644 --- a/xmodule/tests/test_video.py +++ b/xmodule/tests/test_video.py @@ -18,11 +18,11 @@ import shutil import unittest from tempfile import mkdtemp -from uuid import uuid4 from unittest.mock import ANY, MagicMock, Mock, patch +from uuid import uuid4 -import pytest import ddt +import pytest from django.conf import settings from django.test import TestCase from django.test.utils import override_settings @@ -30,16 +30,16 @@ from lxml import etree from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import CourseLocator +from xblock.core import XBlockAside from xblock.field_data import DictFieldData from xblock.fields import ScopeIds +from openedx.core.djangoapps.video_config.transcripts_utils import save_to_store +from xmodule.modulestore.tests.test_asides import AsideTestType from xmodule.tests import get_test_descriptor_system from xmodule.validation import StudioValidationMessage from xmodule.video_block import EXPORT_IMPORT_STATIC_DIR, create_youtube_string from xmodule.video_block.video_block import _BuiltInVideoBlock as VideoBlock -from openedx.core.djangoapps.video_config.transcripts_utils import save_to_store -from xblock.core import XBlockAside -from xmodule.modulestore.tests.test_asides import AsideTestType from .test_import import DummyModuleStoreRuntime diff --git a/xmodule/tests/test_word_cloud.py b/xmodule/tests/test_word_cloud.py index bf8faf4826e0..f6b0f2a0f2b7 100644 --- a/xmodule/tests/test_word_cloud.py +++ b/xmodule/tests/test_word_cloud.py @@ -3,8 +3,7 @@ from unittest.mock import Mock from django.conf import settings -from django.test import TestCase -from django.test import override_settings +from django.test import TestCase, override_settings from fs.memoryfs import MemoryFS from lxml import etree from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator @@ -14,6 +13,7 @@ from xblock.fields import ScopeIds from xmodule import word_cloud_block + from . import get_test_descriptor_system, get_test_system diff --git a/xmodule/tests/xml/__init__.py b/xmodule/tests/xml/__init__.py index d2852a2a860e..0276f7e2c361 100644 --- a/xmodule/tests/xml/__init__.py +++ b/xmodule/tests/xml/__init__.py @@ -11,7 +11,7 @@ from opaque_keys.edx.keys import CourseKey from xblock.runtime import DictKeyValueStore, KvsFieldData -from xmodule.modulestore.xml import XMLParsingModuleStoreRuntime, CourseLocationManager +from xmodule.modulestore.xml import CourseLocationManager, XMLParsingModuleStoreRuntime from xmodule.x_module import policy_key diff --git a/xmodule/util/misc.py b/xmodule/util/misc.py index e7a308f85f1b..3aae7ef6f30c 100644 --- a/xmodule/util/misc.py +++ b/xmodule/util/misc.py @@ -5,10 +5,8 @@ import re -from opaque_keys.edx.locator import ( - CourseLocator, - LibraryLocator, -) +from opaque_keys.edx.locator import CourseLocator, LibraryLocator + from xmodule.annotator_mixin import html_to_text diff --git a/xmodule/video_block/__init__.py b/xmodule/video_block/__init__.py index 48a6f28bf8d2..102ab097c458 100644 --- a/xmodule/video_block/__init__.py +++ b/xmodule/video_block/__init__.py @@ -3,5 +3,6 @@ """ from openedx.core.djangoapps.video_config.transcripts_utils import * # lint-amnesty, pylint: disable=redefined-builtin + from .video_block import * from .video_utils import * diff --git a/xmodule/video_block/video_block.py b/xmodule/video_block/video_block.py index e1850fe5b6f3..7b0ecb0d5bbf 100644 --- a/xmodule/video_block/video_block.py +++ b/xmodule/video_block/video_block.py @@ -30,10 +30,21 @@ from xblock.core import XBlock from xblock.fields import ScopeIds from xblock.runtime import KvsFieldData -from xblocks_contrib.video import VideoBlock as _ExtractedVideoBlock from xblock.utils.resources import ResourceLoader +from xblocks_contrib.video import VideoBlock as _ExtractedVideoBlock +from xblocks_contrib.video.bumper_utils import bumperize +from xblocks_contrib.video.exceptions import TranscriptNotFoundError +from xblocks_contrib.video.video_handlers import VideoStudentViewHandlers, VideoStudioViewHandlers from common.djangoapps.xblock_django.constants import ATTR_KEY_REQUEST_COUNTRY_CODE, ATTR_KEY_USER_ID +from openedx.core.djangoapps.video_config.transcripts_utils import ( + Transcript, + VideoTranscriptsMixin, + clean_video_id, + get_endonym_or_label, + get_html5_ids, + subs_filename, +) from openedx.core.lib.cache_utils import request_cached from openedx.core.lib.license import LicenseMixin from xmodule.contentstore.content import StaticContent @@ -43,27 +54,12 @@ from xmodule.raw_block import EmptyDataRawMixin from xmodule.util.builtin_assets import add_css_to_fragment, add_webpack_js_to_fragment from xmodule.validation import StudioValidation, StudioValidationMessage -from xmodule.x_module import ( - PUBLIC_VIEW, STUDENT_VIEW, - ResourceTemplates, - XModuleMixin, XModuleToXBlockMixin, -) +from xmodule.x_module import PUBLIC_VIEW, STUDENT_VIEW, ResourceTemplates, XModuleMixin, XModuleToXBlockMixin from xmodule.xml_block import XmlMixin, deserialize_field, is_pointer_tag, name_to_pathname -from xblocks_contrib.video.bumper_utils import bumperize -from openedx.core.djangoapps.video_config.transcripts_utils import ( - Transcript, - VideoTranscriptsMixin, - clean_video_id, - get_endonym_or_label, - get_html5_ids, - subs_filename -) -from xblocks_contrib.video.video_handlers import VideoStudentViewHandlers, VideoStudioViewHandlers + from .video_utils import create_youtube_string, format_xml_exception_message, get_poster, rewrite_video_url from .video_xfields import VideoFields -from xblocks_contrib.video.exceptions import TranscriptNotFoundError - # The following import/except block for edxval is temporary measure until # edxval is a proper XBlock Runtime Service. # diff --git a/xmodule/word_cloud_block.py b/xmodule/word_cloud_block.py index 040d8ea67ed3..76873b016e7f 100644 --- a/xmodule/word_cloud_block.py +++ b/xmodule/word_cloud_block.py @@ -6,8 +6,6 @@ If student have answered - words he entered and cloud. """ -from xblocks_contrib.word_cloud import WordCloudBlock as _ExtractedWordCloudBlock - import json import logging import warnings @@ -16,16 +14,12 @@ from web_fragments.fragment import Fragment from xblock.core import XBlock from xblock.fields import Boolean, Dict, Integer, List, Scope, String +from xblocks_contrib.word_cloud import WordCloudBlock as _ExtractedWordCloudBlock from xmodule.editing_block import EditingMixin from xmodule.raw_block import EmptyDataRawMixin -from xmodule.util.builtin_assets import add_webpack_js_to_fragment, add_css_to_fragment -from xmodule.x_module import ( - ResourceTemplates, - shim_xmodule_js, - XModuleMixin, - XModuleToXBlockMixin, -) +from xmodule.util.builtin_assets import add_css_to_fragment, add_webpack_js_to_fragment +from xmodule.x_module import ResourceTemplates, XModuleMixin, XModuleToXBlockMixin, shim_xmodule_js from xmodule.xml_block import XmlMixin log = logging.getLogger(__name__) diff --git a/xmodule/xml_block.py b/xmodule/xml_block.py index dac8fd93d37b..8cadfd17fa1e 100644 --- a/xmodule/xml_block.py +++ b/xmodule/xml_block.py @@ -322,9 +322,7 @@ def parse_xml(cls, node, runtime, keys): # pylint: disable=too-many-locals,too- """ - from xmodule.modulestore.xml import ( # pylint: disable=import-outside-toplevel - XMLImportingModuleStoreRuntime, - ) + from xmodule.modulestore.xml import XMLImportingModuleStoreRuntime # pylint: disable=import-outside-toplevel if keys is None: # Passing keys=None is against the XBlock API but some platform tests do it.