diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index d91c58678..b451cfa83 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -5,3 +5,6 @@ 96e5b1993d7f2451443bfabff4265029ac6625af e00af2f73cb7d27c3755f18b2161b9acbd8ca8aa 29d01c35bc06d5a8462487d614e33b9e8416ba96 + +# import sorting +ca682c8e5647feacb26f8570f77f1bdb6b5d3b9a diff --git a/moto/__init__.py b/moto/__init__.py index a234c1448..0dcfc5f77 100644 --- a/moto/__init__.py +++ b/moto/__init__.py @@ -1,15 +1,24 @@ import importlib import sys from contextlib import ContextDecorator +from typing import ( + TYPE_CHECKING, + Any, + Callable, + List, + Optional, + TypeVar, + Union, + overload, +) -from moto.core.models import BaseMockAWS, base_decorator, BaseDecorator -from typing import Any, Callable, List, Optional, TypeVar, Union, overload -from typing import TYPE_CHECKING +from moto.core.models import BaseDecorator, BaseMockAWS, base_decorator if TYPE_CHECKING: - from moto.xray import XRaySegment as xray_segment_type from typing_extensions import ParamSpec + from moto.xray import XRaySegment as xray_segment_type + P = ParamSpec("P") @@ -255,9 +264,9 @@ __version__ = "4.2.11.dev" try: # Need to monkey-patch botocore requests back to underlying urllib3 classes from botocore.awsrequest import ( - HTTPSConnectionPool, - HTTPConnectionPool, HTTPConnection, + HTTPConnectionPool, + HTTPSConnectionPool, VerifiedHTTPSConnection, ) except ImportError: diff --git a/moto/acm/__init__.py b/moto/acm/__init__.py index dc896d0ed..a77deff4f 100644 --- a/moto/acm/__init__.py +++ b/moto/acm/__init__.py @@ -1,5 +1,5 @@ -from .models import acm_backends from ..core.models import base_decorator +from .models import acm_backends acm_backend = acm_backends["us-east-1"] mock_acm = base_decorator(acm_backends) diff --git a/moto/acm/models.py b/moto/acm/models.py index f899c771f..522061436 100644 --- a/moto/acm/models.py +++ b/moto/acm/models.py @@ -1,25 +1,25 @@ import base64 -import re import datetime -from moto.core import BaseBackend, BackendDict, BaseModel -from moto.core.utils import utcnow +import re +from typing import Any, Dict, Iterable, List, Optional, Set, Tuple + +import cryptography.hazmat.primitives.asymmetric.rsa +import cryptography.x509 +from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives import hashes, serialization +from cryptography.x509 import OID_COMMON_NAME, DNSName, NameOID + from moto import settings -from typing import Any, Dict, List, Iterable, Optional, Tuple, Set +from moto.core import BackendDict, BaseBackend, BaseModel +from moto.core.utils import utcnow from .exceptions import ( - AWSValidationException, AWSTooManyTagsException, + AWSValidationException, CertificateNotFound, ) from .utils import make_arn_for_certificate -import cryptography.x509 -from cryptography.x509 import OID_COMMON_NAME, NameOID, DNSName -import cryptography.hazmat.primitives.asymmetric.rsa -from cryptography.hazmat.primitives import serialization, hashes -from cryptography.hazmat.backends import default_backend - - AWS_ROOT_CA = b"""-----BEGIN CERTIFICATE----- MIIESTCCAzGgAwIBAgITBntQXCplJ7wevi2i0ZmY7bibLDANBgkqhkiG9w0BAQsF ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6 diff --git a/moto/acm/responses.py b/moto/acm/responses.py index 1248b0c3d..7b3636e95 100644 --- a/moto/acm/responses.py +++ b/moto/acm/responses.py @@ -1,11 +1,11 @@ -import json import base64 +import json +from typing import Dict, List, Tuple, Union from moto.core.responses import BaseResponse -from typing import Dict, List, Tuple, Union -from .models import acm_backends, AWSCertificateManagerBackend -from .exceptions import AWSValidationException +from .exceptions import AWSValidationException +from .models import AWSCertificateManagerBackend, acm_backends GENERIC_RESPONSE_TYPE = Union[str, Tuple[str, Dict[str, int]]] diff --git a/moto/acmpca/__init__.py b/moto/acmpca/__init__.py index 8059ab38b..85ccfb456 100644 --- a/moto/acmpca/__init__.py +++ b/moto/acmpca/__init__.py @@ -1,5 +1,5 @@ """acmpca module initialization; sets value for base decorator.""" -from .models import acmpca_backends from ..core.models import base_decorator +from .models import acmpca_backends mock_acmpca = base_decorator(acmpca_backends) diff --git a/moto/acmpca/models.py b/moto/acmpca/models.py index c07ad0f19..c91f35a3d 100644 --- a/moto/acmpca/models.py +++ b/moto/acmpca/models.py @@ -1,18 +1,20 @@ """ACMPCABackend class with methods for supported APIs.""" import base64 -from .exceptions import ResourceNotFoundException -from moto.core import BaseBackend, BackendDict, BaseModel +import datetime +from typing import Any, Dict, List, Optional, Tuple + +import cryptography.hazmat.primitives.asymmetric.rsa +import cryptography.x509 +from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives import hashes, serialization +from cryptography.x509 import Certificate, NameOID, load_pem_x509_certificate + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import unix_time, utcnow from moto.moto_api._internal import mock_random from moto.utilities.tagging_service import TaggingService -import datetime -import cryptography.x509 -from cryptography.x509 import NameOID, load_pem_x509_certificate, Certificate -import cryptography.hazmat.primitives.asymmetric.rsa -from cryptography.hazmat.primitives import serialization, hashes -from cryptography.hazmat.backends import default_backend -from typing import Any, Dict, List, Optional, Tuple +from .exceptions import ResourceNotFoundException class CertificateAuthority(BaseModel): diff --git a/moto/acmpca/responses.py b/moto/acmpca/responses.py index e67769e4c..b26e9568a 100644 --- a/moto/acmpca/responses.py +++ b/moto/acmpca/responses.py @@ -3,7 +3,8 @@ import base64 import json from moto.core.responses import BaseResponse -from .models import acmpca_backends, ACMPCABackend + +from .models import ACMPCABackend, acmpca_backends class ACMPCAResponse(BaseResponse): diff --git a/moto/amp/__init__.py b/moto/amp/__init__.py index a135ba7d5..8af2fc704 100644 --- a/moto/amp/__init__.py +++ b/moto/amp/__init__.py @@ -1,5 +1,5 @@ """amp module initialization; sets value for base decorator.""" -from .models import amp_backends from ..core.models import base_decorator +from .models import amp_backends mock_amp = base_decorator(amp_backends) diff --git a/moto/amp/exceptions.py b/moto/amp/exceptions.py index e5223d163..59085204a 100644 --- a/moto/amp/exceptions.py +++ b/moto/amp/exceptions.py @@ -1,4 +1,5 @@ import json + from moto.core.exceptions import JsonRESTError diff --git a/moto/amp/models.py b/moto/amp/models.py index 847eec133..afb09112c 100644 --- a/moto/amp/models.py +++ b/moto/amp/models.py @@ -1,11 +1,13 @@ """PrometheusServiceBackend class with methods for supported APIs.""" -from moto.core import BaseBackend, BackendDict, BaseModel +from typing import Any, Callable, Dict, List, Optional + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import unix_time from moto.moto_api._internal import mock_random from moto.utilities.paginator import paginate from moto.utilities.tagging_service import TaggingService -from typing import Any, Callable, Dict, List, Optional + from .exceptions import RuleGroupNamespaceNotFound, WorkspaceNotFound from .utils import PAGINATION_MODEL diff --git a/moto/amp/responses.py b/moto/amp/responses.py index feed0092d..e0c720f40 100644 --- a/moto/amp/responses.py +++ b/moto/amp/responses.py @@ -1,11 +1,12 @@ """Handles incoming amp requests, invokes methods, returns responses.""" import json - -from moto.core.responses import BaseResponse -from .models import amp_backends, PrometheusServiceBackend from typing import Any from urllib.parse import unquote +from moto.core.responses import BaseResponse + +from .models import PrometheusServiceBackend, amp_backends + class PrometheusServiceResponse(BaseResponse): """Handler for PrometheusService requests and responses.""" diff --git a/moto/apigateway/__init__.py b/moto/apigateway/__init__.py index 436ec6fec..24465d1ca 100644 --- a/moto/apigateway/__init__.py +++ b/moto/apigateway/__init__.py @@ -1,5 +1,5 @@ -from .models import apigateway_backends from ..core.models import base_decorator +from .models import apigateway_backends apigateway_backend = apigateway_backends["us-east-1"] mock_apigateway = base_decorator(apigateway_backends) diff --git a/moto/apigateway/exceptions.py b/moto/apigateway/exceptions.py index 759366cfc..cfcfa26d8 100644 --- a/moto/apigateway/exceptions.py +++ b/moto/apigateway/exceptions.py @@ -1,6 +1,7 @@ -from moto.core.exceptions import JsonRESTError from typing import Any +from moto.core.exceptions import JsonRESTError + class ApiGatewayException(JsonRESTError): pass diff --git a/moto/apigateway/integration_parsers/__init__.py b/moto/apigateway/integration_parsers/__init__.py index a185d4eca..3be22b3ec 100644 --- a/moto/apigateway/integration_parsers/__init__.py +++ b/moto/apigateway/integration_parsers/__init__.py @@ -1,6 +1,8 @@ import abc from typing import Tuple, Union + from requests.models import PreparedRequest + from ..models import Integration diff --git a/moto/apigateway/integration_parsers/aws_parser.py b/moto/apigateway/integration_parsers/aws_parser.py index ca1d46258..6b1ea7e05 100644 --- a/moto/apigateway/integration_parsers/aws_parser.py +++ b/moto/apigateway/integration_parsers/aws_parser.py @@ -1,8 +1,9 @@ +from typing import Tuple, Union + import requests -from . import IntegrationParser from ..models import Integration -from typing import Tuple, Union +from . import IntegrationParser class TypeAwsParser(IntegrationParser): diff --git a/moto/apigateway/integration_parsers/http_parser.py b/moto/apigateway/integration_parsers/http_parser.py index ef2dd689d..4ae96fef5 100644 --- a/moto/apigateway/integration_parsers/http_parser.py +++ b/moto/apigateway/integration_parsers/http_parser.py @@ -1,8 +1,9 @@ -import requests from typing import Tuple, Union -from . import IntegrationParser +import requests + from ..models import Integration +from . import IntegrationParser class TypeHttpParser(IntegrationParser): diff --git a/moto/apigateway/integration_parsers/unknown_parser.py b/moto/apigateway/integration_parsers/unknown_parser.py index cb887ed0c..90d4eadf9 100644 --- a/moto/apigateway/integration_parsers/unknown_parser.py +++ b/moto/apigateway/integration_parsers/unknown_parser.py @@ -1,7 +1,9 @@ -import requests from typing import Tuple, Union -from . import IntegrationParser + +import requests + from ..models import Integration +from . import IntegrationParser class TypeUnknownParser(IntegrationParser): diff --git a/moto/apigateway/models.py b/moto/apigateway/models.py index 5b066ca81..07dd02d40 100644 --- a/moto/apigateway/models.py +++ b/moto/apigateway/models.py @@ -1,8 +1,8 @@ -from collections import defaultdict -from datetime import datetime import re import string import time +from collections import defaultdict +from datetime import datetime from typing import Any, Dict, List, Optional, Tuple, Union from urllib.parse import urlparse @@ -17,54 +17,56 @@ except ImportError: # (Also exists in 0.7.0, but throws a warning) from openapi_spec_validator import validate_spec as validate # type: ignore from openapi_spec_validator.validation.exceptions import OpenAPIValidationError -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel -from .utils import create_id, to_path + +from moto.apigateway.exceptions import MethodNotFoundException +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.core.utils import path_url +from moto.moto_api._internal import mock_random as random + +from ..core.models import responses_mock from .exceptions import ( - BadRequestException, - ConflictException, - DeploymentNotFoundException, + ApiKeyAlreadyExists, ApiKeyNotFoundException, - UsagePlanNotFoundException, + ApiKeyValueMinLength, + AuthorizerNotFoundException, AwsProxyNotAllowed, + BadRequestException, + BasePathConflictException, + BasePathNotFoundException, + ConflictException, CrossAccountNotAllowed, + DeploymentNotFoundException, + DomainNameNotFound, + GatewayResponseNotFound, IntegrationMethodNotDefined, InvalidArn, - InvalidIntegrationArn, + InvalidBasePathException, + InvalidDomainName, InvalidHttpEndpoint, + InvalidIntegrationArn, + InvalidModelName, InvalidOpenAPIDocumentException, InvalidOpenApiDocVersionException, InvalidOpenApiModeException, InvalidResourcePathException, - AuthorizerNotFoundException, - StageNotFoundException, - ResourceIdNotFoundException, - RoleNotSpecified, + InvalidRestApiId, + InvalidRestApiIdForBasePathMappingException, + InvalidStageException, + ModelNotFound, NoIntegrationDefined, NoIntegrationResponseDefined, NoMethodDefined, - ApiKeyAlreadyExists, - DomainNameNotFound, - InvalidDomainName, - InvalidRestApiId, - InvalidModelName, - RestAPINotFound, RequestValidatorNotFound, - ModelNotFound, - ApiKeyValueMinLength, - InvalidBasePathException, - InvalidRestApiIdForBasePathMappingException, - InvalidStageException, - BasePathConflictException, - BasePathNotFoundException, + ResourceIdNotFoundException, + RestAPINotFound, + RoleNotSpecified, + StageNotFoundException, StageStillActive, - VpcLinkNotFound, + UsagePlanNotFoundException, ValidationException, - GatewayResponseNotFound, + VpcLinkNotFound, ) -from ..core.models import responses_mock -from moto.apigateway.exceptions import MethodNotFoundException -from moto.moto_api._internal import mock_random as random +from .utils import create_id, to_path STAGE_URL = "https://{api_id}.execute-api.{region_name}.amazonaws.com/{stage_name}" diff --git a/moto/apigateway/responses.py b/moto/apigateway/responses.py index e0228c473..03fc0a335 100644 --- a/moto/apigateway/responses.py +++ b/moto/apigateway/responses.py @@ -2,11 +2,12 @@ import json from typing import Any, Dict, List from urllib.parse import unquote +from moto.core.responses import TYPE_RESPONSE, BaseResponse from moto.utilities.utils import merge_multiple_dicts -from moto.core.responses import BaseResponse, TYPE_RESPONSE -from .models import apigateway_backends, APIGatewayBackend -from .utils import deserialize_body + from .exceptions import InvalidRequestInput +from .models import APIGatewayBackend, apigateway_backends +from .utils import deserialize_body API_KEY_SOURCES = ["AUTHORIZER", "HEADER"] AUTHORIZER_TYPES = ["TOKEN", "REQUEST", "COGNITO_USER_POOLS"] diff --git a/moto/apigateway/urls.py b/moto/apigateway/urls.py index e4ab1a566..df89b9cbc 100644 --- a/moto/apigateway/urls.py +++ b/moto/apigateway/urls.py @@ -1,5 +1,5 @@ -from .responses import APIGatewayResponse from ..apigatewayv2.urls import url_paths as url_paths_v2 +from .responses import APIGatewayResponse url_bases = [r"https?://apigateway\.(.+)\.amazonaws.com"] diff --git a/moto/apigateway/utils.py b/moto/apigateway/utils.py index 86e1e424d..971fd218c 100644 --- a/moto/apigateway/utils.py +++ b/moto/apigateway/utils.py @@ -1,9 +1,11 @@ -import string import json -import yaml -from moto.moto_api._internal import mock_random as random +import string from typing import Any, Dict +import yaml + +from moto.moto_api._internal import mock_random as random + def create_id() -> str: size = 10 diff --git a/moto/apigatewaymanagementapi/__init__.py b/moto/apigatewaymanagementapi/__init__.py index 0c986e2bd..9d128abae 100644 --- a/moto/apigatewaymanagementapi/__init__.py +++ b/moto/apigatewaymanagementapi/__init__.py @@ -1,5 +1,5 @@ """apigatewaymanagementapi module initialization; sets value for base decorator.""" -from .models import apigatewaymanagementapi_backends from ..core.models import base_decorator +from .models import apigatewaymanagementapi_backends mock_apigatewaymanagementapi = base_decorator(apigatewaymanagementapi_backends) diff --git a/moto/apigatewaymanagementapi/models.py b/moto/apigatewaymanagementapi/models.py index 9ea9b408b..9947ded1d 100644 --- a/moto/apigatewaymanagementapi/models.py +++ b/moto/apigatewaymanagementapi/models.py @@ -1,7 +1,8 @@ """ApiGatewayManagementApiBackend class with methods for supported APIs.""" from collections import defaultdict from typing import Any, Dict -from moto.core import BaseBackend, BackendDict + +from moto.core import BackendDict, BaseBackend from moto.core.utils import unix_time diff --git a/moto/apigatewaymanagementapi/responses.py b/moto/apigatewaymanagementapi/responses.py index 1accf478f..a3873cb2f 100644 --- a/moto/apigatewaymanagementapi/responses.py +++ b/moto/apigatewaymanagementapi/responses.py @@ -3,7 +3,8 @@ import json from typing import Any from moto.core.responses import BaseResponse -from .models import apigatewaymanagementapi_backends, ApiGatewayManagementApiBackend + +from .models import ApiGatewayManagementApiBackend, apigatewaymanagementapi_backends class ApiGatewayManagementApiResponse(BaseResponse): diff --git a/moto/apigatewayv2/__init__.py b/moto/apigatewayv2/__init__.py index 2ddfce55b..1a095965d 100644 --- a/moto/apigatewayv2/__init__.py +++ b/moto/apigatewayv2/__init__.py @@ -1,5 +1,5 @@ """apigatewayv2 module initialization; sets value for base decorator.""" -from .models import apigatewayv2_backends from ..core.models import base_decorator +from .models import apigatewayv2_backends mock_apigatewayv2 = base_decorator(apigatewayv2_backends) diff --git a/moto/apigatewayv2/models.py b/moto/apigatewayv2/models.py index 5ec2b3992..88e811205 100644 --- a/moto/apigatewayv2/models.py +++ b/moto/apigatewayv2/models.py @@ -1,10 +1,11 @@ """ApiGatewayV2Backend class with methods for supported APIs.""" import hashlib import string -import yaml from typing import Any, Dict, List, Optional, Union -from moto.core import BaseBackend, BackendDict, BaseModel +import yaml + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import unix_time from moto.moto_api._internal import mock_random as random from moto.utilities.tagging_service import TaggingService @@ -14,15 +15,15 @@ from .exceptions import ( ApiNotFound, AuthorizerNotFound, BadRequestException, - ModelNotFound, - RouteResponseNotFound, + DomainNameAlreadyExists, + DomainNameNotFound, IntegrationNotFound, IntegrationResponseNotFound, + ModelNotFound, RouteNotFound, - VpcLinkNotFound, - DomainNameNotFound, - DomainNameAlreadyExists, + RouteResponseNotFound, StageNotFound, + VpcLinkNotFound, ) diff --git a/moto/apigatewayv2/responses.py b/moto/apigatewayv2/responses.py index 82f1c143c..3d76287cb 100644 --- a/moto/apigatewayv2/responses.py +++ b/moto/apigatewayv2/responses.py @@ -1,12 +1,12 @@ """Handles incoming apigatewayv2 requests, invokes methods, returns responses.""" import json - -from moto.core.responses import BaseResponse, TYPE_RESPONSE from typing import Any from urllib.parse import unquote +from moto.core.responses import TYPE_RESPONSE, BaseResponse + from .exceptions import UnknownProtocol -from .models import apigatewayv2_backends, ApiGatewayV2Backend +from .models import ApiGatewayV2Backend, apigatewayv2_backends class ApiGatewayV2Response(BaseResponse): diff --git a/moto/appconfig/__init__.py b/moto/appconfig/__init__.py index 50f09c2f6..de813dde3 100644 --- a/moto/appconfig/__init__.py +++ b/moto/appconfig/__init__.py @@ -1,5 +1,5 @@ """appconfig module initialization; sets value for base decorator.""" -from .models import appconfig_backends from ..core.models import base_decorator +from .models import appconfig_backends mock_appconfig = base_decorator(appconfig_backends) diff --git a/moto/appconfig/models.py b/moto/appconfig/models.py index e993b2045..b4e9ac0b0 100644 --- a/moto/appconfig/models.py +++ b/moto/appconfig/models.py @@ -1,7 +1,9 @@ -from moto.core import BaseBackend, BackendDict, BaseModel +from typing import Any, Dict, Iterable, List, Optional + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.moto_api._internal import mock_random from moto.utilities.tagging_service import TaggingService -from typing import Any, Dict, List, Iterable, Optional + from .exceptions import ( AppNotFoundException, ConfigurationProfileNotFound, diff --git a/moto/appconfig/responses.py b/moto/appconfig/responses.py index 78bff4e1f..2dd55bfd8 100644 --- a/moto/appconfig/responses.py +++ b/moto/appconfig/responses.py @@ -1,10 +1,11 @@ import json - -from moto.core.responses import BaseResponse -from .models import appconfig_backends, AppConfigBackend from typing import Any, Dict, Tuple from urllib.parse import unquote +from moto.core.responses import BaseResponse + +from .models import AppConfigBackend, appconfig_backends + class AppConfigResponse(BaseResponse): def tags(self, request: Any, full_url: str, headers: Any) -> str: # type: ignore[return] diff --git a/moto/applicationautoscaling/__init__.py b/moto/applicationautoscaling/__init__.py index a5fe962e2..b48596b94 100644 --- a/moto/applicationautoscaling/__init__.py +++ b/moto/applicationautoscaling/__init__.py @@ -1,4 +1,4 @@ -from .models import applicationautoscaling_backends from ..core.models import base_decorator +from .models import applicationautoscaling_backends mock_applicationautoscaling = base_decorator(applicationautoscaling_backends) diff --git a/moto/applicationautoscaling/models.py b/moto/applicationautoscaling/models.py index ec384050a..e8feb39bd 100644 --- a/moto/applicationautoscaling/models.py +++ b/moto/applicationautoscaling/models.py @@ -1,11 +1,13 @@ -from moto.core import BaseBackend, BackendDict, BaseModel -from moto.ecs import ecs_backends -from moto.moto_api._internal import mock_random -from .exceptions import AWSValidationException +import time from collections import OrderedDict from enum import Enum, unique -from typing import Dict, List, Union, Optional, Tuple -import time +from typing import Dict, List, Optional, Tuple, Union + +from moto.core import BackendDict, BaseBackend, BaseModel +from moto.ecs import ecs_backends +from moto.moto_api._internal import mock_random + +from .exceptions import AWSValidationException @unique diff --git a/moto/applicationautoscaling/responses.py b/moto/applicationautoscaling/responses.py index 7534dd83b..9733ba8c4 100644 --- a/moto/applicationautoscaling/responses.py +++ b/moto/applicationautoscaling/responses.py @@ -1,16 +1,18 @@ -from moto.core.responses import BaseResponse -from typing import Any, Dict import json +from typing import Any, Dict + +from moto.core.responses import BaseResponse + +from .exceptions import AWSValidationException from .models import ( - applicationautoscaling_backends, + ApplicationAutoscalingBackend, + FakeApplicationAutoscalingPolicy, + FakeScalableTarget, + FakeScheduledAction, ScalableDimensionValueSet, ServiceNamespaceValueSet, - ApplicationAutoscalingBackend, - FakeScalableTarget, - FakeApplicationAutoscalingPolicy, - FakeScheduledAction, + applicationautoscaling_backends, ) -from .exceptions import AWSValidationException class ApplicationAutoScalingResponse(BaseResponse): diff --git a/moto/appsync/__init__.py b/moto/appsync/__init__.py index 9fa424771..90023abd4 100644 --- a/moto/appsync/__init__.py +++ b/moto/appsync/__init__.py @@ -1,5 +1,5 @@ """appsync module initialization; sets value for base decorator.""" -from .models import appsync_backends from ..core.models import base_decorator +from .models import appsync_backends mock_appsync = base_decorator(appsync_backends) diff --git a/moto/appsync/exceptions.py b/moto/appsync/exceptions.py index e387052f5..7e1069e3c 100644 --- a/moto/appsync/exceptions.py +++ b/moto/appsync/exceptions.py @@ -1,4 +1,5 @@ import json + from moto.core.exceptions import JsonRESTError diff --git a/moto/appsync/models.py b/moto/appsync/models.py index 7718f1f5b..3177115d5 100644 --- a/moto/appsync/models.py +++ b/moto/appsync/models.py @@ -1,13 +1,14 @@ import base64 import json -from datetime import timedelta, datetime, timezone +from datetime import datetime, timedelta, timezone from typing import Any, Dict, Iterable, List, Optional, Tuple -from moto.core import BaseBackend, BackendDict, BaseModel + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import unix_time from moto.moto_api._internal import mock_random from moto.utilities.tagging_service import TaggingService -from .exceptions import GraphqlAPINotFound, GraphQLSchemaException, BadRequestException +from .exceptions import BadRequestException, GraphqlAPINotFound, GraphQLSchemaException # AWS custom scalars and directives # https://github.com/dotansimha/graphql-code-generator/discussions/4311#discussioncomment-2921796 @@ -65,8 +66,8 @@ class GraphqlSchema(BaseModel): def _parse_graphql_definition(self) -> None: try: from graphql import parse - from graphql.language.ast import ObjectTypeDefinitionNode from graphql.error.graphql_error import GraphQLError + from graphql.language.ast import ObjectTypeDefinitionNode res = parse(self.definition) for definition in res.definitions: @@ -79,10 +80,10 @@ class GraphqlSchema(BaseModel): def get_introspection_schema(self, format_: str, include_directives: bool) -> str: from graphql import ( - print_schema, build_client_schema, - introspection_from_schema, build_schema, + introspection_from_schema, + print_schema, ) schema = build_schema(self.definition + AWS_CUSTOM_GRAPHQL) diff --git a/moto/appsync/responses.py b/moto/appsync/responses.py index 4265bf679..e7318fe57 100644 --- a/moto/appsync/responses.py +++ b/moto/appsync/responses.py @@ -1,10 +1,11 @@ """Handles incoming appsync requests, invokes methods, returns responses.""" import json - -from moto.core.responses import BaseResponse, TYPE_RESPONSE from typing import Any from urllib.parse import unquote -from .models import appsync_backends, AppSyncBackend + +from moto.core.responses import TYPE_RESPONSE, BaseResponse + +from .models import AppSyncBackend, appsync_backends class AppSyncResponse(BaseResponse): diff --git a/moto/athena/__init__.py b/moto/athena/__init__.py index 0e5ca2628..7e4e6b15b 100644 --- a/moto/athena/__init__.py +++ b/moto/athena/__init__.py @@ -1,5 +1,5 @@ -from .models import athena_backends from ..core.models import base_decorator +from .models import athena_backends athena_backend = athena_backends["us-east-1"] mock_athena = base_decorator(athena_backends) diff --git a/moto/athena/exceptions.py b/moto/athena/exceptions.py index bcbc48c3b..e6aaa19b0 100644 --- a/moto/athena/exceptions.py +++ b/moto/athena/exceptions.py @@ -1,4 +1,5 @@ import json + from moto.core.exceptions import JsonRESTError diff --git a/moto/athena/models.py b/moto/athena/models.py index 4764116fd..a822c53d0 100644 --- a/moto/athena/models.py +++ b/moto/athena/models.py @@ -1,8 +1,8 @@ -from datetime import datetime import time +from datetime import datetime from typing import Any, Dict, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.moto_api._internal import mock_random from moto.utilities.paginator import paginate diff --git a/moto/athena/responses.py b/moto/athena/responses.py index 5bdc38c60..ff235057d 100644 --- a/moto/athena/responses.py +++ b/moto/athena/responses.py @@ -1,8 +1,9 @@ import json +from typing import Dict, Tuple, Union from moto.core.responses import BaseResponse -from .models import athena_backends, AthenaBackend -from typing import Dict, Tuple, Union + +from .models import AthenaBackend, athena_backends class AthenaResponse(BaseResponse): diff --git a/moto/autoscaling/__init__.py b/moto/autoscaling/__init__.py index 14ba8f3d9..a4887b434 100644 --- a/moto/autoscaling/__init__.py +++ b/moto/autoscaling/__init__.py @@ -1,5 +1,5 @@ -from .models import autoscaling_backends from ..core.models import base_decorator +from .models import autoscaling_backends autoscaling_backend = autoscaling_backends["us-east-1"] mock_autoscaling = base_decorator(autoscaling_backends) diff --git a/moto/autoscaling/models.py b/moto/autoscaling/models.py index c731d8120..f81a65916 100644 --- a/moto/autoscaling/models.py +++ b/moto/autoscaling/models.py @@ -1,26 +1,26 @@ import itertools +from collections import OrderedDict from typing import Any, Dict, List, Optional, Tuple, Union -from moto.packages.boto.ec2.blockdevicemapping import ( - BlockDeviceType, - BlockDeviceMapping, -) -from moto.ec2.exceptions import InvalidInstanceIdError - -from collections import OrderedDict -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.core.utils import camelcase_to_underscores from moto.ec2 import ec2_backends +from moto.ec2.exceptions import InvalidInstanceIdError from moto.ec2.models import EC2Backend from moto.ec2.models.instances import Instance -from moto.elb.models import elb_backends, ELBBackend -from moto.elbv2.models import elbv2_backends, ELBv2Backend from moto.elb.exceptions import LoadBalancerNotFoundError +from moto.elb.models import ELBBackend, elb_backends +from moto.elbv2.models import ELBv2Backend, elbv2_backends from moto.moto_api._internal import mock_random as random +from moto.packages.boto.ec2.blockdevicemapping import ( + BlockDeviceMapping, + BlockDeviceType, +) + from .exceptions import ( AutoscalingClientError, - ResourceContentionError, InvalidInstanceError, + ResourceContentionError, ValidationError, ) diff --git a/moto/autoscaling/responses.py b/moto/autoscaling/responses.py index 3240349f1..ceaa2eb9f 100644 --- a/moto/autoscaling/responses.py +++ b/moto/autoscaling/responses.py @@ -1,7 +1,8 @@ from moto.core.responses import BaseResponse from moto.core.utils import iso_8601_datetime_with_milliseconds from moto.utilities.aws_headers import amz_crc32, amzn_request_id -from .models import autoscaling_backends, AutoScalingBackend + +from .models import AutoScalingBackend, autoscaling_backends class AutoScalingResponse(BaseResponse): diff --git a/moto/awslambda/__init__.py b/moto/awslambda/__init__.py index 3954aa95e..8b36f2205 100644 --- a/moto/awslambda/__init__.py +++ b/moto/awslambda/__init__.py @@ -1,5 +1,5 @@ -from .models import lambda_backends from ..core.models import base_decorator +from .models import lambda_backends lambda_backend = lambda_backends["us-east-1"] mock_lambda = base_decorator(lambda_backends) diff --git a/moto/awslambda/exceptions.py b/moto/awslambda/exceptions.py index 19174d401..36636fff7 100644 --- a/moto/awslambda/exceptions.py +++ b/moto/awslambda/exceptions.py @@ -1,6 +1,7 @@ -from moto.core.exceptions import JsonRESTError from typing import Any +from moto.core.exceptions import JsonRESTError + class LambdaClientError(JsonRESTError): def __init__(self, error: str, message: str): diff --git a/moto/awslambda/models.py b/moto/awslambda/models.py index 18e216dd0..5d70c361f 100644 --- a/moto/awslambda/models.py +++ b/moto/awslambda/models.py @@ -1,50 +1,55 @@ import base64 -import time -from collections import defaultdict +import calendar import copy -from datetime import datetime -from gzip import GzipFile -from typing import Any, Dict, Iterable, List, Optional, Tuple, Union -from sys import platform - import hashlib import io +import json import logging import os -import json import re -import zipfile import tarfile -import calendar import threading -import weakref +import time import warnings +import weakref +import zipfile +from collections import defaultdict +from datetime import datetime +from gzip import GzipFile +from sys import platform +from typing import Any, Dict, Iterable, List, Optional, Tuple, Union + import requests.exceptions +from moto import settings from moto.awslambda.policy import Policy -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.core.exceptions import RESTError -from moto.core.utils import unix_time_millis, iso_8601_datetime_with_nanoseconds, utcnow -from moto.utilities.utils import load_resource_as_bytes -from moto.iam.models import iam_backends -from moto.iam.exceptions import IAMNotFoundException +from moto.core.utils import iso_8601_datetime_with_nanoseconds, unix_time_millis, utcnow +from moto.dynamodb import dynamodb_backends +from moto.dynamodbstreams import dynamodbstreams_backends from moto.ecr.exceptions import ImageNotFoundException +from moto.ecr.models import ecr_backends +from moto.iam.exceptions import IAMNotFoundException +from moto.iam.models import iam_backends from moto.logs.models import logs_backends from moto.moto_api._internal import mock_random as random -from moto.s3.models import s3_backends, FakeKey -from moto.ecr.models import ecr_backends from moto.s3.exceptions import MissingBucket, MissingKey -from moto import settings +from moto.s3.models import FakeKey, s3_backends +from moto.sqs import sqs_backends +from moto.utilities.docker_utilities import DockerModel +from moto.utilities.utils import load_resource_as_bytes + from .exceptions import ( ConflictException, CrossAccountNotAllowed, FunctionUrlConfigNotFound, - InvalidRoleFormat, InvalidParameterValueException, + InvalidRoleFormat, + UnknownAliasException, + UnknownFunctionException, UnknownLayerException, UnknownLayerVersionException, - UnknownFunctionException, - UnknownAliasException, ValidationException, ) from .utils import ( @@ -54,10 +59,6 @@ from .utils import ( make_layer_ver_arn, split_layer_arn, ) -from moto.sqs import sqs_backends -from moto.dynamodb import dynamodb_backends -from moto.dynamodbstreams import dynamodbstreams_backends -from moto.utilities.docker_utilities import DockerModel logger = logging.getLogger(__name__) diff --git a/moto/awslambda/policy.py b/moto/awslambda/policy.py index 793bf8684..20f56fedb 100644 --- a/moto/awslambda/policy.py +++ b/moto/awslambda/policy.py @@ -1,11 +1,11 @@ import json +from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, TypeVar from moto.awslambda.exceptions import ( PreconditionFailedException, UnknownPolicyException, ) from moto.moto_api._internal import mock_random -from typing import Any, Callable, Dict, List, Optional, TypeVar, TYPE_CHECKING if TYPE_CHECKING: from .models import LambdaFunction diff --git a/moto/awslambda/responses.py b/moto/awslambda/responses.py index c06eb7b69..78f3ecbb8 100644 --- a/moto/awslambda/responses.py +++ b/moto/awslambda/responses.py @@ -3,11 +3,12 @@ import sys from typing import Any, Dict, List, Tuple, Union from urllib.parse import unquote +from moto.core.responses import TYPE_RESPONSE, BaseResponse from moto.core.utils import path_url from moto.utilities.aws_headers import amz_crc32, amzn_request_id -from moto.core.responses import BaseResponse, TYPE_RESPONSE + from .exceptions import FunctionAlreadyExists, UnknownFunctionException -from .models import lambda_backends, LambdaBackend +from .models import LambdaBackend, lambda_backends class LambdaResponse(BaseResponse): diff --git a/moto/awslambda_simple/__init__.py b/moto/awslambda_simple/__init__.py index e9e77ea9d..a7b640769 100644 --- a/moto/awslambda_simple/__init__.py +++ b/moto/awslambda_simple/__init__.py @@ -1,5 +1,5 @@ -from .models import lambda_simple_backends from ..core.models import base_decorator +from .models import lambda_simple_backends lambda_simple_backend = lambda_simple_backends["us-east-1"] mock_lambda_simple = base_decorator(lambda_simple_backends) diff --git a/moto/awslambda_simple/models.py b/moto/awslambda_simple/models.py index 68b7e32aa..9cd700140 100644 --- a/moto/awslambda_simple/models.py +++ b/moto/awslambda_simple/models.py @@ -1,10 +1,11 @@ +from typing import Any, Optional, Union + from ..awslambda.models import ( - lambda_backends, BaseBackend, LambdaBackend, + lambda_backends, ) from ..core import BackendDict -from typing import Any, Optional, Union class LambdaSimpleBackend(BaseBackend): diff --git a/moto/awslambda_simple/responses.py b/moto/awslambda_simple/responses.py index 022f4bef8..72f138ce7 100644 --- a/moto/awslambda_simple/responses.py +++ b/moto/awslambda_simple/responses.py @@ -1,5 +1,5 @@ from ..awslambda.responses import LambdaResponse -from .models import lambda_simple_backends, LambdaBackend +from .models import LambdaBackend, lambda_simple_backends class LambdaSimpleResponse(LambdaResponse): diff --git a/moto/backends.py b/moto/backends.py index d6bb05670..186685ef5 100644 --- a/moto/backends.py +++ b/moto/backends.py @@ -1,9 +1,9 @@ import importlib -import moto import sys -from moto.core import BackendDict from typing import Iterable, Tuple +import moto +from moto.core import BackendDict decorators = [d for d in dir(moto) if d.startswith("mock_") and not d == "mock_all"] decorator_functions = [getattr(moto, f) for f in decorators] diff --git a/moto/batch/__init__.py b/moto/batch/__init__.py index 753e77002..e90336773 100644 --- a/moto/batch/__init__.py +++ b/moto/batch/__init__.py @@ -1,5 +1,5 @@ -from .models import batch_backends from ..core.models import base_decorator +from .models import batch_backends batch_backend = batch_backends["us-east-1"] mock_batch = base_decorator(batch_backends) diff --git a/moto/batch/models.py b/moto/batch/models.py index 3ad34053a..a9768c107 100644 --- a/moto/batch/models.py +++ b/moto/batch/models.py @@ -1,42 +1,42 @@ import datetime -import dateutil.parser import logging import re import threading import time - -from sys import platform from itertools import cycle +from sys import platform from time import sleep -from typing import Any, Dict, List, Tuple, Optional, Set +from typing import Any, Dict, List, Optional, Set, Tuple -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel -from moto.iam.models import iam_backends, IAMBackend -from moto.ec2.models import ec2_backends, EC2Backend -from moto.ec2.models.instances import Instance -from moto.ecs.models import ecs_backends, EC2ContainerServiceBackend -from moto.logs.models import logs_backends, LogsBackend -from moto.utilities.tagging_service import TaggingService +import dateutil.parser -from .exceptions import InvalidParameterValueException, ClientException, ValidationError -from .utils import ( - make_arn_for_compute_env, - make_arn_for_job_queue, - make_arn_for_job, - make_arn_for_task_def, - lowercase_first_key, - JobStatus, -) -from moto.ec2.exceptions import InvalidSubnetIdError -from moto.ec2.models.instance_types import INSTANCE_TYPES as EC2_INSTANCE_TYPES -from moto.ec2.models.instance_types import INSTANCE_FAMILIES as EC2_INSTANCE_FAMILIES -from moto.iam.exceptions import IAMNotFoundException +from moto import settings +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.core.utils import unix_time_millis +from moto.ec2.exceptions import InvalidSubnetIdError +from moto.ec2.models import EC2Backend, ec2_backends +from moto.ec2.models.instance_types import INSTANCE_FAMILIES as EC2_INSTANCE_FAMILIES +from moto.ec2.models.instance_types import INSTANCE_TYPES as EC2_INSTANCE_TYPES +from moto.ec2.models.instances import Instance +from moto.ecs.models import EC2ContainerServiceBackend, ecs_backends +from moto.iam.exceptions import IAMNotFoundException +from moto.iam.models import IAMBackend, iam_backends +from moto.logs.models import LogsBackend, logs_backends from moto.moto_api import state_manager from moto.moto_api._internal import mock_random from moto.moto_api._internal.managed_state_model import ManagedState from moto.utilities.docker_utilities import DockerModel -from moto import settings +from moto.utilities.tagging_service import TaggingService + +from .exceptions import ClientException, InvalidParameterValueException, ValidationError +from .utils import ( + JobStatus, + lowercase_first_key, + make_arn_for_compute_env, + make_arn_for_job, + make_arn_for_job_queue, + make_arn_for_task_def, +) logger = logging.getLogger(__name__) COMPUTE_ENVIRONMENT_NAME_REGEX = re.compile( diff --git a/moto/batch/responses.py b/moto/batch/responses.py index 8a0ab4675..b074feac3 100644 --- a/moto/batch/responses.py +++ b/moto/batch/responses.py @@ -1,9 +1,10 @@ +import json +from urllib.parse import unquote, urlsplit + from moto.core.responses import BaseResponse from moto.utilities.aws_headers import amzn_request_id -from .models import batch_backends, BatchBackend -from urllib.parse import urlsplit, unquote -import json +from .models import BatchBackend, batch_backends class BatchResponse(BaseResponse): diff --git a/moto/batch_simple/__init__.py b/moto/batch_simple/__init__.py index a28b9cce8..31637eedd 100644 --- a/moto/batch_simple/__init__.py +++ b/moto/batch_simple/__init__.py @@ -1,5 +1,5 @@ -from .models import batch_simple_backends from ..core.models import base_decorator +from .models import batch_simple_backends batch_backend = batch_simple_backends["us-east-1"] mock_batch_simple = base_decorator(batch_simple_backends) diff --git a/moto/batch_simple/models.py b/moto/batch_simple/models.py index 14d6572ef..25dd69531 100644 --- a/moto/batch_simple/models.py +++ b/moto/batch_simple/models.py @@ -1,17 +1,17 @@ +import datetime +from os import getenv +from time import sleep +from typing import Any, Dict, List, Optional, Tuple + from ..batch.models import ( - batch_backends, BaseBackend, BatchBackend, ClientException, Job, + batch_backends, ) from ..core import BackendDict -import datetime -from os import getenv -from time import sleep -from typing import Any, Dict, List, Tuple, Optional - class BatchSimpleBackend(BaseBackend): """ diff --git a/moto/batch_simple/responses.py b/moto/batch_simple/responses.py index b4e7b7adb..dfb9e75e9 100644 --- a/moto/batch_simple/responses.py +++ b/moto/batch_simple/responses.py @@ -1,5 +1,5 @@ from ..batch.responses import BatchResponse -from .models import batch_simple_backends, BatchBackend +from .models import BatchBackend, batch_simple_backends class BatchSimpleResponse(BatchResponse): diff --git a/moto/budgets/__init__.py b/moto/budgets/__init__.py index 22813972b..3573df9f0 100644 --- a/moto/budgets/__init__.py +++ b/moto/budgets/__init__.py @@ -1,4 +1,4 @@ -from .models import budgets_backends from ..core.models import base_decorator +from .models import budgets_backends mock_budgets = base_decorator(budgets_backends) diff --git a/moto/budgets/models.py b/moto/budgets/models.py index d9d2388cc..22269fcac 100644 --- a/moto/budgets/models.py +++ b/moto/budgets/models.py @@ -1,9 +1,11 @@ from collections import defaultdict from copy import deepcopy from datetime import datetime -from moto.core import BaseBackend, BackendDict, BaseModel -from moto.core.utils import unix_time from typing import Any, Dict, Iterable, List + +from moto.core import BackendDict, BaseBackend, BaseModel +from moto.core.utils import unix_time + from .exceptions import BudgetMissingLimit, DuplicateRecordException, NotFoundException diff --git a/moto/budgets/responses.py b/moto/budgets/responses.py index dcfe42c1c..abcc8943a 100644 --- a/moto/budgets/responses.py +++ b/moto/budgets/responses.py @@ -1,7 +1,8 @@ import json from moto.core.responses import BaseResponse -from .models import budgets_backends, BudgetsBackend + +from .models import BudgetsBackend, budgets_backends class BudgetsResponse(BaseResponse): diff --git a/moto/ce/__init__.py b/moto/ce/__init__.py index 5d48cb894..d2e9ae19e 100644 --- a/moto/ce/__init__.py +++ b/moto/ce/__init__.py @@ -1,5 +1,5 @@ """ce module initialization; sets value for base decorator.""" -from .models import ce_backends from ..core.models import base_decorator +from .models import ce_backends mock_ce = base_decorator(ce_backends) diff --git a/moto/ce/models.py b/moto/ce/models.py index a4a37e589..16ff45db2 100644 --- a/moto/ce/models.py +++ b/moto/ce/models.py @@ -1,12 +1,14 @@ """CostExplorerBackend class with methods for supported APIs.""" -from .exceptions import CostCategoryNotFound -from moto.core import BaseBackend, BackendDict, BaseModel -from moto.utilities.tagging_service import TaggingService +from datetime import datetime +from typing import Any, Dict, List, Optional, Tuple + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import iso_8601_datetime_without_milliseconds from moto.moto_api._internal import mock_random -from datetime import datetime -from typing import Any, Dict, List, Tuple, Optional +from moto.utilities.tagging_service import TaggingService + +from .exceptions import CostCategoryNotFound def first_day() -> str: diff --git a/moto/ce/responses.py b/moto/ce/responses.py index bc9ae2334..45770478c 100644 --- a/moto/ce/responses.py +++ b/moto/ce/responses.py @@ -2,7 +2,8 @@ import json from moto.core.responses import BaseResponse -from .models import ce_backends, CostExplorerBackend + +from .models import CostExplorerBackend, ce_backends class CostExplorerResponse(BaseResponse): diff --git a/moto/cloudformation/__init__.py b/moto/cloudformation/__init__.py index 7fb7471d0..539456f54 100644 --- a/moto/cloudformation/__init__.py +++ b/moto/cloudformation/__init__.py @@ -1,5 +1,5 @@ -from .models import cloudformation_backends from ..core.models import base_decorator +from .models import cloudformation_backends cloudformation_backend = cloudformation_backends["us-east-1"] mock_cloudformation = base_decorator(cloudformation_backends) diff --git a/moto/cloudformation/custom_model.py b/moto/cloudformation/custom_model.py index d4b5c32a2..0af0f4e39 100644 --- a/moto/cloudformation/custom_model.py +++ b/moto/cloudformation/custom_model.py @@ -3,8 +3,8 @@ import threading from typing import Any, Dict from moto import settings -from moto.core import CloudFormationModel from moto.awslambda import lambda_backends +from moto.core import CloudFormationModel from moto.moto_api._internal import mock_random diff --git a/moto/cloudformation/exceptions.py b/moto/cloudformation/exceptions.py index e067e0c4f..b6feef57e 100644 --- a/moto/cloudformation/exceptions.py +++ b/moto/cloudformation/exceptions.py @@ -1,7 +1,9 @@ -from moto.core.exceptions import RESTError -from jinja2 import Template from typing import Optional +from jinja2 import Template + +from moto.core.exceptions import RESTError + class UnformattedGetAttTemplateException(Exception): description = ( diff --git a/moto/cloudformation/models.py b/moto/cloudformation/models.py index 7615e00e0..296919853 100644 --- a/moto/cloudformation/models.py +++ b/moto/cloudformation/models.py @@ -1,34 +1,34 @@ -from datetime import datetime, timedelta import json -import yaml - from collections import OrderedDict -from typing import Any, Dict, List, Optional, Iterable, Tuple, Union, Type +from datetime import datetime, timedelta +from typing import Any, Dict, Iterable, List, Optional, Tuple, Type, Union + +import yaml from yaml.parser import ParserError # pylint:disable=c-extension-no-member from yaml.scanner import ScannerError # pylint:disable=c-extension-no-member -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.core.utils import ( iso_8601_datetime_with_milliseconds, iso_8601_datetime_without_milliseconds, utcnow, ) from moto.moto_api._internal import mock_random +from moto.organizations.models import OrganizationsBackend, organizations_backends from moto.sns.models import sns_backends -from moto.organizations.models import organizations_backends, OrganizationsBackend from .custom_model import CustomModel -from .parsing import ResourceMap, Output, OutputMap, Export +from .exceptions import StackSetNotEmpty, StackSetNotFoundException, ValidationError +from .parsing import Export, Output, OutputMap, ResourceMap from .utils import ( generate_changeset_id, generate_stack_id, generate_stackset_arn, generate_stackset_id, - yaml_tag_constructor, - validate_template_cfn_lint, get_stack_from_s3_url, + validate_template_cfn_lint, + yaml_tag_constructor, ) -from .exceptions import ValidationError, StackSetNotEmpty, StackSetNotFoundException class FakeStackSet(BaseModel): diff --git a/moto/cloudformation/parsing.py b/moto/cloudformation/parsing.py index bfa94ee3f..a570b043f 100644 --- a/moto/cloudformation/parsing.py +++ b/moto/cloudformation/parsing.py @@ -1,24 +1,23 @@ -import string +import collections.abc as collections_abc +import copy import functools import json import logging -import copy -import warnings import re - -import collections.abc as collections_abc +import string +import warnings from functools import lru_cache from typing import ( Any, Dict, - List, - Union, Iterable, Iterator, + List, Optional, Tuple, - TypeVar, Type, + TypeVar, + Union, ) # This ugly section of imports is necessary because we @@ -34,6 +33,9 @@ from moto.awslambda import models as lambda_models # noqa # pylint: disable=al from moto.batch import models as batch_models # noqa # pylint: disable=all from moto.cloudformation.custom_model import CustomModel from moto.cloudwatch import models as cw_models # noqa # pylint: disable=all + +# End ugly list of imports +from moto.core import CloudFormationModel from moto.datapipeline import models as data_models # noqa # pylint: disable=all from moto.dynamodb import models as ddb_models # noqa # pylint: disable=all from moto.ec2 import models as ec2_models @@ -51,26 +53,23 @@ from moto.rds import models as rds_models # noqa # pylint: disable=all from moto.redshift import models as redshift_models # noqa # pylint: disable=all from moto.route53 import models as route53_models # noqa # pylint: disable=all from moto.s3 import models as s3_models # noqa # pylint: disable=all +from moto.s3.models import s3_backends +from moto.s3.utils import bucket_and_name_from_url from moto.sagemaker import models as sagemaker_models # noqa # pylint: disable=all from moto.sns import models as sns_models # noqa # pylint: disable=all from moto.sqs import models as sqs_models # noqa # pylint: disable=all -from moto.stepfunctions import models as sfn_models # noqa # pylint: disable=all from moto.ssm import models as ssm_models # noqa # pylint: disable=all - -# End ugly list of imports - -from moto.core import CloudFormationModel -from moto.s3.models import s3_backends -from moto.s3.utils import bucket_and_name_from_url from moto.ssm import ssm_backends -from .utils import random_suffix +from moto.stepfunctions import models as sfn_models # noqa # pylint: disable=all + from .exceptions import ( ExportNotFound, MissingParameterError, UnformattedGetAttTemplateException, - ValidationError, UnsupportedAttribute, + ValidationError, ) +from .utils import random_suffix CF_MODEL = TypeVar("CF_MODEL", bound=CloudFormationModel) diff --git a/moto/cloudformation/responses.py b/moto/cloudformation/responses.py index 6e9986507..cd60af8b5 100644 --- a/moto/cloudformation/responses.py +++ b/moto/cloudformation/responses.py @@ -1,16 +1,18 @@ import json import re +from typing import Any, Dict, List, Optional, Tuple, Union + import yaml -from typing import Any, Dict, Tuple, List, Optional, Union from yaml.parser import ParserError # pylint:disable=c-extension-no-member from yaml.scanner import ScannerError # pylint:disable=c-extension-no-member from moto.core.responses import BaseResponse from moto.s3.exceptions import S3ClientError from moto.utilities.aws_headers import amzn_request_id -from .models import cloudformation_backends, CloudFormationBackend, FakeStack -from .exceptions import ValidationError, MissingParameterError -from .utils import yaml_tag_constructor, get_stack_from_s3_url + +from .exceptions import MissingParameterError, ValidationError +from .models import CloudFormationBackend, FakeStack, cloudformation_backends +from .utils import get_stack_from_s3_url, yaml_tag_constructor def get_template_summary_response_from_template(template_body: str) -> Dict[str, Any]: diff --git a/moto/cloudformation/utils.py b/moto/cloudformation/utils.py index a2e749d4b..965db2b2e 100644 --- a/moto/cloudformation/utils.py +++ b/moto/cloudformation/utils.py @@ -1,10 +1,12 @@ -import yaml import os import string -from moto.moto_api._internal import mock_random as random from typing import Any, List from urllib.parse import urlparse +import yaml + +from moto.moto_api._internal import mock_random as random + def generate_stack_id(stack_name: str, region: str, account: str) -> str: random_id = random.uuid4() @@ -56,7 +58,7 @@ def yaml_tag_constructor(loader: Any, tag: Any, node: Any) -> Any: def validate_template_cfn_lint(template: str) -> List[Any]: # Importing cfnlint adds a significant overhead, so we keep it local - from cfnlint import decode, core + from cfnlint import core, decode # Save the template to a temporary file -- cfn-lint requires a file filename = "file.tmp" diff --git a/moto/cloudfront/__init__.py b/moto/cloudfront/__init__.py index b4c86b029..78f567e62 100644 --- a/moto/cloudfront/__init__.py +++ b/moto/cloudfront/__init__.py @@ -1,4 +1,4 @@ -from .models import cloudfront_backends from ..core.models import base_decorator +from .models import cloudfront_backends mock_cloudfront = base_decorator(cloudfront_backends) diff --git a/moto/cloudfront/exceptions.py b/moto/cloudfront/exceptions.py index 48dc3a5dd..584d999e4 100644 --- a/moto/cloudfront/exceptions.py +++ b/moto/cloudfront/exceptions.py @@ -1,6 +1,7 @@ -from moto.core.exceptions import RESTError from typing import Any +from moto.core.exceptions import RESTError + EXCEPTION_RESPONSE = """ diff --git a/moto/cloudfront/models.py b/moto/cloudfront/models.py index 370575425..2d7342efd 100644 --- a/moto/cloudfront/models.py +++ b/moto/cloudfront/models.py @@ -1,21 +1,21 @@ import string +from typing import Any, Dict, Iterable, List, Optional, Tuple -from typing import Any, Dict, Iterable, List, Tuple, Optional -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import iso_8601_datetime_with_milliseconds from moto.moto_api import state_manager -from moto.moto_api._internal.managed_state_model import ManagedState from moto.moto_api._internal import mock_random as random +from moto.moto_api._internal.managed_state_model import ManagedState from moto.utilities.tagging_service import TaggingService from .exceptions import ( - OriginDoesNotExist, - InvalidOriginServer, - DomainNameNotAnS3Bucket, DistributionAlreadyExists, + DomainNameNotAnS3Bucket, InvalidIfMatchVersion, + InvalidOriginServer, NoSuchDistribution, NoSuchOriginAccessControl, + OriginDoesNotExist, ) diff --git a/moto/cloudfront/responses.py b/moto/cloudfront/responses.py index 8ec785ca8..44bafcd4e 100644 --- a/moto/cloudfront/responses.py +++ b/moto/cloudfront/responses.py @@ -1,10 +1,11 @@ -import xmltodict from typing import Any, Dict from urllib.parse import unquote -from moto.core.responses import BaseResponse, TYPE_RESPONSE -from .models import cloudfront_backends, CloudFrontBackend +import xmltodict +from moto.core.responses import TYPE_RESPONSE, BaseResponse + +from .models import CloudFrontBackend, cloudfront_backends XMLNS = "http://cloudfront.amazonaws.com/doc/2020-05-31/" diff --git a/moto/cloudfront/urls.py b/moto/cloudfront/urls.py index d67e96e16..708b86a60 100644 --- a/moto/cloudfront/urls.py +++ b/moto/cloudfront/urls.py @@ -1,7 +1,6 @@ """cloudfront base URL and path.""" from .responses import CloudFrontResponse - url_bases = [ r"https?://cloudfront\.amazonaws\.com", ] diff --git a/moto/cloudtrail/__init__.py b/moto/cloudtrail/__init__.py index f15a80abb..d0f92058d 100644 --- a/moto/cloudtrail/__init__.py +++ b/moto/cloudtrail/__init__.py @@ -1,5 +1,5 @@ """cloudtrail module initialization; sets value for base decorator.""" -from .models import cloudtrail_backends from ..core.models import base_decorator +from .models import cloudtrail_backends mock_cloudtrail = base_decorator(cloudtrail_backends) diff --git a/moto/cloudtrail/models.py b/moto/cloudtrail/models.py index 686d39727..f1ddfde3a 100644 --- a/moto/cloudtrail/models.py +++ b/moto/cloudtrail/models.py @@ -1,19 +1,20 @@ import re import time - from datetime import datetime -from typing import Any, Dict, List, Optional, Iterable, Tuple -from moto.core import BaseBackend, BackendDict, BaseModel +from typing import Any, Dict, Iterable, List, Optional, Tuple + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import iso_8601_datetime_without_milliseconds, utcnow from moto.utilities.tagging_service import TaggingService + from .exceptions import ( - S3BucketDoesNotExistException, InsufficientSnsTopicPolicyException, + S3BucketDoesNotExistException, + TrailNameInvalidChars, + TrailNameNotEndingCorrectly, + TrailNameNotStartingCorrectly, TrailNameTooLong, TrailNameTooShort, - TrailNameNotStartingCorrectly, - TrailNameNotEndingCorrectly, - TrailNameInvalidChars, TrailNotFoundException, ) diff --git a/moto/cloudtrail/responses.py b/moto/cloudtrail/responses.py index fcdf2a675..a60c2cd51 100644 --- a/moto/cloudtrail/responses.py +++ b/moto/cloudtrail/responses.py @@ -1,9 +1,11 @@ """Handles incoming cloudtrail requests, invokes methods, returns responses.""" import json from typing import Any, Dict + from moto.core.responses import BaseResponse -from .models import cloudtrail_backends, CloudTrailBackend + from .exceptions import InvalidParameterCombinationException +from .models import CloudTrailBackend, cloudtrail_backends class CloudTrailResponse(BaseResponse): diff --git a/moto/cloudwatch/__init__.py b/moto/cloudwatch/__init__.py index 8114b6838..9a890c471 100644 --- a/moto/cloudwatch/__init__.py +++ b/moto/cloudwatch/__init__.py @@ -1,4 +1,4 @@ -from .models import cloudwatch_backends from ..core.models import base_decorator +from .models import cloudwatch_backends mock_cloudwatch = base_decorator(cloudwatch_backends) diff --git a/moto/cloudwatch/metric_data_expression_parser.py b/moto/cloudwatch/metric_data_expression_parser.py index 32b5fe131..9b6d86dd1 100644 --- a/moto/cloudwatch/metric_data_expression_parser.py +++ b/moto/cloudwatch/metric_data_expression_parser.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Tuple, SupportsFloat +from typing import Any, Dict, List, SupportsFloat, Tuple def parse_expression( diff --git a/moto/cloudwatch/models.py b/moto/cloudwatch/models.py index d42755ee4..42a0f8fff 100644 --- a/moto/cloudwatch/models.py +++ b/moto/cloudwatch/models.py @@ -1,28 +1,29 @@ import json +from datetime import datetime, timedelta +from typing import Any, Dict, Iterable, List, Optional, SupportsFloat, Tuple -from moto.core import BaseBackend, BackendDict, BaseModel, CloudWatchMetricProvider +from dateutil import parser +from dateutil.tz import tzutc + +from moto.core import BackendDict, BaseBackend, BaseModel, CloudWatchMetricProvider from moto.core.utils import ( - iso_8601_datetime_without_milliseconds, iso_8601_datetime_with_nanoseconds, + iso_8601_datetime_without_milliseconds, utcnow, ) from moto.moto_api._internal import mock_random -from datetime import datetime, timedelta -from dateutil.tz import tzutc +from ..utilities.tagging_service import TaggingService from .exceptions import ( InvalidFormat, - ResourceNotFound, - ValidationError, - InvalidParameterValue, - ResourceNotFoundException, InvalidParameterCombination, + InvalidParameterValue, + ResourceNotFound, + ResourceNotFoundException, + ValidationError, ) from .metric_data_expression_parser import parse_expression -from .utils import make_arn_for_dashboard, make_arn_for_alarm -from dateutil import parser -from typing import Tuple, Optional, List, Iterable, Dict, Any, SupportsFloat -from ..utilities.tagging_service import TaggingService +from .utils import make_arn_for_alarm, make_arn_for_dashboard _EMPTY_LIST: Any = tuple() diff --git a/moto/cloudwatch/responses.py b/moto/cloudwatch/responses.py index 0ebfe3932..527784476 100644 --- a/moto/cloudwatch/responses.py +++ b/moto/cloudwatch/responses.py @@ -1,20 +1,21 @@ import json +from typing import Dict, Iterable, List, Tuple, Union from dateutil.parser import parse as dtparse -from typing import Dict, List, Iterable, Tuple, Union + from moto.core.responses import BaseResponse from moto.utilities.aws_headers import amzn_request_id + +from .exceptions import InvalidParameterCombination, ValidationError from .models import ( - cloudwatch_backends, CloudWatchBackend, - MetricDataQuery, - MetricStat, - Metric, Dimension, FakeAlarm, + Metric, + MetricDataQuery, + MetricStat, + cloudwatch_backends, ) -from .exceptions import InvalidParameterCombination, ValidationError - ERROR_RESPONSE = Tuple[str, Dict[str, int]] diff --git a/moto/codebuild/__init__.py b/moto/codebuild/__init__.py index 3b7d181d1..764bd3255 100644 --- a/moto/codebuild/__init__.py +++ b/moto/codebuild/__init__.py @@ -1,4 +1,4 @@ -from .models import codebuild_backends from ..core.models import base_decorator +from .models import codebuild_backends mock_codebuild = base_decorator(codebuild_backends) diff --git a/moto/codebuild/models.py b/moto/codebuild/models.py index b4991372f..8442f554f 100644 --- a/moto/codebuild/models.py +++ b/moto/codebuild/models.py @@ -1,10 +1,12 @@ -from moto.core import BaseBackend, BackendDict, BaseModel +import datetime +from collections import defaultdict +from typing import Any, Dict, List, Optional + +from dateutil import parser + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import iso_8601_datetime_with_milliseconds from moto.moto_api._internal import mock_random -from collections import defaultdict -from dateutil import parser -from typing import Any, Dict, List, Optional -import datetime class CodeBuildProjectMetadata(BaseModel): diff --git a/moto/codebuild/responses.py b/moto/codebuild/responses.py index b30a136c0..bcdaecef5 100644 --- a/moto/codebuild/responses.py +++ b/moto/codebuild/responses.py @@ -1,13 +1,15 @@ +import json +import re +from typing import Any, Dict, List + from moto.core.responses import BaseResponse -from .models import codebuild_backends, CodeBuildBackend + from .exceptions import ( InvalidInputException, ResourceAlreadyExistsException, ResourceNotFoundException, ) -import json -import re -from typing import Any, Dict, List +from .models import CodeBuildBackend, codebuild_backends def _validate_required_params_source(source: Dict[str, Any]) -> None: diff --git a/moto/codecommit/__init__.py b/moto/codecommit/__init__.py index 6c5a8f5ad..6deffd1d6 100644 --- a/moto/codecommit/__init__.py +++ b/moto/codecommit/__init__.py @@ -1,4 +1,4 @@ -from .models import codecommit_backends from ..core.models import base_decorator +from .models import codecommit_backends mock_codecommit = base_decorator(codecommit_backends) diff --git a/moto/codecommit/models.py b/moto/codecommit/models.py index b3e027262..bcce77106 100644 --- a/moto/codecommit/models.py +++ b/moto/codecommit/models.py @@ -1,7 +1,9 @@ -from moto.core import BaseBackend, BackendDict, BaseModel +from typing import Dict, List, Optional + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import iso_8601_datetime_with_milliseconds from moto.moto_api._internal import mock_random -from typing import Dict, List, Optional + from .exceptions import RepositoryDoesNotExistException, RepositoryNameExistsException diff --git a/moto/codecommit/responses.py b/moto/codecommit/responses.py index 62290e8ab..28b57d301 100644 --- a/moto/codecommit/responses.py +++ b/moto/codecommit/responses.py @@ -2,8 +2,9 @@ import json import re from moto.core.responses import BaseResponse -from .models import codecommit_backends, CodeCommitBackend + from .exceptions import InvalidRepositoryNameException +from .models import CodeCommitBackend, codecommit_backends def _is_repository_name_valid(repository_name: str) -> bool: diff --git a/moto/codepipeline/__init__.py b/moto/codepipeline/__init__.py index da1f1fa9d..ad16612da 100644 --- a/moto/codepipeline/__init__.py +++ b/moto/codepipeline/__init__.py @@ -1,4 +1,4 @@ -from .models import codepipeline_backends from ..core.models import base_decorator +from .models import codepipeline_backends mock_codepipeline = base_decorator(codepipeline_backends) diff --git a/moto/codepipeline/models.py b/moto/codepipeline/models.py index 354aba641..a0deadafa 100644 --- a/moto/codepipeline/models.py +++ b/moto/codepipeline/models.py @@ -1,17 +1,17 @@ import json from typing import Any, Dict, List, Tuple -from moto.core.utils import iso_8601_datetime_with_milliseconds, utcnow -from moto.iam.exceptions import IAMNotFoundException -from moto.iam.models import iam_backends, IAMBackend from moto.codepipeline.exceptions import ( InvalidStructureException, + InvalidTagsException, PipelineNotFoundException, ResourceNotFoundException, - InvalidTagsException, TooManyTagsException, ) -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel +from moto.core.utils import iso_8601_datetime_with_milliseconds, utcnow +from moto.iam.exceptions import IAMNotFoundException +from moto.iam.models import IAMBackend, iam_backends class CodePipeline(BaseModel): diff --git a/moto/codepipeline/responses.py b/moto/codepipeline/responses.py index 442e9dbe1..22a258750 100644 --- a/moto/codepipeline/responses.py +++ b/moto/codepipeline/responses.py @@ -1,7 +1,8 @@ import json from moto.core.responses import BaseResponse -from .models import codepipeline_backends, CodePipelineBackend + +from .models import CodePipelineBackend, codepipeline_backends class CodePipelineResponse(BaseResponse): diff --git a/moto/cognitoidentity/__init__.py b/moto/cognitoidentity/__init__.py index 4ea132a84..b872dea30 100644 --- a/moto/cognitoidentity/__init__.py +++ b/moto/cognitoidentity/__init__.py @@ -1,4 +1,4 @@ -from .models import cognitoidentity_backends from ..core.models import base_decorator +from .models import cognitoidentity_backends mock_cognitoidentity = base_decorator(cognitoidentity_backends) diff --git a/moto/cognitoidentity/models.py b/moto/cognitoidentity/models.py index 2be58aa7f..c8c8cddb0 100644 --- a/moto/cognitoidentity/models.py +++ b/moto/cognitoidentity/models.py @@ -1,11 +1,12 @@ import datetime import json import re - from collections import OrderedDict from typing import Any, Dict, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import utcnow + from .exceptions import InvalidNameException, ResourceNotFoundError from .utils import get_random_identity_id diff --git a/moto/cognitoidentity/responses.py b/moto/cognitoidentity/responses.py index ba1d157bc..0a8dacba0 100644 --- a/moto/cognitoidentity/responses.py +++ b/moto/cognitoidentity/responses.py @@ -1,5 +1,6 @@ from moto.core.responses import BaseResponse -from .models import cognitoidentity_backends, CognitoIdentityBackend + +from .models import CognitoIdentityBackend, cognitoidentity_backends from .utils import get_random_identity_id diff --git a/moto/cognitoidp/__init__.py b/moto/cognitoidp/__init__.py index 09d8043c1..266037962 100644 --- a/moto/cognitoidp/__init__.py +++ b/moto/cognitoidp/__init__.py @@ -1,4 +1,4 @@ -from .models import cognitoidp_backends from ..core.models import base_decorator +from .models import cognitoidp_backends mock_cognitoidp = base_decorator(cognitoidp_backends) diff --git a/moto/cognitoidp/exceptions.py b/moto/cognitoidp/exceptions.py index 8271af59e..b0bdac427 100644 --- a/moto/cognitoidp/exceptions.py +++ b/moto/cognitoidp/exceptions.py @@ -1,6 +1,7 @@ -from moto.core.exceptions import JsonRESTError from typing import Optional +from moto.core.exceptions import JsonRESTError + class AliasExistsException(JsonRESTError): def __init__(self) -> None: diff --git a/moto/cognitoidp/models.py b/moto/cognitoidp/models.py index f6ddc62e0..e8ec348a6 100644 --- a/moto/cognitoidp/models.py +++ b/moto/cognitoidp/models.py @@ -1,40 +1,43 @@ import datetime +import enum import json import os +import re import time import typing -import enum -import re -from jose import jws from collections import OrderedDict -from typing import Any, Dict, List, Tuple, Optional, Set -from moto.core import BaseBackend, BackendDict, BaseModel +from typing import Any, Dict, List, Optional, Set, Tuple + +from jose import jws + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import utcnow from moto.moto_api._internal import mock_random as random -from .exceptions import ( - AliasExistsException, - GroupExistsException, - NotAuthorizedError, - ResourceNotFoundError, - UserNotFoundError, - UsernameExistsException, - UserNotConfirmedException, - InvalidParameterException, - ExpiredCodeException, - InvalidPasswordException, -) -from .utils import ( - create_id, - check_secret_hash, - generate_id, - validate_username_format, - flatten_attrs, - expand_attrs, - PAGINATION_MODEL, -) from moto.utilities.paginator import paginate from moto.utilities.utils import md5_hash + from ..settings import get_cognito_idp_user_pool_id_strategy +from .exceptions import ( + AliasExistsException, + ExpiredCodeException, + GroupExistsException, + InvalidParameterException, + InvalidPasswordException, + NotAuthorizedError, + ResourceNotFoundError, + UsernameExistsException, + UserNotConfirmedException, + UserNotFoundError, +) +from .utils import ( + PAGINATION_MODEL, + check_secret_hash, + create_id, + expand_attrs, + flatten_attrs, + generate_id, + validate_username_format, +) class UserStatus(str, enum.Enum): diff --git a/moto/cognitoidp/responses.py b/moto/cognitoidp/responses.py index a76369c94..a302ba881 100644 --- a/moto/cognitoidp/responses.py +++ b/moto/cognitoidp/responses.py @@ -4,15 +4,15 @@ import re from typing import Any, Dict, Tuple from moto.core.responses import BaseResponse + +from .exceptions import InvalidParameterException from .models import ( - cognitoidp_backends, - find_account_region_by_value, + CognitoIdpBackend, RegionAgnosticBackend, UserStatus, - CognitoIdpBackend, + cognitoidp_backends, + find_account_region_by_value, ) -from .exceptions import InvalidParameterException - region_agnostic_backend = RegionAgnosticBackend() diff --git a/moto/cognitoidp/urls.py b/moto/cognitoidp/urls.py index a08831178..84d657b4c 100644 --- a/moto/cognitoidp/urls.py +++ b/moto/cognitoidp/urls.py @@ -1,4 +1,4 @@ -from .responses import CognitoIdpResponse, CognitoIdpJsonWebKeyResponse +from .responses import CognitoIdpJsonWebKeyResponse, CognitoIdpResponse url_bases = [r"https?://cognito-idp\.(.+)\.amazonaws.com"] diff --git a/moto/cognitoidp/utils.py b/moto/cognitoidp/utils.py index de5077fc5..5a758ffcf 100644 --- a/moto/cognitoidp/utils.py +++ b/moto/cognitoidp/utils.py @@ -1,11 +1,12 @@ -import string +import base64 import hashlib import hmac -import base64 import re -from moto.moto_api._internal import mock_random as random +import string from typing import Any, Dict, List, Optional +from moto.moto_api._internal import mock_random as random + FORMATS = { "email": r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b", "phone_number": r"\+\d{,15}", diff --git a/moto/comprehend/__init__.py b/moto/comprehend/__init__.py index 02195a5fc..cbbfbb193 100644 --- a/moto/comprehend/__init__.py +++ b/moto/comprehend/__init__.py @@ -1,5 +1,5 @@ """comprehend module initialization; sets value for base decorator.""" -from .models import comprehend_backends from ..core.models import base_decorator +from .models import comprehend_backends mock_comprehend = base_decorator(comprehend_backends) diff --git a/moto/comprehend/exceptions.py b/moto/comprehend/exceptions.py index 0530214af..d4e808d4c 100644 --- a/moto/comprehend/exceptions.py +++ b/moto/comprehend/exceptions.py @@ -1,7 +1,8 @@ """Exceptions raised by the comprehend service.""" -from moto.core.exceptions import JsonRESTError from typing import List +from moto.core.exceptions import JsonRESTError + class ResourceNotFound(JsonRESTError): def __init__(self) -> None: diff --git a/moto/comprehend/models.py b/moto/comprehend/models.py index c06dac041..c6543a41c 100644 --- a/moto/comprehend/models.py +++ b/moto/comprehend/models.py @@ -1,13 +1,15 @@ """ComprehendBackend class with methods for supported APIs.""" -from moto.core import BaseBackend, BackendDict, BaseModel +from typing import Any, Dict, Iterable, List + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.utilities.tagging_service import TaggingService + from .exceptions import ( - ResourceNotFound, DetectPIIValidationException, + ResourceNotFound, TextSizeLimitExceededException, ) -from typing import Any, Dict, List, Iterable CANNED_DETECT_RESPONSE = [ { diff --git a/moto/comprehend/responses.py b/moto/comprehend/responses.py index d439d853d..339fdd199 100644 --- a/moto/comprehend/responses.py +++ b/moto/comprehend/responses.py @@ -2,7 +2,8 @@ import json from moto.core.responses import BaseResponse -from .models import comprehend_backends, ComprehendBackend + +from .models import ComprehendBackend, comprehend_backends class ComprehendResponse(BaseResponse): diff --git a/moto/config/__init__.py b/moto/config/__init__.py index 9ca6a5917..785efe1b0 100644 --- a/moto/config/__init__.py +++ b/moto/config/__init__.py @@ -1,4 +1,4 @@ -from .models import config_backends from ..core.models import base_decorator +from .models import config_backends mock_config = base_decorator(config_backends) diff --git a/moto/config/exceptions.py b/moto/config/exceptions.py index f14b89e30..bbbc09da1 100644 --- a/moto/config/exceptions.py +++ b/moto/config/exceptions.py @@ -1,6 +1,7 @@ -from moto.core.exceptions import JsonRESTError from typing import Any, List, Optional +from moto.core.exceptions import JsonRESTError + class NameTooLongException(JsonRESTError): code = 400 diff --git a/moto/config/models.py b/moto/config/models.py index 83bbf4ed3..f324884d2 100644 --- a/moto/config/models.py +++ b/moto/config/models.py @@ -2,65 +2,62 @@ import json import re import time - from datetime import datetime from typing import Any, Dict, List, Optional, Union from moto.config.exceptions import ( - InvalidResourceTypeException, - InvalidDeliveryFrequency, + DuplicateTags, + InsufficientPermissionsException, InvalidConfigurationRecorderNameException, - NameTooLongException, - MaxNumberOfConfigurationRecordersExceededException, - InvalidRecordingGroupException, - NoSuchConfigurationRecorderException, - NoAvailableConfigurationRecorderException, InvalidDeliveryChannelNameException, - NoSuchBucketException, + InvalidDeliveryFrequency, + InvalidLimitException, + InvalidNextTokenException, + InvalidParameterValueException, + InvalidRecordingGroupException, + InvalidResourceParameters, + InvalidResourceTypeException, + InvalidResultTokenException, InvalidS3KeyPrefixException, InvalidS3KmsKeyArnException, InvalidSNSTopicARNException, - MaxNumberOfDeliveryChannelsExceededException, - NoAvailableDeliveryChannelException, - NoSuchDeliveryChannelException, - LastDeliveryChannelDeleteFailedException, - TagKeyTooBig, - TooManyTags, - TagValueTooBig, - TooManyAccountSources, - InvalidParameterValueException, - InvalidNextTokenException, - NoSuchConfigurationAggregatorException, InvalidTagCharacters, - DuplicateTags, - InvalidLimitException, - InvalidResourceParameters, - TooManyResourceIds, - ResourceNotDiscoveredException, - ResourceNotFoundException, - TooManyResourceKeys, - InvalidResultTokenException, - ValidationException, - NoSuchOrganizationConformancePackException, + LastDeliveryChannelDeleteFailedException, MaxNumberOfConfigRulesExceededException, - InsufficientPermissionsException, + MaxNumberOfConfigurationRecordersExceededException, + MaxNumberOfDeliveryChannelsExceededException, + MissingRequiredConfigRuleParameterException, + NameTooLongException, + NoAvailableConfigurationRecorderException, + NoAvailableDeliveryChannelException, + NoSuchBucketException, NoSuchConfigRuleException, + NoSuchConfigurationAggregatorException, + NoSuchConfigurationRecorderException, + NoSuchDeliveryChannelException, + NoSuchOrganizationConformancePackException, NoSuchRetentionConfigurationException, ResourceInUseException, - MissingRequiredConfigRuleParameterException, + ResourceNotDiscoveredException, + ResourceNotFoundException, + TagKeyTooBig, + TagValueTooBig, + TooManyAccountSources, + TooManyResourceIds, + TooManyResourceKeys, + TooManyTags, + ValidationException, ) - -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.common_models import ConfigQueryModel from moto.core.responses import AWSServiceSpec from moto.core.utils import utcnow -from moto.iam.config import role_config_query, policy_config_query +from moto.iam.config import policy_config_query, role_config_query from moto.moto_api._internal import mock_random as random from moto.s3.config import s3_config_query from moto.s3control.config import s3_account_public_access_block_query from moto.utilities.utils import load_resource - POP_STRINGS = [ "capitalizeStart", "CapitalizeStart", diff --git a/moto/config/responses.py b/moto/config/responses.py index c06db5a8a..d488133a5 100644 --- a/moto/config/responses.py +++ b/moto/config/responses.py @@ -1,6 +1,8 @@ import json + from moto.core.responses import BaseResponse -from .models import config_backends, ConfigBackend + +from .models import ConfigBackend, config_backends class ConfigResponse(BaseResponse): diff --git a/moto/core/base_backend.py b/moto/core/base_backend.py index b694b37e7..d05a46526 100644 --- a/moto/core/base_backend.py +++ b/moto/core/base_backend.py @@ -1,11 +1,14 @@ -from boto3 import Session import re import string from functools import lru_cache from threading import RLock -from typing import Any, List, Dict, Optional, ClassVar, TypeVar, Iterator +from typing import Any, ClassVar, Dict, Iterator, List, Optional, TypeVar from uuid import uuid4 + +from boto3 import Session + from moto.settings import allow_unknown_region, enable_iso_regions + from .model_instances import model_data from .utils import convert_regex_to_flask_path diff --git a/moto/core/botocore_stubber.py b/moto/core/botocore_stubber.py index 7c41e6dfa..1319b6727 100644 --- a/moto/core/botocore_stubber.py +++ b/moto/core/botocore_stubber.py @@ -1,8 +1,11 @@ from collections import defaultdict from io import BytesIO +from typing import Any, Callable, Dict, List, Pattern, Tuple, Union + from botocore.awsrequest import AWSResponse + from moto.core.exceptions import HTTPException -from typing import Any, Dict, Callable, List, Tuple, Union, Pattern + from .responses import TYPE_RESPONSE diff --git a/moto/core/common_models.py b/moto/core/common_models.py index 8848f1c29..f070e1a7e 100644 --- a/moto/core/common_models.py +++ b/moto/core/common_models.py @@ -1,5 +1,6 @@ from abc import abstractmethod from typing import Any, Dict, List, Optional, Tuple + from .base_backend import InstanceTrackerMeta diff --git a/moto/core/common_types.py b/moto/core/common_types.py index 0e1741721..873edea93 100644 --- a/moto/core/common_types.py +++ b/moto/core/common_types.py @@ -1,5 +1,4 @@ from typing import Any, Dict, Tuple, TypeVar, Union - TYPE_RESPONSE = Tuple[int, Dict[str, Any], Union[str, bytes]] TYPE_IF_NONE = TypeVar("TYPE_IF_NONE") diff --git a/moto/core/custom_responses_mock.py b/moto/core/custom_responses_mock.py index e72cf4810..b6ea9f433 100644 --- a/moto/core/custom_responses_mock.py +++ b/moto/core/custom_responses_mock.py @@ -1,14 +1,16 @@ -import responses import types -from io import BytesIO from http.client import responses as http_responses -from typing import Any, Dict, List, Tuple, Optional +from io import BytesIO +from typing import Any, Dict, List, Optional, Tuple from urllib.parse import urlparse + +import responses from werkzeug.wrappers import Request -from .responses import TYPE_RESPONSE from moto.core.versions import is_responses_0_17_x +from .responses import TYPE_RESPONSE + class CallbackResponse(responses.CallbackResponse): """ diff --git a/moto/core/exceptions.py b/moto/core/exceptions.py index 63860533a..ee9a07820 100644 --- a/moto/core/exceptions.py +++ b/moto/core/exceptions.py @@ -1,8 +1,8 @@ -from werkzeug.exceptions import HTTPException -from jinja2 import DictLoader, Environment -from typing import Any, List, Tuple, Optional import json +from typing import Any, List, Optional, Tuple +from jinja2 import DictLoader, Environment +from werkzeug.exceptions import HTTPException SINGLE_ERROR_RESPONSE = """ diff --git a/moto/core/models.py b/moto/core/models.py index 5cae8286b..1bcada3e7 100644 --- a/moto/core/models.py +++ b/moto/core/models.py @@ -5,8 +5,18 @@ import os import re import unittest from types import FunctionType -from typing import Any, Callable, Dict, Optional, Set, TypeVar, Union, overload -from typing import ContextManager, TYPE_CHECKING +from typing import ( + TYPE_CHECKING, + Any, + Callable, + ContextManager, + Dict, + Optional, + Set, + TypeVar, + Union, + overload, +) from unittest.mock import patch import boto3 @@ -16,11 +26,12 @@ from botocore.config import Config from botocore.handlers import BUILTIN_HANDLERS from moto import settings + from .base_backend import BackendDict from .botocore_stubber import BotocoreStubber from .custom_responses_mock import ( - get_response_mock, CallbackResponse, + get_response_mock, not_implemented_callback, reset_responses_mock, ) @@ -414,7 +425,8 @@ class ServerModeMockAWS(BaseMockAWS): # Just started self.reset() - from boto3 import client as real_boto3_client, resource as real_boto3_resource + from boto3 import client as real_boto3_client + from boto3 import resource as real_boto3_resource def fake_boto3_client(*args: Any, **kwargs: Any) -> botocore.client.BaseClient: region = self._get_region(*args, **kwargs) @@ -478,7 +490,8 @@ class ProxyModeMockAWS(BaseMockAWS): # Just started self.reset() - from boto3 import client as real_boto3_client, resource as real_boto3_resource + from boto3 import client as real_boto3_client + from boto3 import resource as real_boto3_resource def fake_boto3_client(*args: Any, **kwargs: Any) -> botocore.client.BaseClient: kwargs["verify"] = False diff --git a/moto/core/responses.py b/moto/core/responses.py index 5d27e60bd..828370973 100644 --- a/moto/core/responses.py +++ b/moto/core/responses.py @@ -1,16 +1,33 @@ -import boto3 -import functools import datetime +import functools import json import logging import os import re +from collections import OrderedDict, defaultdict +from typing import ( + Any, + Callable, + ClassVar, + Dict, + List, + Optional, + Set, + Tuple, + TypeVar, + Union, +) +from urllib.parse import parse_qs, parse_qsl, urlparse +from xml.dom.minidom import parseString as parseXML + +import boto3 import requests import xmltodict +from jinja2 import DictLoader, Environment, Template +from werkzeug.exceptions import HTTPException -from collections import defaultdict, OrderedDict from moto import settings -from moto.core.common_types import TYPE_RESPONSE, TYPE_IF_NONE +from moto.core.common_types import TYPE_IF_NONE, TYPE_RESPONSE from moto.core.exceptions import DryRunClientError from moto.core.utils import ( camelcase_to_underscores, @@ -19,23 +36,6 @@ from moto.core.utils import ( params_sort_function, ) from moto.utilities.utils import load_resource, load_resource_as_bytes -from jinja2 import Environment, DictLoader, Template -from typing import ( - Dict, - Union, - Any, - Tuple, - Optional, - List, - Set, - ClassVar, - Callable, - TypeVar, -) -from urllib.parse import parse_qs, parse_qsl, urlparse -from werkzeug.exceptions import HTTPException -from xml.dom.minidom import parseString as parseXML - log = logging.getLogger(__name__) diff --git a/moto/core/responses_custom_registry.py b/moto/core/responses_custom_registry.py index 3de222fe7..b83a2d286 100644 --- a/moto/core/responses_custom_registry.py +++ b/moto/core/responses_custom_registry.py @@ -1,7 +1,9 @@ # This will only exist in responses >= 0.17 -import responses from collections import defaultdict -from typing import Any, Dict, List, Tuple, Optional +from typing import Any, Dict, List, Optional, Tuple + +import responses + from .custom_responses_mock import CallbackResponse, not_implemented_callback diff --git a/moto/core/utils.py b/moto/core/utils.py index 6cbc7cd3f..3709dddbd 100644 --- a/moto/core/utils.py +++ b/moto/core/utils.py @@ -1,10 +1,12 @@ import datetime import inspect import re -from botocore.exceptions import ClientError from gzip import decompress -from typing import Any, Optional, List, Callable, Dict, Tuple +from typing import Any, Callable, Dict, List, Optional, Tuple from urllib.parse import urlparse + +from botocore.exceptions import ClientError + from .common_types import TYPE_RESPONSE from .versions import PYTHON_311 @@ -100,7 +102,8 @@ class convert_to_flask_response(object): return f"{outer}.{self.callback.__name__}" def __call__(self, args: Any = None, **kwargs: Any) -> Any: - from flask import request, Response + from flask import Response, request + from moto.moto_api import recorder try: diff --git a/moto/databrew/__init__.py b/moto/databrew/__init__.py index 34fff819d..66de01886 100644 --- a/moto/databrew/__init__.py +++ b/moto/databrew/__init__.py @@ -1,4 +1,4 @@ -from .models import databrew_backends from ..core.models import base_decorator +from .models import databrew_backends mock_databrew = base_decorator(databrew_backends) diff --git a/moto/databrew/models.py b/moto/databrew/models.py index 7e2cde5d0..6b14676b1 100644 --- a/moto/databrew/models.py +++ b/moto/databrew/models.py @@ -1,25 +1,21 @@ -from abc import ABCMeta -from abc import abstractmethod - +import math +from abc import ABCMeta, abstractmethod from collections import OrderedDict from copy import deepcopy -import math from datetime import datetime from typing import Any, Dict, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel -from moto.core.utils import underscores_to_camelcase -from moto.core.utils import camelcase_to_pascal - +from moto.core import BackendDict, BaseBackend, BaseModel +from moto.core.utils import camelcase_to_pascal, underscores_to_camelcase from moto.utilities.paginator import paginate from .exceptions import ( AlreadyExistsException, ConflictException, - ValidationException, + ResourceNotFoundException, RulesetAlreadyExistsException, RulesetNotFoundException, - ResourceNotFoundException, + ValidationException, ) diff --git a/moto/databrew/responses.py b/moto/databrew/responses.py index 826340830..28d2e86c8 100644 --- a/moto/databrew/responses.py +++ b/moto/databrew/responses.py @@ -5,7 +5,8 @@ from urllib.parse import unquote from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse from moto.utilities.aws_headers import amzn_request_id -from .models import databrew_backends, DataBrewBackend + +from .models import DataBrewBackend, databrew_backends class DataBrewResponse(BaseResponse): diff --git a/moto/datapipeline/__init__.py b/moto/datapipeline/__init__.py index 4287cee03..65d36727c 100644 --- a/moto/datapipeline/__init__.py +++ b/moto/datapipeline/__init__.py @@ -1,4 +1,4 @@ -from .models import datapipeline_backends from ..core.models import base_decorator +from .models import datapipeline_backends mock_datapipeline = base_decorator(datapipeline_backends) diff --git a/moto/datapipeline/models.py b/moto/datapipeline/models.py index 71727501c..535beb4a5 100644 --- a/moto/datapipeline/models.py +++ b/moto/datapipeline/models.py @@ -1,11 +1,12 @@ import datetime - from collections import OrderedDict -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel -from moto.core.utils import utcnow -from .utils import get_random_pipeline_id, remove_capitalization_of_dict_keys from typing import Any, Dict, Iterable, List +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel +from moto.core.utils import utcnow + +from .utils import get_random_pipeline_id, remove_capitalization_of_dict_keys + class PipelineObject(BaseModel): def __init__(self, object_id: str, name: str, fields: Any): diff --git a/moto/datapipeline/responses.py b/moto/datapipeline/responses.py index ce7bd4fdc..614278587 100644 --- a/moto/datapipeline/responses.py +++ b/moto/datapipeline/responses.py @@ -1,7 +1,8 @@ import json from moto.core.responses import BaseResponse -from .models import datapipeline_backends, DataPipelineBackend + +from .models import DataPipelineBackend, datapipeline_backends class DataPipelineResponse(BaseResponse): diff --git a/moto/datapipeline/utils.py b/moto/datapipeline/utils.py index 99e552582..f22a702c4 100644 --- a/moto/datapipeline/utils.py +++ b/moto/datapipeline/utils.py @@ -1,7 +1,8 @@ import collections.abc as collections_abc -from moto.moto_api._internal import mock_random from typing import Any +from moto.moto_api._internal import mock_random + def get_random_pipeline_id() -> str: return f"df-{mock_random.get_random_hex(length=19)}" diff --git a/moto/datasync/exceptions.py b/moto/datasync/exceptions.py index 6a4b40b24..5d5686ffb 100644 --- a/moto/datasync/exceptions.py +++ b/moto/datasync/exceptions.py @@ -1,6 +1,7 @@ -from moto.core.exceptions import JsonRESTError from typing import Optional +from moto.core.exceptions import JsonRESTError + class DataSyncClientError(JsonRESTError): code = 400 diff --git a/moto/datasync/models.py b/moto/datasync/models.py index 16b4de468..c66691818 100644 --- a/moto/datasync/models.py +++ b/moto/datasync/models.py @@ -1,6 +1,7 @@ from collections import OrderedDict from typing import Any, Dict, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel + +from moto.core import BackendDict, BaseBackend, BaseModel from .exceptions import InvalidRequestException diff --git a/moto/datasync/responses.py b/moto/datasync/responses.py index 2699db9dd..9f7edd8b7 100644 --- a/moto/datasync/responses.py +++ b/moto/datasync/responses.py @@ -2,7 +2,7 @@ import json from moto.core.responses import BaseResponse -from .models import datasync_backends, DataSyncBackend, Location +from .models import DataSyncBackend, Location, datasync_backends class DataSyncResponse(BaseResponse): diff --git a/moto/dax/__init__.py b/moto/dax/__init__.py index 21ac86e6e..13e8910ba 100644 --- a/moto/dax/__init__.py +++ b/moto/dax/__init__.py @@ -1,5 +1,5 @@ """dax module initialization; sets value for base decorator.""" -from .models import dax_backends from ..core.models import base_decorator +from .models import dax_backends mock_dax = base_decorator(dax_backends) diff --git a/moto/dax/exceptions.py b/moto/dax/exceptions.py index 7c50aa039..7a7d726b3 100644 --- a/moto/dax/exceptions.py +++ b/moto/dax/exceptions.py @@ -1,6 +1,7 @@ -from moto.core.exceptions import JsonRESTError from typing import Optional +from moto.core.exceptions import JsonRESTError + class InvalidParameterValueException(JsonRESTError): def __init__(self, message: str): diff --git a/moto/dax/models.py b/moto/dax/models.py index 6dcd1fb47..82439c475 100644 --- a/moto/dax/models.py +++ b/moto/dax/models.py @@ -1,12 +1,13 @@ """DAXBackend class with methods for supported APIs.""" -from moto.core import BaseBackend, BackendDict, BaseModel +from typing import Any, Dict, Iterable, List + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import unix_time from moto.moto_api import state_manager from moto.moto_api._internal import mock_random as random from moto.moto_api._internal.managed_state_model import ManagedState -from moto.utilities.tagging_service import TaggingService from moto.utilities.paginator import paginate -from typing import Any, Dict, List, Iterable +from moto.utilities.tagging_service import TaggingService from .exceptions import ClusterNotFoundFault from .utils import PAGINATION_MODEL diff --git a/moto/dax/responses.py b/moto/dax/responses.py index 86af7806d..105d64c56 100644 --- a/moto/dax/responses.py +++ b/moto/dax/responses.py @@ -2,8 +2,9 @@ import json import re from moto.core.responses import BaseResponse + from .exceptions import InvalidParameterValueException -from .models import dax_backends, DAXBackend +from .models import DAXBackend, dax_backends class DAXResponse(BaseResponse): diff --git a/moto/dms/__init__.py b/moto/dms/__init__.py index af997e2c1..75679f6fc 100644 --- a/moto/dms/__init__.py +++ b/moto/dms/__init__.py @@ -1,5 +1,5 @@ -from .models import dms_backends from ..core.models import base_decorator +from .models import dms_backends dms_backend = dms_backends["us-east-1"] mock_dms = base_decorator(dms_backends) diff --git a/moto/dms/models.py b/moto/dms/models.py index ad8719a4f..51bad6c7a 100644 --- a/moto/dms/models.py +++ b/moto/dms/models.py @@ -1,6 +1,7 @@ from datetime import datetime -from typing import Any, Dict, List, Iterable, Optional -from moto.core import BaseBackend, BackendDict, BaseModel +from typing import Any, Dict, Iterable, List, Optional + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import utcnow from .exceptions import ( diff --git a/moto/dms/responses.py b/moto/dms/responses.py index cdb99e386..6d22c7d33 100644 --- a/moto/dms/responses.py +++ b/moto/dms/responses.py @@ -1,7 +1,9 @@ -from moto.core.responses import BaseResponse -from .models import dms_backends, DatabaseMigrationServiceBackend import json +from moto.core.responses import BaseResponse + +from .models import DatabaseMigrationServiceBackend, dms_backends + class DatabaseMigrationServiceResponse(BaseResponse): def __init__(self) -> None: diff --git a/moto/dms/utils.py b/moto/dms/utils.py index 3cbf33e2d..a878e6f94 100644 --- a/moto/dms/utils.py +++ b/moto/dms/utils.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Iterable +from typing import Any, Dict, Iterable, List def match_task_arn(task: Dict[str, Any], arns: List[str]) -> bool: diff --git a/moto/ds/__init__.py b/moto/ds/__init__.py index 7195bf189..1fec2356d 100644 --- a/moto/ds/__init__.py +++ b/moto/ds/__init__.py @@ -1,5 +1,5 @@ """ds module initialization; sets value for base decorator.""" -from .models import ds_backends from ..core.models import base_decorator +from .models import ds_backends mock_ds = base_decorator(ds_backends) diff --git a/moto/ds/exceptions.py b/moto/ds/exceptions.py index ac1dbbc9c..f34016463 100644 --- a/moto/ds/exceptions.py +++ b/moto/ds/exceptions.py @@ -1,7 +1,8 @@ """Exceptions raised by the Directory Service service.""" -from moto.core.exceptions import JsonRESTError from typing import List, Tuple +from moto.core.exceptions import JsonRESTError + class DsValidationException(JsonRESTError): """Report one of more parameter validation errors.""" diff --git a/moto/ds/models.py b/moto/ds/models.py index 20205ac8c..679cb33be 100644 --- a/moto/ds/models.py +++ b/moto/ds/models.py @@ -1,8 +1,8 @@ """DirectoryServiceBackend class with methods for supported APIs.""" from datetime import datetime, timezone -from typing import Any, Dict, Optional, Tuple, List +from typing import Any, Dict, List, Optional, Tuple -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.ds.exceptions import ( ClientException, DirectoryLimitExceededException, @@ -14,8 +14,8 @@ from moto.ds.exceptions import ( ) from moto.ds.utils import PAGINATION_MODEL from moto.ds.validations import validate_args -from moto.ec2.exceptions import InvalidSubnetIdError from moto.ec2 import ec2_backends +from moto.ec2.exceptions import InvalidSubnetIdError from moto.moto_api._internal import mock_random from moto.utilities.paginator import paginate from moto.utilities.tagging_service import TaggingService diff --git a/moto/ds/responses.py b/moto/ds/responses.py index 46d204c1e..4fc711467 100644 --- a/moto/ds/responses.py +++ b/moto/ds/responses.py @@ -4,7 +4,7 @@ import json from moto.core.exceptions import InvalidToken from moto.core.responses import BaseResponse from moto.ds.exceptions import InvalidNextTokenException -from moto.ds.models import ds_backends, DirectoryServiceBackend +from moto.ds.models import DirectoryServiceBackend, ds_backends class DirectoryServiceResponse(BaseResponse): diff --git a/moto/dynamodb/__init__.py b/moto/dynamodb/__init__.py index 0f01dbaf2..cd9bdca12 100644 --- a/moto/dynamodb/__init__.py +++ b/moto/dynamodb/__init__.py @@ -1,4 +1,5 @@ from moto.dynamodb.models import dynamodb_backends + from ..core.models import base_decorator dynamodb_backend = dynamodb_backends["us-east-1"] diff --git a/moto/dynamodb/comparisons.py b/moto/dynamodb/comparisons.py index 3f330dc84..e9aa44bb3 100644 --- a/moto/dynamodb/comparisons.py +++ b/moto/dynamodb/comparisons.py @@ -1,9 +1,9 @@ import re from collections import deque, namedtuple -from typing import Any, Dict, List, Tuple, Deque, Optional, Iterable, Union +from typing import Any, Deque, Dict, Iterable, List, Optional, Tuple, Union -from moto.dynamodb.models.dynamo_type import Item from moto.dynamodb.exceptions import ConditionAttributeIsReservedKeyword +from moto.dynamodb.models.dynamo_type import Item from moto.dynamodb.parsing.reserved_keywords import ReservedKeywords diff --git a/moto/dynamodb/exceptions.py b/moto/dynamodb/exceptions.py index 029e8eb32..869e22a49 100644 --- a/moto/dynamodb/exceptions.py +++ b/moto/dynamodb/exceptions.py @@ -1,9 +1,9 @@ import json from typing import Any, Dict, List, Optional + from moto.core.exceptions import JsonRESTError from moto.dynamodb.limits import HASH_KEY_MAX_LENGTH, RANGE_KEY_MAX_LENGTH - ERROR_TYPE_PREFIX = "com.amazonaws.dynamodb.v20120810#" diff --git a/moto/dynamodb/models/__init__.py b/moto/dynamodb/models/__init__.py index 1e6df206a..d88ca5e0d 100644 --- a/moto/dynamodb/models/__init__.py +++ b/moto/dynamodb/models/__init__.py @@ -1,41 +1,41 @@ import copy import re - from collections import OrderedDict -from typing import Any, Dict, Optional, List, Tuple, Union, Set -from moto.core import BaseBackend, BackendDict -from moto.core.utils import unix_time +from typing import Any, Dict, List, Optional, Set, Tuple, Union + +from moto.core import BackendDict, BaseBackend from moto.core.exceptions import JsonRESTError -from moto.dynamodb.comparisons import get_filter_expression, get_expected +from moto.core.utils import unix_time +from moto.dynamodb.comparisons import get_expected, get_filter_expression from moto.dynamodb.exceptions import ( + BackupNotFoundException, + ConditionalCheckFailed, ItemSizeTooLarge, ItemSizeToUpdateTooLarge, - ConditionalCheckFailed, - TransactionCanceledException, + MockValidationException, MultipleTransactionsException, - TooManyTransactionsException, - TableNotFoundException, + ResourceInUseException, ResourceNotFoundException, SourceTableNotFoundException, - TableAlreadyExistsException, - BackupNotFoundException, - ResourceInUseException, StreamAlreadyEnabledException, - MockValidationException, + TableAlreadyExistsException, + TableNotFoundException, + TooManyTransactionsException, + TransactionCanceledException, TransactWriteSingleOpException, ) from moto.dynamodb.models.dynamo_type import DynamoType, Item from moto.dynamodb.models.table import ( - Table, - RestoredTable, + Backup, GlobalSecondaryIndex, RestoredPITTable, - Backup, + RestoredTable, + Table, ) +from moto.dynamodb.parsing import partiql from moto.dynamodb.parsing.executors import UpdateExpressionExecutor from moto.dynamodb.parsing.expressions import UpdateExpressionParser # type: ignore from moto.dynamodb.parsing.validators import UpdateExpressionValidator -from moto.dynamodb.parsing import partiql class DynamoDBBackend(BaseBackend): diff --git a/moto/dynamodb/models/dynamo_type.py b/moto/dynamodb/models/dynamo_type.py index fe44ab17f..21b368355 100644 --- a/moto/dynamodb/models/dynamo_type.py +++ b/moto/dynamodb/models/dynamo_type.py @@ -1,17 +1,18 @@ import base64 import copy import decimal +from typing import Any, Dict, List, Optional, Union -from botocore.utils import merge_dicts from boto3.dynamodb.types import TypeDeserializer, TypeSerializer -from typing import Any, Dict, List, Union, Optional +from botocore.utils import merge_dicts from moto.core import BaseModel from moto.dynamodb.exceptions import ( - IncorrectDataType, EmptyKeyAttributeException, + IncorrectDataType, ItemSizeTooLarge, ) + from .utilities import bytesize, find_nested_key deserializer = TypeDeserializer() diff --git a/moto/dynamodb/models/table.py b/moto/dynamodb/models/table.py index dd4db4831..7de01b400 100644 --- a/moto/dynamodb/models/table.py +++ b/moto/dynamodb/models/table.py @@ -1,23 +1,23 @@ -from collections import defaultdict import copy +from collections import defaultdict +from typing import Any, Dict, Iterator, List, Optional, Sequence, Tuple -from typing import Any, Dict, Optional, List, Tuple, Iterator, Sequence from moto.core import BaseModel, CloudFormationModel from moto.core.utils import unix_time, unix_time_millis, utcnow -from moto.dynamodb.comparisons import get_filter_expression, get_expected +from moto.dynamodb.comparisons import get_expected, get_filter_expression from moto.dynamodb.exceptions import ( - InvalidIndexNameError, - HashKeyTooLong, - RangeKeyTooLong, ConditionalCheckFailed, + HashKeyTooLong, InvalidAttributeTypeError, - MockValidationException, InvalidConversion, + InvalidIndexNameError, + MockValidationException, + RangeKeyTooLong, SerializationException, ) -from moto.dynamodb.models.utilities import dynamo_json_dump -from moto.dynamodb.models.dynamo_type import DynamoType, Item from moto.dynamodb.limits import HASH_KEY_MAX_LENGTH, RANGE_KEY_MAX_LENGTH +from moto.dynamodb.models.dynamo_type import DynamoType, Item +from moto.dynamodb.models.utilities import dynamo_json_dump from moto.moto_api._internal import mock_random diff --git a/moto/dynamodb/parsing/ast_nodes.py b/moto/dynamodb/parsing/ast_nodes.py index 93ad8551c..0cf8c1d12 100644 --- a/moto/dynamodb/parsing/ast_nodes.py +++ b/moto/dynamodb/parsing/ast_nodes.py @@ -4,6 +4,7 @@ from abc import abstractmethod from collections import deque from moto.dynamodb.models import DynamoType + from ..exceptions import DuplicateUpdateExpression, TooManyAddClauses diff --git a/moto/dynamodb/parsing/executors.py b/moto/dynamodb/parsing/executors.py index 809bb6fbf..35bd7d9ee 100644 --- a/moto/dynamodb/parsing/executors.py +++ b/moto/dynamodb/parsing/executors.py @@ -1,28 +1,28 @@ from abc import abstractmethod -from typing import Any, Dict, List, Optional, Union, Type +from typing import Any, Dict, List, Optional, Type, Union from moto.dynamodb.exceptions import ( - IncorrectOperandType, IncorrectDataType, + IncorrectOperandType, ProvidedKeyDoesNotExist, ) from moto.dynamodb.models.dynamo_type import ( - DDBTypeConversion, DDBType, + DDBTypeConversion, DynamoType, Item, ) from moto.dynamodb.parsing.ast_nodes import ( # type: ignore - Node, - UpdateExpressionSetAction, - UpdateExpressionDeleteAction, - UpdateExpressionRemoveAction, - UpdateExpressionAddAction, - UpdateExpressionPath, DDBTypedValue, ExpressionAttribute, - ExpressionSelector, ExpressionAttributeName, + ExpressionSelector, + Node, + UpdateExpressionAddAction, + UpdateExpressionDeleteAction, + UpdateExpressionPath, + UpdateExpressionRemoveAction, + UpdateExpressionSetAction, ) from moto.dynamodb.parsing.validators import ExpressionPathResolver diff --git a/moto/dynamodb/parsing/expressions.py b/moto/dynamodb/parsing/expressions.py index 1561f439c..eaf57fd34 100644 --- a/moto/dynamodb/parsing/expressions.py +++ b/moto/dynamodb/parsing/expressions.py @@ -1,37 +1,36 @@ # type: ignore +import abc import logging from abc import abstractmethod -import abc from collections import deque +from moto.dynamodb.exceptions import InvalidTokenException, InvalidUpdateExpression from moto.dynamodb.parsing.ast_nodes import ( - UpdateExpression, - UpdateExpressionSetClause, - UpdateExpressionSetActions, - UpdateExpressionSetAction, - UpdateExpressionRemoveActions, - UpdateExpressionRemoveAction, - UpdateExpressionPath, - UpdateExpressionValue, - UpdateExpressionGroupedValue, - UpdateExpressionRemoveClause, - ExpressionPathDescender, - ExpressionSelector, ExpressionAttribute, ExpressionAttributeName, ExpressionAttributeValue, + ExpressionPathDescender, + ExpressionSelector, ExpressionValueOperator, - UpdateExpressionFunction, - UpdateExpressionAddClause, - UpdateExpressionAddActions, + UpdateExpression, UpdateExpressionAddAction, + UpdateExpressionAddActions, + UpdateExpressionAddClause, UpdateExpressionDeleteAction, UpdateExpressionDeleteActions, UpdateExpressionDeleteClause, + UpdateExpressionFunction, + UpdateExpressionGroupedValue, + UpdateExpressionPath, + UpdateExpressionRemoveAction, + UpdateExpressionRemoveActions, + UpdateExpressionRemoveClause, + UpdateExpressionSetAction, + UpdateExpressionSetActions, + UpdateExpressionSetClause, + UpdateExpressionValue, ) -from moto.dynamodb.exceptions import InvalidTokenException, InvalidUpdateExpression -from moto.dynamodb.parsing.tokens import Token, ExpressionTokenizer - +from moto.dynamodb.parsing.tokens import ExpressionTokenizer, Token logger = logging.getLogger(__name__) diff --git a/moto/dynamodb/parsing/key_condition_expression.py b/moto/dynamodb/parsing/key_condition_expression.py index 2885f7652..b0a3e7ee1 100644 --- a/moto/dynamodb/parsing/key_condition_expression.py +++ b/moto/dynamodb/parsing/key_condition_expression.py @@ -1,6 +1,7 @@ from enum import Enum -from typing import Any, List, Dict, Tuple, Optional, Union -from moto.dynamodb.exceptions import MockValidationException, KeyIsEmptyStringException +from typing import Any, Dict, List, Optional, Tuple, Union + +from moto.dynamodb.exceptions import KeyIsEmptyStringException, MockValidationException from moto.utilities.tokenizer import GenericTokenizer diff --git a/moto/dynamodb/parsing/partiql.py b/moto/dynamodb/parsing/partiql.py index b148921f1..b60f467f8 100644 --- a/moto/dynamodb/parsing/partiql.py +++ b/moto/dynamodb/parsing/partiql.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Dict, List if TYPE_CHECKING: from py_partiql_parser import QueryMetadata diff --git a/moto/dynamodb/parsing/reserved_keywords.py b/moto/dynamodb/parsing/reserved_keywords.py index 9a59adf4f..6b7848302 100644 --- a/moto/dynamodb/parsing/reserved_keywords.py +++ b/moto/dynamodb/parsing/reserved_keywords.py @@ -1,4 +1,5 @@ from typing import List, Optional + from moto.utilities.utils import load_resource_as_str diff --git a/moto/dynamodb/parsing/tokens.py b/moto/dynamodb/parsing/tokens.py index fbb46d66f..43c7b6779 100644 --- a/moto/dynamodb/parsing/tokens.py +++ b/moto/dynamodb/parsing/tokens.py @@ -2,8 +2,8 @@ import re from typing import List, Union from moto.dynamodb.exceptions import ( - InvalidTokenException, InvalidExpressionAttributeNameKey, + InvalidTokenException, ) diff --git a/moto/dynamodb/parsing/validators.py b/moto/dynamodb/parsing/validators.py index d24d2dc39..53d90b1df 100644 --- a/moto/dynamodb/parsing/validators.py +++ b/moto/dynamodb/parsing/validators.py @@ -6,38 +6,38 @@ from copy import deepcopy from typing import Any, Callable, Dict, List, Type, Union from moto.dynamodb.exceptions import ( - AttributeIsReservedKeyword, - ExpressionAttributeValueNotDefined, AttributeDoesNotExist, + AttributeIsReservedKeyword, + EmptyKeyAttributeException, ExpressionAttributeNameNotDefined, + ExpressionAttributeValueNotDefined, IncorrectOperandType, InvalidUpdateExpressionInvalidDocumentPath, - ProvidedKeyDoesNotExist, - EmptyKeyAttributeException, - UpdateHashRangeKeyException, MockValidationException, + ProvidedKeyDoesNotExist, + UpdateHashRangeKeyException, ) from moto.dynamodb.models.dynamo_type import DynamoType, Item from moto.dynamodb.models.table import Table from moto.dynamodb.parsing.ast_nodes import ( # type: ignore - Node, - ExpressionAttribute, - UpdateExpressionClause, - UpdateExpressionPath, - UpdateExpressionSetAction, - UpdateExpressionAddAction, - UpdateExpressionDeleteAction, - UpdateExpressionRemoveAction, DDBTypedValue, - ExpressionAttributeValue, - ExpressionAttributeName, DepthFirstTraverser, - NoneExistingPath, - UpdateExpressionFunction, + ExpressionAttribute, + ExpressionAttributeName, + ExpressionAttributeValue, ExpressionPathDescender, - UpdateExpressionValue, - ExpressionValueOperator, ExpressionSelector, + ExpressionValueOperator, + Node, + NoneExistingPath, + UpdateExpressionAddAction, + UpdateExpressionClause, + UpdateExpressionDeleteAction, + UpdateExpressionFunction, + UpdateExpressionPath, + UpdateExpressionRemoveAction, + UpdateExpressionSetAction, + UpdateExpressionValue, ) from moto.dynamodb.parsing.reserved_keywords import ReservedKeywords diff --git a/moto/dynamodb/responses.py b/moto/dynamodb/responses.py index 77197ecf7..6920719ce 100644 --- a/moto/dynamodb/responses.py +++ b/moto/dynamodb/responses.py @@ -1,25 +1,24 @@ import copy -import json - import itertools +import json from functools import wraps -from typing import Any, Dict, List, Union, Callable, Optional +from typing import Any, Callable, Dict, List, Optional, Union from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse from moto.core.utils import camelcase_to_underscores +from moto.dynamodb.models import DynamoDBBackend, Table, dynamodb_backends +from moto.dynamodb.models.utilities import dynamo_json_dump from moto.dynamodb.parsing.key_condition_expression import parse_expression from moto.dynamodb.parsing.reserved_keywords import ReservedKeywords +from moto.utilities.aws_headers import amz_crc32, amzn_request_id + from .exceptions import ( + KeyIsEmptyStringException, MockValidationException, ResourceNotFoundException, UnknownKeyType, - KeyIsEmptyStringException, ) -from moto.dynamodb.models import dynamodb_backends, Table, DynamoDBBackend -from moto.dynamodb.models.utilities import dynamo_json_dump -from moto.utilities.aws_headers import amz_crc32, amzn_request_id - TRANSACTION_MAX_ITEMS = 25 diff --git a/moto/dynamodb_v20111205/__init__.py b/moto/dynamodb_v20111205/__init__.py index cd234cf23..934802628 100644 --- a/moto/dynamodb_v20111205/__init__.py +++ b/moto/dynamodb_v20111205/__init__.py @@ -1,5 +1,5 @@ -from .models import dynamodb_backends from ..core.models import base_decorator +from .models import dynamodb_backends """ An older API version of DynamoDB. diff --git a/moto/dynamodb_v20111205/comparisons.py b/moto/dynamodb_v20111205/comparisons.py index 883f10203..3e961af94 100644 --- a/moto/dynamodb_v20111205/comparisons.py +++ b/moto/dynamodb_v20111205/comparisons.py @@ -1,5 +1,4 @@ -from typing import Callable, Any - +from typing import Any, Callable # TODO add tests for all of these COMPARISON_FUNCS = { diff --git a/moto/dynamodb_v20111205/models.py b/moto/dynamodb_v20111205/models.py index 89f5b294c..e5a3a309d 100644 --- a/moto/dynamodb_v20111205/models.py +++ b/moto/dynamodb_v20111205/models.py @@ -1,10 +1,10 @@ -from collections import defaultdict -from typing import Any, Dict, Optional, List, Union, Tuple, Iterable import json +from collections import OrderedDict, defaultdict +from typing import Any, Dict, Iterable, List, Optional, Tuple, Union -from collections import OrderedDict -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import unix_time, utcnow + from .comparisons import get_comparison_func diff --git a/moto/dynamodb_v20111205/responses.py b/moto/dynamodb_v20111205/responses.py index 84b98da7d..ca1586817 100644 --- a/moto/dynamodb_v20111205/responses.py +++ b/moto/dynamodb_v20111205/responses.py @@ -4,7 +4,8 @@ from typing import Any, Dict, Optional, Union from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse from moto.core.utils import camelcase_to_underscores -from .models import dynamodb_backends, DynamoDBBackend, dynamo_json_dump + +from .models import DynamoDBBackend, dynamo_json_dump, dynamodb_backends class DynamoHandler(BaseResponse): diff --git a/moto/dynamodbstreams/__init__.py b/moto/dynamodbstreams/__init__.py index 307df29cd..dc6b8edf4 100644 --- a/moto/dynamodbstreams/__init__.py +++ b/moto/dynamodbstreams/__init__.py @@ -1,5 +1,5 @@ -from .models import dynamodbstreams_backends from ..core.models import base_decorator +from .models import dynamodbstreams_backends dynamodbstreams_backend = dynamodbstreams_backends["us-east-1"] mock_dynamodbstreams = base_decorator(dynamodbstreams_backends) diff --git a/moto/dynamodbstreams/models.py b/moto/dynamodbstreams/models.py index e271634a5..3e5cc5279 100644 --- a/moto/dynamodbstreams/models.py +++ b/moto/dynamodbstreams/models.py @@ -1,11 +1,11 @@ -import os -import json import base64 +import json +import os from typing import Any, Dict, Optional -from moto.core import BaseBackend, BackendDict, BaseModel -from moto.dynamodb.models import dynamodb_backends, DynamoDBBackend -from moto.dynamodb.models.table import Table, StreamShard +from moto.core import BackendDict, BaseBackend, BaseModel +from moto.dynamodb.models import DynamoDBBackend, dynamodb_backends +from moto.dynamodb.models.table import StreamShard, Table from moto.dynamodb.models.utilities import DynamoJsonEncoder diff --git a/moto/dynamodbstreams/responses.py b/moto/dynamodbstreams/responses.py index f9a0dc990..5eabc558f 100644 --- a/moto/dynamodbstreams/responses.py +++ b/moto/dynamodbstreams/responses.py @@ -1,6 +1,6 @@ from moto.core.responses import BaseResponse -from .models import dynamodbstreams_backends, DynamoDBStreamsBackend +from .models import DynamoDBStreamsBackend, dynamodbstreams_backends class DynamoDBStreamsHandler(BaseResponse): diff --git a/moto/ebs/__init__.py b/moto/ebs/__init__.py index 8254b63e7..cc67e7d8f 100644 --- a/moto/ebs/__init__.py +++ b/moto/ebs/__init__.py @@ -1,5 +1,5 @@ """ebs module initialization; sets value for base decorator.""" -from .models import ebs_backends from ..core.models import base_decorator +from .models import ebs_backends mock_ebs = base_decorator(ebs_backends) diff --git a/moto/ebs/models.py b/moto/ebs/models.py index a8f8f200b..3b39c4371 100644 --- a/moto/ebs/models.py +++ b/moto/ebs/models.py @@ -1,13 +1,13 @@ """EBSBackend class with methods for supported APIs.""" -from moto.core import BaseBackend, BackendDict, BaseModel +from typing import Any, Dict, List, Optional, Tuple + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import unix_time -from moto.ec2.models import ec2_backends, EC2Backend +from moto.ec2.models import EC2Backend, ec2_backends from moto.ec2.models.elastic_block_store import Snapshot from moto.moto_api._internal import mock_random -from typing import Any, Dict, List, Optional, Tuple - class Block(BaseModel): def __init__( diff --git a/moto/ebs/responses.py b/moto/ebs/responses.py index 0e9b2ad99..5d13cda4b 100644 --- a/moto/ebs/responses.py +++ b/moto/ebs/responses.py @@ -2,9 +2,10 @@ import json from typing import Any -from moto.core.responses import BaseResponse from moto.core.common_types import TYPE_RESPONSE -from .models import ebs_backends, EBSBackend +from moto.core.responses import BaseResponse + +from .models import EBSBackend, ebs_backends class EBSResponse(BaseResponse): diff --git a/moto/ec2/__init__.py b/moto/ec2/__init__.py index 7ac36e67b..d3cc5b4ac 100644 --- a/moto/ec2/__init__.py +++ b/moto/ec2/__init__.py @@ -1,4 +1,4 @@ -from .models import ec2_backends from ..core.models import base_decorator +from .models import ec2_backends mock_ec2 = base_decorator(ec2_backends) diff --git a/moto/ec2/exceptions.py b/moto/ec2/exceptions.py index 2135bee39..c9354d3fb 100644 --- a/moto/ec2/exceptions.py +++ b/moto/ec2/exceptions.py @@ -1,6 +1,6 @@ -from moto.core.exceptions import RESTError -from typing import Any, List, Optional, Union, Iterable +from typing import Any, Iterable, List, Optional, Union +from moto.core.exceptions import RESTError # EC2 has a custom root-tag - vs # `terraform destroy` will complain if the roottag is incorrect diff --git a/moto/ec2/models/__init__.py b/moto/ec2/models/__init__.py index 70bcd56f1..97135e991 100644 --- a/moto/ec2/models/__init__.py +++ b/moto/ec2/models/__init__.py @@ -1,53 +1,55 @@ from typing import Any, Dict, List -from moto.core import BaseBackend, BackendDict + +from moto.core import BackendDict, BaseBackend + from ..exceptions import ( EC2ClientError, InvalidID, MissingParameterError, MotoNotImplementedError, ) +from ..utils import ( + EC2_RESOURCE_TO_PREFIX, + get_prefix, + is_valid_resource_id, +) from .amis import AmiBackend +from .availability_zones_and_regions import RegionsAndZonesBackend from .carrier_gateways import CarrierGatewayBackend from .customer_gateways import CustomerGatewayBackend from .dhcp_options import DHCPOptionsSetBackend from .elastic_block_store import EBSBackend from .elastic_ip_addresses import ElasticAddressBackend from .elastic_network_interfaces import NetworkInterfaceBackend -from .hosts import HostsBackend from .fleets import FleetsBackend from .flow_logs import FlowLogsBackend +from .hosts import HostsBackend +from .iam_instance_profile import IamInstanceProfileAssociationBackend +from .instance_types import InstanceTypeBackend, InstanceTypeOfferingBackend +from .instances import InstanceBackend +from .internet_gateways import ( + EgressOnlyInternetGatewayBackend, + InternetGatewayBackend, +) from .key_pairs import KeyPairBackend from .launch_templates import LaunchTemplateBackend from .managed_prefixes import ManagedPrefixListBackend -from .iam_instance_profile import IamInstanceProfileAssociationBackend -from .internet_gateways import ( - InternetGatewayBackend, - EgressOnlyInternetGatewayBackend, -) -from .instances import InstanceBackend -from .instance_types import InstanceTypeBackend, InstanceTypeOfferingBackend from .nat_gateways import NatGatewayBackend from .network_acls import NetworkAclBackend -from .availability_zones_and_regions import RegionsAndZonesBackend from .route_tables import RouteBackend from .security_groups import SecurityGroupBackend from .spot_requests import SpotRequestBackend from .subnets import SubnetBackend from .tags import TagBackend from .transit_gateway import TransitGatewayBackend -from .transit_gateway_route_tables import TransitGatewayRouteTableBackend from .transit_gateway_attachments import TransitGatewayAttachmentBackend -from .vpn_gateway import VpnGatewayBackend -from .vpn_connections import VPNConnectionBackend -from .vpcs import VPCBackend +from .transit_gateway_route_tables import TransitGatewayRouteTableBackend from .vpc_peering_connections import VPCPeeringConnectionBackend from .vpc_service_configuration import VPCServiceConfigurationBackend +from .vpcs import VPCBackend +from .vpn_connections import VPNConnectionBackend +from .vpn_gateway import VpnGatewayBackend from .windows import WindowsBackend -from ..utils import ( - EC2_RESOURCE_TO_PREFIX, - is_valid_resource_id, - get_prefix, -) def validate_resource_ids(resource_ids: List[str]) -> bool: diff --git a/moto/ec2/models/amis.py b/moto/ec2/models/amis.py index 74884ad6a..12028f2cd 100644 --- a/moto/ec2/models/amis.py +++ b/moto/ec2/models/amis.py @@ -3,23 +3,24 @@ import os import re from os import environ from typing import Any, Dict, List, Optional, Set, cast + from moto import settings from moto.utilities.utils import load_resource + from ..exceptions import ( - InvalidAMIIdError, InvalidAMIAttributeItemValueError, + InvalidAMIIdError, InvalidTaggableResourceType, MalformedAMIIdError, UnvailableAMIIdError, ) -from .core import TaggedEC2Resource -from .instances import Instance from ..utils import ( - random_ami_id, generic_filter, + random_ami_id, utc_date_and_time, ) - +from .core import TaggedEC2Resource +from .instances import Instance if "MOTO_AMIS_PATH" in environ: with open(environ["MOTO_AMIS_PATH"], "r", encoding="utf-8") as f: diff --git a/moto/ec2/models/availability_zones_and_regions.py b/moto/ec2/models/availability_zones_and_regions.py index 56d94eac7..eb46d01ab 100644 --- a/moto/ec2/models/availability_zones_and_regions.py +++ b/moto/ec2/models/availability_zones_and_regions.py @@ -1,5 +1,7 @@ -from boto3 import Session from typing import Any, Dict, List, Optional + +from boto3 import Session + from moto.utilities.utils import filter_resources diff --git a/moto/ec2/models/carrier_gateways.py b/moto/ec2/models/carrier_gateways.py index 9c9e5b6bb..806548e70 100644 --- a/moto/ec2/models/carrier_gateways.py +++ b/moto/ec2/models/carrier_gateways.py @@ -1,9 +1,10 @@ from typing import Any, Dict, List, Optional + from moto.utilities.utils import filter_resources -from .core import TaggedEC2Resource from ..exceptions import InvalidCarrierGatewayID, InvalidVPCIdError from ..utils import random_carrier_gateway_id +from .core import TaggedEC2Resource class CarrierGateway(TaggedEC2Resource): diff --git a/moto/ec2/models/core.py b/moto/ec2/models/core.py index f07e7c31e..f850ce75c 100644 --- a/moto/ec2/models/core.py +++ b/moto/ec2/models/core.py @@ -1,4 +1,5 @@ from typing import Any, Dict, List, Optional + from moto.core import BaseModel from ..exceptions import FilterNotImplementedError diff --git a/moto/ec2/models/customer_gateways.py b/moto/ec2/models/customer_gateways.py index 4d712d227..95255540e 100644 --- a/moto/ec2/models/customer_gateways.py +++ b/moto/ec2/models/customer_gateways.py @@ -1,8 +1,8 @@ from typing import Any, Dict, List, Optional -from .core import TaggedEC2Resource from ..exceptions import InvalidCustomerGatewayIdError from ..utils import random_customer_gateway_id +from .core import TaggedEC2Resource class CustomerGateway(TaggedEC2Resource): diff --git a/moto/ec2/models/dhcp_options.py b/moto/ec2/models/dhcp_options.py index 397407147..4e45a08fa 100644 --- a/moto/ec2/models/dhcp_options.py +++ b/moto/ec2/models/dhcp_options.py @@ -1,13 +1,14 @@ import itertools from typing import Any, Dict, List, Optional + from ..exceptions import ( DependencyViolationError, InvalidDHCPOptionsIdError, InvalidParameterValueError, MalformedDHCPOptionsIdError, ) +from ..utils import generic_filter, random_dhcp_option_id from .core import TaggedEC2Resource -from ..utils import random_dhcp_option_id, generic_filter class DHCPOptionsSet(TaggedEC2Resource): diff --git a/moto/ec2/models/elastic_block_store.py b/moto/ec2/models/elastic_block_store.py index 0a78b6c39..f2ccb515a 100644 --- a/moto/ec2/models/elastic_block_store.py +++ b/moto/ec2/models/elastic_block_store.py @@ -1,25 +1,26 @@ -from typing import Any, Dict, List, Optional, Set, Iterable +from typing import Any, Dict, Iterable, List, Optional, Set from moto.core import CloudFormationModel from moto.packages.boto.ec2.blockdevicemapping import BlockDeviceType + from ..exceptions import ( InvalidAMIAttributeItemValueError, - InvalidSnapshotIdError, - InvalidSnapshotInUse, - InvalidVolumeIdError, - VolumeInUseError, - InvalidVolumeAttachmentError, - InvalidVolumeDetachmentError, InvalidParameterDependency, InvalidParameterValueError, + InvalidSnapshotIdError, + InvalidSnapshotInUse, + InvalidVolumeAttachmentError, + InvalidVolumeDetachmentError, + InvalidVolumeIdError, + VolumeInUseError, ) -from .core import TaggedEC2Resource from ..utils import ( + generic_filter, random_snapshot_id, random_volume_id, - generic_filter, utc_date_and_time, ) +from .core import TaggedEC2Resource IOPS_REQUIRED_VOLUME_TYPES = ["io1", "io2"] IOPS_SUPPORTED_VOLUME_TYPES = ["gp3", "io1", "io2"] diff --git a/moto/ec2/models/elastic_ip_addresses.py b/moto/ec2/models/elastic_ip_addresses.py index 3b2b57133..3a3677e91 100644 --- a/moto/ec2/models/elastic_ip_addresses.py +++ b/moto/ec2/models/elastic_ip_addresses.py @@ -1,19 +1,21 @@ from typing import Any, Dict, List, Optional + from moto.core import CloudFormationModel -from .core import TaggedEC2Resource + from ..exceptions import ( FilterNotImplementedError, InvalidAddressError, InvalidAllocationIdError, - ResourceAlreadyAssociatedError, InvalidAssociationIdError, + ResourceAlreadyAssociatedError, ) from ..utils import ( - random_ip, + generic_filter, random_eip_allocation_id, random_eip_association_id, - generic_filter, + random_ip, ) +from .core import TaggedEC2Resource class ElasticAddress(TaggedEC2Resource, CloudFormationModel): diff --git a/moto/ec2/models/elastic_network_interfaces.py b/moto/ec2/models/elastic_network_interfaces.py index 842693f76..74e022041 100644 --- a/moto/ec2/models/elastic_network_interfaces.py +++ b/moto/ec2/models/elastic_network_interfaces.py @@ -1,5 +1,7 @@ -from typing import Any, Dict, Optional, List, Union, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union + from moto.core import CloudFormationModel + from ..exceptions import InvalidNetworkAttachmentIdError, InvalidNetworkInterfaceIdError from .core import TaggedEC2Resource from .security_groups import SecurityGroup @@ -7,12 +9,12 @@ from .security_groups import SecurityGroup if TYPE_CHECKING: from .instances import Instance from ..utils import ( - random_eni_id, generate_dns_from_ip, + generic_filter, + random_eni_id, random_mac_address, random_private_ip, random_public_ip, - generic_filter, ) diff --git a/moto/ec2/models/fleets.py b/moto/ec2/models/fleets.py index a76a26ea5..611e964ab 100644 --- a/moto/ec2/models/fleets.py +++ b/moto/ec2/models/fleets.py @@ -3,11 +3,12 @@ from collections import defaultdict from typing import Any, Dict, List, Optional, Tuple from moto.ec2.models.spot_requests import SpotFleetLaunchSpec, SpotInstanceRequest -from .core import TaggedEC2Resource + from ..utils import ( - random_fleet_id, convert_tag_spec, + random_fleet_id, ) +from .core import TaggedEC2Resource class Fleet(TaggedEC2Resource): diff --git a/moto/ec2/models/flow_logs.py b/moto/ec2/models/flow_logs.py index e7bab2347..b4db5b103 100644 --- a/moto/ec2/models/flow_logs.py +++ b/moto/ec2/models/flow_logs.py @@ -1,6 +1,8 @@ import itertools from typing import Any, Dict, List, Optional, Tuple + from moto.core import CloudFormationModel + from ..exceptions import ( FlowLogAlreadyExists, InvalidAggregationIntervalParameterError, @@ -8,12 +10,12 @@ from ..exceptions import ( InvalidDependantParameterTypeError, InvalidFlowLogIdError, ) -from .core import TaggedEC2Resource from ..utils import ( - random_flow_log_id, generic_filter, + random_flow_log_id, utc_date_and_time, ) +from .core import TaggedEC2Resource class FlowLogs(TaggedEC2Resource, CloudFormationModel): @@ -221,8 +223,8 @@ class FlowLogsBackend: self.get_network_interface(resource_id) # type: ignore[attr-defined] if log_destination_type == "s3": - from moto.s3.models import s3_backends from moto.s3.exceptions import MissingBucket + from moto.s3.models import s3_backends arn = log_destination.split(":", 5)[5] try: @@ -236,8 +238,8 @@ class FlowLogsBackend: ) continue elif log_destination_type == "cloud-watch-logs": - from moto.logs.models import logs_backends from moto.logs.exceptions import ResourceNotFoundException + from moto.logs.models import logs_backends # API allows to create a FlowLog with a # non-existing LogGroup. It however later diff --git a/moto/ec2/models/hosts.py b/moto/ec2/models/hosts.py index b3183fda7..cc4253b68 100644 --- a/moto/ec2/models/hosts.py +++ b/moto/ec2/models/hosts.py @@ -1,8 +1,10 @@ -from .core import TaggedEC2Resource -from ..utils import generic_filter, random_dedicated_host_id -from moto.core.utils import unix_time from typing import Any, Dict, List, Optional +from moto.core.utils import unix_time + +from ..utils import generic_filter, random_dedicated_host_id +from .core import TaggedEC2Resource + class Host(TaggedEC2Resource): def __init__( diff --git a/moto/ec2/models/iam_instance_profile.py b/moto/ec2/models/iam_instance_profile.py index 943cfd312..ef547325e 100644 --- a/moto/ec2/models/iam_instance_profile.py +++ b/moto/ec2/models/iam_instance_profile.py @@ -3,14 +3,15 @@ from typing import Any, Dict, List, Optional, Tuple from moto.core import CloudFormationModel from moto.ec2.models.instances import Instance from moto.iam.models import InstanceProfile + from ..exceptions import ( IncorrectStateIamProfileAssociationError, InvalidAssociationIDIamProfileAssociationError, ) from ..utils import ( - random_iam_instance_profile_association_id, filter_iam_instance_profile_associations, filter_iam_instance_profiles, + random_iam_instance_profile_association_id, ) diff --git a/moto/ec2/models/instance_types.py b/moto/ec2/models/instance_types.py index 7da4c656c..c31c3f5b5 100644 --- a/moto/ec2/models/instance_types.py +++ b/moto/ec2/models/instance_types.py @@ -1,10 +1,11 @@ import pathlib -from typing import Any, Dict, List, Optional from os import listdir -from ..utils import generic_filter +from typing import Any, Dict, List, Optional from moto.utilities.utils import load_resource + from ..exceptions import InvalidFilter, InvalidInstanceTypeError +from ..utils import generic_filter INSTANCE_TYPES: Dict[str, Any] = load_resource( __name__, "../resources/instance_types.json" diff --git a/moto/ec2/models/instances.py b/moto/ec2/models/instances.py index 8ae642c44..1c94338cc 100644 --- a/moto/ec2/models/instances.py +++ b/moto/ec2/models/instances.py @@ -2,18 +2,18 @@ import contextlib import copy import warnings from collections import OrderedDict -from typing import Any, Dict, ItemsView, List, Tuple, Optional, Set -from moto import settings +from typing import Any, Dict, ItemsView, List, Optional, Set, Tuple +from moto import settings from moto.core import CloudFormationModel from moto.core.utils import camelcase_to_underscores, utcnow -from moto.ec2.models.fleets import Fleet from moto.ec2.models.elastic_network_interfaces import NetworkInterface -from moto.ec2.models.launch_templates import LaunchTemplateVersion +from moto.ec2.models.fleets import Fleet from moto.ec2.models.instance_types import ( INSTANCE_TYPE_OFFERINGS, InstanceTypeOfferingBackend, ) +from moto.ec2.models.launch_templates import LaunchTemplateVersion from moto.ec2.models.security_groups import SecurityGroup from moto.ec2.models.subnets import Subnet from moto.packages.boto.ec2.blockdevicemapping import BlockDeviceMapping @@ -27,8 +27,8 @@ from ..exceptions import ( InvalidParameterCombination, InvalidParameterValueErrorUnknownAttribute, InvalidSecurityGroupNotFoundError, - OperationNotPermitted4, InvalidSubnetIdError, + OperationNotPermitted4, ) from ..utils import ( convert_tag_spec, diff --git a/moto/ec2/models/internet_gateways.py b/moto/ec2/models/internet_gateways.py index 7c441a244..a12f314d5 100644 --- a/moto/ec2/models/internet_gateways.py +++ b/moto/ec2/models/internet_gateways.py @@ -1,21 +1,22 @@ from typing import Any, Dict, List, Optional + from moto.core import CloudFormationModel -from .core import TaggedEC2Resource from ..exceptions import ( - InvalidVPCIdError, - GatewayNotAttachedError, DependencyViolationError, - InvalidInternetGatewayIdError, + GatewayNotAttachedError, InvalidGatewayIDError, + InvalidInternetGatewayIdError, + InvalidVPCIdError, ResourceAlreadyAssociatedError, ) -from .vpn_gateway import VPCGatewayAttachment from ..utils import ( filter_internet_gateways, random_egress_only_internet_gateway_id, random_internet_gateway_id, ) +from .core import TaggedEC2Resource +from .vpn_gateway import VPCGatewayAttachment class EgressOnlyInternetGateway(TaggedEC2Resource): diff --git a/moto/ec2/models/key_pairs.py b/moto/ec2/models/key_pairs.py index dcdd1d357..2d9b49b58 100644 --- a/moto/ec2/models/key_pairs.py +++ b/moto/ec2/models/key_pairs.py @@ -1,20 +1,21 @@ from typing import Any, Dict, List, Optional -from .core import TaggedEC2Resource +from moto.core.utils import iso_8601_datetime_with_milliseconds, utcnow + from ..exceptions import ( - InvalidKeyPairNameError, InvalidKeyPairDuplicateError, InvalidKeyPairFormatError, + InvalidKeyPairNameError, ) from ..utils import ( generic_filter, public_key_fingerprint, public_key_parse, - random_key_pair_id, random_ed25519_key_pair, + random_key_pair_id, random_rsa_key_pair, ) -from moto.core.utils import iso_8601_datetime_with_milliseconds, utcnow +from .core import TaggedEC2Resource class KeyPair(TaggedEC2Resource): diff --git a/moto/ec2/models/launch_templates.py b/moto/ec2/models/launch_templates.py index 99b135036..3e329d866 100644 --- a/moto/ec2/models/launch_templates.py +++ b/moto/ec2/models/launch_templates.py @@ -2,19 +2,20 @@ from collections import OrderedDict from typing import Any, Dict, List, Optional from moto.core import CloudFormationModel -from .core import TaggedEC2Resource -from ..utils import ( - generic_filter, - random_launch_template_id, - utc_date_and_time, - convert_tag_spec, -) + from ..exceptions import ( InvalidLaunchTemplateNameAlreadyExistsError, InvalidLaunchTemplateNameNotFoundError, InvalidLaunchTemplateNameNotFoundWithNameError, MissingParameterError, ) +from ..utils import ( + convert_tag_spec, + generic_filter, + random_launch_template_id, + utc_date_and_time, +) +from .core import TaggedEC2Resource class LaunchTemplateVersion: diff --git a/moto/ec2/models/managed_prefixes.py b/moto/ec2/models/managed_prefixes.py index 35f6326f4..c5a61438c 100644 --- a/moto/ec2/models/managed_prefixes.py +++ b/moto/ec2/models/managed_prefixes.py @@ -1,8 +1,9 @@ from typing import Any, Dict, List, Optional from moto.utilities.utils import filter_resources + +from ..utils import describe_tag_filter, random_managed_prefix_list_id from .core import TaggedEC2Resource -from ..utils import random_managed_prefix_list_id, describe_tag_filter class ManagedPrefixList(TaggedEC2Resource): diff --git a/moto/ec2/models/nat_gateways.py b/moto/ec2/models/nat_gateways.py index 7d6fb80d0..7fd552769 100644 --- a/moto/ec2/models/nat_gateways.py +++ b/moto/ec2/models/nat_gateways.py @@ -2,8 +2,9 @@ from typing import Any, Dict, List, Optional from moto.core import CloudFormationModel from moto.core.utils import iso_8601_datetime_with_milliseconds, utcnow -from .core import TaggedEC2Resource + from ..utils import random_nat_gateway_id, random_private_ip +from .core import TaggedEC2Resource class NatGateway(CloudFormationModel, TaggedEC2Resource): diff --git a/moto/ec2/models/network_acls.py b/moto/ec2/models/network_acls.py index abc6b9993..8c7fcb0a9 100644 --- a/moto/ec2/models/network_acls.py +++ b/moto/ec2/models/network_acls.py @@ -5,12 +5,12 @@ from ..exceptions import ( InvalidRouteTableIdError, NetworkAclEntryAlreadyExistsError, ) -from .core import TaggedEC2Resource from ..utils import ( generic_filter, random_network_acl_id, random_network_acl_subnet_association_id, ) +from .core import TaggedEC2Resource class NetworkAclBackend: diff --git a/moto/ec2/models/route_tables.py b/moto/ec2/models/route_tables.py index 9582f1167..83a4c2c15 100644 --- a/moto/ec2/models/route_tables.py +++ b/moto/ec2/models/route_tables.py @@ -4,21 +4,21 @@ from typing import Any, Dict, List, Optional, Set from moto.core import CloudFormationModel from moto.ec2.models.carrier_gateways import CarrierGateway from moto.ec2.models.elastic_network_interfaces import NetworkInterface -from moto.ec2.models.internet_gateways import EgressOnlyInternetGateway from moto.ec2.models.instances import Instance +from moto.ec2.models.internet_gateways import EgressOnlyInternetGateway from moto.ec2.models.managed_prefixes import ManagedPrefixList from moto.ec2.models.nat_gateways import NatGateway from moto.ec2.models.transit_gateway import TransitGateway from moto.ec2.models.vpc_peering_connections import VPCPeeringConnection from moto.ec2.models.vpn_gateway import VpnGateway -from .core import TaggedEC2Resource + from ..exceptions import ( DependencyViolationError, - InvalidRouteError, - InvalidRouteTableIdError, InvalidAssociationIdError, InvalidDestinationCIDRBlockParameterError, InvalidParameterValueErrorReplaceRoute, + InvalidRouteError, + InvalidRouteTableIdError, RouteAlreadyExistsError, RouteNotSupportedError, ) @@ -26,9 +26,10 @@ from ..utils import ( EC2_RESOURCE_TO_PREFIX, generate_route_id, generic_filter, - random_subnet_association_id, random_route_table_id, + random_subnet_association_id, ) +from .core import TaggedEC2Resource class RouteTable(TaggedEC2Resource, CloudFormationModel): diff --git a/moto/ec2/models/security_groups.py b/moto/ec2/models/security_groups.py index 4aedc9e2a..36dc25564 100644 --- a/moto/ec2/models/security_groups.py +++ b/moto/ec2/models/security_groups.py @@ -3,27 +3,29 @@ import itertools import json from collections import defaultdict from typing import Any, Dict, List, Optional, Tuple + from moto.core import CloudFormationModel from moto.core.utils import aws_api_matches + from ..exceptions import ( InvalidCIDRSubnetError, - InvalidPermissionNotFoundError, InvalidPermissionDuplicateError, + InvalidPermissionNotFoundError, InvalidSecurityGroupDuplicateError, InvalidSecurityGroupNotFoundError, MissingParameterError, MotoNotImplementedError, RulesPerSecurityGroupLimitExceededError, ) -from .core import TaggedEC2Resource from ..utils import ( - random_security_group_id, - random_security_group_rule_id, + is_tag_filter, is_valid_cidr, is_valid_ipv6_cidr, - is_tag_filter, + random_security_group_id, + random_security_group_rule_id, tag_filter_matches, ) +from .core import TaggedEC2Resource class SecurityRule: diff --git a/moto/ec2/models/spot_requests.py b/moto/ec2/models/spot_requests.py index 134b28354..f1fde656c 100644 --- a/moto/ec2/models/spot_requests.py +++ b/moto/ec2/models/spot_requests.py @@ -1,5 +1,5 @@ from collections import defaultdict -from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple from moto.core.common_models import BaseModel, CloudFormationModel from moto.ec2.exceptions import InvalidParameterValueErrorTagSpotFleetRequest @@ -7,14 +7,14 @@ from moto.ec2.exceptions import InvalidParameterValueErrorTagSpotFleetRequest if TYPE_CHECKING: from moto.ec2.models.instances import Instance from moto.ec2.models.security_groups import SecurityGroup -from .core import TaggedEC2Resource -from .instance_types import INSTANCE_TYPE_OFFERINGS from ..utils import ( + convert_tag_spec, + generic_filter, random_spot_fleet_request_id, random_spot_request_id, - generic_filter, - convert_tag_spec, ) +from .core import TaggedEC2Resource +from .instance_types import INSTANCE_TYPE_OFFERINGS class LaunchSpecification(BaseModel): diff --git a/moto/ec2/models/subnets.py b/moto/ec2/models/subnets.py index f80df1585..faece0061 100644 --- a/moto/ec2/models/subnets.py +++ b/moto/ec2/models/subnets.py @@ -1,30 +1,31 @@ import ipaddress import itertools from collections import defaultdict -from typing import Any, Dict, Iterable, List, Optional, Tuple, TYPE_CHECKING, Set +from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Set, Tuple from moto.core import CloudFormationModel if TYPE_CHECKING: from moto.ec2.models.instances import Instance from moto.ec2.models.availability_zones_and_regions import Zone + from ..exceptions import ( GenericInvalidParameterValueError, InvalidAvailabilityZoneError, InvalidCIDRBlockParameterError, InvalidParameterValueError, + InvalidSubnetCidrBlockAssociationID, InvalidSubnetConflictError, InvalidSubnetIdError, InvalidSubnetRangeError, - InvalidSubnetCidrBlockAssociationID, ) -from .core import TaggedEC2Resource -from .availability_zones_and_regions import RegionsAndZonesBackend from ..utils import ( - random_subnet_id, generic_filter, + random_subnet_id, random_subnet_ipv6_cidr_block_association_id, ) +from .availability_zones_and_regions import RegionsAndZonesBackend +from .core import TaggedEC2Resource class Subnet(TaggedEC2Resource, CloudFormationModel): diff --git a/moto/ec2/models/transit_gateway.py b/moto/ec2/models/transit_gateway.py index f2a942134..417f61802 100644 --- a/moto/ec2/models/transit_gateway.py +++ b/moto/ec2/models/transit_gateway.py @@ -1,12 +1,14 @@ from typing import Any, Dict, List, Optional + from moto.core import CloudFormationModel from moto.core.utils import iso_8601_datetime_with_milliseconds, utcnow from moto.utilities.utils import filter_resources, merge_multiple_dicts -from .core import TaggedEC2Resource + from ..utils import ( - random_transit_gateway_id, describe_tag_filter, + random_transit_gateway_id, ) +from .core import TaggedEC2Resource class TransitGateway(TaggedEC2Resource, CloudFormationModel): diff --git a/moto/ec2/models/transit_gateway_attachments.py b/moto/ec2/models/transit_gateway_attachments.py index 108f80ef5..8ed5bb6a2 100644 --- a/moto/ec2/models/transit_gateway_attachments.py +++ b/moto/ec2/models/transit_gateway_attachments.py @@ -1,12 +1,14 @@ -from collections import defaultdict import weakref -from typing import Any, Dict, List, Optional, Iterator +from collections import defaultdict +from typing import Any, Dict, Iterator, List, Optional + from moto.core.utils import iso_8601_datetime_with_milliseconds, utcnow -from moto.utilities.utils import merge_multiple_dicts, filter_resources +from moto.utilities.utils import filter_resources, merge_multiple_dicts + +from ..exceptions import InvalidParameterValueErrorPeeringAttachment +from ..utils import describe_tag_filter, random_transit_gateway_attachment_id from .core import TaggedEC2Resource from .vpc_peering_connections import PeeringConnectionStatus -from ..exceptions import InvalidParameterValueErrorPeeringAttachment -from ..utils import random_transit_gateway_attachment_id, describe_tag_filter class TransitGatewayAttachment(TaggedEC2Resource): diff --git a/moto/ec2/models/transit_gateway_route_tables.py b/moto/ec2/models/transit_gateway_route_tables.py index 603969c9a..ad600b0e1 100644 --- a/moto/ec2/models/transit_gateway_route_tables.py +++ b/moto/ec2/models/transit_gateway_route_tables.py @@ -1,8 +1,10 @@ from typing import Any, Dict, List, Optional + from moto.core.utils import iso_8601_datetime_with_milliseconds, utcnow from moto.utilities.utils import filter_resources -from .core import TaggedEC2Resource + from ..utils import random_transit_gateway_route_table_id +from .core import TaggedEC2Resource class TransitGatewayRouteTable(TaggedEC2Resource): diff --git a/moto/ec2/models/vpc_peering_connections.py b/moto/ec2/models/vpc_peering_connections.py index 075f526fe..5d430f0f1 100644 --- a/moto/ec2/models/vpc_peering_connections.py +++ b/moto/ec2/models/vpc_peering_connections.py @@ -1,7 +1,9 @@ import weakref from collections import defaultdict from typing import Any, Dict, Iterator, List, Optional + from moto.core import CloudFormationModel + from ..exceptions import ( InvalidVPCPeeringConnectionIdError, InvalidVPCPeeringConnectionStateTransitionError, @@ -9,9 +11,9 @@ from ..exceptions import ( OperationNotPermitted3, OperationNotPermitted5, ) +from ..utils import random_vpc_peering_connection_id from .core import TaggedEC2Resource from .vpcs import VPC -from ..utils import random_vpc_peering_connection_id class PeeringConnectionStatus: diff --git a/moto/ec2/models/vpc_service_configuration.py b/moto/ec2/models/vpc_service_configuration.py index 27350b8d6..2cafb16b8 100644 --- a/moto/ec2/models/vpc_service_configuration.py +++ b/moto/ec2/models/vpc_service_configuration.py @@ -1,8 +1,10 @@ from typing import Any, Dict, List, Optional + from moto.core import CloudFormationModel from moto.moto_api._internal import mock_random -from .core import TaggedEC2Resource + from ..exceptions import UnknownVpcEndpointService +from .core import TaggedEC2Resource class VPCServiceConfiguration(TaggedEC2Resource, CloudFormationModel): diff --git a/moto/ec2/models/vpcs.py b/moto/ec2/models/vpcs.py index f0da5bc27..e9f65c24a 100644 --- a/moto/ec2/models/vpcs.py +++ b/moto/ec2/models/vpcs.py @@ -2,38 +2,39 @@ import ipaddress import json import weakref from collections import defaultdict -from typing import Any, Dict, List, Optional from operator import itemgetter +from typing import Any, Dict, List, Optional from moto.core import CloudFormationModel -from .core import TaggedEC2Resource + from ..exceptions import ( CidrLimitExceeded, - UnsupportedTenancy, DefaultVpcAlreadyExists, DependencyViolationError, InvalidCIDRBlockParameterError, - InvalidServiceName, InvalidFilter, InvalidNextToken, InvalidParameterValueError, + InvalidServiceName, InvalidVpcCidrBlockAssociationIdError, + InvalidVpcEndPointIdError, InvalidVPCIdError, InvalidVPCRangeError, OperationNotPermitted, - InvalidVpcEndPointIdError, + UnsupportedTenancy, ) -from .availability_zones_and_regions import RegionsAndZonesBackend from ..utils import ( - random_ipv6_cidr, - random_vpc_ep_id, - random_private_ip, create_dns_entries, - random_vpc_id, - random_vpc_cidr_association_id, generic_filter, + random_ipv6_cidr, + random_private_ip, + random_vpc_cidr_association_id, + random_vpc_ep_id, + random_vpc_id, utc_date_and_time, ) +from .availability_zones_and_regions import RegionsAndZonesBackend +from .core import TaggedEC2Resource MAX_NUMBER_OF_ENDPOINT_SERVICES_RESULTS = 1000 DEFAULT_VPC_ENDPOINT_SERVICES: List[Dict[str, str]] = [] diff --git a/moto/ec2/models/vpn_connections.py b/moto/ec2/models/vpn_connections.py index 82c4ca7dc..03641be94 100644 --- a/moto/ec2/models/vpn_connections.py +++ b/moto/ec2/models/vpn_connections.py @@ -1,7 +1,8 @@ from typing import Any, Dict, List, Optional -from .core import TaggedEC2Resource + from ..exceptions import InvalidVpnConnectionIdError from ..utils import generic_filter, random_vpn_connection_id +from .core import TaggedEC2Resource class VPNConnection(TaggedEC2Resource): diff --git a/moto/ec2/models/vpn_gateway.py b/moto/ec2/models/vpn_gateway.py index 18068648c..524ebfa6c 100644 --- a/moto/ec2/models/vpn_gateway.py +++ b/moto/ec2/models/vpn_gateway.py @@ -1,8 +1,10 @@ from typing import Any, Dict, List, Optional + from moto.core import CloudFormationModel -from .core import TaggedEC2Resource -from ..exceptions import InvalidVpnGatewayIdError, InvalidVpnGatewayAttachmentError + +from ..exceptions import InvalidVpnGatewayAttachmentError, InvalidVpnGatewayIdError from ..utils import generic_filter, random_vpn_gateway_id +from .core import TaggedEC2Resource class VPCGatewayAttachment(CloudFormationModel): diff --git a/moto/ec2/models/windows.py b/moto/ec2/models/windows.py index 0951a09c8..5ea80be62 100644 --- a/moto/ec2/models/windows.py +++ b/moto/ec2/models/windows.py @@ -1,6 +1,5 @@ -from moto.moto_api._internal import mock_random as random - from moto.core import BaseModel +from moto.moto_api._internal import mock_random as random class WindowsBackend(BaseModel): diff --git a/moto/ec2/responses/__init__.py b/moto/ec2/responses/__init__.py index 7c6a9eeac..d06852657 100644 --- a/moto/ec2/responses/__init__.py +++ b/moto/ec2/responses/__init__.py @@ -1,21 +1,25 @@ from .account_attributes import AccountAttributes from .amis import AmisResponse from .availability_zones_and_regions import AvailabilityZonesAndRegions +from .carrier_gateways import CarrierGateway from .customer_gateways import CustomerGateways from .dhcp_options import DHCPOptions +from .egress_only_internet_gateways import EgressOnlyInternetGateway from .elastic_block_store import ElasticBlockStore from .elastic_ip_addresses import ElasticIPAddresses from .elastic_network_interfaces import ElasticNetworkInterfaces from .fleets import Fleets +from .flow_logs import FlowLogs from .general import General from .hosts import HostsResponse +from .iam_instance_profiles import IamInstanceProfiles from .instances import InstanceResponse from .internet_gateways import InternetGateways -from .egress_only_internet_gateways import EgressOnlyInternetGateway from .ip_addresses import IPAddresses from .key_pairs import KeyPairs from .launch_templates import LaunchTemplates from .monitoring import Monitoring +from .nat_gateways import NatGateways from .network_acls import NetworkACLs from .reserved_instances import ReservedInstances from .route_tables import RouteTables @@ -24,20 +28,16 @@ from .settings import Settings from .spot_fleets import SpotFleets from .spot_instances import SpotInstances from .subnets import Subnets -from .flow_logs import FlowLogs from .tags import TagResponse +from .transit_gateway_attachments import TransitGatewayAttachment +from .transit_gateway_route_tables import TransitGatewayRouteTable +from .transit_gateways import TransitGateways from .virtual_private_gateways import VirtualPrivateGateways -from .vpcs import VPCs -from .vpc_service_configuration import VPCEndpointServiceConfiguration from .vpc_peering_connections import VPCPeeringConnections +from .vpc_service_configuration import VPCEndpointServiceConfiguration +from .vpcs import VPCs from .vpn_connections import VPNConnections from .windows import Windows -from .nat_gateways import NatGateways -from .transit_gateways import TransitGateways -from .transit_gateway_route_tables import TransitGatewayRouteTable -from .transit_gateway_attachments import TransitGatewayAttachment -from .iam_instance_profiles import IamInstanceProfiles -from .carrier_gateways import CarrierGateway class EC2Response( diff --git a/moto/ec2/responses/_base_response.py b/moto/ec2/responses/_base_response.py index 05b2e698b..da11941fa 100644 --- a/moto/ec2/responses/_base_response.py +++ b/moto/ec2/responses/_base_response.py @@ -1,5 +1,7 @@ from typing import Any, Dict, Optional + from moto.core.responses import BaseResponse + from ..exceptions import EmptyTagSpecError, InvalidParameter from ..utils import convert_tag_spec diff --git a/moto/ec2/responses/amis.py b/moto/ec2/responses/amis.py index 64980fd40..c9e36607d 100644 --- a/moto/ec2/responses/amis.py +++ b/moto/ec2/responses/amis.py @@ -1,5 +1,5 @@ -from ._base_response import EC2BaseResponse from ..exceptions import AuthFailureRestricted, InvalidRequest +from ._base_response import EC2BaseResponse class AmisResponse(EC2BaseResponse): diff --git a/moto/ec2/responses/carrier_gateways.py b/moto/ec2/responses/carrier_gateways.py index 7e9a7618f..1f0ab19a4 100644 --- a/moto/ec2/responses/carrier_gateways.py +++ b/moto/ec2/responses/carrier_gateways.py @@ -1,4 +1,5 @@ from moto.ec2.utils import add_tag_specification + from ._base_response import EC2BaseResponse diff --git a/moto/ec2/responses/egress_only_internet_gateways.py b/moto/ec2/responses/egress_only_internet_gateways.py index 317ead69d..3b5107560 100644 --- a/moto/ec2/responses/egress_only_internet_gateways.py +++ b/moto/ec2/responses/egress_only_internet_gateways.py @@ -1,6 +1,7 @@ -from ._base_response import EC2BaseResponse from moto.ec2.utils import add_tag_specification +from ._base_response import EC2BaseResponse + class EgressOnlyInternetGateway(EC2BaseResponse): def create_egress_only_internet_gateway(self) -> str: diff --git a/moto/ec2/responses/elastic_ip_addresses.py b/moto/ec2/responses/elastic_ip_addresses.py index dc96c22b9..c421fc8c9 100644 --- a/moto/ec2/responses/elastic_ip_addresses.py +++ b/moto/ec2/responses/elastic_ip_addresses.py @@ -1,4 +1,5 @@ from moto.ec2.utils import add_tag_specification + from ._base_response import EC2BaseResponse diff --git a/moto/ec2/responses/elastic_network_interfaces.py b/moto/ec2/responses/elastic_network_interfaces.py index a4dba0fa2..fe25513ca 100644 --- a/moto/ec2/responses/elastic_network_interfaces.py +++ b/moto/ec2/responses/elastic_network_interfaces.py @@ -1,5 +1,6 @@ from moto.ec2.exceptions import InvalidParameterValueErrorUnknownAttribute -from moto.ec2.utils import get_attribute_value, add_tag_specification +from moto.ec2.utils import add_tag_specification, get_attribute_value + from ._base_response import EC2BaseResponse diff --git a/moto/ec2/responses/flow_logs.py b/moto/ec2/responses/flow_logs.py index 72c9ee461..5f8875eef 100644 --- a/moto/ec2/responses/flow_logs.py +++ b/moto/ec2/responses/flow_logs.py @@ -1,4 +1,5 @@ from moto.ec2.models import validate_resource_ids + from ._base_response import EC2BaseResponse diff --git a/moto/ec2/responses/instances.py b/moto/ec2/responses/instances.py index 9af62bab8..acadb8816 100644 --- a/moto/ec2/responses/instances.py +++ b/moto/ec2/responses/instances.py @@ -1,14 +1,14 @@ +from copy import deepcopy from typing import Any, Dict, List, Optional + from moto.core.utils import camelcase_to_underscores from moto.ec2.exceptions import ( - MissingParameterError, InvalidParameterCombination, InvalidRequest, + MissingParameterError, ) from moto.ec2.utils import filter_iam_instance_profiles -from copy import deepcopy - from ._base_response import EC2BaseResponse diff --git a/moto/ec2/responses/launch_templates.py b/moto/ec2/responses/launch_templates.py index 01e2c8ff8..f9df39a7a 100644 --- a/moto/ec2/responses/launch_templates.py +++ b/moto/ec2/responses/launch_templates.py @@ -1,10 +1,11 @@ from typing import Any +from xml.dom import minidom +from xml.etree import ElementTree + from moto.ec2.exceptions import FilterNotImplementedError from moto.moto_api._internal import mock_random -from ._base_response import EC2BaseResponse -from xml.etree import ElementTree -from xml.dom import minidom +from ._base_response import EC2BaseResponse def xml_root(name: str) -> ElementTree.Element: diff --git a/moto/ec2/responses/nat_gateways.py b/moto/ec2/responses/nat_gateways.py index 3e0be89c3..dc0b7744d 100644 --- a/moto/ec2/responses/nat_gateways.py +++ b/moto/ec2/responses/nat_gateways.py @@ -1,4 +1,5 @@ from moto.ec2.utils import add_tag_specification + from ._base_response import EC2BaseResponse diff --git a/moto/ec2/responses/security_groups.py b/moto/ec2/responses/security_groups.py index 04f2f8b54..f49c74ab3 100644 --- a/moto/ec2/responses/security_groups.py +++ b/moto/ec2/responses/security_groups.py @@ -1,4 +1,5 @@ from typing import Any, Dict, List, Tuple + from ._base_response import EC2BaseResponse diff --git a/moto/ec2/responses/tags.py b/moto/ec2/responses/tags.py index a57945d92..3b5dae1a6 100644 --- a/moto/ec2/responses/tags.py +++ b/moto/ec2/responses/tags.py @@ -1,5 +1,6 @@ -from moto.ec2.models import validate_resource_ids from moto.core.utils import tags_from_query_string +from moto.ec2.models import validate_resource_ids + from ._base_response import EC2BaseResponse diff --git a/moto/ec2/responses/transit_gateway_attachments.py b/moto/ec2/responses/transit_gateway_attachments.py index 751750d92..d16a9694a 100644 --- a/moto/ec2/responses/transit_gateway_attachments.py +++ b/moto/ec2/responses/transit_gateway_attachments.py @@ -1,4 +1,5 @@ from moto.ec2.utils import add_tag_specification + from ._base_response import EC2BaseResponse diff --git a/moto/ec2/responses/transit_gateway_route_tables.py b/moto/ec2/responses/transit_gateway_route_tables.py index 06039fc61..07cedcdc5 100644 --- a/moto/ec2/responses/transit_gateway_route_tables.py +++ b/moto/ec2/responses/transit_gateway_route_tables.py @@ -1,6 +1,7 @@ -from ._base_response import EC2BaseResponse from moto.utilities.utils import str2bool +from ._base_response import EC2BaseResponse + class TransitGatewayRouteTable(EC2BaseResponse): def create_transit_gateway_route_table(self) -> str: diff --git a/moto/ec2/responses/vpc_service_configuration.py b/moto/ec2/responses/vpc_service_configuration.py index 86de3fa28..9aee7861b 100644 --- a/moto/ec2/responses/vpc_service_configuration.py +++ b/moto/ec2/responses/vpc_service_configuration.py @@ -1,5 +1,5 @@ -from ._base_response import EC2BaseResponse from ..exceptions import NoLoadBalancersProvided +from ._base_response import EC2BaseResponse class VPCEndpointServiceConfiguration(EC2BaseResponse): diff --git a/moto/ec2/responses/vpcs.py b/moto/ec2/responses/vpcs.py index 93a80f90c..19de3cc2b 100644 --- a/moto/ec2/responses/vpcs.py +++ b/moto/ec2/responses/vpcs.py @@ -1,5 +1,6 @@ from moto.core.utils import camelcase_to_underscores from moto.ec2.utils import add_tag_specification + from ._base_response import EC2BaseResponse diff --git a/moto/ec2/responses/vpn_connections.py b/moto/ec2/responses/vpn_connections.py index 5db579adb..29fa2be2a 100644 --- a/moto/ec2/responses/vpn_connections.py +++ b/moto/ec2/responses/vpn_connections.py @@ -1,7 +1,9 @@ -from moto.ec2.utils import add_tag_specification -from ._base_response import EC2BaseResponse from xml.sax.saxutils import escape +from moto.ec2.utils import add_tag_specification + +from ._base_response import EC2BaseResponse + class VPNConnections(EC2BaseResponse): def create_vpn_connection(self) -> str: diff --git a/moto/ec2/responses/windows.py b/moto/ec2/responses/windows.py index 0169adb11..f5c58c517 100644 --- a/moto/ec2/responses/windows.py +++ b/moto/ec2/responses/windows.py @@ -1,6 +1,7 @@ -from ._base_response import EC2BaseResponse from moto.ec2.utils import utc_date_and_time +from ._base_response import EC2BaseResponse + class Windows(EC2BaseResponse): def bundle_instance(self) -> str: diff --git a/moto/ec2/urls.py b/moto/ec2/urls.py index 8ab8ead92..bbc58e373 100644 --- a/moto/ec2/urls.py +++ b/moto/ec2/urls.py @@ -1,6 +1,5 @@ from .responses import EC2Response - url_bases = [r"https?://ec2\.(.+)\.amazonaws\.com(|\.cn)"] url_paths = {"{0}/": EC2Response.dispatch} diff --git a/moto/ec2/utils.py b/moto/ec2/utils.py index 2ce0b03df..08638ac37 100644 --- a/moto/ec2/utils.py +++ b/moto/ec2/utils.py @@ -1,17 +1,17 @@ import base64 import fnmatch -import re import ipaddress +import re +from typing import Any, Dict, List, Optional, Set, Tuple, TypeVar, Union -from cryptography.hazmat.primitives import serialization from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives.asymmetric.ed25519 import ( - Ed25519PublicKey, Ed25519PrivateKey, + Ed25519PublicKey, ) from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey -from typing import Any, Dict, List, Set, TypeVar, Tuple, Optional, Union from moto.core.utils import utcnow from moto.iam import iam_backends diff --git a/moto/ec2instanceconnect/models.py b/moto/ec2instanceconnect/models.py index fe1aa74fb..8c5fb8187 100644 --- a/moto/ec2instanceconnect/models.py +++ b/moto/ec2instanceconnect/models.py @@ -1,5 +1,6 @@ import json -from moto.core import BaseBackend, BackendDict + +from moto.core import BackendDict, BaseBackend class Ec2InstanceConnectBackend(BaseBackend): diff --git a/moto/ec2instanceconnect/responses.py b/moto/ec2instanceconnect/responses.py index b01d03bb2..5101329cc 100644 --- a/moto/ec2instanceconnect/responses.py +++ b/moto/ec2instanceconnect/responses.py @@ -1,5 +1,6 @@ from moto.core.responses import BaseResponse -from .models import ec2instanceconnect_backends, Ec2InstanceConnectBackend + +from .models import Ec2InstanceConnectBackend, ec2instanceconnect_backends class Ec2InstanceConnectResponse(BaseResponse): diff --git a/moto/ecr/__init__.py b/moto/ecr/__init__.py index c85a33085..d093f47ea 100644 --- a/moto/ecr/__init__.py +++ b/moto/ecr/__init__.py @@ -1,5 +1,5 @@ -from .models import ecr_backends from ..core.models import base_decorator +from .models import ecr_backends ecr_backend = ecr_backends["us-east-1"] mock_ecr = base_decorator(ecr_backends) diff --git a/moto/ecr/models.py b/moto/ecr/models.py index 4a41e8eea..78cbd7a90 100644 --- a/moto/ecr/models.py +++ b/moto/ecr/models.py @@ -3,23 +3,23 @@ import json import re from collections import namedtuple from datetime import datetime, timezone -from typing import Any, Dict, List, Iterable, Optional, Tuple +from typing import Any, Dict, Iterable, List, Optional, Tuple from botocore.exceptions import ParamValidationError -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.core.utils import iso_8601_datetime_without_milliseconds, utcnow from moto.ecr.exceptions import ( + ImageAlreadyExistsException, ImageNotFoundException, - RepositoryNotFoundException, + InvalidParameterException, + LifecyclePolicyNotFoundException, + LimitExceededException, + RegistryPolicyNotFoundException, RepositoryAlreadyExistsException, RepositoryNotEmptyException, - InvalidParameterException, - ImageAlreadyExistsException, + RepositoryNotFoundException, RepositoryPolicyNotFoundException, - LifecyclePolicyNotFoundException, - RegistryPolicyNotFoundException, - LimitExceededException, ScanNotFoundException, ValidationException, ) diff --git a/moto/ecr/responses.py b/moto/ecr/responses.py index 68b806c8c..903a4d00e 100644 --- a/moto/ecr/responses.py +++ b/moto/ecr/responses.py @@ -1,10 +1,11 @@ import json +import time from base64 import b64encode from datetime import datetime -import time from moto.core.responses import BaseResponse -from .models import ecr_backends, ECRBackend + +from .models import ECRBackend, ecr_backends class ECRResponse(BaseResponse): diff --git a/moto/ecs/__init__.py b/moto/ecs/__init__.py index cf9b335db..52199aece 100644 --- a/moto/ecs/__init__.py +++ b/moto/ecs/__init__.py @@ -1,5 +1,5 @@ -from .models import ecs_backends from ..core.models import base_decorator +from .models import ecs_backends ecs_backend = ecs_backends["us-east-1"] mock_ecs = base_decorator(ecs_backends) diff --git a/moto/ecs/exceptions.py b/moto/ecs/exceptions.py index bb53b9996..7e634c83d 100644 --- a/moto/ecs/exceptions.py +++ b/moto/ecs/exceptions.py @@ -1,4 +1,4 @@ -from moto.core.exceptions import RESTError, JsonRESTError +from moto.core.exceptions import JsonRESTError, RESTError class ServiceNotFoundException(RESTError): diff --git a/moto/ecs/models.py b/moto/ecs/models.py index ba34ea05b..9886e354e 100644 --- a/moto/ecs/models.py +++ b/moto/ecs/models.py @@ -1,30 +1,29 @@ import re from copy import copy from datetime import datetime, timezone -from typing import Any, Dict, Iterator, List, Optional, Tuple from os import getenv +from typing import Any, Dict, Iterator, List, Optional, Tuple from moto import settings -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.core.exceptions import JsonRESTError -from moto.core.utils import unix_time, pascal_to_camelcase, remap_nested_keys - -from ..ec2.utils import random_private_ip +from moto.core.utils import pascal_to_camelcase, remap_nested_keys, unix_time from moto.ec2 import ec2_backends from moto.moto_api import state_manager from moto.moto_api._internal import mock_random from moto.moto_api._internal.managed_state_model import ManagedState +from ..ec2.utils import random_private_ip from .exceptions import ( - EcsClientException, - ServiceNotFoundException, - TaskDefinitionNotFoundException, - TaskSetNotFoundException, ClusterNotFoundException, + EcsClientException, InvalidParameterException, RevisionNotFoundException, + ServiceNotFoundException, TaskDefinitionMemoryError, TaskDefinitionMissingPropertyError, + TaskDefinitionNotFoundException, + TaskSetNotFoundException, UnknownAccountSettingException, ) diff --git a/moto/ecs/responses.py b/moto/ecs/responses.py index 40fa7278f..dd40d60cf 100644 --- a/moto/ecs/responses.py +++ b/moto/ecs/responses.py @@ -2,7 +2,8 @@ import json from typing import Any, Dict from moto.core.responses import BaseResponse -from .models import ecs_backends, EC2ContainerServiceBackend + +from .models import EC2ContainerServiceBackend, ecs_backends class EC2ContainerServiceResponse(BaseResponse): diff --git a/moto/efs/models.py b/moto/efs/models.py index 20b1e7aca..88a31ebdd 100644 --- a/moto/efs/models.py +++ b/moto/efs/models.py @@ -7,14 +7,14 @@ https://docs.aws.amazon.com/efs/latest/ug/whatisefs.html import json import time from copy import deepcopy -from typing import Any, Dict, List, Optional, Tuple, Set, Iterator, Union +from typing import Any, Dict, Iterator, List, Optional, Set, Tuple, Union -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.core.utils import camelcase_to_underscores, underscores_to_camelcase from moto.ec2 import ec2_backends +from moto.ec2.exceptions import InvalidSubnetIdError from moto.ec2.models.elastic_network_interfaces import NetworkInterface from moto.ec2.models.subnets import Subnet -from moto.ec2.exceptions import InvalidSubnetIdError from moto.efs.exceptions import ( AccessPointNotFound, BadRequest, @@ -24,9 +24,9 @@ from moto.efs.exceptions import ( MountTargetConflict, MountTargetNotFound, PolicyNotFound, - SubnetNotFound, - SecurityGroupNotFound, SecurityGroupLimitExceeded, + SecurityGroupNotFound, + SubnetNotFound, ) from moto.moto_api._internal import mock_random from moto.utilities.tagging_service import TaggingService diff --git a/moto/efs/responses.py b/moto/efs/responses.py index 44d3613b9..97fa89378 100644 --- a/moto/efs/responses.py +++ b/moto/efs/responses.py @@ -3,8 +3,7 @@ from typing import Any, Dict, Tuple, Union from moto.core.responses import BaseResponse -from .models import efs_backends, EFSBackend - +from .models import EFSBackend, efs_backends TYPE_RESPONSE = Tuple[str, Dict[str, Union[str, int]]] diff --git a/moto/eks/models.py b/moto/eks/models.py index 74df856df..c85c81b2f 100644 --- a/moto/eks/models.py +++ b/moto/eks/models.py @@ -1,7 +1,7 @@ from datetime import datetime -from typing import Any, Dict, List, Optional, Tuple, Iterator +from typing import Any, Dict, Iterator, List, Optional, Tuple -from moto.core import BaseBackend, BackendDict +from moto.core import BackendDict, BaseBackend from moto.core.utils import iso_8601_datetime_without_milliseconds from moto.moto_api._internal import mock_random as random diff --git a/moto/eks/responses.py b/moto/eks/responses.py index b87054eab..1fa70d97d 100644 --- a/moto/eks/responses.py +++ b/moto/eks/responses.py @@ -1,10 +1,11 @@ import json from typing import Any from urllib.parse import unquote + from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from .models import eks_backends, EKSBackend +from .models import EKSBackend, eks_backends DEFAULT_MAX_RESULTS = 100 DEFAULT_NEXT_TOKEN = "" diff --git a/moto/elasticache/__init__.py b/moto/elasticache/__init__.py index 44da97871..741fe68ee 100644 --- a/moto/elasticache/__init__.py +++ b/moto/elasticache/__init__.py @@ -1,4 +1,4 @@ -from .models import elasticache_backends from ..core.models import base_decorator +from .models import elasticache_backends mock_elasticache = base_decorator(elasticache_backends) diff --git a/moto/elasticache/models.py b/moto/elasticache/models.py index 4772463de..da3978895 100644 --- a/moto/elasticache/models.py +++ b/moto/elasticache/models.py @@ -1,15 +1,15 @@ -from typing import List, Optional, Dict, Any, Tuple +from typing import Any, Dict, List, Optional, Tuple -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import utcnow +from ..moto_api._internal import mock_random from .exceptions import ( - UserAlreadyExists, - UserNotFound, CacheClusterAlreadyExists, CacheClusterNotFound, + UserAlreadyExists, + UserNotFound, ) -from ..moto_api._internal import mock_random class User(BaseModel): diff --git a/moto/elasticache/responses.py b/moto/elasticache/responses.py index 66a78a8e6..19fdbf515 100644 --- a/moto/elasticache/responses.py +++ b/moto/elasticache/responses.py @@ -1,7 +1,7 @@ from moto.core.responses import BaseResponse -from .exceptions import PasswordTooShort, PasswordRequired -from .models import elasticache_backends, ElastiCacheBackend +from .exceptions import PasswordRequired, PasswordTooShort +from .models import ElastiCacheBackend, elasticache_backends class ElastiCacheResponse(BaseResponse): diff --git a/moto/elasticbeanstalk/__init__.py b/moto/elasticbeanstalk/__init__.py index 851fa445b..41eb28565 100644 --- a/moto/elasticbeanstalk/__init__.py +++ b/moto/elasticbeanstalk/__init__.py @@ -1,4 +1,5 @@ -from .models import eb_backends from moto.core.models import base_decorator +from .models import eb_backends + mock_elasticbeanstalk = base_decorator(eb_backends) diff --git a/moto/elasticbeanstalk/models.py b/moto/elasticbeanstalk/models.py index e90887770..8cdb1dfa9 100644 --- a/moto/elasticbeanstalk/models.py +++ b/moto/elasticbeanstalk/models.py @@ -1,12 +1,12 @@ import weakref from typing import Dict, List -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from .exceptions import ( + ApplicationNotFound, InvalidParameterValueError, ResourceNotFoundException, - ApplicationNotFound, ) from .utils import make_arn diff --git a/moto/elasticbeanstalk/responses.py b/moto/elasticbeanstalk/responses.py index e1e24741f..422f14b02 100644 --- a/moto/elasticbeanstalk/responses.py +++ b/moto/elasticbeanstalk/responses.py @@ -2,7 +2,7 @@ from moto.core.responses import BaseResponse from moto.core.utils import tags_from_query_string from .exceptions import InvalidParameterValueError -from .models import eb_backends, EBBackend +from .models import EBBackend, eb_backends class EBResponse(BaseResponse): diff --git a/moto/elastictranscoder/__init__.py b/moto/elastictranscoder/__init__.py index 9ac6afd75..b5013cc35 100644 --- a/moto/elastictranscoder/__init__.py +++ b/moto/elastictranscoder/__init__.py @@ -1,4 +1,4 @@ -from .models import elastictranscoder_backends from ..core.models import base_decorator +from .models import elastictranscoder_backends mock_elastictranscoder = base_decorator(elastictranscoder_backends) diff --git a/moto/elastictranscoder/models.py b/moto/elastictranscoder/models.py index d836c4c98..c5d416cd6 100644 --- a/moto/elastictranscoder/models.py +++ b/moto/elastictranscoder/models.py @@ -1,7 +1,8 @@ -from typing import Any, Dict, List, Tuple -from moto.core import BaseBackend, BackendDict, BaseModel -from moto.moto_api._internal import mock_random as random import string +from typing import Any, Dict, List, Tuple + +from moto.core import BackendDict, BaseBackend, BaseModel +from moto.moto_api._internal import mock_random as random class Pipeline(BaseModel): diff --git a/moto/elastictranscoder/responses.py b/moto/elastictranscoder/responses.py index f2aa81091..99fc116c6 100644 --- a/moto/elastictranscoder/responses.py +++ b/moto/elastictranscoder/responses.py @@ -1,9 +1,11 @@ -from typing import Any, Optional -from moto.core.common_types import TYPE_RESPONSE -from moto.core.responses import BaseResponse -from .models import elastictranscoder_backends, ElasticTranscoderBackend import json import re +from typing import Any, Optional + +from moto.core.common_types import TYPE_RESPONSE +from moto.core.responses import BaseResponse + +from .models import ElasticTranscoderBackend, elastictranscoder_backends class ElasticTranscoderResponse(BaseResponse): diff --git a/moto/elb/__init__.py b/moto/elb/__init__.py index 5fc8a33e8..ee35c435c 100644 --- a/moto/elb/__init__.py +++ b/moto/elb/__init__.py @@ -1,5 +1,5 @@ -from .models import elb_backends from ..core.models import base_decorator +from .models import elb_backends elb_backend = elb_backends["us-east-1"] mock_elb = base_decorator(elb_backends) diff --git a/moto/elb/exceptions.py b/moto/elb/exceptions.py index 63e806869..154fc348d 100644 --- a/moto/elb/exceptions.py +++ b/moto/elb/exceptions.py @@ -1,4 +1,5 @@ from typing import Any + from moto.core.exceptions import RESTError diff --git a/moto/elb/models.py b/moto/elb/models.py index 5c9837939..9c1fba044 100644 --- a/moto/elb/models.py +++ b/moto/elb/models.py @@ -1,22 +1,23 @@ import datetime from collections import OrderedDict -from typing import Any, Dict, List, Iterable, Optional +from typing import Any, Dict, Iterable, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel -from moto.ec2.models import ec2_backends +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.ec2.exceptions import InvalidInstanceIdError +from moto.ec2.models import ec2_backends from moto.moto_api._internal import mock_random + from .exceptions import ( BadHealthCheckDefinition, - DuplicateLoadBalancerName, + CertificateNotFoundException, DuplicateListenerError, + DuplicateLoadBalancerName, EmptyListenersError, InvalidSecurityGroupError, LoadBalancerNotFoundError, NoActiveLoadBalancerFoundError, PolicyNotFoundError, TooManyTagsError, - CertificateNotFoundException, ) from .policies import ( AppCookieStickinessPolicy, @@ -619,7 +620,7 @@ class ELBBackend(BaseBackend): return load_balancer def _register_certificate(self, ssl_certificate_id: str, dns_name: str) -> None: - from moto.acm.models import acm_backends, CertificateNotFound + from moto.acm.models import CertificateNotFound, acm_backends acm_backend = acm_backends[self.account_id][self.region_name] try: diff --git a/moto/elb/responses.py b/moto/elb/responses.py index d772948ae..f8bf14320 100644 --- a/moto/elb/responses.py +++ b/moto/elb/responses.py @@ -1,6 +1,7 @@ from moto.core.responses import BaseResponse -from .models import elb_backends, ELBBackend, FakeLoadBalancer + from .exceptions import DuplicateTagKeysError, LoadBalancerNotFoundError +from .models import ELBBackend, FakeLoadBalancer, elb_backends class ELBResponse(BaseResponse): diff --git a/moto/elb/urls.py b/moto/elb/urls.py index 5b2a5f5bc..f209b29b6 100644 --- a/moto/elb/urls.py +++ b/moto/elb/urls.py @@ -1,5 +1,6 @@ from typing import Any from urllib.parse import parse_qs + from botocore.awsrequest import AWSPreparedRequest from moto.elb.responses import ELBResponse diff --git a/moto/elbv2/__init__.py b/moto/elbv2/__init__.py index 5217dd29f..3a82b9b5b 100644 --- a/moto/elbv2/__init__.py +++ b/moto/elbv2/__init__.py @@ -1,5 +1,5 @@ -from .models import elbv2_backends from ..core.models import base_decorator +from .models import elbv2_backends elb_backend = elbv2_backends["us-east-1"] mock_elbv2 = base_decorator(elbv2_backends) diff --git a/moto/elbv2/exceptions.py b/moto/elbv2/exceptions.py index 469758e7b..97fcf48ca 100644 --- a/moto/elbv2/exceptions.py +++ b/moto/elbv2/exceptions.py @@ -1,4 +1,5 @@ from typing import Any, Optional + from moto.core.exceptions import RESTError diff --git a/moto/elbv2/models.py b/moto/elbv2/models.py index 11c31ce39..fad376219 100644 --- a/moto/elbv2/models.py +++ b/moto/elbv2/models.py @@ -1,43 +1,45 @@ import re -from jinja2 import Template -from botocore.exceptions import ParamValidationError from collections import OrderedDict -from typing import Any, List, Dict, Iterable, Optional +from typing import Any, Dict, Iterable, List, Optional + +from botocore.exceptions import ParamValidationError +from jinja2 import Template + +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.core.exceptions import RESTError -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel from moto.core.utils import iso_8601_datetime_with_milliseconds from moto.ec2.models import ec2_backends from moto.ec2.models.subnets import Subnet from moto.moto_api._internal import mock_random from moto.utilities.tagging_service import TaggingService -from .utils import make_arn_for_target_group -from .utils import make_arn_for_load_balancer + from .exceptions import ( - DuplicateLoadBalancerName, + ActionTargetGroupNotFoundError, DuplicateListenerError, + DuplicateLoadBalancerName, + DuplicatePriorityError, DuplicateTargetGroupName, + InvalidActionTypeError, + InvalidConditionFieldError, + InvalidConditionValueError, + InvalidConfigurationRequest, + InvalidDescribeRulesRequest, + InvalidLoadBalancerActionException, + InvalidModifyRuleArgumentsError, + InvalidStatusCodeActionTypeError, InvalidTargetError, + InvalidTargetGroupNameError, ListenerNotFoundError, LoadBalancerNotFoundError, + PriorityInUseError, + ResourceInUseError, + RuleNotFoundError, SubnetNotFoundError, TargetGroupNotFoundError, TooManyTagsError, - PriorityInUseError, - InvalidConditionFieldError, - InvalidConditionValueError, - InvalidActionTypeError, - ActionTargetGroupNotFoundError, - InvalidDescribeRulesRequest, - ResourceInUseError, - RuleNotFoundError, - DuplicatePriorityError, - InvalidTargetGroupNameError, - InvalidModifyRuleArgumentsError, - InvalidStatusCodeActionTypeError, - InvalidLoadBalancerActionException, ValidationError, - InvalidConfigurationRequest, ) +from .utils import make_arn_for_load_balancer, make_arn_for_target_group ALLOWED_ACTIONS = [ "redirect", @@ -1868,7 +1870,7 @@ Member must satisfy regular expression pattern: {expression}" """ Verify the provided certificate exists in either ACM or IAM """ - from moto.acm.models import acm_backends, CertificateNotFound + from moto.acm.models import CertificateNotFound, acm_backends try: acm_backend = acm_backends[self.account_id][self.region_name] diff --git a/moto/elbv2/responses.py b/moto/elbv2/responses.py index 0f9030d96..2df73d292 100644 --- a/moto/elbv2/responses.py +++ b/moto/elbv2/responses.py @@ -1,9 +1,9 @@ from moto.core.exceptions import RESTError from moto.core.responses import BaseResponse from moto.utilities.aws_headers import amzn_request_id -from .models import elbv2_backends, ELBv2Backend -from .exceptions import TargetGroupNotFoundError -from .exceptions import ListenerOrBalancerMissingError + +from .exceptions import ListenerOrBalancerMissingError, TargetGroupNotFoundError +from .models import ELBv2Backend, elbv2_backends SSL_POLICIES = [ { diff --git a/moto/emr/__init__.py b/moto/emr/__init__.py index dc95b003a..c96f2bf11 100644 --- a/moto/emr/__init__.py +++ b/moto/emr/__init__.py @@ -1,5 +1,5 @@ -from .models import emr_backends from ..core.models import base_decorator +from .models import emr_backends emr_backend = emr_backends["us-east-1"] mock_emr = base_decorator(emr_backends) diff --git a/moto/emr/models.py b/moto/emr/models.py index d07d52004..863c2b0a7 100644 --- a/moto/emr/models.py +++ b/moto/emr/models.py @@ -1,20 +1,22 @@ +import warnings from datetime import datetime, timedelta, timezone from typing import Any, Dict, List, Optional, Tuple -import warnings from dateutil.parser import parse as dtparse -from moto.core import BaseBackend, BackendDict, BaseModel + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.emr.exceptions import ( InvalidRequestException, - ValidationException, ResourceNotFoundException, + ValidationException, ) + from .utils import ( - random_instance_group_id, - random_cluster_id, - random_step_id, CamelToUnderscoresWalker, EmrSecurityGroupManager, + random_cluster_id, + random_instance_group_id, + random_step_id, ) EXAMPLE_AMI_ID = "ami-12c6146b" diff --git a/moto/emr/responses.py b/moto/emr/responses.py index 77819e31d..f047743ec 100644 --- a/moto/emr/responses.py +++ b/moto/emr/responses.py @@ -4,13 +4,12 @@ from datetime import datetime, timezone from functools import wraps from typing import Any, Callable, Dict, List, Pattern -from moto.core.responses import AWSServiceSpec -from moto.core.responses import BaseResponse -from moto.core.responses import xml_to_json_response +from moto.core.responses import AWSServiceSpec, BaseResponse, xml_to_json_response from moto.core.utils import tags_from_query_string + from .exceptions import ValidationException -from .models import emr_backends, ElasticMapReduceBackend -from .utils import steps_from_query_string, Unflattener, ReleaseLabel +from .models import ElasticMapReduceBackend, emr_backends +from .utils import ReleaseLabel, Unflattener, steps_from_query_string def generate_boto3_response( diff --git a/moto/emr/utils.py b/moto/emr/utils.py index 3423db462..53f28b7ac 100644 --- a/moto/emr/utils.py +++ b/moto/emr/utils.py @@ -1,7 +1,8 @@ import copy import re import string -from typing import Any, List, Dict, Tuple, Iterator +from typing import Any, Dict, Iterator, List, Tuple + from moto.core.utils import ( camelcase_to_underscores, iso_8601_datetime_with_milliseconds, diff --git a/moto/emrcontainers/__init__.py b/moto/emrcontainers/__init__.py index 3af933a85..f4989de54 100644 --- a/moto/emrcontainers/__init__.py +++ b/moto/emrcontainers/__init__.py @@ -1,6 +1,6 @@ """emrcontainers module initialization; sets value for base decorator.""" -from .models import emrcontainers_backends from ..core.models import base_decorator +from .models import emrcontainers_backends REGION = "us-east-1" mock_emrcontainers = base_decorator(emrcontainers_backends) diff --git a/moto/emrcontainers/models.py b/moto/emrcontainers/models.py index ac2c091c0..0211e432d 100644 --- a/moto/emrcontainers/models.py +++ b/moto/emrcontainers/models.py @@ -1,15 +1,14 @@ """EMRContainersBackend class with methods for supported APIs.""" import re from datetime import datetime -from typing import Any, Dict, List, Optional, Tuple, Iterator +from typing import Any, Dict, Iterator, List, Optional, Tuple -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import iso_8601_datetime_without_milliseconds -from .utils import random_cluster_id, random_job_id, get_partition, paginated_list -from .exceptions import ResourceNotFoundException - from ..config.exceptions import ValidationException +from .exceptions import ResourceNotFoundException +from .utils import get_partition, paginated_list, random_cluster_id, random_job_id VIRTUAL_CLUSTER_ARN_TEMPLATE = "arn:{partition}:emr-containers:{region}:{account_id}:/virtualclusters/{virtual_cluster_id}" diff --git a/moto/emrcontainers/responses.py b/moto/emrcontainers/responses.py index 09ba85e29..43eebaf99 100644 --- a/moto/emrcontainers/responses.py +++ b/moto/emrcontainers/responses.py @@ -1,8 +1,10 @@ """Handles incoming emrcontainers requests, invokes methods, returns responses.""" import json + from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from .models import emrcontainers_backends, EMRContainersBackend + +from .models import EMRContainersBackend, emrcontainers_backends DEFAULT_MAX_RESULTS = 100 DEFAULT_NEXT_TOKEN = "" diff --git a/moto/emrcontainers/utils.py b/moto/emrcontainers/utils.py index 5844326fc..5ab3f79f7 100644 --- a/moto/emrcontainers/utils.py +++ b/moto/emrcontainers/utils.py @@ -1,6 +1,7 @@ # import json import string from typing import Any, List, Optional, Tuple + from moto.moto_api._internal import mock_random as random diff --git a/moto/emrserverless/__init__.py b/moto/emrserverless/__init__.py index 41abab280..91a973dce 100644 --- a/moto/emrserverless/__init__.py +++ b/moto/emrserverless/__init__.py @@ -1,6 +1,6 @@ """emrserverless module initialization; sets value for base decorator.""" -from .models import emrserverless_backends from ..core.models import base_decorator +from .models import emrserverless_backends REGION = "us-east-1" RELEASE_LABEL = "emr-6.6.0" diff --git a/moto/emrserverless/models.py b/moto/emrserverless/models.py index efdd4e245..fab76443d 100644 --- a/moto/emrserverless/models.py +++ b/moto/emrserverless/models.py @@ -1,20 +1,20 @@ """EMRServerlessBackend class with methods for supported APIs.""" +import inspect import re from datetime import datetime -from typing import Any, Dict, List, Optional, Tuple, Iterator -import inspect +from typing import Any, Dict, Iterator, List, Optional, Tuple -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import iso_8601_datetime_without_milliseconds from moto.emrcontainers.utils import get_partition, paginated_list + +from .exceptions import ResourceNotFoundException, ValidationException from .utils import ( default_auto_start_configuration, default_auto_stop_configuration, random_appplication_id, ) -from .exceptions import ResourceNotFoundException, ValidationException - APPLICATION_ARN_TEMPLATE = "arn:{partition}:emr-containers:{region}:{account_id}:/applications/{application_id}" # Defaults used for creating an EMR Serverless application diff --git a/moto/emrserverless/responses.py b/moto/emrserverless/responses.py index 0e3bbc5e5..e36930517 100644 --- a/moto/emrserverless/responses.py +++ b/moto/emrserverless/responses.py @@ -3,7 +3,8 @@ import json from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from .models import emrserverless_backends, EMRServerlessBackend + +from .models import EMRServerlessBackend, emrserverless_backends DEFAULT_MAX_RESULTS = 100 DEFAULT_NEXT_TOKEN = "" diff --git a/moto/emrserverless/utils.py b/moto/emrserverless/utils.py index fd3bc3de0..96ddb52a5 100644 --- a/moto/emrserverless/utils.py +++ b/moto/emrserverless/utils.py @@ -1,7 +1,8 @@ -from moto.moto_api._internal import mock_random as random import string from typing import Any, Dict +from moto.moto_api._internal import mock_random as random + def random_id(size: int = 13) -> str: chars = list(range(10)) + list(string.ascii_lowercase) diff --git a/moto/es/__init__.py b/moto/es/__init__.py index c015d07da..23fa6f338 100644 --- a/moto/es/__init__.py +++ b/moto/es/__init__.py @@ -1,5 +1,5 @@ """es module initialization; sets value for base decorator.""" -from .models import es_backends from ..core.models import base_decorator +from .models import es_backends mock_es = base_decorator(es_backends) diff --git a/moto/es/models.py b/moto/es/models.py index eda2e915f..fe18e1e4b 100644 --- a/moto/es/models.py +++ b/moto/es/models.py @@ -1,6 +1,8 @@ from typing import Any, Dict, List -from moto.core import BaseBackend, BackendDict, BaseModel + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.moto_api._internal import mock_random + from .exceptions import DomainNotFound diff --git a/moto/es/responses.py b/moto/es/responses.py index 3fb4f7e6d..d8e7ac813 100644 --- a/moto/es/responses.py +++ b/moto/es/responses.py @@ -4,8 +4,9 @@ from typing import Any from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse + from .exceptions import InvalidDomainName -from .models import es_backends, ElasticsearchServiceBackend +from .models import ElasticsearchServiceBackend, es_backends class ElasticsearchServiceResponse(BaseResponse): diff --git a/moto/es/urls.py b/moto/es/urls.py index b26bfd9ca..c1c234de0 100644 --- a/moto/es/urls.py +++ b/moto/es/urls.py @@ -1,6 +1,7 @@ -from .responses import ElasticsearchServiceResponse from moto.opensearch.responses import OpenSearchServiceResponse +from .responses import ElasticsearchServiceResponse + url_bases = [ r"https?://es\.(.+)\.amazonaws\.com", ] diff --git a/moto/events/__init__.py b/moto/events/__init__.py index ec0c24e4b..d40e230b1 100644 --- a/moto/events/__init__.py +++ b/moto/events/__init__.py @@ -1,5 +1,5 @@ -from .models import events_backends from ..core.models import base_decorator +from .models import events_backends events_backend = events_backends["us-east-1"] mock_events = base_decorator(events_backends) diff --git a/moto/events/exceptions.py b/moto/events/exceptions.py index eb5e6f795..179b8d474 100644 --- a/moto/events/exceptions.py +++ b/moto/events/exceptions.py @@ -1,4 +1,5 @@ from typing import Optional + from moto.core.exceptions import JsonRESTError diff --git a/moto/events/models.py b/moto/events/models.py index 7e33ef189..f413eca8c 100644 --- a/moto/events/models.py +++ b/moto/events/models.py @@ -1,32 +1,32 @@ import copy +import json import os import re -import requests -import json import sys import warnings +from collections import OrderedDict from datetime import datetime from enum import Enum, unique from json import JSONDecodeError -from operator import lt, le, eq, ge, gt +from operator import eq, ge, gt, le, lt from typing import Any, Dict, List, Optional, Tuple -from collections import OrderedDict +import requests from moto import settings +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.core.exceptions import JsonRESTError -from moto.core import BaseBackend, BackendDict, CloudFormationModel, BaseModel from moto.core.utils import ( + iso_8601_datetime_without_milliseconds, unix_time, unix_time_millis, - iso_8601_datetime_without_milliseconds, ) from moto.events.exceptions import ( - ValidationException, - ResourceNotFoundException, - ResourceAlreadyExistsException, - InvalidEventPatternException, IllegalStatusException, + InvalidEventPatternException, + ResourceAlreadyExistsException, + ResourceNotFoundException, + ValidationException, ) from moto.moto_api._internal import mock_random as random from moto.utilities.arns import parse_arn diff --git a/moto/events/notifications.py b/moto/events/notifications.py index 0883dd147..78da67f13 100644 --- a/moto/events/notifications.py +++ b/moto/events/notifications.py @@ -1,7 +1,6 @@ import json from typing import Any, Dict - _EVENT_S3_OBJECT_CREATED: Dict[str, Any] = { "version": "0", "id": "17793124-05d4-b198-2fde-7ededc63b103", diff --git a/moto/events/responses.py b/moto/events/responses.py index dfde6a65b..1e5787320 100644 --- a/moto/events/responses.py +++ b/moto/events/responses.py @@ -1,7 +1,8 @@ import json from typing import Any, Dict, Tuple + from moto.core.responses import BaseResponse -from moto.events.models import events_backends, EventsBackend +from moto.events.models import EventsBackend, events_backends class EventsHandler(BaseResponse): diff --git a/moto/firehose/__init__.py b/moto/firehose/__init__.py index 06964e274..815ab47be 100644 --- a/moto/firehose/__init__.py +++ b/moto/firehose/__init__.py @@ -1,5 +1,5 @@ """Firehose module initialization; sets value for base decorator.""" -from .models import firehose_backends from ..core.models import base_decorator +from .models import firehose_backends mock_firehose = base_decorator(firehose_backends) diff --git a/moto/firehose/models.py b/moto/firehose/models.py index f253db770..f22aeff87 100644 --- a/moto/firehose/models.py +++ b/moto/firehose/models.py @@ -11,18 +11,18 @@ Incomplete list of unfinished items: are reported back to the user. Instead an exception is raised. - put_record(), put_record_batch() always set "Encrypted" to False. """ +import io +import json +import warnings from base64 import b64decode, b64encode from datetime import datetime, timezone from gzip import GzipFile -from typing import Any, Dict, List, Optional, Tuple -import io -import json from time import time -import warnings +from typing import Any, Dict, List, Optional, Tuple import requests -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import utcnow from moto.firehose.exceptions import ( ConcurrentModificationException, diff --git a/moto/firehose/responses.py b/moto/firehose/responses.py index c36125fd5..096830128 100644 --- a/moto/firehose/responses.py +++ b/moto/firehose/responses.py @@ -2,7 +2,8 @@ import json from moto.core.responses import BaseResponse -from .models import firehose_backends, FirehoseBackend + +from .models import FirehoseBackend, firehose_backends class FirehoseResponse(BaseResponse): diff --git a/moto/firehose/urls.py b/moto/firehose/urls.py index f3d6f49b8..8d332099b 100644 --- a/moto/firehose/urls.py +++ b/moto/firehose/urls.py @@ -1,6 +1,5 @@ """Firehose base URL and path.""" from .responses import FirehoseResponse - url_bases = [r"https?://firehose\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": FirehoseResponse.dispatch} diff --git a/moto/forecast/__init__.py b/moto/forecast/__init__.py index e8fb838b4..147250b16 100644 --- a/moto/forecast/__init__.py +++ b/moto/forecast/__init__.py @@ -1,5 +1,5 @@ -from .models import forecast_backends from ..core.models import base_decorator +from .models import forecast_backends forecast_backend = forecast_backends["us-east-1"] mock_forecast = base_decorator(forecast_backends) diff --git a/moto/forecast/models.py b/moto/forecast/models.py index ad75ca722..a1fe901f8 100644 --- a/moto/forecast/models.py +++ b/moto/forecast/models.py @@ -2,8 +2,9 @@ import re from datetime import datetime from typing import Dict, List, Optional -from moto.core import BaseBackend, BackendDict +from moto.core import BackendDict, BaseBackend from moto.core.utils import iso_8601_datetime_without_milliseconds + from .exceptions import ( InvalidInputException, ResourceAlreadyExistsException, diff --git a/moto/forecast/responses.py b/moto/forecast/responses.py index 7186cf4ec..3d4dfa0ac 100644 --- a/moto/forecast/responses.py +++ b/moto/forecast/responses.py @@ -3,7 +3,8 @@ import json from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse from moto.utilities.aws_headers import amzn_request_id -from .models import forecast_backends, ForecastBackend + +from .models import ForecastBackend, forecast_backends class ForecastResponse(BaseResponse): diff --git a/moto/glacier/__init__.py b/moto/glacier/__init__.py index 4dec88933..57a9ff943 100644 --- a/moto/glacier/__init__.py +++ b/moto/glacier/__init__.py @@ -1,5 +1,5 @@ -from .models import glacier_backends from ..core.models import base_decorator +from .models import glacier_backends glacier_backend = glacier_backends["us-east-1"] mock_glacier = base_decorator(glacier_backends) diff --git a/moto/glacier/models.py b/moto/glacier/models.py index bbf5578dc..e97d636e9 100644 --- a/moto/glacier/models.py +++ b/moto/glacier/models.py @@ -1,8 +1,8 @@ -import hashlib import datetime +import hashlib from typing import Any, Dict, List, Optional, Union -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.exceptions import JsonRESTError from moto.utilities.utils import md5_hash diff --git a/moto/glacier/responses.py b/moto/glacier/responses.py index ceaf27328..85b4fb15c 100644 --- a/moto/glacier/responses.py +++ b/moto/glacier/responses.py @@ -1,8 +1,10 @@ import json from typing import Any, Dict + from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from .models import glacier_backends, GlacierBackend + +from .models import GlacierBackend, glacier_backends from .utils import vault_from_glacier_url diff --git a/moto/glacier/utils.py b/moto/glacier/utils.py index 067c1f844..cf2753cfc 100644 --- a/moto/glacier/utils.py +++ b/moto/glacier/utils.py @@ -1,6 +1,7 @@ -from moto.moto_api._internal import mock_random as random import string +from moto.moto_api._internal import mock_random as random + def vault_from_glacier_url(full_url: str) -> str: return full_url.split("/")[-1] diff --git a/moto/glue/__init__.py b/moto/glue/__init__.py index ec47f973c..aa9b85fa3 100644 --- a/moto/glue/__init__.py +++ b/moto/glue/__init__.py @@ -1,4 +1,4 @@ -from .models import glue_backends from ..core.models import base_decorator +from .models import glue_backends mock_glue = base_decorator(glue_backends) diff --git a/moto/glue/exceptions.py b/moto/glue/exceptions.py index dfa71bcfe..a8d41d39f 100644 --- a/moto/glue/exceptions.py +++ b/moto/glue/exceptions.py @@ -1,4 +1,5 @@ from typing import Optional + from moto.core.exceptions import JsonRESTError diff --git a/moto/glue/glue_schema_registry_utils.py b/moto/glue/glue_schema_registry_utils.py index 3a9bddd2b..69bbdde61 100644 --- a/moto/glue/glue_schema_registry_utils.py +++ b/moto/glue/glue_schema_registry_utils.py @@ -1,57 +1,56 @@ -import re import json -from typing import Any, Dict, Optional, Tuple, Pattern - -from .glue_schema_registry_constants import ( - MAX_REGISTRY_NAME_LENGTH, - RESOURCE_NAME_PATTERN, - MAX_ARN_LENGTH, - ARN_PATTERN, - MAX_DESCRIPTION_LENGTH, - DESCRIPTION_PATTERN, - MAX_SCHEMA_NAME_LENGTH, - DEFAULT_REGISTRY_NAME, - REGISTRY_NAME, - REGISTRY_ARN, - SCHEMA_NAME, - SCHEMA_ARN, - MAX_TAGS_ALLOWED, - MAX_SCHEMA_DEFINITION_LENGTH, - SCHEMA_DEFINITION, - MAX_SCHEMAS_ALLOWED, - MAX_SCHEMA_VERSIONS_ALLOWED, - MAX_REGISTRIES_ALLOWED, - SCHEMA_VERSION_ID_PATTERN, - SCHEMA_VERSION_ID, - VERSION_NUMBER, - LATEST_VERSION, - METADATA_VALUE, - METADATA_KEY, - MAX_SCHEMA_VERSION_METADATA_LENGTH, - SCHEMA_VERSION_METADATA_PATTERN, - MAX_SCHEMA_VERSION_METADATA_ALLOWED, -) +import re +from typing import Any, Dict, Optional, Pattern, Tuple from .exceptions import ( - ResourceNameTooLongException, - ParamValueContainsInvalidCharactersException, - InvalidSchemaDefinitionException, - InvalidRegistryIdBothParamsProvidedException, - RegistryNotFoundException, - InvalidSchemaIdBothParamsProvidedException, - InvalidSchemaIdNotProvidedException, - SchemaNotFoundException, - InvalidDataFormatException, - InvalidCompatibilityException, - InvalidNumberOfTagsException, + DisabledCompatibilityVersioningException, GeneralGSRAlreadyExistsException, GeneralResourceNumberLimitExceededException, - DisabledCompatibilityVersioningException, - InvalidSchemaVersionNumberBothParamsProvidedException, + InvalidCompatibilityException, + InvalidDataFormatException, + InvalidNumberOfTagsException, + InvalidRegistryIdBothParamsProvidedException, + InvalidSchemaDefinitionException, + InvalidSchemaIdBothParamsProvidedException, + InvalidSchemaIdNotProvidedException, InvalidSchemaVersionIdProvidedWithOtherParamsException, + InvalidSchemaVersionNumberBothParamsProvidedException, InvalidSchemaVersionNumberNotProvidedException, + ParamValueContainsInvalidCharactersException, + RegistryNotFoundException, + ResourceNameTooLongException, + SchemaNotFoundException, SchemaVersionMetadataLimitExceededException, ) +from .glue_schema_registry_constants import ( + ARN_PATTERN, + DEFAULT_REGISTRY_NAME, + DESCRIPTION_PATTERN, + LATEST_VERSION, + MAX_ARN_LENGTH, + MAX_DESCRIPTION_LENGTH, + MAX_REGISTRIES_ALLOWED, + MAX_REGISTRY_NAME_LENGTH, + MAX_SCHEMA_DEFINITION_LENGTH, + MAX_SCHEMA_NAME_LENGTH, + MAX_SCHEMA_VERSION_METADATA_ALLOWED, + MAX_SCHEMA_VERSION_METADATA_LENGTH, + MAX_SCHEMA_VERSIONS_ALLOWED, + MAX_SCHEMAS_ALLOWED, + MAX_TAGS_ALLOWED, + METADATA_KEY, + METADATA_VALUE, + REGISTRY_ARN, + REGISTRY_NAME, + RESOURCE_NAME_PATTERN, + SCHEMA_ARN, + SCHEMA_DEFINITION, + SCHEMA_NAME, + SCHEMA_VERSION_ID, + SCHEMA_VERSION_ID_PATTERN, + SCHEMA_VERSION_METADATA_PATTERN, + VERSION_NUMBER, +) def validate_registry_name_pattern_and_length(param_value: str) -> None: diff --git a/moto/glue/models.py b/moto/glue/models.py index 695ea1e32..d46cd3c0a 100644 --- a/moto/glue/models.py +++ b/moto/glue/models.py @@ -1,62 +1,63 @@ import json +import re import time from collections import OrderedDict from datetime import datetime -import re from typing import Any, Dict, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel +from moto.core.utils import unix_time, utcnow from moto.moto_api import state_manager from moto.moto_api._internal import mock_random -from moto.core.utils import unix_time, utcnow from moto.moto_api._internal.managed_state_model import ManagedState -from .exceptions import ( - JsonRESTError, - CrawlerRunningException, - CrawlerNotRunningException, - CrawlerAlreadyExistsException, - CrawlerNotFoundException, - DatabaseAlreadyExistsException, - DatabaseNotFoundException, - TableAlreadyExistsException, - TableNotFoundException, - PartitionAlreadyExistsException, - PartitionNotFoundException, - VersionNotFoundException, - JobNotFoundException, - JobRunNotFoundException, - ConcurrentRunsExceededException, - SchemaVersionNotFoundFromSchemaVersionIdException, - SchemaVersionNotFoundFromSchemaIdException, - SchemaNotFoundException, - SchemaVersionMetadataAlreadyExistsException, - SessionAlreadyExistsException, - SessionNotFoundException, - IllegalSessionStateException, - TriggerNotFoundException, -) -from .utils import PartitionFilter -from .glue_schema_registry_utils import ( - validate_registry_id, - validate_schema_id, - validate_schema_params, - get_schema_version_if_definition_exists, - validate_registry_params, - validate_schema_version_params, - validate_schema_definition_length, - validate_schema_version_metadata_pattern_and_length, - validate_number_of_schema_version_metadata_allowed, - get_put_schema_version_metadata_response, - validate_register_schema_version_params, - delete_schema_response, -) -from .glue_schema_registry_constants import ( - DEFAULT_REGISTRY_NAME, - AVAILABLE_STATUS, - DELETING_STATUS, -) + from ..utilities.paginator import paginate from ..utilities.tagging_service import TaggingService +from .exceptions import ( + ConcurrentRunsExceededException, + CrawlerAlreadyExistsException, + CrawlerNotFoundException, + CrawlerNotRunningException, + CrawlerRunningException, + DatabaseAlreadyExistsException, + DatabaseNotFoundException, + IllegalSessionStateException, + JobNotFoundException, + JobRunNotFoundException, + JsonRESTError, + PartitionAlreadyExistsException, + PartitionNotFoundException, + SchemaNotFoundException, + SchemaVersionMetadataAlreadyExistsException, + SchemaVersionNotFoundFromSchemaIdException, + SchemaVersionNotFoundFromSchemaVersionIdException, + SessionAlreadyExistsException, + SessionNotFoundException, + TableAlreadyExistsException, + TableNotFoundException, + TriggerNotFoundException, + VersionNotFoundException, +) +from .glue_schema_registry_constants import ( + AVAILABLE_STATUS, + DEFAULT_REGISTRY_NAME, + DELETING_STATUS, +) +from .glue_schema_registry_utils import ( + delete_schema_response, + get_put_schema_version_metadata_response, + get_schema_version_if_definition_exists, + validate_number_of_schema_version_metadata_allowed, + validate_register_schema_version_params, + validate_registry_id, + validate_registry_params, + validate_schema_definition_length, + validate_schema_id, + validate_schema_params, + validate_schema_version_metadata_pattern_and_length, + validate_schema_version_params, +) +from .utils import PartitionFilter class GlueBackend(BaseBackend): diff --git a/moto/glue/responses.py b/moto/glue/responses.py index 591aa6def..f35417445 100644 --- a/moto/glue/responses.py +++ b/moto/glue/responses.py @@ -3,7 +3,8 @@ from typing import Any, Dict, List from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from .models import glue_backends, GlueBackend, FakeJob, FakeCrawler, FakeSession + +from .models import FakeCrawler, FakeJob, FakeSession, GlueBackend, glue_backends class GlueResponse(BaseResponse): diff --git a/moto/greengrass/__init__.py b/moto/greengrass/__init__.py index d6dd58b5b..550542cee 100644 --- a/moto/greengrass/__init__.py +++ b/moto/greengrass/__init__.py @@ -1,4 +1,4 @@ -from .models import greengrass_backends from ..core.models import base_decorator +from .models import greengrass_backends mock_greengrass = base_decorator(greengrass_backends) diff --git a/moto/greengrass/models.py b/moto/greengrass/models.py index 493058e15..84ac09028 100644 --- a/moto/greengrass/models.py +++ b/moto/greengrass/models.py @@ -1,17 +1,18 @@ import json +import re from collections import OrderedDict from datetime import datetime -from typing import Any, Dict, List, Iterable, Optional -import re +from typing import Any, Dict, Iterable, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import iso_8601_datetime_with_milliseconds, utcnow from moto.moto_api._internal import mock_random + from .exceptions import ( GreengrassClientError, IdNotFoundException, - InvalidInputException, InvalidContainerDefinitionException, + InvalidInputException, MissingCoreException, ResourceNotFoundException, VersionNotFoundException, diff --git a/moto/greengrass/responses.py b/moto/greengrass/responses.py index e01f2249f..9db3e5ddd 100644 --- a/moto/greengrass/responses.py +++ b/moto/greengrass/responses.py @@ -1,10 +1,11 @@ -from typing import Any import json +from typing import Any from moto.core.common_types import TYPE_RESPONSE -from moto.core.utils import iso_8601_datetime_with_milliseconds from moto.core.responses import BaseResponse -from .models import greengrass_backends, GreengrassBackend +from moto.core.utils import iso_8601_datetime_with_milliseconds + +from .models import GreengrassBackend, greengrass_backends class GreengrassResponse(BaseResponse): diff --git a/moto/guardduty/__init__.py b/moto/guardduty/__init__.py index c9d9d1c16..01a69fe39 100644 --- a/moto/guardduty/__init__.py +++ b/moto/guardduty/__init__.py @@ -1,5 +1,5 @@ -from .models import guardduty_backends from ..core.models import base_decorator +from .models import guardduty_backends guardduty_backend = guardduty_backends["us-east-1"] mock_guardduty = base_decorator(guardduty_backends) diff --git a/moto/guardduty/exceptions.py b/moto/guardduty/exceptions.py index 59ebe6df5..51483a9e6 100644 --- a/moto/guardduty/exceptions.py +++ b/moto/guardduty/exceptions.py @@ -1,4 +1,5 @@ from typing import Any, List, Tuple + from moto.core.exceptions import JsonRESTError diff --git a/moto/guardduty/models.py b/moto/guardduty/models.py index d30ece1b3..0bf50d94b 100644 --- a/moto/guardduty/models.py +++ b/moto/guardduty/models.py @@ -1,7 +1,8 @@ -from typing import Any, Dict, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel -from moto.moto_api._internal import mock_random from datetime import datetime +from typing import Any, Dict, List, Optional + +from moto.core import BackendDict, BaseBackend, BaseModel +from moto.moto_api._internal import mock_random from .exceptions import DetectorNotFoundException, FilterNotFoundException diff --git a/moto/guardduty/responses.py b/moto/guardduty/responses.py index 03763e057..033cd8f6e 100644 --- a/moto/guardduty/responses.py +++ b/moto/guardduty/responses.py @@ -1,9 +1,11 @@ +import json from typing import Any +from urllib.parse import unquote + from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from .models import guardduty_backends, GuardDutyBackend -import json -from urllib.parse import unquote + +from .models import GuardDutyBackend, guardduty_backends class GuardDutyResponse(BaseResponse): diff --git a/moto/iam/__init__.py b/moto/iam/__init__.py index 401c426b3..bade9a5a7 100644 --- a/moto/iam/__init__.py +++ b/moto/iam/__init__.py @@ -1,4 +1,4 @@ -from .models import iam_backends from ..core.models import base_decorator +from .models import iam_backends mock_iam = base_decorator(iam_backends) diff --git a/moto/iam/access_control.py b/moto/iam/access_control.py index 2627a4b7a..0ec12b595 100644 --- a/moto/iam/access_control.py +++ b/moto/iam/access_control.py @@ -15,32 +15,33 @@ TODO add support for resource-based policies import json import logging import re -from abc import abstractmethod, ABCMeta +from abc import ABCMeta, abstractmethod from enum import Enum -from typing import Any, Dict, Optional, Match, List, Union +from typing import Any, Dict, List, Match, Optional, Union -from botocore.auth import SigV4Auth, S3SigV4Auth +from botocore.auth import S3SigV4Auth, SigV4Auth from botocore.awsrequest import AWSRequest from botocore.credentials import Credentials from moto.core.exceptions import ( - SignatureDoesNotMatchError, AccessDeniedError, - InvalidClientTokenIdError, AuthFailureError, + InvalidClientTokenIdError, + SignatureDoesNotMatchError, ) from moto.s3.exceptions import ( BucketAccessDeniedError, - S3AccessDeniedError, - BucketInvalidTokenError, - S3InvalidTokenError, - S3InvalidAccessKeyIdError, BucketInvalidAccessKeyIdError, + BucketInvalidTokenError, BucketSignatureDoesNotMatchError, + S3AccessDeniedError, + S3InvalidAccessKeyIdError, + S3InvalidTokenError, S3SignatureDoesNotMatchError, ) from moto.sts.models import sts_backends -from .models import iam_backends, Policy, IAMBackend + +from .models import IAMBackend, Policy, iam_backends log = logging.getLogger(__name__) diff --git a/moto/iam/config.py b/moto/iam/config.py index 654ea9397..ca2e67c8f 100644 --- a/moto/iam/config.py +++ b/moto/iam/config.py @@ -1,8 +1,10 @@ import json -import boto3 from typing import Any, Dict, List, Optional, Tuple -from moto.core.exceptions import InvalidNextTokenException + +import boto3 + from moto.core.common_models import ConfigQueryModel +from moto.core.exceptions import InvalidNextTokenException from moto.iam import iam_backends diff --git a/moto/iam/exceptions.py b/moto/iam/exceptions.py index aebc3b0c8..da01bb4d5 100644 --- a/moto/iam/exceptions.py +++ b/moto/iam/exceptions.py @@ -1,4 +1,5 @@ from typing import Any + from moto.core.exceptions import RESTError XMLNS_IAM = "https://iam.amazonaws.com/doc/2010-05-08/" diff --git a/moto/iam/models.py b/moto/iam/models.py index f1fc5ead4..6438b7f72 100644 --- a/moto/iam/models.py +++ b/moto/iam/models.py @@ -1,29 +1,28 @@ import base64 import copy +import json import os +import re import string from datetime import datetime -import json -import re +from typing import Any, Dict, Iterable, List, Optional, Tuple, Union +from urllib import parse from cryptography import x509 from cryptography.hazmat.backends import default_backend - from jinja2 import Template -from typing import Any, Dict, Optional, Tuple, Union -from typing import List, Iterable -from urllib import parse -from moto.core.exceptions import RESTError + from moto.core import ( DEFAULT_ACCOUNT_ID, + BackendDict, BaseBackend, BaseModel, CloudFormationModel, - BackendDict, ) +from moto.core.exceptions import RESTError from moto.core.utils import ( - iso_8601_datetime_without_milliseconds, iso_8601_datetime_with_milliseconds, + iso_8601_datetime_without_milliseconds, unix_time, utcnow, ) @@ -34,33 +33,32 @@ from moto.iam.policy_validation import ( from moto.moto_api._internal import mock_random as random from moto.utilities.utils import md5_hash +from ..utilities.tagging_service import TaggingService from .aws_managed_policies import aws_managed_policies_data from .exceptions import ( - IAMNotFoundException, - IAMConflictException, - IAMReportNotPresentException, - IAMLimitExceededException, - MalformedCertificate, DuplicateTags, - TagKeyTooBig, - InvalidTagCharacters, - TooManyTags, - TagValueTooBig, EntityAlreadyExists, - ValidationError, + IAMConflictException, + IAMLimitExceededException, + IAMNotFoundException, + IAMReportNotPresentException, InvalidInput, + InvalidTagCharacters, + MalformedCertificate, NoSuchEntity, + TagKeyTooBig, + TagValueTooBig, + TooManyTags, + ValidationError, ) from .utils import ( + generate_access_key_id_from_account_id, random_access_key, random_alphanumeric, - random_resource_id, random_policy_id, + random_resource_id, random_role_id, - generate_access_key_id_from_account_id, ) -from ..utilities.tagging_service import TaggingService - # Map to convert service names used in ServiceLinkedRoles # The PascalCase should be used as part of the RoleName diff --git a/moto/iam/policy_validation.py b/moto/iam/policy_validation.py index cc2516ac0..02eea188f 100644 --- a/moto/iam/policy_validation.py +++ b/moto/iam/policy_validation.py @@ -1,8 +1,8 @@ import json import re from typing import Any, Dict, List -from moto.iam.exceptions import MalformedPolicyDocument +from moto.iam.exceptions import MalformedPolicyDocument VALID_TOP_ELEMENTS = ["Version", "Id", "Statement", "Conditions"] diff --git a/moto/iam/responses.py b/moto/iam/responses.py index 32ce56392..e30cb14eb 100644 --- a/moto/iam/responses.py +++ b/moto/iam/responses.py @@ -1,6 +1,6 @@ from moto.core.responses import BaseResponse -from .models import iam_backends, IAMBackend, User +from .models import IAMBackend, User, iam_backends class IamResponse(BaseResponse): diff --git a/moto/iam/utils.py b/moto/iam/utils.py index db19115ac..a31aed6f2 100644 --- a/moto/iam/utils.py +++ b/moto/iam/utils.py @@ -1,6 +1,7 @@ -from moto.moto_api._internal import mock_random as random -import string import base64 +import string + +from moto.moto_api._internal import mock_random as random AWS_ROLE_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567" ACCOUNT_OFFSET = 549755813888 # int.from_bytes(base64.b32decode(b"QAAAAAAA"), byteorder="big"), start value diff --git a/moto/identitystore/__init__.py b/moto/identitystore/__init__.py index 072589539..423ff5262 100644 --- a/moto/identitystore/__init__.py +++ b/moto/identitystore/__init__.py @@ -1,5 +1,5 @@ """identitystore module initialization; sets value for base decorator.""" -from .models import identitystore_backends from ..core.models import base_decorator +from .models import identitystore_backends mock_identitystore = base_decorator(identitystore_backends) diff --git a/moto/identitystore/exceptions.py b/moto/identitystore/exceptions.py index 87d46ff0a..1f064ff62 100644 --- a/moto/identitystore/exceptions.py +++ b/moto/identitystore/exceptions.py @@ -1,9 +1,8 @@ """Exceptions raised by the identitystore service.""" import json - -from moto.core.exceptions import AWSError from typing import Any +from moto.core.exceptions import AWSError request_id = "178936da-50ad-4d58-8871-22d9979e8658example" diff --git a/moto/identitystore/models.py b/moto/identitystore/models.py index d5d38d6e7..167705355 100644 --- a/moto/identitystore/models.py +++ b/moto/identitystore/models.py @@ -1,16 +1,17 @@ -from typing import Dict, Tuple, List, Any, NamedTuple, Optional, TYPE_CHECKING -from moto.utilities.paginator import paginate +import warnings +from typing import TYPE_CHECKING, Any, Dict, List, NamedTuple, Optional, Tuple from botocore.exceptions import ParamValidationError +from moto.core import BackendDict, BaseBackend from moto.moto_api._internal import mock_random -from moto.core import BaseBackend, BackendDict +from moto.utilities.paginator import paginate + from .exceptions import ( + ConflictException, ResourceNotFoundException, ValidationException, - ConflictException, ) -import warnings if TYPE_CHECKING: from typing_extensions import Self diff --git a/moto/identitystore/responses.py b/moto/identitystore/responses.py index 59b755453..a54dfd66e 100644 --- a/moto/identitystore/responses.py +++ b/moto/identitystore/responses.py @@ -1,9 +1,10 @@ """Handles incoming identitystore requests, invokes methods, returns responses.""" import json -from typing import NamedTuple, Any, Dict, Optional +from typing import Any, Dict, NamedTuple, Optional from moto.core.responses import BaseResponse -from .models import identitystore_backends, IdentityStoreBackend + +from .models import IdentityStoreBackend, identitystore_backends class IdentityStoreResponse(BaseResponse): diff --git a/moto/inspector2/__init__.py b/moto/inspector2/__init__.py index 0ce83bc98..dfc08a4cc 100644 --- a/moto/inspector2/__init__.py +++ b/moto/inspector2/__init__.py @@ -1,5 +1,5 @@ """inspector2 module initialization; sets value for base decorator.""" -from .models import inspector2_backends from ..core.models import base_decorator +from .models import inspector2_backends mock_inspector2 = base_decorator(inspector2_backends) diff --git a/moto/inspector2/models.py b/moto/inspector2/models.py index 8ae024569..eba170f7d 100644 --- a/moto/inspector2/models.py +++ b/moto/inspector2/models.py @@ -1,6 +1,7 @@ import json -from typing import Any, Dict, List, Optional, Iterable -from moto.core import BaseBackend, BackendDict, BaseModel +from typing import Any, Dict, Iterable, List, Optional + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import unix_time from moto.moto_api._internal import mock_random from moto.utilities.tagging_service import TaggingService diff --git a/moto/inspector2/responses.py b/moto/inspector2/responses.py index fb457d713..2f86409e9 100644 --- a/moto/inspector2/responses.py +++ b/moto/inspector2/responses.py @@ -4,7 +4,8 @@ from urllib.parse import unquote from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from .models import inspector2_backends, Inspector2Backend + +from .models import Inspector2Backend, inspector2_backends class Inspector2Response(BaseResponse): diff --git a/moto/instance_metadata/models.py b/moto/instance_metadata/models.py index 76e4b8dfe..fd3fd7243 100644 --- a/moto/instance_metadata/models.py +++ b/moto/instance_metadata/models.py @@ -1,4 +1,4 @@ -from moto.core import BaseBackend, BackendDict +from moto.core import BackendDict, BaseBackend class InstanceMetadataBackend(BaseBackend): diff --git a/moto/iot/__init__.py b/moto/iot/__init__.py index ccd2af5f7..853b80fe2 100644 --- a/moto/iot/__init__.py +++ b/moto/iot/__init__.py @@ -1,4 +1,4 @@ -from .models import iot_backends from ..core.models import base_decorator +from .models import iot_backends mock_iot = base_decorator(iot_backends) diff --git a/moto/iot/models.py b/moto/iot/models.py index d35e0e3cc..3ba23276c 100644 --- a/moto/iot/models.py +++ b/moto/iot/models.py @@ -2,31 +2,32 @@ import hashlib import re import time from collections import OrderedDict +from datetime import datetime, timedelta +from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Pattern, Tuple + from cryptography import x509 from cryptography.hazmat._oid import NameOID from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives import hashes, serialization from cryptography.hazmat.primitives.asymmetric import rsa -from cryptography.hazmat.primitives import serialization, hashes -from datetime import datetime, timedelta -from typing import Any, Dict, List, Tuple, Optional, Pattern, Iterable, TYPE_CHECKING -from .utils import PAGINATION_MODEL - -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import utcnow from moto.moto_api._internal import mock_random as random from moto.utilities.paginator import paginate + from .exceptions import ( CertificateStateException, DeleteConflictException, - ResourceNotFoundException, InvalidRequestException, InvalidStateTransitionException, - VersionConflictException, ResourceAlreadyExistsException, - VersionsLimitExceededException, + ResourceNotFoundException, ThingStillAttached, + VersionConflictException, + VersionsLimitExceededException, ) +from .utils import PAGINATION_MODEL if TYPE_CHECKING: from moto.iotdata.models import FakeShadow diff --git a/moto/iot/responses.py b/moto/iot/responses.py index 2daec7068..ee0f7489b 100644 --- a/moto/iot/responses.py +++ b/moto/iot/responses.py @@ -4,7 +4,8 @@ from urllib.parse import unquote from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from .models import iot_backends, IoTBackend + +from .models import IoTBackend, iot_backends class IoTResponse(BaseResponse): diff --git a/moto/iotdata/__init__.py b/moto/iotdata/__init__.py index 48d964979..1c30e234e 100644 --- a/moto/iotdata/__init__.py +++ b/moto/iotdata/__init__.py @@ -1,4 +1,4 @@ -from .models import iotdata_backends from ..core.models import base_decorator +from .models import iotdata_backends mock_iotdata = base_decorator(iotdata_backends) diff --git a/moto/iotdata/models.py b/moto/iotdata/models.py index e8a283fe9..f149bfbfa 100644 --- a/moto/iotdata/models.py +++ b/moto/iotdata/models.py @@ -1,15 +1,17 @@ import json import time -import jsondiff -from typing import Any, Dict, List, Tuple, Optional +from typing import Any, Dict, List, Optional, Tuple -from moto.core import BaseBackend, BackendDict, BaseModel +import jsondiff + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import merge_dicts -from moto.iot.models import iot_backends, IoTBackend +from moto.iot.models import IoTBackend, iot_backends + from .exceptions import ( ConflictException, - ResourceNotFoundException, InvalidRequestException, + ResourceNotFoundException, ) diff --git a/moto/iotdata/responses.py b/moto/iotdata/responses.py index e39ef5a8c..4db68514e 100644 --- a/moto/iotdata/responses.py +++ b/moto/iotdata/responses.py @@ -1,9 +1,11 @@ -from moto.core.responses import BaseResponse -from .models import iotdata_backends, IoTDataPlaneBackend import json from typing import Any from urllib.parse import unquote +from moto.core.responses import BaseResponse + +from .models import IoTDataPlaneBackend, iotdata_backends + class IoTDataPlaneResponse(BaseResponse): def __init__(self) -> None: diff --git a/moto/ivs/__init__.py b/moto/ivs/__init__.py index e68e33550..ccda88cd1 100644 --- a/moto/ivs/__init__.py +++ b/moto/ivs/__init__.py @@ -1,5 +1,5 @@ """ivs module initialization; sets value for base decorator.""" -from .models import ivs_backends from ..core.models import base_decorator +from .models import ivs_backends mock_ivs = base_decorator(ivs_backends) diff --git a/moto/ivs/models.py b/moto/ivs/models.py index ea762d44c..e9d71e441 100644 --- a/moto/ivs/models.py +++ b/moto/ivs/models.py @@ -1,9 +1,10 @@ """IVSBackend class with methods for supported APIs.""" -from typing import Optional, Any, List, Dict, Tuple -from moto.core import BaseBackend, BackendDict +from typing import Any, Dict, List, Optional, Tuple + +from moto.core import BackendDict, BaseBackend from moto.ivs.exceptions import ResourceNotFoundException -from moto.utilities.paginator import paginate from moto.moto_api._internal import mock_random +from moto.utilities.paginator import paginate class IVSBackend(BaseBackend): diff --git a/moto/ivs/responses.py b/moto/ivs/responses.py index a15a7f1c8..d3552b6b6 100644 --- a/moto/ivs/responses.py +++ b/moto/ivs/responses.py @@ -1,6 +1,8 @@ """Handles incoming ivs requests, invokes methods, returns responses.""" import json + from moto.core.responses import BaseResponse + from .models import IVSBackend, ivs_backends diff --git a/moto/ivs/urls.py b/moto/ivs/urls.py index f0edd4af1..89e0a2acd 100644 --- a/moto/ivs/urls.py +++ b/moto/ivs/urls.py @@ -1,7 +1,6 @@ """ivs base URL and path.""" from .responses import IVSResponse - url_bases = [ r"https?://ivs\.(.+)\.amazonaws\.com", ] diff --git a/moto/kinesis/__init__.py b/moto/kinesis/__init__.py index a706a0101..05810378d 100644 --- a/moto/kinesis/__init__.py +++ b/moto/kinesis/__init__.py @@ -1,5 +1,5 @@ -from .models import kinesis_backends from ..core.models import base_decorator +from .models import kinesis_backends kinesis_backend = kinesis_backends["us-east-1"] mock_kinesis = base_decorator(kinesis_backends) diff --git a/moto/kinesis/exceptions.py b/moto/kinesis/exceptions.py index e4c96c23a..55a7febf3 100644 --- a/moto/kinesis/exceptions.py +++ b/moto/kinesis/exceptions.py @@ -1,6 +1,7 @@ -from moto.core.exceptions import JsonRESTError from typing import Optional +from moto.core.exceptions import JsonRESTError + class ResourceNotFoundError(JsonRESTError): def __init__(self, message: str): diff --git a/moto/kinesis/models.py b/moto/kinesis/models.py index adabb162c..770dff1ac 100644 --- a/moto/kinesis/models.py +++ b/moto/kinesis/models.py @@ -1,41 +1,41 @@ -from base64 import b64encode, b64decode -from collections import OrderedDict -from gzip import GzipFile import datetime import io +import itertools import json import re -import itertools - +from base64 import b64decode, b64encode +from collections import OrderedDict +from gzip import GzipFile from operator import attrgetter -from typing import Any, Dict, List, Optional, Tuple, Iterable +from typing import Any, Dict, Iterable, List, Optional, Tuple -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.core.utils import unix_time, utcnow from moto.moto_api._internal import mock_random as random from moto.utilities.paginator import paginate from moto.utilities.utils import md5_hash + from .exceptions import ( ConsumerNotFound, - StreamNotFoundError, - StreamCannotBeUpdatedError, - ShardNotFoundError, - ResourceInUseError, - ResourceNotFoundError, InvalidArgumentError, - InvalidRetentionPeriod, InvalidDecreaseRetention, InvalidIncreaseRetention, - ValidationException, + InvalidRetentionPeriod, RecordSizeExceedsLimit, - TotalRecordsSizeExceedsLimit, + ResourceInUseError, + ResourceNotFoundError, + ShardNotFoundError, + StreamCannotBeUpdatedError, + StreamNotFoundError, TooManyRecords, + TotalRecordsSizeExceedsLimit, + ValidationException, ) from .utils import ( - compose_shard_iterator, - compose_new_shard_iterator, - decompose_shard_iterator, PAGINATION_MODEL, + compose_new_shard_iterator, + compose_shard_iterator, + decompose_shard_iterator, ) diff --git a/moto/kinesis/responses.py b/moto/kinesis/responses.py index 167be3f89..5ba00cbba 100644 --- a/moto/kinesis/responses.py +++ b/moto/kinesis/responses.py @@ -1,7 +1,8 @@ import json from moto.core.responses import BaseResponse -from .models import kinesis_backends, KinesisBackend + +from .models import KinesisBackend, kinesis_backends class KinesisResponse(BaseResponse): diff --git a/moto/kinesis/utils.py b/moto/kinesis/utils.py index 56b0dfa67..92f03b90a 100644 --- a/moto/kinesis/utils.py +++ b/moto/kinesis/utils.py @@ -1,10 +1,9 @@ import base64 from datetime import datetime -from typing import Any, Optional, List +from typing import Any, List, Optional from .exceptions import InvalidArgumentError - encode_method = base64.encodebytes decode_method = base64.decodebytes diff --git a/moto/kinesisvideo/__init__.py b/moto/kinesisvideo/__init__.py index ac1bfc6a5..5a887492d 100644 --- a/moto/kinesisvideo/__init__.py +++ b/moto/kinesisvideo/__init__.py @@ -1,5 +1,5 @@ -from .models import kinesisvideo_backends from ..core.models import base_decorator +from .models import kinesisvideo_backends kinesisvideo_backend = kinesisvideo_backends["us-east-1"] mock_kinesisvideo = base_decorator(kinesisvideo_backends) diff --git a/moto/kinesisvideo/models.py b/moto/kinesisvideo/models.py index 30f1a890e..12a9b58d7 100644 --- a/moto/kinesisvideo/models.py +++ b/moto/kinesisvideo/models.py @@ -1,9 +1,11 @@ from typing import Any, Dict, List -from moto.core import BaseBackend, BackendDict, BaseModel + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import utcnow -from .exceptions import ResourceNotFoundException, ResourceInUseException from moto.moto_api._internal import mock_random as random +from .exceptions import ResourceInUseException, ResourceNotFoundException + class Stream(BaseModel): def __init__( diff --git a/moto/kinesisvideo/responses.py b/moto/kinesisvideo/responses.py index f9cdf25c4..47844ee4e 100644 --- a/moto/kinesisvideo/responses.py +++ b/moto/kinesisvideo/responses.py @@ -1,7 +1,9 @@ -from moto.core.responses import BaseResponse -from .models import kinesisvideo_backends, KinesisVideoBackend import json +from moto.core.responses import BaseResponse + +from .models import KinesisVideoBackend, kinesisvideo_backends + class KinesisVideoResponse(BaseResponse): def __init__(self) -> None: diff --git a/moto/kinesisvideoarchivedmedia/__init__.py b/moto/kinesisvideoarchivedmedia/__init__.py index 21412ffea..a94140017 100644 --- a/moto/kinesisvideoarchivedmedia/__init__.py +++ b/moto/kinesisvideoarchivedmedia/__init__.py @@ -1,5 +1,5 @@ -from .models import kinesisvideoarchivedmedia_backends from ..core.models import base_decorator +from .models import kinesisvideoarchivedmedia_backends kinesisvideoarchivedmedia_backend = kinesisvideoarchivedmedia_backends["us-east-1"] mock_kinesisvideoarchivedmedia = base_decorator(kinesisvideoarchivedmedia_backends) diff --git a/moto/kinesisvideoarchivedmedia/models.py b/moto/kinesisvideoarchivedmedia/models.py index cdc9575fc..c3e626fc8 100644 --- a/moto/kinesisvideoarchivedmedia/models.py +++ b/moto/kinesisvideoarchivedmedia/models.py @@ -1,6 +1,7 @@ from typing import Tuple -from moto.core import BaseBackend, BackendDict -from moto.kinesisvideo.models import kinesisvideo_backends, KinesisVideoBackend + +from moto.core import BackendDict, BaseBackend +from moto.kinesisvideo.models import KinesisVideoBackend, kinesisvideo_backends from moto.sts.utils import random_session_token diff --git a/moto/kinesisvideoarchivedmedia/responses.py b/moto/kinesisvideoarchivedmedia/responses.py index 22db6fe48..1f9ef4178 100644 --- a/moto/kinesisvideoarchivedmedia/responses.py +++ b/moto/kinesisvideoarchivedmedia/responses.py @@ -1,7 +1,9 @@ -from typing import Dict, Tuple -from moto.core.responses import BaseResponse -from .models import kinesisvideoarchivedmedia_backends, KinesisVideoArchivedMediaBackend import json +from typing import Dict, Tuple + +from moto.core.responses import BaseResponse + +from .models import KinesisVideoArchivedMediaBackend, kinesisvideoarchivedmedia_backends class KinesisVideoArchivedMediaResponse(BaseResponse): diff --git a/moto/kms/__init__.py b/moto/kms/__init__.py index cb055437c..05db0ad9c 100644 --- a/moto/kms/__init__.py +++ b/moto/kms/__init__.py @@ -1,5 +1,5 @@ -from .models import kms_backends from ..core.models import base_decorator +from .models import kms_backends kms_backend = kms_backends["us-east-1"] mock_kms = base_decorator(kms_backends) diff --git a/moto/kms/models.py b/moto/kms/models.py index 16abc0cf2..928a2dc88 100644 --- a/moto/kms/models.py +++ b/moto/kms/models.py @@ -3,24 +3,24 @@ import os from collections import defaultdict from copy import copy from datetime import datetime, timedelta -from typing import Any, Dict, List, Tuple, Optional, Iterable, Set +from typing import Any, Dict, Iterable, List, Optional, Set, Tuple -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel +from moto.core.exceptions import JsonRESTError from moto.core.utils import unix_time from moto.moto_api._internal import mock_random from moto.utilities.tagging_service import TaggingService -from moto.core.exceptions import JsonRESTError from .exceptions import ValidationException from .utils import ( RESERVED_ALIASES, + KeySpec, + SigningAlgorithm, decrypt, encrypt, generate_key_id, generate_master_key, generate_private_key, - KeySpec, - SigningAlgorithm, ) diff --git a/moto/kms/policy_validator.py b/moto/kms/policy_validator.py index 72392e8fc..1d1a78148 100644 --- a/moto/kms/policy_validator.py +++ b/moto/kms/policy_validator.py @@ -1,9 +1,9 @@ +import json from collections import defaultdict from typing import Any, Dict, List -import json -from .models import Key -from .exceptions import AccessDeniedException +from .exceptions import AccessDeniedException +from .models import Key ALTERNATIVE_ACTIONS = defaultdict(list) ALTERNATIVE_ACTIONS["kms:DescribeKey"] = ["kms:*", "kms:Describe*", "kms:DescribeKey"] diff --git a/moto/kms/responses.py b/moto/kms/responses.py index 03e2adf07..ef02e0f1f 100644 --- a/moto/kms/responses.py +++ b/moto/kms/responses.py @@ -6,15 +6,16 @@ import warnings from typing import Any, Dict from moto.core.responses import BaseResponse -from moto.kms.utils import RESERVED_ALIASES, RESERVED_ALIASE_TARGET_KEY_IDS -from .models import kms_backends, KmsBackend -from .policy_validator import validate_policy +from moto.kms.utils import RESERVED_ALIASE_TARGET_KEY_IDS, RESERVED_ALIASES + from .exceptions import ( - NotFoundException, - ValidationException, AlreadyExistsException, NotAuthorizedException, + NotFoundException, + ValidationException, ) +from .models import KmsBackend, kms_backends +from .policy_validator import validate_policy class KmsResponse(BaseResponse): diff --git a/moto/kms/utils.py b/moto/kms/utils.py index 0e6b322cd..4e7527611 100644 --- a/moto/kms/utils.py +++ b/moto/kms/utils.py @@ -1,28 +1,27 @@ -from abc import abstractmethod, ABCMeta -from collections import namedtuple -from typing import Any, Dict, Tuple, List -from enum import Enum import io import os import struct -from moto.moto_api._internal import mock_random +from abc import ABCMeta, abstractmethod +from collections import namedtuple +from enum import Enum +from typing import Any, Dict, List, Tuple from cryptography.exceptions import InvalidSignature from cryptography.hazmat.backends import default_backend -from cryptography.hazmat.primitives.ciphers import algorithms, Cipher, modes from cryptography.hazmat.primitives import hashes, serialization from cryptography.hazmat.primitives._asymmetric import AsymmetricPadding -from cryptography.hazmat.primitives.asymmetric import rsa, padding, ec +from cryptography.hazmat.primitives.asymmetric import ec, padding, rsa +from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes +from moto.moto_api._internal import mock_random from .exceptions import ( - InvalidCiphertextException, AccessDeniedException, + InvalidCiphertextException, NotFoundException, ValidationException, ) - MASTER_KEY_LEN = 32 KEY_ID_LEN = 36 IV_LEN = 12 diff --git a/moto/lakeformation/__init__.py b/moto/lakeformation/__init__.py index 29c3287bc..34e54adf6 100644 --- a/moto/lakeformation/__init__.py +++ b/moto/lakeformation/__init__.py @@ -1,5 +1,5 @@ """lakeformation module initialization; sets value for base decorator.""" -from .models import lakeformation_backends from ..core.models import base_decorator +from .models import lakeformation_backends mock_lakeformation = base_decorator(lakeformation_backends) diff --git a/moto/lakeformation/models.py b/moto/lakeformation/models.py index 796242174..1c8c79893 100644 --- a/moto/lakeformation/models.py +++ b/moto/lakeformation/models.py @@ -1,10 +1,11 @@ -from enum import Enum from collections import defaultdict -from typing import Any, Dict, List, Tuple, Optional +from enum import Enum +from typing import Any, Dict, List, Optional, Tuple -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.utilities.tagging_service import TaggingService -from .exceptions import EntityNotFound, InvalidInput, AlreadyExists + +from .exceptions import AlreadyExists, EntityNotFound, InvalidInput class RessourceType(Enum): diff --git a/moto/lakeformation/responses.py b/moto/lakeformation/responses.py index e6720985a..b3e1af6bd 100644 --- a/moto/lakeformation/responses.py +++ b/moto/lakeformation/responses.py @@ -3,18 +3,18 @@ import json from typing import Any, Dict from moto.core.responses import BaseResponse + +from .exceptions import InvalidInput from .models import ( - lakeformation_backends, LakeFormationBackend, ListPermissionsResource, ListPermissionsResourceDatabase, ListPermissionsResourceDataLocation, ListPermissionsResourceTable, RessourceType, + lakeformation_backends, ) -from .exceptions import InvalidInput - class LakeFormationResponse(BaseResponse): """Handler for LakeFormation requests and responses.""" diff --git a/moto/logs/__init__.py b/moto/logs/__init__.py index bbe77cd9d..6eb4aca07 100644 --- a/moto/logs/__init__.py +++ b/moto/logs/__init__.py @@ -1,4 +1,4 @@ -from .models import logs_backends from ..core.models import base_decorator +from .models import logs_backends mock_logs = base_decorator(logs_backends) diff --git a/moto/logs/exceptions.py b/moto/logs/exceptions.py index c6854c37e..a4118febb 100644 --- a/moto/logs/exceptions.py +++ b/moto/logs/exceptions.py @@ -1,4 +1,5 @@ from typing import Any, Optional + from moto.core.exceptions import JsonRESTError diff --git a/moto/logs/logs_query/__init__.py b/moto/logs/logs_query/__init__.py index e47bf1a03..0d34dbd35 100644 --- a/moto/logs/logs_query/__init__.py +++ b/moto/logs/logs_query/__init__.py @@ -1,10 +1,9 @@ -from typing import Any, Dict, List -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Dict, List if TYPE_CHECKING: - from ..models import LogGroup, LogEvent, LogStream + from ..models import LogEvent, LogGroup, LogStream -from .query_parser import parse_query, ParsedQuery +from .query_parser import ParsedQuery, parse_query class ParsedEvent: diff --git a/moto/logs/models.py b/moto/logs/models.py index e12d2de09..08d1780b4 100644 --- a/moto/logs/models.py +++ b/moto/logs/models.py @@ -1,21 +1,22 @@ import json -from datetime import timedelta, datetime -from typing import Any, Dict, Iterable, List, Tuple, Optional -from moto.core import BaseBackend, BackendDict, BaseModel -from moto.core import CloudFormationModel +from datetime import datetime, timedelta +from typing import Any, Dict, Iterable, List, Optional, Tuple + +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.core.utils import unix_time_millis, utcnow -from moto.logs.metric_filters import MetricFilters from moto.logs.exceptions import ( - ResourceNotFoundException, - ResourceAlreadyExistsException, InvalidParameterException, LimitExceededException, + ResourceAlreadyExistsException, + ResourceNotFoundException, ) from moto.logs.logs_query import execute_query +from moto.logs.metric_filters import MetricFilters from moto.moto_api._internal import mock_random from moto.s3.models import s3_backends from moto.utilities.paginator import paginate from moto.utilities.tagging_service import TaggingService + from .utils import PAGINATION_MODEL, EventMessageFilter MAX_RESOURCE_POLICIES_PER_REGION = 10 diff --git a/moto/logs/responses.py b/moto/logs/responses.py index 503d315c0..9b211018f 100644 --- a/moto/logs/responses.py +++ b/moto/logs/responses.py @@ -2,10 +2,10 @@ import json import re from typing import Any, Callable, Optional -from .exceptions import InvalidParameterException - from moto.core.responses import BaseResponse -from .models import logs_backends, LogsBackend + +from .exceptions import InvalidParameterException +from .models import LogsBackend, logs_backends # See http://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/Welcome.html diff --git a/moto/logs/utils.py b/moto/logs/utils.py index 0ce061457..9f4fdf4d9 100644 --- a/moto/logs/utils.py +++ b/moto/logs/utils.py @@ -1,6 +1,5 @@ from typing import Type - PAGINATION_MODEL = { "describe_log_groups": { "input_token": "next_token", diff --git a/moto/managedblockchain/__init__.py b/moto/managedblockchain/__init__.py index 3199f4fb7..3ee8532f1 100644 --- a/moto/managedblockchain/__init__.py +++ b/moto/managedblockchain/__init__.py @@ -1,5 +1,5 @@ -from .models import managedblockchain_backends from ..core.models import base_decorator +from .models import managedblockchain_backends managedblockchain_backend = managedblockchain_backends["us-east-1"] mock_managedblockchain = base_decorator(managedblockchain_backends) diff --git a/moto/managedblockchain/exceptions.py b/moto/managedblockchain/exceptions.py index f64915b6d..5f7199929 100644 --- a/moto/managedblockchain/exceptions.py +++ b/moto/managedblockchain/exceptions.py @@ -1,7 +1,8 @@ import json -from moto.core.exceptions import JsonRESTError from typing import Any, List, Tuple +from moto.core.exceptions import JsonRESTError + class ManagedBlockchainClientError(JsonRESTError): def __init__(self, error_type: str, message: str): diff --git a/moto/managedblockchain/models.py b/moto/managedblockchain/models.py index edb50d56c..7cfce11a4 100644 --- a/moto/managedblockchain/models.py +++ b/moto/managedblockchain/models.py @@ -2,28 +2,27 @@ import datetime import re from typing import Any, Dict, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import utcnow from .exceptions import ( BadRequestException, - ResourceNotFoundException, InvalidRequestException, - ResourceLimitExceededException, ResourceAlreadyExistsException, + ResourceLimitExceededException, + ResourceNotFoundException, ) - from .utils import ( - get_network_id, - get_member_id, - get_proposal_id, - get_invitation_id, - member_name_exist_in_network, - number_of_members_in_network, admin_password_ok, + get_invitation_id, + get_member_id, + get_network_id, get_node_id, - number_of_nodes_in_member, + get_proposal_id, + member_name_exist_in_network, nodes_in_member, + number_of_members_in_network, + number_of_nodes_in_member, ) FRAMEWORKS = [ diff --git a/moto/managedblockchain/responses.py b/moto/managedblockchain/responses.py index 8912f725f..7091da4f9 100644 --- a/moto/managedblockchain/responses.py +++ b/moto/managedblockchain/responses.py @@ -1,13 +1,14 @@ import json from moto.core.responses import BaseResponse -from .models import managedblockchain_backends, ManagedBlockchainBackend + +from .models import ManagedBlockchainBackend, managedblockchain_backends from .utils import ( - networkid_from_managedblockchain_url, - proposalid_from_managedblockchain_url, invitationid_from_managedblockchain_url, memberid_from_managedblockchain_request, + networkid_from_managedblockchain_url, nodeid_from_managedblockchain_url, + proposalid_from_managedblockchain_url, ) diff --git a/moto/managedblockchain/utils.py b/moto/managedblockchain/utils.py index 9db9378e5..baeaced86 100644 --- a/moto/managedblockchain/utils.py +++ b/moto/managedblockchain/utils.py @@ -1,10 +1,11 @@ import json import re import string -from moto.moto_api._internal import mock_random as random from typing import Any, Dict, List, Optional from urllib.parse import parse_qs, urlparse +from moto.moto_api._internal import mock_random as random + def networkid_from_managedblockchain_url(full_url: str) -> str: id_search = re.search(r"\/n-[A-Z0-9]{26}", full_url, re.IGNORECASE) diff --git a/moto/mediaconnect/__init__.py b/moto/mediaconnect/__init__.py index e930e79e6..77e66a657 100644 --- a/moto/mediaconnect/__init__.py +++ b/moto/mediaconnect/__init__.py @@ -1,5 +1,5 @@ -from .models import mediaconnect_backends from ..core.models import base_decorator +from .models import mediaconnect_backends mediaconnect_backend = mediaconnect_backends["us-east-1"] mock_mediaconnect = base_decorator(mediaconnect_backends) diff --git a/moto/mediaconnect/models.py b/moto/mediaconnect/models.py index 3a5247d49..1e87fe29a 100644 --- a/moto/mediaconnect/models.py +++ b/moto/mediaconnect/models.py @@ -1,7 +1,7 @@ from collections import OrderedDict from typing import Any, Dict, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.mediaconnect.exceptions import NotFoundException from moto.moto_api._internal import mock_random as random from moto.utilities.tagging_service import TaggingService diff --git a/moto/mediaconnect/responses.py b/moto/mediaconnect/responses.py index 994bf0ac2..3e1158e9f 100644 --- a/moto/mediaconnect/responses.py +++ b/moto/mediaconnect/responses.py @@ -1,9 +1,9 @@ import json +from urllib.parse import unquote from moto.core.responses import BaseResponse -from .models import mediaconnect_backends, MediaConnectBackend -from urllib.parse import unquote +from .models import MediaConnectBackend, mediaconnect_backends class MediaConnectResponse(BaseResponse): diff --git a/moto/medialive/__init__.py b/moto/medialive/__init__.py index 407213697..1deaf15f4 100644 --- a/moto/medialive/__init__.py +++ b/moto/medialive/__init__.py @@ -1,4 +1,4 @@ -from .models import medialive_backends from ..core.models import base_decorator +from .models import medialive_backends mock_medialive = base_decorator(medialive_backends) diff --git a/moto/medialive/models.py b/moto/medialive/models.py index 82fc1b219..b0b720526 100644 --- a/moto/medialive/models.py +++ b/moto/medialive/models.py @@ -1,7 +1,7 @@ from collections import OrderedDict from typing import Any, Dict, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.moto_api._internal import mock_random diff --git a/moto/medialive/responses.py b/moto/medialive/responses.py index 571f3c957..f9515fe8a 100644 --- a/moto/medialive/responses.py +++ b/moto/medialive/responses.py @@ -1,7 +1,9 @@ -from moto.core.responses import BaseResponse -from .models import medialive_backends, MediaLiveBackend import json +from moto.core.responses import BaseResponse + +from .models import MediaLiveBackend, medialive_backends + class MediaLiveResponse(BaseResponse): def __init__(self) -> None: diff --git a/moto/mediapackage/__init__.py b/moto/mediapackage/__init__.py index e7561de2b..914f6e730 100644 --- a/moto/mediapackage/__init__.py +++ b/moto/mediapackage/__init__.py @@ -1,5 +1,5 @@ -from .models import mediapackage_backends from ..core.models import base_decorator +from .models import mediapackage_backends mediapackage_backend = mediapackage_backends["us-east-1"] mock_mediapackage = base_decorator(mediapackage_backends) diff --git a/moto/mediapackage/models.py b/moto/mediapackage/models.py index 88db5b58c..380307186 100644 --- a/moto/mediapackage/models.py +++ b/moto/mediapackage/models.py @@ -1,7 +1,7 @@ from collections import OrderedDict from typing import Any, Dict, List -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from .exceptions import ClientError diff --git a/moto/mediapackage/responses.py b/moto/mediapackage/responses.py index 082e40f39..c802fd567 100644 --- a/moto/mediapackage/responses.py +++ b/moto/mediapackage/responses.py @@ -1,7 +1,9 @@ -from moto.core.responses import BaseResponse -from .models import mediapackage_backends, MediaPackageBackend import json +from moto.core.responses import BaseResponse + +from .models import MediaPackageBackend, mediapackage_backends + class MediaPackageResponse(BaseResponse): def __init__(self) -> None: diff --git a/moto/mediastore/__init__.py b/moto/mediastore/__init__.py index 420866c4c..22092c022 100644 --- a/moto/mediastore/__init__.py +++ b/moto/mediastore/__init__.py @@ -1,5 +1,5 @@ -from .models import mediastore_backends from ..core.models import base_decorator +from .models import mediastore_backends mediastore_backend = mediastore_backends["us-east-1"] mock_mediastore = base_decorator(mediastore_backends) diff --git a/moto/mediastore/exceptions.py b/moto/mediastore/exceptions.py index 8967ea328..3e43fd5cb 100644 --- a/moto/mediastore/exceptions.py +++ b/moto/mediastore/exceptions.py @@ -1,4 +1,5 @@ from typing import Optional + from moto.core.exceptions import JsonRESTError diff --git a/moto/mediastore/models.py b/moto/mediastore/models.py index 7dd08c7d7..44de5d7e4 100644 --- a/moto/mediastore/models.py +++ b/moto/mediastore/models.py @@ -2,11 +2,12 @@ from collections import OrderedDict from datetime import date from typing import Any, Dict, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel + from .exceptions import ( ContainerNotFoundException, - ResourceNotFoundException, PolicyNotFoundException, + ResourceNotFoundException, ) diff --git a/moto/mediastore/responses.py b/moto/mediastore/responses.py index 7ba3862f1..4c0dcb35b 100644 --- a/moto/mediastore/responses.py +++ b/moto/mediastore/responses.py @@ -1,7 +1,8 @@ import json from moto.core.responses import BaseResponse -from .models import mediastore_backends, MediaStoreBackend + +from .models import MediaStoreBackend, mediastore_backends class MediaStoreResponse(BaseResponse): diff --git a/moto/mediastoredata/__init__.py b/moto/mediastoredata/__init__.py index 9b8df256c..6a1ed3cac 100644 --- a/moto/mediastoredata/__init__.py +++ b/moto/mediastoredata/__init__.py @@ -1,5 +1,5 @@ -from .models import mediastoredata_backends from ..core.models import base_decorator +from .models import mediastoredata_backends mediastoredata_backend = mediastoredata_backends["us-east-1"] mock_mediastoredata = base_decorator(mediastoredata_backends) diff --git a/moto/mediastoredata/models.py b/moto/mediastoredata/models.py index f04ec3a1b..3597b3c4c 100644 --- a/moto/mediastoredata/models.py +++ b/moto/mediastoredata/models.py @@ -2,7 +2,8 @@ import hashlib from collections import OrderedDict from typing import Any, Dict, List -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel + from .exceptions import ClientError diff --git a/moto/mediastoredata/responses.py b/moto/mediastoredata/responses.py index 48503852e..82fb1c587 100644 --- a/moto/mediastoredata/responses.py +++ b/moto/mediastoredata/responses.py @@ -2,7 +2,8 @@ import json from typing import Dict, Tuple from moto.core.responses import BaseResponse -from .models import mediastoredata_backends, MediaStoreDataBackend + +from .models import MediaStoreDataBackend, mediastoredata_backends class MediaStoreDataResponse(BaseResponse): diff --git a/moto/meteringmarketplace/__init__.py b/moto/meteringmarketplace/__init__.py index 73497d4e4..132a05560 100644 --- a/moto/meteringmarketplace/__init__.py +++ b/moto/meteringmarketplace/__init__.py @@ -1,5 +1,5 @@ -from .models import meteringmarketplace_backends from ..core.models import base_decorator +from .models import meteringmarketplace_backends meteringmarketplace_backend = meteringmarketplace_backends["us-east-1"] mock_meteringmarketplace = base_decorator(meteringmarketplace_backends) diff --git a/moto/meteringmarketplace/models.py b/moto/meteringmarketplace/models.py index e50cb463a..9c61be9fc 100644 --- a/moto/meteringmarketplace/models.py +++ b/moto/meteringmarketplace/models.py @@ -1,6 +1,7 @@ import collections from typing import Any, Deque, Dict, List -from moto.core import BaseBackend, BackendDict, BaseModel + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.moto_api._internal import mock_random diff --git a/moto/meteringmarketplace/responses.py b/moto/meteringmarketplace/responses.py index 9d14cbab4..4c143258a 100644 --- a/moto/meteringmarketplace/responses.py +++ b/moto/meteringmarketplace/responses.py @@ -1,7 +1,8 @@ import json from moto.core.responses import BaseResponse -from .models import meteringmarketplace_backends, MeteringMarketplaceBackend + +from .models import MeteringMarketplaceBackend, meteringmarketplace_backends class MarketplaceMeteringResponse(BaseResponse): diff --git a/moto/moto_api/_internal/__init__.py b/moto/moto_api/_internal/__init__.py index 5deee67be..758c907a6 100644 --- a/moto/moto_api/_internal/__init__.py +++ b/moto/moto_api/_internal/__init__.py @@ -1,8 +1,7 @@ from .models import moto_api_backend -from .state_manager import StateManager # noqa -from .recorder.models import Recorder # noqa from .moto_random import MotoRandom - +from .recorder.models import Recorder # noqa +from .state_manager import StateManager # noqa moto_api_backends = {"global": moto_api_backend} diff --git a/moto/moto_api/_internal/managed_state_model.py b/moto/moto_api/_internal/managed_state_model.py index 5e78f76f3..a0cb4e676 100644 --- a/moto/moto_api/_internal/managed_state_model.py +++ b/moto/moto_api/_internal/managed_state_model.py @@ -1,6 +1,7 @@ from datetime import datetime, timedelta +from typing import List, Optional, Tuple + from moto.moto_api import state_manager -from typing import List, Tuple, Optional class ManagedState: diff --git a/moto/moto_api/_internal/models.py b/moto/moto_api/_internal/models.py index 6690cb6c4..1da14c4ec 100644 --- a/moto/moto_api/_internal/models.py +++ b/moto/moto_api/_internal/models.py @@ -1,7 +1,8 @@ -from moto.core import BaseBackend, DEFAULT_ACCOUNT_ID -from moto.core.model_instances import reset_model_data from typing import Any, Dict, List, Optional +from moto.core import DEFAULT_ACCOUNT_ID, BaseBackend +from moto.core.model_instances import reset_model_data + class MotoAPIBackend(BaseBackend): def reset(self) -> None: @@ -40,7 +41,7 @@ class MotoAPIBackend(BaseBackend): account_id: str, region: str, ) -> None: - from moto.athena.models import athena_backends, QueryResults + from moto.athena.models import QueryResults, athena_backends backend = athena_backends[account_id][region] results = QueryResults(rows=rows, column_info=column_info) @@ -70,7 +71,7 @@ class MotoAPIBackend(BaseBackend): account_id: str, region: str, ) -> None: - from moto.rdsdata.models import rdsdata_backends, QueryResults + from moto.rdsdata.models import QueryResults, rdsdata_backends backend = rdsdata_backends[account_id][region] backend.results_queue.append( diff --git a/moto/moto_api/_internal/moto_random.py b/moto/moto_api/_internal/moto_random.py index 0bd405b67..3082752b8 100644 --- a/moto/moto_api/_internal/moto_random.py +++ b/moto/moto_api/_internal/moto_random.py @@ -1,8 +1,7 @@ -from random import Random import string -from uuid import UUID from base64 import urlsafe_b64encode - +from random import Random +from uuid import UUID HEX_CHARS = list(range(10)) + ["a", "b", "c", "d", "e", "f"] diff --git a/moto/moto_api/_internal/recorder/models.py b/moto/moto_api/_internal/recorder/models.py index ea407084c..20a40ea5c 100644 --- a/moto/moto_api/_internal/recorder/models.py +++ b/moto/moto_api/_internal/recorder/models.py @@ -2,11 +2,11 @@ import base64 import io import json import os +from typing import Any, Optional, Tuple, Union +from urllib.parse import urlparse import requests from botocore.awsrequest import AWSPreparedRequest -from typing import Any, Optional, Union, Tuple -from urllib.parse import urlparse class Recorder: diff --git a/moto/moto_api/_internal/recorder/responses.py b/moto/moto_api/_internal/recorder/responses.py index 667d45d4a..5937b5997 100644 --- a/moto/moto_api/_internal/recorder/responses.py +++ b/moto/moto_api/_internal/recorder/responses.py @@ -1,7 +1,9 @@ -from ... import recorder +from typing import Any + from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from typing import Any + +from ... import recorder class RecorderResponse(BaseResponse): diff --git a/moto/moto_api/_internal/responses.py b/moto/moto_api/_internal/responses.py index fc094a5a5..8302d0077 100644 --- a/moto/moto_api/_internal/responses.py +++ b/moto/moto_api/_internal/responses.py @@ -1,10 +1,10 @@ import json +from typing import Any, Dict, List from moto import settings from moto.core import DEFAULT_ACCOUNT_ID from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import ActionAuthenticatorMixin, BaseResponse -from typing import Any, Dict, List class MotoAPIResponse(BaseResponse): diff --git a/moto/moto_api/_internal/state_manager.py b/moto/moto_api/_internal/state_manager.py index 7d369de2d..f69a89c67 100644 --- a/moto/moto_api/_internal/state_manager.py +++ b/moto/moto_api/_internal/state_manager.py @@ -1,6 +1,5 @@ from typing import Any, Dict, List - DEFAULT_TRANSITION = {"progression": "immediate"} diff --git a/moto/moto_api/_internal/urls.py b/moto/moto_api/_internal/urls.py index 58b7191e7..987a4278c 100644 --- a/moto/moto_api/_internal/urls.py +++ b/moto/moto_api/_internal/urls.py @@ -1,5 +1,5 @@ -from .responses import MotoAPIResponse from .recorder.responses import RecorderResponse +from .responses import MotoAPIResponse url_bases = ["https?://motoapi.amazonaws.com"] diff --git a/moto/moto_proxy/__init__.py b/moto/moto_proxy/__init__.py index e1df6d2cc..d25cd88a3 100644 --- a/moto/moto_proxy/__init__.py +++ b/moto/moto_proxy/__init__.py @@ -1,7 +1,6 @@ import logging import sys - log_format = "%(levelname)s %(asctime)s - %(message)s" logging.basicConfig(stream=sys.stdout, format=log_format) logger = logging.getLogger("MOTO_PROXY") diff --git a/moto/moto_proxy/certificate_creator.py b/moto/moto_proxy/certificate_creator.py index a288d4346..c5699a0b4 100644 --- a/moto/moto_proxy/certificate_creator.py +++ b/moto/moto_proxy/certificate_creator.py @@ -1,7 +1,7 @@ import os import threading import time -from subprocess import Popen, PIPE +from subprocess import PIPE, Popen from uuid import uuid4 from . import debug, info diff --git a/moto/moto_proxy/proxy3.py b/moto/moto_proxy/proxy3.py index c134ec56d..a6289efb9 100644 --- a/moto/moto_proxy/proxy3.py +++ b/moto/moto_proxy/proxy3.py @@ -1,20 +1,22 @@ # -*- coding: utf-8 -*- +import re import socket import ssl -import re from http.server import BaseHTTPRequestHandler -from subprocess import check_output, CalledProcessError +from subprocess import CalledProcessError, check_output from threading import Lock from typing import Any, Dict from botocore.awsrequest import AWSPreparedRequest -from moto.backends import get_backend + from moto.backend_index import backend_url_patterns -from moto.core import BackendDict, DEFAULT_ACCOUNT_ID +from moto.backends import get_backend +from moto.core import DEFAULT_ACCOUNT_ID, BackendDict from moto.core.exceptions import RESTError + from . import debug, error, info, with_color -from .utils import get_body_from_form_data from .certificate_creator import CertificateCreator +from .utils import get_body_from_form_data # Adapted from https://github.com/xxlv/proxy3 diff --git a/moto/moto_proxy/utils.py b/moto/moto_proxy/utils.py index c42c33558..bbdb055af 100644 --- a/moto/moto_proxy/utils.py +++ b/moto/moto_proxy/utils.py @@ -1,6 +1,7 @@ import io +from typing import Dict, Optional, Tuple + import multipart -from typing import Dict, Tuple, Optional def get_body_from_form_data( diff --git a/moto/moto_server/threaded_moto_server.py b/moto/moto_server/threaded_moto_server.py index 602f06cec..8849ade6f 100644 --- a/moto/moto_server/threaded_moto_server.py +++ b/moto/moto_server/threaded_moto_server.py @@ -1,7 +1,8 @@ import time from threading import Thread from typing import Optional -from werkzeug.serving import make_server, BaseWSGIServer + +from werkzeug.serving import BaseWSGIServer, make_server from .werkzeug_app import DomainDispatcherApplication, create_backend_app diff --git a/moto/moto_server/utilities.py b/moto/moto_server/utilities.py index bf4268b1c..7b0923dca 100644 --- a/moto/moto_server/utilities.py +++ b/moto/moto_server/utilities.py @@ -1,7 +1,8 @@ import json -from flask.testing import FlaskClient from typing import Any, Dict from urllib.parse import urlencode + +from flask.testing import FlaskClient from werkzeug.routing import BaseConverter diff --git a/moto/moto_server/werkzeug_app.py b/moto/moto_server/werkzeug_app.py index 9de05a1d1..5fde1d409 100644 --- a/moto/moto_server/werkzeug_app.py +++ b/moto/moto_server/werkzeug_app.py @@ -15,9 +15,9 @@ except ImportError: ) raise -import moto.backends as backends import moto.backend_index as backend_index -from moto.core import BackendDict, DEFAULT_ACCOUNT_ID +import moto.backends as backends +from moto.core import DEFAULT_ACCOUNT_ID, BackendDict from moto.core.utils import convert_to_flask_response from .utilities import AWSTestHelper, RegexConverter diff --git a/moto/mq/__init__.py b/moto/mq/__init__.py index cde94761c..d98737807 100644 --- a/moto/mq/__init__.py +++ b/moto/mq/__init__.py @@ -1,5 +1,5 @@ """mq module initialization; sets value for base decorator.""" -from .models import mq_backends from ..core.models import base_decorator +from .models import mq_backends mock_mq = base_decorator(mq_backends) diff --git a/moto/mq/exceptions.py b/moto/mq/exceptions.py index a3d83deab..eba0efe41 100644 --- a/moto/mq/exceptions.py +++ b/moto/mq/exceptions.py @@ -1,5 +1,6 @@ import json from typing import Any + from moto.core.exceptions import JsonRESTError diff --git a/moto/mq/models.py b/moto/mq/models.py index 393a3bb80..1a2623f16 100644 --- a/moto/mq/models.py +++ b/moto/mq/models.py @@ -1,8 +1,9 @@ import base64 -import xmltodict -from typing import Any, Dict, List, Iterable, Optional, Tuple +from typing import Any, Dict, Iterable, List, Optional, Tuple -from moto.core import BaseBackend, BackendDict, BaseModel +import xmltodict + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import unix_time from moto.moto_api._internal import mock_random from moto.utilities.tagging_service import TaggingService @@ -11,8 +12,8 @@ from .configuration import DEFAULT_CONFIGURATION_DATA from .exceptions import ( UnknownBroker, UnknownConfiguration, - UnknownUser, UnknownEngineType, + UnknownUser, ) diff --git a/moto/mq/responses.py b/moto/mq/responses.py index ecfb3bfaa..ce3d9c1a3 100644 --- a/moto/mq/responses.py +++ b/moto/mq/responses.py @@ -5,7 +5,8 @@ from urllib.parse import unquote from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from .models import mq_backends, MQBackend + +from .models import MQBackend, mq_backends class MQResponse(BaseResponse): diff --git a/moto/neptune/__init__.py b/moto/neptune/__init__.py index 9a4342414..8507c7410 100644 --- a/moto/neptune/__init__.py +++ b/moto/neptune/__init__.py @@ -5,7 +5,7 @@ It shares almost everything with RDS: the endpoint URL, and the features. Only t Because the endpoint URL is the same (rds.amazonaws.com), every request is intercepted by the RDS service. RDS then has to determine whether any incoming call was meant for RDS, or for neptune. """ -from .models import neptune_backends from ..core.models import base_decorator +from .models import neptune_backends mock_neptune = base_decorator(neptune_backends) diff --git a/moto/neptune/exceptions.py b/moto/neptune/exceptions.py index a05480bab..c2958b0e8 100644 --- a/moto/neptune/exceptions.py +++ b/moto/neptune/exceptions.py @@ -1,4 +1,5 @@ from jinja2 import Template + from moto.core.exceptions import RESTError diff --git a/moto/neptune/models.py b/moto/neptune/models.py index b8372e866..ecb3d8d25 100644 --- a/moto/neptune/models.py +++ b/moto/neptune/models.py @@ -1,12 +1,14 @@ import copy import string -from jinja2 import Template from typing import Any, Dict, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel +from jinja2 import Template + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import iso_8601_datetime_with_milliseconds -from moto.utilities.utils import load_resource from moto.moto_api._internal import mock_random as random +from moto.utilities.utils import load_resource + from .exceptions import DBClusterNotFoundError diff --git a/moto/neptune/responses.py b/moto/neptune/responses.py index 8079d7d02..d9b57532a 100644 --- a/moto/neptune/responses.py +++ b/moto/neptune/responses.py @@ -1,5 +1,6 @@ from moto.core.responses import BaseResponse -from .models import neptune_backends, NeptuneBackend + +from .models import NeptuneBackend, neptune_backends class NeptuneResponse(BaseResponse): diff --git a/moto/opensearch/__init__.py b/moto/opensearch/__init__.py index 90fa32ba7..8589bcb50 100644 --- a/moto/opensearch/__init__.py +++ b/moto/opensearch/__init__.py @@ -1,5 +1,5 @@ """opensearch module initialization; sets value for base decorator.""" -from .models import opensearch_backends from ..core.models import base_decorator +from .models import opensearch_backends mock_opensearch = base_decorator(opensearch_backends) diff --git a/moto/opensearch/models.py b/moto/opensearch/models.py index d2b724021..60e5a845a 100644 --- a/moto/opensearch/models.py +++ b/moto/opensearch/models.py @@ -1,10 +1,10 @@ from typing import Any, Dict, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.utilities.tagging_service import TaggingService from .data import compatible_versions -from .exceptions import ResourceNotFoundException, EngineTypeNotFoundException +from .exceptions import EngineTypeNotFoundException, ResourceNotFoundException default_cluster_config = { "InstanceType": "t3.small.search", diff --git a/moto/opensearch/responses.py b/moto/opensearch/responses.py index 2d3bbf088..ed13c48e1 100644 --- a/moto/opensearch/responses.py +++ b/moto/opensearch/responses.py @@ -3,7 +3,7 @@ import json from moto.core.responses import BaseResponse -from .models import opensearch_backends, OpenSearchServiceBackend +from .models import OpenSearchServiceBackend, opensearch_backends class OpenSearchServiceResponse(BaseResponse): diff --git a/moto/opsworks/__init__.py b/moto/opsworks/__init__.py index ef945994d..9fc813dbf 100644 --- a/moto/opsworks/__init__.py +++ b/moto/opsworks/__init__.py @@ -1,5 +1,5 @@ -from .models import opsworks_backends from ..core.models import base_decorator +from .models import opsworks_backends opsworks_backend = opsworks_backends["us-east-1"] mock_opsworks = base_decorator(opsworks_backends) diff --git a/moto/opsworks/models.py b/moto/opsworks/models.py index 221671ddf..a717ff261 100644 --- a/moto/opsworks/models.py +++ b/moto/opsworks/models.py @@ -1,8 +1,9 @@ -from moto.core import BaseBackend, BackendDict, BaseModel +from typing import Any, Dict, List, Optional + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import utcnow from moto.ec2 import ec2_backends from moto.moto_api._internal import mock_random as random -from typing import Any, Dict, List, Optional from .exceptions import ResourceNotFoundException, ValidationException diff --git a/moto/opsworks/responses.py b/moto/opsworks/responses.py index eb5aa46c5..f1efb9ea0 100644 --- a/moto/opsworks/responses.py +++ b/moto/opsworks/responses.py @@ -1,7 +1,8 @@ import json from moto.core.responses import BaseResponse -from .models import opsworks_backends, OpsWorksBackend + +from .models import OpsWorksBackend, opsworks_backends class OpsWorksResponse(BaseResponse): diff --git a/moto/organizations/__init__.py b/moto/organizations/__init__.py index 0b163ad17..8a343171e 100644 --- a/moto/organizations/__init__.py +++ b/moto/organizations/__init__.py @@ -1,4 +1,4 @@ -from .models import organizations_backends from ..core.models import base_decorator +from .models import organizations_backends mock_organizations = base_decorator(organizations_backends) diff --git a/moto/organizations/models.py b/moto/organizations/models.py index 92bfd290e..9ca8bb780 100644 --- a/moto/organizations/models.py +++ b/moto/organizations/models.py @@ -1,27 +1,28 @@ -import re import json +import re from typing import Any, Dict, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.exceptions import RESTError from moto.core.utils import unix_time, utcnow from moto.organizations import utils from moto.organizations.exceptions import ( - InvalidInputException, + AccountAlreadyRegisteredException, + AccountNotFoundException, + AccountNotRegisteredException, + AWSOrganizationsNotInUseException, + ConstraintViolationException, DuplicateOrganizationalUnitException, DuplicatePolicyException, - AccountNotFoundException, - ConstraintViolationException, - AccountAlreadyRegisteredException, - AWSOrganizationsNotInUseException, - AccountNotRegisteredException, - RootNotFoundException, + InvalidInputException, PolicyNotFoundException, PolicyTypeAlreadyEnabledException, PolicyTypeNotEnabledException, + RootNotFoundException, TargetNotFoundException, ) from moto.utilities.paginator import paginate + from .utils import PAGINATION_MODEL diff --git a/moto/organizations/responses.py b/moto/organizations/responses.py index 67f28d2e4..1f970caed 100644 --- a/moto/organizations/responses.py +++ b/moto/organizations/responses.py @@ -2,7 +2,8 @@ import json from typing import Any, Dict from moto.core.responses import BaseResponse -from .models import organizations_backends, OrganizationsBackend + +from .models import OrganizationsBackend, organizations_backends class OrganizationsResponse(BaseResponse): diff --git a/moto/organizations/utils.py b/moto/organizations/utils.py index 9e1335c64..b21d25bc0 100644 --- a/moto/organizations/utils.py +++ b/moto/organizations/utils.py @@ -1,8 +1,8 @@ import re import string -from moto.moto_api._internal import mock_random as random from typing import Pattern, Union +from moto.moto_api._internal import mock_random as random MASTER_ACCOUNT_EMAIL = "master@example.com" DEFAULT_POLICY_ID = "p-FullAWSAccess" diff --git a/moto/packages/boto/ec2/ec2object.py b/moto/packages/boto/ec2/ec2object.py index f87f72f46..d8a869701 100644 --- a/moto/packages/boto/ec2/ec2object.py +++ b/moto/packages/boto/ec2/ec2object.py @@ -24,6 +24,7 @@ Represents an EC2 Object """ from typing import Any + from moto.packages.boto.ec2.tag import TagSet diff --git a/moto/packages/boto/ec2/instance.py b/moto/packages/boto/ec2/instance.py index 571c095e2..f529fc2b5 100644 --- a/moto/packages/boto/ec2/instance.py +++ b/moto/packages/boto/ec2/instance.py @@ -25,6 +25,7 @@ Represents an EC2 Instance """ from typing import Any + from moto.packages.boto.ec2.ec2object import EC2Object, TaggedEC2Object from moto.packages.boto.ec2.image import ProductCodes diff --git a/moto/packages/cfnresponse/cfnresponse.py b/moto/packages/cfnresponse/cfnresponse.py index 4be9e11e3..0887c2c67 100644 --- a/moto/packages/cfnresponse/cfnresponse.py +++ b/moto/packages/cfnresponse/cfnresponse.py @@ -5,9 +5,11 @@ # SPDX-License-Identifier: MIT-0 from __future__ import print_function -from typing import Any -import urllib3 + import json +from typing import Any + +import urllib3 SUCCESS = "SUCCESS" FAILED = "FAILED" diff --git a/moto/personalize/__init__.py b/moto/personalize/__init__.py index fe2fdaa2a..963636aab 100644 --- a/moto/personalize/__init__.py +++ b/moto/personalize/__init__.py @@ -1,5 +1,5 @@ """personalize module initialization; sets value for base decorator.""" -from .models import personalize_backends from ..core.models import base_decorator +from .models import personalize_backends mock_personalize = base_decorator(personalize_backends) diff --git a/moto/personalize/models.py b/moto/personalize/models.py index 3b66371ce..46f3de006 100644 --- a/moto/personalize/models.py +++ b/moto/personalize/models.py @@ -1,9 +1,10 @@ from typing import Any, Dict, Iterable -from .exceptions import ResourceNotFoundException -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import unix_time +from .exceptions import ResourceNotFoundException + class Schema(BaseModel): def __init__( diff --git a/moto/personalize/responses.py b/moto/personalize/responses.py index f42913ee4..b6aa2f13a 100644 --- a/moto/personalize/responses.py +++ b/moto/personalize/responses.py @@ -2,7 +2,8 @@ import json from moto.core.responses import BaseResponse -from .models import personalize_backends, PersonalizeBackend + +from .models import PersonalizeBackend, personalize_backends class PersonalizeResponse(BaseResponse): diff --git a/moto/pinpoint/__init__.py b/moto/pinpoint/__init__.py index 106031bed..711f49426 100644 --- a/moto/pinpoint/__init__.py +++ b/moto/pinpoint/__init__.py @@ -1,5 +1,5 @@ """pinpoint module initialization; sets value for base decorator.""" -from .models import pinpoint_backends from ..core.models import base_decorator +from .models import pinpoint_backends mock_pinpoint = base_decorator(pinpoint_backends) diff --git a/moto/pinpoint/models.py b/moto/pinpoint/models.py index b3d33669f..c0817b3f8 100644 --- a/moto/pinpoint/models.py +++ b/moto/pinpoint/models.py @@ -1,6 +1,7 @@ from datetime import datetime -from typing import Any, Dict, List, Iterable, Optional -from moto.core import BaseBackend, BackendDict, BaseModel +from typing import Any, Dict, Iterable, List, Optional + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import unix_time from moto.moto_api._internal import mock_random from moto.utilities.tagging_service import TaggingService diff --git a/moto/pinpoint/responses.py b/moto/pinpoint/responses.py index 5b9f9b861..ad7ad4f38 100644 --- a/moto/pinpoint/responses.py +++ b/moto/pinpoint/responses.py @@ -1,11 +1,12 @@ """Handles incoming pinpoint requests, invokes methods, returns responses.""" import json from typing import Any +from urllib.parse import unquote from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from urllib.parse import unquote -from .models import pinpoint_backends, PinpointBackend + +from .models import PinpointBackend, pinpoint_backends class PinpointResponse(BaseResponse): diff --git a/moto/polly/__init__.py b/moto/polly/__init__.py index 3bce14d12..906646c33 100644 --- a/moto/polly/__init__.py +++ b/moto/polly/__init__.py @@ -1,5 +1,5 @@ -from .models import polly_backends from ..core.models import base_decorator +from .models import polly_backends polly_backend = polly_backends["us-east-1"] mock_polly = base_decorator(polly_backends) diff --git a/moto/polly/models.py b/moto/polly/models.py index 0bf5b75b2..063099743 100644 --- a/moto/polly/models.py +++ b/moto/polly/models.py @@ -1,8 +1,8 @@ +import datetime from typing import Any, Dict, List, Optional from xml.etree import ElementTree as ET -import datetime -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from .resources import VOICE_DATA from .utils import make_arn_for_lexicon diff --git a/moto/polly/responses.py b/moto/polly/responses.py index 0a73a3af0..f84d21f9b 100644 --- a/moto/polly/responses.py +++ b/moto/polly/responses.py @@ -4,7 +4,8 @@ from typing import Any, Dict, Tuple, Union from urllib.parse import urlsplit from moto.core.responses import BaseResponse -from .models import polly_backends, PollyBackend + +from .models import PollyBackend, polly_backends from .resources import LANGUAGE_CODES, VOICE_IDS LEXICON_NAME_REGEX = re.compile(r"^[0-9A-Za-z]{1,20}$") diff --git a/moto/proxy.py b/moto/proxy.py index 961e21c75..e6c293b02 100644 --- a/moto/proxy.py +++ b/moto/proxy.py @@ -7,7 +7,7 @@ from http.server import ThreadingHTTPServer from typing import Any from moto.moto_proxy import logger -from moto.moto_proxy.proxy3 import ProxyRequestHandler, with_color, CertificateCreator +from moto.moto_proxy.proxy3 import CertificateCreator, ProxyRequestHandler, with_color def signal_handler(signum: Any, frame: Any) -> None: # pylint: disable=unused-argument diff --git a/moto/quicksight/__init__.py b/moto/quicksight/__init__.py index c58340038..123c078b7 100644 --- a/moto/quicksight/__init__.py +++ b/moto/quicksight/__init__.py @@ -1,5 +1,5 @@ """quicksight module initialization; sets value for base decorator.""" -from .models import quicksight_backends from ..core.models import base_decorator +from .models import quicksight_backends mock_quicksight = base_decorator(quicksight_backends) diff --git a/moto/quicksight/models.py b/moto/quicksight/models.py index 74c06a30f..2d1c15bf0 100644 --- a/moto/quicksight/models.py +++ b/moto/quicksight/models.py @@ -1,6 +1,8 @@ from typing import Any, Dict, Iterable -from moto.core import BaseBackend, BackendDict, BaseModel + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.moto_api._internal import mock_random as random + from .exceptions import ResourceNotFoundException diff --git a/moto/quicksight/responses.py b/moto/quicksight/responses.py index 1ec85525a..8678fce72 100644 --- a/moto/quicksight/responses.py +++ b/moto/quicksight/responses.py @@ -4,7 +4,8 @@ from typing import Any from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from .models import quicksight_backends, QuickSightBackend + +from .models import QuickSightBackend, quicksight_backends class QuickSightResponse(BaseResponse): diff --git a/moto/ram/__init__.py b/moto/ram/__init__.py index a4925944f..767c2d0ca 100644 --- a/moto/ram/__init__.py +++ b/moto/ram/__init__.py @@ -1,5 +1,5 @@ -from .models import ram_backends from ..core.models import base_decorator +from .models import ram_backends ram_backend = ram_backends["us-east-1"] mock_ram = base_decorator(ram_backends) diff --git a/moto/ram/models.py b/moto/ram/models.py index e4f12106e..150c8225d 100644 --- a/moto/ram/models.py +++ b/moto/ram/models.py @@ -2,15 +2,15 @@ import re import string from typing import Any, Dict, List -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import unix_time, utcnow from moto.moto_api._internal import mock_random as random -from moto.organizations.models import organizations_backends, OrganizationsBackend +from moto.organizations.models import OrganizationsBackend, organizations_backends from moto.ram.exceptions import ( - MalformedArnException, InvalidParameterException, - UnknownResourceException, + MalformedArnException, OperationNotPermittedException, + UnknownResourceException, ) diff --git a/moto/ram/responses.py b/moto/ram/responses.py index d07061614..6f20efff7 100644 --- a/moto/ram/responses.py +++ b/moto/ram/responses.py @@ -2,7 +2,8 @@ import json from typing import Any, Dict from moto.core.responses import BaseResponse -from .models import ram_backends, ResourceAccessManagerBackend + +from .models import ResourceAccessManagerBackend, ram_backends class ResourceAccessManagerResponse(BaseResponse): diff --git a/moto/rds/__init__.py b/moto/rds/__init__.py index f4ad5814a..2d5a3732f 100644 --- a/moto/rds/__init__.py +++ b/moto/rds/__init__.py @@ -1,5 +1,5 @@ -from .models import rds_backends from ..core.models import base_decorator +from .models import rds_backends rds_backend = rds_backends["us-west-1"] mock_rds = base_decorator(rds_backends) diff --git a/moto/rds/exceptions.py b/moto/rds/exceptions.py index d6c015311..cc78be6d0 100644 --- a/moto/rds/exceptions.py +++ b/moto/rds/exceptions.py @@ -1,4 +1,5 @@ from jinja2 import Template + from moto.core.exceptions import RESTError diff --git a/moto/rds/models.py b/moto/rds/models.py index 82a7c0755..f7dd2b680 100644 --- a/moto/rds/models.py +++ b/moto/rds/models.py @@ -2,55 +2,56 @@ import copy import os import re import string - -from collections import defaultdict -from jinja2 import Template +from collections import OrderedDict, defaultdict from re import compile as re_compile -from collections import OrderedDict -from typing import Any, Dict, List, Optional, Iterable, Tuple, Union -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel +from typing import Any, Dict, Iterable, List, Optional, Tuple, Union + +from jinja2 import Template + +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.core.utils import iso_8601_datetime_with_milliseconds from moto.ec2.models import ec2_backends from moto.moto_api._internal import mock_random as random -from moto.neptune.models import neptune_backends, NeptuneBackend +from moto.neptune.models import NeptuneBackend, neptune_backends from moto.utilities.utils import load_resource + from .exceptions import ( - RDSClientError, DBClusterNotFoundError, + DBClusterParameterGroupNotFoundError, DBClusterSnapshotAlreadyExistsError, DBClusterSnapshotNotFoundError, DBClusterToBeDeletedHasActiveMembers, DBInstanceNotFoundError, - DBSnapshotNotFoundError, - DBSecurityGroupNotFoundError, - DBSubnetGroupNotFoundError, DBParameterGroupNotFoundError, - DBClusterParameterGroupNotFoundError, - OptionGroupNotFoundFaultError, + DBSecurityGroupNotFoundError, + DBSnapshotAlreadyExistsError, + DBSnapshotNotFoundError, + DBSubnetGroupNotFoundError, + ExportTaskAlreadyExistsError, + ExportTaskNotFoundError, + InvalidDBClusterStateFault, InvalidDBClusterStateFaultError, InvalidDBInstanceEngine, - InvalidDBInstanceStateError, - SnapshotQuotaExceededError, - DBSnapshotAlreadyExistsError, - InvalidParameterValue, - InvalidParameterCombination, - InvalidDBClusterStateFault, InvalidDBInstanceIdentifier, - InvalidGlobalClusterStateFault, - ExportTaskNotFoundError, - ExportTaskAlreadyExistsError, + InvalidDBInstanceStateError, InvalidExportSourceStateError, - SubscriptionNotFoundError, + InvalidGlobalClusterStateFault, + InvalidParameterCombination, + InvalidParameterValue, + OptionGroupNotFoundFaultError, + RDSClientError, + SnapshotQuotaExceededError, SubscriptionAlreadyExistError, + SubscriptionNotFoundError, ) from .utils import ( + ClusterEngine, + DbInstanceEngine, FilterDef, apply_filter, merge_filters, - validate_filters, valid_preferred_maintenance_window, - DbInstanceEngine, - ClusterEngine, + validate_filters, ) diff --git a/moto/rds/responses.py b/moto/rds/responses.py index 001734ef9..09edcb15e 100644 --- a/moto/rds/responses.py +++ b/moto/rds/responses.py @@ -1,18 +1,19 @@ from collections import defaultdict -from typing import Any, Dict, List, Iterable +from typing import Any, Dict, Iterable, List from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse from moto.ec2.models import ec2_backends -from moto.neptune.responses import NeptuneResponse from moto.neptune.responses import ( CREATE_GLOBAL_CLUSTER_TEMPLATE, - DESCRIBE_GLOBAL_CLUSTERS_TEMPLATE, DELETE_GLOBAL_CLUSTER_TEMPLATE, + DESCRIBE_GLOBAL_CLUSTERS_TEMPLATE, REMOVE_FROM_GLOBAL_CLUSTER_TEMPLATE, + NeptuneResponse, ) -from .models import rds_backends, RDSBackend + from .exceptions import DBParameterGroupNotFoundError +from .models import RDSBackend, rds_backends class RDSResponse(BaseResponse): diff --git a/moto/rds/utils.py b/moto/rds/utils.py index b890ff9b5..546274afe 100644 --- a/moto/rds/utils.py +++ b/moto/rds/utils.py @@ -1,13 +1,11 @@ import copy -from collections import namedtuple -from typing import Any, Dict, Tuple, Optional, List -from enum import Enum - -from botocore.utils import merge_dicts - -from collections import OrderedDict import datetime import re +from collections import OrderedDict, namedtuple +from enum import Enum +from typing import Any, Dict, List, Optional, Tuple + +from botocore.utils import merge_dicts SECONDS_IN_ONE_DAY = 24 * 60 * 60 FilterDef = namedtuple( diff --git a/moto/rdsdata/__init__.py b/moto/rdsdata/__init__.py index 41ff3651f..5db4af5ca 100644 --- a/moto/rdsdata/__init__.py +++ b/moto/rdsdata/__init__.py @@ -1,5 +1,5 @@ """rdsdata module initialization; sets value for base decorator.""" -from .models import rdsdata_backends from ..core.models import base_decorator +from .models import rdsdata_backends mock_rdsdata = base_decorator(rdsdata_backends) diff --git a/moto/rdsdata/models.py b/moto/rdsdata/models.py index 45964f8a2..c7cd01332 100644 --- a/moto/rdsdata/models.py +++ b/moto/rdsdata/models.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Optional, Tuple -from moto.core import BaseBackend, BackendDict +from moto.core import BackendDict, BaseBackend class QueryResults: diff --git a/moto/rdsdata/responses.py b/moto/rdsdata/responses.py index f3bd89cb0..486255c8d 100644 --- a/moto/rdsdata/responses.py +++ b/moto/rdsdata/responses.py @@ -1,7 +1,8 @@ import json from moto.core.responses import BaseResponse -from .models import rdsdata_backends, RDSDataServiceBackend + +from .models import RDSDataServiceBackend, rdsdata_backends class RDSDataServiceResponse(BaseResponse): diff --git a/moto/redshift/__init__.py b/moto/redshift/__init__.py index 0bd3d0b8e..50fb3c90d 100644 --- a/moto/redshift/__init__.py +++ b/moto/redshift/__init__.py @@ -1,4 +1,4 @@ -from .models import redshift_backends from ..core.models import base_decorator +from .models import redshift_backends mock_redshift = base_decorator(redshift_backends) diff --git a/moto/redshift/exceptions.py b/moto/redshift/exceptions.py index ce46f7fb2..7d50599a1 100644 --- a/moto/redshift/exceptions.py +++ b/moto/redshift/exceptions.py @@ -1,5 +1,6 @@ import json from typing import List, Optional + from moto.core.exceptions import JsonRESTError diff --git a/moto/redshift/models.py b/moto/redshift/models.py index 624429729..104fb783e 100644 --- a/moto/redshift/models.py +++ b/moto/redshift/models.py @@ -1,23 +1,26 @@ -from collections import OrderedDict import copy import datetime +from collections import OrderedDict from typing import Any, Dict, Iterable, List, Optional from dateutil.tz import tzutc -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.core.utils import iso_8601_datetime_with_milliseconds from moto.ec2 import ec2_backends from moto.ec2.models.security_groups import SecurityGroup as EC2SecurityGroup from moto.moto_api._internal import mock_random + from .exceptions import ( ClusterAlreadyExistsFaultError, ClusterNotFoundError, ClusterParameterGroupNotFoundError, ClusterSecurityGroupNotFoundError, + ClusterSecurityGroupNotFoundFaultError, ClusterSnapshotAlreadyExistsError, ClusterSnapshotNotFoundError, ClusterSubnetGroupNotFoundError, + InvalidClusterSnapshotStateFaultError, InvalidParameterCombinationError, InvalidParameterValueError, InvalidSubnetError, @@ -28,8 +31,6 @@ from .exceptions import ( SnapshotCopyGrantAlreadyExistsFaultError, SnapshotCopyGrantNotFoundFaultError, UnknownSnapshotCopyRegionFaultError, - ClusterSecurityGroupNotFoundFaultError, - InvalidClusterSnapshotStateFaultError, ) diff --git a/moto/redshift/responses.py b/moto/redshift/responses.py index 7ec05a59d..89a3ed3bd 100644 --- a/moto/redshift/responses.py +++ b/moto/redshift/responses.py @@ -1,13 +1,13 @@ import json +from typing import Any, Dict, List import xmltodict - from jinja2 import Template -from typing import Any, Dict, List from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from .models import redshift_backends, RedshiftBackend + +from .models import RedshiftBackend, redshift_backends def convert_json_error_to_xml(json_error: Any) -> str: diff --git a/moto/redshiftdata/__init__.py b/moto/redshiftdata/__init__.py index 57a653521..c0736a0a5 100644 --- a/moto/redshiftdata/__init__.py +++ b/moto/redshiftdata/__init__.py @@ -1,4 +1,4 @@ -from .models import redshiftdata_backends from ..core.models import base_decorator +from .models import redshiftdata_backends mock_redshiftdata = base_decorator(redshiftdata_backends) diff --git a/moto/redshiftdata/models.py b/moto/redshiftdata/models.py index 230afd590..75673f21f 100644 --- a/moto/redshiftdata/models.py +++ b/moto/redshiftdata/models.py @@ -1,11 +1,11 @@ import re from datetime import datetime -from typing import Any, Dict, Iterable, Iterator, List, Tuple, Optional +from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple -from moto.core import BaseBackend, BackendDict +from moto.core import BackendDict, BaseBackend from moto.core.utils import iso_8601_datetime_without_milliseconds from moto.moto_api._internal import mock_random as random -from moto.redshiftdata.exceptions import ValidationException, ResourceNotFoundException +from moto.redshiftdata.exceptions import ResourceNotFoundException, ValidationException class Statement(Iterable[Tuple[str, Any]]): diff --git a/moto/redshiftdata/responses.py b/moto/redshiftdata/responses.py index e94b2fca7..7a31599f5 100644 --- a/moto/redshiftdata/responses.py +++ b/moto/redshiftdata/responses.py @@ -1,7 +1,9 @@ import json + from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from .models import redshiftdata_backends, RedshiftDataAPIServiceBackend + +from .models import RedshiftDataAPIServiceBackend, redshiftdata_backends class RedshiftDataAPIServiceResponse(BaseResponse): diff --git a/moto/rekognition/__init__.py b/moto/rekognition/__init__.py index cfa43786b..7e9a8f5b0 100644 --- a/moto/rekognition/__init__.py +++ b/moto/rekognition/__init__.py @@ -1,5 +1,5 @@ """rekognition module initialization; sets value for base decorator.""" -from .models import rekognition_backends from ..core.models import base_decorator +from .models import rekognition_backends mock_rekognition = base_decorator(rekognition_backends) diff --git a/moto/rekognition/models.py b/moto/rekognition/models.py index b5b2f20e3..d5589f9e5 100644 --- a/moto/rekognition/models.py +++ b/moto/rekognition/models.py @@ -3,7 +3,7 @@ import string from typing import Any, Dict, List, Tuple -from moto.core import BaseBackend, BackendDict +from moto.core import BackendDict, BaseBackend from moto.moto_api._internal import mock_random as random diff --git a/moto/rekognition/responses.py b/moto/rekognition/responses.py index b1f73c3ae..37af625b3 100644 --- a/moto/rekognition/responses.py +++ b/moto/rekognition/responses.py @@ -2,7 +2,8 @@ import json from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from .models import rekognition_backends, RekognitionBackend + +from .models import RekognitionBackend, rekognition_backends class RekognitionResponse(BaseResponse): diff --git a/moto/resourcegroups/__init__.py b/moto/resourcegroups/__init__.py index 35153ade5..c889fe6e7 100644 --- a/moto/resourcegroups/__init__.py +++ b/moto/resourcegroups/__init__.py @@ -1,5 +1,5 @@ -from .models import resourcegroups_backends from ..core.models import base_decorator +from .models import resourcegroups_backends resourcegroups_backend = resourcegroups_backends["us-east-1"] mock_resourcegroups = base_decorator(resourcegroups_backends) diff --git a/moto/resourcegroups/models.py b/moto/resourcegroups/models.py index 0dd363fad..7760dac00 100644 --- a/moto/resourcegroups/models.py +++ b/moto/resourcegroups/models.py @@ -1,9 +1,9 @@ -from typing import Any, Dict, List, Optional - import json import re +from typing import Any, Dict, List, Optional + +from moto.core import BackendDict, BaseBackend, BaseModel -from moto.core import BaseBackend, BackendDict, BaseModel from .exceptions import BadRequestException diff --git a/moto/resourcegroups/responses.py b/moto/resourcegroups/responses.py index 4057ba4f4..800720456 100644 --- a/moto/resourcegroups/responses.py +++ b/moto/resourcegroups/responses.py @@ -1,9 +1,9 @@ import json - from urllib.parse import unquote from moto.core.responses import BaseResponse -from .models import resourcegroups_backends, ResourceGroupsBackend + +from .models import ResourceGroupsBackend, resourcegroups_backends class ResourceGroupsResponse(BaseResponse): diff --git a/moto/resourcegroupstaggingapi/__init__.py b/moto/resourcegroupstaggingapi/__init__.py index d28d6f6db..effa91700 100644 --- a/moto/resourcegroupstaggingapi/__init__.py +++ b/moto/resourcegroupstaggingapi/__init__.py @@ -1,5 +1,5 @@ -from .models import resourcegroupstaggingapi_backends from ..core.models import base_decorator +from .models import resourcegroupstaggingapi_backends resourcegroupstaggingapi_backend = resourcegroupstaggingapi_backends["us-east-1"] mock_resourcegroupstaggingapi = base_decorator(resourcegroupstaggingapi_backends) diff --git a/moto/resourcegroupstaggingapi/models.py b/moto/resourcegroupstaggingapi/models.py index ed90dcaca..5e904b9c6 100644 --- a/moto/resourcegroupstaggingapi/models.py +++ b/moto/resourcegroupstaggingapi/models.py @@ -1,24 +1,24 @@ -from typing import Any, Dict, List, Iterator, Optional, Tuple -from moto.core import BaseBackend, BackendDict -from moto.core.exceptions import RESTError -from moto.moto_api._internal import mock_random -from moto.utilities.tagging_service import TaggingService +from typing import Any, Dict, Iterator, List, Optional, Tuple -from moto.s3.models import s3_backends, S3Backend +from moto.acm.models import AWSCertificateManagerBackend, acm_backends +from moto.awslambda.models import LambdaBackend, lambda_backends +from moto.core import BackendDict, BaseBackend +from moto.core.exceptions import RESTError from moto.ec2 import ec2_backends -from moto.elb.models import elb_backends, ELBBackend -from moto.elbv2.models import elbv2_backends, ELBv2Backend -from moto.glue.models import glue_backends, GlueBackend -from moto.kinesis.models import kinesis_backends, KinesisBackend -from moto.logs.models import logs_backends, LogsBackend -from moto.kms.models import kms_backends, KmsBackend -from moto.rds.models import rds_backends, RDSBackend -from moto.glacier.models import glacier_backends, GlacierBackend -from moto.redshift.models import redshift_backends, RedshiftBackend -from moto.emr.models import emr_backends, ElasticMapReduceBackend -from moto.awslambda.models import lambda_backends, LambdaBackend -from moto.ecs.models import ecs_backends, EC2ContainerServiceBackend -from moto.acm.models import acm_backends, AWSCertificateManagerBackend +from moto.ecs.models import EC2ContainerServiceBackend, ecs_backends +from moto.elb.models import ELBBackend, elb_backends +from moto.elbv2.models import ELBv2Backend, elbv2_backends +from moto.emr.models import ElasticMapReduceBackend, emr_backends +from moto.glacier.models import GlacierBackend, glacier_backends +from moto.glue.models import GlueBackend, glue_backends +from moto.kinesis.models import KinesisBackend, kinesis_backends +from moto.kms.models import KmsBackend, kms_backends +from moto.logs.models import LogsBackend, logs_backends +from moto.moto_api._internal import mock_random +from moto.rds.models import RDSBackend, rds_backends +from moto.redshift.models import RedshiftBackend, redshift_backends +from moto.s3.models import S3Backend, s3_backends +from moto.utilities.tagging_service import TaggingService # Left: EC2 ElastiCache RDS ELB CloudFront WorkSpaces Lambda EMR Glacier Kinesis Redshift Route53 # StorageGateway DynamoDB MachineLearning ACM DirectConnect DirectoryService CloudHSM diff --git a/moto/resourcegroupstaggingapi/responses.py b/moto/resourcegroupstaggingapi/responses.py index dbe95e70a..b2c724a7e 100644 --- a/moto/resourcegroupstaggingapi/responses.py +++ b/moto/resourcegroupstaggingapi/responses.py @@ -1,7 +1,9 @@ -from moto.core.responses import BaseResponse -from .models import resourcegroupstaggingapi_backends, ResourceGroupsTaggingAPIBackend import json +from moto.core.responses import BaseResponse + +from .models import ResourceGroupsTaggingAPIBackend, resourcegroupstaggingapi_backends + class ResourceGroupsTaggingAPIResponse(BaseResponse): def __init__(self) -> None: diff --git a/moto/robomaker/__init__.py b/moto/robomaker/__init__.py index 99dc70c6f..0efef621e 100644 --- a/moto/robomaker/__init__.py +++ b/moto/robomaker/__init__.py @@ -1,5 +1,5 @@ """robomaker module initialization; sets value for base decorator.""" -from .models import robomaker_backends from ..core.models import base_decorator +from .models import robomaker_backends mock_robomaker = base_decorator(robomaker_backends) diff --git a/moto/robomaker/models.py b/moto/robomaker/models.py index a03234d4e..7ceb1302b 100644 --- a/moto/robomaker/models.py +++ b/moto/robomaker/models.py @@ -1,7 +1,7 @@ -from moto.core import BaseBackend, BackendDict, BaseModel -from moto.core.utils import unix_time +from typing import Any, Dict, Iterable, List -from typing import Any, Dict, List, Iterable +from moto.core import BackendDict, BaseBackend, BaseModel +from moto.core.utils import unix_time class RobotApplication(BaseModel): diff --git a/moto/robomaker/responses.py b/moto/robomaker/responses.py index 59d44e76b..40fca2dff 100644 --- a/moto/robomaker/responses.py +++ b/moto/robomaker/responses.py @@ -1,7 +1,8 @@ import json from moto.core.responses import BaseResponse -from .models import robomaker_backends, RoboMakerBackend + +from .models import RoboMakerBackend, robomaker_backends class RoboMakerResponse(BaseResponse): diff --git a/moto/route53/__init__.py b/moto/route53/__init__.py index 358e1ee67..7baa67891 100644 --- a/moto/route53/__init__.py +++ b/moto/route53/__init__.py @@ -1,4 +1,4 @@ -from .models import route53_backends from ..core.models import base_decorator +from .models import route53_backends mock_route53 = base_decorator(route53_backends) diff --git a/moto/route53/exceptions.py b/moto/route53/exceptions.py index 5cfa4621a..c5d5d7459 100644 --- a/moto/route53/exceptions.py +++ b/moto/route53/exceptions.py @@ -1,5 +1,6 @@ """Exceptions raised by the Route53 service.""" from typing import Any + from moto.core.exceptions import RESTError diff --git a/moto/route53/models.py b/moto/route53/models.py index f3d6bf612..5b943550f 100644 --- a/moto/route53/models.py +++ b/moto/route53/models.py @@ -5,14 +5,18 @@ import re import string from collections import defaultdict from datetime import datetime - -from jinja2 import Template from typing import Any, Dict, List, Optional, Tuple +from jinja2 import Template + +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel +from moto.moto_api._internal import mock_random as random from moto.route53.exceptions import ( + DnsNameInvalidForZone, HostedZoneNotEmpty, InvalidActionValue, InvalidCloudWatchArn, + InvalidInput, LastVPCAssociation, NoSuchCloudWatchLogsLogGroup, NoSuchDelegationSet, @@ -21,13 +25,10 @@ from moto.route53.exceptions import ( NoSuchQueryLoggingConfig, PublicZoneVPCAssociation, QueryLoggingConfigAlreadyExists, - DnsNameInvalidForZone, ResourceRecordAlreadyExists, - InvalidInput, ) -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel -from moto.moto_api._internal import mock_random as random from moto.utilities.paginator import paginate + from .utils import PAGINATION_MODEL ROUTE53_ID_CHOICE = string.ascii_uppercase + string.digits diff --git a/moto/route53/responses.py b/moto/route53/responses.py index eea217093..3b2bdafed 100644 --- a/moto/route53/responses.py +++ b/moto/route53/responses.py @@ -1,16 +1,16 @@ """Handles Route53 API requests, invokes method and returns response.""" import re +from typing import Any from urllib.parse import parse_qs -from jinja2 import Template -from typing import Any import xmltodict +from jinja2 import Template from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse from moto.core.utils import iso_8601_datetime_with_milliseconds from moto.route53.exceptions import InvalidChangeBatch -from moto.route53.models import route53_backends, Route53Backend +from moto.route53.models import Route53Backend, route53_backends XMLNS = "https://route53.amazonaws.com/doc/2013-04-01/" diff --git a/moto/route53/urls.py b/moto/route53/urls.py index ef8b11a44..156fc127d 100644 --- a/moto/route53/urls.py +++ b/moto/route53/urls.py @@ -1,8 +1,10 @@ """Route53 base URL and path.""" from typing import Any -from .responses import Route53 + from moto.core.common_types import TYPE_RESPONSE +from .responses import Route53 + url_bases = [r"https?://route53(\..+)?\.amazonaws.com"] diff --git a/moto/route53resolver/__init__.py b/moto/route53resolver/__init__.py index ae5d8b000..6d01fbf05 100644 --- a/moto/route53resolver/__init__.py +++ b/moto/route53resolver/__init__.py @@ -1,5 +1,5 @@ """route53resolver module initialization; sets value for base decorator.""" -from .models import route53resolver_backends from ..core.models import base_decorator +from .models import route53resolver_backends mock_route53resolver = base_decorator(route53resolver_backends) diff --git a/moto/route53resolver/exceptions.py b/moto/route53resolver/exceptions.py index e0ce342b4..7149985ce 100644 --- a/moto/route53resolver/exceptions.py +++ b/moto/route53resolver/exceptions.py @@ -1,4 +1,5 @@ from typing import List, Tuple + from moto.core.exceptions import JsonRESTError diff --git a/moto/route53resolver/models.py b/moto/route53resolver/models.py index 94b941f8d..60a98db7c 100644 --- a/moto/route53resolver/models.py +++ b/moto/route53resolver/models.py @@ -1,14 +1,13 @@ """Route53ResolverBackend class with methods for supported APIs.""" +import re from collections import defaultdict from datetime import datetime, timezone -from ipaddress import ip_address, ip_network, IPv4Address +from ipaddress import IPv4Address, ip_address, ip_network from typing import Any, Dict, List, Optional, Set -import re -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.ec2 import ec2_backends -from moto.ec2.exceptions import InvalidSubnetIdError -from moto.ec2.exceptions import InvalidSecurityGroupNotFoundError +from moto.ec2.exceptions import InvalidSecurityGroupNotFoundError, InvalidSubnetIdError from moto.moto_api._internal import mock_random from moto.route53resolver.exceptions import ( InvalidParameterException, @@ -21,7 +20,6 @@ from moto.route53resolver.exceptions import ( ) from moto.route53resolver.utils import PAGINATION_MODEL from moto.route53resolver.validations import validate_args - from moto.utilities.paginator import paginate from moto.utilities.tagging_service import TaggingService diff --git a/moto/route53resolver/responses.py b/moto/route53resolver/responses.py index 8478f9a76..52655780a 100644 --- a/moto/route53resolver/responses.py +++ b/moto/route53resolver/responses.py @@ -4,7 +4,7 @@ import json from moto.core.exceptions import InvalidToken from moto.core.responses import BaseResponse from moto.route53resolver.exceptions import InvalidNextTokenException -from moto.route53resolver.models import route53resolver_backends, Route53ResolverBackend +from moto.route53resolver.models import Route53ResolverBackend, route53resolver_backends from moto.route53resolver.validations import validate_args diff --git a/moto/route53resolver/validations.py b/moto/route53resolver/validations.py index c6fc00f73..e17851738 100644 --- a/moto/route53resolver/validations.py +++ b/moto/route53resolver/validations.py @@ -3,7 +3,7 @@ Note that ValidationExceptions are accumulative. """ import re -from typing import Any, Dict, List, Tuple, Optional +from typing import Any, Dict, List, Optional, Tuple from moto.route53resolver.exceptions import RRValidationException diff --git a/moto/s3/__init__.py b/moto/s3/__init__.py index f34e49585..252a29767 100644 --- a/moto/s3/__init__.py +++ b/moto/s3/__init__.py @@ -1,4 +1,4 @@ -from .models import s3_backends from ..core.models import base_decorator +from .models import s3_backends mock_s3 = base_decorator(s3_backends) diff --git a/moto/s3/config.py b/moto/s3/config.py index 889c946cd..45258f9c3 100644 --- a/moto/s3/config.py +++ b/moto/s3/config.py @@ -1,8 +1,8 @@ import json from typing import Any, Dict, List, Optional, Tuple -from moto.core.exceptions import InvalidNextTokenException from moto.core.common_models import ConfigQueryModel +from moto.core.exceptions import InvalidNextTokenException from moto.s3 import s3_backends diff --git a/moto/s3/exceptions.py b/moto/s3/exceptions.py index c2c73815b..737fa9d7a 100644 --- a/moto/s3/exceptions.py +++ b/moto/s3/exceptions.py @@ -1,4 +1,5 @@ -from typing import Any, Optional, Union, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Optional, Union + from moto.core.exceptions import RESTError if TYPE_CHECKING: diff --git a/moto/s3/models.py b/moto/s3/models.py index 63adababf..07838192d 100644 --- a/moto/s3/models.py +++ b/moto/s3/models.py @@ -1,21 +1,27 @@ +import base64 +import codecs +import copy +import datetime +import itertools import json import os -import base64 -import datetime -import copy -import itertools -import codecs import string +import sys import tempfile import threading -import sys import urllib.parse - from bisect import insort -from typing import Any, Dict, List, Optional, Set, Tuple, Iterator, Union from importlib import reload -from moto.core import BaseBackend, BaseModel, BackendDict, CloudFormationModel -from moto.core import CloudWatchMetricProvider +from typing import Any, Dict, Iterator, List, Optional, Set, Tuple, Union + +from moto.cloudwatch.models import MetricDatum +from moto.core import ( + BackendDict, + BaseBackend, + BaseModel, + CloudFormationModel, + CloudWatchMetricProvider, +) from moto.core.utils import ( iso_8601_datetime_without_milliseconds_s3, rfc_1123_datetime, @@ -23,43 +29,51 @@ from moto.core.utils import ( unix_time_millis, utcnow, ) -from moto.cloudwatch.models import MetricDatum from moto.moto_api import state_manager from moto.moto_api._internal import mock_random as random from moto.moto_api._internal.managed_state_model import ManagedState -from moto.utilities.tagging_service import TaggingService -from moto.utilities.utils import LowercaseDict, md5_hash from moto.s3.exceptions import ( AccessDeniedByLock, BucketAlreadyExists, BucketNeedsToBeNew, CopyObjectMustChangeSomething, - MissingBucket, - InvalidBucketName, - InvalidPart, - InvalidRequest, - EntityTooSmall, - MissingKey, - InvalidNotificationDestination, - MalformedXML, - HeadOnDeleteMarker, - InvalidStorageClass, - InvalidTargetBucketForLogging, CrossLocationLoggingProhibitted, - NoSuchPublicAccessBlockConfiguration, + EntityTooSmall, + HeadOnDeleteMarker, + InvalidBucketName, + InvalidNotificationDestination, + InvalidPart, InvalidPublicAccessBlockConfiguration, + InvalidRequest, + InvalidStorageClass, + InvalidTagError, + InvalidTargetBucketForLogging, + MalformedXML, + MissingBucket, + MissingKey, + NoSuchPublicAccessBlockConfiguration, NoSuchUpload, ObjectLockConfigurationNotFoundError, - InvalidTagError, ) -from .cloud_formation import cfn_to_api_encryption, is_replacement_update -from . import notifications -from .select_object_content import parse_query -from .utils import _VersionedKeyStore, CaseInsensitiveDict -from .utils import ARCHIVE_STORAGE_CLASSES, STORAGE_CLASS, LOGGING_SERVICE_PRINCIPAL +from moto.utilities.tagging_service import TaggingService +from moto.utilities.utils import LowercaseDict, md5_hash + from ..events.notifications import send_notification as events_send_notification -from ..settings import get_s3_default_key_buffer_size, S3_UPLOAD_PART_MIN_SIZE -from ..settings import s3_allow_crossdomain_access +from ..settings import ( + S3_UPLOAD_PART_MIN_SIZE, + get_s3_default_key_buffer_size, + s3_allow_crossdomain_access, +) +from . import notifications +from .cloud_formation import cfn_to_api_encryption, is_replacement_update +from .select_object_content import parse_query +from .utils import ( + ARCHIVE_STORAGE_CLASSES, + LOGGING_SERVICE_PRINCIPAL, + STORAGE_CLASS, + CaseInsensitiveDict, + _VersionedKeyStore, +) MAX_BUCKET_NAME_LENGTH = 63 MIN_BUCKET_NAME_LENGTH = 3 diff --git a/moto/s3/responses.py b/moto/s3/responses.py index 1d8eb6eb7..d2575fe44 100644 --- a/moto/s3/responses.py +++ b/moto/s3/responses.py @@ -1,71 +1,77 @@ import io import re -from typing import Any, Dict, List, Iterator, Union, Tuple, Optional, Type - import urllib.parse - -from moto import settings -from moto.core.utils import ( - extract_region_from_aws_authorization, - str_to_rfc_1123_datetime, -) -from urllib.parse import parse_qs, urlparse, unquote, urlencode, urlunparse +from typing import Any, Dict, Iterator, List, Optional, Tuple, Type, Union +from urllib.parse import parse_qs, unquote, urlencode, urlparse, urlunparse +from xml.dom import minidom import xmltodict +from moto import settings from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from moto.core.utils import path_url - +from moto.core.utils import ( + extract_region_from_aws_authorization, + path_url, + str_to_rfc_1123_datetime, +) from moto.s3bucket_path.utils import ( bucket_name_from_url as bucketpath_bucket_name_from_url, +) +from moto.s3bucket_path.utils import ( parse_key_name as bucketpath_parse_key_name, ) from moto.utilities.aws_headers import amzn_request_id from .exceptions import ( - BucketAlreadyExists, + AccessForbidden, BucketAccessDeniedError, + BucketAlreadyExists, BucketMustHaveLockeEnabled, DuplicateTagKeys, + HeadOnDeleteMarker, + IllegalLocationConstraintException, InvalidContentMD5, InvalidContinuationToken, - S3ClientError, - HeadOnDeleteMarker, + InvalidMaxPartArgument, + InvalidMaxPartNumberArgument, + InvalidNotificationARN, + InvalidNotificationEvent, + InvalidObjectState, + InvalidPartOrder, + InvalidRange, + LockNotEnabled, + MalformedACLError, + MalformedXML, MissingBucket, MissingKey, MissingVersion, - InvalidMaxPartArgument, - InvalidMaxPartNumberArgument, - NotAnIntegerException, - InvalidPartOrder, - MalformedXML, - MalformedACLError, - IllegalLocationConstraintException, - InvalidNotificationARN, - InvalidNotificationEvent, - S3AclAndGrantError, - InvalidObjectState, - ObjectNotInActiveTierError, NoSystemTags, + NotAnIntegerException, + ObjectNotInActiveTierError, PreconditionFailed, - InvalidRange, - LockNotEnabled, - AccessForbidden, + S3AclAndGrantError, + S3ClientError, +) +from .models import ( + FakeAcl, + FakeBucket, + FakeGrant, + FakeGrantee, + FakeKey, + S3Backend, + get_canned_acl, + s3_backends, ) -from .models import s3_backends, S3Backend -from .models import get_canned_acl, FakeGrantee, FakeGrant, FakeAcl, FakeKey, FakeBucket from .select_object_content import serialize_select from .utils import ( + ARCHIVE_STORAGE_CLASSES, bucket_name_from_url, + compute_checksum, + cors_matches_origin, metadata_from_headers, parse_region_from_url, - compute_checksum, - ARCHIVE_STORAGE_CLASSES, - cors_matches_origin, ) -from xml.dom import minidom - DEFAULT_REGION_NAME = "us-east-1" diff --git a/moto/s3/utils.py b/moto/s3/utils.py index 5eab429c1..cae502ba8 100644 --- a/moto/s3/utils.py +++ b/moto/s3/utils.py @@ -1,14 +1,15 @@ -import logging import base64 import binascii -import re import hashlib -from urllib.parse import urlparse -from requests.structures import CaseInsensitiveDict -from typing import Any, Dict, List, Iterator, Union, Tuple, Optional +import logging +import re import sys -from moto.settings import S3_IGNORE_SUBDOMAIN_BUCKETNAME +from typing import Any, Dict, Iterator, List, Optional, Tuple, Union +from urllib.parse import urlparse +from requests.structures import CaseInsensitiveDict + +from moto.settings import S3_IGNORE_SUBDOMAIN_BUCKETNAME log = logging.getLogger(__name__) diff --git a/moto/s3control/__init__.py b/moto/s3control/__init__.py index 1ef58b939..595b08d42 100644 --- a/moto/s3control/__init__.py +++ b/moto/s3control/__init__.py @@ -1,5 +1,5 @@ """s3control module initialization; sets value for base decorator.""" -from .models import s3control_backends from ..core.models import base_decorator +from .models import s3control_backends mock_s3control = base_decorator(s3control_backends) diff --git a/moto/s3control/config.py b/moto/s3control/config.py index a6906d9e1..8d30236a0 100644 --- a/moto/s3control/config.py +++ b/moto/s3control/config.py @@ -1,10 +1,10 @@ import json - -from boto3 import Session from typing import Any, Dict, List, Optional, Tuple -from moto.core.exceptions import InvalidNextTokenException +from boto3 import Session + from moto.core.common_models import ConfigQueryModel +from moto.core.exceptions import InvalidNextTokenException from moto.core.utils import unix_time, utcnow from moto.s3control import s3control_backends diff --git a/moto/s3control/exceptions.py b/moto/s3control/exceptions.py index 9572ace0d..05d962f50 100644 --- a/moto/s3control/exceptions.py +++ b/moto/s3control/exceptions.py @@ -1,6 +1,6 @@ from typing import Any -from moto.core.exceptions import RESTError +from moto.core.exceptions import RESTError ERROR_WITH_ACCESS_POINT_NAME = """{% extends 'wrapped_single_error' %} {% block extra %}{{ name }}{% endblock %} diff --git a/moto/s3control/models.py b/moto/s3control/models.py index cb4bfd786..53035f4e2 100644 --- a/moto/s3control/models.py +++ b/moto/s3control/models.py @@ -2,12 +2,12 @@ from collections import defaultdict from datetime import datetime from typing import Any, Dict, Optional -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.moto_api._internal import mock_random from moto.s3.exceptions import ( - WrongPublicAccessBlockAccountIdError, - NoSuchPublicAccessBlockConfiguration, InvalidPublicAccessBlockConfiguration, + NoSuchPublicAccessBlockConfiguration, + WrongPublicAccessBlockAccountIdError, ) from moto.s3.models import PublicAccessBlock diff --git a/moto/s3control/responses.py b/moto/s3control/responses.py index 536672f2c..8122c5c62 100644 --- a/moto/s3control/responses.py +++ b/moto/s3control/responses.py @@ -1,13 +1,15 @@ import json -import xmltodict from typing import Any, Dict, Tuple +import xmltodict + from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse from moto.s3.exceptions import S3ClientError from moto.s3.responses import S3_PUBLIC_ACCESS_BLOCK_CONFIGURATION from moto.utilities.aws_headers import amzn_request_id -from .models import s3control_backends, S3ControlBackend + +from .models import S3ControlBackend, s3control_backends class S3ControlResponse(BaseResponse): diff --git a/moto/sagemaker/__init__.py b/moto/sagemaker/__init__.py index 71ccc5479..71b9bd2e1 100644 --- a/moto/sagemaker/__init__.py +++ b/moto/sagemaker/__init__.py @@ -1,5 +1,5 @@ -from .models import sagemaker_backends from ..core.models import base_decorator +from .models import sagemaker_backends sagemaker_backend = sagemaker_backends["us-east-1"] mock_sagemaker = base_decorator(sagemaker_backends) diff --git a/moto/sagemaker/exceptions.py b/moto/sagemaker/exceptions.py index 86dcf505a..77e930862 100644 --- a/moto/sagemaker/exceptions.py +++ b/moto/sagemaker/exceptions.py @@ -1,5 +1,6 @@ from typing import Any -from moto.core.exceptions import RESTError, JsonRESTError, AWSError + +from moto.core.exceptions import AWSError, JsonRESTError, RESTError ERROR_WITH_MODEL_NAME = """{% extends 'single_error' %} {% block extra %}{{ model }}{% endblock %} diff --git a/moto/sagemaker/models.py b/moto/sagemaker/models.py index aa855b321..d4c932d3e 100644 --- a/moto/sagemaker/models.py +++ b/moto/sagemaker/models.py @@ -3,25 +3,28 @@ import os import random import string from datetime import datetime -from dateutil.tz import tzutc -from typing import Any, Dict, List, Optional, Iterable, Union +from typing import Any, Dict, Iterable, List, Optional, Union -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel +from dateutil.tz import tzutc + +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.sagemaker import validators from moto.utilities.paginator import paginate + from .exceptions import ( - MissingModel, - ValidationError, AWSValidationException, + MissingModel, ResourceNotFound, + ValidationError, ) from .utils import ( - get_pipeline_from_name, + arn_formatter, get_pipeline_execution_from_arn, + get_pipeline_from_name, get_pipeline_name_from_execution_arn, + load_pipeline_definition_from_s3, validate_model_approval_status, ) -from .utils import load_pipeline_definition_from_s3, arn_formatter PAGINATION_MODEL = { "list_experiments": { diff --git a/moto/sagemaker/responses.py b/moto/sagemaker/responses.py index f490296d7..f260130d1 100644 --- a/moto/sagemaker/responses.py +++ b/moto/sagemaker/responses.py @@ -1,12 +1,12 @@ import json from typing import Any -from moto.sagemaker.exceptions import AWSValidationException - from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse +from moto.sagemaker.exceptions import AWSValidationException from moto.utilities.aws_headers import amzn_request_id -from .models import sagemaker_backends, SageMakerModelBackend + +from .models import SageMakerModelBackend, sagemaker_backends def format_enum_error(value: str, attribute: str, allowed: Any) -> str: diff --git a/moto/sagemaker/utils.py b/moto/sagemaker/utils.py index f10f85108..de5cb873e 100644 --- a/moto/sagemaker/utils.py +++ b/moto/sagemaker/utils.py @@ -1,8 +1,9 @@ +import json import typing +from typing import Any, Dict from moto.s3.models import s3_backends -import json -from typing import Any, Dict + from .exceptions import ValidationError if typing.TYPE_CHECKING: diff --git a/moto/sagemakerruntime/__init__.py b/moto/sagemakerruntime/__init__.py index 8cdc930a6..be055bdf7 100644 --- a/moto/sagemakerruntime/__init__.py +++ b/moto/sagemakerruntime/__init__.py @@ -1,5 +1,5 @@ """sagemakerruntime module initialization; sets value for base decorator.""" -from .models import sagemakerruntime_backends from ..core.models import base_decorator +from .models import sagemakerruntime_backends mock_sagemakerruntime = base_decorator(sagemakerruntime_backends) diff --git a/moto/sagemakerruntime/models.py b/moto/sagemakerruntime/models.py index c28d3931f..26928bcf8 100644 --- a/moto/sagemakerruntime/models.py +++ b/moto/sagemakerruntime/models.py @@ -1,6 +1,7 @@ -from moto.core import BaseBackend, BackendDict from typing import Dict, List, Tuple +from moto.core import BackendDict, BaseBackend + class SageMakerRuntimeBackend(BaseBackend): """Implementation of SageMakerRuntime APIs.""" diff --git a/moto/sagemakerruntime/responses.py b/moto/sagemakerruntime/responses.py index 24cc48633..ee1b86608 100644 --- a/moto/sagemakerruntime/responses.py +++ b/moto/sagemakerruntime/responses.py @@ -3,7 +3,8 @@ import json from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from .models import sagemakerruntime_backends, SageMakerRuntimeBackend + +from .models import SageMakerRuntimeBackend, sagemakerruntime_backends class SageMakerRuntimeResponse(BaseResponse): diff --git a/moto/scheduler/__init__.py b/moto/scheduler/__init__.py index 369fe0fa5..0a0632a45 100644 --- a/moto/scheduler/__init__.py +++ b/moto/scheduler/__init__.py @@ -1,5 +1,5 @@ """scheduler module initialization; sets value for base decorator.""" -from .models import scheduler_backends from ..core.models import base_decorator +from .models import scheduler_backends mock_scheduler = base_decorator(scheduler_backends) diff --git a/moto/scheduler/models.py b/moto/scheduler/models.py index 090e9fc53..bd440a9f8 100644 --- a/moto/scheduler/models.py +++ b/moto/scheduler/models.py @@ -1,12 +1,11 @@ """EventBridgeSchedulerBackend class with methods for supported APIs.""" -from typing import Any, Dict, List, Iterable, Optional +from typing import Any, Dict, Iterable, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import unix_time from moto.utilities.tagging_service import TaggingService -from .exceptions import ScheduleExists -from .exceptions import ScheduleNotFound, ScheduleGroupNotFound +from .exceptions import ScheduleExists, ScheduleGroupNotFound, ScheduleNotFound class Schedule(BaseModel): diff --git a/moto/scheduler/responses.py b/moto/scheduler/responses.py index ae0e9ef89..6f6c160c2 100644 --- a/moto/scheduler/responses.py +++ b/moto/scheduler/responses.py @@ -5,7 +5,8 @@ from urllib.parse import unquote from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from .models import scheduler_backends, EventBridgeSchedulerBackend + +from .models import EventBridgeSchedulerBackend, scheduler_backends class EventBridgeSchedulerResponse(BaseResponse): diff --git a/moto/sdb/__init__.py b/moto/sdb/__init__.py index 3d1cdfd5d..3ddbb5658 100644 --- a/moto/sdb/__init__.py +++ b/moto/sdb/__init__.py @@ -1,5 +1,5 @@ """sdb module initialization; sets value for base decorator.""" -from .models import sdb_backends from ..core.models import base_decorator +from .models import sdb_backends mock_sdb = base_decorator(sdb_backends) diff --git a/moto/sdb/exceptions.py b/moto/sdb/exceptions.py index 6ab6f9a3a..9d90ecddc 100644 --- a/moto/sdb/exceptions.py +++ b/moto/sdb/exceptions.py @@ -1,7 +1,7 @@ """Exceptions raised by the sdb service.""" from typing import Any -from moto.core.exceptions import RESTError +from moto.core.exceptions import RESTError SDB_ERROR = """ diff --git a/moto/sdb/models.py b/moto/sdb/models.py index f093e30a8..59e05e2c0 100644 --- a/moto/sdb/models.py +++ b/moto/sdb/models.py @@ -2,9 +2,10 @@ import re from collections import defaultdict from threading import Lock -from typing import Any, Dict, List, Iterable, Optional +from typing import Any, Dict, Iterable, List, Optional + +from moto.core import BackendDict, BaseBackend, BaseModel -from moto.core import BaseBackend, BackendDict, BaseModel from .exceptions import InvalidDomainName, UnknownDomainName diff --git a/moto/sdb/responses.py b/moto/sdb/responses.py index 11b197428..1009ef63e 100644 --- a/moto/sdb/responses.py +++ b/moto/sdb/responses.py @@ -1,5 +1,6 @@ from moto.core.responses import BaseResponse -from .models import sdb_backends, SimpleDBBackend + +from .models import SimpleDBBackend, sdb_backends class SimpleDBResponse(BaseResponse): diff --git a/moto/secretsmanager/__init__.py b/moto/secretsmanager/__init__.py index 0be3a35dd..30d0731c7 100644 --- a/moto/secretsmanager/__init__.py +++ b/moto/secretsmanager/__init__.py @@ -1,5 +1,5 @@ -from .models import secretsmanager_backends from ..core.models import base_decorator +from .models import secretsmanager_backends secretsmanager_backend = secretsmanager_backends["us-east-1"] mock_secretsmanager = base_decorator(secretsmanager_backends) diff --git a/moto/secretsmanager/list_secrets/filters.py b/moto/secretsmanager/list_secrets/filters.py index 62e1d4669..659d4c636 100644 --- a/moto/secretsmanager/list_secrets/filters.py +++ b/moto/secretsmanager/list_secrets/filters.py @@ -1,4 +1,4 @@ -from typing import List, TYPE_CHECKING +from typing import TYPE_CHECKING, List if TYPE_CHECKING: from ..models import FakeSecret diff --git a/moto/secretsmanager/models.py b/moto/secretsmanager/models.py index 36fd3e7f1..3293c395c 100644 --- a/moto/secretsmanager/models.py +++ b/moto/secretsmanager/models.py @@ -1,31 +1,30 @@ -import time -import json import datetime +import json +import time +from typing import Any, Dict, List, Optional, Tuple -from typing import Any, Dict, List, Tuple, Optional - -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import utcnow from moto.moto_api._internal import mock_random + from .exceptions import ( - SecretNotFoundException, - SecretHasNoValueException, + ClientError, InvalidParameterException, + InvalidRequestException, ResourceExistsException, ResourceNotFoundException, + SecretHasNoValueException, + SecretNotFoundException, SecretStageVersionMismatchException, - InvalidRequestException, - ClientError, ) -from .utils import random_password, secret_arn, get_secret_name_from_partial_arn from .list_secrets.filters import ( + description_filter, filter_all, + name_filter, tag_key, tag_value, - description_filter, - name_filter, ) - +from .utils import get_secret_name_from_partial_arn, random_password, secret_arn _filter_functions = { "all": filter_all, diff --git a/moto/secretsmanager/responses.py b/moto/secretsmanager/responses.py index d5bff4bce..da38b2814 100644 --- a/moto/secretsmanager/responses.py +++ b/moto/secretsmanager/responses.py @@ -1,14 +1,14 @@ +import json from typing import Any, Dict, List + from moto.core.responses import BaseResponse from moto.secretsmanager.exceptions import ( - InvalidRequestException, InvalidParameterException, + InvalidRequestException, ValidationException, ) -from .models import secretsmanager_backends, filter_keys, SecretsManagerBackend - -import json +from .models import SecretsManagerBackend, filter_keys, secretsmanager_backends def _validate_filters(filters: List[Dict[str, Any]]) -> None: diff --git a/moto/secretsmanager/utils.py b/moto/secretsmanager/utils.py index c2052d3ab..76a17d507 100644 --- a/moto/secretsmanager/utils.py +++ b/moto/secretsmanager/utils.py @@ -1,5 +1,6 @@ -import string import re +import string + from moto.moto_api._internal import mock_random as random diff --git a/moto/server.py b/moto/server.py index 0e727d611..051e81a33 100644 --- a/moto/server.py +++ b/moto/server.py @@ -7,13 +7,13 @@ from typing import Any, List, Optional from werkzeug.serving import run_simple +from moto.moto_server.threaded_moto_server import ( # noqa # pylint: disable=unused-import + ThreadedMotoServer, +) from moto.moto_server.werkzeug_app import ( DomainDispatcherApplication, create_backend_app, ) -from moto.moto_server.threaded_moto_server import ( # noqa # pylint: disable=unused-import - ThreadedMotoServer, -) def signal_handler(signum: Any, frame: Any) -> None: # pylint: disable=unused-argument diff --git a/moto/servicediscovery/__init__.py b/moto/servicediscovery/__init__.py index 983db1ab4..5f021995f 100644 --- a/moto/servicediscovery/__init__.py +++ b/moto/servicediscovery/__init__.py @@ -1,5 +1,5 @@ """servicediscovery module initialization; sets value for base decorator.""" -from .models import servicediscovery_backends from ..core.models import base_decorator +from .models import servicediscovery_backends mock_servicediscovery = base_decorator(servicediscovery_backends) diff --git a/moto/servicediscovery/models.py b/moto/servicediscovery/models.py index 0be697c80..d4bbe603c 100644 --- a/moto/servicediscovery/models.py +++ b/moto/servicediscovery/models.py @@ -1,7 +1,7 @@ import string from typing import Any, Dict, Iterable, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import unix_time from moto.moto_api._internal import mock_random as random from moto.utilities.tagging_service import TaggingService diff --git a/moto/servicediscovery/responses.py b/moto/servicediscovery/responses.py index 6a3032f86..f8087ad62 100644 --- a/moto/servicediscovery/responses.py +++ b/moto/servicediscovery/responses.py @@ -3,7 +3,8 @@ import json from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse -from .models import servicediscovery_backends, ServiceDiscoveryBackend + +from .models import ServiceDiscoveryBackend, servicediscovery_backends class ServiceDiscoveryResponse(BaseResponse): diff --git a/moto/servicequotas/__init__.py b/moto/servicequotas/__init__.py index d8e8601ef..7ed935ece 100644 --- a/moto/servicequotas/__init__.py +++ b/moto/servicequotas/__init__.py @@ -1,5 +1,5 @@ """servicequotas module initialization; sets value for base decorator.""" -from .models import servicequotas_backends from ..core.models import base_decorator +from .models import servicequotas_backends mock_servicequotas = base_decorator(servicequotas_backends) diff --git a/moto/servicequotas/models.py b/moto/servicequotas/models.py index 2331ab2d1..5bb5a7eaf 100644 --- a/moto/servicequotas/models.py +++ b/moto/servicequotas/models.py @@ -1,7 +1,9 @@ """ServiceQuotasBackend class with methods for supported APIs.""" -from moto.core import BaseBackend, BackendDict from typing import Any, Dict, List + +from moto.core import BackendDict, BaseBackend + from .exceptions import NoSuchResource from .resources.default_quotas.vpc import VPC_DEFAULT_QUOTAS diff --git a/moto/servicequotas/responses.py b/moto/servicequotas/responses.py index 40442e4e6..eb4975a16 100644 --- a/moto/servicequotas/responses.py +++ b/moto/servicequotas/responses.py @@ -2,7 +2,8 @@ import json from moto.core.responses import BaseResponse -from .models import servicequotas_backends, ServiceQuotasBackend + +from .models import ServiceQuotasBackend, servicequotas_backends class ServiceQuotasResponse(BaseResponse): diff --git a/moto/ses/__init__.py b/moto/ses/__init__.py index 20de2f5aa..e0e64559b 100644 --- a/moto/ses/__init__.py +++ b/moto/ses/__init__.py @@ -1,4 +1,4 @@ -from .models import ses_backends from ..core.models import base_decorator +from .models import ses_backends mock_ses = base_decorator(ses_backends) diff --git a/moto/ses/models.py b/moto/ses/models.py index f40c853fe..06d0be9f8 100644 --- a/moto/ses/models.py +++ b/moto/ses/models.py @@ -1,33 +1,34 @@ -import json -import email import datetime -from email.mime.base import MIMEBase -from email.utils import formataddr, getaddresses, parseaddr -from email.mime.multipart import MIMEMultipart +import email +import json from email.encoders import encode_7or8bit +from email.mime.base import MIMEBase +from email.mime.multipart import MIMEMultipart +from email.utils import formataddr, getaddresses, parseaddr from typing import Any, Dict, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import utcnow from moto.sns.models import sns_backends + from .exceptions import ( - MessageRejectedError, + ConfigurationSetAlreadyExists, ConfigurationSetDoesNotExist, EventDestinationAlreadyExists, - TemplateNameAlreadyExists, - ValidationError, InvalidParameterValue, InvalidRenderingParameterException, - TemplateDoesNotExist, - RuleDoesNotExist, - RuleSetNameAlreadyExists, - RuleSetDoesNotExist, + MessageRejectedError, RuleAlreadyExists, - ConfigurationSetAlreadyExists, + RuleDoesNotExist, + RuleSetDoesNotExist, + RuleSetNameAlreadyExists, + TemplateDoesNotExist, + TemplateNameAlreadyExists, + ValidationError, ) +from .feedback import BOUNCE, COMMON_MAIL, COMPLAINT, DELIVERY from .template import parse_template from .utils import get_random_message_id, is_valid_address -from .feedback import COMMON_MAIL, BOUNCE, COMPLAINT, DELIVERY RECIPIENT_LIMIT = 50 diff --git a/moto/ses/responses.py b/moto/ses/responses.py index 4d35dedb6..a16b2460c 100644 --- a/moto/ses/responses.py +++ b/moto/ses/responses.py @@ -3,8 +3,9 @@ from typing import Any, Dict, List from moto.core.responses import BaseResponse from moto.core.utils import utcnow + from .exceptions import ValidationError -from .models import ses_backends, SESBackend +from .models import SESBackend, ses_backends class EmailResponse(BaseResponse): diff --git a/moto/ses/template.py b/moto/ses/template.py index 987dc9fb9..61f686abd 100644 --- a/moto/ses/template.py +++ b/moto/ses/template.py @@ -1,8 +1,9 @@ from typing import Any, Dict, Optional, Type -from .exceptions import MissingRenderingAttributeException from moto.utilities.tokenizer import GenericTokenizer +from .exceptions import MissingRenderingAttributeException + class BlockProcessor: def __init__( diff --git a/moto/ses/utils.py b/moto/ses/utils.py index 0f28cba3b..4314a4c93 100644 --- a/moto/ses/utils.py +++ b/moto/ses/utils.py @@ -1,7 +1,7 @@ import string +from email.utils import parseaddr from typing import Optional -from email.utils import parseaddr from moto.moto_api._internal import mock_random as random diff --git a/moto/sesv2/__init__.py b/moto/sesv2/__init__.py index ce12d13ff..b59780cc1 100644 --- a/moto/sesv2/__init__.py +++ b/moto/sesv2/__init__.py @@ -1,5 +1,5 @@ """sesv2 module initialization; sets value for base decorator.""" -from .models import sesv2_backends from ..core.models import base_decorator +from .models import sesv2_backends mock_sesv2 = base_decorator(sesv2_backends) diff --git a/moto/sesv2/models.py b/moto/sesv2/models.py index 465199d64..489f687f6 100644 --- a/moto/sesv2/models.py +++ b/moto/sesv2/models.py @@ -1,11 +1,13 @@ """SESV2Backend class with methods for supported APIs.""" +from typing import Any, Dict, List + from moto.core import BackendDict, BaseBackend, BaseModel -from ..ses.models import ses_backends, Message, RawMessage -from typing import Dict, List, Any -from .exceptions import NotFoundException from moto.core.utils import iso_8601_datetime_with_milliseconds +from ..ses.models import Message, RawMessage, ses_backends +from .exceptions import NotFoundException + class Contact(BaseModel): def __init__( diff --git a/moto/sesv2/responses.py b/moto/sesv2/responses.py index 775d4ad1d..d37b8001c 100644 --- a/moto/sesv2/responses.py +++ b/moto/sesv2/responses.py @@ -1,14 +1,14 @@ """Handles incoming sesv2 requests, invokes methods, returns responses.""" import base64 import json - -from moto.core.responses import BaseResponse -from .models import sesv2_backends -from ..ses.responses import SEND_EMAIL_RESPONSE -from .models import SESV2Backend from typing import List from urllib.parse import unquote +from moto.core.responses import BaseResponse + +from ..ses.responses import SEND_EMAIL_RESPONSE +from .models import SESV2Backend, sesv2_backends + class SESV2Response(BaseResponse): """Handler for SESV2 requests and responses.""" diff --git a/moto/settings.py b/moto/settings.py index d93e58e87..ed85efcfe 100644 --- a/moto/settings.py +++ b/moto/settings.py @@ -1,7 +1,6 @@ import json import os import pathlib - from functools import lru_cache from typing import List, Optional diff --git a/moto/signer/__init__.py b/moto/signer/__init__.py index 2972ffddf..a676e064d 100644 --- a/moto/signer/__init__.py +++ b/moto/signer/__init__.py @@ -1,5 +1,5 @@ """signer module initialization; sets value for base decorator.""" -from .models import signer_backends from ..core.models import base_decorator +from .models import signer_backends mock_signer = base_decorator(signer_backends) diff --git a/moto/signer/models.py b/moto/signer/models.py index 6d6e69bec..d426e20ae 100644 --- a/moto/signer/models.py +++ b/moto/signer/models.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.moto_api._internal import mock_random from moto.utilities.tagging_service import TaggingService diff --git a/moto/signer/responses.py b/moto/signer/responses.py index 143209290..9ac758325 100644 --- a/moto/signer/responses.py +++ b/moto/signer/responses.py @@ -4,7 +4,8 @@ from typing import Any from urllib.parse import unquote from moto.core.responses import BaseResponse -from .models import signer_backends, SignerBackend + +from .models import SignerBackend, signer_backends class SignerResponse(BaseResponse): diff --git a/moto/sns/__init__.py b/moto/sns/__init__.py index e3dbba6e3..eb729f1f6 100644 --- a/moto/sns/__init__.py +++ b/moto/sns/__init__.py @@ -1,4 +1,4 @@ -from .models import sns_backends from ..core.models import base_decorator +from .models import sns_backends mock_sns = base_decorator(sns_backends) diff --git a/moto/sns/exceptions.py b/moto/sns/exceptions.py index 807f0b717..770139005 100644 --- a/moto/sns/exceptions.py +++ b/moto/sns/exceptions.py @@ -1,4 +1,5 @@ from typing import Any, Optional + from moto.core.exceptions import RESTError diff --git a/moto/sns/models.py b/moto/sns/models.py index 4506f2bb2..e4a038977 100644 --- a/moto/sns/models.py +++ b/moto/sns/models.py @@ -1,40 +1,40 @@ import contextlib import json -import requests import re - from collections import OrderedDict -from typing import Any, Dict, List, Iterable, Optional, Tuple, Set +from typing import Any, Dict, Iterable, List, Optional, Set, Tuple -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel +import requests + +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.core.utils import ( - iso_8601_datetime_with_milliseconds, camelcase_to_underscores, + iso_8601_datetime_with_milliseconds, ) from moto.moto_api._internal import mock_random from moto.sqs import sqs_backends from moto.sqs.exceptions import MissingParameter +from moto.utilities.arns import parse_arn from .exceptions import ( - SNSNotFoundError, - TopicNotFound, + BatchEntryIdsNotDistinct, DuplicateSnsEndpointError, + InternalError, + InvalidParameterValue, + ResourceNotFoundError, SnsEndpointDisabled, SNSInvalidParameter, - InvalidParameterValue, - InternalError, - ResourceNotFoundError, + SNSNotFoundError, TagLimitExceededError, TooManyEntriesInBatchRequest, - BatchEntryIdsNotDistinct, + TopicNotFound, ) from .utils import ( - make_arn_for_topic, - make_arn_for_subscription, - is_e164, FilterPolicyMatcher, + is_e164, + make_arn_for_subscription, + make_arn_for_topic, ) -from moto.utilities.arns import parse_arn DEFAULT_PAGE_SIZE = 100 MAXIMUM_MESSAGE_LENGTH = 262144 # 256 KiB diff --git a/moto/sns/responses.py b/moto/sns/responses.py index 76d9fc37e..3eb0352de 100644 --- a/moto/sns/responses.py +++ b/moto/sns/responses.py @@ -5,8 +5,9 @@ from typing import Any, Dict, Tuple, Union from moto.core.responses import BaseResponse from moto.core.utils import camelcase_to_underscores -from .models import sns_backends, SNSBackend + from .exceptions import InvalidParameterValue, SNSNotFoundError +from .models import SNSBackend, sns_backends from .utils import is_e164 diff --git a/moto/sns/utils.py b/moto/sns/utils.py index 26a229e7e..901498416 100644 --- a/moto/sns/utils.py +++ b/moto/sns/utils.py @@ -1,7 +1,8 @@ -import re -from moto.moto_api._internal import mock_random -from typing import Any, Dict, List, Iterable, Optional, Tuple, Union, Callable import json +import re +from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union + +from moto.moto_api._internal import mock_random E164_REGEX = re.compile(r"^\+?[1-9]\d{1,14}$") diff --git a/moto/sqs/__init__.py b/moto/sqs/__init__.py index 5ea59d91b..d4c35ecc1 100644 --- a/moto/sqs/__init__.py +++ b/moto/sqs/__init__.py @@ -1,4 +1,4 @@ -from .models import sqs_backends from ..core.models import base_decorator +from .models import sqs_backends mock_sqs = base_decorator(sqs_backends) diff --git a/moto/sqs/models.py b/moto/sqs/models.py index 05d03e583..37e241bf3 100644 --- a/moto/sqs/models.py +++ b/moto/sqs/models.py @@ -3,41 +3,41 @@ import hashlib import json import re import string - import struct from copy import deepcopy -from typing import Any, Dict, List, Optional, Tuple, Set, TYPE_CHECKING from threading import Condition +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set, Tuple from urllib.parse import ParseResult from xml.sax.saxutils import escape +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.core.exceptions import RESTError -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel from moto.core.utils import ( camelcase_to_underscores, + tags_from_cloudformation_tags_list, unix_time, unix_time_millis, - tags_from_cloudformation_tags_list, ) from moto.moto_api._internal import mock_random as random from moto.utilities.utils import md5_hash + from .constants import MAXIMUM_VISIBILITY_TIMEOUT -from .utils import generate_receipt_handle from .exceptions import ( - MessageAttributesInvalid, - QueueDoesNotExist, - QueueAlreadyExists, - ReceiptHandleIsInvalid, - InvalidBatchEntryId, - BatchRequestTooLong, BatchEntryIdsNotDistinct, - TooManyEntriesInBatchRequest, + BatchRequestTooLong, InvalidAttributeName, + InvalidAttributeValue, + InvalidBatchEntryId, InvalidParameterValue, + MessageAttributesInvalid, MissingParameter, OverLimit, - InvalidAttributeValue, + QueueAlreadyExists, + QueueDoesNotExist, + ReceiptHandleIsInvalid, + TooManyEntriesInBatchRequest, ) +from .utils import generate_receipt_handle if TYPE_CHECKING: from moto.awslambda.models import EventSourceMapping diff --git a/moto/sqs/responses.py b/moto/sqs/responses.py index 2dc827f3a..b2a0cf1dc 100644 --- a/moto/sqs/responses.py +++ b/moto/sqs/responses.py @@ -2,18 +2,18 @@ import json import re from functools import wraps from typing import Any, Callable, Dict, Optional, Union +from urllib.parse import urlparse from moto.core.common_types import TYPE_RESPONSE from moto.core.exceptions import JsonRESTError from moto.core.responses import BaseResponse from moto.core.utils import ( - underscores_to_camelcase, camelcase_to_pascal, camelcase_to_underscores, + underscores_to_camelcase, ) from moto.utilities.aws_headers import amz_crc32, amzn_request_id from moto.utilities.constants import JSON_TYPES -from urllib.parse import urlparse from .constants import ( DEFAULT_RECEIVED_MESSAGES, @@ -21,15 +21,15 @@ from .constants import ( MAXIMUM_VISIBILITY_TIMEOUT, ) from .exceptions import ( - RESTError, + BatchEntryIdsNotDistinct, EmptyBatchRequest, InvalidAttributeName, - BatchEntryIdsNotDistinct, + RESTError, ) -from .models import sqs_backends, SQSBackend +from .models import SQSBackend, sqs_backends from .utils import ( - parse_message_attributes, extract_input_message_attributes, + parse_message_attributes, validate_message_attributes, ) diff --git a/moto/sqs/utils.py b/moto/sqs/utils.py index 7f1d777d6..ed3544c5e 100644 --- a/moto/sqs/utils.py +++ b/moto/sqs/utils.py @@ -2,6 +2,7 @@ import string from typing import Any, Dict, List from moto.moto_api._internal import mock_random as random + from .exceptions import MessageAttributesInvalid diff --git a/moto/ssm/__init__.py b/moto/ssm/__init__.py index 4d9b60c48..baef803d7 100644 --- a/moto/ssm/__init__.py +++ b/moto/ssm/__init__.py @@ -1,4 +1,4 @@ -from .models import ssm_backends from ..core.models import base_decorator +from .models import ssm_backends mock_ssm = base_decorator(ssm_backends) diff --git a/moto/ssm/models.py b/moto/ssm/models.py index a650bf425..dcb0b1e50 100644 --- a/moto/ssm/models.py +++ b/moto/ssm/models.py @@ -1,48 +1,47 @@ +import datetime +import hashlib +import json import re -from dataclasses import dataclass -from typing import Any, Dict, List, Iterator, Optional, Tuple -from typing import DefaultDict - +import time from collections import defaultdict +from dataclasses import dataclass +from typing import Any, DefaultDict, Dict, Iterator, List, Optional, Tuple -from moto.core import BaseBackend, BackendDict, BaseModel, CloudFormationModel +import yaml + +from moto.core import BackendDict, BaseBackend, BaseModel, CloudFormationModel from moto.core.exceptions import RESTError from moto.core.utils import utcnow from moto.ec2 import ec2_backends +from moto.moto_api._internal import mock_random as random from moto.secretsmanager import secretsmanager_backends from moto.secretsmanager.exceptions import SecretsManagerClientError from moto.utilities.utils import load_resource -import datetime -import time -import json -import yaml -import hashlib -from moto.moto_api._internal import mock_random as random -from .utils import parameter_arn, convert_to_params from .exceptions import ( - ValidationException, - InvalidFilterValue, - InvalidFilterOption, - InvalidFilterKey, - ParameterVersionLabelLimitExceeded, - ParameterVersionNotFound, - ParameterNotFound, - DocumentAlreadyExists, - InvalidDocumentOperation, AccessDeniedException, + DocumentAlreadyExists, + DocumentPermissionLimit, + DuplicateDocumentContent, + DuplicateDocumentVersionName, InvalidDocument, InvalidDocumentContent, + InvalidDocumentOperation, InvalidDocumentVersion, - DuplicateDocumentVersionName, - DuplicateDocumentContent, - ParameterMaxVersionLimitExceeded, - DocumentPermissionLimit, + InvalidFilterKey, + InvalidFilterOption, + InvalidFilterValue, InvalidPermissionType, InvalidResourceId, InvalidResourceType, ParameterAlreadyExists, + ParameterMaxVersionLimitExceeded, + ParameterNotFound, + ParameterVersionLabelLimitExceeded, + ParameterVersionNotFound, + ValidationException, ) +from .utils import convert_to_params, parameter_arn class ParameterDict(DefaultDict[str, List["Parameter"]]): diff --git a/moto/ssm/responses.py b/moto/ssm/responses.py index 2d565a2c2..a3b5bcd41 100644 --- a/moto/ssm/responses.py +++ b/moto/ssm/responses.py @@ -2,8 +2,9 @@ import json from typing import Any, Dict, Tuple, Union from moto.core.responses import BaseResponse + from .exceptions import ValidationException -from .models import ssm_backends, SimpleSystemManagerBackend +from .models import SimpleSystemManagerBackend, ssm_backends class SimpleSystemManagerResponse(BaseResponse): diff --git a/moto/ssoadmin/__init__.py b/moto/ssoadmin/__init__.py index a6c002391..d6f5fe987 100644 --- a/moto/ssoadmin/__init__.py +++ b/moto/ssoadmin/__init__.py @@ -1,5 +1,5 @@ """ssoadmin module initialization; sets value for base decorator.""" -from .models import ssoadmin_backends from ..core.models import base_decorator +from .models import ssoadmin_backends mock_ssoadmin = base_decorator(ssoadmin_backends) diff --git a/moto/ssoadmin/models.py b/moto/ssoadmin/models.py index 5b4592961..3bb69e19a 100644 --- a/moto/ssoadmin/models.py +++ b/moto/ssoadmin/models.py @@ -1,9 +1,10 @@ from typing import Any, Dict, List -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import unix_time from moto.moto_api._internal import mock_random as random from moto.utilities.paginator import paginate + from .exceptions import ResourceNotFound from .utils import PAGINATION_MODEL diff --git a/moto/ssoadmin/responses.py b/moto/ssoadmin/responses.py index 7276a71ce..8a684233e 100644 --- a/moto/ssoadmin/responses.py +++ b/moto/ssoadmin/responses.py @@ -3,7 +3,7 @@ import json from moto.core.responses import BaseResponse from moto.moto_api._internal import mock_random -from .models import ssoadmin_backends, SSOAdminBackend +from .models import SSOAdminBackend, ssoadmin_backends class SSOAdminResponse(BaseResponse): diff --git a/moto/stepfunctions/__init__.py b/moto/stepfunctions/__init__.py index cd4bf405a..7181c73d3 100644 --- a/moto/stepfunctions/__init__.py +++ b/moto/stepfunctions/__init__.py @@ -1,4 +1,4 @@ -from .models import stepfunction_backends from ..core.models import base_decorator +from .models import stepfunction_backends mock_stepfunctions = base_decorator(stepfunction_backends) diff --git a/moto/stepfunctions/models.py b/moto/stepfunctions/models.py index bcabad663..c37e7e0a6 100644 --- a/moto/stepfunctions/models.py +++ b/moto/stepfunctions/models.py @@ -1,25 +1,27 @@ import json import re from datetime import datetime -from dateutil.tz import tzlocal -from typing import Any, Dict, List, Iterable, Optional, Pattern +from typing import Any, Dict, Iterable, List, Optional, Pattern -from moto.core import BaseBackend, BackendDict, CloudFormationModel +from dateutil.tz import tzlocal + +from moto import settings +from moto.core import BackendDict, BaseBackend, CloudFormationModel from moto.core.utils import iso_8601_datetime_with_milliseconds from moto.moto_api._internal import mock_random +from moto.utilities.paginator import paginate + from .exceptions import ( ExecutionAlreadyExists, ExecutionDoesNotExist, InvalidArn, InvalidExecutionInput, InvalidName, + NameTooLongException, ResourceNotFound, StateMachineDoesNotExist, - NameTooLongException, ) -from .utils import api_to_cfn_tags, cfn_to_api_tags, PAGINATION_MODEL -from moto import settings -from moto.utilities.paginator import paginate +from .utils import PAGINATION_MODEL, api_to_cfn_tags, cfn_to_api_tags class StateMachine(CloudFormationModel): diff --git a/moto/stepfunctions/responses.py b/moto/stepfunctions/responses.py index c6685aa19..997188c84 100644 --- a/moto/stepfunctions/responses.py +++ b/moto/stepfunctions/responses.py @@ -3,7 +3,8 @@ import json from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse from moto.utilities.aws_headers import amzn_request_id -from .models import stepfunction_backends, StepFunctionBackend + +from .models import StepFunctionBackend, stepfunction_backends class StepFunctionResponse(BaseResponse): diff --git a/moto/stepfunctions/utils.py b/moto/stepfunctions/utils.py index db9aa1f36..bf3e3e89d 100644 --- a/moto/stepfunctions/utils.py +++ b/moto/stepfunctions/utils.py @@ -1,6 +1,5 @@ from typing import Dict, List - PAGINATION_MODEL = { "list_executions": { "input_token": "next_token", diff --git a/moto/sts/__init__.py b/moto/sts/__init__.py index 301cecc41..fa08e2649 100644 --- a/moto/sts/__init__.py +++ b/moto/sts/__init__.py @@ -1,4 +1,4 @@ -from .models import sts_backends from ..core.models import base_decorator +from .models import sts_backends mock_sts = base_decorator(sts_backends) diff --git a/moto/sts/exceptions.py b/moto/sts/exceptions.py index 6f136af2d..38148f019 100644 --- a/moto/sts/exceptions.py +++ b/moto/sts/exceptions.py @@ -1,4 +1,5 @@ from typing import Any + from moto.core.exceptions import RESTError diff --git a/moto/sts/models.py b/moto/sts/models.py index b465b0039..5d17cdadc 100644 --- a/moto/sts/models.py +++ b/moto/sts/models.py @@ -1,16 +1,17 @@ -from base64 import b64decode -from typing import Any, Dict, List, Optional, Tuple import datetime import re +from base64 import b64decode +from typing import Any, Dict, List, Optional, Tuple + import xmltodict -from moto.core import BaseBackend, BaseModel, BackendDict +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import iso_8601_datetime_with_milliseconds, utcnow -from moto.iam.models import iam_backends, AccessKey +from moto.iam.models import AccessKey, iam_backends from moto.sts.utils import ( - random_session_token, DEFAULT_STS_SESSION_DURATION, random_assumed_role_id, + random_session_token, ) diff --git a/moto/sts/responses.py b/moto/sts/responses.py index 7e95e6535..f597aeb51 100644 --- a/moto/sts/responses.py +++ b/moto/sts/responses.py @@ -1,6 +1,7 @@ from moto.core.responses import BaseResponse + from .exceptions import STSValidationError -from .models import sts_backends, STSBackend +from .models import STSBackend, sts_backends MAX_FEDERATION_TOKEN_POLICY_LENGTH = 2048 diff --git a/moto/sts/utils.py b/moto/sts/utils.py index c2149146f..35130f89e 100644 --- a/moto/sts/utils.py +++ b/moto/sts/utils.py @@ -1,6 +1,7 @@ import base64 import os import string + from moto.moto_api._internal import mock_random as random ACCOUNT_SPECIFIC_ACCESS_KEY_PREFIX = "8NWMTLYQ" diff --git a/moto/support/__init__.py b/moto/support/__init__.py index 560832ad6..082fda2df 100644 --- a/moto/support/__init__.py +++ b/moto/support/__init__.py @@ -1,4 +1,4 @@ -from .models import support_backends from ..core.models import base_decorator +from .models import support_backends mock_support = base_decorator(support_backends) diff --git a/moto/support/models.py b/moto/support/models.py index 852e94a8c..9b3c81ce9 100644 --- a/moto/support/models.py +++ b/moto/support/models.py @@ -1,11 +1,11 @@ -from moto.core import BaseBackend, BackendDict -from moto.moto_api import state_manager -from moto.moto_api._internal.managed_state_model import ManagedState -from moto.moto_api._internal import mock_random as random -from moto.utilities.utils import load_resource import datetime from typing import Any, Dict, List, Optional +from moto.core import BackendDict, BaseBackend +from moto.moto_api import state_manager +from moto.moto_api._internal import mock_random as random +from moto.moto_api._internal.managed_state_model import ManagedState +from moto.utilities.utils import load_resource checks_json = "resources/describe_trusted_advisor_checks.json" ADVISOR_CHECKS = load_resource(__name__, checks_json) diff --git a/moto/support/responses.py b/moto/support/responses.py index fc5507cfd..eb9118d19 100644 --- a/moto/support/responses.py +++ b/moto/support/responses.py @@ -1,7 +1,9 @@ -from moto.core.responses import BaseResponse -from .models import support_backends, SupportBackend import json +from moto.core.responses import BaseResponse + +from .models import SupportBackend, support_backends + class SupportResponse(BaseResponse): def __init__(self) -> None: diff --git a/moto/swf/__init__.py b/moto/swf/__init__.py index b6b843ed8..79339bdf5 100644 --- a/moto/swf/__init__.py +++ b/moto/swf/__init__.py @@ -1,4 +1,4 @@ -from .models import swf_backends from ..core.models import base_decorator +from .models import swf_backends mock_swf = base_decorator(swf_backends) diff --git a/moto/swf/exceptions.py b/moto/swf/exceptions.py index 4e3c9a503..dc8bc7086 100644 --- a/moto/swf/exceptions.py +++ b/moto/swf/exceptions.py @@ -1,4 +1,5 @@ -from typing import Any, Dict, List, Optional, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Dict, List, Optional + from moto.core.exceptions import JsonRESTError if TYPE_CHECKING: diff --git a/moto/swf/models/__init__.py b/moto/swf/models/__init__.py index 4eb499e51..694310f43 100644 --- a/moto/swf/models/__init__.py +++ b/moto/swf/models/__init__.py @@ -1,12 +1,14 @@ +from time import sleep from typing import Any, Dict, List, Optional -from moto.core import BaseBackend, BackendDict + +from moto.core import BackendDict, BaseBackend from ..exceptions import ( - SWFUnknownResourceFault, SWFDomainAlreadyExistsFault, SWFDomainDeprecatedFault, SWFTypeAlreadyExistsFault, SWFTypeDeprecatedFault, + SWFUnknownResourceFault, SWFValidationException, ) from .activity_task import ActivityTask # noqa @@ -17,9 +19,8 @@ from .generic_type import GenericType, TGenericType # noqa from .history_event import HistoryEvent # noqa from .timeout import Timeout # noqa from .timer import Timer # noqa -from .workflow_type import WorkflowType # noqa from .workflow_execution import WorkflowExecution # noqa -from time import sleep +from .workflow_type import WorkflowType # noqa KNOWN_SWF_TYPES = {"activity": ActivityType, "workflow": WorkflowType} diff --git a/moto/swf/models/activity_task.py b/moto/swf/models/activity_task.py index 2ef3b52d6..c24b92360 100644 --- a/moto/swf/models/activity_task.py +++ b/moto/swf/models/activity_task.py @@ -1,10 +1,10 @@ -from typing import Any, Dict, Optional, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Dict, Optional from moto.core import BaseModel from moto.core.utils import unix_time, utcnow from moto.moto_api._internal import mock_random -from ..exceptions import SWFWorkflowExecutionClosedError +from ..exceptions import SWFWorkflowExecutionClosedError from .timeout import Timeout if TYPE_CHECKING: diff --git a/moto/swf/models/activity_type.py b/moto/swf/models/activity_type.py index fcee00fb9..5a6cacb1b 100644 --- a/moto/swf/models/activity_type.py +++ b/moto/swf/models/activity_type.py @@ -1,4 +1,5 @@ from typing import List + from .generic_type import GenericType diff --git a/moto/swf/models/decision_task.py b/moto/swf/models/decision_task.py index d41a189cf..bb7cb6ed9 100644 --- a/moto/swf/models/decision_task.py +++ b/moto/swf/models/decision_task.py @@ -1,10 +1,10 @@ -from typing import Any, Dict, Optional, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Dict, Optional from moto.core import BaseModel from moto.core.utils import unix_time, utcnow from moto.moto_api._internal import mock_random -from ..exceptions import SWFWorkflowExecutionClosedError +from ..exceptions import SWFWorkflowExecutionClosedError from .timeout import Timeout if TYPE_CHECKING: diff --git a/moto/swf/models/domain.py b/moto/swf/models/domain.py index bfc772902..ae368069c 100644 --- a/moto/swf/models/domain.py +++ b/moto/swf/models/domain.py @@ -1,7 +1,8 @@ from collections import defaultdict -from typing import Any, Dict, List, Optional, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Dict, List, Optional from moto.core import BaseModel + from ..exceptions import ( SWFUnknownResourceFault, SWFWorkflowExecutionAlreadyStartedFault, diff --git a/moto/swf/models/generic_type.py b/moto/swf/models/generic_type.py index ac97b1976..681956b4f 100644 --- a/moto/swf/models/generic_type.py +++ b/moto/swf/models/generic_type.py @@ -1,4 +1,5 @@ from typing import Any, Dict, List, TypeVar + from moto.core import BaseModel from moto.core.utils import camelcase_to_underscores diff --git a/moto/swf/models/history_event.py b/moto/swf/models/history_event.py index 3d42c41d8..12122de7e 100644 --- a/moto/swf/models/history_event.py +++ b/moto/swf/models/history_event.py @@ -1,10 +1,10 @@ from typing import Any, Dict, Optional + from moto.core import BaseModel from moto.core.utils import underscores_to_camelcase, unix_time from ..utils import decapitalize - # We keep track of which history event types we support # so that we'll be able to catch specific formatting # for new events if needed. diff --git a/moto/swf/models/timeout.py b/moto/swf/models/timeout.py index 7e1c42e41..de86fe38c 100644 --- a/moto/swf/models/timeout.py +++ b/moto/swf/models/timeout.py @@ -1,4 +1,5 @@ from typing import Any + from moto.core import BaseModel from moto.core.utils import unix_time diff --git a/moto/swf/models/timer.py b/moto/swf/models/timer.py index 780e58992..1634432ce 100644 --- a/moto/swf/models/timer.py +++ b/moto/swf/models/timer.py @@ -1,4 +1,5 @@ from threading import Timer as ThreadingTimer + from moto.core import BaseModel diff --git a/moto/swf/models/workflow_execution.py b/moto/swf/models/workflow_execution.py index 68193636a..fb01a48bb 100644 --- a/moto/swf/models/workflow_execution.py +++ b/moto/swf/models/workflow_execution.py @@ -1,4 +1,5 @@ -from threading import Timer as ThreadingTimer, Lock +from threading import Lock +from threading import Timer as ThreadingTimer from typing import Any, Dict, Iterable, List, Optional from moto.core import BaseModel @@ -7,9 +8,9 @@ from moto.moto_api._internal import mock_random from ..constants import DECISIONS_FIELDS from ..exceptions import ( + SWFDecisionValidationException, SWFDefaultUndefinedFault, SWFValidationException, - SWFDecisionValidationException, ) from ..utils import decapitalize from .activity_task import ActivityTask diff --git a/moto/swf/models/workflow_type.py b/moto/swf/models/workflow_type.py index 4427f7f03..2807cfef3 100644 --- a/moto/swf/models/workflow_type.py +++ b/moto/swf/models/workflow_type.py @@ -1,4 +1,5 @@ from typing import List + from .generic_type import GenericType diff --git a/moto/swf/responses.py b/moto/swf/responses.py index c856d6cbb..493f98941 100644 --- a/moto/swf/responses.py +++ b/moto/swf/responses.py @@ -4,7 +4,7 @@ from typing import Any, List from moto.core.responses import BaseResponse from .exceptions import SWFSerializationException, SWFValidationException -from .models import swf_backends, SWFBackend, GenericType +from .models import GenericType, SWFBackend, swf_backends class SWFResponse(BaseResponse): diff --git a/moto/textract/__init__.py b/moto/textract/__init__.py index 4bce9832b..a516837af 100644 --- a/moto/textract/__init__.py +++ b/moto/textract/__init__.py @@ -1,5 +1,5 @@ """textract module initialization; sets value for base decorator.""" -from .models import textract_backends from ..core.models import base_decorator +from .models import textract_backends mock_textract = base_decorator(textract_backends) diff --git a/moto/textract/models.py b/moto/textract/models.py index 876acc2f5..361a2e543 100644 --- a/moto/textract/models.py +++ b/moto/textract/models.py @@ -1,10 +1,10 @@ from collections import defaultdict from typing import Any, Dict, List -from moto.core import BaseBackend, BackendDict, BaseModel +from moto.core import BackendDict, BaseBackend, BaseModel from moto.moto_api._internal import mock_random -from .exceptions import InvalidParameterException, InvalidJobIdException +from .exceptions import InvalidJobIdException, InvalidParameterException class TextractJobStatus: diff --git a/moto/textract/responses.py b/moto/textract/responses.py index df72a5ded..d723c1f8e 100644 --- a/moto/textract/responses.py +++ b/moto/textract/responses.py @@ -2,7 +2,8 @@ import json from moto.core.responses import BaseResponse -from .models import textract_backends, TextractBackend + +from .models import TextractBackend, textract_backends class TextractResponse(BaseResponse): diff --git a/moto/timestreamwrite/__init__.py b/moto/timestreamwrite/__init__.py index f8b12f3bf..9bf046209 100644 --- a/moto/timestreamwrite/__init__.py +++ b/moto/timestreamwrite/__init__.py @@ -1,4 +1,4 @@ -from .models import timestreamwrite_backends from ..core.models import base_decorator +from .models import timestreamwrite_backends mock_timestreamwrite = base_decorator(timestreamwrite_backends) diff --git a/moto/timestreamwrite/models.py b/moto/timestreamwrite/models.py index 19669164f..6d6a7a665 100644 --- a/moto/timestreamwrite/models.py +++ b/moto/timestreamwrite/models.py @@ -1,7 +1,9 @@ -from typing import Any, Dict, List, Iterable -from moto.core import BaseBackend, BackendDict, BaseModel +from typing import Any, Dict, Iterable, List + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import unix_time from moto.utilities.tagging_service import TaggingService + from .exceptions import ResourceNotFound diff --git a/moto/timestreamwrite/responses.py b/moto/timestreamwrite/responses.py index ead96206a..179140d20 100644 --- a/moto/timestreamwrite/responses.py +++ b/moto/timestreamwrite/responses.py @@ -1,7 +1,8 @@ import json from moto.core.responses import BaseResponse -from .models import timestreamwrite_backends, TimestreamWriteBackend + +from .models import TimestreamWriteBackend, timestreamwrite_backends class TimestreamWriteResponse(BaseResponse): diff --git a/moto/transcribe/__init__.py b/moto/transcribe/__init__.py index 0cde03003..885f41a37 100644 --- a/moto/transcribe/__init__.py +++ b/moto/transcribe/__init__.py @@ -1,5 +1,5 @@ -from .models import transcribe_backends from ..core.models import base_decorator +from .models import transcribe_backends transcribe_backend = transcribe_backends["us-east-1"] mock_transcribe = base_decorator(transcribe_backends) diff --git a/moto/transcribe/models.py b/moto/transcribe/models.py index 6442c0eb9..70f12d936 100644 --- a/moto/transcribe/models.py +++ b/moto/transcribe/models.py @@ -1,11 +1,13 @@ import re from datetime import datetime, timedelta from typing import Any, Dict, List, Optional -from moto.core import BaseBackend, BackendDict, BaseModel + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.moto_api import state_manager from moto.moto_api._internal import mock_random from moto.moto_api._internal.managed_state_model import ManagedState -from .exceptions import ConflictException, BadRequestException + +from .exceptions import BadRequestException, ConflictException class BaseObject(BaseModel): diff --git a/moto/transcribe/responses.py b/moto/transcribe/responses.py index 593837c75..e8e31876f 100644 --- a/moto/transcribe/responses.py +++ b/moto/transcribe/responses.py @@ -2,7 +2,8 @@ import json from moto.core.responses import BaseResponse from moto.utilities.aws_headers import amzn_request_id -from .models import transcribe_backends, TranscribeBackend + +from .models import TranscribeBackend, transcribe_backends class TranscribeResponse(BaseResponse): diff --git a/moto/utilities/aws_headers.py b/moto/utilities/aws_headers.py index 5f7350e2b..c63a3f73e 100644 --- a/moto/utilities/aws_headers.py +++ b/moto/utilities/aws_headers.py @@ -1,5 +1,5 @@ from functools import wraps -from typing import Any, Callable, Dict, TypeVar, Optional, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, TypeVar if TYPE_CHECKING: from typing_extensions import Protocol @@ -8,8 +8,8 @@ else: import binascii import re -from moto.moto_api._internal import mock_random as random +from moto.moto_api._internal import mock_random as random TypeDec = TypeVar("TypeDec", bound=Callable[..., Any]) diff --git a/moto/utilities/docker_utilities.py b/moto/utilities/docker_utilities.py index 9a0f28087..acaf3088e 100644 --- a/moto/utilities/docker_utilities.py +++ b/moto/utilities/docker_utilities.py @@ -1,6 +1,7 @@ import functools +from typing import TYPE_CHECKING, Any, Tuple + import requests.adapters -from typing import Any, Tuple, TYPE_CHECKING from moto import settings diff --git a/moto/utilities/paginator.py b/moto/utilities/paginator.py index 43c5beb19..2283d269d 100644 --- a/moto/utilities/paginator.py +++ b/moto/utilities/paginator.py @@ -1,14 +1,12 @@ import inspect - from copy import deepcopy from functools import wraps -from typing import Any, Dict, List, Tuple, Optional +from typing import Any, Dict, List, Optional, Tuple from botocore.paginate import TokenDecoder, TokenEncoder from moto.core.exceptions import InvalidToken - # This should be typed using ParamSpec # https://stackoverflow.com/a/70591060/13245310 # This currently does not work for our usecase diff --git a/moto/utilities/utils.py b/moto/utilities/utils.py index 66f0c8312..3bfa777f7 100644 --- a/moto/utilities/utils.py +++ b/moto/utilities/utils.py @@ -1,8 +1,7 @@ -import json import hashlib +import json import pkgutil - -from typing import Any, Dict, Iterator, List, TypeVar, Tuple, Optional, MutableMapping +from typing import Any, Dict, Iterator, List, MutableMapping, Optional, Tuple, TypeVar def str2bool(v: Any) -> Optional[bool]: diff --git a/moto/wafv2/__init__.py b/moto/wafv2/__init__.py index 5c984e3cc..edb4bdb69 100644 --- a/moto/wafv2/__init__.py +++ b/moto/wafv2/__init__.py @@ -1,5 +1,5 @@ -from .models import wafv2_backends from ..core.models import base_decorator +from .models import wafv2_backends wafv2_backend = wafv2_backends["us-east-1"] mock_wafv2 = base_decorator(wafv2_backends) diff --git a/moto/wafv2/models.py b/moto/wafv2/models.py index f420c7a80..6e02e6639 100644 --- a/moto/wafv2/models.py +++ b/moto/wafv2/models.py @@ -1,13 +1,14 @@ import re -from typing import Any, Dict, List, Optional, TYPE_CHECKING -from moto.core import BaseBackend, BackendDict, BaseModel +from collections import OrderedDict +from typing import TYPE_CHECKING, Any, Dict, List, Optional -from .utils import make_arn_for_wacl -from .exceptions import WAFV2DuplicateItemException, WAFNonexistentItemException +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.utils import iso_8601_datetime_with_milliseconds from moto.moto_api._internal import mock_random from moto.utilities.tagging_service import TaggingService -from collections import OrderedDict + +from .exceptions import WAFNonexistentItemException, WAFV2DuplicateItemException +from .utils import make_arn_for_wacl if TYPE_CHECKING: from moto.apigateway.models import Stage diff --git a/moto/wafv2/responses.py b/moto/wafv2/responses.py index bcaaf92dd..62b3dc93e 100644 --- a/moto/wafv2/responses.py +++ b/moto/wafv2/responses.py @@ -1,8 +1,10 @@ import json + from moto.core.common_types import TYPE_RESPONSE from moto.core.responses import BaseResponse from moto.utilities.aws_headers import amzn_request_id -from .models import GLOBAL_REGION, wafv2_backends, WAFV2Backend + +from .models import GLOBAL_REGION, WAFV2Backend, wafv2_backends class WAFV2Response(BaseResponse): diff --git a/moto/xray/__init__.py b/moto/xray/__init__.py index e47d7642b..2ef57babd 100644 --- a/moto/xray/__init__.py +++ b/moto/xray/__init__.py @@ -1,6 +1,6 @@ -from .models import xray_backends from ..core.models import base_decorator from .mock_client import MockXrayClient, XRaySegment # noqa +from .models import xray_backends xray_backend = xray_backends["us-east-1"] mock_xray = base_decorator(xray_backends) diff --git a/moto/xray/mock_client.py b/moto/xray/mock_client.py index ffad067ea..1521246b2 100644 --- a/moto/xray/mock_client.py +++ b/moto/xray/mock_client.py @@ -1,10 +1,12 @@ import os from typing import Any -from moto.xray.models import xray_backends, XRayBackend + import aws_xray_sdk.core from aws_xray_sdk.core.context import Context as AWSContext from aws_xray_sdk.core.emitters.udp_emitter import UDPEmitter +from moto.xray.models import XRayBackend, xray_backends + class MockEmitter(UDPEmitter): # type: ignore """ diff --git a/moto/xray/models.py b/moto/xray/models.py index 76bee1dd9..8940e6855 100644 --- a/moto/xray/models.py +++ b/moto/xray/models.py @@ -1,10 +1,12 @@ import bisect import datetime +import json from collections import defaultdict from typing import Any, Dict, List, Optional, Tuple -import json -from moto.core import BaseBackend, BackendDict, BaseModel + +from moto.core import BackendDict, BaseBackend, BaseModel from moto.core.exceptions import AWSError + from .exceptions import BadSegmentException diff --git a/moto/xray/responses.py b/moto/xray/responses.py index 660e9559e..859eb9d98 100644 --- a/moto/xray/responses.py +++ b/moto/xray/responses.py @@ -1,13 +1,13 @@ -import json import datetime +import json from typing import Any, Dict, Tuple, Union - -from moto.core.responses import BaseResponse -from moto.core.exceptions import AWSError from urllib.parse import urlsplit -from .models import xray_backends, XRayBackend +from moto.core.exceptions import AWSError +from moto.core.responses import BaseResponse + from .exceptions import BadSegmentException +from .models import XRayBackend, xray_backends class XRayResponse(BaseResponse): diff --git a/ruff.toml b/ruff.toml index f419fc5d8..334e35f66 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1 +1,2 @@ ignore = ["E501"] +extend-select = ["I"] diff --git a/tests/__init__.py b/tests/__init__.py index db2939e1d..ff95f7c52 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,7 +1,6 @@ import logging import os - # Disable extra logging for tests logging.getLogger("boto").setLevel(logging.CRITICAL) logging.getLogger("boto3").setLevel(logging.CRITICAL) diff --git a/tests/terraformtests/get_tf_tests.py b/tests/terraformtests/get_tf_tests.py index 1acfaea59..3caaac72f 100644 --- a/tests/terraformtests/get_tf_tests.py +++ b/tests/terraformtests/get_tf_tests.py @@ -1,6 +1,7 @@ -import yaml import sys +import yaml + def print_test_names(service): with open("tests/terraformtests/terraform-tests.success.txt") as f: diff --git a/tests/test_acm/test_acm.py b/tests/test_acm/test_acm.py index a1f1d4036..14db902b6 100644 --- a/tests/test_acm/test_acm.py +++ b/tests/test_acm/test_acm.py @@ -1,7 +1,6 @@ -from moto.acm.models import AWS_ROOT_CA - import os import uuid +from unittest import SkipTest, mock import boto3 import pytest @@ -9,9 +8,10 @@ from botocore.exceptions import ClientError from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import serialization from freezegun import freeze_time + from moto import mock_acm, mock_elb, settings +from moto.acm.models import AWS_ROOT_CA from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from unittest import SkipTest, mock RESOURCE_FOLDER = os.path.join(os.path.dirname(__file__), "resources") diff --git a/tests/test_acmpca/test_acmpca.py b/tests/test_acmpca/test_acmpca.py index 443fe0a33..cdb3ed792 100644 --- a/tests/test_acmpca/test_acmpca.py +++ b/tests/test_acmpca/test_acmpca.py @@ -1,18 +1,19 @@ """Unit tests for acmpca-supported APIs.""" +import datetime + import boto3 +import cryptography.hazmat.primitives.asymmetric.rsa +import cryptography.x509 import pytest from botocore.exceptions import ClientError +from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives import hashes, serialization +from cryptography.x509 import NameOID + from moto import mock_acmpca from moto.core import DEFAULT_ACCOUNT_ID from moto.core.utils import utcnow -import datetime -import cryptography.x509 -from cryptography.x509 import NameOID -import cryptography.hazmat.primitives.asymmetric.rsa -from cryptography.hazmat.primitives import serialization, hashes -from cryptography.hazmat.backends import default_backend - # See our Development Tips on writing tests for hints on how to write good tests: # http://docs.getmoto.org/en/latest/docs/contributing/development_tips/tests.html diff --git a/tests/test_amp/test_amp_logging_config.py b/tests/test_amp/test_amp_logging_config.py index d1bf6cc56..583064fdf 100644 --- a/tests/test_amp/test_amp_logging_config.py +++ b/tests/test_amp/test_amp_logging_config.py @@ -1,5 +1,7 @@ -import boto3 import unittest + +import boto3 + from moto import mock_amp diff --git a/tests/test_amp/test_amp_rulegroupnamespaces.py b/tests/test_amp/test_amp_rulegroupnamespaces.py index 0bd40a22b..c9a097a1c 100644 --- a/tests/test_amp/test_amp_rulegroupnamespaces.py +++ b/tests/test_amp/test_amp_rulegroupnamespaces.py @@ -1,8 +1,8 @@ """Unit tests for amp-supported APIs.""" import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_amp # See our Development Tips on writing tests for hints on how to write good tests: diff --git a/tests/test_amp/test_amp_workspaces.py b/tests/test_amp/test_amp_workspaces.py index f31806f39..81c81a630 100644 --- a/tests/test_amp/test_amp_workspaces.py +++ b/tests/test_amp/test_amp_workspaces.py @@ -1,9 +1,10 @@ +from uuid import uuid4 + import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_amp -from uuid import uuid4 # See our Development Tips on writing tests for hints on how to write good tests: # http://docs.getmoto.org/en/latest/docs/contributing/development_tips/tests.html diff --git a/tests/test_apigateway/test_apigateway.py b/tests/test_apigateway/test_apigateway.py index 9ccdfc489..19eb37c1a 100644 --- a/tests/test_apigateway/test_apigateway.py +++ b/tests/test_apigateway/test_apigateway.py @@ -1,13 +1,12 @@ import json import boto3 -from freezegun import freeze_time +import pytest from botocore.exceptions import ClientError +from freezegun import freeze_time from moto import mock_apigateway, mock_cognitoidp, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -import pytest - from tests import DEFAULT_ACCOUNT_ID diff --git a/tests/test_apigateway/test_apigateway_cloudformation.py b/tests/test_apigateway/test_apigateway_cloudformation.py index 7440cefa0..507e83049 100644 --- a/tests/test_apigateway/test_apigateway_cloudformation.py +++ b/tests/test_apigateway/test_apigateway_cloudformation.py @@ -1,7 +1,8 @@ -import boto3 import json -from moto import mock_lambda, mock_cloudformation, mock_apigateway, mock_iam, mock_logs +import boto3 + +from moto import mock_apigateway, mock_cloudformation, mock_iam, mock_lambda, mock_logs template = """{ "AWSTemplateFormatVersion": "2010-09-09", diff --git a/tests/test_apigateway/test_apigateway_deployments.py b/tests/test_apigateway/test_apigateway_deployments.py index 3ec7729b4..b8352e07b 100644 --- a/tests/test_apigateway/test_apigateway_deployments.py +++ b/tests/test_apigateway/test_apigateway_deployments.py @@ -1,8 +1,8 @@ import boto3 +import pytest from botocore.exceptions import ClientError from moto import mock_apigateway -import pytest from .test_apigateway import create_method_integration diff --git a/tests/test_apigateway/test_apigateway_export.py b/tests/test_apigateway/test_apigateway_export.py index b54c1dec8..27873956d 100644 --- a/tests/test_apigateway/test_apigateway_export.py +++ b/tests/test_apigateway/test_apigateway_export.py @@ -1,9 +1,10 @@ -import boto3 import json import os -import pytest +import boto3 +import pytest from botocore.exceptions import ClientError + from moto import mock_apigateway diff --git a/tests/test_apigateway/test_apigateway_gatewayresponses.py b/tests/test_apigateway/test_apigateway_gatewayresponses.py index b9af1237b..a9d9a06e6 100644 --- a/tests/test_apigateway/test_apigateway_gatewayresponses.py +++ b/tests/test_apigateway/test_apigateway_gatewayresponses.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_apigateway diff --git a/tests/test_apigateway/test_apigateway_importrestapi.py b/tests/test_apigateway/test_apigateway_importrestapi.py index 677409cb5..bfdf0b785 100644 --- a/tests/test_apigateway/test_apigateway_importrestapi.py +++ b/tests/test_apigateway/test_apigateway_importrestapi.py @@ -1,12 +1,13 @@ -import boto3 import os -import pytest import sys - -from botocore.exceptions import ClientError -from moto import mock_apigateway, settings from unittest import SkipTest +import boto3 +import pytest +from botocore.exceptions import ClientError + +from moto import mock_apigateway, settings + @mock_apigateway def test_import_rest_api__api_is_created(): diff --git a/tests/test_apigateway/test_apigateway_integration.py b/tests/test_apigateway/test_apigateway_integration.py index 2edb642a1..0856c1e47 100644 --- a/tests/test_apigateway/test_apigateway_integration.py +++ b/tests/test_apigateway/test_apigateway_integration.py @@ -1,11 +1,11 @@ -import boto3 import json +from unittest import SkipTest + +import boto3 import requests -from moto import mock_apigateway, mock_dynamodb -from moto import settings +from moto import mock_apigateway, mock_dynamodb, settings from moto.core.models import responses_mock -from unittest import SkipTest @mock_apigateway diff --git a/tests/test_apigateway/test_apigateway_putrestapi.py b/tests/test_apigateway/test_apigateway_putrestapi.py index 16b440fb1..ea83618fa 100644 --- a/tests/test_apigateway/test_apigateway_putrestapi.py +++ b/tests/test_apigateway/test_apigateway_putrestapi.py @@ -1,12 +1,13 @@ -import boto3 import os -import pytest import sys - -from botocore.exceptions import ClientError -from moto import mock_apigateway, settings from unittest import SkipTest +import boto3 +import pytest +from botocore.exceptions import ClientError + +from moto import mock_apigateway, settings + @mock_apigateway def test_put_rest_api__api_details_are_persisted(): diff --git a/tests/test_apigateway/test_apigateway_stage.py b/tests/test_apigateway/test_apigateway_stage.py index baa3edd2c..4d6fcd7eb 100644 --- a/tests/test_apigateway/test_apigateway_stage.py +++ b/tests/test_apigateway/test_apigateway_stage.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_apigateway from .test_apigateway import create_method_integration diff --git a/tests/test_apigateway/test_apigateway_validators.py b/tests/test_apigateway/test_apigateway_validators.py index dd6dc0591..25819e187 100644 --- a/tests/test_apigateway/test_apigateway_validators.py +++ b/tests/test_apigateway/test_apigateway_validators.py @@ -1,7 +1,8 @@ import boto3 -from moto import mock_apigateway -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError + +from moto import mock_apigateway ID = "id" NAME = "name" diff --git a/tests/test_apigateway/test_apigateway_vpclink.py b/tests/test_apigateway/test_apigateway_vpclink.py index c08395a43..2e98f69e5 100644 --- a/tests/test_apigateway/test_apigateway_vpclink.py +++ b/tests/test_apigateway/test_apigateway_vpclink.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_apigateway diff --git a/tests/test_apigatewaymanagementapi/test_apigatewaymanagementapi.py b/tests/test_apigatewaymanagementapi/test_apigatewaymanagementapi.py index 19f4c0839..c17ab4dd5 100644 --- a/tests/test_apigatewaymanagementapi/test_apigatewaymanagementapi.py +++ b/tests/test_apigatewaymanagementapi/test_apigatewaymanagementapi.py @@ -1,11 +1,12 @@ """Unit tests for apigatewaymanagementapi-supported APIs.""" +from unittest import SkipTest + import boto3 from moto import mock_apigatewaymanagementapi, settings -from moto.core.versions import is_werkzeug_2_3_x from moto.apigatewaymanagementapi.models import apigatewaymanagementapi_backends +from moto.core.versions import is_werkzeug_2_3_x from tests import DEFAULT_ACCOUNT_ID -from unittest import SkipTest # See our Development Tips on writing tests for hints on how to write good tests: # http://docs.getmoto.org/en/latest/docs/contributing/development_tips/tests.html diff --git a/tests/test_apigatewayv2/test_apigatewayv2.py b/tests/test_apigatewayv2/test_apigatewayv2.py index 6b301b42a..94a5ee12f 100644 --- a/tests/test_apigatewayv2/test_apigatewayv2.py +++ b/tests/test_apigatewayv2/test_apigatewayv2.py @@ -1,8 +1,8 @@ """Unit tests for apigatewayv2-supported APIs.""" import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_apigatewayv2 # See our Development Tips on writing tests for hints on how to write good tests: diff --git a/tests/test_apigatewayv2/test_apigatewayv2_authorizers.py b/tests/test_apigatewayv2/test_apigatewayv2_authorizers.py index b556a677f..36a3eec19 100644 --- a/tests/test_apigatewayv2/test_apigatewayv2_authorizers.py +++ b/tests/test_apigatewayv2/test_apigatewayv2_authorizers.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_apigatewayv2 diff --git a/tests/test_apigatewayv2/test_apigatewayv2_domains.py b/tests/test_apigatewayv2/test_apigatewayv2_domains.py index 034ef8fec..a92906f4f 100644 --- a/tests/test_apigatewayv2/test_apigatewayv2_domains.py +++ b/tests/test_apigatewayv2/test_apigatewayv2_domains.py @@ -1,6 +1,7 @@ import boto3 -import pytest import botocore.exceptions +import pytest + from moto import mock_apigatewayv2 diff --git a/tests/test_apigatewayv2/test_apigatewayv2_integrationresponses.py b/tests/test_apigatewayv2/test_apigatewayv2_integrationresponses.py index ce45a0fb0..fbc9aad5f 100644 --- a/tests/test_apigatewayv2/test_apigatewayv2_integrationresponses.py +++ b/tests/test_apigatewayv2/test_apigatewayv2_integrationresponses.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_apigatewayv2 diff --git a/tests/test_apigatewayv2/test_apigatewayv2_integrations.py b/tests/test_apigatewayv2/test_apigatewayv2_integrations.py index 32ecfe62f..1b970ac3a 100644 --- a/tests/test_apigatewayv2/test_apigatewayv2_integrations.py +++ b/tests/test_apigatewayv2/test_apigatewayv2_integrations.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_apigatewayv2 diff --git a/tests/test_apigatewayv2/test_apigatewayv2_mappings.py b/tests/test_apigatewayv2/test_apigatewayv2_mappings.py index 027dec385..1fa2ee8e7 100644 --- a/tests/test_apigatewayv2/test_apigatewayv2_mappings.py +++ b/tests/test_apigatewayv2/test_apigatewayv2_mappings.py @@ -1,6 +1,7 @@ import boto3 -import pytest import botocore.exceptions +import pytest + from moto import mock_apigatewayv2 diff --git a/tests/test_apigatewayv2/test_apigatewayv2_models.py b/tests/test_apigatewayv2/test_apigatewayv2_models.py index 013c6a3a7..9346b8fa3 100644 --- a/tests/test_apigatewayv2/test_apigatewayv2_models.py +++ b/tests/test_apigatewayv2/test_apigatewayv2_models.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_apigatewayv2 diff --git a/tests/test_apigatewayv2/test_apigatewayv2_reimport.py b/tests/test_apigatewayv2/test_apigatewayv2_reimport.py index ae14ce0a9..e4fd7b3e6 100644 --- a/tests/test_apigatewayv2/test_apigatewayv2_reimport.py +++ b/tests/test_apigatewayv2/test_apigatewayv2_reimport.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_apigatewayv2 diff --git a/tests/test_apigatewayv2/test_apigatewayv2_routes.py b/tests/test_apigatewayv2/test_apigatewayv2_routes.py index d00480382..15cb2487d 100644 --- a/tests/test_apigatewayv2/test_apigatewayv2_routes.py +++ b/tests/test_apigatewayv2/test_apigatewayv2_routes.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_apigatewayv2 diff --git a/tests/test_apigatewayv2/test_apigatewayv2_stages.py b/tests/test_apigatewayv2/test_apigatewayv2_stages.py index 3dfe47332..b9dd8d4e8 100644 --- a/tests/test_apigatewayv2/test_apigatewayv2_stages.py +++ b/tests/test_apigatewayv2/test_apigatewayv2_stages.py @@ -1,6 +1,7 @@ import boto3 import pytest from botocore.exceptions import ClientError + from moto import mock_apigatewayv2 diff --git a/tests/test_apigatewayv2/test_apigatewayv2_vpclinks.py b/tests/test_apigatewayv2/test_apigatewayv2_vpclinks.py index 7a0f24f03..758ce715c 100644 --- a/tests/test_apigatewayv2/test_apigatewayv2_vpclinks.py +++ b/tests/test_apigatewayv2/test_apigatewayv2_vpclinks.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_apigatewayv2 diff --git a/tests/test_appconfig/test_appconfig_applications.py b/tests/test_appconfig/test_appconfig_applications.py index 76dfe65df..7e03ef9a0 100644 --- a/tests/test_appconfig/test_appconfig_applications.py +++ b/tests/test_appconfig/test_appconfig_applications.py @@ -1,8 +1,8 @@ """Unit tests for appconfig-supported APIs.""" import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_appconfig # See our Development Tips on writing tests for hints on how to write good tests: diff --git a/tests/test_appconfig/test_appconfig_config_profiles.py b/tests/test_appconfig/test_appconfig_config_profiles.py index c0fb8943f..91808fa3f 100644 --- a/tests/test_appconfig/test_appconfig_config_profiles.py +++ b/tests/test_appconfig/test_appconfig_config_profiles.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_appconfig diff --git a/tests/test_appconfig/test_appconfig_hosted_config_versions.py b/tests/test_appconfig/test_appconfig_hosted_config_versions.py index 40748f9f3..bdb9bf151 100644 --- a/tests/test_appconfig/test_appconfig_hosted_config_versions.py +++ b/tests/test_appconfig/test_appconfig_hosted_config_versions.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_appconfig diff --git a/tests/test_applicationautoscaling/test_applicationautoscaling.py b/tests/test_applicationautoscaling/test_applicationautoscaling.py index 634c1b800..be5f61941 100644 --- a/tests/test_applicationautoscaling/test_applicationautoscaling.py +++ b/tests/test_applicationautoscaling/test_applicationautoscaling.py @@ -2,6 +2,7 @@ import re import boto3 import pytest + from moto import mock_applicationautoscaling, mock_ecs from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_applicationautoscaling/test_validation.py b/tests/test_applicationautoscaling/test_validation.py index a4212624e..0049937b4 100644 --- a/tests/test_applicationautoscaling/test_validation.py +++ b/tests/test_applicationautoscaling/test_validation.py @@ -1,9 +1,11 @@ import boto3 +import pytest +from botocore.exceptions import ClientError + from moto import mock_applicationautoscaling, mock_ecs from moto.applicationautoscaling import models from moto.applicationautoscaling.exceptions import AWSValidationException -import pytest -from botocore.exceptions import ClientError + from .test_applicationautoscaling import register_scalable_target DEFAULT_REGION = "us-east-1" diff --git a/tests/test_appsync/test_appsync.py b/tests/test_appsync/test_appsync.py index 97bcba9dc..8b9ed0361 100644 --- a/tests/test_appsync/test_appsync.py +++ b/tests/test_appsync/test_appsync.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_appsync from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_appsync/test_appsync_apikeys.py b/tests/test_appsync/test_appsync_apikeys.py index 9acef9f17..d8b60e1be 100644 --- a/tests/test_appsync/test_appsync_apikeys.py +++ b/tests/test_appsync/test_appsync_apikeys.py @@ -1,6 +1,7 @@ +from datetime import datetime, timedelta + import boto3 -from datetime import timedelta, datetime from moto import mock_appsync from moto.core.utils import unix_time diff --git a/tests/test_appsync/test_appsync_schema.py b/tests/test_appsync/test_appsync_schema.py index 1f903bfb4..462814f7a 100644 --- a/tests/test_appsync/test_appsync_schema.py +++ b/tests/test_appsync/test_appsync_schema.py @@ -1,7 +1,9 @@ -import boto3 import json -from botocore.exceptions import ClientError + +import boto3 import pytest +from botocore.exceptions import ClientError + from moto import mock_appsync schema = """type Mutation { diff --git a/tests/test_athena/test_athena.py b/tests/test_athena/test_athena.py index 143d7f5cc..a2648e4c2 100644 --- a/tests/test_athena/test_athena.py +++ b/tests/test_athena/test_athena.py @@ -1,9 +1,9 @@ -from botocore.exceptions import ClientError -import pytest import boto3 +import pytest +from botocore.exceptions import ClientError from moto import mock_athena, settings -from moto.athena.models import athena_backends, QueryResults +from moto.athena.models import QueryResults, athena_backends from moto.core import DEFAULT_ACCOUNT_ID diff --git a/tests/test_athena/test_athena_server_api.py b/tests/test_athena/test_athena_server_api.py index 4568ac3de..41acf4eb2 100644 --- a/tests/test_athena/test_athena_server_api.py +++ b/tests/test_athena/test_athena_server_api.py @@ -3,7 +3,6 @@ import requests from moto import mock_athena, mock_sts, settings - DEFAULT_COLUMN_INFO = [ { "CatalogName": "string", diff --git a/tests/test_autoscaling/test_autoscaling.py b/tests/test_autoscaling/test_autoscaling.py index d84ebb213..9a47b1986 100644 --- a/tests/test_autoscaling/test_autoscaling.py +++ b/tests/test_autoscaling/test_autoscaling.py @@ -1,12 +1,14 @@ +from uuid import uuid4 + import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_autoscaling, mock_ec2 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from tests import EXAMPLE_AMI_ID -from uuid import uuid4 -from .utils import setup_networking, setup_instance_with_networking + +from .utils import setup_instance_with_networking, setup_networking @mock_autoscaling diff --git a/tests/test_autoscaling/test_autoscaling_cloudformation.py b/tests/test_autoscaling/test_autoscaling_cloudformation.py index feb39af9e..f6004ec89 100644 --- a/tests/test_autoscaling/test_autoscaling_cloudformation.py +++ b/tests/test_autoscaling/test_autoscaling_cloudformation.py @@ -1,10 +1,11 @@ -import boto3 import json +import boto3 + from moto import mock_autoscaling, mock_cloudformation, mock_ec2, mock_elb +from tests import EXAMPLE_AMI_ID from .utils import setup_networking -from tests import EXAMPLE_AMI_ID @mock_autoscaling diff --git a/tests/test_autoscaling/test_autoscaling_groups.py b/tests/test_autoscaling/test_autoscaling_groups.py index facbb619d..e853fe781 100644 --- a/tests/test_autoscaling/test_autoscaling_groups.py +++ b/tests/test_autoscaling/test_autoscaling_groups.py @@ -1,9 +1,11 @@ +from unittest import TestCase + import boto3 from moto import mock_autoscaling from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from tests import EXAMPLE_AMI_ID -from unittest import TestCase + from .utils import setup_networking diff --git a/tests/test_autoscaling/test_autoscaling_metrics.py b/tests/test_autoscaling/test_autoscaling_metrics.py index 58dcfc5e3..5d898b493 100644 --- a/tests/test_autoscaling/test_autoscaling_metrics.py +++ b/tests/test_autoscaling/test_autoscaling_metrics.py @@ -1,9 +1,9 @@ import boto3 -from moto import mock_autoscaling, mock_elb, mock_ec2 +from moto import mock_autoscaling, mock_ec2, mock_elb +from tests import EXAMPLE_AMI_ID from .utils import setup_networking -from tests import EXAMPLE_AMI_ID @mock_autoscaling diff --git a/tests/test_autoscaling/test_autoscaling_scheduledactions.py b/tests/test_autoscaling/test_autoscaling_scheduledactions.py index 787b81b1e..c8f88715d 100644 --- a/tests/test_autoscaling/test_autoscaling_scheduledactions.py +++ b/tests/test_autoscaling/test_autoscaling_scheduledactions.py @@ -1,7 +1,8 @@ +from unittest import TestCase + import boto3 from moto import mock_autoscaling -from unittest import TestCase @mock_autoscaling diff --git a/tests/test_autoscaling/test_autoscaling_tags.py b/tests/test_autoscaling/test_autoscaling_tags.py index cce02bccc..016007130 100644 --- a/tests/test_autoscaling/test_autoscaling_tags.py +++ b/tests/test_autoscaling/test_autoscaling_tags.py @@ -3,9 +3,9 @@ import copy import boto3 from moto import mock_autoscaling, mock_ec2 +from tests import EXAMPLE_AMI_ID from .utils import setup_networking -from tests import EXAMPLE_AMI_ID @mock_autoscaling diff --git a/tests/test_autoscaling/test_autoscaling_warm_pools.py b/tests/test_autoscaling/test_autoscaling_warm_pools.py index 5252734aa..c1a6a9ae1 100644 --- a/tests/test_autoscaling/test_autoscaling_warm_pools.py +++ b/tests/test_autoscaling/test_autoscaling_warm_pools.py @@ -1,8 +1,10 @@ +from unittest import TestCase + import boto3 from moto import mock_autoscaling, mock_ec2 from tests import EXAMPLE_AMI_ID -from unittest import TestCase + from .utils import setup_networking diff --git a/tests/test_autoscaling/test_elb.py b/tests/test_autoscaling/test_elb.py index ca0d16a1f..8d67cab25 100644 --- a/tests/test_autoscaling/test_elb.py +++ b/tests/test_autoscaling/test_elb.py @@ -1,11 +1,13 @@ -import boto3 - -from moto import mock_autoscaling, mock_elb, mock_ec2 -from .utils import setup_networking -from tests import EXAMPLE_AMI_ID from unittest import TestCase from uuid import uuid4 +import boto3 + +from moto import mock_autoscaling, mock_ec2, mock_elb +from tests import EXAMPLE_AMI_ID + +from .utils import setup_networking + @mock_autoscaling @mock_ec2 diff --git a/tests/test_autoscaling/test_elbv2.py b/tests/test_autoscaling/test_elbv2.py index 074a0bd7f..3cf6d72b5 100644 --- a/tests/test_autoscaling/test_elbv2.py +++ b/tests/test_autoscaling/test_elbv2.py @@ -1,8 +1,11 @@ -import boto3 import unittest +from uuid import uuid4 + +import boto3 + from moto import mock_autoscaling, mock_elbv2 from tests import EXAMPLE_AMI_ID -from uuid import uuid4 + from .utils import setup_networking diff --git a/tests/test_autoscaling/test_launch_configurations.py b/tests/test_autoscaling/test_launch_configurations.py index 4e7b7d931..cb72b33eb 100644 --- a/tests/test_autoscaling/test_launch_configurations.py +++ b/tests/test_autoscaling/test_launch_configurations.py @@ -1,13 +1,14 @@ import base64 -import boto3 import os -import pytest +from unittest import SkipTest, mock +import boto3 +import pytest from botocore.exceptions import ClientError + from moto import mock_autoscaling, mock_ec2, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from tests import EXAMPLE_AMI_ID -from unittest import mock, SkipTest @mock_autoscaling diff --git a/tests/test_autoscaling/test_policies.py b/tests/test_autoscaling/test_policies.py index 09efa2fdc..af040892e 100644 --- a/tests/test_autoscaling/test_policies.py +++ b/tests/test_autoscaling/test_policies.py @@ -2,9 +2,9 @@ import boto3 import pytest from moto import mock_autoscaling +from tests import EXAMPLE_AMI_ID from .utils import setup_networking -from tests import EXAMPLE_AMI_ID def setup_autoscale_group_boto3(): diff --git a/tests/test_autoscaling/utils.py b/tests/test_autoscaling/utils.py index d637c465a..412d0959c 100644 --- a/tests/test_autoscaling/utils.py +++ b/tests/test_autoscaling/utils.py @@ -1,4 +1,5 @@ import boto3 + from moto import mock_ec2 diff --git a/tests/test_awslambda/test_awslambda_cloudformation.py b/tests/test_awslambda/test_awslambda_cloudformation.py index 3ef4bea4d..58c70e8fb 100644 --- a/tests/test_awslambda/test_awslambda_cloudformation.py +++ b/tests/test_awslambda/test_awslambda_cloudformation.py @@ -1,13 +1,15 @@ -import boto3 import io -import zipfile -from botocore.exceptions import ClientError -from moto import mock_cloudformation, mock_iam, mock_lambda, mock_s3, mock_sqs -import pytest import re +import zipfile from string import Template from uuid import uuid4 +import boto3 +import pytest +from botocore.exceptions import ClientError + +from moto import mock_cloudformation, mock_iam, mock_lambda, mock_s3, mock_sqs + def random_stack_name(): return str(uuid4())[0:6] diff --git a/tests/test_awslambda/test_lambda.py b/tests/test_awslambda/test_lambda.py index df22c3074..e4b982039 100644 --- a/tests/test_awslambda/test_lambda.py +++ b/tests/test_awslambda/test_lambda.py @@ -1,24 +1,26 @@ import base64 +import hashlib import json import os from unittest import SkipTest, mock -import boto3 -import hashlib -import pytest +from uuid import uuid4 +import boto3 +import pytest from botocore.exceptions import ClientError, ParamValidationError from freezegun import freeze_time -from tests.test_ecr.test_ecr_helpers import _create_image_manifest -from moto import mock_lambda, mock_s3, mock_ecr, settings + +from moto import mock_ecr, mock_lambda, mock_s3, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from uuid import uuid4 +from tests.test_ecr.test_ecr_helpers import _create_image_manifest + from .utilities import ( + _process_lambda, + create_invalid_lambda, get_role_name, get_test_zip_file1, get_test_zip_file2, get_test_zip_file3, - create_invalid_lambda, - _process_lambda, ) PYTHON_VERSION = "python3.11" diff --git a/tests/test_awslambda/test_lambda_alias.py b/tests/test_awslambda/test_lambda_alias.py index 59bc50877..39707f3ac 100644 --- a/tests/test_awslambda/test_lambda_alias.py +++ b/tests/test_awslambda/test_lambda_alias.py @@ -2,11 +2,12 @@ from uuid import uuid4 import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_lambda from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID + from .utilities import ( get_role_name, get_test_zip_file1, diff --git a/tests/test_awslambda/test_lambda_concurrency.py b/tests/test_awslambda/test_lambda_concurrency.py index a5a6d43f3..4ad7d861e 100644 --- a/tests/test_awslambda/test_lambda_concurrency.py +++ b/tests/test_awslambda/test_lambda_concurrency.py @@ -1,8 +1,10 @@ +from uuid import uuid4 + import boto3 import pytest from moto import mock_lambda -from uuid import uuid4 + from .utilities import get_role_name, get_test_zip_file1 PYTHON_VERSION = "python3.11" diff --git a/tests/test_awslambda/test_lambda_eventsourcemapping.py b/tests/test_awslambda/test_lambda_eventsourcemapping.py index c65d8d951..e643ac493 100644 --- a/tests/test_awslambda/test_lambda_eventsourcemapping.py +++ b/tests/test_awslambda/test_lambda_eventsourcemapping.py @@ -1,19 +1,21 @@ -import boto3 import json -import pytest import time import uuid - -from botocore.exceptions import ClientError -from moto import mock_dynamodb, mock_lambda, mock_logs, mock_sns, mock_sqs from uuid import uuid4 + +import boto3 +import pytest +from botocore.exceptions import ClientError + +from moto import mock_dynamodb, mock_lambda, mock_logs, mock_sns, mock_sqs + +from ..markers import requires_docker from .utilities import ( get_role_name, get_test_zip_file3, - wait_for_log_msg, get_test_zip_file_error, + wait_for_log_msg, ) -from ..markers import requires_docker PYTHON_VERSION = "python3.11" _lambda_region = "us-west-2" diff --git a/tests/test_awslambda/test_lambda_function_urls.py b/tests/test_awslambda/test_lambda_function_urls.py index 3ca080c83..c3ad1b9fe 100644 --- a/tests/test_awslambda/test_lambda_function_urls.py +++ b/tests/test_awslambda/test_lambda_function_urls.py @@ -1,9 +1,12 @@ +from uuid import uuid4 + import boto3 import pytest from botocore.exceptions import ClientError + from moto import mock_lambda -from uuid import uuid4 -from .utilities import get_test_zip_file1, get_role_name + +from .utilities import get_role_name, get_test_zip_file1 PYTHON_VERSION = "python3.11" diff --git a/tests/test_awslambda/test_lambda_invoke.py b/tests/test_awslambda/test_lambda_invoke.py index 3507d234e..763be9773 100644 --- a/tests/test_awslambda/test_lambda_invoke.py +++ b/tests/test_awslambda/test_lambda_invoke.py @@ -1,24 +1,26 @@ import base64 -import boto3 import json -import pytest - -from botocore.exceptions import ClientError -from moto import mock_lambda, mock_ec2, settings -from uuid import uuid4 from unittest import SkipTest +from uuid import uuid4 + +import boto3 +import pytest +from botocore.exceptions import ClientError + +from moto import mock_ec2, mock_lambda, settings + +from ..markers import requires_docker from .utilities import ( - get_role_name, - get_test_zip_file_error, - get_test_zip_file1, - get_zip_with_multiple_files, - get_test_zip_file2, get_lambda_using_environment_port, get_lambda_using_network_mode, - get_test_zip_largeresponse, get_proxy_zip_file, + get_role_name, + get_test_zip_file1, + get_test_zip_file2, + get_test_zip_file_error, + get_test_zip_largeresponse, + get_zip_with_multiple_files, ) -from ..markers import requires_docker PYTHON_VERSION = "python3.11" _lambda_region = "us-west-2" diff --git a/tests/test_awslambda/test_lambda_layers.py b/tests/test_awslambda/test_lambda_layers.py index 1e4aa9121..7541826f9 100644 --- a/tests/test_awslambda/test_lambda_layers.py +++ b/tests/test_awslambda/test_lambda_layers.py @@ -1,13 +1,14 @@ -import boto3 import os -import pytest +from unittest import SkipTest, mock +from uuid import uuid4 +import boto3 +import pytest from botocore.exceptions import ClientError from freezegun import freeze_time + from moto import mock_lambda, mock_s3, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from unittest import mock, SkipTest -from uuid import uuid4 from .utilities import get_role_name, get_test_zip_file1 diff --git a/tests/test_awslambda/test_lambda_layers_invoked.py b/tests/test_awslambda/test_lambda_layers_invoked.py index 50811f48c..34d5fb1f9 100644 --- a/tests/test_awslambda/test_lambda_layers_invoked.py +++ b/tests/test_awslambda/test_lambda_layers_invoked.py @@ -1,11 +1,12 @@ -import boto3 import pkgutil - -from moto import mock_lambda from uuid import uuid4 +import boto3 + +from moto import mock_lambda from tests.markers import requires_docker -from .utilities import get_role_name, _process_lambda + +from .utilities import _process_lambda, get_role_name PYTHON_VERSION = "python3.11" _lambda_region = "us-west-2" diff --git a/tests/test_awslambda/test_lambda_policy.py b/tests/test_awslambda/test_lambda_policy.py index ae7d1badd..b1848d2d9 100644 --- a/tests/test_awslambda/test_lambda_policy.py +++ b/tests/test_awslambda/test_lambda_policy.py @@ -1,11 +1,13 @@ -import boto3 import json -import pytest +from uuid import uuid4 +import boto3 +import pytest from botocore.exceptions import ClientError + from moto import mock_lambda, mock_s3 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from uuid import uuid4 + from .utilities import get_role_name, get_test_zip_file1, get_test_zip_file2 PYTHON_VERSION = "python3.11" diff --git a/tests/test_awslambda/test_lambda_tags.py b/tests/test_awslambda/test_lambda_tags.py index fe65ad88a..c4c8c07ae 100644 --- a/tests/test_awslambda/test_lambda_tags.py +++ b/tests/test_awslambda/test_lambda_tags.py @@ -1,10 +1,12 @@ +from uuid import uuid4 + import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_lambda, mock_s3 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from uuid import uuid4 + from .utilities import get_role_name, get_test_zip_file2 PYTHON_VERSION = "python3.11" diff --git a/tests/test_awslambda/utilities.py b/tests/test_awslambda/utilities.py index 1495e8861..f7e78e20a 100644 --- a/tests/test_awslambda/utilities.py +++ b/tests/test_awslambda/utilities.py @@ -1,13 +1,14 @@ -import boto3 import io -import pytest import time import zipfile - -from botocore.exceptions import ClientError -from moto import settings, mock_iam from uuid import uuid4 +import boto3 +import pytest +from botocore.exceptions import ClientError + +from moto import mock_iam, settings + _lambda_region = "us-west-2" diff --git a/tests/test_awslambda_simple/test_lambda_simple.py b/tests/test_awslambda_simple/test_lambda_simple.py index e316b7890..71ec3e595 100644 --- a/tests/test_awslambda_simple/test_lambda_simple.py +++ b/tests/test_awslambda_simple/test_lambda_simple.py @@ -1,9 +1,11 @@ import json from unittest import SkipTest + import boto3 from moto import mock_iam, mock_lambda_simple, settings -from ..test_awslambda.utilities import get_test_zip_file1, get_role_name + +from ..test_awslambda.utilities import get_role_name, get_test_zip_file1 LAMBDA_REGION = "us-west-2" PYTHON_VERSION = "3.11" diff --git a/tests/test_batch/__init__.py b/tests/test_batch/__init__.py index b3320fd02..35c0c3eae 100644 --- a/tests/test_batch/__init__.py +++ b/tests/test_batch/__init__.py @@ -1,6 +1,6 @@ -import boto3 from uuid import uuid4 +import boto3 DEFAULT_REGION = "eu-central-1" diff --git a/tests/test_batch/test_batch_cloudformation.py b/tests/test_batch/test_batch_cloudformation.py index f20f16c11..adc2f34f7 100644 --- a/tests/test_batch/test_batch_cloudformation.py +++ b/tests/test_batch/test_batch_cloudformation.py @@ -1,8 +1,10 @@ -import boto3 -from moto import mock_batch, mock_iam, mock_ec2, mock_ecs, mock_cloudformation import json from uuid import uuid4 +import boto3 + +from moto import mock_batch, mock_cloudformation, mock_ec2, mock_ecs, mock_iam + DEFAULT_REGION = "eu-central-1" diff --git a/tests/test_batch/test_batch_compute_envs.py b/tests/test_batch/test_batch_compute_envs.py index 1c016cbbb..fb5c7a294 100644 --- a/tests/test_batch/test_batch_compute_envs.py +++ b/tests/test_batch/test_batch_compute_envs.py @@ -1,8 +1,11 @@ -from . import _get_clients, _setup +from uuid import uuid4 + import pytest from botocore.exceptions import ClientError -from moto import mock_batch, mock_iam, mock_ec2, mock_ecs, settings -from uuid import uuid4 + +from moto import mock_batch, mock_ec2, mock_ecs, mock_iam, settings + +from . import _get_clients, _setup # Yes, yes it talks to all the things diff --git a/tests/test_batch/test_batch_job_queue.py b/tests/test_batch/test_batch_job_queue.py index 7f38ca409..139f48f92 100644 --- a/tests/test_batch/test_batch_job_queue.py +++ b/tests/test_batch/test_batch_job_queue.py @@ -1,9 +1,12 @@ -from . import _get_clients, _setup +from uuid import uuid4 + import boto3 import pytest from botocore.exceptions import ClientError -from moto import mock_batch, mock_iam, mock_ec2, mock_ecs -from uuid import uuid4 + +from moto import mock_batch, mock_ec2, mock_ecs, mock_iam + +from . import _get_clients, _setup @mock_ec2 diff --git a/tests/test_batch/test_batch_jobs.py b/tests/test_batch/test_batch_jobs.py index 32a137487..428f94961 100644 --- a/tests/test_batch/test_batch_jobs.py +++ b/tests/test_batch/test_batch_jobs.py @@ -1,14 +1,15 @@ -import botocore.exceptions import datetime -import pytest import time from uuid import uuid4 -from moto import mock_batch, mock_iam, mock_ec2, mock_ecs, mock_logs +import botocore.exceptions +import pytest + +from moto import mock_batch, mock_ec2, mock_ecs, mock_iam, mock_logs from tests import DEFAULT_ACCOUNT_ID -from . import _get_clients, _setup from ..markers import requires_docker +from . import _get_clients, _setup @mock_logs diff --git a/tests/test_batch/test_batch_tags_job_definition.py b/tests/test_batch/test_batch_tags_job_definition.py index 3fccfca2c..f8ab03923 100644 --- a/tests/test_batch/test_batch_tags_job_definition.py +++ b/tests/test_batch/test_batch_tags_job_definition.py @@ -1,7 +1,8 @@ -from . import _get_clients +from uuid import uuid4 from moto import mock_batch -from uuid import uuid4 + +from . import _get_clients container_properties = { "image": "busybox", diff --git a/tests/test_batch/test_batch_tags_job_queue.py b/tests/test_batch/test_batch_tags_job_queue.py index 335c26fee..d4df887aa 100644 --- a/tests/test_batch/test_batch_tags_job_queue.py +++ b/tests/test_batch/test_batch_tags_job_queue.py @@ -1,8 +1,9 @@ -from . import _get_clients, _setup - -from moto import mock_batch, mock_iam, mock_ec2, mock_ecs from uuid import uuid4 +from moto import mock_batch, mock_ec2, mock_ecs, mock_iam + +from . import _get_clients, _setup + @mock_ec2 @mock_ecs diff --git a/tests/test_batch/test_batch_task_definition.py b/tests/test_batch/test_batch_task_definition.py index f50da4caa..e6bf114f0 100644 --- a/tests/test_batch/test_batch_task_definition.py +++ b/tests/test_batch/test_batch_task_definition.py @@ -1,9 +1,12 @@ -from . import _get_clients import random -import pytest -from moto import mock_batch from uuid import uuid4 +import pytest + +from moto import mock_batch + +from . import _get_clients + @mock_batch @pytest.mark.parametrize("use_resource_reqs", [True, False]) diff --git a/tests/test_batch/test_utils.py b/tests/test_batch/test_utils.py index 0c203ff1e..870b2bad0 100644 --- a/tests/test_batch/test_utils.py +++ b/tests/test_batch/test_utils.py @@ -1,7 +1,6 @@ import pytest from moto.batch.exceptions import ValidationError - from moto.batch.utils import JobStatus diff --git a/tests/test_batch_simple/test_batch_cloudformation.py b/tests/test_batch_simple/test_batch_cloudformation.py index 40878a357..981ea7097 100644 --- a/tests/test_batch_simple/test_batch_cloudformation.py +++ b/tests/test_batch_simple/test_batch_cloudformation.py @@ -1,9 +1,10 @@ -import boto3 import json -from moto import mock_iam, mock_ec2, mock_ecs, mock_cloudformation -from moto import mock_batch_simple as mock_batch_without_docker from uuid import uuid4 +import boto3 + +from moto import mock_batch_simple as mock_batch_without_docker +from moto import mock_cloudformation, mock_ec2, mock_ecs, mock_iam # Copy of test_batch/test_batch_cloudformation # Except that we verify this behaviour still works without docker diff --git a/tests/test_batch_simple/test_batch_compute_envs.py b/tests/test_batch_simple/test_batch_compute_envs.py index a9439062b..8eb359d2e 100644 --- a/tests/test_batch_simple/test_batch_compute_envs.py +++ b/tests/test_batch_simple/test_batch_compute_envs.py @@ -1,7 +1,8 @@ -from ..test_batch import _get_clients, _setup -from moto import mock_batch_simple, mock_iam, mock_ec2, mock_ecs, settings from uuid import uuid4 +from moto import mock_batch_simple, mock_ec2, mock_ecs, mock_iam, settings + +from ..test_batch import _get_clients, _setup # Copy of test_batch/test_batch_compute_envs # Except that we verify this behaviour still works without docker diff --git a/tests/test_batch_simple/test_batch_jobs.py b/tests/test_batch_simple/test_batch_jobs.py index 2d2c940ff..ae09d1399 100644 --- a/tests/test_batch_simple/test_batch_jobs.py +++ b/tests/test_batch_simple/test_batch_jobs.py @@ -1,11 +1,10 @@ -from ..test_batch import _get_clients, _setup - import os -from moto import mock_iam, mock_ec2, mock_ecs, mock_logs, settings -from moto import mock_batch_simple +from unittest import SkipTest, mock from uuid import uuid4 -from unittest import mock, SkipTest +from moto import mock_batch_simple, mock_ec2, mock_ecs, mock_iam, mock_logs, settings + +from ..test_batch import _get_clients, _setup # Copy of test_batch/test_batch_jobs # Except that we verify this behaviour still works without docker diff --git a/tests/test_budgets/test_budgets.py b/tests/test_budgets/test_budgets.py index a58c7093a..e7e4ea0a3 100644 --- a/tests/test_budgets/test_budgets.py +++ b/tests/test_budgets/test_budgets.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_budgets from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_budgets/test_notifications.py b/tests/test_budgets/test_notifications.py index f9a306f25..580f19f7a 100644 --- a/tests/test_budgets/test_notifications.py +++ b/tests/test_budgets/test_notifications.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_budgets from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_ce/test_ce.py b/tests/test_ce/test_ce.py index 0b3ff82e1..c234d1b62 100644 --- a/tests/test_ce/test_ce.py +++ b/tests/test_ce/test_ce.py @@ -1,8 +1,8 @@ """Unit tests for ce-supported APIs.""" import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_ce from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_cloudformation/test_cloudformation_custom_resources.py b/tests/test_cloudformation/test_cloudformation_custom_resources.py index 33e058f7b..2fbef1f7b 100644 --- a/tests/test_cloudformation/test_cloudformation_custom_resources.py +++ b/tests/test_cloudformation/test_cloudformation_custom_resources.py @@ -1,16 +1,18 @@ -import boto3 import json -import requests import time -import pytest - -from botocore.exceptions import ClientError -from moto import mock_lambda, mock_cloudformation, mock_logs, mock_s3, settings from unittest import SkipTest from uuid import uuid4 + +import boto3 +import pytest +import requests +from botocore.exceptions import ClientError + +from moto import mock_cloudformation, mock_lambda, mock_logs, mock_s3, settings from tests.test_awslambda.utilities import wait_for_log_msg -from .fixtures.custom_lambda import get_template, get_template_for_unknown_lambda + from ..markers import requires_docker +from .fixtures.custom_lambda import get_template, get_template_for_unknown_lambda def get_lambda_code(): diff --git a/tests/test_cloudformation/test_cloudformation_depends_on.py b/tests/test_cloudformation/test_cloudformation_depends_on.py index c593cf594..ed2d2f81b 100644 --- a/tests/test_cloudformation/test_cloudformation_depends_on.py +++ b/tests/test_cloudformation/test_cloudformation_depends_on.py @@ -1,7 +1,8 @@ -import boto3 -from moto import mock_cloudformation, mock_ecs, mock_autoscaling, mock_s3 import json +import boto3 + +from moto import mock_autoscaling, mock_cloudformation, mock_ecs, mock_s3 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from tests import EXAMPLE_AMI_ID diff --git a/tests/test_cloudformation/test_cloudformation_multi_accounts.py b/tests/test_cloudformation/test_cloudformation_multi_accounts.py index a01bd35ef..633bc42c9 100644 --- a/tests/test_cloudformation/test_cloudformation_multi_accounts.py +++ b/tests/test_cloudformation/test_cloudformation_multi_accounts.py @@ -1,14 +1,15 @@ -import boto3 import json -import pytest -from botocore.exceptions import ClientError -from moto import mock_cloudformation, mock_organizations, mock_sqs, settings -from moto.core import DEFAULT_ACCOUNT_ID -from moto.cloudformation import cloudformation_backends as cf_backends -from moto.sqs import sqs_backends from unittest import SkipTest, TestCase from uuid import uuid4 +import boto3 +import pytest +from botocore.exceptions import ClientError + +from moto import mock_cloudformation, mock_organizations, mock_sqs, settings +from moto.cloudformation import cloudformation_backends as cf_backends +from moto.core import DEFAULT_ACCOUNT_ID +from moto.sqs import sqs_backends TEMPLATE_DCT = { "AWSTemplateFormatVersion": "2010-09-09", diff --git a/tests/test_cloudformation/test_cloudformation_nested_stacks.py b/tests/test_cloudformation/test_cloudformation_nested_stacks.py index ce4b6919b..6095e7b22 100644 --- a/tests/test_cloudformation/test_cloudformation_nested_stacks.py +++ b/tests/test_cloudformation/test_cloudformation_nested_stacks.py @@ -1,7 +1,8 @@ -import boto3 import json from uuid import uuid4 +import boto3 + from moto import mock_cloudformation, mock_s3 diff --git a/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py b/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py index 05db186cb..fcbfac2c0 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py +++ b/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py @@ -1,14 +1,14 @@ -import boto3 import copy import json import os -import pytest - -from botocore.exceptions import ClientError from collections import OrderedDict from datetime import datetime, timedelta, timezone from unittest import SkipTest +import boto3 +import pytest +from botocore.exceptions import ClientError + from moto import ( mock_cloudformation, mock_dynamodb, @@ -22,7 +22,6 @@ from moto import ( ) from moto.cloudformation import cloudformation_backends from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID - from tests import EXAMPLE_AMI_ID dummy_template = { diff --git a/tests/test_cloudformation/test_cloudformation_stack_integration.py b/tests/test_cloudformation/test_cloudformation_stack_integration.py index 88616ffc0..9d605c6fb 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_integration.py +++ b/tests/test_cloudformation/test_cloudformation_stack_integration.py @@ -1,29 +1,28 @@ -import boto3 -import json import io -import pytest +import json import zipfile - -from botocore.exceptions import ClientError from decimal import Decimal from string import Template +import boto3 +import pytest +from botocore.exceptions import ClientError + from moto import ( mock_autoscaling, mock_cloudformation, mock_dynamodb, mock_ec2, + mock_elbv2, mock_events, mock_kms, mock_lambda, mock_logs, mock_s3, mock_sqs, - mock_elbv2, mock_ssm, ) from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID - from tests import EXAMPLE_AMI_ID, EXAMPLE_AMI_ID2 from tests.markers import requires_docker from tests.test_cloudformation.fixtures import fn_join, single_instance_with_ebs_volume diff --git a/tests/test_cloudformation/test_cloudformation_stack_policies.py b/tests/test_cloudformation/test_cloudformation_stack_policies.py index 5f5ea0a08..fa124eef1 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_policies.py +++ b/tests/test_cloudformation/test_cloudformation_stack_policies.py @@ -1,10 +1,11 @@ -import boto3 import json +import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_cloudformation, mock_s3 + from .test_cloudformation_stack_crud_boto3 import dummy_template_json diff --git a/tests/test_cloudformation/test_stack_parsing.py b/tests/test_cloudformation/test_stack_parsing.py index d046cc640..505d8eb9f 100644 --- a/tests/test_cloudformation/test_stack_parsing.py +++ b/tests/test_cloudformation/test_stack_parsing.py @@ -1,24 +1,23 @@ -import boto3 import json -import yaml - -import pytest -from botocore.exceptions import ClientError from unittest.mock import patch +import boto3 +import pytest +import yaml +from botocore.exceptions import ClientError + +from moto import mock_cloudformation, mock_sqs, mock_ssm, settings from moto.cloudformation.exceptions import ValidationError from moto.cloudformation.models import FakeStack from moto.cloudformation.parsing import ( - resource_class_from_type, - parse_condition, Output, + parse_condition, + resource_class_from_type, ) -from moto import mock_cloudformation, mock_sqs, mock_ssm, settings -from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from moto.sqs.models import Queue -from moto.s3.models import FakeBucket from moto.cloudformation.utils import yaml_tag_constructor - +from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID +from moto.s3.models import FakeBucket +from moto.sqs.models import Queue dummy_template = { "AWSTemplateFormatVersion": "2010-09-09", diff --git a/tests/test_cloudformation/test_validate.py b/tests/test_cloudformation/test_validate.py index 706581444..58bedc030 100644 --- a/tests/test_cloudformation/test_validate.py +++ b/tests/test_cloudformation/test_validate.py @@ -1,4 +1,5 @@ import json + import boto3 import botocore import pytest diff --git a/tests/test_cloudfront/test_cloudfront.py b/tests/test_cloudfront/test_cloudfront.py index 5a42cbdb6..04884d7a1 100644 --- a/tests/test_cloudfront/test_cloudfront.py +++ b/tests/test_cloudfront/test_cloudfront.py @@ -1,9 +1,11 @@ """Unit tests for cloudfront-supported APIs.""" -import pytest import boto3 +import pytest from botocore.exceptions import ClientError, ParamValidationError + from moto import mock_cloudfront from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID + from . import cloudfront_test_scaffolding as scaffold # See our Development Tips on writing tests for hints on how to write good tests: diff --git a/tests/test_cloudfront/test_cloudfront_dist_tags.py b/tests/test_cloudfront/test_cloudfront_dist_tags.py index 13e9e1e86..5d1906ccd 100644 --- a/tests/test_cloudfront/test_cloudfront_dist_tags.py +++ b/tests/test_cloudfront/test_cloudfront_dist_tags.py @@ -1,5 +1,7 @@ import boto3 + from moto import mock_cloudfront + from . import cloudfront_test_scaffolding as scaffold diff --git a/tests/test_cloudfront/test_cloudfront_distributions.py b/tests/test_cloudfront/test_cloudfront_distributions.py index e5de3ffab..45fc528f9 100644 --- a/tests/test_cloudfront/test_cloudfront_distributions.py +++ b/tests/test_cloudfront/test_cloudfront_distributions.py @@ -1,9 +1,11 @@ import boto3 +import pytest from botocore.exceptions import ClientError + from moto import mock_cloudfront from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID + from . import cloudfront_test_scaffolding as scaffold -import pytest @mock_cloudfront diff --git a/tests/test_cloudfront/test_cloudfront_invalidation.py b/tests/test_cloudfront/test_cloudfront_invalidation.py index 7dd85f53c..3f92de7eb 100644 --- a/tests/test_cloudfront/test_cloudfront_invalidation.py +++ b/tests/test_cloudfront/test_cloudfront_invalidation.py @@ -1,5 +1,7 @@ import boto3 + from moto import mock_cloudfront + from . import cloudfront_test_scaffolding as scaffold diff --git a/tests/test_cloudfront/test_cloudfront_oac.py b/tests/test_cloudfront/test_cloudfront_oac.py index 439f5189a..073d57c75 100644 --- a/tests/test_cloudfront/test_cloudfront_oac.py +++ b/tests/test_cloudfront/test_cloudfront_oac.py @@ -1,6 +1,7 @@ import boto3 import pytest from botocore.exceptions import ClientError + from moto import mock_cloudfront diff --git a/tests/test_cloudfront/test_server.py b/tests/test_cloudfront/test_server.py index 534ca606a..09c7d7ed0 100644 --- a/tests/test_cloudfront/test_server.py +++ b/tests/test_cloudfront/test_server.py @@ -1,7 +1,7 @@ import xmltodict -from moto import mock_cloudfront import moto.server as server +from moto import mock_cloudfront @mock_cloudfront diff --git a/tests/test_cloudtrail/test_cloudtrail.py b/tests/test_cloudtrail/test_cloudtrail.py index d3e9ec9af..7f25610c8 100644 --- a/tests/test_cloudtrail/test_cloudtrail.py +++ b/tests/test_cloudtrail/test_cloudtrail.py @@ -1,12 +1,13 @@ """Unit tests for cloudtrail-supported APIs.""" +from datetime import datetime +from uuid import uuid4 + import boto3 import pytest - from botocore.exceptions import ClientError -from datetime import datetime + from moto import mock_cloudtrail, mock_s3, mock_sns from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from uuid import uuid4 @mock_s3 diff --git a/tests/test_cloudtrail/test_cloudtrail_tags.py b/tests/test_cloudtrail/test_cloudtrail_tags.py index 2c60719b2..d61f4f926 100644 --- a/tests/test_cloudtrail/test_cloudtrail_tags.py +++ b/tests/test_cloudtrail/test_cloudtrail_tags.py @@ -2,7 +2,7 @@ import boto3 from moto import mock_cloudtrail, mock_s3, mock_sns -from .test_cloudtrail import create_trail_simple, create_trail_advanced +from .test_cloudtrail import create_trail_advanced, create_trail_simple @mock_cloudtrail diff --git a/tests/test_cloudwatch/test_cloudwatch_boto3.py b/tests/test_cloudwatch/test_cloudwatch_boto3.py index 2857b1110..613674941 100644 --- a/tests/test_cloudwatch/test_cloudwatch_boto3.py +++ b/tests/test_cloudwatch/test_cloudwatch_boto3.py @@ -1,15 +1,14 @@ import copy +from datetime import datetime, timedelta, timezone +from decimal import Decimal +from operator import itemgetter +from uuid import uuid4 import boto3 import pytest - from botocore.exceptions import ClientError -from datetime import datetime, timedelta, timezone from dateutil.tz import tzutc -from decimal import Decimal from freezegun import freeze_time -from operator import itemgetter -from uuid import uuid4 from moto import mock_cloudwatch, mock_s3 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_cloudwatch/test_cloudwatch_expressions.py b/tests/test_cloudwatch/test_cloudwatch_expressions.py index 663105b5f..16dfdbaaa 100644 --- a/tests/test_cloudwatch/test_cloudwatch_expressions.py +++ b/tests/test_cloudwatch/test_cloudwatch_expressions.py @@ -1,8 +1,9 @@ +from datetime import datetime, timedelta, timezone + import boto3 import pytest - from botocore.exceptions import ClientError -from datetime import datetime, timedelta, timezone + from moto import mock_cloudwatch diff --git a/tests/test_cloudwatch/test_cloudwatch_tags.py b/tests/test_cloudwatch/test_cloudwatch_tags.py index 4ee43ce7a..b3c9445df 100644 --- a/tests/test_cloudwatch/test_cloudwatch_tags.py +++ b/tests/test_cloudwatch/test_cloudwatch_tags.py @@ -1,8 +1,8 @@ from operator import itemgetter import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_cloudwatch from moto.cloudwatch.utils import make_arn_for_alarm diff --git a/tests/test_codebuild/test_codebuild.py b/tests/test_codebuild/test_codebuild.py index b915cd794..a966099c2 100644 --- a/tests/test_codebuild/test_codebuild.py +++ b/tests/test_codebuild/test_codebuild.py @@ -1,9 +1,11 @@ +from uuid import uuid1 + import boto3 +import pytest +from botocore.exceptions import ClientError, ParamValidationError + from moto import mock_codebuild from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from botocore.exceptions import ClientError, ParamValidationError -from uuid import uuid1 -import pytest @mock_codebuild diff --git a/tests/test_codecommit/test_codecommit.py b/tests/test_codecommit/test_codecommit.py index d34ba0dc4..24c6a23ad 100644 --- a/tests/test_codecommit/test_codecommit.py +++ b/tests/test_codecommit/test_codecommit.py @@ -1,9 +1,9 @@ import boto3 +import pytest +from botocore.exceptions import ClientError from moto import mock_codecommit from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from botocore.exceptions import ClientError -import pytest @mock_codecommit diff --git a/tests/test_codepipeline/test_codepipeline.py b/tests/test_codepipeline/test_codepipeline.py index 1a394fee1..7b1b8a12f 100644 --- a/tests/test_codepipeline/test_codepipeline.py +++ b/tests/test_codepipeline/test_codepipeline.py @@ -3,12 +3,11 @@ from copy import deepcopy from datetime import datetime import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_codepipeline, mock_iam - expected_pipeline_details = { "name": "test-pipeline", "roleArn": "arn:aws:iam::123456789012:role/test-role", diff --git a/tests/test_cognitoidentity/test_cognitoidentity.py b/tests/test_cognitoidentity/test_cognitoidentity.py index 742c27a81..7646e8cd9 100644 --- a/tests/test_cognitoidentity/test_cognitoidentity.py +++ b/tests/test_cognitoidentity/test_cognitoidentity.py @@ -1,15 +1,15 @@ -import boto3 -from unittest import mock -from botocore.exceptions import ClientError -from datetime import datetime -import pytest import os +from datetime import datetime +from unittest import SkipTest, mock +from uuid import UUID + +import boto3 +import pytest +from botocore.exceptions import ClientError from moto import mock_cognitoidentity, settings from moto.cognitoidentity.utils import get_random_identity_id from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from unittest import SkipTest -from uuid import UUID @mock_cognitoidentity diff --git a/tests/test_cognitoidp/test_cognitoidp.py b/tests/test_cognitoidp/test_cognitoidp.py index 152570f20..23c5aa1f1 100644 --- a/tests/test_cognitoidp/test_cognitoidp.py +++ b/tests/test_cognitoidp/test_cognitoidp.py @@ -1,25 +1,21 @@ import base64 import datetime - -import boto3 +import hashlib +import hmac import json import os import random import re - -from unittest import mock -import moto.cognitoidp.models -import requests -import hmac -import hashlib import uuid +from unittest import SkipTest, mock - +import boto3 +import pytest +import requests from botocore.exceptions import ClientError, ParamValidationError from jose import jws, jwt -from unittest import SkipTest -import pytest +import moto.cognitoidp.models from moto import mock_cognitoidp, settings from moto.cognitoidp.utils import create_id from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_cognitoidp/test_cognitoidp_exceptions.py b/tests/test_cognitoidp/test_cognitoidp_exceptions.py index 200e52a17..e010ba3e6 100644 --- a/tests/test_cognitoidp/test_cognitoidp_exceptions.py +++ b/tests/test_cognitoidp/test_cognitoidp_exceptions.py @@ -2,9 +2,9 @@ from unittest import TestCase import boto3 import pytest +from botocore.exceptions import ClientError from moto import mock_cognitoidp -from botocore.exceptions import ClientError @mock_cognitoidp diff --git a/tests/test_cognitoidp/test_cognitoidp_replay.py b/tests/test_cognitoidp/test_cognitoidp_replay.py index 23cfe6c4f..fea72f865 100644 --- a/tests/test_cognitoidp/test_cognitoidp_replay.py +++ b/tests/test_cognitoidp/test_cognitoidp_replay.py @@ -1,14 +1,14 @@ import os +import uuid +from unittest import TestCase import boto3 -import uuid import pytest import requests - from botocore.exceptions import ClientError + from moto import mock_cognitoidp, settings from moto.moto_api import recorder -from unittest import TestCase @mock_cognitoidp diff --git a/tests/test_cognitoidp/test_server.py b/tests/test_cognitoidp/test_server.py index f2807092a..1b1f6f100 100644 --- a/tests/test_cognitoidp/test_server.py +++ b/tests/test_cognitoidp/test_server.py @@ -1,4 +1,5 @@ import json + import moto.server as server diff --git a/tests/test_comprehend/test_comprehend.py b/tests/test_comprehend/test_comprehend.py index 24fe9e21e..a26afcf45 100644 --- a/tests/test_comprehend/test_comprehend.py +++ b/tests/test_comprehend/test_comprehend.py @@ -2,6 +2,7 @@ import boto3 import pytest from botocore.exceptions import ClientError + from moto import mock_comprehend from moto.comprehend.models import ( CANNED_DETECT_RESPONSE, diff --git a/tests/test_config/test_config.py b/tests/test_config/test_config.py index 4b66d951a..c15b62a14 100644 --- a/tests/test_config/test_config.py +++ b/tests/test_config/test_config.py @@ -2,12 +2,12 @@ import json import os import time from datetime import datetime, timedelta +from unittest import SkipTest import boto3 +import pytest from botocore.config import Config from botocore.exceptions import ClientError -from unittest import SkipTest -import pytest from moto import mock_s3 from moto.config import mock_config diff --git a/tests/test_config/test_config_rules.py b/tests/test_config/test_config_rules.py index 35dba4b11..4a8bb0bc7 100644 --- a/tests/test_config/test_config_rules.py +++ b/tests/test_config/test_config_rules.py @@ -9,12 +9,12 @@ import json from string import ascii_lowercase import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError -from moto.config import mock_config -from moto.config.models import ConfigRule, CONFIG_RULE_PAGE_SIZE from moto import settings +from moto.config import mock_config +from moto.config.models import CONFIG_RULE_PAGE_SIZE, ConfigRule from moto.moto_api._internal import mock_random TEST_REGION = "us-east-1" if settings.TEST_SERVER_MODE else "us-west-2" diff --git a/tests/test_config/test_config_rules_integration.py b/tests/test_config/test_config_rules_integration.py index 98fe559a2..e409f5a18 100644 --- a/tests/test_config/test_config_rules_integration.py +++ b/tests/test_config/test_config_rules_integration.py @@ -1,14 +1,16 @@ -from .test_config_rules import managed_config_rule, TEST_REGION -from botocore.exceptions import ClientError -from moto import mock_config, mock_iam, mock_lambda -from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID +import json from io import BytesIO from uuid import uuid4 -from zipfile import ZipFile, ZIP_DEFLATED +from zipfile import ZIP_DEFLATED, ZipFile import boto3 -import json import pytest +from botocore.exceptions import ClientError + +from moto import mock_config, mock_iam, mock_lambda +from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID + +from .test_config_rules import TEST_REGION, managed_config_rule def custom_config_rule(func_name="test_config_rule"): diff --git a/tests/test_config/test_config_tags.py b/tests/test_config/test_config_tags.py index 67297fb90..856100df6 100644 --- a/tests/test_config/test_config_tags.py +++ b/tests/test_config/test_config_tags.py @@ -7,9 +7,8 @@ """ import boto3 -from botocore.exceptions import ClientError -from botocore.exceptions import ParamValidationError import pytest +from botocore.exceptions import ClientError, ParamValidationError from moto.config import mock_config from moto.config.models import MAX_TAGS_IN_ARG diff --git a/tests/test_core/test_account_id_resolution.py b/tests/test_core/test_account_id_resolution.py index fd42c9022..4f008ca24 100644 --- a/tests/test_core/test_account_id_resolution.py +++ b/tests/test_core/test_account_id_resolution.py @@ -1,4 +1,5 @@ import os +from unittest import SkipTest import requests import xmltodict @@ -6,8 +7,6 @@ import xmltodict from moto import settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.server import ThreadedMotoServer -from unittest import SkipTest - SERVER_PORT = 5001 BASE_URL = f"http://localhost:{SERVER_PORT}/" diff --git a/tests/test_core/test_auth.py b/tests/test_core/test_auth.py index 8aceb2cf5..04b77ce14 100644 --- a/tests/test_core/test_auth.py +++ b/tests/test_core/test_auth.py @@ -1,14 +1,13 @@ import json +from uuid import uuid4 import boto3 +import pytest from botocore.exceptions import ClientError -import pytest - -from moto import mock_iam, mock_ec2, mock_s3, mock_sts, mock_ssm, mock_elbv2, mock_rds -from moto.core import set_initial_no_auth_action_count +from moto import mock_ec2, mock_elbv2, mock_iam, mock_rds, mock_s3, mock_ssm, mock_sts from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from uuid import uuid4 +from moto.core import set_initial_no_auth_action_count @mock_iam diff --git a/tests/test_core/test_backenddict.py b/tests/test_core/test_backenddict.py index afe1e930b..e56a5a8d3 100644 --- a/tests/test_core/test_backenddict.py +++ b/tests/test_core/test_backenddict.py @@ -1,16 +1,15 @@ import random import time +from threading import Thread + import pytest -from moto.core import BaseBackend, BackendDict, DEFAULT_ACCOUNT_ID -from moto.core.base_backend import AccountSpecificBackend - from moto.autoscaling.models import AutoScalingBackend +from moto.core import DEFAULT_ACCOUNT_ID, BackendDict, BaseBackend +from moto.core.base_backend import AccountSpecificBackend from moto.ec2.models import EC2Backend from moto.elbv2.models import ELBv2Backend -from threading import Thread - class ExampleBackend(BaseBackend): def __init__(self, region_name, account_id): diff --git a/tests/test_core/test_context_manager.py b/tests/test_core/test_context_manager.py index 68ee52736..f471716ae 100644 --- a/tests/test_core/test_context_manager.py +++ b/tests/test_core/test_context_manager.py @@ -1,4 +1,5 @@ import boto3 + from moto import mock_sqs, settings from tests import DEFAULT_ACCOUNT_ID diff --git a/tests/test_core/test_decorator_calls.py b/tests/test_core/test_decorator_calls.py index b04256d30..30a0c6479 100644 --- a/tests/test_core/test_decorator_calls.py +++ b/tests/test_core/test_decorator_calls.py @@ -1,11 +1,12 @@ +import unittest +from typing import Any +from unittest import SkipTest + import boto3 import pytest -import unittest - from botocore.exceptions import ClientError -from typing import Any + from moto import mock_ec2, mock_kinesis, mock_s3, settings -from unittest import SkipTest """ Test the different ways that the decorator can be used diff --git a/tests/test_core/test_ec2_vpc_endpoint_services.py b/tests/test_core/test_ec2_vpc_endpoint_services.py index 8b345d9c2..8813067b1 100644 --- a/tests/test_core/test_ec2_vpc_endpoint_services.py +++ b/tests/test_core/test_ec2_vpc_endpoint_services.py @@ -3,9 +3,8 @@ # # There are some issues with running these tests in parallel # Running them as part of 'moto/core' avoids that problem -import pytest - import boto3 +import pytest from botocore.exceptions import ClientError from moto import mock_ec2 diff --git a/tests/test_core/test_environ_patching.py b/tests/test_core/test_environ_patching.py index 5f21d9b9c..b852443da 100644 --- a/tests/test_core/test_environ_patching.py +++ b/tests/test_core/test_environ_patching.py @@ -1,4 +1,5 @@ import os + from moto import mock_ec2, mock_s3 KEY = "AWS_ACCESS_KEY_ID" diff --git a/tests/test_core/test_importorder.py b/tests/test_core/test_importorder.py index af704aa2c..504374060 100644 --- a/tests/test_core/test_importorder.py +++ b/tests/test_core/test_importorder.py @@ -3,8 +3,7 @@ from unittest import SkipTest import boto3 import pytest -from moto import mock_s3 -from moto import settings +from moto import mock_s3, settings @pytest.fixture(scope="function", name="aws_credentials") diff --git a/tests/test_core/test_mock_regions.py b/tests/test_core/test_mock_regions.py index 24e487d87..7128b5b67 100644 --- a/tests/test_core/test_mock_regions.py +++ b/tests/test_core/test_mock_regions.py @@ -1,9 +1,10 @@ -import boto3 -from unittest import mock import os +from unittest import SkipTest, mock + +import boto3 import pytest + from moto import mock_dynamodb, mock_sns, settings -from unittest import SkipTest @mock_sns diff --git a/tests/test_core/test_moto_api.py b/tests/test_core/test_moto_api.py index 00badcb3b..cbe9971a6 100644 --- a/tests/test_core/test_moto_api.py +++ b/tests/test_core/test_moto_api.py @@ -1,12 +1,13 @@ -import requests +import json +from unittest import SkipTest, TestCase import boto3 -import json import pytest +import requests from botocore.exceptions import ClientError + from moto import mock_autoscaling, mock_s3, mock_sqs, settings from moto.core.model_instances import model_data, reset_model_data -from unittest import SkipTest, TestCase base_url = ( "http://localhost:5000" diff --git a/tests/test_core/test_nested.py b/tests/test_core/test_nested.py index bd2ee0d9a..f0acb9aee 100644 --- a/tests/test_core/test_nested.py +++ b/tests/test_core/test_nested.py @@ -1,7 +1,8 @@ -import boto3 import unittest -from moto import mock_sqs, mock_ec2 +import boto3 + +from moto import mock_ec2, mock_sqs from tests import EXAMPLE_AMI_ID diff --git a/tests/test_core/test_request_mocking.py b/tests/test_core/test_request_mocking.py index 701a34296..40a47f45e 100644 --- a/tests/test_core/test_request_mocking.py +++ b/tests/test_core/test_request_mocking.py @@ -1,8 +1,8 @@ -import requests -import pytest - import boto3 -from moto import mock_s3, mock_sts, mock_sqs, settings +import pytest +import requests + +from moto import mock_s3, mock_sqs, mock_sts, settings @mock_sqs diff --git a/tests/test_core/test_responses.py b/tests/test_core/test_responses.py index d33edb8ce..173f0c49d 100644 --- a/tests/test_core/test_responses.py +++ b/tests/test_core/test_responses.py @@ -1,17 +1,15 @@ import datetime -from unittest import SkipTest, mock - from collections import OrderedDict from gzip import compress as gzip_compress +from unittest import SkipTest, mock from botocore.awsrequest import AWSPreparedRequest - -from moto.core.responses import AWSServiceSpec, BaseResponse -from moto.core.responses import flatten_json_request_body -from moto.s3.responses import S3Response -from moto import settings from freezegun import freeze_time +from moto import settings +from moto.core.responses import AWSServiceSpec, BaseResponse, flatten_json_request_body +from moto.s3.responses import S3Response + def test_flatten_json_request_body(): spec = AWSServiceSpec("data/emr/2009-03-31/service-2.json").input_spec("RunJobFlow") diff --git a/tests/test_core/test_responses_module.py b/tests/test_core/test_responses_module.py index fc22ee79a..eb89dea48 100644 --- a/tests/test_core/test_responses_module.py +++ b/tests/test_core/test_responses_module.py @@ -2,14 +2,16 @@ Ensure that the responses module plays nice with our mocks """ +from unittest import SkipTest, TestCase + import boto3 import requests import responses + from moto import mock_dynamodb, mock_s3, settings from moto.core.models import override_responses_real_send from moto.core.versions import RESPONSES_VERSION from moto.utilities.distutils_version import LooseVersion -from unittest import SkipTest, TestCase class TestResponsesModule(TestCase): diff --git a/tests/test_core/test_server.py b/tests/test_core/test_server.py index cf25afc1c..9f847e552 100644 --- a/tests/test_core/test_server.py +++ b/tests/test_core/test_server.py @@ -1,5 +1,6 @@ from unittest.mock import patch -from moto.server import main, create_backend_app, DomainDispatcherApplication + +from moto.server import DomainDispatcherApplication, create_backend_app, main def test_wrong_arguments(): diff --git a/tests/test_core/test_settings.py b/tests/test_core/test_settings.py index ac5862c93..ce2d4b777 100644 --- a/tests/test_core/test_settings.py +++ b/tests/test_core/test_settings.py @@ -1,10 +1,10 @@ import os from unittest import mock + import pytest from moto import settings - """ Sanity checks for interpretation of the MOTO_ECS_NEW_ARN-variable """ diff --git a/tests/test_core/test_socket.py b/tests/test_core/test_socket.py index f3ade2096..d68592fe5 100644 --- a/tests/test_core/test_socket.py +++ b/tests/test_core/test_socket.py @@ -1,6 +1,7 @@ -import unittest -from moto import mock_dynamodb import socket +import unittest + +from moto import mock_dynamodb class TestSocketPair(unittest.TestCase): diff --git a/tests/test_core/test_url_base_regex.py b/tests/test_core/test_url_base_regex.py index 1103d539d..80ab86646 100644 --- a/tests/test_core/test_url_base_regex.py +++ b/tests/test_core/test_url_base_regex.py @@ -1,8 +1,8 @@ import boto3 -import moto import pytest -from moto import mock_s3 +import moto +from moto import mock_s3 service_names = [ (d[5:], "") diff --git a/tests/test_core/test_utils.py b/tests/test_core/test_utils.py index 4186f2117..916b37ec0 100644 --- a/tests/test_core/test_utils.py +++ b/tests/test_core/test_utils.py @@ -2,11 +2,11 @@ import pytest from freezegun import freeze_time from moto.core.utils import ( + camelcase_to_pascal, camelcase_to_underscores, + pascal_to_camelcase, underscores_to_camelcase, unix_time, - camelcase_to_pascal, - pascal_to_camelcase, ) diff --git a/tests/test_databrew/test_databrew_recipes.py b/tests/test_databrew/test_databrew_recipes.py index c77803e1a..ba22b46ce 100644 --- a/tests/test_databrew/test_databrew_recipes.py +++ b/tests/test_databrew/test_databrew_recipes.py @@ -1,9 +1,9 @@ import uuid +from datetime import datetime import boto3 import pytest from botocore.exceptions import ClientError -from datetime import datetime from moto import mock_databrew diff --git a/tests/test_datapipeline/test_datapipeline_cloudformation.py b/tests/test_datapipeline/test_datapipeline_cloudformation.py index 2760fdfdc..7af5b6fd6 100644 --- a/tests/test_datapipeline/test_datapipeline_cloudformation.py +++ b/tests/test_datapipeline/test_datapipeline_cloudformation.py @@ -1,6 +1,6 @@ -import boto3 import json +import boto3 from moto import mock_cloudformation, mock_datapipeline diff --git a/tests/test_datasync/test_datasync.py b/tests/test_datasync/test_datasync.py index 00f1460be..8dbaabca8 100644 --- a/tests/test_datasync/test_datasync.py +++ b/tests/test_datasync/test_datasync.py @@ -1,6 +1,7 @@ import boto3 import pytest from botocore.exceptions import ClientError + from moto import mock_datasync diff --git a/tests/test_dax/test_dax.py b/tests/test_dax/test_dax.py index 31a2a5c25..770547ab1 100644 --- a/tests/test_dax/test_dax.py +++ b/tests/test_dax/test_dax.py @@ -6,7 +6,6 @@ from botocore.exceptions import ClientError from moto import mock_dax from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID - # See our Development Tips on writing tests for hints on how to write good tests: # http://docs.getmoto.org/en/latest/docs/contributing/development_tips/tests.html diff --git a/tests/test_dms/test_dms.py b/tests/test_dms/test_dms.py index 4c15a7a06..f0f4df08f 100644 --- a/tests/test_dms/test_dms.py +++ b/tests/test_dms/test_dms.py @@ -1,7 +1,8 @@ -from botocore.exceptions import ClientError +import json + import boto3 import pytest -import json +from botocore.exceptions import ClientError from moto import mock_dms diff --git a/tests/test_ds/test_ds.py b/tests/test_ds/test_ds.py index a8c772862..a336b48dd 100644 --- a/tests/test_ds/test_ds.py +++ b/tests/test_ds/test_ds.py @@ -6,14 +6,14 @@ common to the other directory types. from datetime import datetime, timezone import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_ds from moto.ec2 import mock_ec2 from moto.moto_api._internal import mock_random -from .test_ds_simple_ad_directory import create_test_directory, TEST_REGION +from .test_ds_simple_ad_directory import TEST_REGION, create_test_directory @mock_ec2 diff --git a/tests/test_ds/test_ds_ad_connect.py b/tests/test_ds/test_ds_ad_connect.py index c2fd33c2e..d042c975b 100644 --- a/tests/test_ds/test_ds_ad_connect.py +++ b/tests/test_ds/test_ds_ad_connect.py @@ -6,14 +6,14 @@ The logic to check the details of VPCs and Subnets is shared between the from datetime import datetime, timezone import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_ds from moto.ec2 import mock_ec2 from moto.moto_api._internal import mock_random -from .test_ds_simple_ad_directory import TEST_REGION, create_vpc, create_subnets +from .test_ds_simple_ad_directory import TEST_REGION, create_subnets, create_vpc def create_test_ad_connector( diff --git a/tests/test_ds/test_ds_microsoft_ad.py b/tests/test_ds/test_ds_microsoft_ad.py index ff28362fe..26fe86e81 100644 --- a/tests/test_ds/test_ds_microsoft_ad.py +++ b/tests/test_ds/test_ds_microsoft_ad.py @@ -6,14 +6,14 @@ The logic to check the details of VPCs and Subnets is shared between the from datetime import datetime, timezone import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_ds from moto.ec2 import mock_ec2 from moto.moto_api._internal import mock_random -from .test_ds_simple_ad_directory import TEST_REGION, create_vpc, create_subnets +from .test_ds_simple_ad_directory import TEST_REGION, create_subnets, create_vpc def create_test_microsoft_ad(ds_client, ec2_client, vpc_settings=None, tags=None): diff --git a/tests/test_ds/test_ds_simple_ad_directory.py b/tests/test_ds/test_ds_simple_ad_directory.py index 8ac856bce..c409aec1e 100644 --- a/tests/test_ds/test_ds_simple_ad_directory.py +++ b/tests/test_ds/test_ds_simple_ad_directory.py @@ -1,10 +1,9 @@ """Directory-related unit tests for Simple AD Directory Services.""" import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError -from moto import mock_ds -from moto import settings +from moto import mock_ds, settings from moto.ec2 import mock_ec2 from moto.moto_api._internal import mock_random diff --git a/tests/test_ds/test_ds_tags.py b/tests/test_ds/test_ds_tags.py index 31efd4eb9..a6a3032e8 100644 --- a/tests/test_ds/test_ds_tags.py +++ b/tests/test_ds/test_ds_tags.py @@ -4,14 +4,14 @@ Simple AD directories are used for test data, but the operations are common to the other directory types. """ import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_ds from moto.ds.models import Directory from moto.ec2 import mock_ec2 -from .test_ds_simple_ad_directory import create_test_directory, TEST_REGION +from .test_ds_simple_ad_directory import TEST_REGION, create_test_directory @mock_ec2 diff --git a/tests/test_dynamodb/__init__.py b/tests/test_dynamodb/__init__.py index fe46e5127..df8354a72 100644 --- a/tests/test_dynamodb/__init__.py +++ b/tests/test_dynamodb/__init__.py @@ -1,9 +1,11 @@ -import boto3 import os from functools import wraps -from moto import mock_dynamodb from uuid import uuid4 +import boto3 + +from moto import mock_dynamodb + def dynamodb_aws_verified(create_table: bool = True): """ diff --git a/tests/test_dynamodb/conftest.py b/tests/test_dynamodb/conftest.py index 63b1c950e..04d975c2b 100644 --- a/tests/test_dynamodb/conftest.py +++ b/tests/test_dynamodb/conftest.py @@ -1,4 +1,5 @@ import pytest + from moto.core import DEFAULT_ACCOUNT_ID from moto.dynamodb.models import Table diff --git a/tests/test_dynamodb/exceptions/test_dynamodb_exceptions.py b/tests/test_dynamodb/exceptions/test_dynamodb_exceptions.py index ffca7dab2..e1bbc0c5c 100644 --- a/tests/test_dynamodb/exceptions/test_dynamodb_exceptions.py +++ b/tests/test_dynamodb/exceptions/test_dynamodb_exceptions.py @@ -1,10 +1,13 @@ +from unittest import SkipTest + import boto3 import botocore import pytest from boto3.dynamodb.conditions import Key from botocore.exceptions import ClientError -from unittest import SkipTest + from moto import mock_dynamodb, settings + from .. import dynamodb_aws_verified table_schema = { diff --git a/tests/test_dynamodb/exceptions/test_key_length_exceptions.py b/tests/test_dynamodb/exceptions/test_key_length_exceptions.py index 90c200855..8cf7b1c68 100644 --- a/tests/test_dynamodb/exceptions/test_key_length_exceptions.py +++ b/tests/test_dynamodb/exceptions/test_key_length_exceptions.py @@ -1,9 +1,9 @@ import boto3 import pytest +from boto3.dynamodb.conditions import Key +from botocore.exceptions import ClientError from moto import mock_dynamodb -from botocore.exceptions import ClientError -from boto3.dynamodb.conditions import Key from moto.dynamodb.limits import HASH_KEY_MAX_LENGTH, RANGE_KEY_MAX_LENGTH diff --git a/tests/test_dynamodb/models/test_item.py b/tests/test_dynamodb/models/test_item.py index e26a3375a..5c328585c 100644 --- a/tests/test_dynamodb/models/test_item.py +++ b/tests/test_dynamodb/models/test_item.py @@ -1,5 +1,4 @@ -from moto.dynamodb.models.dynamo_type import DynamoType, Item -from moto.dynamodb.models.dynamo_type import serializer +from moto.dynamodb.models.dynamo_type import DynamoType, Item, serializer class TestFindNestedKeys: diff --git a/tests/test_dynamodb/models/test_key_condition_expression_parser.py b/tests/test_dynamodb/models/test_key_condition_expression_parser.py index 1c502e9d2..30545a3d6 100644 --- a/tests/test_dynamodb/models/test_key_condition_expression_parser.py +++ b/tests/test_dynamodb/models/test_key_condition_expression_parser.py @@ -1,4 +1,5 @@ import pytest + from moto.dynamodb.exceptions import DynamodbException from moto.dynamodb.parsing.key_condition_expression import parse_expression diff --git a/tests/test_dynamodb/test_dynamodb.py b/tests/test_dynamodb/test_dynamodb.py index 8c8b186d2..65bad216f 100644 --- a/tests/test_dynamodb/test_dynamodb.py +++ b/tests/test_dynamodb/test_dynamodb.py @@ -1,19 +1,20 @@ -import boto3 -import pytest -import uuid import re -from botocore.exceptions import ClientError +import uuid from datetime import datetime from decimal import Decimal +import boto3 +import pytest from boto3.dynamodb.conditions import Attr, Key from boto3.dynamodb.types import Binary +from botocore.exceptions import ClientError + +import moto.dynamodb.comparisons +import moto.dynamodb.models from moto import mock_dynamodb, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.dynamodb import dynamodb_backends -import moto.dynamodb.comparisons -import moto.dynamodb.models from . import dynamodb_aws_verified diff --git a/tests/test_dynamodb/test_dynamodb_batch_get_item.py b/tests/test_dynamodb/test_dynamodb_batch_get_item.py index fa75e92ac..f98ed1013 100644 --- a/tests/test_dynamodb/test_dynamodb_batch_get_item.py +++ b/tests/test_dynamodb/test_dynamodb_batch_get_item.py @@ -1,8 +1,8 @@ import boto3 import pytest +from botocore.exceptions import ClientError from moto import mock_dynamodb -from botocore.exceptions import ClientError def _create_user_table(): diff --git a/tests/test_dynamodb/test_dynamodb_cloudformation.py b/tests/test_dynamodb/test_dynamodb_cloudformation.py index 9a4c4415a..03222cc0a 100644 --- a/tests/test_dynamodb/test_dynamodb_cloudformation.py +++ b/tests/test_dynamodb/test_dynamodb_cloudformation.py @@ -1,8 +1,8 @@ -import boto3 import json -from moto import mock_cloudformation, mock_dynamodb +import boto3 +from moto import mock_cloudformation, mock_dynamodb template_create_table = { "AWSTemplateFormatVersion": "2010-09-09", diff --git a/tests/test_dynamodb/test_dynamodb_condition_expressions.py b/tests/test_dynamodb/test_dynamodb_condition_expressions.py index 57f2a2ebb..d05d21f6c 100644 --- a/tests/test_dynamodb/test_dynamodb_condition_expressions.py +++ b/tests/test_dynamodb/test_dynamodb_condition_expressions.py @@ -1,8 +1,9 @@ -from decimal import Decimal import re +from decimal import Decimal import boto3 import pytest + from moto import mock_dynamodb diff --git a/tests/test_dynamodb/test_dynamodb_consumedcapacity.py b/tests/test_dynamodb/test_dynamodb_consumedcapacity.py index ae69427d6..9db70daca 100644 --- a/tests/test_dynamodb/test_dynamodb_consumedcapacity.py +++ b/tests/test_dynamodb/test_dynamodb_consumedcapacity.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_dynamodb diff --git a/tests/test_dynamodb/test_dynamodb_create_table.py b/tests/test_dynamodb/test_dynamodb_create_table.py index c659ca22b..1d2e382d7 100644 --- a/tests/test_dynamodb/test_dynamodb_create_table.py +++ b/tests/test_dynamodb/test_dynamodb_create_table.py @@ -1,7 +1,8 @@ -import boto3 -from botocore.exceptions import ClientError from datetime import datetime + +import boto3 import pytest +from botocore.exceptions import ClientError from moto import mock_dynamodb from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_dynamodb/test_dynamodb_executor.py b/tests/test_dynamodb/test_dynamodb_executor.py index caed8b2cd..e176c51bb 100644 --- a/tests/test_dynamodb/test_dynamodb_executor.py +++ b/tests/test_dynamodb/test_dynamodb_executor.py @@ -1,11 +1,11 @@ import pytest -from moto.dynamodb.exceptions import IncorrectOperandType, IncorrectDataType -from moto.dynamodb.models import Item, DynamoType +from moto.dynamodb.exceptions import IncorrectDataType, IncorrectOperandType +from moto.dynamodb.models import DynamoType, Item from moto.dynamodb.parsing.ast_nodes import ( UpdateExpression, - UpdateExpressionAddClause, UpdateExpressionAddAction, + UpdateExpressionAddClause, UpdateExpressionRemoveAction, UpdateExpressionSetAction, ) diff --git a/tests/test_dynamodb/test_dynamodb_expression_tokenizer.py b/tests/test_dynamodb/test_dynamodb_expression_tokenizer.py index 08c274f31..72c721ac3 100644 --- a/tests/test_dynamodb/test_dynamodb_expression_tokenizer.py +++ b/tests/test_dynamodb/test_dynamodb_expression_tokenizer.py @@ -1,8 +1,8 @@ import pytest from moto.dynamodb.exceptions import ( - InvalidTokenException, InvalidExpressionAttributeNameKey, + InvalidTokenException, ) from moto.dynamodb.parsing.tokens import ExpressionTokenizer, Token diff --git a/tests/test_dynamodb/test_dynamodb_statements.py b/tests/test_dynamodb/test_dynamodb_statements.py index a5cda8e0c..7cacb6a0a 100644 --- a/tests/test_dynamodb/test_dynamodb_statements.py +++ b/tests/test_dynamodb/test_dynamodb_statements.py @@ -1,12 +1,12 @@ +from unittest import TestCase + import boto3 import pytest from moto import mock_dynamodb -from unittest import TestCase from . import dynamodb_aws_verified - item1 = { "pk": {"S": "msg1"}, "body": {"S": "some text"}, diff --git a/tests/test_dynamodb/test_dynamodb_table_with_range_key.py b/tests/test_dynamodb/test_dynamodb_table_with_range_key.py index addcf3199..48cd2b8a1 100644 --- a/tests/test_dynamodb/test_dynamodb_table_with_range_key.py +++ b/tests/test_dynamodb/test_dynamodb_table_with_range_key.py @@ -1,12 +1,12 @@ from decimal import Decimal +from uuid import uuid4 import boto3 +import pytest from boto3.dynamodb.conditions import Key from botocore.exceptions import ClientError -import pytest from moto import mock_dynamodb -from uuid import uuid4 @mock_dynamodb diff --git a/tests/test_dynamodb/test_dynamodb_table_without_range_key.py b/tests/test_dynamodb/test_dynamodb_table_without_range_key.py index 99ded99ea..461bc83db 100644 --- a/tests/test_dynamodb/test_dynamodb_table_without_range_key.py +++ b/tests/test_dynamodb/test_dynamodb_table_without_range_key.py @@ -1,8 +1,10 @@ +from datetime import datetime + import boto3 import pytest from boto3.dynamodb.conditions import Key -from datetime import datetime from botocore.exceptions import ClientError + from moto import mock_dynamodb from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_dynamodb/test_dynamodb_update_expressions.py b/tests/test_dynamodb/test_dynamodb_update_expressions.py index 74ce504bc..e37b79c09 100644 --- a/tests/test_dynamodb/test_dynamodb_update_expressions.py +++ b/tests/test_dynamodb/test_dynamodb_update_expressions.py @@ -1,4 +1,5 @@ import boto3 + from moto import mock_dynamodb diff --git a/tests/test_dynamodb/test_dynamodb_validation.py b/tests/test_dynamodb/test_dynamodb_validation.py index 56aacbe59..3d89c6c3f 100644 --- a/tests/test_dynamodb/test_dynamodb_validation.py +++ b/tests/test_dynamodb/test_dynamodb_validation.py @@ -1,18 +1,18 @@ import pytest from moto.dynamodb.exceptions import ( - AttributeIsReservedKeyword, - ExpressionAttributeValueNotDefined, AttributeDoesNotExist, + AttributeIsReservedKeyword, ExpressionAttributeNameNotDefined, + ExpressionAttributeValueNotDefined, IncorrectOperandType, InvalidUpdateExpressionInvalidDocumentPath, ) -from moto.dynamodb.models import Item, DynamoType +from moto.dynamodb.models import DynamoType, Item from moto.dynamodb.parsing.ast_nodes import ( + DDBTypedValue, NodeDepthLeftTypeFetcher, UpdateExpressionSetAction, - DDBTypedValue, ) from moto.dynamodb.parsing.expressions import UpdateExpressionParser from moto.dynamodb.parsing.validators import UpdateExpressionValidator diff --git a/tests/test_dynamodb/test_server.py b/tests/test_dynamodb/test_server.py index ef0a30c35..b3ee10526 100644 --- a/tests/test_dynamodb/test_server.py +++ b/tests/test_dynamodb/test_server.py @@ -1,6 +1,7 @@ import json -from moto import mock_dynamodb + import moto.server as server +from moto import mock_dynamodb """ Test the different server responses diff --git a/tests/test_dynamodb_v20111205/test_server.py b/tests/test_dynamodb_v20111205/test_server.py index e544a8981..3ba559cba 100644 --- a/tests/test_dynamodb_v20111205/test_server.py +++ b/tests/test_dynamodb_v20111205/test_server.py @@ -1,4 +1,5 @@ import json + import pytest import moto.server as server diff --git a/tests/test_dynamodb_v20111205/test_servermode.py b/tests/test_dynamodb_v20111205/test_servermode.py index 692ddf7c2..9b4d0d00d 100644 --- a/tests/test_dynamodb_v20111205/test_servermode.py +++ b/tests/test_dynamodb_v20111205/test_servermode.py @@ -1,9 +1,10 @@ import json +from unittest import SkipTest +from uuid import uuid4 + import requests from moto import settings -from unittest import SkipTest -from uuid import uuid4 """ Test the different server responses diff --git a/tests/test_dynamodbstreams/test_dynamodbstreams.py b/tests/test_dynamodbstreams/test_dynamodbstreams.py index 00494ea73..a0d8959b4 100644 --- a/tests/test_dynamodbstreams/test_dynamodbstreams.py +++ b/tests/test_dynamodbstreams/test_dynamodbstreams.py @@ -1,6 +1,6 @@ +import boto3 import pytest -import boto3 from moto import mock_dynamodb, mock_dynamodbstreams diff --git a/tests/test_ebs/test_ebs.py b/tests/test_ebs/test_ebs.py index 06cc49dfc..ee039a23c 100644 --- a/tests/test_ebs/test_ebs.py +++ b/tests/test_ebs/test_ebs.py @@ -1,6 +1,8 @@ """Unit tests for ebs-supported APIs.""" -import boto3 import hashlib + +import boto3 + from moto import mock_ebs, mock_ec2 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_ec2/__init__.py b/tests/test_ec2/__init__.py index 3e0ec5ea0..e3a730d82 100644 --- a/tests/test_ec2/__init__.py +++ b/tests/test_ec2/__init__.py @@ -1,5 +1,6 @@ import os from functools import wraps + from moto import mock_ec2, mock_ssm diff --git a/tests/test_ec2/helpers.py b/tests/test_ec2/helpers.py index 00a3b9efb..4fdb0c9c9 100644 --- a/tests/test_ec2/helpers.py +++ b/tests/test_ec2/helpers.py @@ -1,6 +1,6 @@ from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import serialization -from cryptography.hazmat.primitives.asymmetric import rsa, ed25519 +from cryptography.hazmat.primitives.asymmetric import ed25519, rsa def check_private_key(private_key_material, key_type): diff --git a/tests/test_ec2/test_account_attributes.py b/tests/test_ec2/test_account_attributes.py index e9465904b..f89b4f3d3 100644 --- a/tests/test_ec2/test_account_attributes.py +++ b/tests/test_ec2/test_account_attributes.py @@ -1,4 +1,5 @@ import boto3 + from moto import mock_ec2 diff --git a/tests/test_ec2/test_amis.py b/tests/test_ec2/test_amis.py index 47dcd6c2e..018247e56 100644 --- a/tests/test_ec2/test_amis.py +++ b/tests/test_ec2/test_amis.py @@ -1,15 +1,16 @@ -import boto3 import os -import pytest import random +from unittest import SkipTest, mock +from uuid import uuid4 + +import boto3 +import pytest +from botocore.exceptions import ClientError from moto import mock_ec2, settings -from moto.ec2.models.amis import AMIS from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from botocore.exceptions import ClientError +from moto.ec2.models.amis import AMIS from tests import EXAMPLE_AMI_ID, EXAMPLE_AMI_PARAVIRTUAL -from unittest import mock, SkipTest -from uuid import uuid4 # The default AMIs are not loaded for our test case, to speed things up diff --git a/tests/test_ec2/test_availability_zones_and_regions.py b/tests/test_ec2/test_availability_zones_and_regions.py index d63d21ec7..7d593bdd5 100644 --- a/tests/test_ec2/test_availability_zones_and_regions.py +++ b/tests/test_ec2/test_availability_zones_and_regions.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_ec2 diff --git a/tests/test_ec2/test_carrier_gateways.py b/tests/test_ec2/test_carrier_gateways.py index d33f166c3..4dbcda440 100644 --- a/tests/test_ec2/test_carrier_gateways.py +++ b/tests/test_ec2/test_carrier_gateways.py @@ -1,9 +1,11 @@ +from unittest import SkipTest + import boto3 import pytest from botocore.exceptions import ClientError + from moto import mock_ec2, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from unittest import SkipTest @mock_ec2 diff --git a/tests/test_ec2/test_customer_gateways.py b/tests/test_ec2/test_customer_gateways.py index 37b96028a..769b1821d 100644 --- a/tests/test_ec2/test_customer_gateways.py +++ b/tests/test_ec2/test_customer_gateways.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_ec2 diff --git a/tests/test_ec2/test_dhcp_options.py b/tests/test_ec2/test_dhcp_options.py index 7910c0c81..45e6cf0c9 100644 --- a/tests/test_ec2/test_dhcp_options.py +++ b/tests/test_ec2/test_dhcp_options.py @@ -1,13 +1,12 @@ -import pytest - -import boto3 -from botocore.exceptions import ClientError - import random import uuid +from unittest import SkipTest + +import boto3 +import pytest +from botocore.exceptions import ClientError from moto import mock_ec2, settings -from unittest import SkipTest SAMPLE_DOMAIN_NAME = "example.com" SAMPLE_NAME_SERVERS = ["10.0.0.6", "10.0.0.7"] diff --git a/tests/test_ec2/test_ec2_cloudformation.py b/tests/test_ec2/test_ec2_cloudformation.py index d17b36c0b..f2872a722 100644 --- a/tests/test_ec2/test_ec2_cloudformation.py +++ b/tests/test_ec2/test_ec2_cloudformation.py @@ -1,16 +1,19 @@ +import json +from uuid import uuid4 + +import boto3 +import pytest from botocore.exceptions import ClientError + from moto import mock_cloudformation, mock_ec2 from tests import EXAMPLE_AMI_ID -from tests.test_cloudformation.fixtures import ec2_classic_eip -from tests.test_cloudformation.fixtures import single_instance_with_ebs_volume -from tests.test_cloudformation.fixtures import vpc_eip -from tests.test_cloudformation.fixtures import vpc_eni -from tests.test_cloudformation.fixtures import vpc_single_instance_in_subnet -from uuid import uuid4 -import boto3 -import json -import pytest - +from tests.test_cloudformation.fixtures import ( + ec2_classic_eip, + single_instance_with_ebs_volume, + vpc_eip, + vpc_eni, + vpc_single_instance_in_subnet, +) template_vpc = { "AWSTemplateFormatVersion": "2010-09-09", diff --git a/tests/test_ec2/test_egress_only_igw.py b/tests/test_ec2/test_egress_only_igw.py index 425dd8bec..70fc8ee46 100644 --- a/tests/test_ec2/test_egress_only_igw.py +++ b/tests/test_ec2/test_egress_only_igw.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_ec2 diff --git a/tests/test_ec2/test_elastic_block_store.py b/tests/test_ec2/test_elastic_block_store.py index 28facc694..3a103fd13 100644 --- a/tests/test_ec2/test_elastic_block_store.py +++ b/tests/test_ec2/test_elastic_block_store.py @@ -1,14 +1,16 @@ -import boto3 import os +from unittest import SkipTest, mock +from uuid import uuid4 + +import boto3 import pytest from botocore.exceptions import ClientError + from moto import mock_ec2, settings from moto.core import DEFAULT_ACCOUNT_ID as OWNER_ID from moto.ec2.models.elastic_block_store import IOPS_REQUIRED_VOLUME_TYPES from moto.kms import mock_kms from tests import EXAMPLE_AMI_ID -from unittest import mock, SkipTest -from uuid import uuid4 @mock_ec2 diff --git a/tests/test_ec2/test_elastic_ip_addresses.py b/tests/test_ec2/test_elastic_ip_addresses.py index 9985b4735..ee607a023 100644 --- a/tests/test_ec2/test_elastic_ip_addresses.py +++ b/tests/test_ec2/test_elastic_ip_addresses.py @@ -1,8 +1,8 @@ -import pytest +from uuid import uuid4 import boto3 +import pytest from botocore.exceptions import ClientError -from uuid import uuid4 from moto import mock_ec2 from tests import EXAMPLE_AMI_ID diff --git a/tests/test_ec2/test_elastic_network_interfaces.py b/tests/test_ec2/test_elastic_network_interfaces.py index ff968f9fa..fc8dbde65 100644 --- a/tests/test_ec2/test_elastic_network_interfaces.py +++ b/tests/test_ec2/test_elastic_network_interfaces.py @@ -1,14 +1,14 @@ -import pytest import random +from uuid import uuid4 import boto3 +import pytest from botocore.exceptions import ClientError from moto import mock_ec2, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.ec2.utils import random_private_ip from tests import EXAMPLE_AMI_ID -from uuid import uuid4 @mock_ec2 diff --git a/tests/test_ec2/test_fleets.py b/tests/test_ec2/test_fleets.py index b63595411..a60548c85 100644 --- a/tests/test_ec2/test_fleets.py +++ b/tests/test_ec2/test_fleets.py @@ -1,9 +1,10 @@ +from uuid import uuid4 + import boto3 import pytest from moto import mock_ec2 from tests import EXAMPLE_AMI_ID -from uuid import uuid4 from . import ec2_aws_verified diff --git a/tests/test_ec2/test_flow_logs.py b/tests/test_ec2/test_flow_logs.py index df7377371..b47d4d5de 100644 --- a/tests/test_ec2/test_flow_logs.py +++ b/tests/test_ec2/test_flow_logs.py @@ -1,12 +1,11 @@ -import pytest +from uuid import uuid4 import boto3 - +import pytest from botocore.exceptions import ClientError -from moto import mock_ec2, mock_s3, mock_logs +from moto import mock_ec2, mock_logs, mock_s3 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from uuid import uuid4 @mock_s3 diff --git a/tests/test_ec2/test_flow_logs_cloudformation.py b/tests/test_ec2/test_flow_logs_cloudformation.py index ded2bcedb..ee64834ab 100644 --- a/tests/test_ec2/test_flow_logs_cloudformation.py +++ b/tests/test_ec2/test_flow_logs_cloudformation.py @@ -1,11 +1,11 @@ -import boto3 - import json +from uuid import uuid4 + +import boto3 from moto import mock_cloudformation, mock_ec2, mock_s3 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from tests import EXAMPLE_AMI_ID -from uuid import uuid4 @mock_cloudformation diff --git a/tests/test_ec2/test_general.py b/tests/test_ec2/test_general.py index 091e08fee..c5547ce28 100644 --- a/tests/test_ec2/test_general.py +++ b/tests/test_ec2/test_general.py @@ -1,6 +1,5 @@ -import pytest - import boto3 +import pytest from botocore.exceptions import ClientError from moto import mock_ec2 diff --git a/tests/test_ec2/test_hosts.py b/tests/test_ec2/test_hosts.py index ef2382153..aa65f3a7a 100644 --- a/tests/test_ec2/test_hosts.py +++ b/tests/test_ec2/test_hosts.py @@ -1,7 +1,8 @@ +from uuid import uuid4 + import boto3 from moto import mock_ec2 -from uuid import uuid4 @mock_ec2 diff --git a/tests/test_ec2/test_iam_integration.py b/tests/test_ec2/test_iam_integration.py index 01a7056a5..81fb41232 100644 --- a/tests/test_ec2/test_iam_integration.py +++ b/tests/test_ec2/test_iam_integration.py @@ -1,11 +1,11 @@ -import pytest +from uuid import uuid4 import boto3 +import pytest from botocore.exceptions import ClientError from moto import mock_ec2, mock_iam from tests import EXAMPLE_AMI_ID -from uuid import uuid4 def quick_instance_creation(): diff --git a/tests/test_ec2/test_instance_types.py b/tests/test_ec2/test_instance_types.py index 4ff9acfb8..18215cdc3 100644 --- a/tests/test_ec2/test_instance_types.py +++ b/tests/test_ec2/test_instance_types.py @@ -1,6 +1,5 @@ import boto3 import pytest - from botocore.exceptions import ClientError from moto import mock_ec2 diff --git a/tests/test_ec2/test_instances.py b/tests/test_ec2/test_instances.py index 2a6169068..0c6dcef8e 100644 --- a/tests/test_ec2/test_instances.py +++ b/tests/test_ec2/test_instances.py @@ -10,6 +10,7 @@ import boto3 import pytest from botocore.exceptions import ClientError, ParamValidationError from freezegun import freeze_time + from moto import mock_ec2, mock_iam, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from tests import EXAMPLE_AMI_ID diff --git a/tests/test_ec2/test_internet_gateways.py b/tests/test_ec2/test_internet_gateways.py index 80e480f55..454e58722 100644 --- a/tests/test_ec2/test_internet_gateways.py +++ b/tests/test_ec2/test_internet_gateways.py @@ -1,10 +1,10 @@ -import boto3 -import pytest - -from botocore.exceptions import ClientError -from moto import mock_ec2 from uuid import uuid4 +import boto3 +import pytest +from botocore.exceptions import ClientError + +from moto import mock_ec2 VPC_CIDR = "10.0.0.0/16" BAD_VPC = "vpc-deadbeef" diff --git a/tests/test_ec2/test_key_pairs.py b/tests/test_ec2/test_key_pairs.py index cf684fdf1..37988acdb 100644 --- a/tests/test_ec2/test_key_pairs.py +++ b/tests/test_ec2/test_key_pairs.py @@ -1,15 +1,15 @@ +from datetime import datetime +from unittest import SkipTest +from uuid import uuid4 + import boto3 import pytest - from botocore.exceptions import ClientError -from datetime import datetime + from moto import mock_ec2, settings -from uuid import uuid4 -from unittest import SkipTest from .helpers import check_private_key - ED25519_PUBLIC_KEY_OPENSSH = b"""\ ssh-ed25519 \ AAAAC3NzaC1lZDI1NTE5AAAAIEwsSB9HbTeKCdkSlMZeTq9jZggaPJUwAsUi/7wakB+B \ diff --git a/tests/test_ec2/test_launch_templates.py b/tests/test_ec2/test_launch_templates.py index 43508b5e3..44cdee397 100644 --- a/tests/test_ec2/test_launch_templates.py +++ b/tests/test_ec2/test_launch_templates.py @@ -1,10 +1,10 @@ -import boto3 -import pytest - -from botocore.client import ClientError -from moto import mock_ec2, settings from uuid import uuid4 +import boto3 +import pytest +from botocore.client import ClientError + +from moto import mock_ec2, settings from tests import EXAMPLE_AMI_ID diff --git a/tests/test_ec2/test_nat_gateway.py b/tests/test_ec2/test_nat_gateway.py index f94296650..4bb050377 100644 --- a/tests/test_ec2/test_nat_gateway.py +++ b/tests/test_ec2/test_nat_gateway.py @@ -1,7 +1,8 @@ +from unittest import SkipTest + import boto3 from moto import mock_ec2, settings -from unittest import SkipTest @mock_ec2 diff --git a/tests/test_ec2/test_network_acls.py b/tests/test_ec2/test_network_acls.py index 2766c4634..8e2f678f8 100644 --- a/tests/test_ec2/test_network_acls.py +++ b/tests/test_ec2/test_network_acls.py @@ -1,11 +1,12 @@ +from random import randint +from unittest import SkipTest + import boto3 import pytest from botocore.exceptions import ClientError from moto import mock_ec2, settings from moto.core import DEFAULT_ACCOUNT_ID as OWNER_ID -from random import randint -from unittest import SkipTest @mock_ec2 diff --git a/tests/test_ec2/test_regions.py b/tests/test_ec2/test_regions.py index f297935f7..db8bf37e4 100644 --- a/tests/test_ec2/test_regions.py +++ b/tests/test_ec2/test_regions.py @@ -1,11 +1,12 @@ +from uuid import uuid4 + import boto3 import pytest - from botocore.exceptions import ClientError -from moto import mock_autoscaling, mock_ec2, mock_elb +from moto import mock_autoscaling, mock_ec2, mock_elb from tests import EXAMPLE_AMI_ID, EXAMPLE_AMI_ID2 -from uuid import uuid4 + from .test_instances import retrieve_all_instances diff --git a/tests/test_ec2/test_route_tables.py b/tests/test_ec2/test_route_tables.py index 7952383dc..e2b8b8e75 100644 --- a/tests/test_ec2/test_route_tables.py +++ b/tests/test_ec2/test_route_tables.py @@ -1,10 +1,11 @@ +from uuid import uuid4 + import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_ec2, settings from tests import EXAMPLE_AMI_ID -from uuid import uuid4 @mock_ec2 diff --git a/tests/test_ec2/test_security_groups.py b/tests/test_ec2/test_security_groups.py index de3d11601..5ead9689b 100644 --- a/tests/test_ec2/test_security_groups.py +++ b/tests/test_ec2/test_security_groups.py @@ -1,17 +1,17 @@ -import boto3 import copy import json -import pytest import unittest +from random import randint +from unittest import SkipTest +from uuid import uuid4 +import boto3 +import pytest from botocore.exceptions import ClientError from moto import mock_ec2, settings from moto.core import DEFAULT_ACCOUNT_ID from moto.ec2 import ec2_backends -from random import randint -from uuid import uuid4 -from unittest import SkipTest @mock_ec2 diff --git a/tests/test_ec2/test_security_groups_cloudformation.py b/tests/test_ec2/test_security_groups_cloudformation.py index db467dd22..d2b6a7c5d 100644 --- a/tests/test_ec2/test_security_groups_cloudformation.py +++ b/tests/test_ec2/test_security_groups_cloudformation.py @@ -1,13 +1,13 @@ -import boto3 -import pytest import json -from moto import mock_cloudformation, mock_ec2 -from tests import EXAMPLE_AMI_ID from string import Template from uuid import uuid4 +import boto3 +import pytest from botocore.exceptions import ClientError +from moto import mock_cloudformation, mock_ec2 +from tests import EXAMPLE_AMI_ID SEC_GROUP_INGRESS = Template( """{ diff --git a/tests/test_ec2/test_server.py b/tests/test_ec2/test_server.py index 1061ea1dc..3010ec597 100644 --- a/tests/test_ec2/test_server.py +++ b/tests/test_ec2/test_server.py @@ -1,5 +1,6 @@ """Test the different server responses.""" import re + import xmltodict import moto.server as server diff --git a/tests/test_ec2/test_spot_fleet.py b/tests/test_ec2/test_spot_fleet.py index b9ad2d18d..13bc13265 100644 --- a/tests/test_ec2/test_spot_fleet.py +++ b/tests/test_ec2/test_spot_fleet.py @@ -1,11 +1,12 @@ +from uuid import uuid4 + import boto3 import pytest +from botocore.exceptions import ClientError from moto import mock_ec2 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from botocore.exceptions import ClientError from tests import EXAMPLE_AMI_ID -from uuid import uuid4 def get_subnet_id(conn): diff --git a/tests/test_ec2/test_spot_instances.py b/tests/test_ec2/test_spot_instances.py index ce30d999c..16d428052 100644 --- a/tests/test_ec2/test_spot_instances.py +++ b/tests/test_ec2/test_spot_instances.py @@ -1,14 +1,14 @@ -import pytest import datetime -import boto3 +from unittest import SkipTest +from uuid import uuid4 +import boto3 +import pytest from botocore.exceptions import ClientError from moto import mock_ec2, settings from moto.core.utils import iso_8601_datetime_with_milliseconds from tests import EXAMPLE_AMI_ID -from uuid import uuid4 -from unittest import SkipTest @mock_ec2 diff --git a/tests/test_ec2/test_subnets.py b/tests/test_ec2/test_subnets.py index 8dfe1f701..32ff55284 100644 --- a/tests/test_ec2/test_subnets.py +++ b/tests/test_ec2/test_subnets.py @@ -1,12 +1,13 @@ import random +from unittest import SkipTest +from uuid import uuid4 + import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_ec2, settings from tests import EXAMPLE_AMI_ID -from uuid import uuid4 -from unittest import SkipTest @mock_ec2 diff --git a/tests/test_ec2/test_tags.py b/tests/test_ec2/test_tags.py index 158cd98ec..b55856da9 100644 --- a/tests/test_ec2/test_tags.py +++ b/tests/test_ec2/test_tags.py @@ -1,12 +1,13 @@ +from uuid import uuid4 + import boto3 import pytest - from botocore.exceptions import ClientError -from moto import mock_ec2 +from moto import mock_ec2 from tests import EXAMPLE_AMI_ID + from .test_instances import retrieve_all_instances -from uuid import uuid4 @mock_ec2 diff --git a/tests/test_ec2/test_transit_gateway.py b/tests/test_ec2/test_transit_gateway.py index 7d1094a18..cc6f3baeb 100644 --- a/tests/test_ec2/test_transit_gateway.py +++ b/tests/test_ec2/test_transit_gateway.py @@ -1,9 +1,10 @@ +from unittest import SkipTest + import boto3 import pytest from moto import mock_ec2, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from unittest import SkipTest @mock_ec2 diff --git a/tests/test_ec2/test_transit_gateway_cloudformation.py b/tests/test_ec2/test_transit_gateway_cloudformation.py index 72e82c8b5..dd2ac5013 100644 --- a/tests/test_ec2/test_transit_gateway_cloudformation.py +++ b/tests/test_ec2/test_transit_gateway_cloudformation.py @@ -1,8 +1,9 @@ -import boto3 import json +from uuid import uuid4 + +import boto3 from moto import mock_cloudformation, mock_ec2 -from uuid import uuid4 @mock_cloudformation diff --git a/tests/test_ec2/test_transit_gateway_peering_attachments.py b/tests/test_ec2/test_transit_gateway_peering_attachments.py index e09d4ac36..6e5412af8 100644 --- a/tests/test_ec2/test_transit_gateway_peering_attachments.py +++ b/tests/test_ec2/test_transit_gateway_peering_attachments.py @@ -1,4 +1,5 @@ import os +from unittest import SkipTest, mock import boto3 import pytest @@ -6,7 +7,6 @@ from botocore.exceptions import ClientError from moto import mock_ec2, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from unittest import SkipTest, mock @mock_ec2 diff --git a/tests/test_ec2/test_utils.py b/tests/test_ec2/test_utils.py index 9211b59fa..095276655 100644 --- a/tests/test_ec2/test_utils.py +++ b/tests/test_ec2/test_utils.py @@ -1,6 +1,7 @@ -from copy import deepcopy import ipaddress +from copy import deepcopy from unittest.mock import patch + from pytest import raises from moto.ec2 import utils diff --git a/tests/test_ec2/test_virtual_private_gateways.py b/tests/test_ec2/test_virtual_private_gateways.py index b4116e6fc..d94b6f670 100644 --- a/tests/test_ec2/test_virtual_private_gateways.py +++ b/tests/test_ec2/test_virtual_private_gateways.py @@ -1,8 +1,9 @@ import boto3 import pytest +from botocore.exceptions import ClientError from moto import mock_ec2 -from botocore.exceptions import ClientError + from .test_tags import retrieve_all_tagged diff --git a/tests/test_ec2/test_vpc_peering.py b/tests/test_ec2/test_vpc_peering.py index 4bf4bc0d2..f99389f6e 100644 --- a/tests/test_ec2/test_vpc_peering.py +++ b/tests/test_ec2/test_vpc_peering.py @@ -3,7 +3,6 @@ from unittest import mock import boto3 import pytest - from botocore.exceptions import ClientError from moto import mock_ec2, settings diff --git a/tests/test_ec2/test_vpc_service_configuration_integration.py b/tests/test_ec2/test_vpc_service_configuration_integration.py index 80dd07650..36fe8e1f0 100644 --- a/tests/test_ec2/test_vpc_service_configuration_integration.py +++ b/tests/test_ec2/test_vpc_service_configuration_integration.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_ec2, mock_elbv2 from moto.core import DEFAULT_ACCOUNT_ID from moto.moto_api._internal import mock_random diff --git a/tests/test_ec2/test_vpcs.py b/tests/test_ec2/test_vpcs.py index bb6c320a8..6fd401e7d 100644 --- a/tests/test_ec2/test_vpcs.py +++ b/tests/test_ec2/test_vpcs.py @@ -1,13 +1,14 @@ +import json +import random +from unittest import SkipTest +from uuid import uuid4 + +import boto3 import pytest from botocore.exceptions import ClientError -import boto3 -import json -import random - from moto import mock_ec2, settings -from unittest import SkipTest -from uuid import uuid4 + from .test_tags import retrieve_all_tagged SAMPLE_DOMAIN_NAME = "example.com" diff --git a/tests/test_ec2/test_vpn_connections.py b/tests/test_ec2/test_vpn_connections.py index bbb33c6e6..099674c77 100644 --- a/tests/test_ec2/test_vpn_connections.py +++ b/tests/test_ec2/test_vpn_connections.py @@ -1,6 +1,7 @@ import boto3 import pytest from botocore.exceptions import ClientError + from moto import mock_ec2 diff --git a/tests/test_ec2/test_windows.py b/tests/test_ec2/test_windows.py index c9bd9516c..9b5f2545f 100644 --- a/tests/test_ec2/test_windows.py +++ b/tests/test_ec2/test_windows.py @@ -1,9 +1,10 @@ -import boto3 import os +from unittest import SkipTest, mock + +import boto3 from moto import mock_ec2, settings -from tests import EXAMPLE_AMI_WINDOWS, EXAMPLE_AMI_PARAVIRTUAL -from unittest import mock, SkipTest +from tests import EXAMPLE_AMI_PARAVIRTUAL, EXAMPLE_AMI_WINDOWS # The default AMIs are not loaded for our test case, to speed things up diff --git a/tests/test_ecr/test_ecr_boto3.py b/tests/test_ecr/test_ecr_boto3.py index 6499ca824..a6bd83a00 100644 --- a/tests/test_ecr/test_ecr_boto3.py +++ b/tests/test_ecr/test_ecr_boto3.py @@ -1,14 +1,14 @@ -import boto3 import json -import pytest - -from botocore.exceptions import ClientError from datetime import datetime -from dateutil.tz import tzlocal -from freezegun import freeze_time -from moto import mock_ecr, settings from unittest import SkipTest +import boto3 +import pytest +from botocore.exceptions import ClientError +from dateutil.tz import tzlocal +from freezegun import freeze_time + +from moto import mock_ecr, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from .test_ecr_helpers import _create_image_manifest, _create_image_manifest_list diff --git a/tests/test_ecr/test_ecr_cloudformation.py b/tests/test_ecr/test_ecr_cloudformation.py index bd2f043bf..b5cfd3609 100644 --- a/tests/test_ecr/test_ecr_cloudformation.py +++ b/tests/test_ecr/test_ecr_cloudformation.py @@ -1,9 +1,10 @@ import copy -import boto3 import json -from moto import mock_cloudformation, mock_ecr from string import Template +import boto3 + +from moto import mock_cloudformation, mock_ecr from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID repo_template = Template( diff --git a/tests/test_ecr/test_ecr_scanning_config.py b/tests/test_ecr/test_ecr_scanning_config.py index 945026134..4114f53f6 100644 --- a/tests/test_ecr/test_ecr_scanning_config.py +++ b/tests/test_ecr/test_ecr_scanning_config.py @@ -1,4 +1,5 @@ import boto3 + from moto import mock_ecr diff --git a/tests/test_ecs/test_ecs_account_settings.py b/tests/test_ecs/test_ecs_account_settings.py index 0f4258966..ccbe22abd 100644 --- a/tests/test_ecs/test_ecs_account_settings.py +++ b/tests/test_ecs/test_ecs_account_settings.py @@ -1,11 +1,12 @@ -import boto3 import json -import pytest +import boto3 +import pytest from botocore.exceptions import ClientError + +from moto import mock_ec2, mock_ecs from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.ec2 import utils as ec2_utils -from moto import mock_ecs, mock_ec2 from tests import EXAMPLE_AMI_ID diff --git a/tests/test_ecs/test_ecs_boto3.py b/tests/test_ecs/test_ecs_boto3.py index 7b76b0a6b..d63f0cc10 100644 --- a/tests/test_ecs/test_ecs_boto3.py +++ b/tests/test_ecs/test_ecs_boto3.py @@ -1,16 +1,16 @@ -import boto3 import json import os -import pytest - -from botocore.exceptions import ClientError from datetime import datetime -from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from moto.ec2 import utils as ec2_utils -from unittest import mock, SkipTest +from unittest import SkipTest, mock from uuid import UUID -from moto import mock_ecs, mock_ec2, settings +import boto3 +import pytest +from botocore.exceptions import ClientError + +from moto import mock_ec2, mock_ecs, settings +from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID +from moto.ec2 import utils as ec2_utils from moto.moto_api import state_manager from tests import EXAMPLE_AMI_ID diff --git a/tests/test_ecs/test_ecs_cloudformation.py b/tests/test_ecs/test_ecs_cloudformation.py index 2f83e470b..0b3b6b805 100644 --- a/tests/test_ecs/test_ecs_cloudformation.py +++ b/tests/test_ecs/test_ecs_cloudformation.py @@ -1,6 +1,8 @@ -import boto3 import json from copy import deepcopy + +import boto3 + from moto import mock_cloudformation, mock_ecs from moto.core.utils import pascal_to_camelcase, remap_nested_keys diff --git a/tests/test_ecs/test_ecs_efs.py b/tests/test_ecs/test_ecs_efs.py index f755e11f4..b34332b85 100644 --- a/tests/test_ecs/test_ecs_efs.py +++ b/tests/test_ecs/test_ecs_efs.py @@ -1,4 +1,5 @@ import boto3 + from moto import mock_ecs, mock_efs diff --git a/tests/test_ecs/test_ecs_task_tags.py b/tests/test_ecs/test_ecs_task_tags.py index 9b8d08c65..9f706a457 100644 --- a/tests/test_ecs/test_ecs_task_tags.py +++ b/tests/test_ecs/test_ecs_task_tags.py @@ -1,6 +1,7 @@ import boto3 from moto import mock_ec2, mock_ecs + from .test_ecs_boto3 import setup_ecs_cluster_with_ec2_instance diff --git a/tests/test_ecs/test_ecs_tasksets.py b/tests/test_ecs/test_ecs_tasksets.py index bdaa769dd..bad12dc31 100644 --- a/tests/test_ecs/test_ecs_tasksets.py +++ b/tests/test_ecs/test_ecs_tasksets.py @@ -1,9 +1,8 @@ -from botocore.exceptions import ClientError import boto3 +import pytest +from botocore.exceptions import ClientError from moto import mock_ecs -import pytest - cluster_name = "test_ecs_cluster" service_name = "test_ecs_service" diff --git a/tests/test_efs/test_access_point_tagging.py b/tests/test_efs/test_access_point_tagging.py index 8b249c66a..bbd5e5a8c 100644 --- a/tests/test_efs/test_access_point_tagging.py +++ b/tests/test_efs/test_access_point_tagging.py @@ -1,4 +1,5 @@ import pytest + from . import fixture_efs # noqa # pylint: disable=unused-import diff --git a/tests/test_efs/test_access_points.py b/tests/test_efs/test_access_points.py index 62f068d12..5312a414a 100644 --- a/tests/test_efs/test_access_points.py +++ b/tests/test_efs/test_access_points.py @@ -2,6 +2,7 @@ import pytest from botocore.exceptions import ClientError from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID + from . import fixture_efs # noqa # pylint: disable=unused-import diff --git a/tests/test_efs/test_file_system.py b/tests/test_efs/test_file_system.py index 324bfb0cb..a6ea2edad 100644 --- a/tests/test_efs/test_file_system.py +++ b/tests/test_efs/test_file_system.py @@ -4,6 +4,7 @@ import pytest from botocore.exceptions import ClientError from tests.test_efs.junk_drawer import has_status_code + from . import fixture_efs # noqa # pylint: disable=unused-import ARN_PATT = r"^arn:(?P[^:\n]*):(?P[^:\n]*):(?P[^:\n]*):(?P[^:\n]*):(?P(?P[^:\/\n]*)[:\/])?(?P.*)$" diff --git a/tests/test_efs/test_mount_target.py b/tests/test_efs/test_mount_target.py index e168a2440..604c6ace8 100644 --- a/tests/test_efs/test_mount_target.py +++ b/tests/test_efs/test_mount_target.py @@ -6,6 +6,7 @@ from botocore.exceptions import ClientError from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from tests.test_efs.junk_drawer import has_status_code + from . import fixture_ec2, fixture_efs # noqa # pylint: disable=unused-import diff --git a/tests/test_efs/test_server.py b/tests/test_efs/test_server.py index 4a97c852e..0b1445b5b 100644 --- a/tests/test_efs/test_server.py +++ b/tests/test_efs/test_server.py @@ -1,9 +1,9 @@ import re + import pytest -from moto import mock_efs, mock_ec2 import moto.server as server - +from moto import mock_ec2, mock_efs FILE_SYSTEMS = "/2015-02-01/file-systems" MOUNT_TARGETS = "/2015-02-01/mount-targets" diff --git a/tests/test_eks/test_eks.py b/tests/test_eks/test_eks.py index 5e2d11322..6dc9efeeb 100644 --- a/tests/test_eks/test_eks.py +++ b/tests/test_eks/test_eks.py @@ -1,8 +1,7 @@ from copy import deepcopy -from unittest import SkipTest +from unittest import SkipTest, mock import boto3 -from unittest import mock import pytest from botocore.exceptions import ClientError from freezegun import freeze_time @@ -35,29 +34,29 @@ from moto.eks.responses import DEFAULT_MAX_RESULTS from moto.moto_api._internal import mock_random from .test_eks_constants import ( - BatchCountSize, - ClusterAttributes, - ClusterInputs, DEFAULT_NAMESPACE, DISK_SIZE, - ErrorAttributes, - FargateProfileAttributes, - FargateProfileInputs, FROZEN_TIME, INSTANCE_TYPES, LAUNCH_TEMPLATE, MAX_FARGATE_LABELS, + PARTITIONS, + POD_EXECUTION_ROLE_ARN, + REGION, + REMOTE_ACCESS, + SERVICE, + BatchCountSize, + ClusterAttributes, + ClusterInputs, + ErrorAttributes, + FargateProfileAttributes, + FargateProfileInputs, NodegroupAttributes, NodegroupInputs, PageCount, - PARTITIONS, - POD_EXECUTION_ROLE_ARN, PossibleTestResults, RegExTemplates, - REGION, - REMOTE_ACCESS, ResponseAttributes, - SERVICE, ) from .test_eks_utils import ( attributes_to_test, diff --git a/tests/test_eks/test_eks_ec2.py b/tests/test_eks/test_eks_ec2.py index 65b2c4168..1b5ffd38b 100644 --- a/tests/test_eks/test_eks_ec2.py +++ b/tests/test_eks/test_eks_ec2.py @@ -1,6 +1,7 @@ import boto3 from moto import mock_ec2, mock_eks + from .test_eks_constants import NODEROLE_ARN_VALUE, SUBNET_IDS diff --git a/tests/test_eks/test_eks_utils.py b/tests/test_eks/test_eks_utils.py index 8c9b85b94..b3c38cf34 100644 --- a/tests/test_eks/test_eks_utils.py +++ b/tests/test_eks/test_eks_utils.py @@ -8,6 +8,7 @@ except ImportError: from moto.moto_api._internal import mock_random from tests.test_eks.test_eks_constants import ( + STATUS, ClusterAttributes, ClusterInputs, FargateProfileAttributes, @@ -15,10 +16,8 @@ from tests.test_eks.test_eks_constants import ( NodegroupAttributes, NodegroupInputs, ResponseAttributes, - STATUS, ) - generate_random_name = mock_random.get_random_string diff --git a/tests/test_eks/test_server.py b/tests/test_eks/test_server.py index 348620698..e8eb853eb 100644 --- a/tests/test_eks/test_server.py +++ b/tests/test_eks/test_server.py @@ -1,8 +1,9 @@ import json -import pytest import unittest - from copy import deepcopy + +import pytest + import moto.server as server from moto import mock_eks, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID @@ -17,26 +18,26 @@ from moto.eks.models import ( from moto.eks.responses import DEFAULT_MAX_RESULTS, DEFAULT_NEXT_TOKEN from tests.test_eks.test_eks import all_arn_values_should_be_valid from tests.test_eks.test_eks_constants import ( - AddonAttributes, - ClusterAttributes, DEFAULT_ENCODING, DEFAULT_HTTP_HEADERS, DEFAULT_REGION, + NODEROLE_ARN_KEY, + NODEROLE_ARN_VALUE, + PARTITIONS, + ROLE_ARN_KEY, + ROLE_ARN_VALUE, + SERVICE, + SUBNETS_KEY, + SUBNETS_VALUE, + AddonAttributes, + ClusterAttributes, Endpoints, FargateProfileAttributes, HttpHeaders, NodegroupAttributes, - NODEROLE_ARN_KEY, - NODEROLE_ARN_VALUE, - PARTITIONS, RegExTemplates, ResponseAttributes, - ROLE_ARN_KEY, - ROLE_ARN_VALUE, - SERVICE, StatusCodes, - SUBNETS_KEY, - SUBNETS_VALUE, ) """ diff --git a/tests/test_elasticache/test_elasticache.py b/tests/test_elasticache/test_elasticache.py index e119fe1a4..763157b77 100644 --- a/tests/test_elasticache/test_elasticache.py +++ b/tests/test_elasticache/test_elasticache.py @@ -1,10 +1,9 @@ import boto3 import pytest from botocore.exceptions import ClientError -from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto import mock_elasticache - +from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID # See our Development Tips on writing tests for hints on how to write good tests: # http://docs.getmoto.org/en/latest/docs/contributing/development_tips/tests.html diff --git a/tests/test_elastictranscoder/test_elastictranscoder.py b/tests/test_elastictranscoder/test_elastictranscoder.py index 47e713d32..ca7d1e8b5 100644 --- a/tests/test_elastictranscoder/test_elastictranscoder.py +++ b/tests/test_elastictranscoder/test_elastictranscoder.py @@ -1,6 +1,7 @@ -from botocore.exceptions import ClientError import boto3 import pytest +from botocore.exceptions import ClientError + from moto import mock_elastictranscoder from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_elb/test_elb.py b/tests/test_elb/test_elb.py index 40252933c..b57872741 100644 --- a/tests/test_elb/test_elb.py +++ b/tests/test_elb/test_elb.py @@ -1,11 +1,12 @@ +from uuid import uuid4 + import boto3 import pytest - from botocore.exceptions import ClientError -from moto import mock_acm, mock_elb, mock_ec2, mock_iam + +from moto import mock_acm, mock_ec2, mock_elb, mock_iam from moto.core import DEFAULT_ACCOUNT_ID from tests import EXAMPLE_AMI_ID -from uuid import uuid4 @pytest.mark.parametrize("region_name", ["us-east-1", "ap-south-1"]) diff --git a/tests/test_elb/test_elb_availabilityzones.py b/tests/test_elb/test_elb_availabilityzones.py index 93e2ddefe..428ae0941 100644 --- a/tests/test_elb/test_elb_availabilityzones.py +++ b/tests/test_elb/test_elb_availabilityzones.py @@ -1,6 +1,6 @@ import boto3 -from moto import mock_elb, mock_ec2 +from moto import mock_ec2, mock_elb @mock_elb diff --git a/tests/test_elb/test_elb_cloudformation.py b/tests/test_elb/test_elb_cloudformation.py index d38d3ff67..1f522d001 100644 --- a/tests/test_elb/test_elb_cloudformation.py +++ b/tests/test_elb/test_elb_cloudformation.py @@ -1,6 +1,7 @@ -import boto3 import json +import boto3 + from moto import mock_cloudformation, mock_ec2, mock_elb from tests import EXAMPLE_AMI_ID diff --git a/tests/test_elb/test_elb_policies.py b/tests/test_elb/test_elb_policies.py index e428abfd4..858025571 100644 --- a/tests/test_elb/test_elb_policies.py +++ b/tests/test_elb/test_elb_policies.py @@ -1,9 +1,10 @@ +from uuid import uuid4 + import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_elb -from uuid import uuid4 @mock_elb diff --git a/tests/test_elbv2/test_elbv2.py b/tests/test_elbv2/test_elbv2.py index 734a24add..cd933cb5a 100644 --- a/tests/test_elbv2/test_elbv2.py +++ b/tests/test_elbv2/test_elbv2.py @@ -1,12 +1,13 @@ import copy import os -import boto3 -from botocore.exceptions import ClientError -import pytest -from moto import mock_elbv2, mock_ec2, mock_acm -from moto.elbv2 import elbv2_backends +import boto3 +import pytest +from botocore.exceptions import ClientError + +from moto import mock_acm, mock_ec2, mock_elbv2 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID +from moto.elbv2 import elbv2_backends from tests import EXAMPLE_AMI_ID diff --git a/tests/test_elbv2/test_elbv2_cloudformation.py b/tests/test_elbv2/test_elbv2_cloudformation.py index 3ae7da1ac..c5c125d8e 100644 --- a/tests/test_elbv2/test_elbv2_cloudformation.py +++ b/tests/test_elbv2/test_elbv2_cloudformation.py @@ -1,7 +1,8 @@ -import boto3 import json -from moto import mock_elbv2, mock_ec2, mock_cloudformation +import boto3 + +from moto import mock_cloudformation, mock_ec2, mock_elbv2 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_elbv2/test_elbv2_listener_rule_tags.py b/tests/test_elbv2/test_elbv2_listener_rule_tags.py index c7953bbd4..2c5daa4fd 100644 --- a/tests/test_elbv2/test_elbv2_listener_rule_tags.py +++ b/tests/test_elbv2/test_elbv2_listener_rule_tags.py @@ -1,4 +1,4 @@ -from moto import mock_elbv2, mock_ec2 +from moto import mock_ec2, mock_elbv2 from .test_elbv2 import create_load_balancer diff --git a/tests/test_elbv2/test_elbv2_listener_rules.py b/tests/test_elbv2/test_elbv2_listener_rules.py index 6c2b7a224..bb841d783 100644 --- a/tests/test_elbv2/test_elbv2_listener_rules.py +++ b/tests/test_elbv2/test_elbv2_listener_rules.py @@ -1,8 +1,8 @@ import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError -from moto import mock_elbv2, mock_ec2 +from moto import mock_ec2, mock_elbv2 default_action = { "FixedResponseConfig": {"StatusCode": "200", "ContentType": "text/plain"}, diff --git a/tests/test_elbv2/test_elbv2_listener_tags.py b/tests/test_elbv2/test_elbv2_listener_tags.py index 7912f0163..a8dab0d9c 100644 --- a/tests/test_elbv2/test_elbv2_listener_tags.py +++ b/tests/test_elbv2/test_elbv2_listener_tags.py @@ -1,4 +1,4 @@ -from moto import mock_elbv2, mock_ec2 +from moto import mock_ec2, mock_elbv2 from .test_elbv2 import create_load_balancer diff --git a/tests/test_elbv2/test_elbv2_set_subnets.py b/tests/test_elbv2/test_elbv2_set_subnets.py index 6b4679430..172a2ff0e 100644 --- a/tests/test_elbv2/test_elbv2_set_subnets.py +++ b/tests/test_elbv2/test_elbv2_set_subnets.py @@ -1,6 +1,6 @@ import boto3 -from moto import mock_elbv2, mock_ec2 +from moto import mock_ec2, mock_elbv2 @mock_elbv2 diff --git a/tests/test_elbv2/test_elbv2_target_groups.py b/tests/test_elbv2/test_elbv2_target_groups.py index 512f1f118..a6c1014d5 100644 --- a/tests/test_elbv2/test_elbv2_target_groups.py +++ b/tests/test_elbv2/test_elbv2_target_groups.py @@ -1,8 +1,8 @@ import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError -from moto import mock_elbv2, mock_ec2 +from moto import mock_ec2, mock_elbv2 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from .test_elbv2 import create_load_balancer diff --git a/tests/test_emr/test_emr_boto3.py b/tests/test_emr/test_emr_boto3.py index 90bf4a8f0..9a2008589 100644 --- a/tests/test_emr/test_emr_boto3.py +++ b/tests/test_emr/test_emr_boto3.py @@ -1,16 +1,15 @@ +import json import time from copy import deepcopy from datetime import datetime, timezone import boto3 -import json -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_emr from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID - run_job_flow_args = dict( Instances={ "InstanceCount": 3, diff --git a/tests/test_emr/test_emr_integration.py b/tests/test_emr/test_emr_integration.py index 3ef220f9e..62c4ca51c 100644 --- a/tests/test_emr/test_emr_integration.py +++ b/tests/test_emr/test_emr_integration.py @@ -3,11 +3,10 @@ import pytest from moto import settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from moto.ec2 import mock_ec2, ec2_backends +from moto.ec2 import ec2_backends, mock_ec2 from moto.emr import mock_emr from moto.emr.utils import EmrSecurityGroupManager - ec2_backend = ec2_backends[ACCOUNT_ID]["us-east-1"] diff --git a/tests/test_emrcontainers/test_emrcontainers.py b/tests/test_emrcontainers/test_emrcontainers.py index 6339e973f..50d1deb35 100644 --- a/tests/test_emrcontainers/test_emrcontainers.py +++ b/tests/test_emrcontainers/test_emrcontainers.py @@ -1,12 +1,12 @@ """Unit tests for emrcontainers-supported APIs.""" -from datetime import datetime, timezone, timedelta import re -from unittest.mock import patch +from datetime import datetime, timedelta, timezone from unittest import SkipTest +from unittest.mock import patch import boto3 -from botocore.exceptions import ClientError, ParamValidationError import pytest +from botocore.exceptions import ClientError, ParamValidationError from moto import mock_emrcontainers, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_emrcontainers/test_server.py b/tests/test_emrcontainers/test_server.py index f2255e1e1..40b301a1a 100644 --- a/tests/test_emrcontainers/test_server.py +++ b/tests/test_emrcontainers/test_server.py @@ -1,5 +1,6 @@ """Test the different server responses.""" import json + import moto.server as server diff --git a/tests/test_emrserverless/test_emrserverless.py b/tests/test_emrserverless/test_emrserverless.py index df9958443..f93675310 100644 --- a/tests/test_emrserverless/test_emrserverless.py +++ b/tests/test_emrserverless/test_emrserverless.py @@ -5,8 +5,8 @@ from datetime import datetime, timezone from unittest.mock import patch import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_emrserverless, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_es/test_es.py b/tests/test_es/test_es.py index 0137c529e..c24e08977 100644 --- a/tests/test_es/test_es.py +++ b/tests/test_es/test_es.py @@ -2,6 +2,7 @@ import boto3 import pytest from botocore.exceptions import ClientError + from moto import mock_es # See our Development Tips on writing tests for hints on how to write good tests: diff --git a/tests/test_events/test_event_pattern.py b/tests/test_events/test_event_pattern.py index 384a80131..0ee01aaba 100644 --- a/tests/test_events/test_event_pattern.py +++ b/tests/test_events/test_event_pattern.py @@ -1,4 +1,5 @@ import json + import pytest from moto.events.models import EventPattern diff --git a/tests/test_events/test_events_cloudformation.py b/tests/test_events/test_events_cloudformation.py index 02cbc11df..711563564 100644 --- a/tests/test_events/test_events_cloudformation.py +++ b/tests/test_events/test_events_cloudformation.py @@ -1,12 +1,12 @@ -import pytest import copy +import json from string import Template import boto3 -import json +import pytest from botocore.exceptions import ClientError -from moto import mock_cloudformation, mock_events +from moto import mock_cloudformation, mock_events from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID archive_template = Template( diff --git a/tests/test_events/test_events_http_integration.py b/tests/test_events/test_events_http_integration.py index 6d33ffc4d..fe5d9eed6 100644 --- a/tests/test_events/test_events_http_integration.py +++ b/tests/test_events/test_events_http_integration.py @@ -1,10 +1,11 @@ -import boto3 import json import os +from unittest import SkipTest, mock + +import boto3 import responses from moto import mock_events, settings -from unittest import mock, SkipTest @mock_events diff --git a/tests/test_events/test_events_integration.py b/tests/test_events/test_events_integration.py index 543151548..6aee4c927 100644 --- a/tests/test_events/test_events_integration.py +++ b/tests/test_events/test_events_integration.py @@ -1,11 +1,11 @@ import json +import os from datetime import datetime from unittest import SkipTest, mock import boto3 -import os -from moto import mock_events, mock_sqs, mock_logs, settings +from moto import mock_events, mock_logs, mock_sqs, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.core.utils import iso_8601_datetime_without_milliseconds, utcnow diff --git a/tests/test_events/test_events_lambdatriggers_integration.py b/tests/test_events/test_events_lambdatriggers_integration.py index 35f849b1f..2f8842867 100644 --- a/tests/test_events/test_events_lambdatriggers_integration.py +++ b/tests/test_events/test_events_lambdatriggers_integration.py @@ -1,8 +1,10 @@ -import boto3 import json +import boto3 + from moto import mock_events, mock_iam, mock_lambda, mock_logs, mock_s3 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID + from ..markers import requires_docker from ..test_awslambda.utilities import get_test_zip_file1, wait_for_log_msg diff --git a/tests/test_events/test_events_partners_integration.py b/tests/test_events/test_events_partners_integration.py index 1109dc014..684a33f9a 100644 --- a/tests/test_events/test_events_partners_integration.py +++ b/tests/test_events/test_events_partners_integration.py @@ -1,10 +1,11 @@ -import boto3 import json import os - from datetime import datetime +from unittest import SkipTest, mock + +import boto3 + from moto import mock_events, mock_logs, settings -from unittest import mock, SkipTest @mock_events diff --git a/tests/test_firehose/test_firehose.py b/tests/test_firehose/test_firehose.py index 9ce7ce7d1..6271f8ccf 100644 --- a/tests/test_firehose/test_firehose.py +++ b/tests/test_firehose/test_firehose.py @@ -1,13 +1,12 @@ """Unit tests specific to basic Firehose Delivery Stream-related APIs.""" -from unittest import SkipTest import warnings +from unittest import SkipTest import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError -from moto import mock_firehose -from moto import settings +from moto import mock_firehose, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.firehose.models import DeliveryStream from moto.moto_api._internal import mock_random diff --git a/tests/test_firehose/test_firehose_destination_types.py b/tests/test_firehose/test_firehose_destination_types.py index 2d8c2a9fb..b02f2cfce 100644 --- a/tests/test_firehose/test_firehose_destination_types.py +++ b/tests/test_firehose/test_firehose_destination_types.py @@ -1,8 +1,7 @@ """Unit tests verifying various delivery stream destination content.""" import boto3 -from moto import mock_firehose -from moto import settings +from moto import mock_firehose, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.moto_api._internal import mock_random diff --git a/tests/test_firehose/test_firehose_encryption.py b/tests/test_firehose/test_firehose_encryption.py index ca46d84a3..b4ac540c2 100644 --- a/tests/test_firehose/test_firehose_encryption.py +++ b/tests/test_firehose/test_firehose_encryption.py @@ -1,9 +1,11 @@ +from uuid import uuid4 + import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_firehose -from uuid import uuid4 + from .test_firehose import sample_s3_dest_config diff --git a/tests/test_firehose/test_firehose_put.py b/tests/test_firehose/test_firehose_put.py index 73552bc47..59211c962 100644 --- a/tests/test_firehose/test_firehose_put.py +++ b/tests/test_firehose/test_firehose_put.py @@ -1,12 +1,10 @@ """Unit tests verifying put-related delivery stream APIs.""" import boto3 -from moto import mock_firehose -from moto import mock_s3 +from moto import mock_firehose, mock_s3 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.moto_api._internal import mock_random -from tests.test_firehose.test_firehose import TEST_REGION -from tests.test_firehose.test_firehose import sample_s3_dest_config +from tests.test_firehose.test_firehose import TEST_REGION, sample_s3_dest_config from tests.test_firehose.test_firehose_destination_types import ( create_redshift_delivery_stream, ) diff --git a/tests/test_firehose/test_firehose_tags.py b/tests/test_firehose/test_firehose_tags.py index 3c30dc6af..43f595745 100644 --- a/tests/test_firehose/test_firehose_tags.py +++ b/tests/test_firehose/test_firehose_tags.py @@ -1,14 +1,13 @@ """Unit tests verifying tag-related delivery stream APIs.""" import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_firehose from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.firehose.models import MAX_TAGS_PER_DELIVERY_STREAM from moto.moto_api._internal import mock_random -from tests.test_firehose.test_firehose import TEST_REGION -from tests.test_firehose.test_firehose import sample_s3_dest_config +from tests.test_firehose.test_firehose import TEST_REGION, sample_s3_dest_config @mock_firehose diff --git a/tests/test_firehose/test_http_destinations.py b/tests/test_firehose/test_http_destinations.py index 1797bebe6..4756c972c 100644 --- a/tests/test_firehose/test_http_destinations.py +++ b/tests/test_firehose/test_http_destinations.py @@ -3,6 +3,7 @@ import boto3 from moto import mock_firehose from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.moto_api._internal import mock_random + from .test_firehose_destination_types import create_http_delivery_stream TEST_REGION = "us-west-1" diff --git a/tests/test_forecast/test_forecast.py b/tests/test_forecast/test_forecast.py index be5b2e09e..f2ae615c6 100644 --- a/tests/test_forecast/test_forecast.py +++ b/tests/test_forecast/test_forecast.py @@ -1,6 +1,6 @@ import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_forecast from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_glacier/test_glacier_archives.py b/tests/test_glacier/test_glacier_archives.py index e3180cddb..47bb973b8 100644 --- a/tests/test_glacier/test_glacier_archives.py +++ b/tests/test_glacier/test_glacier_archives.py @@ -1,9 +1,10 @@ -import boto3 import os + +import boto3 import pytest +from botocore.exceptions import ClientError from moto import mock_glacier -from botocore.exceptions import ClientError @mock_glacier diff --git a/tests/test_glacier/test_glacier_jobs.py b/tests/test_glacier/test_glacier_jobs.py index 395377447..a80d1d94f 100644 --- a/tests/test_glacier/test_glacier_jobs.py +++ b/tests/test_glacier/test_glacier_jobs.py @@ -1,6 +1,7 @@ -import boto3 import time +import boto3 + from moto import mock_glacier from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_glacier/test_glacier_vaults.py b/tests/test_glacier/test_glacier_vaults.py index dbee055f3..1886c05d9 100644 --- a/tests/test_glacier/test_glacier_vaults.py +++ b/tests/test_glacier/test_glacier_vaults.py @@ -1,10 +1,11 @@ +from uuid import uuid4 + import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_glacier from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from uuid import uuid4 @mock_glacier diff --git a/tests/test_glue/helpers.py b/tests/test_glue/helpers.py index ca31c97ad..e900a5195 100644 --- a/tests/test_glue/helpers.py +++ b/tests/test_glue/helpers.py @@ -1,14 +1,14 @@ import copy -from .fixtures.datacatalog import TABLE_INPUT, PARTITION_INPUT, DATABASE_INPUT +from .fixtures.datacatalog import DATABASE_INPUT, PARTITION_INPUT, TABLE_INPUT from .fixtures.schema_registry import ( - TEST_REGISTRY_NAME, - TEST_SCHEMA_NAME, - TEST_BACKWARD_COMPATIBILITY, TEST_AVRO_DATA_FORMAT, TEST_AVRO_SCHEMA_DEFINITION, - TEST_SCHEMA_ID, + TEST_BACKWARD_COMPATIBILITY, TEST_NEW_AVRO_SCHEMA_DEFINITION, + TEST_REGISTRY_NAME, + TEST_SCHEMA_ID, + TEST_SCHEMA_NAME, ) diff --git a/tests/test_glue/test_datacatalog.py b/tests/test_glue/test_datacatalog.py index b1d02f986..c90cfa1bb 100644 --- a/tests/test_glue/test_datacatalog.py +++ b/tests/test_glue/test_datacatalog.py @@ -1,16 +1,15 @@ -import pytest import json -import boto3 -from botocore.client import ClientError - - from datetime import datetime, timezone + +import boto3 +import pytest +from botocore.client import ClientError from freezegun import freeze_time from moto import mock_glue, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from . import helpers +from . import helpers FROZEN_CREATE_TIME = datetime(2015, 1, 1, 0, 0, 0, tzinfo=timezone.utc) diff --git a/tests/test_glue/test_glue.py b/tests/test_glue/test_glue.py index 144c4835b..97868709c 100644 --- a/tests/test_glue/test_glue.py +++ b/tests/test_glue/test_glue.py @@ -4,8 +4,8 @@ from uuid import uuid4 import boto3 import pytest -from botocore.exceptions import ParamValidationError from botocore.client import ClientError +from botocore.exceptions import ParamValidationError from moto import mock_glue diff --git a/tests/test_glue/test_glue_job_runs.py b/tests/test_glue/test_glue_job_runs.py index 890e5d967..2e8afad09 100644 --- a/tests/test_glue/test_glue_job_runs.py +++ b/tests/test_glue/test_glue_job_runs.py @@ -1,10 +1,12 @@ +from unittest import SkipTest + import pytest from botocore.client import ClientError -from unittest import SkipTest from moto import mock_glue, settings from moto.moto_api import state_manager -from .test_glue import create_test_job, create_glue_client + +from .test_glue import create_glue_client, create_test_job @mock_glue diff --git a/tests/test_glue/test_schema_registry.py b/tests/test_glue/test_schema_registry.py index 37ba98f96..1554f618a 100644 --- a/tests/test_glue/test_schema_registry.py +++ b/tests/test_glue/test_schema_registry.py @@ -2,42 +2,42 @@ import boto3 import pytest from botocore.client import ClientError -from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto import mock_glue +from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from . import helpers from .fixtures.schema_registry import ( - TEST_REGISTRY_NAME, - TEST_REGISTRY_ARN, - TEST_DESCRIPTION, - TEST_TAGS, - TEST_SCHEMA_NAME, - TEST_SCHEMA_ARN, - TEST_AVRO_SCHEMA_DEFINITION, - TEST_NEW_AVRO_SCHEMA_DEFINITION, - TEST_JSON_SCHEMA_DEFINITION, - TEST_NEW_JSON_SCHEMA_DEFINITION, - TEST_PROTOBUF_SCHEMA_DEFINITION, - TEST_NEW_PROTOBUF_SCHEMA_DEFINITION, - TEST_AVRO_DATA_FORMAT, - TEST_JSON_DATA_FORMAT, - TEST_PROTOBUF_DATA_FORMAT, - TEST_REGISTRY_ID, - TEST_SCHEMA_ID, - TEST_BACKWARD_COMPATIBILITY, - TEST_DISABLED_COMPATIBILITY, TEST_AVAILABLE_STATUS, + TEST_AVRO_DATA_FORMAT, + TEST_AVRO_SCHEMA_DEFINITION, + TEST_BACKWARD_COMPATIBILITY, + TEST_DELETING_STATUS, + TEST_DESCRIPTION, + TEST_DISABLED_COMPATIBILITY, + TEST_INVALID_SCHEMA_ID_REGISTRY_DOES_NOT_EXIST, + TEST_INVALID_SCHEMA_ID_SCHEMA_DOES_NOT_EXIST, + TEST_INVALID_SCHEMA_NAME_DOES_NOT_EXIST, + TEST_JSON_DATA_FORMAT, + TEST_JSON_SCHEMA_DEFINITION, + TEST_METADATA_KEY, + TEST_METADATA_KEY_VALUE, + TEST_METADATA_VALUE, + TEST_NEW_AVRO_SCHEMA_DEFINITION, + TEST_NEW_JSON_SCHEMA_DEFINITION, + TEST_NEW_PROTOBUF_SCHEMA_DEFINITION, + TEST_PROTOBUF_DATA_FORMAT, + TEST_PROTOBUF_SCHEMA_DEFINITION, + TEST_REGISTRY_ARN, + TEST_REGISTRY_ID, + TEST_REGISTRY_NAME, + TEST_SCHEMA_ARN, + TEST_SCHEMA_ID, + TEST_SCHEMA_NAME, TEST_SCHEMA_VERSION_NUMBER, TEST_SCHEMA_VERSION_NUMBER_LATEST_VERSION, + TEST_TAGS, TEST_VERSION_ID, - TEST_INVALID_SCHEMA_NAME_DOES_NOT_EXIST, - TEST_INVALID_SCHEMA_ID_SCHEMA_DOES_NOT_EXIST, - TEST_INVALID_SCHEMA_ID_REGISTRY_DOES_NOT_EXIST, - TEST_METADATA_KEY_VALUE, - TEST_METADATA_KEY, - TEST_METADATA_VALUE, - TEST_DELETING_STATUS, ) diff --git a/tests/test_greengrass/test_greengrass_core.py b/tests/test_greengrass/test_greengrass_core.py index ae1ff0d6d..250372fa2 100644 --- a/tests/test_greengrass/test_greengrass_core.py +++ b/tests/test_greengrass/test_greengrass_core.py @@ -1,7 +1,7 @@ import boto3 -from botocore.client import ClientError import freezegun import pytest +from botocore.client import ClientError from moto import mock_greengrass from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_greengrass/test_greengrass_deployment.py b/tests/test_greengrass/test_greengrass_deployment.py index 4d0bdccae..aa1ae367b 100644 --- a/tests/test_greengrass/test_greengrass_deployment.py +++ b/tests/test_greengrass/test_greengrass_deployment.py @@ -1,9 +1,9 @@ import json import boto3 -from botocore.client import ClientError import freezegun import pytest +from botocore.client import ClientError from moto import mock_greengrass from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_greengrass/test_greengrass_device.py b/tests/test_greengrass/test_greengrass_device.py index ad07706d9..a4b719821 100644 --- a/tests/test_greengrass/test_greengrass_device.py +++ b/tests/test_greengrass/test_greengrass_device.py @@ -1,7 +1,7 @@ import boto3 -from botocore.client import ClientError import freezegun import pytest +from botocore.client import ClientError from moto import mock_greengrass from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_greengrass/test_greengrass_functions.py b/tests/test_greengrass/test_greengrass_functions.py index 2534f19f2..7dc5e7e0a 100644 --- a/tests/test_greengrass/test_greengrass_functions.py +++ b/tests/test_greengrass/test_greengrass_functions.py @@ -1,8 +1,7 @@ import boto3 -from botocore.client import ClientError import freezegun import pytest - +from botocore.client import ClientError from moto import mock_greengrass from moto.settings import TEST_SERVER_MODE diff --git a/tests/test_greengrass/test_greengrass_groups.py b/tests/test_greengrass/test_greengrass_groups.py index a0745e649..6e8cd082c 100644 --- a/tests/test_greengrass/test_greengrass_groups.py +++ b/tests/test_greengrass/test_greengrass_groups.py @@ -1,7 +1,7 @@ import boto3 -from botocore.exceptions import ClientError import freezegun import pytest +from botocore.exceptions import ClientError from moto import mock_greengrass from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_greengrass/test_greengrass_resource.py b/tests/test_greengrass/test_greengrass_resource.py index c31e1b23d..b176432b0 100644 --- a/tests/test_greengrass/test_greengrass_resource.py +++ b/tests/test_greengrass/test_greengrass_resource.py @@ -1,7 +1,7 @@ import boto3 -from botocore.client import ClientError import freezegun import pytest +from botocore.client import ClientError from moto import mock_greengrass from moto.settings import TEST_SERVER_MODE diff --git a/tests/test_greengrass/test_greengrass_subscriptions.py b/tests/test_greengrass/test_greengrass_subscriptions.py index d7992d2db..e3cddbbe7 100644 --- a/tests/test_greengrass/test_greengrass_subscriptions.py +++ b/tests/test_greengrass/test_greengrass_subscriptions.py @@ -1,7 +1,7 @@ import boto3 -from botocore.client import ClientError import freezegun import pytest +from botocore.client import ClientError from moto import mock_greengrass from moto.settings import TEST_SERVER_MODE diff --git a/tests/test_guardduty/test_guardduty.py b/tests/test_guardduty/test_guardduty.py index 4087b79ad..98d7bc9d9 100644 --- a/tests/test_guardduty/test_guardduty.py +++ b/tests/test_guardduty/test_guardduty.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_guardduty diff --git a/tests/test_guardduty/test_guardduty_filters.py b/tests/test_guardduty/test_guardduty_filters.py index 2726c9898..84dc97ac9 100644 --- a/tests/test_guardduty/test_guardduty_filters.py +++ b/tests/test_guardduty/test_guardduty_filters.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_guardduty diff --git a/tests/test_iam/test_iam.py b/tests/test_iam/test_iam.py index 7afe6654d..572379136 100644 --- a/tests/test_iam/test_iam.py +++ b/tests/test_iam/test_iam.py @@ -1,23 +1,20 @@ +import csv import json +from datetime import datetime +from urllib import parse +from uuid import uuid4 import boto3 -import csv +import pytest from botocore.exceptions import ClientError from moto import mock_config, mock_iam, settings +from moto.backends import get_backend from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.core.utils import utcnow from moto.iam import iam_backends -from moto.backends import get_backend -from tests import DEFAULT_ACCOUNT_ID -import pytest - -from datetime import datetime -from uuid import uuid4 -from urllib import parse - from moto.s3.responses import DEFAULT_REGION_NAME - +from tests import DEFAULT_ACCOUNT_ID MOCK_CERT = """-----BEGIN CERTIFICATE----- MIIBpzCCARACCQCY5yOdxCTrGjANBgkqhkiG9w0BAQsFADAXMRUwEwYDVQQKDAxt @@ -3583,8 +3580,8 @@ def test_role_list_config_discovered_resources(): @mock_iam def test_role_config_dict(): - from moto.iam.config import role_config_query, policy_config_query - from moto.iam.utils import random_role_id, random_policy_id + from moto.iam.config import policy_config_query, role_config_query + from moto.iam.utils import random_policy_id, random_role_id # Without any roles assert not role_config_query.get_config_resource(DEFAULT_ACCOUNT_ID, "something") @@ -4192,7 +4189,7 @@ def test_policy_list_config_discovered_resources(): @mock_iam def test_policy_config_dict(): - from moto.iam.config import role_config_query, policy_config_query + from moto.iam.config import policy_config_query, role_config_query from moto.iam.utils import random_policy_id # Without any roles diff --git a/tests/test_iam/test_iam_access_integration.py b/tests/test_iam/test_iam_access_integration.py index 3c4f6af09..4fb2db769 100644 --- a/tests/test_iam/test_iam_access_integration.py +++ b/tests/test_iam/test_iam_access_integration.py @@ -1,12 +1,13 @@ +import csv import datetime +from unittest import SkipTest import boto3 -import csv -from moto import mock_ec2, mock_iam, mock_sts, settings -from moto.iam.models import iam_backends, IAMBackend from dateutil.parser import parse + +from moto import mock_ec2, mock_iam, mock_sts, settings +from moto.iam.models import IAMBackend, iam_backends from tests import DEFAULT_ACCOUNT_ID -from unittest import SkipTest @mock_ec2 diff --git a/tests/test_iam/test_iam_account_aliases.py b/tests/test_iam/test_iam_account_aliases.py index 8b128c891..afba06a70 100644 --- a/tests/test_iam/test_iam_account_aliases.py +++ b/tests/test_iam/test_iam_account_aliases.py @@ -1,4 +1,5 @@ import boto3 + from moto import mock_iam diff --git a/tests/test_iam/test_iam_cloudformation.py b/tests/test_iam/test_iam_cloudformation.py index 3bad1805c..09d3a9b55 100644 --- a/tests/test_iam/test_iam_cloudformation.py +++ b/tests/test_iam/test_iam_cloudformation.py @@ -1,15 +1,14 @@ -import boto3 import json -import yaml +import boto3 import pytest +import yaml from botocore.exceptions import ClientError +from moto import mock_autoscaling, mock_cloudformation, mock_iam, mock_s3, mock_sts from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from moto import mock_autoscaling, mock_iam, mock_cloudformation, mock_s3, mock_sts from tests import EXAMPLE_AMI_ID - TEMPLATE_MINIMAL_ROLE = """ AWSTemplateFormatVersion: 2010-09-09 Resources: diff --git a/tests/test_iam/test_iam_groups.py b/tests/test_iam/test_iam_groups.py index 0f7b040e3..f526bf756 100644 --- a/tests/test_iam/test_iam_groups.py +++ b/tests/test_iam/test_iam_groups.py @@ -1,16 +1,16 @@ +import json from datetime import datetime import boto3 -import json - import pytest from botocore.exceptions import ClientError +from dateutil.tz import tzlocal +from freezegun import freeze_time + from moto import mock_iam, settings +from moto.backends import get_backend from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.core.utils import utcnow -from moto.backends import get_backend -from freezegun import freeze_time -from dateutil.tz import tzlocal MOCK_POLICY = """ { diff --git a/tests/test_iam/test_iam_oidc.py b/tests/test_iam/test_iam_oidc.py index c1d0f2e28..174f9349f 100644 --- a/tests/test_iam/test_iam_oidc.py +++ b/tests/test_iam/test_iam_oidc.py @@ -1,11 +1,11 @@ +from datetime import datetime + import boto3 +import pytest from botocore.exceptions import ClientError from moto import mock_iam from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -import pytest - -from datetime import datetime @mock_iam diff --git a/tests/test_iam/test_iam_password_last_used.py b/tests/test_iam/test_iam_password_last_used.py index c8408447f..8940fd102 100644 --- a/tests/test_iam/test_iam_password_last_used.py +++ b/tests/test_iam/test_iam_password_last_used.py @@ -1,9 +1,11 @@ +from unittest import SkipTest + import boto3 + from moto import mock_iam, settings from moto.backends import get_backend from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.core.utils import utcnow -from unittest import SkipTest @mock_iam diff --git a/tests/test_iam/test_iam_policies.py b/tests/test_iam/test_iam_policies.py index 6f917718b..66ccbc503 100644 --- a/tests/test_iam/test_iam_policies.py +++ b/tests/test_iam/test_iam_policies.py @@ -1,8 +1,9 @@ -import boto3 import json -import pytest +import boto3 +import pytest from botocore.exceptions import ClientError + from moto import mock_iam invalid_policy_document_test_cases = [ diff --git a/tests/test_iam/test_iam_resets.py b/tests/test_iam/test_iam_resets.py index 49a2397c4..dc63f204f 100644 --- a/tests/test_iam/test_iam_resets.py +++ b/tests/test_iam/test_iam_resets.py @@ -1,6 +1,7 @@ -import boto3 import json +import boto3 + from moto import mock_iam diff --git a/tests/test_iam/test_iam_server_certificates.py b/tests/test_iam/test_iam_server_certificates.py index 2065bdca2..e5fdffa6c 100644 --- a/tests/test_iam/test_iam_server_certificates.py +++ b/tests/test_iam/test_iam_server_certificates.py @@ -1,8 +1,8 @@ +from datetime import datetime + import boto3 import pytest - from botocore.exceptions import ClientError -from datetime import datetime from moto import mock_iam from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_identitystore/test_identitystore.py b/tests/test_identitystore/test_identitystore.py index ab4bfd70d..b5ec13b32 100644 --- a/tests/test_identitystore/test_identitystore.py +++ b/tests/test_identitystore/test_identitystore.py @@ -10,7 +10,6 @@ from botocore.exceptions import ClientError from moto import mock_identitystore from moto.moto_api._internal import mock_random - # See our Development Tips on writing tests for hints on how to write good tests: # http://docs.getmoto.org/en/latest/docs/contributing/development_tips/tests.html diff --git a/tests/test_iot/test_iot.py b/tests/test_iot/test_iot.py index 7ee9fab68..030fd6a92 100644 --- a/tests/test_iot/test_iot.py +++ b/tests/test_iot/test_iot.py @@ -1,9 +1,9 @@ import boto3 +import pytest +from botocore.exceptions import ClientError from moto import mock_iot from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from botocore.exceptions import ClientError -import pytest @mock_iot diff --git a/tests/test_iot/test_iot_ca_certificates.py b/tests/test_iot/test_iot_ca_certificates.py index 88d98dbcf..f84324a49 100644 --- a/tests/test_iot/test_iot_ca_certificates.py +++ b/tests/test_iot/test_iot_ca_certificates.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_iot diff --git a/tests/test_iot/test_iot_certificates.py b/tests/test_iot/test_iot_certificates.py index b7293c1f1..8773c2ed9 100644 --- a/tests/test_iot/test_iot_certificates.py +++ b/tests/test_iot/test_iot_certificates.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_iot diff --git a/tests/test_iot/test_iot_job_executions.py b/tests/test_iot/test_iot_job_executions.py index e84f19ff8..8295aa5e5 100644 --- a/tests/test_iot/test_iot_job_executions.py +++ b/tests/test_iot/test_iot_job_executions.py @@ -1,8 +1,9 @@ -import boto3 import json -import pytest +import boto3 +import pytest from botocore.exceptions import ClientError + from moto import mock_iot diff --git a/tests/test_iot/test_iot_jobs.py b/tests/test_iot/test_iot_jobs.py index 6295f4ff6..b939f43e7 100644 --- a/tests/test_iot/test_iot_jobs.py +++ b/tests/test_iot/test_iot_jobs.py @@ -1,6 +1,7 @@ -import boto3 import json +import boto3 + from moto import mock_iot diff --git a/tests/test_iot/test_iot_policies.py b/tests/test_iot/test_iot_policies.py index 076a92c22..1d954b6e4 100644 --- a/tests/test_iot/test_iot_policies.py +++ b/tests/test_iot/test_iot_policies.py @@ -1,9 +1,10 @@ -import boto3 import json -import pytest +import boto3 +import pytest from botocore.exceptions import ClientError -from moto import mock_iot, mock_cognitoidentity + +from moto import mock_cognitoidentity, mock_iot @pytest.fixture(name="region_name") diff --git a/tests/test_iot/test_iot_thing_groups.py b/tests/test_iot/test_iot_thing_groups.py index 6c343ab63..ac82ac3e5 100644 --- a/tests/test_iot/test_iot_thing_groups.py +++ b/tests/test_iot/test_iot_thing_groups.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_iot diff --git a/tests/test_iot/test_iot_topic_rules.py b/tests/test_iot/test_iot_topic_rules.py index 484266fd1..d8003e883 100644 --- a/tests/test_iot/test_iot_topic_rules.py +++ b/tests/test_iot/test_iot_topic_rules.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_iot name = "my-rule" diff --git a/tests/test_iot/test_server.py b/tests/test_iot/test_server.py index 6c4d8df20..9aefb9493 100644 --- a/tests/test_iot/test_server.py +++ b/tests/test_iot/test_server.py @@ -1,8 +1,8 @@ import json -import pytest - from urllib.parse import quote +import pytest + import moto.server as server from moto import mock_iot diff --git a/tests/test_iotdata/test_iotdata.py b/tests/test_iotdata/test_iotdata.py index 983b177c2..009e5a6d7 100644 --- a/tests/test_iotdata/test_iotdata.py +++ b/tests/test_iotdata/test_iotdata.py @@ -1,10 +1,11 @@ import json + import boto3 import pytest from botocore.exceptions import ClientError import moto.iotdata.models -from moto import mock_iotdata, mock_iot, settings +from moto import mock_iot, mock_iotdata, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_ivs/test_ivs.py b/tests/test_ivs/test_ivs.py index b5a2f1867..0ca8b44f3 100644 --- a/tests/test_ivs/test_ivs.py +++ b/tests/test_ivs/test_ivs.py @@ -1,9 +1,11 @@ """Unit tests for ivs-supported APIs.""" +from re import fullmatch + import boto3 from botocore.exceptions import ClientError from pytest import raises + from moto import mock_ivs -from re import fullmatch @mock_ivs diff --git a/tests/test_kinesis/test_kinesis.py b/tests/test_kinesis/test_kinesis.py index 556fe1a08..6ba2f181d 100644 --- a/tests/test_kinesis/test_kinesis.py +++ b/tests/test_kinesis/test_kinesis.py @@ -1,10 +1,9 @@ import datetime import time -import pytest import boto3 +import pytest from botocore.exceptions import ClientError - from dateutil.tz import tzlocal from moto import mock_kinesis diff --git a/tests/test_kinesis/test_kinesis_boto3.py b/tests/test_kinesis/test_kinesis_boto3.py index e41347769..300882553 100644 --- a/tests/test_kinesis/test_kinesis_boto3.py +++ b/tests/test_kinesis/test_kinesis_boto3.py @@ -1,9 +1,10 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_kinesis from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID + from .test_kinesis import get_stream_arn diff --git a/tests/test_kinesis/test_kinesis_cloudformation.py b/tests/test_kinesis/test_kinesis_cloudformation.py index c20ed60c9..6b7961a8b 100644 --- a/tests/test_kinesis/test_kinesis_cloudformation.py +++ b/tests/test_kinesis/test_kinesis_cloudformation.py @@ -1,6 +1,6 @@ import boto3 -from moto import mock_kinesis, mock_cloudformation +from moto import mock_cloudformation, mock_kinesis @mock_cloudformation diff --git a/tests/test_kinesis/test_kinesis_encryption.py b/tests/test_kinesis/test_kinesis_encryption.py index 76b1f81d9..a2739cf06 100644 --- a/tests/test_kinesis/test_kinesis_encryption.py +++ b/tests/test_kinesis/test_kinesis_encryption.py @@ -1,6 +1,7 @@ import boto3 from moto import mock_kinesis + from .test_kinesis import get_stream_arn diff --git a/tests/test_kinesis/test_kinesis_monitoring.py b/tests/test_kinesis/test_kinesis_monitoring.py index 45b1cf6f2..e7248ff82 100644 --- a/tests/test_kinesis/test_kinesis_monitoring.py +++ b/tests/test_kinesis/test_kinesis_monitoring.py @@ -2,6 +2,7 @@ import boto3 from moto import mock_kinesis from tests import DEFAULT_ACCOUNT_ID + from .test_kinesis import get_stream_arn diff --git a/tests/test_kinesis/test_kinesis_stream_consumers.py b/tests/test_kinesis/test_kinesis_stream_consumers.py index d494aa65d..9cd81bf09 100644 --- a/tests/test_kinesis/test_kinesis_stream_consumers.py +++ b/tests/test_kinesis/test_kinesis_stream_consumers.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_kinesis from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_kinesis/test_kinesis_stream_limits.py b/tests/test_kinesis/test_kinesis_stream_limits.py index 95c4fc4dc..3918c4ebd 100644 --- a/tests/test_kinesis/test_kinesis_stream_limits.py +++ b/tests/test_kinesis/test_kinesis_stream_limits.py @@ -1,9 +1,8 @@ import boto3 import pytest - from botocore.exceptions import ClientError -from moto import mock_kinesis +from moto import mock_kinesis ONE_MB = 2**20 diff --git a/tests/test_kinesisvideo/test_kinesisvideo.py b/tests/test_kinesisvideo/test_kinesisvideo.py index fe334a67f..0798cbc6e 100644 --- a/tests/test_kinesisvideo/test_kinesisvideo.py +++ b/tests/test_kinesisvideo/test_kinesisvideo.py @@ -1,8 +1,9 @@ import boto3 import pytest -from moto import mock_kinesisvideo from botocore.exceptions import ClientError +from moto import mock_kinesisvideo + @mock_kinesisvideo def test_create_stream(): diff --git a/tests/test_kinesisvideoarchivedmedia/test_kinesisvideoarchivedmedia.py b/tests/test_kinesisvideoarchivedmedia/test_kinesisvideoarchivedmedia.py index fc5a5ff32..ced33ab69 100644 --- a/tests/test_kinesisvideoarchivedmedia/test_kinesisvideoarchivedmedia.py +++ b/tests/test_kinesisvideoarchivedmedia/test_kinesisvideoarchivedmedia.py @@ -1,9 +1,10 @@ -import boto3 -from moto import mock_kinesisvideoarchivedmedia -from moto import mock_kinesisvideo -from moto.core.utils import utcnow from datetime import timedelta +import boto3 + +from moto import mock_kinesisvideo, mock_kinesisvideoarchivedmedia +from moto.core.utils import utcnow + @mock_kinesisvideo @mock_kinesisvideoarchivedmedia diff --git a/tests/test_kms/test_kms_boto3.py b/tests/test_kms/test_kms_boto3.py index 3754815e8..bcdfeded1 100644 --- a/tests/test_kms/test_kms_boto3.py +++ b/tests/test_kms/test_kms_boto3.py @@ -1,24 +1,22 @@ -import json -from datetime import datetime -from cryptography.hazmat.primitives import hashes, serialization -from cryptography.hazmat.primitives.asymmetric import rsa, ec -import itertools -from unittest import mock -from dateutil.tz import tzutc import base64 +import itertools +import json import os - +from datetime import datetime +from unittest import mock import boto3 import botocore.exceptions -from botocore.exceptions import ClientError -from freezegun import freeze_time import pytest +from botocore.exceptions import ClientError +from cryptography.hazmat.primitives import hashes, serialization +from cryptography.hazmat.primitives.asymmetric import ec, rsa +from dateutil.tz import tzutc +from freezegun import freeze_time from moto import mock_kms from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID - PLAINTEXT_VECTORS = [ b"some encodeable plaintext", b"some unencodeable plaintext \xec\x8a\xcf\xb6r\xe9\xb5\xeb\xff\xa23\x16", diff --git a/tests/test_kms/test_kms_encrypt.py b/tests/test_kms/test_kms_encrypt.py index d745a3266..4454330f4 100644 --- a/tests/test_kms/test_kms_encrypt.py +++ b/tests/test_kms/test_kms_encrypt.py @@ -1,10 +1,11 @@ import base64 import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_kms + from .test_kms_boto3 import PLAINTEXT_VECTORS, _get_encoded_value diff --git a/tests/test_kms/test_kms_grants.py b/tests/test_kms/test_kms_grants.py index e1b11ab5d..29a54fb17 100644 --- a/tests/test_kms/test_kms_grants.py +++ b/tests/test_kms/test_kms_grants.py @@ -1,12 +1,12 @@ +from unittest import mock + import boto3 import pytest from cryptography.hazmat.primitives.asymmetric import rsa -from unittest import mock from moto import mock_kms from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID - grantee_principal = ( f"arn:aws:iam::{ACCOUNT_ID}:role/service-role/tf-acc-test-7071877926602081451" ) diff --git a/tests/test_kms/test_kms_policy_enforcement.py b/tests/test_kms/test_kms_policy_enforcement.py index f08e22f41..ea9dcb605 100644 --- a/tests/test_kms/test_kms_policy_enforcement.py +++ b/tests/test_kms/test_kms_policy_enforcement.py @@ -1,14 +1,15 @@ -import boto3 import json +from unittest import mock + +import boto3 import pytest from botocore.exceptions import ClientError -from unittest import mock +from cryptography.hazmat.primitives.asymmetric import rsa from moto import mock_kms from moto.kms.exceptions import AccessDeniedException from moto.kms.models import Key from moto.kms.policy_validator import validate_policy -from cryptography.hazmat.primitives.asymmetric import rsa @mock_kms diff --git a/tests/test_kms/test_utils.py b/tests/test_kms/test_utils.py index 03e8b8d4e..2ef81064f 100644 --- a/tests/test_kms/test_utils.py +++ b/tests/test_kms/test_utils.py @@ -8,19 +8,19 @@ from moto.kms.exceptions import ( ) from moto.kms.models import Key from moto.kms.utils import ( + MASTER_KEY_LEN, + Ciphertext, + ECDSAPrivateKey, + KeySpec, + RSAPrivateKey, + SigningAlgorithm, _deserialize_ciphertext_blob, _serialize_ciphertext_blob, _serialize_encryption_context, + decrypt, + encrypt, generate_data_key, generate_master_key, - MASTER_KEY_LEN, - encrypt, - decrypt, - Ciphertext, - KeySpec, - SigningAlgorithm, - RSAPrivateKey, - ECDSAPrivateKey, ) ENCRYPTION_CONTEXT_VECTORS = [ diff --git a/tests/test_lakeformation/__init__.py b/tests/test_lakeformation/__init__.py index 6d2c63bbf..a7c38a5c7 100644 --- a/tests/test_lakeformation/__init__.py +++ b/tests/test_lakeformation/__init__.py @@ -1,9 +1,11 @@ -import boto3 import os from functools import wraps -from moto import mock_glue, mock_lakeformation, mock_s3, mock_sts from uuid import uuid4 +import boto3 + +from moto import mock_glue, mock_lakeformation, mock_s3, mock_sts + def lakeformation_aws_verified(func): """ diff --git a/tests/test_lakeformation/test_lakeformation.py b/tests/test_lakeformation/test_lakeformation.py index 3a72f6d88..db63d5f0e 100644 --- a/tests/test_lakeformation/test_lakeformation.py +++ b/tests/test_lakeformation/test_lakeformation.py @@ -1,9 +1,10 @@ """Unit tests for lakeformation-supported APIs.""" from typing import Dict, Optional + import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_lakeformation # See our Development Tips on writing tests for hints on how to write good tests: diff --git a/tests/test_lakeformation/test_resource_tags_integration.py b/tests/test_lakeformation/test_resource_tags_integration.py index 1887e5a1c..8a0342094 100644 --- a/tests/test_lakeformation/test_resource_tags_integration.py +++ b/tests/test_lakeformation/test_resource_tags_integration.py @@ -1,8 +1,8 @@ +from uuid import uuid4 + import boto3 import pytest -from uuid import uuid4 - from . import lakeformation_aws_verified diff --git a/tests/test_logs/test_integration.py b/tests/test_logs/test_integration.py index 4714b5946..dbdbea54c 100644 --- a/tests/test_logs/test_integration.py +++ b/tests/test_logs/test_integration.py @@ -1,17 +1,16 @@ import base64 -from io import BytesIO import json import time -from zipfile import ZipFile, ZIP_DEFLATED import zlib +from io import BytesIO +from zipfile import ZIP_DEFLATED, ZipFile import boto3 -from botocore.exceptions import ClientError -from moto import mock_logs, mock_lambda, mock_iam, mock_firehose, mock_s3 -from moto import mock_kinesis -from moto.core.utils import unix_time_millis import pytest +from botocore.exceptions import ClientError +from moto import mock_firehose, mock_iam, mock_kinesis, mock_lambda, mock_logs, mock_s3 +from moto.core.utils import unix_time_millis from tests.markers import requires_docker diff --git a/tests/test_logs/test_logs.py b/tests/test_logs/test_logs.py index fedc8bbfe..89c45c939 100644 --- a/tests/test_logs/test_logs.py +++ b/tests/test_logs/test_logs.py @@ -1,5 +1,5 @@ import json -from datetime import timedelta, datetime +from datetime import datetime, timedelta from uuid import UUID import boto3 diff --git a/tests/test_logs/test_logs_filter.py b/tests/test_logs/test_logs_filter.py index 60a416abf..786021be1 100644 --- a/tests/test_logs/test_logs_filter.py +++ b/tests/test_logs/test_logs_filter.py @@ -1,6 +1,7 @@ -import boto3 -from unittest import TestCase from datetime import timedelta +from unittest import TestCase + +import boto3 from moto import mock_logs from moto.core.utils import unix_time_millis, utcnow diff --git a/tests/test_logs/test_logs_query/test_query.py b/tests/test_logs/test_logs_query/test_query.py index a37574831..20e28e821 100644 --- a/tests/test_logs/test_logs_query/test_query.py +++ b/tests/test_logs/test_logs_query/test_query.py @@ -1,11 +1,10 @@ -from moto.core import DEFAULT_ACCOUNT_ID -from moto.logs.models import LogGroup -from moto.logs.logs_query import execute_query -from moto.core.utils import unix_time, unix_time_millis - from unittest import TestCase from uuid import uuid4 +from moto.core import DEFAULT_ACCOUNT_ID +from moto.core.utils import unix_time, unix_time_millis +from moto.logs.logs_query import execute_query +from moto.logs.models import LogGroup DEFAULT_QUERY = """fields @timestamp, @message, @logStream, @log | sort @timestamp desc diff --git a/tests/test_managedblockchain/test_managedblockchain_invitations.py b/tests/test_managedblockchain/test_managedblockchain_invitations.py index d097f0f32..433de475a 100644 --- a/tests/test_managedblockchain/test_managedblockchain_invitations.py +++ b/tests/test_managedblockchain/test_managedblockchain_invitations.py @@ -1,8 +1,9 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_managedblockchain + from . import helpers diff --git a/tests/test_managedblockchain/test_managedblockchain_members.py b/tests/test_managedblockchain/test_managedblockchain_members.py index 40030e5d6..9a7497112 100644 --- a/tests/test_managedblockchain/test_managedblockchain_members.py +++ b/tests/test_managedblockchain/test_managedblockchain_members.py @@ -1,9 +1,10 @@ import boto3 import pytest - from botocore.config import Config from botocore.exceptions import ClientError, ParamValidationError + from moto import mock_managedblockchain + from . import helpers diff --git a/tests/test_managedblockchain/test_managedblockchain_networks.py b/tests/test_managedblockchain/test_managedblockchain_networks.py index 4ee6844a5..24aaafab8 100644 --- a/tests/test_managedblockchain/test_managedblockchain_networks.py +++ b/tests/test_managedblockchain/test_managedblockchain_networks.py @@ -1,8 +1,9 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_managedblockchain + from . import helpers diff --git a/tests/test_managedblockchain/test_managedblockchain_nodes.py b/tests/test_managedblockchain/test_managedblockchain_nodes.py index d53ae4404..c8ab6c272 100644 --- a/tests/test_managedblockchain/test_managedblockchain_nodes.py +++ b/tests/test_managedblockchain/test_managedblockchain_nodes.py @@ -1,9 +1,10 @@ import boto3 import pytest - from botocore.config import Config from botocore.exceptions import ClientError + from moto import mock_managedblockchain + from . import helpers diff --git a/tests/test_managedblockchain/test_managedblockchain_proposals.py b/tests/test_managedblockchain/test_managedblockchain_proposals.py index 705d062c0..05f0d93eb 100644 --- a/tests/test_managedblockchain/test_managedblockchain_proposals.py +++ b/tests/test_managedblockchain/test_managedblockchain_proposals.py @@ -1,8 +1,9 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_managedblockchain + from . import helpers diff --git a/tests/test_managedblockchain/test_managedblockchain_proposalvotes.py b/tests/test_managedblockchain/test_managedblockchain_proposalvotes.py index 867b6a385..97f511f9c 100644 --- a/tests/test_managedblockchain/test_managedblockchain_proposalvotes.py +++ b/tests/test_managedblockchain/test_managedblockchain_proposalvotes.py @@ -1,12 +1,13 @@ import os +from unittest import SkipTest import boto3 import pytest from botocore.exceptions import ClientError from freezegun import freeze_time -from unittest import SkipTest from moto import mock_managedblockchain + from . import helpers diff --git a/tests/test_mediaconnect/test_server.py b/tests/test_mediaconnect/test_server.py index 6edffd782..36b973cad 100644 --- a/tests/test_mediaconnect/test_server.py +++ b/tests/test_mediaconnect/test_server.py @@ -1,4 +1,5 @@ import json + import moto.server as server from moto import mock_mediaconnect diff --git a/tests/test_medialive/test_medialive.py b/tests/test_medialive/test_medialive.py index ce5e55df5..973581c48 100644 --- a/tests/test_medialive/test_medialive.py +++ b/tests/test_medialive/test_medialive.py @@ -1,7 +1,8 @@ -import boto3 -from moto import mock_medialive from uuid import uuid4 +import boto3 + +from moto import mock_medialive from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID region = "eu-west-1" diff --git a/tests/test_medialive/test_server.py b/tests/test_medialive/test_server.py index 46e830377..adb658a5c 100644 --- a/tests/test_medialive/test_server.py +++ b/tests/test_medialive/test_server.py @@ -1,4 +1,5 @@ import json + import moto.server as server from moto import mock_medialive diff --git a/tests/test_meteringmarketplace/test_meteringmarketplace.py b/tests/test_meteringmarketplace/test_meteringmarketplace.py index ecb869b4f..b6811154b 100644 --- a/tests/test_meteringmarketplace/test_meteringmarketplace.py +++ b/tests/test_meteringmarketplace/test_meteringmarketplace.py @@ -6,7 +6,6 @@ import boto3 from moto import mock_meteringmarketplace from moto.meteringmarketplace.models import Result - USAGE_RECORDS = [ { "Timestamp": datetime(2019, 8, 25, 21, 1, 38), diff --git a/tests/test_moto_api/recorder/test_recorder.py b/tests/test_moto_api/recorder/test_recorder.py index 90a70c2f1..96314c221 100644 --- a/tests/test_moto_api/recorder/test_recorder.py +++ b/tests/test_moto_api/recorder/test_recorder.py @@ -1,20 +1,22 @@ import base64 -import boto3 import json -import requests import os +from unittest import SkipTest, TestCase + +import boto3 +import requests + from moto import ( - settings, mock_apigateway, mock_dynamodb, mock_ec2, mock_s3, mock_timestreamwrite, + settings, ) from moto.moto_api import recorder from moto.server import ThreadedMotoServer from tests import EXAMPLE_AMI_ID -from unittest import SkipTest, TestCase @mock_apigateway diff --git a/tests/test_moto_api/state_manager/servermode/test_state_manager.py b/tests/test_moto_api/state_manager/servermode/test_state_manager.py index 48d356582..faadc918f 100644 --- a/tests/test_moto_api/state_manager/servermode/test_state_manager.py +++ b/tests/test_moto_api/state_manager/servermode/test_state_manager.py @@ -1,8 +1,9 @@ import json +from unittest import SkipTest + import requests from moto import settings -from unittest import SkipTest def test_set_transition(): diff --git a/tests/test_moto_api/state_manager/test_batch_integration.py b/tests/test_moto_api/state_manager/test_batch_integration.py index 7cdfad621..6e67ebe5f 100644 --- a/tests/test_moto_api/state_manager/test_batch_integration.py +++ b/tests/test_moto_api/state_manager/test_batch_integration.py @@ -1,10 +1,10 @@ +from unittest import SkipTest + +from moto import mock_batch, mock_ec2, mock_ecs, mock_iam, mock_logs, settings +from moto.moto_api import state_manager from tests.markers import requires_docker from tests.test_batch import _get_clients, _setup -from tests.test_batch.test_batch_jobs import prepare_job, _wait_for_job_status - -from moto import mock_batch, mock_iam, mock_ec2, mock_ecs, mock_logs, settings -from moto.moto_api import state_manager -from unittest import SkipTest +from tests.test_batch.test_batch_jobs import _wait_for_job_status, prepare_job @mock_logs diff --git a/tests/test_moto_api/state_manager/test_managed_state_model.py b/tests/test_moto_api/state_manager/test_managed_state_model.py index 00f778bd7..d4bad2da7 100644 --- a/tests/test_moto_api/state_manager/test_managed_state_model.py +++ b/tests/test_moto_api/state_manager/test_managed_state_model.py @@ -1,5 +1,5 @@ -from moto.moto_api._internal.managed_state_model import ManagedState from moto.moto_api import state_manager +from moto.moto_api._internal.managed_state_model import ManagedState class ExampleModel(ManagedState): diff --git a/tests/test_mq/test_mq.py b/tests/test_mq/test_mq.py index 4bd3c299c..6b1b380b1 100644 --- a/tests/test_mq/test_mq.py +++ b/tests/test_mq/test_mq.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_mq # See our Development Tips on writing tests for hints on how to write good tests: diff --git a/tests/test_mq/test_mq_configuration.py b/tests/test_mq/test_mq_configuration.py index 8e52caa69..1450f54b6 100644 --- a/tests/test_mq/test_mq_configuration.py +++ b/tests/test_mq/test_mq_configuration.py @@ -3,8 +3,8 @@ import base64 import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_mq from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_mq/test_mq_users.py b/tests/test_mq/test_mq_users.py index 5584fee27..1734ba068 100644 --- a/tests/test_mq/test_mq_users.py +++ b/tests/test_mq/test_mq_users.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_mq diff --git a/tests/test_mq/test_server.py b/tests/test_mq/test_server.py index 4842ca270..d2a3c469f 100644 --- a/tests/test_mq/test_server.py +++ b/tests/test_mq/test_server.py @@ -1,7 +1,7 @@ import json -from moto import mock_mq import moto.server as server +from moto import mock_mq @mock_mq diff --git a/tests/test_neptune/test_cluster_options.py b/tests/test_neptune/test_cluster_options.py index 12869305c..d67db38b2 100644 --- a/tests/test_neptune/test_cluster_options.py +++ b/tests/test_neptune/test_cluster_options.py @@ -1,4 +1,5 @@ import boto3 + from moto import mock_neptune diff --git a/tests/test_neptune/test_cluster_tags.py b/tests/test_neptune/test_cluster_tags.py index 0c2651c86..82a87708d 100644 --- a/tests/test_neptune/test_cluster_tags.py +++ b/tests/test_neptune/test_cluster_tags.py @@ -1,4 +1,5 @@ import boto3 + from moto import mock_neptune diff --git a/tests/test_neptune/test_clusters.py b/tests/test_neptune/test_clusters.py index 04f9827ca..5610edf40 100644 --- a/tests/test_neptune/test_clusters.py +++ b/tests/test_neptune/test_clusters.py @@ -2,6 +2,7 @@ import boto3 import pytest from botocore.exceptions import ClientError + from moto import mock_neptune # See our Development Tips on writing tests for hints on how to write good tests: diff --git a/tests/test_neptune/test_global_clusters.py b/tests/test_neptune/test_global_clusters.py index 3198b0e2f..2f0204ea2 100644 --- a/tests/test_neptune/test_global_clusters.py +++ b/tests/test_neptune/test_global_clusters.py @@ -1,4 +1,5 @@ import boto3 + from moto import mock_neptune diff --git a/tests/test_opensearch/test_opensearch.py b/tests/test_opensearch/test_opensearch.py index 380e018bd..1b5afa250 100644 --- a/tests/test_opensearch/test_opensearch.py +++ b/tests/test_opensearch/test_opensearch.py @@ -4,7 +4,6 @@ from botocore.exceptions import ClientError from moto import mock_opensearch - # See our Development Tips on writing tests for hints on how to write good tests: # http://docs.getmoto.org/en/latest/docs/contributing/development_tips/tests.html diff --git a/tests/test_opsworks/test_apps.py b/tests/test_opsworks/test_apps.py index 6bbe53f6e..d2d30ec6a 100644 --- a/tests/test_opsworks/test_apps.py +++ b/tests/test_opsworks/test_apps.py @@ -1,6 +1,5 @@ import boto3 import pytest - from botocore.exceptions import ClientError from freezegun import freeze_time diff --git a/tests/test_opsworks/test_instances.py b/tests/test_opsworks/test_instances.py index a0e17543c..b85dc945f 100644 --- a/tests/test_opsworks/test_instances.py +++ b/tests/test_opsworks/test_instances.py @@ -1,9 +1,8 @@ import boto3 import pytest - from botocore.exceptions import ClientError -from moto import mock_opsworks -from moto import mock_ec2 + +from moto import mock_ec2, mock_opsworks from tests import EXAMPLE_AMI_ID diff --git a/tests/test_opsworks/test_layers.py b/tests/test_opsworks/test_layers.py index 198779102..26d04a26b 100644 --- a/tests/test_opsworks/test_layers.py +++ b/tests/test_opsworks/test_layers.py @@ -1,6 +1,5 @@ import boto3 import pytest - from botocore.exceptions import ClientError from freezegun import freeze_time diff --git a/tests/test_organizations/test_organizations_boto3.py b/tests/test_organizations/test_organizations_boto3.py index 78bfa05ac..a2101cccd 100644 --- a/tests/test_organizations/test_organizations_boto3.py +++ b/tests/test_organizations/test_organizations_boto3.py @@ -1,13 +1,14 @@ -from datetime import datetime import json import re +from datetime import datetime import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError -from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto import mock_organizations +from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID +from moto.organizations import utils from moto.organizations.exceptions import InvalidInputException, TargetNotFoundException from moto.organizations.models import ( FakeAccount, @@ -17,15 +18,15 @@ from moto.organizations.models import ( FakeRoot, OrganizationsBackend, ) -from moto.organizations import utils + from .organizations_test_utils import ( - validate_organization, - validate_roots, - validate_organizational_unit, validate_account, validate_create_account_status, - validate_service_control_policy, + validate_organization, + validate_organizational_unit, validate_policy_summary, + validate_roots, + validate_service_control_policy, ) diff --git a/tests/test_personalize/test_personalize_schema.py b/tests/test_personalize/test_personalize_schema.py index 31862ee96..fa31aea64 100644 --- a/tests/test_personalize/test_personalize_schema.py +++ b/tests/test_personalize/test_personalize_schema.py @@ -3,8 +3,8 @@ import json import re import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_personalize from moto.core import DEFAULT_ACCOUNT_ID diff --git a/tests/test_pinpoint/test_pinpoint.py b/tests/test_pinpoint/test_pinpoint.py index f9e58b4bf..4230fee58 100644 --- a/tests/test_pinpoint/test_pinpoint.py +++ b/tests/test_pinpoint/test_pinpoint.py @@ -1,7 +1,7 @@ """Unit tests for pinpoint-supported APIs.""" import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_pinpoint diff --git a/tests/test_pinpoint/test_pinpoint_event_stream.py b/tests/test_pinpoint/test_pinpoint_event_stream.py index 3774c0c2a..7f0ed5b53 100644 --- a/tests/test_pinpoint/test_pinpoint_event_stream.py +++ b/tests/test_pinpoint/test_pinpoint_event_stream.py @@ -1,7 +1,7 @@ """Unit tests for pinpoint-supported APIs.""" import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_pinpoint diff --git a/tests/test_quicksight/test_quicksight_groups.py b/tests/test_quicksight/test_quicksight_groups.py index c93dc6154..5624b0fc6 100644 --- a/tests/test_quicksight/test_quicksight_groups.py +++ b/tests/test_quicksight/test_quicksight_groups.py @@ -1,7 +1,7 @@ """Unit tests for quicksight-supported APIs.""" import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_quicksight from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_quicksight/test_quicksight_users.py b/tests/test_quicksight/test_quicksight_users.py index ddffbe2c1..255e5f05a 100644 --- a/tests/test_quicksight/test_quicksight_users.py +++ b/tests/test_quicksight/test_quicksight_users.py @@ -1,7 +1,7 @@ """Unit tests for quicksight-supported APIs.""" import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_quicksight from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_ram/test_ram.py b/tests/test_ram/test_ram.py index 660c774f6..79ec87947 100644 --- a/tests/test_ram/test_ram.py +++ b/tests/test_ram/test_ram.py @@ -3,10 +3,10 @@ import time from datetime import datetime import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError -from moto import mock_ram, mock_organizations +from moto import mock_organizations, mock_ram from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_rds/test_db_cluster_param_group.py b/tests/test_rds/test_db_cluster_param_group.py index 7bb7ae8a0..3257bd624 100644 --- a/tests/test_rds/test_db_cluster_param_group.py +++ b/tests/test_rds/test_db_cluster_param_group.py @@ -1,6 +1,6 @@ import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_rds from moto.core import DEFAULT_ACCOUNT_ID diff --git a/tests/test_rds/test_filters.py b/tests/test_rds/test_filters.py index b9920e5e2..cb4045241 100644 --- a/tests/test_rds/test_filters.py +++ b/tests/test_rds/test_filters.py @@ -1,6 +1,6 @@ import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_rds diff --git a/tests/test_rds/test_global_clusters.py b/tests/test_rds/test_global_clusters.py index f02432407..0eb02a4b1 100644 --- a/tests/test_rds/test_global_clusters.py +++ b/tests/test_rds/test_global_clusters.py @@ -1,6 +1,6 @@ import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_rds from moto.core import DEFAULT_ACCOUNT_ID diff --git a/tests/test_rds/test_rds.py b/tests/test_rds/test_rds.py index 613a5118c..5e845f94a 100644 --- a/tests/test_rds/test_rds.py +++ b/tests/test_rds/test_rds.py @@ -1,8 +1,8 @@ import datetime import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_ec2, mock_kms, mock_rds from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_rds/test_rds_cloudformation.py b/tests/test_rds/test_rds_cloudformation.py index f256203df..6238044be 100644 --- a/tests/test_rds/test_rds_cloudformation.py +++ b/tests/test_rds/test_rds_cloudformation.py @@ -3,8 +3,10 @@ import json import boto3 from moto import mock_cloudformation, mock_ec2, mock_rds -from tests.test_cloudformation.fixtures import rds_mysql_with_db_parameter_group -from tests.test_cloudformation.fixtures import rds_mysql_with_read_replica +from tests.test_cloudformation.fixtures import ( + rds_mysql_with_db_parameter_group, + rds_mysql_with_read_replica, +) @mock_ec2 diff --git a/tests/test_rds/test_rds_clusters.py b/tests/test_rds/test_rds_clusters.py index b099e0f6b..d1f6a702c 100644 --- a/tests/test_rds/test_rds_clusters.py +++ b/tests/test_rds/test_rds_clusters.py @@ -1,8 +1,8 @@ import re import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_rds from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_rds/test_rds_clusters_with_instances.py b/tests/test_rds/test_rds_clusters_with_instances.py index c7352bad1..17c65f315 100644 --- a/tests/test_rds/test_rds_clusters_with_instances.py +++ b/tests/test_rds/test_rds_clusters_with_instances.py @@ -1,6 +1,6 @@ import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_rds diff --git a/tests/test_rds/test_rds_event_subscriptions.py b/tests/test_rds/test_rds_event_subscriptions.py index 7ec29d0ec..9a636f901 100644 --- a/tests/test_rds/test_rds_event_subscriptions.py +++ b/tests/test_rds/test_rds_event_subscriptions.py @@ -1,6 +1,6 @@ import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_rds from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_rds/test_rds_export_tasks.py b/tests/test_rds/test_rds_export_tasks.py index 6193cc9af..872287349 100644 --- a/tests/test_rds/test_rds_export_tasks.py +++ b/tests/test_rds/test_rds_export_tasks.py @@ -1,6 +1,6 @@ import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_rds from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_rds/test_server.py b/tests/test_rds/test_server.py index 82dab5db2..51f4104c0 100644 --- a/tests/test_rds/test_server.py +++ b/tests/test_rds/test_server.py @@ -1,4 +1,5 @@ from urllib.parse import urlencode + import moto.server as server diff --git a/tests/test_rds/test_utils.py b/tests/test_rds/test_utils.py index 0642eec3a..6ed6f5a28 100644 --- a/tests/test_rds/test_utils.py +++ b/tests/test_rds/test_utils.py @@ -1,13 +1,13 @@ import pytest from moto.rds.utils import ( + ORDERABLE_DB_INSTANCE_ENCODING, FilterDef, apply_filter, + decode_orderable_db_instance, + encode_orderable_db_instance, merge_filters, validate_filters, - encode_orderable_db_instance, - decode_orderable_db_instance, - ORDERABLE_DB_INSTANCE_ENCODING, ) diff --git a/tests/test_redshift/test_redshift.py b/tests/test_redshift/test_redshift.py index b765e10dd..e7f51b111 100644 --- a/tests/test_redshift/test_redshift.py +++ b/tests/test_redshift/test_redshift.py @@ -3,12 +3,11 @@ import re import time import boto3 +import pytest from botocore.exceptions import ClientError from dateutil.tz import tzutc -import pytest -from moto import mock_ec2 -from moto import mock_redshift +from moto import mock_ec2, mock_redshift from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_redshift/test_server.py b/tests/test_redshift/test_server.py index 4b1f86c55..75d982c0d 100644 --- a/tests/test_redshift/test_server.py +++ b/tests/test_redshift/test_server.py @@ -1,9 +1,10 @@ """Test the different server responses.""" import json import re +import unittest + import pytest import xmltodict -import unittest import moto.server as server from moto import mock_redshift, settings diff --git a/tests/test_redshiftdata/test_redshiftdata.py b/tests/test_redshiftdata/test_redshiftdata.py index 6679eb4f7..50a35d0ff 100644 --- a/tests/test_redshiftdata/test_redshiftdata.py +++ b/tests/test_redshiftdata/test_redshiftdata.py @@ -1,6 +1,6 @@ import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_redshiftdata from tests.test_redshiftdata.test_redshiftdata_constants import ErrorAttributes diff --git a/tests/test_redshiftdata/test_server.py b/tests/test_redshiftdata/test_server.py index b81f72010..3cce643e2 100644 --- a/tests/test_redshiftdata/test_server.py +++ b/tests/test_redshiftdata/test_server.py @@ -1,11 +1,12 @@ """Test different server responses.""" import json -import pytest import unittest from uuid import UUID -from moto import settings +import pytest + import moto.server as server +from moto import settings from tests.test_redshiftdata.test_redshiftdata_constants import ( DEFAULT_ENCODING, HttpHeaders, diff --git a/tests/test_resourcegroupstaggingapi/test_resourcegroupstagging_logs.py b/tests/test_resourcegroupstaggingapi/test_resourcegroupstagging_logs.py index 9bae4d153..e9190dc51 100644 --- a/tests/test_resourcegroupstaggingapi/test_resourcegroupstagging_logs.py +++ b/tests/test_resourcegroupstaggingapi/test_resourcegroupstagging_logs.py @@ -1,8 +1,8 @@ -import boto3 import unittest -from moto import mock_logs -from moto import mock_resourcegroupstaggingapi +import boto3 + +from moto import mock_logs, mock_resourcegroupstaggingapi @mock_logs diff --git a/tests/test_resourcegroupstaggingapi/test_resourcegroupstagging_rds.py b/tests/test_resourcegroupstaggingapi/test_resourcegroupstagging_rds.py index d46069c71..ab0c132e8 100644 --- a/tests/test_resourcegroupstaggingapi/test_resourcegroupstagging_rds.py +++ b/tests/test_resourcegroupstaggingapi/test_resourcegroupstagging_rds.py @@ -1,8 +1,8 @@ -import boto3 import unittest -from moto import mock_rds -from moto import mock_resourcegroupstaggingapi +import boto3 + +from moto import mock_rds, mock_resourcegroupstaggingapi @mock_rds diff --git a/tests/test_resourcegroupstaggingapi/test_resourcegroupstaggingapi.py b/tests/test_resourcegroupstaggingapi/test_resourcegroupstaggingapi.py index 5c921722e..8b44182d5 100644 --- a/tests/test_resourcegroupstaggingapi/test_resourcegroupstaggingapi.py +++ b/tests/test_resourcegroupstaggingapi/test_resourcegroupstaggingapi.py @@ -1,20 +1,22 @@ import json +import logging import boto3 from botocore.client import ClientError -from moto import mock_acm -from moto import mock_ec2 -from moto import mock_elbv2 -from moto import mock_kms -from moto import mock_resourcegroupstaggingapi -from moto import mock_s3 -from moto import mock_lambda -from moto import mock_iam -from moto import mock_cloudformation -from moto import mock_ecs +from moto import ( + mock_acm, + mock_cloudformation, + mock_ec2, + mock_ecs, + mock_elbv2, + mock_iam, + mock_kms, + mock_lambda, + mock_resourcegroupstaggingapi, + mock_s3, +) from tests import EXAMPLE_AMI_ID, EXAMPLE_AMI_ID2 -import logging @mock_kms diff --git a/tests/test_route53/test_change_set_model.py b/tests/test_route53/test_change_set_model.py index 919f14ca2..65895bda8 100644 --- a/tests/test_route53/test_change_set_model.py +++ b/tests/test_route53/test_change_set_model.py @@ -1,4 +1,5 @@ import copy + from moto.route53.models import ChangeList diff --git a/tests/test_route53/test_route53.py b/tests/test_route53/test_route53.py index c19f7531f..a284408ee 100644 --- a/tests/test_route53/test_route53.py +++ b/tests/test_route53/test_route53.py @@ -2,7 +2,6 @@ import boto3 import botocore import pytest import requests - from botocore.exceptions import ClientError from moto import mock_ec2, mock_route53, settings diff --git a/tests/test_route53/test_route53_cloudformation.py b/tests/test_route53/test_route53_cloudformation.py index fd62cf9d1..c24a8f660 100644 --- a/tests/test_route53/test_route53_cloudformation.py +++ b/tests/test_route53/test_route53_cloudformation.py @@ -1,11 +1,14 @@ -import boto3 import json - from copy import deepcopy + +import boto3 + from moto import mock_cloudformation, mock_ec2, mock_route53 -from tests.test_cloudformation.fixtures import route53_ec2_instance_with_public_ip -from tests.test_cloudformation.fixtures import route53_health_check -from tests.test_cloudformation.fixtures import route53_roundrobin +from tests.test_cloudformation.fixtures import ( + route53_ec2_instance_with_public_ip, + route53_health_check, + route53_roundrobin, +) template_hosted_zone = { "AWSTemplateFormatVersion": "2010-09-09", diff --git a/tests/test_route53/test_route53_delegationsets.py b/tests/test_route53/test_route53_delegationsets.py index c0123a778..636fbb96d 100644 --- a/tests/test_route53/test_route53_delegationsets.py +++ b/tests/test_route53/test_route53_delegationsets.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_route53 diff --git a/tests/test_route53/test_route53_healthchecks.py b/tests/test_route53/test_route53_healthchecks.py index 066763934..38f5d61a4 100644 --- a/tests/test_route53/test_route53_healthchecks.py +++ b/tests/test_route53/test_route53_healthchecks.py @@ -1,6 +1,7 @@ import boto3 import pytest from botocore.exceptions import ClientError + from moto import mock_route53 diff --git a/tests/test_route53/test_route53_query_logging_config.py b/tests/test_route53/test_route53_query_logging_config.py index 25afd5e1d..2b6e830fb 100644 --- a/tests/test_route53/test_route53_query_logging_config.py +++ b/tests/test_route53/test_route53_query_logging_config.py @@ -1,11 +1,9 @@ """Route53 unit tests specific to query_logging_config APIs.""" -import pytest - import boto3 +import pytest from botocore.exceptions import ClientError -from moto import mock_logs -from moto import mock_route53 +from moto import mock_logs, mock_route53 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.moto_api._internal import mock_random diff --git a/tests/test_route53/test_route53_vpcs.py b/tests/test_route53/test_route53_vpcs.py index 55c5904b0..88e162fc7 100644 --- a/tests/test_route53/test_route53_vpcs.py +++ b/tests/test_route53/test_route53_vpcs.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_ec2, mock_route53 diff --git a/tests/test_route53resolver/test_route53resolver_endpoint.py b/tests/test_route53resolver/test_route53resolver_endpoint.py index 762f98d7d..bbd1387a1 100644 --- a/tests/test_route53resolver/test_route53resolver_endpoint.py +++ b/tests/test_route53resolver/test_route53resolver_endpoint.py @@ -2,12 +2,10 @@ from datetime import datetime, timezone import boto3 +import pytest from botocore.exceptions import ClientError -import pytest - -from moto import mock_route53resolver -from moto import settings +from moto import mock_route53resolver, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.ec2 import mock_ec2 from moto.moto_api._internal import mock_random diff --git a/tests/test_route53resolver/test_route53resolver_rule.py b/tests/test_route53resolver/test_route53resolver_rule.py index 5fdc95dba..23bf50a57 100644 --- a/tests/test_route53resolver/test_route53resolver_rule.py +++ b/tests/test_route53resolver/test_route53resolver_rule.py @@ -1,9 +1,9 @@ """Unit tests for route53resolver rule-related APIs.""" -from botocore.exceptions import ClientError from datetime import datetime, timezone import boto3 import pytest +from botocore.exceptions import ClientError from moto import mock_route53resolver from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_route53resolver/test_route53resolver_rule_associations.py b/tests/test_route53resolver/test_route53resolver_rule_associations.py index 6a580bd9e..048b6a5da 100644 --- a/tests/test_route53resolver/test_route53resolver_rule_associations.py +++ b/tests/test_route53resolver/test_route53resolver_rule_associations.py @@ -1,8 +1,7 @@ """Unit tests for route53resolver rule association-related APIs.""" import boto3 -from botocore.exceptions import ClientError - import pytest +from botocore.exceptions import ClientError from moto import mock_route53resolver from moto.ec2 import mock_ec2 diff --git a/tests/test_route53resolver/test_route53resolver_tags.py b/tests/test_route53resolver/test_route53resolver_tags.py index 110f311c4..d42def924 100644 --- a/tests/test_route53resolver/test_route53resolver_tags.py +++ b/tests/test_route53resolver/test_route53resolver_tags.py @@ -1,8 +1,7 @@ """Route53Resolver-related unit tests focusing on tag-related functionality.""" import boto3 -from botocore.exceptions import ClientError - import pytest +from botocore.exceptions import ClientError from moto import mock_route53resolver from moto.ec2 import mock_ec2 diff --git a/tests/test_s3/__init__.py b/tests/test_s3/__init__.py index d5cda0981..fe81a5438 100644 --- a/tests/test_s3/__init__.py +++ b/tests/test_s3/__init__.py @@ -1,10 +1,12 @@ -import boto3 import os from functools import wraps -from moto import mock_s3, mock_sts, mock_s3control -from moto.s3.responses import DEFAULT_REGION_NAME from uuid import uuid4 +import boto3 + +from moto import mock_s3, mock_s3control, mock_sts +from moto.s3.responses import DEFAULT_REGION_NAME + def s3_aws_verified(func): """ diff --git a/tests/test_s3/test_multiple_accounts_server.py b/tests/test_s3/test_multiple_accounts_server.py index 9a7f87876..664890d06 100644 --- a/tests/test_s3/test_multiple_accounts_server.py +++ b/tests/test_s3/test_multiple_accounts_server.py @@ -5,7 +5,6 @@ import requests from moto import settings from moto.server import ThreadedMotoServer - SERVER_PORT = 5001 BASE_URL = f"http://localhost:{SERVER_PORT}/" diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py index d87ab5d2e..db4aff3fe 100644 --- a/tests/test_s3/test_s3.py +++ b/tests/test_s3/test_s3.py @@ -1,31 +1,30 @@ import datetime -from gzip import GzipFile -from io import BytesIO import json import os import pickle -from unittest import SkipTest -from urllib.parse import urlparse, parse_qs import uuid -from uuid import uuid4 import zlib +from gzip import GzipFile +from io import BytesIO +from unittest import SkipTest +from urllib.parse import parse_qs, urlparse +from uuid import uuid4 import boto3 -from botocore.client import ClientError import botocore.exceptions -from botocore.handlers import disable_signing -from freezegun import freeze_time import pytest import requests +from botocore.client import ClientError +from botocore.handlers import disable_signing +from freezegun import freeze_time -from moto import settings, mock_s3, mock_config -from moto.moto_api import state_manager -from moto.core.utils import utcnow -from moto import moto_proxy -from moto.s3.responses import DEFAULT_REGION_NAME import moto.s3.models as s3model - +from moto import mock_config, mock_s3, moto_proxy, settings +from moto.core.utils import utcnow +from moto.moto_api import state_manager +from moto.s3.responses import DEFAULT_REGION_NAME from tests import DEFAULT_ACCOUNT_ID + from . import s3_aws_verified diff --git a/tests/test_s3/test_s3_acl.py b/tests/test_s3/test_s3_acl.py index 156ea80e2..032b2de0e 100644 --- a/tests/test_s3/test_s3_acl.py +++ b/tests/test_s3/test_s3_acl.py @@ -4,10 +4,11 @@ from uuid import uuid4 import boto3 import pytest import requests - from botocore.exceptions import ClientError from botocore.handlers import disable_signing + from moto import mock_s3, settings + from .test_s3 import add_proxy_details DEFAULT_REGION_NAME = "us-east-1" diff --git a/tests/test_s3/test_s3_auth.py b/tests/test_s3/test_s3_auth.py index bfa553800..338f4e6e0 100644 --- a/tests/test_s3/test_s3_auth.py +++ b/tests/test_s3/test_s3_auth.py @@ -3,11 +3,11 @@ from unittest import SkipTest import boto3 import pytest - from botocore.exceptions import ClientError from moto import mock_iam, mock_s3, mock_sts, settings -from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID, set_initial_no_auth_action_count +from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID +from moto.core import set_initial_no_auth_action_count from moto.s3.responses import DEFAULT_REGION_NAME diff --git a/tests/test_s3/test_s3_bucket_policy.py b/tests/test_s3/test_s3_bucket_policy.py index 3fdd5e595..d129d461a 100644 --- a/tests/test_s3/test_s3_bucket_policy.py +++ b/tests/test_s3/test_s3_bucket_policy.py @@ -1,13 +1,13 @@ import json +from unittest import SkipTest import boto3 -import requests import pytest - +import requests from botocore.exceptions import ClientError + from moto import settings from moto.moto_server.threaded_moto_server import ThreadedMotoServer -from unittest import SkipTest class TestBucketPolicy: diff --git a/tests/test_s3/test_s3_classdecorator.py b/tests/test_s3/test_s3_classdecorator.py index d5c3c65e7..6401091cd 100644 --- a/tests/test_s3/test_s3_classdecorator.py +++ b/tests/test_s3/test_s3_classdecorator.py @@ -1,6 +1,7 @@ import unittest import boto3 + from moto import mock_s3 diff --git a/tests/test_s3/test_s3_cloudformation.py b/tests/test_s3/test_s3_cloudformation.py index b95710686..6a1f01490 100644 --- a/tests/test_s3/test_s3_cloudformation.py +++ b/tests/test_s3/test_s3_cloudformation.py @@ -3,7 +3,7 @@ import re import boto3 -from moto import mock_s3, mock_cloudformation +from moto import mock_cloudformation, mock_s3 @mock_s3 diff --git a/tests/test_s3/test_s3_config.py b/tests/test_s3/test_s3_config.py index 040984ed0..c4c64d200 100644 --- a/tests/test_s3/test_s3_config.py +++ b/tests/test_s3/test_s3_config.py @@ -1,4 +1,5 @@ import json + import pytest from moto import mock_s3 @@ -376,7 +377,7 @@ def test_s3_notification_config_dict(): @mock_s3 def test_s3_acl_to_config_dict(): - from moto.s3.models import FakeAcl, FakeGrant, FakeGrantee, OWNER + from moto.s3.models import OWNER, FakeAcl, FakeGrant, FakeGrantee # With 1 bucket in us-west-2: s3_config_query_backend.create_bucket("logbucket", "us-west-2") @@ -447,7 +448,7 @@ def test_s3_acl_to_config_dict(): @mock_s3 def test_s3_config_dict(): - from moto.s3.models import FakeAcl, FakeGrant, FakeGrantee, OWNER + from moto.s3.models import OWNER, FakeAcl, FakeGrant, FakeGrantee # Without any buckets: assert not s3_config_query.get_config_resource(DEFAULT_ACCOUNT_ID, "some_bucket") diff --git a/tests/test_s3/test_s3_copyobject.py b/tests/test_s3/test_s3_copyobject.py index 747c6d0ba..a0fca248f 100644 --- a/tests/test_s3/test_s3_copyobject.py +++ b/tests/test_s3/test_s3_copyobject.py @@ -1,11 +1,11 @@ import datetime import boto3 +import pytest from botocore.client import ClientError -from moto import mock_s3, mock_kms +from moto import mock_kms, mock_s3 from moto.s3.responses import DEFAULT_REGION_NAME -import pytest @pytest.mark.parametrize( diff --git a/tests/test_s3/test_s3_cross_account.py b/tests/test_s3/test_s3_cross_account.py index 93fe1d8df..78cc1e38c 100644 --- a/tests/test_s3/test_s3_cross_account.py +++ b/tests/test_s3/test_s3_cross_account.py @@ -2,10 +2,10 @@ import os from unittest import SkipTest, mock import boto3 -from botocore.client import ClientError import pytest +from botocore.client import ClientError -from moto import settings, mock_s3 +from moto import mock_s3, settings from moto.s3.responses import DEFAULT_REGION_NAME diff --git a/tests/test_s3/test_s3_custom_endpoint.py b/tests/test_s3/test_s3_custom_endpoint.py index ea97b4e7f..dc40edd51 100644 --- a/tests/test_s3/test_s3_custom_endpoint.py +++ b/tests/test_s3/test_s3_custom_endpoint.py @@ -7,7 +7,6 @@ import pytest from moto import mock_s3, settings - DEFAULT_REGION_NAME = "us-east-1" CUSTOM_ENDPOINT = "https://s3.local.some-test-domain.de" CUSTOM_ENDPOINT_2 = "https://caf-o.s3-ext.jc.rl.ac.uk" diff --git a/tests/test_s3/test_s3_encryption.py b/tests/test_s3/test_s3_encryption.py index e8f8683cf..b0662f43c 100644 --- a/tests/test_s3/test_s3_encryption.py +++ b/tests/test_s3/test_s3_encryption.py @@ -1,8 +1,8 @@ from uuid import uuid4 import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_s3 diff --git a/tests/test_s3/test_s3_file_handles.py b/tests/test_s3/test_s3_file_handles.py index 6e50c899b..c738ff1e5 100644 --- a/tests/test_s3/test_s3_file_handles.py +++ b/tests/test_s3/test_s3_file_handles.py @@ -6,14 +6,13 @@ from unittest import SkipTest, TestCase import boto3 -from moto import settings, mock_s3 +from moto import mock_s3, settings from moto.dynamodb.models import DynamoDBBackend -from moto.s3 import models as s3model, s3_backends +from moto.s3 import models as s3model +from moto.s3 import s3_backends from moto.s3.responses import S3Response - from tests import DEFAULT_ACCOUNT_ID - TEST_BUCKET = "my-bucket" TEST_BUCKET_VERSIONED = "versioned-bucket" TEST_KEY = "my-key" diff --git a/tests/test_s3/test_s3_lambda_integration.py b/tests/test_s3/test_s3_lambda_integration.py index 301af5f49..0762148db 100644 --- a/tests/test_s3/test_s3_lambda_integration.py +++ b/tests/test_s3/test_s3_lambda_integration.py @@ -8,12 +8,11 @@ from moto import mock_lambda, mock_logs, mock_s3, mock_sns, mock_sqs from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from tests.markers import requires_docker from tests.test_awslambda.utilities import ( - get_test_zip_file_print_event, get_role_name, + get_test_zip_file_print_event, wait_for_log_msg, ) - REGION_NAME = "us-east-1" diff --git a/tests/test_s3/test_s3_lifecycle.py b/tests/test_s3/test_s3_lifecycle.py index 19bcbea2d..fb80ee134 100644 --- a/tests/test_s3/test_s3_lifecycle.py +++ b/tests/test_s3/test_s3_lifecycle.py @@ -1,8 +1,8 @@ from datetime import datetime import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_s3 diff --git a/tests/test_s3/test_s3_lock.py b/tests/test_s3/test_s3_lock.py index ef3338159..e56554185 100644 --- a/tests/test_s3/test_s3_lock.py +++ b/tests/test_s3/test_s3_lock.py @@ -2,9 +2,9 @@ import datetime import time import boto3 -from botocore.config import Config -from botocore.client import ClientError import pytest +from botocore.client import ClientError +from botocore.config import Config from moto import mock_s3 from moto.core.utils import utcnow diff --git a/tests/test_s3/test_s3_logging.py b/tests/test_s3/test_s3_logging.py index 91bb4e1ff..1ade74b1a 100644 --- a/tests/test_s3/test_s3_logging.py +++ b/tests/test_s3/test_s3_logging.py @@ -1,14 +1,12 @@ import json +from unittest import SkipTest +from unittest.mock import patch import boto3 import pytest from botocore.client import ClientError -from unittest import SkipTest -from unittest.mock import patch - -from moto import mock_s3 -from moto import settings +from moto import mock_s3, settings from moto.core import DEFAULT_ACCOUNT_ID from moto.s3 import s3_backends from moto.s3.models import FakeBucket diff --git a/tests/test_s3/test_s3_multipart.py b/tests/test_s3/test_s3_multipart.py index b80869fe5..821c062e4 100644 --- a/tests/test_s3/test_s3_multipart.py +++ b/tests/test_s3/test_s3_multipart.py @@ -1,23 +1,24 @@ -from functools import wraps -from io import BytesIO import os import re - -import boto3 -from botocore.client import ClientError -import pytest -import requests +from functools import wraps +from io import BytesIO from unittest import SkipTest -from moto import settings, mock_s3 +import boto3 +import pytest +import requests +from botocore.client import ClientError + import moto.s3.models as s3model +from moto import mock_s3, settings from moto.s3.responses import DEFAULT_REGION_NAME from moto.settings import ( - get_s3_default_key_buffer_size, S3_UPLOAD_PART_MIN_SIZE, + get_s3_default_key_buffer_size, test_proxy_mode, ) from tests import DEFAULT_ACCOUNT_ID + from .test_s3 import add_proxy_details if settings.TEST_DECORATOR_MODE: diff --git a/tests/test_s3/test_s3_ownership.py b/tests/test_s3/test_s3_ownership.py index f973ce973..fc4913ef9 100644 --- a/tests/test_s3/test_s3_ownership.py +++ b/tests/test_s3/test_s3_ownership.py @@ -1,6 +1,6 @@ import boto3 -from botocore.client import ClientError import pytest +from botocore.client import ClientError from moto import mock_s3 from moto.s3.responses import DEFAULT_REGION_NAME diff --git a/tests/test_s3/test_s3_replication.py b/tests/test_s3/test_s3_replication.py index 0f70bca8c..3c7d5f2b2 100644 --- a/tests/test_s3/test_s3_replication.py +++ b/tests/test_s3/test_s3_replication.py @@ -1,8 +1,8 @@ from uuid import uuid4 import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_s3 diff --git a/tests/test_s3/test_s3_select.py b/tests/test_s3/test_s3_select.py index 84a80dc34..8d55ed546 100644 --- a/tests/test_s3/test_s3_select.py +++ b/tests/test_s3/test_s3_select.py @@ -1,10 +1,10 @@ -import boto3 import json + +import boto3 import pytest from . import s3_aws_verified - SIMPLE_JSON = {"a1": "b1", "a2": "b2", "a3": None} SIMPLE_JSON2 = {"a1": "b2", "a3": "b3"} NESTED_JSON = {"a1": {"b1": "b2"}, "a2": [True, False], "a3": True, "a4": [1, 5]} diff --git a/tests/test_s3/test_s3_storageclass.py b/tests/test_s3/test_s3_storageclass.py index c2f40ffd2..f342fefdb 100644 --- a/tests/test_s3/test_s3_storageclass.py +++ b/tests/test_s3/test_s3_storageclass.py @@ -1,6 +1,6 @@ import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_s3 diff --git a/tests/test_s3/test_s3_tagging.py b/tests/test_s3/test_s3_tagging.py index f6350959a..de5215270 100644 --- a/tests/test_s3/test_s3_tagging.py +++ b/tests/test_s3/test_s3_tagging.py @@ -1,10 +1,11 @@ import boto3 -from botocore.client import ClientError import pytest import requests +from botocore.client import ClientError from moto import mock_s3, settings from moto.s3.responses import DEFAULT_REGION_NAME + from .test_s3 import add_proxy_details diff --git a/tests/test_s3/test_s3_utils.py b/tests/test_s3/test_s3_utils.py index 43731617f..32c0990b1 100644 --- a/tests/test_s3/test_s3_utils.py +++ b/tests/test_s3/test_s3_utils.py @@ -1,11 +1,13 @@ from unittest.mock import patch + import pytest + from moto.s3.utils import ( - bucket_name_from_url, _VersionedKeyStore, - parse_region_from_url, + bucket_name_from_url, compute_checksum, cors_matches_origin, + parse_region_from_url, ) diff --git a/tests/test_s3/test_server.py b/tests/test_s3/test_server.py index 6e48a9e6e..7af3fe21e 100644 --- a/tests/test_s3/test_server.py +++ b/tests/test_s3/test_server.py @@ -1,12 +1,12 @@ """Test different server responses.""" import io from unittest.mock import patch -from urllib.parse import urlparse, parse_qs -import xmltodict +from urllib.parse import parse_qs, urlparse -from flask.testing import FlaskClient import pytest import requests +import xmltodict +from flask.testing import FlaskClient import moto.server as server from moto.moto_server.threaded_moto_server import ThreadedMotoServer diff --git a/tests/test_s3bucket_path/test_server.py b/tests/test_s3bucket_path/test_server.py index 1af7f3d11..c70f441db 100644 --- a/tests/test_s3bucket_path/test_server.py +++ b/tests/test_s3bucket_path/test_server.py @@ -1,5 +1,6 @@ """Test the different server responses.""" from flask.testing import FlaskClient + import moto.server as server diff --git a/tests/test_s3control/test_s3control.py b/tests/test_s3control/test_s3control.py index fbf925c21..f7c95cd69 100644 --- a/tests/test_s3control/test_s3control.py +++ b/tests/test_s3control/test_s3control.py @@ -1,8 +1,8 @@ import boto3 import pytest - from boto3 import Session from botocore.client import ClientError + from moto import mock_s3control diff --git a/tests/test_s3control/test_s3control_access_points.py b/tests/test_s3control/test_s3control_access_points.py index 265a0b83e..7f3295cb5 100644 --- a/tests/test_s3control/test_s3control_access_points.py +++ b/tests/test_s3control/test_s3control_access_points.py @@ -1,10 +1,10 @@ import re +from uuid import uuid4 import boto3 import pytest - from botocore.client import ClientError -from uuid import uuid4 + from moto import mock_s3control from tests.test_s3 import s3_aws_verified diff --git a/tests/test_s3control/test_s3control_accesspoint_policy.py b/tests/test_s3control/test_s3control_accesspoint_policy.py index a2e6e7f36..0f4270468 100644 --- a/tests/test_s3control/test_s3control_accesspoint_policy.py +++ b/tests/test_s3control/test_s3control_accesspoint_policy.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.client import ClientError + from moto import mock_s3control diff --git a/tests/test_s3control/test_s3control_config_integration.py b/tests/test_s3control/test_s3control_config_integration.py index ec5ce3cb0..fb2214678 100644 --- a/tests/test_s3control/test_s3control_config_integration.py +++ b/tests/test_s3control/test_s3control_config_integration.py @@ -1,10 +1,11 @@ import json -import pytest import boto3 +import pytest from boto3 import Session from botocore.client import ClientError -from moto import settings, mock_s3control, mock_config + +from moto import mock_config, mock_s3control, settings # All tests for s3-control cannot be run under the server without a modification of the # hosts file on your system. This is due to the fact that the URL to the host is in the form of: diff --git a/tests/test_s3control/test_s3control_s3.py b/tests/test_s3control/test_s3control_s3.py index 2ea3d3afb..b3c12d7d0 100644 --- a/tests/test_s3control/test_s3control_s3.py +++ b/tests/test_s3control/test_s3control_s3.py @@ -4,7 +4,6 @@ import boto3 from moto import mock_s3, mock_s3control, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID - REGION = "us-east-1" diff --git a/tests/test_sagemaker/test_sagemaker_cloudformation.py b/tests/test_sagemaker/test_sagemaker_cloudformation.py index 7f0f0129f..b456ede50 100644 --- a/tests/test_sagemaker/test_sagemaker_cloudformation.py +++ b/tests/test_sagemaker/test_sagemaker_cloudformation.py @@ -1,18 +1,18 @@ import re import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_cloudformation, mock_sagemaker from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from .cloudformation_test_configs import ( - NotebookInstanceTestConfig, - NotebookInstanceLifecycleConfigTestConfig, - ModelTestConfig, EndpointConfigTestConfig, EndpointTestConfig, + ModelTestConfig, + NotebookInstanceLifecycleConfigTestConfig, + NotebookInstanceTestConfig, ) diff --git a/tests/test_sagemaker/test_sagemaker_endpoint.py b/tests/test_sagemaker/test_sagemaker_endpoint.py index 053a3fdbe..647c310ef 100644 --- a/tests/test_sagemaker/test_sagemaker_endpoint.py +++ b/tests/test_sagemaker/test_sagemaker_endpoint.py @@ -3,11 +3,11 @@ import re import uuid import boto3 +import pytest from botocore.exceptions import ClientError from moto import mock_sagemaker from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -import pytest TEST_REGION_NAME = "us-east-1" TEST_ROLE_ARN = f"arn:aws:iam::{ACCOUNT_ID}:role/FakeRole" diff --git a/tests/test_sagemaker/test_sagemaker_model_package_groups.py b/tests/test_sagemaker/test_sagemaker_model_package_groups.py index 966286ed0..9092ed9a5 100644 --- a/tests/test_sagemaker/test_sagemaker_model_package_groups.py +++ b/tests/test_sagemaker/test_sagemaker_model_package_groups.py @@ -1,10 +1,10 @@ """Unit tests for sagemaker-supported APIs.""" -from unittest import SkipTest from datetime import datetime +from unittest import SkipTest import boto3 -from freezegun import freeze_time from dateutil.tz import tzutc # type: ignore +from freezegun import freeze_time from moto import mock_sagemaker, settings diff --git a/tests/test_sagemaker/test_sagemaker_model_packages.py b/tests/test_sagemaker/test_sagemaker_model_packages.py index 4d9f326ae..1a8f303b6 100644 --- a/tests/test_sagemaker/test_sagemaker_model_packages.py +++ b/tests/test_sagemaker/test_sagemaker_model_packages.py @@ -3,13 +3,12 @@ from datetime import datetime from unittest import SkipTest, TestCase import boto3 -from freezegun import freeze_time +import pytest from dateutil.tz import tzutc # type: ignore +from freezegun import freeze_time from moto import mock_sagemaker, settings -import pytest - # See our Development Tips on writing tests for hints on how to write good tests: # http://docs.getmoto.org/en/latest/docs/contributing/development_tips/tests.html from moto.sagemaker.exceptions import ValidationError diff --git a/tests/test_sagemaker/test_sagemaker_models.py b/tests/test_sagemaker/test_sagemaker_models.py index d7c3c829c..41be9a582 100644 --- a/tests/test_sagemaker/test_sagemaker_models.py +++ b/tests/test_sagemaker/test_sagemaker_models.py @@ -1,8 +1,8 @@ import re import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_sagemaker from moto.sagemaker.models import VpcConfig diff --git a/tests/test_sagemaker/test_sagemaker_notebooks.py b/tests/test_sagemaker/test_sagemaker_notebooks.py index f1d7e015a..034261d15 100644 --- a/tests/test_sagemaker/test_sagemaker_notebooks.py +++ b/tests/test_sagemaker/test_sagemaker_notebooks.py @@ -1,8 +1,8 @@ import datetime import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_sagemaker from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_sagemaker/test_sagemaker_pipeline.py b/tests/test_sagemaker/test_sagemaker_pipeline.py index 3183b1c6c..8323eb29b 100644 --- a/tests/test_sagemaker/test_sagemaker_pipeline.py +++ b/tests/test_sagemaker/test_sagemaker_pipeline.py @@ -1,6 +1,6 @@ +import json from contextlib import contextmanager from datetime import datetime -import json from time import sleep from unittest import SkipTest @@ -9,17 +9,17 @@ import botocore import pytest from moto import mock_sagemaker, settings -from moto.s3 import mock_s3 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID +from moto.s3 import mock_s3 from moto.sagemaker.exceptions import ValidationError -from moto.sagemaker.utils import ( - get_pipeline_from_name, - get_pipeline_execution_from_arn, - get_pipeline_name_from_execution_arn, -) from moto.sagemaker.models import FakePipeline, sagemaker_backends -from moto.sagemaker.utils import arn_formatter, load_pipeline_definition_from_s3 - +from moto.sagemaker.utils import ( + arn_formatter, + get_pipeline_execution_from_arn, + get_pipeline_from_name, + get_pipeline_name_from_execution_arn, + load_pipeline_definition_from_s3, +) FAKE_ROLE_ARN = f"arn:aws:iam::{ACCOUNT_ID}:role/FakeRole" TEST_REGION_NAME = "us-west-1" diff --git a/tests/test_sagemaker/test_sagemaker_processing.py b/tests/test_sagemaker/test_sagemaker_processing.py index fefac10f4..bf68895f5 100644 --- a/tests/test_sagemaker/test_sagemaker_processing.py +++ b/tests/test_sagemaker/test_sagemaker_processing.py @@ -2,8 +2,8 @@ import datetime import re import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_sagemaker from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_sagemaker/test_sagemaker_search.py b/tests/test_sagemaker/test_sagemaker_search.py index 20d2bcc18..ca20cd136 100644 --- a/tests/test_sagemaker/test_sagemaker_search.py +++ b/tests/test_sagemaker/test_sagemaker_search.py @@ -1,6 +1,6 @@ import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_sagemaker diff --git a/tests/test_sagemaker/test_sagemaker_training.py b/tests/test_sagemaker/test_sagemaker_training.py index b3be6df8d..d691619a8 100644 --- a/tests/test_sagemaker/test_sagemaker_training.py +++ b/tests/test_sagemaker/test_sagemaker_training.py @@ -2,8 +2,8 @@ import datetime import re import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_sagemaker from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_sagemaker/test_sagemaker_transform.py b/tests/test_sagemaker/test_sagemaker_transform.py index a4459d46b..956b21fd1 100644 --- a/tests/test_sagemaker/test_sagemaker_transform.py +++ b/tests/test_sagemaker/test_sagemaker_transform.py @@ -2,8 +2,8 @@ import datetime import re import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_sagemaker from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_sagemaker/test_sagemaker_trial_component.py b/tests/test_sagemaker/test_sagemaker_trial_component.py index f460ee54f..6f33596e9 100644 --- a/tests/test_sagemaker/test_sagemaker_trial_component.py +++ b/tests/test_sagemaker/test_sagemaker_trial_component.py @@ -1,8 +1,8 @@ import uuid import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_sagemaker from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_scheduler/test_schedule_groups.py b/tests/test_scheduler/test_schedule_groups.py index ced28e4af..fae0e455f 100644 --- a/tests/test_scheduler/test_schedule_groups.py +++ b/tests/test_scheduler/test_schedule_groups.py @@ -1,8 +1,8 @@ """Unit tests for scheduler-supported APIs.""" import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_scheduler from moto.core import DEFAULT_ACCOUNT_ID diff --git a/tests/test_scheduler/test_scheduler.py b/tests/test_scheduler/test_scheduler.py index fea2ca458..7abab8173 100644 --- a/tests/test_scheduler/test_scheduler.py +++ b/tests/test_scheduler/test_scheduler.py @@ -1,9 +1,10 @@ """Unit tests for scheduler-supported APIs.""" +from datetime import datetime + import boto3 import pytest - from botocore.client import ClientError -from datetime import datetime + from moto import mock_scheduler from moto.core import DEFAULT_ACCOUNT_ID diff --git a/tests/test_sdb/test_sdb_attributes.py b/tests/test_sdb/test_sdb_attributes.py index 9f07d08fe..337279bb2 100644 --- a/tests/test_sdb/test_sdb_attributes.py +++ b/tests/test_sdb/test_sdb_attributes.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_sdb diff --git a/tests/test_sdb/test_sdb_domains.py b/tests/test_sdb/test_sdb_domains.py index e40637ca8..6a9265264 100644 --- a/tests/test_sdb/test_sdb_domains.py +++ b/tests/test_sdb/test_sdb_domains.py @@ -1,7 +1,7 @@ import boto3 import pytest - from botocore.exceptions import ClientError + from moto import mock_sdb diff --git a/tests/test_secretsmanager/test_list_secrets.py b/tests/test_secretsmanager/test_list_secrets.py index f84d72e31..a69510e95 100644 --- a/tests/test_secretsmanager/test_list_secrets.py +++ b/tests/test_secretsmanager/test_list_secrets.py @@ -2,9 +2,9 @@ from datetime import datetime import boto3 +import pytest from botocore.exceptions import ClientError from dateutil.tz import tzlocal -import pytest from moto import mock_secretsmanager diff --git a/tests/test_secretsmanager/test_policy.py b/tests/test_secretsmanager/test_policy.py index f501b403d..e5ce60f14 100644 --- a/tests/test_secretsmanager/test_policy.py +++ b/tests/test_secretsmanager/test_policy.py @@ -1,8 +1,8 @@ import json import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_secretsmanager diff --git a/tests/test_secretsmanager/test_secretsmanager.py b/tests/test_secretsmanager/test_secretsmanager.py index a06d26e2d..08c76d17e 100644 --- a/tests/test_secretsmanager/test_secretsmanager.py +++ b/tests/test_secretsmanager/test_secretsmanager.py @@ -1,17 +1,17 @@ -from datetime import datetime, timedelta, timezone import os import re import string +from datetime import datetime, timedelta, timezone from unittest import SkipTest from uuid import uuid4 import boto3 +import pytest from botocore.exceptions import ClientError, ParamValidationError from dateutil.tz import tzlocal from freezegun import freeze_time -import pytest -from moto import mock_secretsmanager, mock_lambda, settings +from moto import mock_lambda, mock_secretsmanager, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID DEFAULT_SECRET_NAME = "test-secret7" diff --git a/tests/test_secretsmanager/test_server.py b/tests/test_secretsmanager/test_server.py index 9911eb9cd..60c8978d4 100644 --- a/tests/test_secretsmanager/test_server.py +++ b/tests/test_secretsmanager/test_server.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- import json +import unittest import boto3 import pytest -import unittest import moto.server as server -from moto import mock_secretsmanager, mock_lambda, mock_iam, mock_logs, settings +from moto import mock_iam, mock_lambda, mock_logs, mock_secretsmanager, settings from tests.markers import requires_docker from tests.test_awslambda.test_lambda import get_test_zip_file1 diff --git a/tests/test_servicediscovery/test_servicediscovery_httpnamespaces.py b/tests/test_servicediscovery/test_servicediscovery_httpnamespaces.py index d99e972d4..342c79c84 100644 --- a/tests/test_servicediscovery/test_servicediscovery_httpnamespaces.py +++ b/tests/test_servicediscovery/test_servicediscovery_httpnamespaces.py @@ -2,8 +2,8 @@ import re import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_servicediscovery from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_servicediscovery/test_servicediscovery_operations.py b/tests/test_servicediscovery/test_servicediscovery_operations.py index 1a1946e9a..310b2ef39 100644 --- a/tests/test_servicediscovery/test_servicediscovery_operations.py +++ b/tests/test_servicediscovery/test_servicediscovery_operations.py @@ -2,8 +2,8 @@ import re import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_servicediscovery diff --git a/tests/test_servicediscovery/test_servicediscovery_service.py b/tests/test_servicediscovery/test_servicediscovery_service.py index 291e6349c..88893161c 100644 --- a/tests/test_servicediscovery/test_servicediscovery_service.py +++ b/tests/test_servicediscovery/test_servicediscovery_service.py @@ -1,7 +1,7 @@ """Unit tests for servicediscovery-supported APIs.""" import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_servicediscovery diff --git a/tests/test_servicequotas/test_servicequotas.py b/tests/test_servicequotas/test_servicequotas.py index 39570bb66..00b84986c 100644 --- a/tests/test_servicequotas/test_servicequotas.py +++ b/tests/test_servicequotas/test_servicequotas.py @@ -1,7 +1,7 @@ """Unit tests for servicequotas-supported APIs.""" import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_servicequotas diff --git a/tests/test_ses/__init__.py b/tests/test_ses/__init__.py index 914f7dfe5..78e3b825a 100644 --- a/tests/test_ses/__init__.py +++ b/tests/test_ses/__init__.py @@ -1,5 +1,6 @@ import os from functools import wraps + from moto import mock_ses diff --git a/tests/test_ses/test_server.py b/tests/test_ses/test_server.py index 3b7cb7137..0adddcfef 100644 --- a/tests/test_ses/test_server.py +++ b/tests/test_ses/test_server.py @@ -1,6 +1,6 @@ """Test the different server responses.""" -from datetime import datetime import re +from datetime import datetime import moto.server as server diff --git a/tests/test_ses/test_ses_boto3.py b/tests/test_ses/test_ses_boto3.py index 770839895..4e61f22ba 100644 --- a/tests/test_ses/test_ses_boto3.py +++ b/tests/test_ses/test_ses_boto3.py @@ -3,10 +3,11 @@ from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import boto3 -from botocore.exceptions import ClientError -from botocore.exceptions import ParamValidationError import pytest +from botocore.exceptions import ClientError, ParamValidationError + from moto import mock_ses + from . import ses_aws_verified diff --git a/tests/test_ses/test_ses_sns_boto3.py b/tests/test_ses/test_ses_sns_boto3.py index f56ef4b12..8c5f17f11 100644 --- a/tests/test_ses/test_ses_sns_boto3.py +++ b/tests/test_ses/test_ses_sns_boto3.py @@ -3,8 +3,8 @@ import json import boto3 from moto import mock_ses, mock_sns, mock_sqs -from moto.ses.models import SESFeedback from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID +from moto.ses.models import SESFeedback @mock_ses diff --git a/tests/test_sesv2/test_sesv2.py b/tests/test_sesv2/test_sesv2.py index f390800c1..785369667 100644 --- a/tests/test_sesv2/test_sesv2.py +++ b/tests/test_sesv2/test_sesv2.py @@ -1,9 +1,11 @@ import boto3 -from botocore.exceptions import ClientError import pytest -from moto import mock_sesv2, mock_ses, settings -from moto.ses.models import ses_backends, RawMessage, Message +from botocore.exceptions import ClientError + +from moto import mock_ses, mock_sesv2, settings +from moto.ses.models import Message, RawMessage, ses_backends from tests import DEFAULT_ACCOUNT_ID + from ..test_ses.test_ses_boto3 import get_raw_email diff --git a/tests/test_sns/__init__.py b/tests/test_sns/__init__.py index c41ea932d..555f0781f 100644 --- a/tests/test_sns/__init__.py +++ b/tests/test_sns/__init__.py @@ -1,10 +1,12 @@ -import boto3 -import botocore import os from functools import wraps -from moto import mock_sns, mock_sts from unittest import SkipTest +import boto3 +import botocore + +from moto import mock_sns, mock_sts + def sns_aws_verified(func): """ diff --git a/tests/test_sns/test_application_boto3.py b/tests/test_sns/test_application_boto3.py index b02281547..04714bb03 100644 --- a/tests/test_sns/test_application_boto3.py +++ b/tests/test_sns/test_application_boto3.py @@ -1,7 +1,8 @@ +from uuid import uuid4 + import boto3 import pytest from botocore.exceptions import ClientError -from uuid import uuid4 from moto import mock_sns from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_sns/test_publish_batch.py b/tests/test_sns/test_publish_batch.py index 80d7ef69d..ca3792524 100644 --- a/tests/test_sns/test_publish_batch.py +++ b/tests/test_sns/test_publish_batch.py @@ -1,8 +1,8 @@ import json import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_sns, mock_sqs from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_sns/test_publishing_boto3.py b/tests/test_sns/test_publishing_boto3.py index 7b429a648..0fadf872c 100644 --- a/tests/test_sns/test_publishing_boto3.py +++ b/tests/test_sns/test_publishing_boto3.py @@ -4,9 +4,9 @@ import re from unittest import SkipTest import boto3 +import pytest from botocore.exceptions import ClientError from freezegun import freeze_time -import pytest from moto import mock_sns, mock_sqs, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_sns/test_server.py b/tests/test_sns/test_server.py index 778e96b2a..11fa05b4b 100644 --- a/tests/test_sns/test_server.py +++ b/tests/test_sns/test_server.py @@ -1,6 +1,6 @@ """Test the different server responses.""" -from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID import moto.server as server +from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID def test_sns_server_get(): diff --git a/tests/test_sns/test_subscriptions_boto3.py b/tests/test_sns/test_subscriptions_boto3.py index 3b7ce9d0d..700ccd32a 100644 --- a/tests/test_sns/test_subscriptions_boto3.py +++ b/tests/test_sns/test_subscriptions_boto3.py @@ -1,14 +1,14 @@ import json import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_sns, mock_sqs from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.sns.models import ( - DEFAULT_PAGE_SIZE, DEFAULT_EFFECTIVE_DELIVERY_POLICY, + DEFAULT_PAGE_SIZE, ) diff --git a/tests/test_sns/test_topics_boto3.py b/tests/test_sns/test_topics_boto3.py index 35fe4ffdd..d5c5ef144 100644 --- a/tests/test_sns/test_topics_boto3.py +++ b/tests/test_sns/test_topics_boto3.py @@ -1,11 +1,12 @@ import json import boto3 -from botocore.exceptions import ClientError -from moto import mock_sns -from moto.sns.models import DEFAULT_EFFECTIVE_DELIVERY_POLICY, DEFAULT_PAGE_SIZE -from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID import pytest +from botocore.exceptions import ClientError + +from moto import mock_sns +from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID +from moto.sns.models import DEFAULT_EFFECTIVE_DELIVERY_POLICY, DEFAULT_PAGE_SIZE @mock_sns diff --git a/tests/test_special_cases/test_custom_amis.py b/tests/test_special_cases/test_custom_amis.py index ccdfaffb6..41c27d5ae 100644 --- a/tests/test_special_cases/test_custom_amis.py +++ b/tests/test_special_cases/test_custom_amis.py @@ -2,15 +2,16 @@ This test lives on its own as it requires moto to be imported after setting of MOTO_AMIS_PATH env var, as per ec2 models documentation """ -import boto3 +import importlib import json import os -import importlib -from unittest import SkipTest, TestCase, mock from pathlib import Path +from unittest import SkipTest, TestCase, mock + +import boto3 import moto -from moto import settings, mock_ec2 +from moto import mock_ec2, settings from moto.core import DEFAULT_ACCOUNT_ID from moto.ec2.models import ec2_backends diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index dd6eb3805..3dc3be847 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -9,19 +9,19 @@ from uuid import uuid4 import boto3 import botocore.exceptions +import pytest from botocore.exceptions import ClientError from freezegun import freeze_time -import pytest from moto import mock_sqs, settings -from moto.utilities.distutils_version import LooseVersion from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.sqs.models import ( - Queue, + MAXIMUM_MESSAGE_LENGTH, MAXIMUM_MESSAGE_SIZE_ATTR_LOWER_BOUND, MAXIMUM_MESSAGE_SIZE_ATTR_UPPER_BOUND, - MAXIMUM_MESSAGE_LENGTH, + Queue, ) +from moto.utilities.distutils_version import LooseVersion TEST_POLICY = """ { diff --git a/tests/test_sqs/test_sqs_cloudformation.py b/tests/test_sqs/test_sqs_cloudformation.py index 5e35cd8ae..e1e0e8b19 100644 --- a/tests/test_sqs/test_sqs_cloudformation.py +++ b/tests/test_sqs/test_sqs_cloudformation.py @@ -1,11 +1,11 @@ import json -from string import Template from random import randint +from string import Template from uuid import uuid4 import boto3 -from moto import mock_sqs, mock_cloudformation +from moto import mock_cloudformation, mock_sqs from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID simple_queue = Template( diff --git a/tests/test_sqs/test_sqs_integration.py b/tests/test_sqs/test_sqs_integration.py index 9c7b43ebc..84fbd864d 100644 --- a/tests/test_sqs/test_sqs_integration.py +++ b/tests/test_sqs/test_sqs_integration.py @@ -4,9 +4,9 @@ import uuid import boto3 -from moto import mock_lambda, mock_sqs, mock_logs +from moto import mock_lambda, mock_logs, mock_sqs from tests.markers import requires_docker -from tests.test_awslambda.test_lambda import get_test_zip_file1, get_role_name +from tests.test_awslambda.test_lambda import get_role_name, get_test_zip_file1 from tests.test_awslambda.utilities import get_test_zip_file_print_event diff --git a/tests/test_sqs/test_sqs_multiaccount.py b/tests/test_sqs/test_sqs_multiaccount.py index e569bf769..a9a74edd8 100644 --- a/tests/test_sqs/test_sqs_multiaccount.py +++ b/tests/test_sqs/test_sqs_multiaccount.py @@ -3,7 +3,7 @@ from uuid import uuid4 import boto3 -from moto import mock_sts, mock_sqs +from moto import mock_sqs, mock_sts class TestStsAssumeRole(unittest.TestCase): diff --git a/tests/test_ssm/test_ssm_boto3.py b/tests/test_ssm/test_ssm_boto3.py index fc8a4af17..33f2d86c2 100644 --- a/tests/test_ssm/test_ssm_boto3.py +++ b/tests/test_ssm/test_ssm_boto3.py @@ -5,12 +5,12 @@ import uuid import boto3 import botocore.exceptions -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_ec2, mock_ssm from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from moto.ssm.models import PARAMETER_VERSION_LIMIT, PARAMETER_HISTORY_MAX_RESULTS +from moto.ssm.models import PARAMETER_HISTORY_MAX_RESULTS, PARAMETER_VERSION_LIMIT from tests import EXAMPLE_AMI_ID diff --git a/tests/test_ssm/test_ssm_cloudformation.py b/tests/test_ssm/test_ssm_cloudformation.py index ff7e42abb..95d26421a 100644 --- a/tests/test_ssm/test_ssm_cloudformation.py +++ b/tests/test_ssm/test_ssm_cloudformation.py @@ -2,7 +2,7 @@ import json import boto3 -from moto import mock_ssm, mock_cloudformation +from moto import mock_cloudformation, mock_ssm from tests import EXAMPLE_AMI_ID diff --git a/tests/test_ssm/test_ssm_default_amis.py b/tests/test_ssm/test_ssm_default_amis.py index d64f1c79e..f5e933ba2 100644 --- a/tests/test_ssm/test_ssm_default_amis.py +++ b/tests/test_ssm/test_ssm_default_amis.py @@ -2,7 +2,6 @@ import boto3 from moto import mock_ssm - test_ami = "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64" diff --git a/tests/test_ssm/test_ssm_doc_permissions.py b/tests/test_ssm/test_ssm_doc_permissions.py index af0ac18a7..3d61a64b9 100644 --- a/tests/test_ssm/test_ssm_doc_permissions.py +++ b/tests/test_ssm/test_ssm_doc_permissions.py @@ -1,11 +1,12 @@ import re -import yaml import boto3 -from botocore.exceptions import ClientError import pytest +import yaml +from botocore.exceptions import ClientError from moto import mock_ssm + from .test_ssm_docs import _get_yaml_template diff --git a/tests/test_ssm/test_ssm_docs.py b/tests/test_ssm/test_ssm_docs.py index ba04c0d8d..8cad210f9 100644 --- a/tests/test_ssm/test_ssm_docs.py +++ b/tests/test_ssm/test_ssm_docs.py @@ -1,18 +1,18 @@ import copy import datetime -from datetime import timezone import hashlib import json import pkgutil -import yaml +from datetime import timezone import boto3 import botocore.exceptions -from botocore.exceptions import ClientError import pytest +import yaml +from botocore.exceptions import ClientError -from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto import mock_ssm +from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID def _get_yaml_template(): diff --git a/tests/test_ssm/test_ssm_ec2_integration.py b/tests/test_ssm/test_ssm_ec2_integration.py index a9b23e15a..141cf87e7 100644 --- a/tests/test_ssm/test_ssm_ec2_integration.py +++ b/tests/test_ssm/test_ssm_ec2_integration.py @@ -1,9 +1,9 @@ -import boto3 import os +from unittest import SkipTest, mock + +import boto3 from moto import mock_ec2, mock_ssm, settings -from unittest import mock, SkipTest - test_ami = "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64" diff --git a/tests/test_ssm/test_ssm_ecs_images.py b/tests/test_ssm/test_ssm_ecs_images.py index 0e6f038ce..4846b6b96 100644 --- a/tests/test_ssm/test_ssm_ecs_images.py +++ b/tests/test_ssm/test_ssm_ecs_images.py @@ -1,8 +1,9 @@ -import boto3 import os +from unittest import SkipTest, mock + +import boto3 from moto import mock_ec2, mock_ssm, settings -from unittest import mock, SkipTest # The default AMIs are not loaded for our test case, to speed things up diff --git a/tests/test_ssm/test_ssm_secretsmanager.py b/tests/test_ssm/test_ssm_secretsmanager.py index 276b8dce2..cee57ef66 100644 --- a/tests/test_ssm/test_ssm_secretsmanager.py +++ b/tests/test_ssm/test_ssm_secretsmanager.py @@ -1,11 +1,10 @@ import json import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError -from moto import mock_ssm, mock_secretsmanager - +from moto import mock_secretsmanager, mock_ssm # https://docs.aws.amazon.com/systems-manager/latest/userguide/integration-ps-secretsmanager.html diff --git a/tests/test_ssm/test_ssm_utils.py b/tests/test_ssm/test_ssm_utils.py index 2c18cd9a9..3889dd807 100644 --- a/tests/test_ssm/test_ssm_utils.py +++ b/tests/test_ssm/test_ssm_utils.py @@ -1,4 +1,4 @@ -from moto.ssm.utils import convert_to_tree, convert_to_params +from moto.ssm.utils import convert_to_params, convert_to_tree SOURCE_PARAMS = [ { diff --git a/tests/test_ssoadmin/test_ssoadmin.py b/tests/test_ssoadmin/test_ssoadmin.py index 0dab5f0a2..1dddae081 100644 --- a/tests/test_ssoadmin/test_ssoadmin.py +++ b/tests/test_ssoadmin/test_ssoadmin.py @@ -2,8 +2,8 @@ import datetime from uuid import uuid4 import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_ssoadmin diff --git a/tests/test_stepfunctions/test_stepfunctions.py b/tests/test_stepfunctions/test_stepfunctions.py index 97f959714..49a609dcb 100644 --- a/tests/test_stepfunctions/test_stepfunctions.py +++ b/tests/test_stepfunctions/test_stepfunctions.py @@ -1,15 +1,15 @@ -from datetime import datetime import json import os import re +from datetime import datetime from unittest import SkipTest, mock import boto3 +import pytest from botocore.exceptions import ClientError from dateutil.tz import tzutc -import pytest -from moto import mock_sts, mock_stepfunctions +from moto import mock_stepfunctions, mock_sts from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID region = "us-east-1" diff --git a/tests/test_stepfunctions/test_stepfunctions_cloudformation.py b/tests/test_stepfunctions/test_stepfunctions_cloudformation.py index 88d2bd17f..b1217066d 100644 --- a/tests/test_stepfunctions/test_stepfunctions_cloudformation.py +++ b/tests/test_stepfunctions/test_stepfunctions_cloudformation.py @@ -1,8 +1,8 @@ import json import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_cloudformation, mock_stepfunctions diff --git a/tests/test_sts/test_sts.py b/tests/test_sts/test_sts.py index a83cd409e..e08aa017c 100644 --- a/tests/test_sts/test_sts.py +++ b/tests/test_sts/test_sts.py @@ -1,15 +1,15 @@ -from base64 import b64encode -from datetime import datetime import json import re +from base64 import b64encode +from datetime import datetime from unittest.mock import patch import boto3 +import pytest from botocore.client import ClientError from freezegun import freeze_time -import pytest -from moto import mock_sts, mock_iam, settings +from moto import mock_iam, mock_sts, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.sts.responses import MAX_FEDERATION_TOKEN_POLICY_LENGTH diff --git a/tests/test_sts/test_sts_integration.py b/tests/test_sts/test_sts_integration.py index 844ad7b90..141cd526d 100644 --- a/tests/test_sts/test_sts_integration.py +++ b/tests/test_sts/test_sts_integration.py @@ -1,8 +1,9 @@ -from base64 import b64encode import unittest +from base64 import b64encode import boto3 -from moto import mock_dynamodb, mock_sts, mock_iam + +from moto import mock_dynamodb, mock_iam, mock_sts from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_swf/models/test_activity_task.py b/tests/test_swf/models/test_activity_task.py index f295b6b87..8ba35c8e2 100644 --- a/tests/test_swf/models/test_activity_task.py +++ b/tests/test_swf/models/test_activity_task.py @@ -1,7 +1,7 @@ import re -from freezegun import freeze_time import pytest +from freezegun import freeze_time from moto.swf.exceptions import SWFWorkflowExecutionClosedError from moto.swf.models import ActivityTask, ActivityType, Timeout diff --git a/tests/test_swf/models/test_decision_task.py b/tests/test_swf/models/test_decision_task.py index 459669e0d..632867243 100644 --- a/tests/test_swf/models/test_decision_task.py +++ b/tests/test_swf/models/test_decision_task.py @@ -1,10 +1,10 @@ import re -from freezegun import freeze_time import pytest +from freezegun import freeze_time -from moto.swf.models import DecisionTask, Timeout from moto.swf.exceptions import SWFWorkflowExecutionClosedError +from moto.swf.models import DecisionTask, Timeout from ..utils import make_workflow_execution, process_first_timeout diff --git a/tests/test_swf/models/test_history_event.py b/tests/test_swf/models/test_history_event.py index fdbbb9863..6d98c8008 100644 --- a/tests/test_swf/models/test_history_event.py +++ b/tests/test_swf/models/test_history_event.py @@ -1,5 +1,5 @@ -from freezegun import freeze_time import pytest +from freezegun import freeze_time from moto.swf.models import HistoryEvent diff --git a/tests/test_swf/models/test_timer.py b/tests/test_swf/models/test_timer.py index 5a45da185..c307422b7 100644 --- a/tests/test_swf/models/test_timer.py +++ b/tests/test_swf/models/test_timer.py @@ -1,7 +1,7 @@ from threading import Timer as ThreadingTimer +from unittest.mock import Mock from moto.swf.models import Timer -from unittest.mock import Mock def test_timer_creation(): diff --git a/tests/test_swf/models/test_workflow_execution.py b/tests/test_swf/models/test_workflow_execution.py index 3af31234f..3f01c9445 100644 --- a/tests/test_swf/models/test_workflow_execution.py +++ b/tests/test_swf/models/test_workflow_execution.py @@ -3,17 +3,18 @@ from threading import Timer as ThreadingTimer from time import sleep from unittest.mock import Mock, patch -from freezegun import freeze_time import pytest +from freezegun import freeze_time from moto.swf.exceptions import SWFDefaultUndefinedFault from moto.swf.models import ( ActivityType, Timeout, Timer, - WorkflowType, WorkflowExecution, + WorkflowType, ) + from ..utils import ( auto_start_decision_tasks, get_basic_domain, @@ -21,7 +22,6 @@ from ..utils import ( make_workflow_execution, ) - VALID_ACTIVITY_TASK_ATTRIBUTES = { "activityId": "my-activity-001", "activityType": {"name": "test-activity", "version": "v1.1"}, diff --git a/tests/test_swf/responses/test_activity_tasks.py b/tests/test_swf/responses/test_activity_tasks.py index 541876af2..afb941d4f 100644 --- a/tests/test_swf/responses/test_activity_tasks.py +++ b/tests/test_swf/responses/test_activity_tasks.py @@ -1,16 +1,13 @@ import re from unittest import SkipTest +import pytest from botocore.exceptions import ClientError from freezegun import freeze_time -import pytest -from moto import mock_swf -from moto import settings - -from ..utils import SCHEDULE_ACTIVITY_TASK_DECISION -from ..utils import setup_workflow_boto3 +from moto import mock_swf, settings +from ..utils import SCHEDULE_ACTIVITY_TASK_DECISION, setup_workflow_boto3 # PollForActivityTask endpoint diff --git a/tests/test_swf/responses/test_activity_types.py b/tests/test_swf/responses/test_activity_types.py index 6ba3ef65d..d723bd227 100644 --- a/tests/test_swf/responses/test_activity_types.py +++ b/tests/test_swf/responses/test_activity_types.py @@ -1,6 +1,6 @@ import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_swf diff --git a/tests/test_swf/responses/test_decision_tasks.py b/tests/test_swf/responses/test_decision_tasks.py index 052c2e372..9e688ef36 100644 --- a/tests/test_swf/responses/test_decision_tasks.py +++ b/tests/test_swf/responses/test_decision_tasks.py @@ -1,17 +1,16 @@ -from datetime import datetime import re +from datetime import datetime from time import sleep +import pytest from botocore.exceptions import ClientError from dateutil.parser import parse as dtparse from freezegun import freeze_time -import pytest from moto import mock_swf, settings from ..utils import setup_workflow_boto3 - # PollForDecisionTask endpoint diff --git a/tests/test_swf/responses/test_domains.py b/tests/test_swf/responses/test_domains.py index 6e99d0e92..a6d08ceb8 100644 --- a/tests/test_swf/responses/test_domains.py +++ b/tests/test_swf/responses/test_domains.py @@ -1,6 +1,6 @@ import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_swf from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_swf/responses/test_timeouts.py b/tests/test_swf/responses/test_timeouts.py index 91f530992..490eb2c17 100644 --- a/tests/test_swf/responses/test_timeouts.py +++ b/tests/test_swf/responses/test_timeouts.py @@ -6,8 +6,7 @@ from freezegun import freeze_time from moto import mock_swf, settings -from ..utils import SCHEDULE_ACTIVITY_TASK_DECISION -from ..utils import setup_workflow_boto3 +from ..utils import SCHEDULE_ACTIVITY_TASK_DECISION, setup_workflow_boto3 # Activity Task Heartbeat timeout diff --git a/tests/test_swf/responses/test_workflow_executions.py b/tests/test_swf/responses/test_workflow_executions.py index 2212de32b..d17276b55 100644 --- a/tests/test_swf/responses/test_workflow_executions.py +++ b/tests/test_swf/responses/test_workflow_executions.py @@ -1,8 +1,8 @@ from datetime import timedelta import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_swf from moto.core.utils import unix_time, utcnow diff --git a/tests/test_swf/responses/test_workflow_types.py b/tests/test_swf/responses/test_workflow_types.py index ae7553e2a..6e055956f 100644 --- a/tests/test_swf/responses/test_workflow_types.py +++ b/tests/test_swf/responses/test_workflow_types.py @@ -1,8 +1,8 @@ import boto3 import pytest +from botocore.exceptions import ClientError from moto import mock_swf -from botocore.exceptions import ClientError # RegisterWorkflowType endpoint diff --git a/tests/test_swf/test_exceptions.py b/tests/test_swf/test_exceptions.py index d85ce1f0e..e1235e5a1 100644 --- a/tests/test_swf/test_exceptions.py +++ b/tests/test_swf/test_exceptions.py @@ -3,16 +3,16 @@ import re from moto.swf.exceptions import ( SWFClientError, - SWFUnknownResourceFault, + SWFDecisionValidationException, + SWFDefaultUndefinedFault, SWFDomainAlreadyExistsFault, SWFDomainDeprecatedFault, SWFSerializationException, SWFTypeAlreadyExistsFault, SWFTypeDeprecatedFault, - SWFWorkflowExecutionAlreadyStartedFault, - SWFDefaultUndefinedFault, + SWFUnknownResourceFault, SWFValidationException, - SWFDecisionValidationException, + SWFWorkflowExecutionAlreadyStartedFault, ) from moto.swf.models import WorkflowType diff --git a/tests/test_swf/utils.py b/tests/test_swf/utils.py index f5282acf2..1e24ef85f 100644 --- a/tests/test_swf/utils.py +++ b/tests/test_swf/utils.py @@ -1,8 +1,7 @@ import boto3 from moto.core import DEFAULT_ACCOUNT_ID -from moto.swf.models import ActivityType, Domain, WorkflowType, WorkflowExecution - +from moto.swf.models import ActivityType, Domain, WorkflowExecution, WorkflowType # Some useful constants # Here are some activity timeouts we use in moto/swf tests ; they're extracted diff --git a/tests/test_textract/test_server.py b/tests/test_textract/test_server.py index 49bb37702..72dc62d7a 100644 --- a/tests/test_textract/test_server.py +++ b/tests/test_textract/test_server.py @@ -1,5 +1,6 @@ """Test different server responses.""" import json + import moto.server as server from moto import mock_textract diff --git a/tests/test_textract/test_textract.py b/tests/test_textract/test_textract.py index a0254c58c..b994516f8 100644 --- a/tests/test_textract/test_textract.py +++ b/tests/test_textract/test_textract.py @@ -1,12 +1,13 @@ """Unit tests for textract-supported APIs.""" from random import randint -from botocore.exceptions import ClientError, ParamValidationError -import pytest -import boto3 - from unittest import SkipTest + +import boto3 +import pytest +from botocore.exceptions import ClientError, ParamValidationError + +from moto import mock_textract, settings from moto.textract.models import TextractBackend -from moto import settings, mock_textract # See our Development Tips on writing tests for hints on how to write good tests: # http://docs.getmoto.org/en/latest/docs/contributing/development_tips/tests.html diff --git a/tests/test_timestreamwrite/__init__.py b/tests/test_timestreamwrite/__init__.py index 707d83fb0..94cbaf92e 100644 --- a/tests/test_timestreamwrite/__init__.py +++ b/tests/test_timestreamwrite/__init__.py @@ -1,6 +1,7 @@ import os from functools import wraps -from moto import mock_timestreamwrite, mock_s3, mock_sts + +from moto import mock_s3, mock_sts, mock_timestreamwrite def timestreamwrite_aws_verified(func): diff --git a/tests/test_timestreamwrite/test_timestreamwrite_database.py b/tests/test_timestreamwrite/test_timestreamwrite_database.py index 3427fe1d9..9596fd065 100644 --- a/tests/test_timestreamwrite/test_timestreamwrite_database.py +++ b/tests/test_timestreamwrite/test_timestreamwrite_database.py @@ -1,7 +1,8 @@ +from uuid import uuid4 + import boto3 import pytest from botocore.exceptions import ClientError -from uuid import uuid4 from moto import mock_timestreamwrite from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_timestreamwrite/test_timestreamwrite_table.py b/tests/test_timestreamwrite/test_timestreamwrite_table.py index 3c2727a86..201177adf 100644 --- a/tests/test_timestreamwrite/test_timestreamwrite_table.py +++ b/tests/test_timestreamwrite/test_timestreamwrite_table.py @@ -1,9 +1,9 @@ +import time +from uuid import uuid4 + import boto3 import pytest -import time - from botocore.exceptions import ClientError -from uuid import uuid4 from moto import mock_timestreamwrite, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID diff --git a/tests/test_timestreamwrite/test_timestreamwrite_tagging.py b/tests/test_timestreamwrite/test_timestreamwrite_tagging.py index 0ad0d178a..a2def7986 100644 --- a/tests/test_timestreamwrite/test_timestreamwrite_tagging.py +++ b/tests/test_timestreamwrite/test_timestreamwrite_tagging.py @@ -1,6 +1,7 @@ +from uuid import uuid4 + import boto3 import pytest -from uuid import uuid4 from moto import mock_timestreamwrite diff --git a/tests/test_utilities/test_paginator.py b/tests/test_utilities/test_paginator.py index 5a5b5a830..2b48011e1 100644 --- a/tests/test_utilities/test_paginator.py +++ b/tests/test_utilities/test_paginator.py @@ -1,11 +1,10 @@ -from collections import OrderedDict import unittest +from collections import OrderedDict import pytest -from moto.utilities.paginator import Paginator, paginate from moto.core.exceptions import InvalidToken - +from moto.utilities.paginator import Paginator, paginate results = [ {"id": f"id{i}", "name": f"name{i}", "arn": f"arn:aws:thing/name{i}"} diff --git a/tests/test_wafv2/test_server.py b/tests/test_wafv2/test_server.py index cf308d6e7..314818220 100644 --- a/tests/test_wafv2/test_server.py +++ b/tests/test_wafv2/test_server.py @@ -1,6 +1,7 @@ +import moto.server as server from moto import mock_wafv2 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -import moto.server as server + from .test_helper_functions import CREATE_WEB_ACL_BODY, LIST_WEB_ACL_BODY CREATE_WEB_ACL_HEADERS = { diff --git a/tests/test_wafv2/test_utils.py b/tests/test_wafv2/test_utils.py index 54510c118..ae6951e47 100644 --- a/tests/test_wafv2/test_utils.py +++ b/tests/test_wafv2/test_utils.py @@ -1,7 +1,7 @@ import uuid -from moto.wafv2.utils import make_arn_for_wacl from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID +from moto.wafv2.utils import make_arn_for_wacl def test_make_arn_for_wacl(): diff --git a/tests/test_wafv2/test_wafv2.py b/tests/test_wafv2/test_wafv2.py index f1a4c3393..9890ff19a 100644 --- a/tests/test_wafv2/test_wafv2.py +++ b/tests/test_wafv2/test_wafv2.py @@ -1,9 +1,10 @@ import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_wafv2 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID + from .test_helper_functions import CREATE_WEB_ACL_BODY, LIST_WEB_ACL_BODY diff --git a/tests/test_wafv2/test_wafv2_integration.py b/tests/test_wafv2/test_wafv2_integration.py index eff2862c5..875feadb2 100644 --- a/tests/test_wafv2/test_wafv2_integration.py +++ b/tests/test_wafv2/test_wafv2_integration.py @@ -1,9 +1,10 @@ import boto3 -from botocore.exceptions import ClientError import pytest +from botocore.exceptions import ClientError from moto import mock_apigateway, mock_wafv2 from tests.test_apigateway.test_apigateway_stage import create_method_integration + from .test_helper_functions import CREATE_WEB_ACL_BODY diff --git a/tests/test_wafv2/test_wafv2_rules.py b/tests/test_wafv2/test_wafv2_rules.py index 5273cb73b..3acc50442 100644 --- a/tests/test_wafv2/test_wafv2_rules.py +++ b/tests/test_wafv2/test_wafv2_rules.py @@ -1,4 +1,5 @@ import boto3 + from moto import mock_wafv2 diff --git a/tests/test_wafv2/test_wafv2_tags.py b/tests/test_wafv2/test_wafv2_tags.py index 36c9700e7..7abce87ef 100644 --- a/tests/test_wafv2/test_wafv2_tags.py +++ b/tests/test_wafv2/test_wafv2_tags.py @@ -1,6 +1,7 @@ import boto3 from moto import mock_wafv2 + from .test_helper_functions import CREATE_WEB_ACL_BODY diff --git a/tests/test_xray/test_xray_boto3.py b/tests/test_xray/test_xray_boto3.py index 69d22a982..d04fe8649 100644 --- a/tests/test_xray/test_xray_boto3.py +++ b/tests/test_xray/test_xray_boto3.py @@ -1,5 +1,6 @@ import datetime import json + import boto3 from moto import mock_xray diff --git a/tests/test_xray/test_xray_client.py b/tests/test_xray/test_xray_client.py index 80f4ca0db..2bc529d89 100644 --- a/tests/test_xray/test_xray_client.py +++ b/tests/test_xray/test_xray_client.py @@ -1,5 +1,4 @@ import os -import requests # noqa # pylint: disable=all import sys from unittest import SkipTest @@ -8,8 +7,9 @@ import aws_xray_sdk.core.patcher as xray_core_patcher import boto3 import botocore.client import botocore.endpoint +import requests # noqa # pylint: disable=all -from moto import mock_xray_client, XRaySegment, mock_dynamodb +from moto import XRaySegment, mock_dynamodb, mock_xray_client from moto.utilities.distutils_version import LooseVersion from moto.xray.mock_client import MockEmitter