diff --git a/pyproject.toml b/pyproject.toml index 58b47af..91ce07b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,13 +8,13 @@ keywords = ["AWS", "EC2", "command line", "cli"] classifiers = ["License :: OSI Approved :: MIT License"] requires-python = ">=3.8" dependencies = [ - "boto3==1.34.19", - "importlib_resources==6.1.1", + "boto3==1.34.59", + "importlib_resources==6.1.3", "pytoml==0.1.21", - "pytz==2023.3.post1", + "pytz==2024.1", "requests==2.31.0", - "rich==13.7.0", - "typing_extensions==4.9.0", + "rich==13.7.1", + "typing_extensions==4.10.0", ] [project.optional-dependencies] @@ -23,12 +23,12 @@ dev = [ "boto3-stubs[ec2,compute-optimizer,ssm,s3]", "cogapp~=3.3", "dirty-equals~=0.6", - "moto[ec2]~=4.2.13", + "moto[ec2]~=5.0.2", "pre-commit~=3.5", "pyfakefs~=5.1", - "pytest~=7.4", + "pytest~=8.0", "pytest-mock~=3.11", - "twine~=4.0", + "twine~=5.0", ] [project.scripts] diff --git a/src/aec/util/docgen.py b/src/aec/util/docgen.py index 037a8d7..8b24249 100644 --- a/src/aec/util/docgen.py +++ b/src/aec/util/docgen.py @@ -4,7 +4,7 @@ from contextlib import redirect_stdout from typing import Any, Iterator -from moto import mock_ec2 +from moto import mock_aws from moto.ec2.models import ec2_backends from moto.ec2.models.amis import AMIS @@ -13,7 +13,7 @@ from aec.util.config import Config # fixtures -mock_ec2().start() +mock_aws().start() region = "us-east-1" mock_aws_config: Config = { "region": region, diff --git a/tests/conftest.py b/tests/conftest.py index fbba781..acbc399 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,10 @@ import os import pytest +from moto import mock_aws +from moto.core.models import DEFAULT_ACCOUNT_ID +from moto.ec2.models import ec2_backends +from moto.ssm.models import ssm_backends @pytest.fixture(scope="session", autouse=True) @@ -11,3 +15,23 @@ def aws_credentials(): # RuntimeError: Credentials were refreshed, but the refreshed credentials are still expired. if "AWS_CREDENTIAL_EXPIRATION" in os.environ: del os.environ["AWS_CREDENTIAL_EXPIRATION"] + + +@pytest.fixture(scope="session") +def _mock_aws(): + with mock_aws(): + yield + + +@pytest.fixture +def _mock_ec2(_mock_aws: None): + yield + # reset just the ec2 backend because its quicker than resetting all backends + ec2_backends[DEFAULT_ACCOUNT_ID].reset() + + +@pytest.fixture +def _mock_ssm(_mock_aws: None): + yield + # reset just the ssm backend because its quicker than resetting all backends + ssm_backends[DEFAULT_ACCOUNT_ID].reset() diff --git a/tests/test_ami.py b/tests/test_ami.py index 363a450..e5ad83d 100644 --- a/tests/test_ami.py +++ b/tests/test_ami.py @@ -2,7 +2,6 @@ import boto3 import pytest -from moto import mock_ec2 from moto.ec2.models.amis import AMIS from mypy_boto3_ec2 import EC2Client from mypy_boto3_ec2.type_defs import TagTypeDef @@ -12,10 +11,7 @@ @pytest.fixture -def mock_aws_config() -> Config: - mock = mock_ec2() - mock.start() - +def mock_aws_config(_mock_ec2: None) -> Config: return { "region": "ap-southeast-2", } diff --git a/tests/test_compute_optimizer.py b/tests/test_compute_optimizer.py index 13847ff..ae24bc1 100644 --- a/tests/test_compute_optimizer.py +++ b/tests/test_compute_optimizer.py @@ -1,5 +1,5 @@ import pytest -from moto import mock_ec2 +from moto.core.models import DEFAULT_ACCOUNT_ID from moto.ec2.models import ec2_backends from moto.ec2.models.amis import AMIS @@ -9,9 +9,7 @@ @pytest.fixture -def mock_aws_config(): - mock = mock_ec2() - mock.start() +def mock_aws_config(_mock_ec2: None) -> Config: region = "us-east-1" return { @@ -20,7 +18,7 @@ def mock_aws_config(): "key_name": "test_key", "vpc": { "name": "test vpc", - "subnet": ec2_backends["123456789012"]["us-east-1"].get_default_subnet("us-east-1a").id, + "subnet": ec2_backends[DEFAULT_ACCOUNT_ID][region].get_default_subnet("us-east-1a").id, "security_group": "default", }, } diff --git a/tests/test_ec2.py b/tests/test_ec2.py index 9e650be..c316434 100644 --- a/tests/test_ec2.py +++ b/tests/test_ec2.py @@ -6,7 +6,7 @@ import boto3 import pytest from dirty_equals import IsDatetime -from moto import mock_ec2, mock_iam +from moto.core.models import DEFAULT_ACCOUNT_ID from moto.ec2.models import ec2_backends from moto.ec2.models.amis import AMIS from mypy_boto3_ec2.type_defs import TagTypeDef @@ -33,9 +33,7 @@ @pytest.fixture -def mock_aws_config() -> Config: - mock = mock_ec2() - mock.start() +def mock_aws_config(_mock_ec2: None) -> Config: region = "us-east-1" return { @@ -43,7 +41,7 @@ def mock_aws_config() -> Config: "key_name": "test_key", "vpc": { "name": "test vpc", - "subnet": ec2_backends["123456789012"]["us-east-1"].get_default_subnet("us-east-1a").id, + "subnet": ec2_backends[DEFAULT_ACCOUNT_ID][region].get_default_subnet("us-east-1a").id, "security_group": "default", }, } @@ -96,7 +94,6 @@ def test_launch_multiple_security_groups(mock_aws_config: Config): print(launch(mock_aws_config, "alice", ami_id)) -@mock_iam def test_launch_with_instance_profile(mock_aws_config: Config): iam = boto3.client("iam", "us-east-1") diff --git a/tests/test_ssm.py b/tests/test_ssm.py index 65b4f8c..def1456 100644 --- a/tests/test_ssm.py +++ b/tests/test_ssm.py @@ -4,7 +4,6 @@ import boto3 import pytest -from moto import mock_ec2, mock_ssm from moto.ec2.models.amis import AMIS from mypy_boto3_ec2 import EC2Client from pytest import MonkeyPatch @@ -17,10 +16,7 @@ @pytest.fixture -def mock_aws_config(): - mock_ec2().start() - mock_ssm().start() - +def mock_aws_config(_mock_ec2: None, _mock_ssm: None): return { "region": "ap-southeast-2", }