diff --git a/src/backend/joanie/badges/models.py b/src/backend/joanie/badges/models.py index 215763d1c..cd9850bc5 100644 --- a/src/backend/joanie/badges/models.py +++ b/src/backend/joanie/badges/models.py @@ -1,6 +1,7 @@ """ Declare and configure the models for the badges part """ + from functools import lru_cache from django.db import models diff --git a/src/backend/joanie/celery_app.py b/src/backend/joanie/celery_app.py index 68d5f7fa1..cc3e927ec 100644 --- a/src/backend/joanie/celery_app.py +++ b/src/backend/joanie/celery_app.py @@ -1,4 +1,5 @@ """Joanie celery configuration file.""" + import os from celery import Celery diff --git a/src/backend/joanie/client_urls.py b/src/backend/joanie/client_urls.py index 862940eb5..0fadbb5ca 100644 --- a/src/backend/joanie/client_urls.py +++ b/src/backend/joanie/client_urls.py @@ -13,6 +13,7 @@ 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ + from django.conf import settings from django.urls import include, path, re_path diff --git a/src/backend/joanie/core/api/__init__.py b/src/backend/joanie/core/api/__init__.py index 8505cee79..41b290f3c 100644 --- a/src/backend/joanie/core/api/__init__.py +++ b/src/backend/joanie/core/api/__init__.py @@ -1,4 +1,5 @@ """API for the joanie project.""" + from http import HTTPStatus from django.core.exceptions import ValidationError as DjangoValidationError diff --git a/src/backend/joanie/core/api/admin.py b/src/backend/joanie/core/api/admin.py index b481ca788..1b380bc62 100755 --- a/src/backend/joanie/core/api/admin.py +++ b/src/backend/joanie/core/api/admin.py @@ -1,6 +1,7 @@ """ Admin API Endpoints """ + from http import HTTPStatus from django.core.exceptions import ValidationError diff --git a/src/backend/joanie/core/api/base.py b/src/backend/joanie/core/api/base.py index 1b50f8377..71e433e06 100644 --- a/src/backend/joanie/core/api/base.py +++ b/src/backend/joanie/core/api/base.py @@ -1,4 +1,5 @@ -"""Base API classes for the Joanie project. """ +"""Base API classes for the Joanie project.""" + from rest_framework import viewsets diff --git a/src/backend/joanie/core/api/client.py b/src/backend/joanie/core/api/client.py index 6bfc4995b..b22176777 100644 --- a/src/backend/joanie/core/api/client.py +++ b/src/backend/joanie/core/api/client.py @@ -1,6 +1,7 @@ """ Client API endpoints """ + # pylint: disable=too-many-ancestors, too-many-lines import io import uuid @@ -470,9 +471,9 @@ def invoice(self, request, pk=None): # pylint: disable=no-self-use, invalid-nam response = HttpResponse( invoice_pdf_bytes, content_type="application/pdf", status=HTTPStatus.OK ) - response[ - "Content-Disposition" - ] = f"attachment; filename={invoice.reference}.pdf;" + response["Content-Disposition"] = ( + f"attachment; filename={invoice.reference}.pdf;" + ) return response diff --git a/src/backend/joanie/core/api/remote_endpoints.py b/src/backend/joanie/core/api/remote_endpoints.py index fee67959d..5eb4f9f32 100644 --- a/src/backend/joanie/core/api/remote_endpoints.py +++ b/src/backend/joanie/core/api/remote_endpoints.py @@ -1,6 +1,7 @@ """ Remote endpoints API for other servers. """ + from http import HTTPStatus from django.http import JsonResponse diff --git a/src/backend/joanie/core/apps.py b/src/backend/joanie/core/apps.py index ceae20028..607a2d544 100644 --- a/src/backend/joanie/core/apps.py +++ b/src/backend/joanie/core/apps.py @@ -1,4 +1,5 @@ """Joanie Core application""" + from django.apps import AppConfig from django.db.models.signals import m2m_changed, post_save from django.utils.translation import gettext_lazy as _ diff --git a/src/backend/joanie/core/authentication.py b/src/backend/joanie/core/authentication.py index 0938629f2..6aaf396e2 100644 --- a/src/backend/joanie/core/authentication.py +++ b/src/backend/joanie/core/authentication.py @@ -1,4 +1,5 @@ """Authentication for joanie's core app.""" + from django.conf import settings from django.utils.functional import SimpleLazyObject from django.utils.translation import get_supported_language_variant diff --git a/src/backend/joanie/core/enums.py b/src/backend/joanie/core/enums.py index c26ec3494..26b248051 100644 --- a/src/backend/joanie/core/enums.py +++ b/src/backend/joanie/core/enums.py @@ -1,6 +1,7 @@ """ Core application enums declaration """ + from django.conf import global_settings, settings from django.utils.translation import gettext_lazy as _ from django.utils.translation import pgettext_lazy diff --git a/src/backend/joanie/core/factories.py b/src/backend/joanie/core/factories.py index 49415f92f..91d6967fe 100644 --- a/src/backend/joanie/core/factories.py +++ b/src/backend/joanie/core/factories.py @@ -2,6 +2,7 @@ """ Core application factories """ + import hashlib import json import random diff --git a/src/backend/joanie/core/fields/multiselect.py b/src/backend/joanie/core/fields/multiselect.py index 48d8522f2..21b90348a 100644 --- a/src/backend/joanie/core/fields/multiselect.py +++ b/src/backend/joanie/core/fields/multiselect.py @@ -1,4 +1,5 @@ """A multi select field where the array of values is stored as a comma separated string.""" + from django.core import checks, exceptions, validators from django.db import models from django.forms import MultipleChoiceField, widgets diff --git a/src/backend/joanie/core/filters/admin.py b/src/backend/joanie/core/filters/admin.py index 6c3586b7f..a3a67cbd5 100755 --- a/src/backend/joanie/core/filters/admin.py +++ b/src/backend/joanie/core/filters/admin.py @@ -1,6 +1,7 @@ """ Admin API Resource Filters """ + from typing import List from django.conf import settings diff --git a/src/backend/joanie/core/filters/client.py b/src/backend/joanie/core/filters/client.py index 32be8dd3c..c7ba23eb0 100755 --- a/src/backend/joanie/core/filters/client.py +++ b/src/backend/joanie/core/filters/client.py @@ -1,6 +1,7 @@ """ Client API Resource Filters """ + from typing import List from django.db.models import Q diff --git a/src/backend/joanie/core/forms.py b/src/backend/joanie/core/forms.py index d418ee8f1..9ff815555 100644 --- a/src/backend/joanie/core/forms.py +++ b/src/backend/joanie/core/forms.py @@ -1,6 +1,7 @@ """ Core application forms declaration """ + from django import forms from django.contrib.admin import widgets diff --git a/src/backend/joanie/core/helpers.py b/src/backend/joanie/core/helpers.py index bff0c6469..66bee3ea7 100644 --- a/src/backend/joanie/core/helpers.py +++ b/src/backend/joanie/core/helpers.py @@ -1,6 +1,7 @@ """ Helpers that can be useful throughout Joanie's core app """ + from joanie.core import enums diff --git a/src/backend/joanie/core/management/commands/generate_certificates.py b/src/backend/joanie/core/management/commands/generate_certificates.py index 368c121a2..d5bbe6b30 100644 --- a/src/backend/joanie/core/management/commands/generate_certificates.py +++ b/src/backend/joanie/core/management/commands/generate_certificates.py @@ -1,4 +1,5 @@ """Management command to generate all pending certificates.""" + import logging from django.core.management import BaseCommand diff --git a/src/backend/joanie/core/management/commands/synchronize_course_runs.py b/src/backend/joanie/core/management/commands/synchronize_course_runs.py index cec260e72..e75725c70 100644 --- a/src/backend/joanie/core/management/commands/synchronize_course_runs.py +++ b/src/backend/joanie/core/management/commands/synchronize_course_runs.py @@ -1,4 +1,5 @@ """Management command to synchronize course runs or equivalent course runs.""" + import logging from uuid import UUID diff --git a/src/backend/joanie/core/middleware.py b/src/backend/joanie/core/middleware.py index fdf1dcd18..825cf48d0 100644 --- a/src/backend/joanie/core/middleware.py +++ b/src/backend/joanie/core/middleware.py @@ -1,4 +1,5 @@ """Middleware for joanie project.""" + import time from dockerflow.django.middleware import DockerflowMiddleware diff --git a/src/backend/joanie/core/models/__init__.py b/src/backend/joanie/core/models/__init__.py index d4ca68aa2..f9c099b43 100644 --- a/src/backend/joanie/core/models/__init__.py +++ b/src/backend/joanie/core/models/__init__.py @@ -1,4 +1,5 @@ """Make models.py a module containing one file per model as it was getting too long.""" + # pylint: disable=wildcard-import from .accounts import * from .certifications import * diff --git a/src/backend/joanie/core/models/accounts.py b/src/backend/joanie/core/models/accounts.py index 253315106..861c4e8ed 100644 --- a/src/backend/joanie/core/models/accounts.py +++ b/src/backend/joanie/core/models/accounts.py @@ -1,6 +1,7 @@ """ Declare and configure the models for the customers part """ + import django.contrib.auth.models as auth_models from django.conf import settings from django.core.exceptions import ValidationError diff --git a/src/backend/joanie/core/models/base.py b/src/backend/joanie/core/models/base.py index 46fa5d544..0b35a5175 100644 --- a/src/backend/joanie/core/models/base.py +++ b/src/backend/joanie/core/models/base.py @@ -4,6 +4,7 @@ In this base model, we activate generic behaviours that apply to all our models and enforce checks and validation that go further than what Django is doing. """ + import uuid from itertools import chain diff --git a/src/backend/joanie/core/models/certifications.py b/src/backend/joanie/core/models/certifications.py index 49768d0ee..d38f84335 100644 --- a/src/backend/joanie/core/models/certifications.py +++ b/src/backend/joanie/core/models/certifications.py @@ -1,6 +1,7 @@ """ Declare and configure the models for the certifications part """ + import logging from django.conf import settings diff --git a/src/backend/joanie/core/models/contracts.py b/src/backend/joanie/core/models/contracts.py index dc8e58011..bfab68ae4 100644 --- a/src/backend/joanie/core/models/contracts.py +++ b/src/backend/joanie/core/models/contracts.py @@ -1,6 +1,7 @@ """ Declare and configure the models for Joanie's contracts """ + import logging import textwrap from datetime import timedelta diff --git a/src/backend/joanie/core/models/course_wishes.py b/src/backend/joanie/core/models/course_wishes.py index e38424ed3..5b93777bf 100644 --- a/src/backend/joanie/core/models/course_wishes.py +++ b/src/backend/joanie/core/models/course_wishes.py @@ -1,6 +1,7 @@ """ Declare and configure models for course wishes """ + from django.db import models from django.utils.translation import gettext_lazy as _ diff --git a/src/backend/joanie/core/models/courses.py b/src/backend/joanie/core/models/courses.py index 940a81177..868336e4e 100644 --- a/src/backend/joanie/core/models/courses.py +++ b/src/backend/joanie/core/models/courses.py @@ -1,6 +1,7 @@ """ Declare and configure the models for the courses part """ + import itertools import logging from collections.abc import Mapping diff --git a/src/backend/joanie/core/models/products.py b/src/backend/joanie/core/models/products.py index e0a342a64..a1011a9de 100644 --- a/src/backend/joanie/core/models/products.py +++ b/src/backend/joanie/core/models/products.py @@ -1,6 +1,7 @@ """ Declare and configure the models for the product / order part """ + import itertools import logging from collections import defaultdict diff --git a/src/backend/joanie/core/models/site.py b/src/backend/joanie/core/models/site.py index 27e1b0b67..33b37bc14 100644 --- a/src/backend/joanie/core/models/site.py +++ b/src/backend/joanie/core/models/site.py @@ -1,4 +1,5 @@ """Site extension models for the Joanie project.""" + import textwrap from django.contrib.sites.models import Site diff --git a/src/backend/joanie/core/pagination.py b/src/backend/joanie/core/pagination.py index a76b78f7c..640da6ecd 100644 --- a/src/backend/joanie/core/pagination.py +++ b/src/backend/joanie/core/pagination.py @@ -1,4 +1,5 @@ """Pagination used by django rest framework.""" + from rest_framework.pagination import PageNumberPagination diff --git a/src/backend/joanie/core/permissions.py b/src/backend/joanie/core/permissions.py index eebbc67f1..6b462dc76 100644 --- a/src/backend/joanie/core/permissions.py +++ b/src/backend/joanie/core/permissions.py @@ -1,4 +1,5 @@ """Permission handlers for joanie's core app.""" + from django.conf import settings from rest_framework import permissions diff --git a/src/backend/joanie/core/serializers/admin.py b/src/backend/joanie/core/serializers/admin.py index bc189ec16..19805c6fe 100755 --- a/src/backend/joanie/core/serializers/admin.py +++ b/src/backend/joanie/core/serializers/admin.py @@ -1,5 +1,6 @@ # pylint: disable=too-many-lines """Admin serializers for Joanie Core app.""" + from django.conf import settings from drf_spectacular.utils import extend_schema_serializer diff --git a/src/backend/joanie/core/serializers/base.py b/src/backend/joanie/core/serializers/base.py index 7be9afcfd..1b844c727 100644 --- a/src/backend/joanie/core/serializers/base.py +++ b/src/backend/joanie/core/serializers/base.py @@ -1,4 +1,5 @@ """Base Serializer classes for the Joanie project.""" + from django.conf import settings from django.core.cache import cache diff --git a/src/backend/joanie/core/serializers/client.py b/src/backend/joanie/core/serializers/client.py index c80849d57..3af9d738f 100644 --- a/src/backend/joanie/core/serializers/client.py +++ b/src/backend/joanie/core/serializers/client.py @@ -1,4 +1,5 @@ """Client serializers for Joanie Core app.""" + # pylint: disable=too-many-lines from django.conf import settings from django.utils.translation import get_language @@ -983,10 +984,10 @@ def validate(self, attrs): errors = {} if course_product_relation_id: try: - attrs[ - "course_product_relation" - ] = models.CourseProductRelation.objects.get( - pk=course_product_relation_id + attrs["course_product_relation"] = ( + models.CourseProductRelation.objects.get( + pk=course_product_relation_id + ) ) except models.CourseProductRelation.DoesNotExist: errors["course_product_relation_id"] = ( diff --git a/src/backend/joanie/core/serializers/fields.py b/src/backend/joanie/core/serializers/fields.py index 51867996b..0f02daef8 100644 --- a/src/backend/joanie/core/serializers/fields.py +++ b/src/backend/joanie/core/serializers/fields.py @@ -1,4 +1,5 @@ """Custom serializer fields.""" + from drf_spectacular.types import OpenApiTypes from drf_spectacular.utils import extend_schema_field from easy_thumbnails.alias import aliases diff --git a/src/backend/joanie/core/signals.py b/src/backend/joanie/core/signals.py index 010f7a086..17d55dc40 100644 --- a/src/backend/joanie/core/signals.py +++ b/src/backend/joanie/core/signals.py @@ -1,6 +1,7 @@ """ Helpers that can be useful throughout Joanie's core app """ + import logging from django.core.exceptions import ValidationError diff --git a/src/backend/joanie/core/storages.py b/src/backend/joanie/core/storages.py index 9a89157e0..f432d0d31 100644 --- a/src/backend/joanie/core/storages.py +++ b/src/backend/joanie/core/storages.py @@ -1,4 +1,5 @@ """Module containing specific storages.""" + from django.conf import settings from storages.backends.s3 import S3Storage diff --git a/src/backend/joanie/core/tasks.py b/src/backend/joanie/core/tasks.py index 4c973faee..14d3c1bd6 100644 --- a/src/backend/joanie/core/tasks.py +++ b/src/backend/joanie/core/tasks.py @@ -1,4 +1,5 @@ """Celery tasks for the `core` app of Joanie""" + from logging import getLogger from django.core.management import call_command diff --git a/src/backend/joanie/core/templatetags/extra_tags.py b/src/backend/joanie/core/templatetags/extra_tags.py index e59249f56..c9601f346 100644 --- a/src/backend/joanie/core/templatetags/extra_tags.py +++ b/src/backend/joanie/core/templatetags/extra_tags.py @@ -1,4 +1,5 @@ """Custom template tags for the core application of Joanie.""" + import math from django import template diff --git a/src/backend/joanie/core/utils/__init__.py b/src/backend/joanie/core/utils/__init__.py index 0c7b3e685..4d23c9102 100755 --- a/src/backend/joanie/core/utils/__init__.py +++ b/src/backend/joanie/core/utils/__init__.py @@ -1,6 +1,7 @@ """ Utils that can be useful throughout Joanie's core app """ + import base64 import collections.abc import json diff --git a/src/backend/joanie/core/utils/contract.py b/src/backend/joanie/core/utils/contract.py index bdbf30e0a..c9b213fed 100644 --- a/src/backend/joanie/core/utils/contract.py +++ b/src/backend/joanie/core/utils/contract.py @@ -1,4 +1,5 @@ """Utility to generate a ZIP archive of PDF bytes files for contracts that are signed""" + import io import zipfile from logging import getLogger diff --git a/src/backend/joanie/core/utils/contract_definition.py b/src/backend/joanie/core/utils/contract_definition.py index 627198f51..c7ffedcb3 100644 --- a/src/backend/joanie/core/utils/contract_definition.py +++ b/src/backend/joanie/core/utils/contract_definition.py @@ -1,4 +1,5 @@ """Utility to `generate document context` data""" + from django.conf import settings from django.contrib.sites.models import Site from django.utils.translation import gettext as _ diff --git a/src/backend/joanie/core/utils/course_run.py b/src/backend/joanie/core/utils/course_run.py index 9a93b4535..4ebba7f55 100644 --- a/src/backend/joanie/core/utils/course_run.py +++ b/src/backend/joanie/core/utils/course_run.py @@ -1,6 +1,7 @@ """ Utility methods for Course Run on enrollments metrics and orders made. """ + import logging from django.core.exceptions import ValidationError diff --git a/src/backend/joanie/core/utils/issuers.py b/src/backend/joanie/core/utils/issuers.py index 0e677388a..68926a508 100644 --- a/src/backend/joanie/core/utils/issuers.py +++ b/src/backend/joanie/core/utils/issuers.py @@ -1,4 +1,5 @@ """Utils that can be useful throughout Joanie's core app for document issuers""" + from pathlib import Path from django.template import Context diff --git a/src/backend/joanie/core/utils/webhooks.py b/src/backend/joanie/core/utils/webhooks.py index 1ca364826..5770aeff8 100644 --- a/src/backend/joanie/core/utils/webhooks.py +++ b/src/backend/joanie/core/utils/webhooks.py @@ -1,6 +1,7 @@ """ Utils that can be useful throughout Joanie's core app to synchronize data with other services """ + import hashlib import hmac import json diff --git a/src/backend/joanie/core/views/__init__.py b/src/backend/joanie/core/views/__init__.py index 1fbbce629..8c6bc22f0 100644 --- a/src/backend/joanie/core/views/__init__.py +++ b/src/backend/joanie/core/views/__init__.py @@ -1,3 +1,4 @@ """Views of the ``core`` app of the Joanie project.""" + from .certificate import * from .redirect import * diff --git a/src/backend/joanie/core/views/certificate.py b/src/backend/joanie/core/views/certificate.py index 018f976d6..81ef01f9d 100644 --- a/src/backend/joanie/core/views/certificate.py +++ b/src/backend/joanie/core/views/certificate.py @@ -1,4 +1,5 @@ """Certificate views for the Joanie core app.""" + import base64 from django.contrib.sites.models import Site diff --git a/src/backend/joanie/core/views/redirect.py b/src/backend/joanie/core/views/redirect.py index 2c89e9752..9bc6a5e75 100644 --- a/src/backend/joanie/core/views/redirect.py +++ b/src/backend/joanie/core/views/redirect.py @@ -1,4 +1,5 @@ """Redirect views of the `core`app.""" + from django.conf import settings from django.views.generic.base import RedirectView diff --git a/src/backend/joanie/debug/views.py b/src/backend/joanie/debug/views.py index dd1c3548c..7110df4d3 100644 --- a/src/backend/joanie/debug/views.py +++ b/src/backend/joanie/debug/views.py @@ -1,4 +1,5 @@ """All debug views of the `debug`app.""" + import base64 import datetime from logging import getLogger diff --git a/src/backend/joanie/demo/management/commands/create_dev_demo.py b/src/backend/joanie/demo/management/commands/create_dev_demo.py index 2ac024636..02b1133b0 100644 --- a/src/backend/joanie/demo/management/commands/create_dev_demo.py +++ b/src/backend/joanie/demo/management/commands/create_dev_demo.py @@ -1,5 +1,6 @@ # ruff: noqa: S311, PLR0913, PLR0915 """Management command to initialize some fake data (products, courses and course runs)""" + import random from django.conf import settings diff --git a/src/backend/joanie/demo/management/commands/generate_jwt_tokens.py b/src/backend/joanie/demo/management/commands/generate_jwt_tokens.py index b3b63bcbd..108334f7e 100644 --- a/src/backend/joanie/demo/management/commands/generate_jwt_tokens.py +++ b/src/backend/joanie/demo/management/commands/generate_jwt_tokens.py @@ -1,4 +1,5 @@ """Management command to generate user JWT tokens""" + import json from datetime import datetime, timedelta diff --git a/src/backend/joanie/edx_imports/checks.py b/src/backend/joanie/edx_imports/checks.py index 8627373fe..73a1245df 100644 --- a/src/backend/joanie/edx_imports/checks.py +++ b/src/backend/joanie/edx_imports/checks.py @@ -3,6 +3,7 @@ """ Check the environment variables and database connections required for the import tasks. """ + from http import HTTPStatus from logging import getLogger diff --git a/src/backend/joanie/edx_imports/edx_factories.py b/src/backend/joanie/edx_imports/edx_factories.py index 3bb52aafc..adf32acf8 100644 --- a/src/backend/joanie/edx_imports/edx_factories.py +++ b/src/backend/joanie/edx_imports/edx_factories.py @@ -1,4 +1,5 @@ """Factory classes for generating fake data for testing.""" + import random import factory diff --git a/src/backend/joanie/edx_imports/edx_models.py b/src/backend/joanie/edx_imports/edx_models.py index aa72aaf74..f90b7970a 100644 --- a/src/backend/joanie/edx_imports/edx_models.py +++ b/src/backend/joanie/edx_imports/edx_models.py @@ -1,4 +1,5 @@ """Models for the Open edX database.""" + import datetime import decimal from typing import List, Optional @@ -42,9 +43,9 @@ class User(Base): user_api_userpreference: Mapped[List["UserPreference"]] = relationship( "UserPreference", back_populates="user" ) - certificates_generatedcertificate: Mapped[ - List["GeneratedCertificate"] - ] = relationship("GeneratedCertificate", back_populates="user") + certificates_generatedcertificate: Mapped[List["GeneratedCertificate"]] = ( + relationship("GeneratedCertificate", back_populates="user") + ) class UserProfile(Base): @@ -216,9 +217,9 @@ class Course(Base): course_overviews_courseoverview: Mapped["CourseOverview"] = relationship( "CourseOverview", back_populates="course" ) - courses_courseuniversityrelation: Mapped[ - List["CourseUniversityRelation"] - ] = relationship("CourseUniversityRelation", back_populates="course") + courses_courseuniversityrelation: Mapped[List["CourseUniversityRelation"]] = ( + relationship("CourseUniversityRelation", back_populates="course") + ) class University(Base): @@ -250,9 +251,9 @@ class University(Base): banner: Mapped[Optional[str]] = mapped_column(String(100)) certificate_logo: Mapped[Optional[str]] = mapped_column(String(100)) - courses_courseuniversityrelation: Mapped[ - List["CourseUniversityRelation"] - ] = relationship("CourseUniversityRelation", back_populates="university") + courses_courseuniversityrelation: Mapped[List["CourseUniversityRelation"]] = ( + relationship("CourseUniversityRelation", back_populates="university") + ) class CourseUniversityRelation(Base): diff --git a/src/backend/joanie/edx_imports/edx_mongodb.py b/src/backend/joanie/edx_imports/edx_mongodb.py index 816db25a9..179818aaf 100644 --- a/src/backend/joanie/edx_imports/edx_mongodb.py +++ b/src/backend/joanie/edx_imports/edx_mongodb.py @@ -1,4 +1,5 @@ """Module to connect to Open edX mongodb and extract data""" + from django.conf import settings from pymongo import MongoClient diff --git a/src/backend/joanie/edx_imports/management/commands/migrate_edx.py b/src/backend/joanie/edx_imports/management/commands/migrate_edx.py index 9d0402f8d..fc5ba3897 100644 --- a/src/backend/joanie/edx_imports/management/commands/migrate_edx.py +++ b/src/backend/joanie/edx_imports/management/commands/migrate_edx.py @@ -1,4 +1,5 @@ """Import data from Open edX database to Joanie database""" + import logging from django.core.management import BaseCommand diff --git a/src/backend/joanie/edx_imports/tasks/__init__.py b/src/backend/joanie/edx_imports/tasks/__init__.py index 127b71c7e..e47ec08d1 100644 --- a/src/backend/joanie/edx_imports/tasks/__init__.py +++ b/src/backend/joanie/edx_imports/tasks/__init__.py @@ -1,4 +1,5 @@ """Module for importing tasks.""" + from .certificates import import_certificates_batch_task from .course_runs import import_course_runs_batch_task from .enrollments import import_enrollments_batch_task diff --git a/src/backend/joanie/edx_imports/tasks/universities.py b/src/backend/joanie/edx_imports/tasks/universities.py index 17ba8c481..2c1d39041 100644 --- a/src/backend/joanie/edx_imports/tasks/universities.py +++ b/src/backend/joanie/edx_imports/tasks/universities.py @@ -1,4 +1,5 @@ """Celery tasks for importing Open edX universities to Joanie organizations.""" + from logging import getLogger from joanie.celery_app import app diff --git a/src/backend/joanie/lms_handler/__init__.py b/src/backend/joanie/lms_handler/__init__.py index edaa11272..6fe417908 100644 --- a/src/backend/joanie/lms_handler/__init__.py +++ b/src/backend/joanie/lms_handler/__init__.py @@ -1,4 +1,5 @@ """LMS Handler""" + import re from django.conf import settings diff --git a/src/backend/joanie/lms_handler/api.py b/src/backend/joanie/lms_handler/api.py index 99177b581..fbc00b8c2 100644 --- a/src/backend/joanie/lms_handler/api.py +++ b/src/backend/joanie/lms_handler/api.py @@ -1,6 +1,7 @@ """ API endpoints """ + import hashlib import hmac from http import HTTPStatus diff --git a/src/backend/joanie/lms_handler/backends/moodle.py b/src/backend/joanie/lms_handler/backends/moodle.py index 7d72a7579..a7ead3a51 100644 --- a/src/backend/joanie/lms_handler/backends/moodle.py +++ b/src/backend/joanie/lms_handler/backends/moodle.py @@ -1,6 +1,7 @@ """ Backend to connect Joanie to Moodle LMS """ + import logging from urllib.parse import parse_qs, urlparse diff --git a/src/backend/joanie/lms_handler/backends/openedx.py b/src/backend/joanie/lms_handler/backends/openedx.py index 409cd2717..b4eb40d16 100644 --- a/src/backend/joanie/lms_handler/backends/openedx.py +++ b/src/backend/joanie/lms_handler/backends/openedx.py @@ -1,6 +1,7 @@ """ Backend to connect Joanie to OpenEdX LMS """ + import json import logging import re diff --git a/src/backend/joanie/lms_handler/serializers.py b/src/backend/joanie/lms_handler/serializers.py index 7945f1e36..0bfcc7c5d 100644 --- a/src/backend/joanie/lms_handler/serializers.py +++ b/src/backend/joanie/lms_handler/serializers.py @@ -1,4 +1,5 @@ """Serializers for Joanie's LMS handler.""" + from django.utils.functional import lazy from rest_framework import serializers diff --git a/src/backend/joanie/lms_handler/urls.py b/src/backend/joanie/lms_handler/urls.py index 6af3de8c0..0731435ae 100644 --- a/src/backend/joanie/lms_handler/urls.py +++ b/src/backend/joanie/lms_handler/urls.py @@ -1,6 +1,7 @@ """ API routes exposed by our LMS handler app. """ + from django.urls import re_path from rest_framework import routers diff --git a/src/backend/joanie/payment/__init__.py b/src/backend/joanie/payment/__init__.py index 26c8b50e9..f3506983c 100644 --- a/src/backend/joanie/payment/__init__.py +++ b/src/backend/joanie/payment/__init__.py @@ -1,4 +1,5 @@ """Payment""" + from django.conf import settings from django.utils.module_loading import import_string diff --git a/src/backend/joanie/payment/admin.py b/src/backend/joanie/payment/admin.py index ce7c66dea..dfd3c77db 100644 --- a/src/backend/joanie/payment/admin.py +++ b/src/backend/joanie/payment/admin.py @@ -1,6 +1,7 @@ """ Payment application admin """ + from django.contrib import admin from django.contrib.admin.options import csrf_protect_m from django.urls import reverse diff --git a/src/backend/joanie/payment/api.py b/src/backend/joanie/payment/api.py index 4b70b0b8a..f4c9ecd27 100644 --- a/src/backend/joanie/payment/api.py +++ b/src/backend/joanie/payment/api.py @@ -1,6 +1,7 @@ """ API endpoints """ + import logging from http import HTTPStatus diff --git a/src/backend/joanie/payment/apps.py b/src/backend/joanie/payment/apps.py index a034cc887..16a2d69e0 100644 --- a/src/backend/joanie/payment/apps.py +++ b/src/backend/joanie/payment/apps.py @@ -1,4 +1,5 @@ """Joanie Payment application""" + from django.apps import AppConfig from django.utils.translation import gettext_lazy as _ diff --git a/src/backend/joanie/payment/backends/base.py b/src/backend/joanie/payment/backends/base.py index f1b832d06..e3f17d3e0 100644 --- a/src/backend/joanie/payment/backends/base.py +++ b/src/backend/joanie/payment/backends/base.py @@ -1,4 +1,5 @@ """Base Payment Backend""" + import smtplib from logging import getLogger diff --git a/src/backend/joanie/payment/backends/dummy.py b/src/backend/joanie/payment/backends/dummy.py index 903f19822..7b2cc560f 100644 --- a/src/backend/joanie/payment/backends/dummy.py +++ b/src/backend/joanie/payment/backends/dummy.py @@ -1,4 +1,5 @@ """Dummy Payment Backend""" + import json import logging from decimal import Decimal as D diff --git a/src/backend/joanie/payment/backends/payplug/__init__.py b/src/backend/joanie/payment/backends/payplug/__init__.py index 89baae478..9fbb0e830 100644 --- a/src/backend/joanie/payment/backends/payplug/__init__.py +++ b/src/backend/joanie/payment/backends/payplug/__init__.py @@ -1,4 +1,5 @@ """Payplug Payment Backend""" + import logging from decimal import Decimal as D diff --git a/src/backend/joanie/payment/backends/payplug/factories.py b/src/backend/joanie/payment/backends/payplug/factories.py index a434dd541..20fd4e700 100644 --- a/src/backend/joanie/payment/backends/payplug/factories.py +++ b/src/backend/joanie/payment/backends/payplug/factories.py @@ -1,4 +1,5 @@ """Payplug objects factories""" + import string import factory diff --git a/src/backend/joanie/payment/exceptions.py b/src/backend/joanie/payment/exceptions.py index 788b5a710..023d44015 100644 --- a/src/backend/joanie/payment/exceptions.py +++ b/src/backend/joanie/payment/exceptions.py @@ -1,4 +1,5 @@ """Payment exceptions""" + from http import HTTPStatus from django.utils.translation import gettext_lazy as _ diff --git a/src/backend/joanie/payment/factories.py b/src/backend/joanie/payment/factories.py index dd1ca2e48..6a6591ca5 100644 --- a/src/backend/joanie/payment/factories.py +++ b/src/backend/joanie/payment/factories.py @@ -1,6 +1,7 @@ """ Payment application factories """ + import string import factory.fuzzy diff --git a/src/backend/joanie/payment/models.py b/src/backend/joanie/payment/models.py index f36552fdf..9df84d3eb 100644 --- a/src/backend/joanie/payment/models.py +++ b/src/backend/joanie/payment/models.py @@ -1,6 +1,7 @@ """ Declare and configure models for the payment part """ + import logging from decimal import Decimal as D diff --git a/src/backend/joanie/payment/serializers.py b/src/backend/joanie/payment/serializers.py index 3f556499f..f9babd08b 100644 --- a/src/backend/joanie/payment/serializers.py +++ b/src/backend/joanie/payment/serializers.py @@ -1,4 +1,5 @@ """Serializers for api.""" + from rest_framework import serializers from joanie.payment import models diff --git a/src/backend/joanie/payment/urls.py b/src/backend/joanie/payment/urls.py index 27e5c51c7..32037bdf4 100644 --- a/src/backend/joanie/payment/urls.py +++ b/src/backend/joanie/payment/urls.py @@ -1,6 +1,7 @@ """ API routes exposed by our Payment app """ + from django.urls import re_path from rest_framework.routers import DefaultRouter diff --git a/src/backend/joanie/remote_endpoints_urls.py b/src/backend/joanie/remote_endpoints_urls.py index 5f7470da9..3a0152bcd 100644 --- a/src/backend/joanie/remote_endpoints_urls.py +++ b/src/backend/joanie/remote_endpoints_urls.py @@ -1,6 +1,7 @@ """ API routes exposed for server to server. Requires a specific token to request. """ + from django.conf import settings from django.urls import path diff --git a/src/backend/joanie/settings.py b/src/backend/joanie/settings.py index e135a71b0..e7d20a9fd 100755 --- a/src/backend/joanie/settings.py +++ b/src/backend/joanie/settings.py @@ -9,6 +9,7 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.1/ref/settings/ """ + import json import os diff --git a/src/backend/joanie/signature/api.py b/src/backend/joanie/signature/api.py index bef3f3333..155f1be69 100644 --- a/src/backend/joanie/signature/api.py +++ b/src/backend/joanie/signature/api.py @@ -1,6 +1,7 @@ """ API endpoint for Signature """ + import logging from http import HTTPStatus diff --git a/src/backend/joanie/signature/apps.py b/src/backend/joanie/signature/apps.py index eb9bcfc6b..7f3549026 100644 --- a/src/backend/joanie/signature/apps.py +++ b/src/backend/joanie/signature/apps.py @@ -1,4 +1,5 @@ """Joanie Signature application""" + from django.apps import AppConfig from django.conf import settings from django.core.exceptions import ImproperlyConfigured diff --git a/src/backend/joanie/signature/backends/__init__.py b/src/backend/joanie/signature/backends/__init__.py index 2495e5dd0..1c3e4d9f2 100644 --- a/src/backend/joanie/signature/backends/__init__.py +++ b/src/backend/joanie/signature/backends/__init__.py @@ -1,4 +1,5 @@ """Get Signature Backend""" + from django.conf import settings from django.utils.module_loading import import_string diff --git a/src/backend/joanie/signature/backends/base.py b/src/backend/joanie/signature/backends/base.py index 4913ce3bf..8a97b3aa6 100644 --- a/src/backend/joanie/signature/backends/base.py +++ b/src/backend/joanie/signature/backends/base.py @@ -1,4 +1,5 @@ """Base Signature Backend""" + import re from logging import getLogger diff --git a/src/backend/joanie/signature/backends/dummy.py b/src/backend/joanie/signature/backends/dummy.py index e03e52663..c3115c7ef 100644 --- a/src/backend/joanie/signature/backends/dummy.py +++ b/src/backend/joanie/signature/backends/dummy.py @@ -1,4 +1,5 @@ """Dummy Signature Backend""" + import smtplib from logging import getLogger from uuid import uuid4 diff --git a/src/backend/joanie/signature/backends/lex_persona.py b/src/backend/joanie/signature/backends/lex_persona.py index b4269281b..b8f93a299 100644 --- a/src/backend/joanie/signature/backends/lex_persona.py +++ b/src/backend/joanie/signature/backends/lex_persona.py @@ -1,4 +1,5 @@ """Signature Backend for Lex Persona Provider""" + import io import json import re diff --git a/src/backend/joanie/signature/exceptions.py b/src/backend/joanie/signature/exceptions.py index 1af61c5c2..1f325af67 100644 --- a/src/backend/joanie/signature/exceptions.py +++ b/src/backend/joanie/signature/exceptions.py @@ -1,4 +1,5 @@ """Signature exceptions""" + from http import HTTPStatus from django.utils.translation import gettext_lazy as _ diff --git a/src/backend/joanie/signature/management/commands/generate_zip_archive_of_contracts.py b/src/backend/joanie/signature/management/commands/generate_zip_archive_of_contracts.py index df4582563..32521a630 100644 --- a/src/backend/joanie/signature/management/commands/generate_zip_archive_of_contracts.py +++ b/src/backend/joanie/signature/management/commands/generate_zip_archive_of_contracts.py @@ -1,4 +1,5 @@ """Management command to generate a ZIP archive of signed contracts into file system storage""" + import logging import uuid diff --git a/src/backend/joanie/signature/urls.py b/src/backend/joanie/signature/urls.py index 54d0a6ff4..e920f70a5 100644 --- a/src/backend/joanie/signature/urls.py +++ b/src/backend/joanie/signature/urls.py @@ -1,6 +1,7 @@ """ API routes exposed by our Signature app """ + from django.urls import re_path from rest_framework.routers import DefaultRouter diff --git a/src/backend/joanie/tests/badges/test_models.py b/src/backend/joanie/tests/badges/test_models.py index 4e9c43e46..a6dfc7952 100644 --- a/src/backend/joanie/tests/badges/test_models.py +++ b/src/backend/joanie/tests/badges/test_models.py @@ -1,4 +1,5 @@ """Test suite for badge models.""" + from django.test import TestCase from joanie.badges import factories, models diff --git a/src/backend/joanie/tests/base.py b/src/backend/joanie/tests/base.py index ff88c1d26..11bb9a714 100644 --- a/src/backend/joanie/tests/base.py +++ b/src/backend/joanie/tests/base.py @@ -1,6 +1,7 @@ """ Common base test cases """ + from datetime import datetime, timedelta from django.conf import settings diff --git a/src/backend/joanie/tests/core/api/admin/course_product_relations/test_create.py b/src/backend/joanie/tests/core/api/admin/course_product_relations/test_create.py index fe2af765d..e18c1e5cf 100644 --- a/src/backend/joanie/tests/core/api/admin/course_product_relations/test_create.py +++ b/src/backend/joanie/tests/core/api/admin/course_product_relations/test_create.py @@ -2,6 +2,7 @@ """ Test suite for CourseProductRelation create Admin API. """ + import uuid from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/core/api/admin/course_product_relations/test_delete.py b/src/backend/joanie/tests/core/api/admin/course_product_relations/test_delete.py index 72c56314c..1fec95710 100644 --- a/src/backend/joanie/tests/core/api/admin/course_product_relations/test_delete.py +++ b/src/backend/joanie/tests/core/api/admin/course_product_relations/test_delete.py @@ -1,6 +1,7 @@ """ Test suite for CourseProductRelation delete Admin API. """ + from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/core/api/admin/course_product_relations/test_list.py b/src/backend/joanie/tests/core/api/admin/course_product_relations/test_list.py index 0f6ee868d..91173a0b0 100644 --- a/src/backend/joanie/tests/core/api/admin/course_product_relations/test_list.py +++ b/src/backend/joanie/tests/core/api/admin/course_product_relations/test_list.py @@ -2,6 +2,7 @@ """ Test suite for CourseProductRelation list Admin API. """ + from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/core/api/admin/course_product_relations/test_retrieve.py b/src/backend/joanie/tests/core/api/admin/course_product_relations/test_retrieve.py index 4891adffc..a98d0e119 100644 --- a/src/backend/joanie/tests/core/api/admin/course_product_relations/test_retrieve.py +++ b/src/backend/joanie/tests/core/api/admin/course_product_relations/test_retrieve.py @@ -2,6 +2,7 @@ """ Test suite for CourseProductRelation retrieve Admin API. """ + from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/core/api/admin/course_product_relations/test_update.py b/src/backend/joanie/tests/core/api/admin/course_product_relations/test_update.py index 982ab1380..6ebd053cb 100644 --- a/src/backend/joanie/tests/core/api/admin/course_product_relations/test_update.py +++ b/src/backend/joanie/tests/core/api/admin/course_product_relations/test_update.py @@ -2,6 +2,7 @@ """ Test suite for CourseProductRelation update Admin API. """ + import uuid from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/core/api/order/test_abort.py b/src/backend/joanie/tests/core/api/order/test_abort.py index 54cb642d1..4a39d3811 100644 --- a/src/backend/joanie/tests/core/api/order/test_abort.py +++ b/src/backend/joanie/tests/core/api/order/test_abort.py @@ -1,4 +1,5 @@ """Tests for the Order abort API.""" + from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/core/api/order/test_cancel.py b/src/backend/joanie/tests/core/api/order/test_cancel.py index 077a6b051..3524c057d 100644 --- a/src/backend/joanie/tests/core/api/order/test_cancel.py +++ b/src/backend/joanie/tests/core/api/order/test_cancel.py @@ -1,4 +1,5 @@ """Tests for the Order cancel API.""" + from http import HTTPStatus from django.core.cache import cache diff --git a/src/backend/joanie/tests/core/api/order/test_create.py b/src/backend/joanie/tests/core/api/order/test_create.py index 250b363bc..74ac70e24 100644 --- a/src/backend/joanie/tests/core/api/order/test_create.py +++ b/src/backend/joanie/tests/core/api/order/test_create.py @@ -1,4 +1,5 @@ """Tests for the Order create API.""" + # pylint: disable=too-many-lines import random import uuid diff --git a/src/backend/joanie/tests/core/api/order/test_delete.py b/src/backend/joanie/tests/core/api/order/test_delete.py index 65486cacf..c6df60c85 100644 --- a/src/backend/joanie/tests/core/api/order/test_delete.py +++ b/src/backend/joanie/tests/core/api/order/test_delete.py @@ -1,4 +1,5 @@ """Tests for the Order delete API.""" + import random from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/api/order/test_invoice.py b/src/backend/joanie/tests/core/api/order/test_invoice.py index 264058d19..6cd052fc2 100644 --- a/src/backend/joanie/tests/core/api/order/test_invoice.py +++ b/src/backend/joanie/tests/core/api/order/test_invoice.py @@ -1,4 +1,5 @@ """Tests for the Order invoice API.""" + from http import HTTPStatus from io import BytesIO diff --git a/src/backend/joanie/tests/core/api/order/test_read_detail.py b/src/backend/joanie/tests/core/api/order/test_read_detail.py index 3e20da400..c2e2f3480 100644 --- a/src/backend/joanie/tests/core/api/order/test_read_detail.py +++ b/src/backend/joanie/tests/core/api/order/test_read_detail.py @@ -1,4 +1,5 @@ """Tests for the Order read detail API.""" + from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/core/api/order/test_read_list.py b/src/backend/joanie/tests/core/api/order/test_read_list.py index 2400167d2..b04c4b087 100644 --- a/src/backend/joanie/tests/core/api/order/test_read_list.py +++ b/src/backend/joanie/tests/core/api/order/test_read_list.py @@ -1,4 +1,5 @@ """Tests for the Order read list API.""" + # pylint: disable=too-many-lines from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/core/api/order/test_submit.py b/src/backend/joanie/tests/core/api/order/test_submit.py index fe4c550b0..242146f70 100644 --- a/src/backend/joanie/tests/core/api/order/test_submit.py +++ b/src/backend/joanie/tests/core/api/order/test_submit.py @@ -1,4 +1,5 @@ """Tests for the Order submit API.""" + import random from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/core/api/order/test_submit_for_signature.py b/src/backend/joanie/tests/core/api/order/test_submit_for_signature.py index 4f13243ff..6ad8689a8 100644 --- a/src/backend/joanie/tests/core/api/order/test_submit_for_signature.py +++ b/src/backend/joanie/tests/core/api/order/test_submit_for_signature.py @@ -1,4 +1,5 @@ """Tests for the Order submit for signature API.""" + import json import random from datetime import timedelta diff --git a/src/backend/joanie/tests/core/api/order/test_update.py b/src/backend/joanie/tests/core/api/order/test_update.py index fa211d745..3582353e3 100644 --- a/src/backend/joanie/tests/core/api/order/test_update.py +++ b/src/backend/joanie/tests/core/api/order/test_update.py @@ -1,4 +1,5 @@ """Tests for the Order update API.""" + import json import random import uuid diff --git a/src/backend/joanie/tests/core/api/order/test_validate.py b/src/backend/joanie/tests/core/api/order/test_validate.py index 427fa52a3..335727431 100644 --- a/src/backend/joanie/tests/core/api/order/test_validate.py +++ b/src/backend/joanie/tests/core/api/order/test_validate.py @@ -1,4 +1,5 @@ """Tests for the Order validate API.""" + from http import HTTPStatus from django.core.cache import cache diff --git a/src/backend/joanie/tests/core/api/organizations/test_api_organization_accesses.py b/src/backend/joanie/tests/core/api/organizations/test_api_organization_accesses.py index c495b6af7..d7ec05a7f 100644 --- a/src/backend/joanie/tests/core/api/organizations/test_api_organization_accesses.py +++ b/src/backend/joanie/tests/core/api/organizations/test_api_organization_accesses.py @@ -1,6 +1,7 @@ """ Tests organization access API endpoints in Joanie's core app. """ + import random from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/core/api/organizations/test_api_organizations_contract.py b/src/backend/joanie/tests/core/api/organizations/test_api_organizations_contract.py index 7537a9170..02f5555a3 100644 --- a/src/backend/joanie/tests/core/api/organizations/test_api_organizations_contract.py +++ b/src/backend/joanie/tests/core/api/organizations/test_api_organizations_contract.py @@ -1,5 +1,6 @@ # pylint: disable=duplicate-code """Test suite for the Organizations Contract API""" + from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/core/api/organizations/test_api_organizations_course_product_relations.py b/src/backend/joanie/tests/core/api/organizations/test_api_organizations_course_product_relations.py index 012457791..344b5b783 100644 --- a/src/backend/joanie/tests/core/api/organizations/test_api_organizations_course_product_relations.py +++ b/src/backend/joanie/tests/core/api/organizations/test_api_organizations_course_product_relations.py @@ -1,6 +1,7 @@ """ Test suite for Organization's CourseProductRelation API endpoint. """ + from http import HTTPStatus from joanie.core import factories, models diff --git a/src/backend/joanie/tests/core/api/organizations/test_api_organizations_courses.py b/src/backend/joanie/tests/core/api/organizations/test_api_organizations_courses.py index 1e7cba461..7f8e63792 100644 --- a/src/backend/joanie/tests/core/api/organizations/test_api_organizations_courses.py +++ b/src/backend/joanie/tests/core/api/organizations/test_api_organizations_courses.py @@ -1,6 +1,7 @@ """ Test suite for Organization's courses API endpoint. """ + import random from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/api/organizations/test_contracts_signature_link.py b/src/backend/joanie/tests/core/api/organizations/test_contracts_signature_link.py index 97ce6d994..99a413fb2 100644 --- a/src/backend/joanie/tests/core/api/organizations/test_contracts_signature_link.py +++ b/src/backend/joanie/tests/core/api/organizations/test_contracts_signature_link.py @@ -1,6 +1,7 @@ """ Test suite for Organization Contracts signature link API endpoint. """ + import random from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/api/organizations/test_create.py b/src/backend/joanie/tests/core/api/organizations/test_create.py index 871aa39d1..a4040c05f 100644 --- a/src/backend/joanie/tests/core/api/organizations/test_create.py +++ b/src/backend/joanie/tests/core/api/organizations/test_create.py @@ -1,6 +1,7 @@ """ Test suite for Organization Create API endpoint. """ + import random from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/api/organizations/test_delete.py b/src/backend/joanie/tests/core/api/organizations/test_delete.py index 8f7f4559b..7f1a970da 100644 --- a/src/backend/joanie/tests/core/api/organizations/test_delete.py +++ b/src/backend/joanie/tests/core/api/organizations/test_delete.py @@ -1,6 +1,7 @@ """ Test suite for Organization delete API endpoint. """ + import random from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/api/organizations/test_list.py b/src/backend/joanie/tests/core/api/organizations/test_list.py index be444f1e6..11300d911 100644 --- a/src/backend/joanie/tests/core/api/organizations/test_list.py +++ b/src/backend/joanie/tests/core/api/organizations/test_list.py @@ -1,6 +1,7 @@ """ Test suite for Organization list API endpoint. """ + import uuid from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/core/api/organizations/test_retrieve.py b/src/backend/joanie/tests/core/api/organizations/test_retrieve.py index 456e1dca3..52caa1119 100644 --- a/src/backend/joanie/tests/core/api/organizations/test_retrieve.py +++ b/src/backend/joanie/tests/core/api/organizations/test_retrieve.py @@ -1,6 +1,7 @@ """ Test suite for Organization retrieve API endpoint. """ + from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/core/api/organizations/test_update.py b/src/backend/joanie/tests/core/api/organizations/test_update.py index 4f49f3e93..bee7fe436 100644 --- a/src/backend/joanie/tests/core/api/organizations/test_update.py +++ b/src/backend/joanie/tests/core/api/organizations/test_update.py @@ -1,6 +1,7 @@ """ Test suite for Organization update API endpoint. """ + import random from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/api/remote_endpoints/course_run/test_course_run.py b/src/backend/joanie/tests/core/api/remote_endpoints/course_run/test_course_run.py index 35fb95992..ef3caf051 100644 --- a/src/backend/joanie/tests/core/api/remote_endpoints/course_run/test_course_run.py +++ b/src/backend/joanie/tests/core/api/remote_endpoints/course_run/test_course_run.py @@ -1,4 +1,5 @@ """Test suite for remote API endpoints on course run.""" + from datetime import timedelta from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/debug/test_debug_urls_template_preview.py b/src/backend/joanie/tests/core/debug/test_debug_urls_template_preview.py index bb9495582..8ea922afd 100644 --- a/src/backend/joanie/tests/core/debug/test_debug_urls_template_preview.py +++ b/src/backend/joanie/tests/core/debug/test_debug_urls_template_preview.py @@ -7,6 +7,7 @@ If we don't create two distinct classes, the reload of urls configuration were not reflecting the DEBUG setting value, and some routes were available when they should not be. """ + from http import HTTPStatus from django.core.cache import cache diff --git a/src/backend/joanie/tests/core/test_admin_course.py b/src/backend/joanie/tests/core/test_admin_course.py index a9649dc7b..aac6d36e5 100644 --- a/src/backend/joanie/tests/core/test_admin_course.py +++ b/src/backend/joanie/tests/core/test_admin_course.py @@ -1,6 +1,7 @@ """ Test suite for courses admin pages """ + from http import HTTPStatus from django.conf import settings diff --git a/src/backend/joanie/tests/core/test_admin_order.py b/src/backend/joanie/tests/core/test_admin_order.py index 2bb6d5f7b..ff07ae051 100644 --- a/src/backend/joanie/tests/core/test_admin_order.py +++ b/src/backend/joanie/tests/core/test_admin_order.py @@ -1,6 +1,7 @@ """ Test suite for orders admin pages """ + from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/core/test_admin_product.py b/src/backend/joanie/tests/core/test_admin_product.py index 420d519b2..cf4d41866 100644 --- a/src/backend/joanie/tests/core/test_admin_product.py +++ b/src/backend/joanie/tests/core/test_admin_product.py @@ -1,6 +1,7 @@ """ Test suite for products admin pages """ + import random import uuid from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/test_api_address.py b/src/backend/joanie/tests/core/test_api_address.py index 644de1a37..ea87fcc8c 100644 --- a/src/backend/joanie/tests/core/test_api_address.py +++ b/src/backend/joanie/tests/core/test_api_address.py @@ -1,6 +1,7 @@ """ Test suite for addresses API """ + import json import uuid from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/test_api_admin_certificate_definitions.py b/src/backend/joanie/tests/core/test_api_admin_certificate_definitions.py index 7ea989953..0bb48efca 100644 --- a/src/backend/joanie/tests/core/test_api_admin_certificate_definitions.py +++ b/src/backend/joanie/tests/core/test_api_admin_certificate_definitions.py @@ -1,6 +1,7 @@ """ Test suite for Certificate definition Admin API. """ + import random from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/test_api_admin_contract_definitions.py b/src/backend/joanie/tests/core/test_api_admin_contract_definitions.py index fa473eb22..62e47a3e5 100644 --- a/src/backend/joanie/tests/core/test_api_admin_contract_definitions.py +++ b/src/backend/joanie/tests/core/test_api_admin_contract_definitions.py @@ -1,6 +1,7 @@ """ Test suite for Contract definition Admin API. """ + import random from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/test_api_admin_course_access.py b/src/backend/joanie/tests/core/test_api_admin_course_access.py index 10684a77f..ce57a44fa 100644 --- a/src/backend/joanie/tests/core/test_api_admin_course_access.py +++ b/src/backend/joanie/tests/core/test_api_admin_course_access.py @@ -1,6 +1,7 @@ """ Test suite for CourseAccess Admin API. """ + import uuid from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/test_api_admin_course_runs.py b/src/backend/joanie/tests/core/test_api_admin_course_runs.py index 7b19060ff..77c81e34a 100644 --- a/src/backend/joanie/tests/core/test_api_admin_course_runs.py +++ b/src/backend/joanie/tests/core/test_api_admin_course_runs.py @@ -1,6 +1,7 @@ """ Test suite for Course run Admin API. """ + import random import uuid from datetime import datetime, timedelta, timezone diff --git a/src/backend/joanie/tests/core/test_api_admin_courses.py b/src/backend/joanie/tests/core/test_api_admin_courses.py index 3fd87a4c2..2319bc550 100644 --- a/src/backend/joanie/tests/core/test_api_admin_courses.py +++ b/src/backend/joanie/tests/core/test_api_admin_courses.py @@ -1,6 +1,7 @@ """ Test suite for Course Admin API. """ + import datetime import random import uuid diff --git a/src/backend/joanie/tests/core/test_api_admin_order_group.py b/src/backend/joanie/tests/core/test_api_admin_order_group.py index 73529d3b2..285ac7937 100644 --- a/src/backend/joanie/tests/core/test_api_admin_order_group.py +++ b/src/backend/joanie/tests/core/test_api_admin_order_group.py @@ -1,6 +1,7 @@ """ Test suite for OrderGroup Admin API. """ + from http import HTTPStatus from operator import itemgetter diff --git a/src/backend/joanie/tests/core/test_api_admin_orders.py b/src/backend/joanie/tests/core/test_api_admin_orders.py index 3a9a4a257..f58f7d243 100644 --- a/src/backend/joanie/tests/core/test_api_admin_orders.py +++ b/src/backend/joanie/tests/core/test_api_admin_orders.py @@ -1,4 +1,5 @@ """Test suite for the admin orders API endpoints.""" + import uuid from decimal import Decimal as D from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/test_api_admin_organization_access.py b/src/backend/joanie/tests/core/test_api_admin_organization_access.py index 61e7a8af1..b77bb8e02 100644 --- a/src/backend/joanie/tests/core/test_api_admin_organization_access.py +++ b/src/backend/joanie/tests/core/test_api_admin_organization_access.py @@ -1,6 +1,7 @@ """ Test suite for OrganizationAccess Admin API. """ + import uuid from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/test_api_admin_organization_addresses.py b/src/backend/joanie/tests/core/test_api_admin_organization_addresses.py index 26b388f94..a1eeffa80 100644 --- a/src/backend/joanie/tests/core/test_api_admin_organization_addresses.py +++ b/src/backend/joanie/tests/core/test_api_admin_organization_addresses.py @@ -1,6 +1,7 @@ """ Test suite for Organization Address Admin API endpoints. """ + import uuid from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/test_api_admin_organizations.py b/src/backend/joanie/tests/core/test_api_admin_organizations.py index 22595baee..5a400c47d 100755 --- a/src/backend/joanie/tests/core/test_api_admin_organizations.py +++ b/src/backend/joanie/tests/core/test_api_admin_organizations.py @@ -1,6 +1,7 @@ """ Test suite for Organization Admin API. """ + import random import re from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/test_api_admin_products.py b/src/backend/joanie/tests/core/test_api_admin_products.py index 003de0d76..32cf022d0 100644 --- a/src/backend/joanie/tests/core/test_api_admin_products.py +++ b/src/backend/joanie/tests/core/test_api_admin_products.py @@ -1,6 +1,7 @@ """ Test suite for Product Admin API. """ + import random from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/test_api_admin_users.py b/src/backend/joanie/tests/core/test_api_admin_users.py index 17a9ca899..96932ac3f 100644 --- a/src/backend/joanie/tests/core/test_api_admin_users.py +++ b/src/backend/joanie/tests/core/test_api_admin_users.py @@ -1,6 +1,7 @@ """ Test suite for User Admin API. """ + import random from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/test_api_base.py b/src/backend/joanie/tests/core/test_api_base.py index 3247dfa8f..d72cc2254 100644 --- a/src/backend/joanie/tests/core/test_api_base.py +++ b/src/backend/joanie/tests/core/test_api_base.py @@ -1,6 +1,7 @@ """ Test suite for BaseTest class """ + from datetime import datetime, timedelta from joanie.core import factories diff --git a/src/backend/joanie/tests/core/test_api_certificate.py b/src/backend/joanie/tests/core/test_api_certificate.py index 4a234acdd..6d0480291 100644 --- a/src/backend/joanie/tests/core/test_api_certificate.py +++ b/src/backend/joanie/tests/core/test_api_certificate.py @@ -1,4 +1,5 @@ """Tests for the Certificate API""" + import uuid from http import HTTPStatus from io import BytesIO diff --git a/src/backend/joanie/tests/core/test_api_contract.py b/src/backend/joanie/tests/core/test_api_contract.py index 36f2d9f78..c909af7b2 100644 --- a/src/backend/joanie/tests/core/test_api_contract.py +++ b/src/backend/joanie/tests/core/test_api_contract.py @@ -1,4 +1,5 @@ """Test suite for the Contract API""" + import json import random from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/test_api_contract_definitions.py b/src/backend/joanie/tests/core/test_api_contract_definitions.py index 4221e0085..6803e9ff8 100644 --- a/src/backend/joanie/tests/core/test_api_contract_definitions.py +++ b/src/backend/joanie/tests/core/test_api_contract_definitions.py @@ -1,6 +1,7 @@ """ Test suite for Contract Definition API. """ + from http import HTTPStatus from io import BytesIO diff --git a/src/backend/joanie/tests/core/test_api_course.py b/src/backend/joanie/tests/core/test_api_course.py index 3e921b201..17e036081 100644 --- a/src/backend/joanie/tests/core/test_api_course.py +++ b/src/backend/joanie/tests/core/test_api_course.py @@ -1,6 +1,7 @@ """ Test suite for Course API endpoint. """ + import random from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/core/test_api_course_accesses.py b/src/backend/joanie/tests/core/test_api_course_accesses.py index a16b67bfc..d444870eb 100644 --- a/src/backend/joanie/tests/core/test_api_course_accesses.py +++ b/src/backend/joanie/tests/core/test_api_course_accesses.py @@ -1,6 +1,7 @@ """ Tests course access API endpoints in Joanie's core app. """ + import random from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/core/test_api_course_product_relations.py b/src/backend/joanie/tests/core/test_api_course_product_relations.py index fdac4647a..07f65e8fc 100644 --- a/src/backend/joanie/tests/core/test_api_course_product_relations.py +++ b/src/backend/joanie/tests/core/test_api_course_product_relations.py @@ -1,5 +1,6 @@ # pylint: disable=too-many-lines """Test suite for the Course Product Relation API.""" + import random import uuid from http import HTTPStatus diff --git a/src/backend/joanie/tests/core/test_api_course_run.py b/src/backend/joanie/tests/core/test_api_course_run.py index d4127503a..b56187c93 100644 --- a/src/backend/joanie/tests/core/test_api_course_run.py +++ b/src/backend/joanie/tests/core/test_api_course_run.py @@ -1,4 +1,5 @@ """Test suite for the CourseRun API""" + from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/core/test_api_course_wishes.py b/src/backend/joanie/tests/core/test_api_course_wishes.py index 0fb1bd20e..3a1008ff7 100644 --- a/src/backend/joanie/tests/core/test_api_course_wishes.py +++ b/src/backend/joanie/tests/core/test_api_course_wishes.py @@ -1,6 +1,7 @@ """ Test suite for wish API """ + from http import HTTPStatus import arrow diff --git a/src/backend/joanie/tests/core/test_api_courses_contract.py b/src/backend/joanie/tests/core/test_api_courses_contract.py index 67fd9b813..9525bad73 100644 --- a/src/backend/joanie/tests/core/test_api_courses_contract.py +++ b/src/backend/joanie/tests/core/test_api_courses_contract.py @@ -1,5 +1,6 @@ # pylint: disable=duplicate-code """Test suite for the Courses Contract API""" + from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/core/test_api_courses_order.py b/src/backend/joanie/tests/core/test_api_courses_order.py index 2b96956ef..00b011696 100644 --- a/src/backend/joanie/tests/core/test_api_courses_order.py +++ b/src/backend/joanie/tests/core/test_api_courses_order.py @@ -1,4 +1,5 @@ """Test suite for nested Order viewset on Courses""" + from http import HTTPStatus from uuid import uuid4 diff --git a/src/backend/joanie/tests/core/test_api_enrollment.py b/src/backend/joanie/tests/core/test_api_enrollment.py index 3cc9b7ba7..1a202379e 100644 --- a/src/backend/joanie/tests/core/test_api_enrollment.py +++ b/src/backend/joanie/tests/core/test_api_enrollment.py @@ -1,4 +1,5 @@ """Tests for the Enrollment API.""" + # pylint: disable=too-many-lines import itertools import json diff --git a/src/backend/joanie/tests/core/test_api_users.py b/src/backend/joanie/tests/core/test_api_users.py index 75d940430..2cfbe2e59 100644 --- a/src/backend/joanie/tests/core/test_api_users.py +++ b/src/backend/joanie/tests/core/test_api_users.py @@ -1,6 +1,7 @@ """ Test suite for User API. """ + from http import HTTPStatus from joanie.core import factories diff --git a/src/backend/joanie/tests/core/test_authentication_delegated_jwt_authentication.py b/src/backend/joanie/tests/core/test_authentication_delegated_jwt_authentication.py index 5758cb510..5cebf3d2c 100644 --- a/src/backend/joanie/tests/core/test_authentication_delegated_jwt_authentication.py +++ b/src/backend/joanie/tests/core/test_authentication_delegated_jwt_authentication.py @@ -1,6 +1,7 @@ """ Unit tests for the DelegatedJWTAuthentication backend. """ + from joanie.core import factories, models from joanie.core.authentication import DelegatedJWTAuthentication from joanie.tests.base import BaseAPITestCase diff --git a/src/backend/joanie/tests/core/test_commands_generate_certificates.py b/src/backend/joanie/tests/core/test_commands_generate_certificates.py index 1e1d0ce83..6eb556319 100644 --- a/src/backend/joanie/tests/core/test_commands_generate_certificates.py +++ b/src/backend/joanie/tests/core/test_commands_generate_certificates.py @@ -1,4 +1,5 @@ """Test suite for the management command 'generate_certificates'""" + import uuid from django.core.management import call_command diff --git a/src/backend/joanie/tests/core/test_commands_synchronize_course_runs.py b/src/backend/joanie/tests/core/test_commands_synchronize_course_runs.py index 41a10cd56..c4b594685 100644 --- a/src/backend/joanie/tests/core/test_commands_synchronize_course_runs.py +++ b/src/backend/joanie/tests/core/test_commands_synchronize_course_runs.py @@ -1,4 +1,5 @@ """Test suite for the management command `synchronize_course_runs`.""" + import random import uuid from unittest import mock diff --git a/src/backend/joanie/tests/core/test_factories_course_run.py b/src/backend/joanie/tests/core/test_factories_course_run.py index a00a49fec..3e2ec63f6 100644 --- a/src/backend/joanie/tests/core/test_factories_course_run.py +++ b/src/backend/joanie/tests/core/test_factories_course_run.py @@ -1,4 +1,5 @@ """Test suite for the CourseRunFactory.""" + import random from datetime import timedelta diff --git a/src/backend/joanie/tests/core/test_fields_iso8601_duration_field.py b/src/backend/joanie/tests/core/test_fields_iso8601_duration_field.py index a973da318..cc303161a 100644 --- a/src/backend/joanie/tests/core/test_fields_iso8601_duration_field.py +++ b/src/backend/joanie/tests/core/test_fields_iso8601_duration_field.py @@ -1,4 +1,5 @@ """Test suite for the ISO8601DurationField for serializers""" + from datetime import timedelta from django.test import TestCase diff --git a/src/backend/joanie/tests/core/test_helpers.py b/src/backend/joanie/tests/core/test_helpers.py index 4d68ee914..4c47d4e0c 100644 --- a/src/backend/joanie/tests/core/test_helpers.py +++ b/src/backend/joanie/tests/core/test_helpers.py @@ -1,4 +1,5 @@ """Joanie core helpers tests suite""" + from unittest import mock from django.test.testcases import TestCase diff --git a/src/backend/joanie/tests/core/test_models_address.py b/src/backend/joanie/tests/core/test_models_address.py index fe2e1b7c1..4c393e62c 100644 --- a/src/backend/joanie/tests/core/test_models_address.py +++ b/src/backend/joanie/tests/core/test_models_address.py @@ -1,6 +1,7 @@ """ Test suite for accounts models for users and organizations. """ + from django.core.exceptions import ValidationError from django.db import IntegrityError from django.test import TestCase diff --git a/src/backend/joanie/tests/core/test_models_certificate.py b/src/backend/joanie/tests/core/test_models_certificate.py index bf76d28d0..47017b5f0 100644 --- a/src/backend/joanie/tests/core/test_models_certificate.py +++ b/src/backend/joanie/tests/core/test_models_certificate.py @@ -1,4 +1,5 @@ """Test suite for Certificate Model""" + from django.conf import settings from django.test import TestCase diff --git a/src/backend/joanie/tests/core/test_models_contract.py b/src/backend/joanie/tests/core/test_models_contract.py index 278397a89..4c391c429 100644 --- a/src/backend/joanie/tests/core/test_models_contract.py +++ b/src/backend/joanie/tests/core/test_models_contract.py @@ -1,4 +1,5 @@ """Tests for the Contract Model""" + from datetime import datetime, timedelta from zoneinfo import ZoneInfo diff --git a/src/backend/joanie/tests/core/test_models_contract_definition.py b/src/backend/joanie/tests/core/test_models_contract_definition.py index 8efa9ac39..fff1e901e 100644 --- a/src/backend/joanie/tests/core/test_models_contract_definition.py +++ b/src/backend/joanie/tests/core/test_models_contract_definition.py @@ -1,4 +1,5 @@ """Tests for the Contract Definition Model""" + from django.test import TestCase from joanie.core import factories diff --git a/src/backend/joanie/tests/core/test_models_course.py b/src/backend/joanie/tests/core/test_models_course.py index 7197f9596..9ada6244e 100644 --- a/src/backend/joanie/tests/core/test_models_course.py +++ b/src/backend/joanie/tests/core/test_models_course.py @@ -1,6 +1,7 @@ """ Test suite for course models """ + from datetime import timedelta from django.contrib.auth.models import AnonymousUser diff --git a/src/backend/joanie/tests/core/test_models_course_access.py b/src/backend/joanie/tests/core/test_models_course_access.py index f5a050493..a8f4cfa7c 100644 --- a/src/backend/joanie/tests/core/test_models_course_access.py +++ b/src/backend/joanie/tests/core/test_models_course_access.py @@ -1,6 +1,7 @@ """ Test suite for course access models """ + from django.contrib.auth.models import AnonymousUser from django.core.exceptions import ValidationError diff --git a/src/backend/joanie/tests/core/test_models_course_product_relation.py b/src/backend/joanie/tests/core/test_models_course_product_relation.py index ce8da2be4..e30141bd6 100644 --- a/src/backend/joanie/tests/core/test_models_course_product_relation.py +++ b/src/backend/joanie/tests/core/test_models_course_product_relation.py @@ -1,6 +1,7 @@ """ Test suite for CourseProductRelation model """ + from django.test import TestCase from joanie.core import factories diff --git a/src/backend/joanie/tests/core/test_models_course_run.py b/src/backend/joanie/tests/core/test_models_course_run.py index 6a57d99e9..207105725 100644 --- a/src/backend/joanie/tests/core/test_models_course_run.py +++ b/src/backend/joanie/tests/core/test_models_course_run.py @@ -1,6 +1,7 @@ """ Test suite for order models """ + import random from datetime import datetime, timedelta, timezone from unittest import mock diff --git a/src/backend/joanie/tests/core/test_models_enrollment.py b/src/backend/joanie/tests/core/test_models_enrollment.py index 4db2ae905..3e08b2e86 100644 --- a/src/backend/joanie/tests/core/test_models_enrollment.py +++ b/src/backend/joanie/tests/core/test_models_enrollment.py @@ -1,6 +1,7 @@ """ Test suite for enrollment models """ + from datetime import timedelta from unittest import mock diff --git a/src/backend/joanie/tests/core/test_models_order.py b/src/backend/joanie/tests/core/test_models_order.py index 8643f2d96..93627bb6f 100644 --- a/src/backend/joanie/tests/core/test_models_order.py +++ b/src/backend/joanie/tests/core/test_models_order.py @@ -1,6 +1,7 @@ """ Test suite for order models """ + # pylint: disable=too-many-lines,too-many-public-methods import json import random @@ -1253,9 +1254,10 @@ def test_models_order_submit_for_signature_fails_when_the_product_has_no_contrac product=factories.ProductFactory(contract_definition=None), ) - with self.assertRaises(ValidationError) as context, self.assertLogs( - "joanie" - ) as logger: + with ( + self.assertRaises(ValidationError) as context, + self.assertLogs("joanie") as logger, + ): order.submit_for_signature(user=user) self.assertEqual( @@ -1296,9 +1298,10 @@ def test_models_order_submit_for_signature_fails_because_order_is_not_state_vali product__contract_definition=factories.ContractDefinitionFactory(), ) - with self.assertRaises(ValidationError) as context, self.assertLogs( - "joanie" - ) as logger: + with ( + self.assertRaises(ValidationError) as context, + self.assertLogs("joanie") as logger, + ): order.submit_for_signature(user=user) self.assertEqual( @@ -1530,9 +1533,10 @@ def test_models_order_submit_for_signature_but_contract_is_already_signed_should organization_signed_on=now, ) - with self.assertRaises(PermissionDenied) as context, self.assertLogs( - "joanie" - ) as logger: + with ( + self.assertRaises(PermissionDenied) as context, + self.assertLogs("joanie") as logger, + ): order.submit_for_signature(user=user) self.assertEqual( diff --git a/src/backend/joanie/tests/core/test_models_order_enroll_user_to_course_run.py b/src/backend/joanie/tests/core/test_models_order_enroll_user_to_course_run.py index 2c90c0e71..6383567e4 100644 --- a/src/backend/joanie/tests/core/test_models_order_enroll_user_to_course_run.py +++ b/src/backend/joanie/tests/core/test_models_order_enroll_user_to_course_run.py @@ -1,6 +1,7 @@ """ Test suite the `enroll_user_to_course_run` method on Order model """ + import random from django.test import RequestFactory, TestCase diff --git a/src/backend/joanie/tests/core/test_models_order_get_or_generate_certificate_for_certificate_product.py b/src/backend/joanie/tests/core/test_models_order_get_or_generate_certificate_for_certificate_product.py index 0f47d2b52..798d6d1a2 100644 --- a/src/backend/joanie/tests/core/test_models_order_get_or_generate_certificate_for_certificate_product.py +++ b/src/backend/joanie/tests/core/test_models_order_get_or_generate_certificate_for_certificate_product.py @@ -1,6 +1,7 @@ """ Test suite for order models: `get_or_generate_certificate` method for a certificate product """ + from datetime import timedelta from unittest import mock diff --git a/src/backend/joanie/tests/core/test_models_order_get_or_generate_certificate_for_credential_product.py b/src/backend/joanie/tests/core/test_models_order_get_or_generate_certificate_for_credential_product.py index d7640d3b8..14826f28f 100644 --- a/src/backend/joanie/tests/core/test_models_order_get_or_generate_certificate_for_credential_product.py +++ b/src/backend/joanie/tests/core/test_models_order_get_or_generate_certificate_for_credential_product.py @@ -1,6 +1,7 @@ """ Test suite for order models: `get_or_generate_certificate` method for a credential product """ + from datetime import timedelta from unittest import mock diff --git a/src/backend/joanie/tests/core/test_models_order_get_or_generate_certificate_for_enrollment_product.py b/src/backend/joanie/tests/core/test_models_order_get_or_generate_certificate_for_enrollment_product.py index aa36c8f8e..f70e5db8c 100644 --- a/src/backend/joanie/tests/core/test_models_order_get_or_generate_certificate_for_enrollment_product.py +++ b/src/backend/joanie/tests/core/test_models_order_get_or_generate_certificate_for_enrollment_product.py @@ -1,6 +1,7 @@ """ Test suite for order model: `get_or_generate_certificate` method for an enrollment product """ + from datetime import timedelta from django.test import TestCase diff --git a/src/backend/joanie/tests/core/test_models_order_group.py b/src/backend/joanie/tests/core/test_models_order_group.py index 8d431ab5d..803fa6162 100644 --- a/src/backend/joanie/tests/core/test_models_order_group.py +++ b/src/backend/joanie/tests/core/test_models_order_group.py @@ -1,6 +1,7 @@ """ Test suite for OrderGroup model """ + from django.test import TestCase from joanie.core import factories diff --git a/src/backend/joanie/tests/core/test_models_organization.py b/src/backend/joanie/tests/core/test_models_organization.py index 5f6d74ac9..0700c2d37 100644 --- a/src/backend/joanie/tests/core/test_models_organization.py +++ b/src/backend/joanie/tests/core/test_models_organization.py @@ -1,6 +1,7 @@ """ Test suite for organization models """ + import uuid from django.contrib.auth.models import AnonymousUser diff --git a/src/backend/joanie/tests/core/test_models_organization_access.py b/src/backend/joanie/tests/core/test_models_organization_access.py index ea0ae2297..d3b266240 100644 --- a/src/backend/joanie/tests/core/test_models_organization_access.py +++ b/src/backend/joanie/tests/core/test_models_organization_access.py @@ -1,6 +1,7 @@ """ Test suite for organization access models """ + from django.contrib.auth.models import AnonymousUser from django.core.exceptions import ValidationError diff --git a/src/backend/joanie/tests/core/test_models_product.py b/src/backend/joanie/tests/core/test_models_product.py index 78b449600..aecca271f 100644 --- a/src/backend/joanie/tests/core/test_models_product.py +++ b/src/backend/joanie/tests/core/test_models_product.py @@ -1,6 +1,7 @@ """ Test suite for products models """ + import random from datetime import datetime, timedelta, timezone from decimal import Decimal as D diff --git a/src/backend/joanie/tests/core/test_models_product_get_cache_key.py b/src/backend/joanie/tests/core/test_models_product_get_cache_key.py index 13f283ba3..5316b7ac9 100644 --- a/src/backend/joanie/tests/core/test_models_product_get_cache_key.py +++ b/src/backend/joanie/tests/core/test_models_product_get_cache_key.py @@ -1,4 +1,5 @@ """Product model 'get_cache_key' test suite""" + from datetime import datetime from unittest import mock diff --git a/src/backend/joanie/tests/core/test_models_site_config.py b/src/backend/joanie/tests/core/test_models_site_config.py index bb9a70d09..28a2d9817 100644 --- a/src/backend/joanie/tests/core/test_models_site_config.py +++ b/src/backend/joanie/tests/core/test_models_site_config.py @@ -1,4 +1,5 @@ """Test suite for the SiteConfig model.""" + from django.test import TestCase from joanie.core.factories import SiteConfigFactory diff --git a/src/backend/joanie/tests/core/test_models_user.py b/src/backend/joanie/tests/core/test_models_user.py index 8cd80e0b5..84c9f2776 100644 --- a/src/backend/joanie/tests/core/test_models_user.py +++ b/src/backend/joanie/tests/core/test_models_user.py @@ -1,4 +1,5 @@ """Test suite for badge models.""" + from django.core.exceptions import ValidationError from django.test.utils import override_settings diff --git a/src/backend/joanie/tests/core/test_serializers_cached_model_serializer.py b/src/backend/joanie/tests/core/test_serializers_cached_model_serializer.py index cfb00f344..27e59feb3 100644 --- a/src/backend/joanie/tests/core/test_serializers_cached_model_serializer.py +++ b/src/backend/joanie/tests/core/test_serializers_cached_model_serializer.py @@ -1,4 +1,5 @@ """Tests for the CachedModelSerializer class.""" + from django.test import TestCase, override_settings from joanie.core import factories, models diff --git a/src/backend/joanie/tests/core/test_serializers_course_access.py b/src/backend/joanie/tests/core/test_serializers_course_access.py index 7081e9b2d..af8c98e12 100644 --- a/src/backend/joanie/tests/core/test_serializers_course_access.py +++ b/src/backend/joanie/tests/core/test_serializers_course_access.py @@ -1,4 +1,5 @@ """Test suite for the course access serializer""" + import random from django.test import TestCase diff --git a/src/backend/joanie/tests/core/test_serializers_organization_access.py b/src/backend/joanie/tests/core/test_serializers_organization_access.py index 46a3e28b7..00780ef5c 100644 --- a/src/backend/joanie/tests/core/test_serializers_organization_access.py +++ b/src/backend/joanie/tests/core/test_serializers_organization_access.py @@ -1,4 +1,5 @@ """Test suite for the organization access serializer""" + import random from django.test import TestCase diff --git a/src/backend/joanie/tests/core/test_settings.py b/src/backend/joanie/tests/core/test_settings.py index 8d5f5c8ec..cdd4ba53c 100644 --- a/src/backend/joanie/tests/core/test_settings.py +++ b/src/backend/joanie/tests/core/test_settings.py @@ -1,6 +1,7 @@ """ Test suite for Joanie's main module """ + from unittest import mock from django.test import TestCase diff --git a/src/backend/joanie/tests/core/test_signals.py b/src/backend/joanie/tests/core/test_signals.py index 004474772..a6f5c2ac3 100644 --- a/src/backend/joanie/tests/core/test_signals.py +++ b/src/backend/joanie/tests/core/test_signals.py @@ -1,4 +1,5 @@ """Joanie core helpers tests suite""" + import random from datetime import datetime from unittest import mock diff --git a/src/backend/joanie/tests/core/test_templatetags_extra_tags.py b/src/backend/joanie/tests/core/test_templatetags_extra_tags.py index e532db9f4..9ee64bfd3 100644 --- a/src/backend/joanie/tests/core/test_templatetags_extra_tags.py +++ b/src/backend/joanie/tests/core/test_templatetags_extra_tags.py @@ -1,6 +1,7 @@ """ Test suite for extra template tags of the joanie core app """ + import random from django.test import TestCase diff --git a/src/backend/joanie/tests/core/test_utils_contract.py b/src/backend/joanie/tests/core/test_utils_contract.py index 4ea1e7b22..0d655f7c1 100644 --- a/src/backend/joanie/tests/core/test_utils_contract.py +++ b/src/backend/joanie/tests/core/test_utils_contract.py @@ -1,4 +1,5 @@ """Test suite to generate a ZIP archive of signed contract PDF files in bytes utility""" + import random from io import BytesIO from uuid import uuid4 diff --git a/src/backend/joanie/tests/core/test_utils_contract_definition_generate_document_context.py b/src/backend/joanie/tests/core/test_utils_contract_definition_generate_document_context.py index 36d9286eb..203d4d736 100644 --- a/src/backend/joanie/tests/core/test_utils_contract_definition_generate_document_context.py +++ b/src/backend/joanie/tests/core/test_utils_contract_definition_generate_document_context.py @@ -1,4 +1,5 @@ """Test suite for `generate_document_context` utility""" + from django.contrib.sites.models import Site from django.test import TestCase diff --git a/src/backend/joanie/tests/core/test_utils_course_run.py b/src/backend/joanie/tests/core/test_utils_course_run.py index 0feb91f7b..a176f1fc8 100644 --- a/src/backend/joanie/tests/core/test_utils_course_run.py +++ b/src/backend/joanie/tests/core/test_utils_course_run.py @@ -1,4 +1,5 @@ """Test suite for course run utility methods.""" + from datetime import timedelta from django.core.exceptions import ValidationError diff --git a/src/backend/joanie/tests/core/test_utils_image_to_base64.py b/src/backend/joanie/tests/core/test_utils_image_to_base64.py index d4d842c75..d3b05d0cd 100644 --- a/src/backend/joanie/tests/core/test_utils_image_to_base64.py +++ b/src/backend/joanie/tests/core/test_utils_image_to_base64.py @@ -1,6 +1,7 @@ """ Test suite for utils of the joanie core app """ + import io from django.test import TestCase, override_settings diff --git a/src/backend/joanie/tests/core/test_utils_issuers_certificate_and_degree_generate_document.py b/src/backend/joanie/tests/core/test_utils_issuers_certificate_and_degree_generate_document.py index a99af65b5..9b5ffb17a 100644 --- a/src/backend/joanie/tests/core/test_utils_issuers_certificate_and_degree_generate_document.py +++ b/src/backend/joanie/tests/core/test_utils_issuers_certificate_and_degree_generate_document.py @@ -1,4 +1,5 @@ """Test suite for utility method to generate document of Certificate/Degree in PDF bytes format.""" + from io import BytesIO from django.test import TestCase diff --git a/src/backend/joanie/tests/core/test_utils_issuers_contract_definition_generate_document.py b/src/backend/joanie/tests/core/test_utils_issuers_contract_definition_generate_document.py index 7c9e43a88..09d6a0b4c 100644 --- a/src/backend/joanie/tests/core/test_utils_issuers_contract_definition_generate_document.py +++ b/src/backend/joanie/tests/core/test_utils_issuers_contract_definition_generate_document.py @@ -1,4 +1,5 @@ """Test suite for utility method to generate document of Contract Definition in PDF bytes format""" + from io import BytesIO from django.contrib.sites.models import Site diff --git a/src/backend/joanie/tests/core/test_utils_issuers_generate_document.py b/src/backend/joanie/tests/core/test_utils_issuers_generate_document.py index 2a61edf8e..0e8c87e01 100644 --- a/src/backend/joanie/tests/core/test_utils_issuers_generate_document.py +++ b/src/backend/joanie/tests/core/test_utils_issuers_generate_document.py @@ -1,4 +1,5 @@ """Test suite for `generate_document` utility""" + import textwrap from io import BytesIO diff --git a/src/backend/joanie/tests/core/test_utils_issuers_invoice_generate_document.py b/src/backend/joanie/tests/core/test_utils_issuers_invoice_generate_document.py index d6664515d..ee147b1e0 100644 --- a/src/backend/joanie/tests/core/test_utils_issuers_invoice_generate_document.py +++ b/src/backend/joanie/tests/core/test_utils_issuers_invoice_generate_document.py @@ -1,4 +1,5 @@ """Test suite for utility method to generate an invoice in PDF bytes format.""" + from io import BytesIO from django.test import TestCase diff --git a/src/backend/joanie/tests/core/test_utils_webhooks_synchronize_course_runs.py b/src/backend/joanie/tests/core/test_utils_webhooks_synchronize_course_runs.py index 8d3a436ef..9307056bf 100644 --- a/src/backend/joanie/tests/core/test_utils_webhooks_synchronize_course_runs.py +++ b/src/backend/joanie/tests/core/test_utils_webhooks_synchronize_course_runs.py @@ -1,6 +1,7 @@ """ Test suite for the "synchronize_course_runs" utility """ + import json import random import re @@ -40,11 +41,14 @@ def test_utils_synchronize_course_runs_no_hooks(self): def test_utils_synchronize_course_runs_no_course_runs(self): """If no course runs are passed as arguments, the method should not make any request.""" - with override_settings( - COURSE_WEB_HOOKS=[ - {"url": "http://richie.education/webhook", "secret": "abc"}, - ] - ), responses.RequestsMock(): + with ( + override_settings( + COURSE_WEB_HOOKS=[ + {"url": "http://richie.education/webhook", "secret": "abc"}, + ] + ), + responses.RequestsMock(), + ): webhooks.synchronize_course_runs([]) self.assertEqual(len(responses.calls), 0) @@ -52,12 +56,15 @@ def test_utils_synchronize_course_runs_no_course_runs(self): @mock.patch.object(Logger, "info") def test_utils_synchronize_course_runs_success(self, mock_info): """Course runs passed to the function should get synchronized.""" - with override_settings( - COURSE_WEB_HOOKS=[ - {"url": "http://richie.education/webhook1", "secret": "abc"}, - {"url": "http://richie.education/webhook2", "secret": "abc"}, - ] - ), responses.RequestsMock() as rsps: + with ( + override_settings( + COURSE_WEB_HOOKS=[ + {"url": "http://richie.education/webhook1", "secret": "abc"}, + {"url": "http://richie.education/webhook2", "secret": "abc"}, + ] + ), + responses.RequestsMock() as rsps, + ): # Ensure successful response by webhook using "responses": rsp = rsps.post( re.compile("http://richie.education/webhook{1}"), @@ -137,11 +144,14 @@ def test_utils_synchronize_course_runs_success(self, mock_info): @mock.patch.object(Logger, "error") def test_utils_synchronize_course_runs_failure(self, mock_error): """The logger should be called on webhook call failure.""" - with override_settings( - COURSE_WEB_HOOKS=[ - {"url": "http://richie.education/webhook", "secret": "abc"}, - ] - ), responses.RequestsMock() as rsps: + with ( + override_settings( + COURSE_WEB_HOOKS=[ + {"url": "http://richie.education/webhook", "secret": "abc"}, + ] + ), + responses.RequestsMock() as rsps, + ): # Simulate webhook failure using "responses": rsp = rsps.post( re.compile("http://richie.education/webhook"), @@ -213,13 +223,16 @@ def test_utils_synchronize_course_runs_retries(self, mock_info, mock_error): "course": "1", }, ] - with override_settings( - COURSE_WEB_HOOKS=[ - {"url": "http://richie.education/webhook", "secret": "abc"}, - ] - ), responses.RequestsMock( - registry=responses.registries.OrderedRegistry - ) as rsps: + with ( + override_settings( + COURSE_WEB_HOOKS=[ + {"url": "http://richie.education/webhook", "secret": "abc"}, + ] + ), + responses.RequestsMock( + registry=responses.registries.OrderedRegistry + ) as rsps, + ): # Make webhook fail 3 times before succeeding using "responses" url = "http://richie.education/webhook" all_rsps = [ @@ -253,11 +266,14 @@ def test_utils_synchronize_course_runs_retries(self, mock_info, mock_error): @mock.patch.object(Logger, "error") def test_utils_synchronize_course_runs_max_retries_exceeded(self, mock_error): """Course runs synchronization supports retries has exceeded max retries.""" - with override_settings( - COURSE_WEB_HOOKS=[ - {"url": "http://richie.education/webhook", "secret": "abc"}, - ] - ), responses.RequestsMock() as rsps: + with ( + override_settings( + COURSE_WEB_HOOKS=[ + {"url": "http://richie.education/webhook", "secret": "abc"}, + ] + ), + responses.RequestsMock() as rsps, + ): # Simulate webhook failure using "responses": rsp = rsps.post( re.compile("http://richie.education/webhook"), diff --git a/src/backend/joanie/tests/core/test_views_backoffice_redirect.py b/src/backend/joanie/tests/core/test_views_backoffice_redirect.py index 794e638a7..b887a30f8 100644 --- a/src/backend/joanie/tests/core/test_views_backoffice_redirect.py +++ b/src/backend/joanie/tests/core/test_views_backoffice_redirect.py @@ -1,4 +1,5 @@ """BackOfficeRedirectView test suite.""" + from http import HTTPStatus from django.test import TestCase, override_settings diff --git a/src/backend/joanie/tests/core/test_views_certificate_verify.py b/src/backend/joanie/tests/core/test_views_certificate_verify.py index 70e5220f3..ec78a0690 100644 --- a/src/backend/joanie/tests/core/test_views_certificate_verify.py +++ b/src/backend/joanie/tests/core/test_views_certificate_verify.py @@ -1,4 +1,5 @@ """CertificateVerificationView test suite.""" + import uuid from http import HTTPStatus diff --git a/src/backend/joanie/tests/demo/test_commands_create_demo.py b/src/backend/joanie/tests/demo/test_commands_create_demo.py index b2cea592e..f2d6f7038 100644 --- a/src/backend/joanie/tests/demo/test_commands_create_demo.py +++ b/src/backend/joanie/tests/demo/test_commands_create_demo.py @@ -1,4 +1,5 @@ """Test suite for the management command 'create_demo'""" + from unittest import mock from django.core.management import call_command diff --git a/src/backend/joanie/tests/demo/test_commands_create_dev_demo.py b/src/backend/joanie/tests/demo/test_commands_create_dev_demo.py index af26daf25..4d60fecc7 100644 --- a/src/backend/joanie/tests/demo/test_commands_create_dev_demo.py +++ b/src/backend/joanie/tests/demo/test_commands_create_dev_demo.py @@ -1,4 +1,5 @@ """Test suite for the management command 'create_demo'""" + from django.core.management import call_command from django.test import TestCase from django.test.utils import override_settings diff --git a/src/backend/joanie/tests/edx_imports/base_test_commands_migrate.py b/src/backend/joanie/tests/edx_imports/base_test_commands_migrate.py index 809b82d13..b0a7abb27 100644 --- a/src/backend/joanie/tests/edx_imports/base_test_commands_migrate.py +++ b/src/backend/joanie/tests/edx_imports/base_test_commands_migrate.py @@ -1,4 +1,5 @@ """Base test case for the migrate command.""" + from django.test import TestCase, override_settings from joanie.edx_imports.edx_factories import session diff --git a/src/backend/joanie/tests/edx_imports/test_commands_migrate_course_runs.py b/src/backend/joanie/tests/edx_imports/test_commands_migrate_course_runs.py index 0bb311f9a..466ca6bb5 100644 --- a/src/backend/joanie/tests/edx_imports/test_commands_migrate_course_runs.py +++ b/src/backend/joanie/tests/edx_imports/test_commands_migrate_course_runs.py @@ -1,4 +1,5 @@ """Tests for the migrate_edx command to import course runs from Open edX.""" + from unittest.mock import patch from django.core.management import call_command diff --git a/src/backend/joanie/tests/edx_imports/test_edx_database.py b/src/backend/joanie/tests/edx_imports/test_edx_database.py index 19dad140c..612ea242a 100644 --- a/src/backend/joanie/tests/edx_imports/test_edx_database.py +++ b/src/backend/joanie/tests/edx_imports/test_edx_database.py @@ -1,4 +1,5 @@ """Module for testing the Open edX database class.""" + from django.test import TestCase from joanie.edx_imports.edx_database import OpenEdxDB diff --git a/src/backend/joanie/tests/edx_imports/test_edx_mongodb.py b/src/backend/joanie/tests/edx_imports/test_edx_mongodb.py index 1a910f5c3..820b9d65b 100644 --- a/src/backend/joanie/tests/edx_imports/test_edx_mongodb.py +++ b/src/backend/joanie/tests/edx_imports/test_edx_mongodb.py @@ -1,4 +1,5 @@ """Module for testing the edx_mongodb module.""" + from unittest.mock import MagicMock, patch from django.test import TestCase diff --git a/src/backend/joanie/tests/lms_handler/test_api_course_run_sync_edx.py b/src/backend/joanie/tests/lms_handler/test_api_course_run_sync_edx.py index 9a214daa9..1f1d37e83 100644 --- a/src/backend/joanie/tests/lms_handler/test_api_course_run_sync_edx.py +++ b/src/backend/joanie/tests/lms_handler/test_api_course_run_sync_edx.py @@ -1,6 +1,7 @@ """ Tests for CourseRun web hook. """ + import json from http import HTTPStatus diff --git a/src/backend/joanie/tests/lms_handler/test_backend_dummy.py b/src/backend/joanie/tests/lms_handler/test_backend_dummy.py index fc7f090fb..9f64ad3a9 100644 --- a/src/backend/joanie/tests/lms_handler/test_backend_dummy.py +++ b/src/backend/joanie/tests/lms_handler/test_backend_dummy.py @@ -1,4 +1,5 @@ """Test suite for the Dummy LMS Backend""" + from datetime import timedelta from django.core.cache import cache diff --git a/src/backend/joanie/tests/lms_handler/test_backend_moodle.py b/src/backend/joanie/tests/lms_handler/test_backend_moodle.py index 3156e54fa..7a525dfe0 100644 --- a/src/backend/joanie/tests/lms_handler/test_backend_moodle.py +++ b/src/backend/joanie/tests/lms_handler/test_backend_moodle.py @@ -1,4 +1,5 @@ """Test suite for the Moodle LMS Backend.""" + import random from http import HTTPStatus from logging import ERROR @@ -415,9 +416,12 @@ def test_backend_moodle_create_user_error(self): status=HTTPStatus.INTERNAL_SERVER_ERROR, ) - with self.assertLogs( - "joanie.lms_handler.backends.moodle", level=ERROR - ) as error_logs, self.assertRaises(MoodleUserCreateException): + with ( + self.assertLogs( + "joanie.lms_handler.backends.moodle", level=ERROR + ) as error_logs, + self.assertRaises(MoodleUserCreateException), + ): self.backend.create_user(user) self.assertEqual( @@ -582,9 +586,12 @@ def test_backend_moodle_set_enrollment_user_error(self): status=HTTPStatus.INTERNAL_SERVER_ERROR, ) - with self.assertLogs( - "joanie.lms_handler.backends.moodle", level=ERROR - ) as error_logs, self.assertRaises(EnrollmentError): + with ( + self.assertLogs( + "joanie.lms_handler.backends.moodle", level=ERROR + ) as error_logs, + self.assertRaises(EnrollmentError), + ): self.backend.set_enrollment(enrollment) self.assertEqual( @@ -714,9 +721,12 @@ def test_backend_moodle_set_enrollment_unenroll_user_not_found(self): }, ) - with self.assertLogs( - "joanie.lms_handler.backends.moodle", level=ERROR - ) as error_logs, self.assertRaises(EnrollmentError): + with ( + self.assertLogs( + "joanie.lms_handler.backends.moodle", level=ERROR + ) as error_logs, + self.assertRaises(EnrollmentError), + ): self.backend.set_enrollment(enrollment) self.assertEqual( @@ -749,9 +759,12 @@ def test_backend_moodle_set_enrollment_student_role_error(self): status=HTTPStatus.INTERNAL_SERVER_ERROR, ) - with self.assertLogs( - "joanie.lms_handler.backends.moodle", level=ERROR - ) as error_logs, self.assertRaises(EnrollmentError): + with ( + self.assertLogs( + "joanie.lms_handler.backends.moodle", level=ERROR + ) as error_logs, + self.assertRaises(EnrollmentError), + ): self.backend.set_enrollment(enrollment) self.assertEqual( @@ -797,9 +810,12 @@ def test_backend_moodle_set_enrollment_student_role_not_found(self): ], ) - with self.assertLogs( - "joanie.lms_handler.backends.moodle", level=ERROR - ) as error_logs, self.assertRaises(EnrollmentError): + with ( + self.assertLogs( + "joanie.lms_handler.backends.moodle", level=ERROR + ) as error_logs, + self.assertRaises(EnrollmentError), + ): self.backend.set_enrollment(enrollment) self.assertEqual( @@ -864,9 +880,12 @@ def test_backend_moodle_set_enrollment_enroll_fail(self): body=RequestException("Something went wrong..."), ) - with self.assertLogs( - "joanie.lms_handler.backends.moodle", level=ERROR - ) as error_logs, self.assertRaises(EnrollmentError): + with ( + self.assertLogs( + "joanie.lms_handler.backends.moodle", level=ERROR + ) as error_logs, + self.assertRaises(EnrollmentError), + ): self.backend.set_enrollment(enrollment) self.assertEqual( @@ -934,9 +953,12 @@ def test_backend_moodle_set_enrollment_unenroll_fail(self): body=RequestException("Something went wrong..."), ) - with self.assertLogs( - "joanie.lms_handler.backends.moodle", level=ERROR - ) as error_logs, self.assertRaises(EnrollmentError): + with ( + self.assertLogs( + "joanie.lms_handler.backends.moodle", level=ERROR + ) as error_logs, + self.assertRaises(EnrollmentError), + ): self.backend.set_enrollment(enrollment) self.assertEqual( @@ -1052,9 +1074,12 @@ def test_backend_moodle_get_grades_user_error(self): status=HTTPStatus.INTERNAL_SERVER_ERROR, ) - with self.assertLogs( - "joanie.lms_handler.backends.moodle", level=ERROR - ) as error_logs, self.assertRaises(GradeError): + with ( + self.assertLogs( + "joanie.lms_handler.backends.moodle", level=ERROR + ) as error_logs, + self.assertRaises(GradeError), + ): self.backend.get_grades("student", resource_link) self.assertEqual( @@ -1091,9 +1116,12 @@ def test_backend_moodle_get_grades_user_not_found(self): }, ) - with self.assertLogs( - "joanie.lms_handler.backends.moodle", level=ERROR - ) as error_logs, self.assertRaises(GradeError): + with ( + self.assertLogs( + "joanie.lms_handler.backends.moodle", level=ERROR + ) as error_logs, + self.assertRaises(GradeError), + ): self.backend.get_grades("student", resource_link) self.assertEqual( @@ -1141,9 +1169,12 @@ def test_backend_moodle_get_grades_fail(self): body=RequestException("Something went wrong..."), ) - with self.assertLogs( - "joanie.lms_handler.backends.moodle", level=ERROR - ) as error_logs, self.assertRaises(GradeError): + with ( + self.assertLogs( + "joanie.lms_handler.backends.moodle", level=ERROR + ) as error_logs, + self.assertRaises(GradeError), + ): self.backend.get_grades("student", resource_link) self.assertEqual( diff --git a/src/backend/joanie/tests/lms_handler/test_backend_openedx.py b/src/backend/joanie/tests/lms_handler/test_backend_openedx.py index 1ac6e840e..8487a69c0 100644 --- a/src/backend/joanie/tests/lms_handler/test_backend_openedx.py +++ b/src/backend/joanie/tests/lms_handler/test_backend_openedx.py @@ -1,4 +1,5 @@ """Test suite for the OpenEdX LMS Backend.""" + import json import random from datetime import timedelta diff --git a/src/backend/joanie/tests/lms_handler/test_handler.py b/src/backend/joanie/tests/lms_handler/test_handler.py index 0f7fd699c..6bf11f571 100644 --- a/src/backend/joanie/tests/lms_handler/test_handler.py +++ b/src/backend/joanie/tests/lms_handler/test_handler.py @@ -1,4 +1,5 @@ """Test suite for the LMSHandler class.""" + from django.test import TestCase from django.test.utils import override_settings diff --git a/src/backend/joanie/tests/payment/base_payment.py b/src/backend/joanie/tests/payment/base_payment.py index 7953d7df6..ebbc0bf63 100644 --- a/src/backend/joanie/tests/payment/base_payment.py +++ b/src/backend/joanie/tests/payment/base_payment.py @@ -1,4 +1,5 @@ """Common Base Payment backend test""" + from django.core import mail from django.test import TestCase diff --git a/src/backend/joanie/tests/payment/test_admin_invoice.py b/src/backend/joanie/tests/payment/test_admin_invoice.py index c3437ae68..f38998e7d 100644 --- a/src/backend/joanie/tests/payment/test_admin_invoice.py +++ b/src/backend/joanie/tests/payment/test_admin_invoice.py @@ -1,4 +1,5 @@ """Invoice admin test suite""" + from http import HTTPStatus from django.test import TestCase diff --git a/src/backend/joanie/tests/payment/test_api_credit_card.py b/src/backend/joanie/tests/payment/test_api_credit_card.py index dac87dd5f..66c04292f 100644 --- a/src/backend/joanie/tests/payment/test_api_credit_card.py +++ b/src/backend/joanie/tests/payment/test_api_credit_card.py @@ -1,6 +1,7 @@ """ Test suite for the Credit Card API """ + from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/payment/test_api_payment.py b/src/backend/joanie/tests/payment/test_api_payment.py index a10903e6f..7f0013737 100644 --- a/src/backend/joanie/tests/payment/test_api_payment.py +++ b/src/backend/joanie/tests/payment/test_api_payment.py @@ -1,4 +1,5 @@ """Test suite for the payment api""" + from http import HTTPStatus from unittest import mock diff --git a/src/backend/joanie/tests/payment/test_backend_base.py b/src/backend/joanie/tests/payment/test_backend_base.py index 3dddeab36..a3a56f45e 100644 --- a/src/backend/joanie/tests/payment/test_backend_base.py +++ b/src/backend/joanie/tests/payment/test_backend_base.py @@ -1,4 +1,5 @@ """Test suite of the Base Payment backend""" + import smtplib from logging import Logger from unittest import mock diff --git a/src/backend/joanie/tests/payment/test_backend_dummy_payment.py b/src/backend/joanie/tests/payment/test_backend_dummy_payment.py index 529bb5200..460f1c7f9 100644 --- a/src/backend/joanie/tests/payment/test_backend_dummy_payment.py +++ b/src/backend/joanie/tests/payment/test_backend_dummy_payment.py @@ -1,4 +1,5 @@ """Test suite of the Dummy Payment backend""" + import json import re from logging import Logger diff --git a/src/backend/joanie/tests/payment/test_backend_payplug.py b/src/backend/joanie/tests/payment/test_backend_payplug.py index 9c0a43e11..b7ecbc80a 100644 --- a/src/backend/joanie/tests/payment/test_backend_payplug.py +++ b/src/backend/joanie/tests/payment/test_backend_payplug.py @@ -1,4 +1,5 @@ """Test suite of the Payplug backend""" + import re from decimal import Decimal as D from unittest import mock diff --git a/src/backend/joanie/tests/payment/test_models_invoice.py b/src/backend/joanie/tests/payment/test_models_invoice.py index efe8913bc..8d0886949 100644 --- a/src/backend/joanie/tests/payment/test_models_invoice.py +++ b/src/backend/joanie/tests/payment/test_models_invoice.py @@ -1,4 +1,5 @@ """Test suite for the Invoice model.""" + import re from decimal import Decimal as D diff --git a/src/backend/joanie/tests/payment/test_models_transaction.py b/src/backend/joanie/tests/payment/test_models_transaction.py index 3b1c23f4f..fe2c68c18 100644 --- a/src/backend/joanie/tests/payment/test_models_transaction.py +++ b/src/backend/joanie/tests/payment/test_models_transaction.py @@ -1,4 +1,5 @@ """Test suite for transaction model""" + from django.db.models import ProtectedError from django.test import TestCase diff --git a/src/backend/joanie/tests/signature/backends/lex_persona/test_delete_signing_procedure.py b/src/backend/joanie/tests/signature/backends/lex_persona/test_delete_signing_procedure.py index 4d92e8d62..3297ee770 100644 --- a/src/backend/joanie/tests/signature/backends/lex_persona/test_delete_signing_procedure.py +++ b/src/backend/joanie/tests/signature/backends/lex_persona/test_delete_signing_procedure.py @@ -1,4 +1,5 @@ """Test suite for the Lex Persona Signature Backend delete_signing_procedure""" + from http import HTTPStatus from django.test import TestCase diff --git a/src/backend/joanie/tests/signature/backends/lex_persona/test_get_signature_invitation_link.py b/src/backend/joanie/tests/signature/backends/lex_persona/test_get_signature_invitation_link.py index 3e97e3fbb..e5c97b051 100644 --- a/src/backend/joanie/tests/signature/backends/lex_persona/test_get_signature_invitation_link.py +++ b/src/backend/joanie/tests/signature/backends/lex_persona/test_get_signature_invitation_link.py @@ -1,4 +1,5 @@ """Test suite for the Lex Persona Signature Backend get_signature_invitation_link""" + from http import HTTPStatus from django.test import TestCase diff --git a/src/backend/joanie/tests/signature/backends/lex_persona/test_get_signed_file.py b/src/backend/joanie/tests/signature/backends/lex_persona/test_get_signed_file.py index d3697de4a..88a7d80f3 100644 --- a/src/backend/joanie/tests/signature/backends/lex_persona/test_get_signed_file.py +++ b/src/backend/joanie/tests/signature/backends/lex_persona/test_get_signed_file.py @@ -1,4 +1,5 @@ """Test suite for the Lex Persona Signature Backend get_signed_file""" + from http import HTTPStatus from django.core.exceptions import ValidationError diff --git a/src/backend/joanie/tests/signature/backends/lex_persona/test_handle_notification.py b/src/backend/joanie/tests/signature/backends/lex_persona/test_handle_notification.py index 5ad0657f5..1ed6d3491 100644 --- a/src/backend/joanie/tests/signature/backends/lex_persona/test_handle_notification.py +++ b/src/backend/joanie/tests/signature/backends/lex_persona/test_handle_notification.py @@ -1,4 +1,5 @@ """Test suite for the Lex Persona Signature Backend handle_notification""" + import json from datetime import datetime, timedelta from http import HTTPStatus @@ -77,9 +78,10 @@ def test_backend_lex_persona_handle_notification_workflowstarted_unsupported_eve backend = get_signature_backend() - with self.assertRaises(ValidationError) as context, self.assertLogs( - "joanie" - ) as logger: + with ( + self.assertRaises(ValidationError) as context, + self.assertLogs("joanie") as logger, + ): backend.handle_notification(request) self.assertEqual( @@ -153,9 +155,10 @@ def test_backend_lex_persona_handle_notification_workflowstopped_unsupported_eve ) backend = get_signature_backend() - with self.assertRaises(ValidationError) as context, self.assertLogs( - "joanie" - ) as logger: + with ( + self.assertRaises(ValidationError) as context, + self.assertLogs("joanie") as logger, + ): backend.handle_notification(request) self.assertEqual( @@ -197,9 +200,10 @@ def test_backend_lex_persona_handle_notification_incoming_request_body_is_an_emp request.__dict__.update(request_data) backend = get_signature_backend() - with self.assertRaises(KeyError) as context, self.assertLogs( - "joanie" - ) as logger: + with ( + self.assertRaises(KeyError) as context, + self.assertLogs("joanie") as logger, + ): backend.handle_notification(request) self.assertEqual( @@ -237,9 +241,10 @@ def test_backend_lex_persona_handle_notification_body_is_missing_id_key(self): request.__dict__.update(request_data) backend = get_signature_backend() - with self.assertRaises(KeyError) as context, self.assertLogs( - "joanie" - ) as logger: + with ( + self.assertRaises(KeyError) as context, + self.assertLogs("joanie") as logger, + ): backend.handle_notification(request) self.assertEqual( @@ -266,9 +271,10 @@ def test_backend_lex_persona_handle_notification_with_malformed_json_body(self): request.__dict__.update(request_data) backend = get_signature_backend() - with self.assertRaises(ValidationError) as context, self.assertLogs( - "joanie" - ) as logger: + with ( + self.assertRaises(ValidationError) as context, + self.assertLogs("joanie") as logger, + ): backend.handle_notification(request) self.assertEqual( @@ -324,9 +330,10 @@ def test_backend_lex_persona_handle_notification_verify_webhook_event_failed_to_ ) backend = get_signature_backend() - with self.assertRaises(ValidationError) as context, self.assertLogs( - "joanie" - ) as logger: + with ( + self.assertRaises(ValidationError) as context, + self.assertLogs("joanie") as logger, + ): backend.handle_notification(request) self.assertEqual( @@ -490,9 +497,10 @@ def test_backend_lex_persona_handle_notification_workflow_finished_event_but_sig backend = get_signature_backend() - with self.assertRaises(ValidationError) as context, self.assertLogs( - "joanie" - ) as logger: + with ( + self.assertRaises(ValidationError) as context, + self.assertLogs("joanie") as logger, + ): backend.handle_notification(request) self.assertEqual( diff --git a/src/backend/joanie/tests/signature/backends/lex_persona/test_submit_for_signature.py b/src/backend/joanie/tests/signature/backends/lex_persona/test_submit_for_signature.py index 6ece3f84f..31227511b 100644 --- a/src/backend/joanie/tests/signature/backends/lex_persona/test_submit_for_signature.py +++ b/src/backend/joanie/tests/signature/backends/lex_persona/test_submit_for_signature.py @@ -1,4 +1,5 @@ """Lex Persona backend test for submit_for_signature.""" + from http import HTTPStatus from django.conf import settings diff --git a/src/backend/joanie/tests/signature/test_backend_signature_app_config.py b/src/backend/joanie/tests/signature/test_backend_signature_app_config.py index 9b1721a2f..dbf987acc 100644 --- a/src/backend/joanie/tests/signature/test_backend_signature_app_config.py +++ b/src/backend/joanie/tests/signature/test_backend_signature_app_config.py @@ -1,4 +1,5 @@ """Test suite of the method ready() for Signature AppConfig""" + import random from django.apps import apps diff --git a/src/backend/joanie/tests/signature/test_backend_signature_base.py b/src/backend/joanie/tests/signature/test_backend_signature_base.py index a3f875d9f..c93747e38 100644 --- a/src/backend/joanie/tests/signature/test_backend_signature_base.py +++ b/src/backend/joanie/tests/signature/test_backend_signature_base.py @@ -1,4 +1,5 @@ """Test suite of common methods for Base, to Dummy and Client Signature Backend.""" + import random from datetime import timedelta from unittest import mock diff --git a/src/backend/joanie/tests/signature/test_backend_signature_dummy.py b/src/backend/joanie/tests/signature/test_backend_signature_dummy.py index 649fa3fb6..57b6fe407 100644 --- a/src/backend/joanie/tests/signature/test_backend_signature_dummy.py +++ b/src/backend/joanie/tests/signature/test_backend_signature_dummy.py @@ -1,4 +1,5 @@ """Test suite of the DummySignatureBackend""" + import random from io import BytesIO diff --git a/src/backend/joanie/tests/signature/test_backend_signature_get_backend.py b/src/backend/joanie/tests/signature/test_backend_signature_get_backend.py index 8d55a7a1b..f4543976a 100644 --- a/src/backend/joanie/tests/signature/test_backend_signature_get_backend.py +++ b/src/backend/joanie/tests/signature/test_backend_signature_get_backend.py @@ -1,4 +1,5 @@ """get_signature_backend() test suite""" + from django.test import TestCase from django.test.utils import override_settings diff --git a/src/backend/joanie/tests/signature/test_commands_generate_zip_archive_of_contracts.py b/src/backend/joanie/tests/signature/test_commands_generate_zip_archive_of_contracts.py index 675011bb2..ea3a4821d 100644 --- a/src/backend/joanie/tests/signature/test_commands_generate_zip_archive_of_contracts.py +++ b/src/backend/joanie/tests/signature/test_commands_generate_zip_archive_of_contracts.py @@ -1,4 +1,5 @@ """Test suite for the management command `generate_zip_archive_of_contracts`""" + import random from io import BytesIO, StringIO from uuid import uuid4 diff --git a/src/backend/joanie/tests/swagger/test_openapi_schema.py b/src/backend/joanie/tests/swagger/test_openapi_schema.py index 309e5e108..056ac71e9 100644 --- a/src/backend/joanie/tests/swagger/test_openapi_schema.py +++ b/src/backend/joanie/tests/swagger/test_openapi_schema.py @@ -1,6 +1,7 @@ """ Test suite for generated openapi schema. """ + import json from http import HTTPStatus diff --git a/src/backend/joanie/tests/testing_utils.py b/src/backend/joanie/tests/testing_utils.py index 4ab8cf5e8..defd8d146 100644 --- a/src/backend/joanie/tests/testing_utils.py +++ b/src/backend/joanie/tests/testing_utils.py @@ -1,4 +1,5 @@ """Test utils module.""" + import sys from importlib import reload diff --git a/src/backend/manage.py b/src/backend/manage.py index 71ee703d4..f2c41862d 100644 --- a/src/backend/manage.py +++ b/src/backend/manage.py @@ -2,6 +2,7 @@ """ Joanie's sandbox management script. """ + import os import sys