From e926a3e6b4986661bb7c6af0aa84e12d5c9aa8ea Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 9 Mar 2024 06:12:16 +0000 Subject: [PATCH 1/2] build(deps-dev): bump the pip group with 8 updates Updates the requirements on [boto3](https://github.com/boto/boto3), [importlib-resources](https://github.com/python/importlib_resources), [pytz](https://github.com/stub42/pytz), [rich](https://github.com/Textualize/rich), [typing-extensions](https://github.com/python/typing_extensions), [moto[ec2]](https://github.com/getmoto/moto), [pytest](https://github.com/pytest-dev/pytest) and [twine](https://github.com/pypa/twine) to permit the latest version. Updates `boto3` from 1.34.19 to 1.34.59 - [Release notes](https://github.com/boto/boto3/releases) - [Changelog](https://github.com/boto/boto3/blob/develop/CHANGELOG.rst) - [Commits](https://github.com/boto/boto3/compare/1.34.19...1.34.59) Updates `importlib-resources` from 6.1.1 to 6.1.3 - [Release notes](https://github.com/python/importlib_resources/releases) - [Changelog](https://github.com/python/importlib_resources/blob/main/NEWS.rst) - [Commits](https://github.com/python/importlib_resources/compare/v6.1.1...v6.1.3) Updates `pytz` from 2023.3.post1 to 2024.1 - [Release notes](https://github.com/stub42/pytz/releases) - [Commits](https://github.com/stub42/pytz/compare/release_2023.3.post1...release_2024.1) Updates `rich` from 13.7.0 to 13.7.1 - [Release notes](https://github.com/Textualize/rich/releases) - [Changelog](https://github.com/Textualize/rich/blob/master/CHANGELOG.md) - [Commits](https://github.com/Textualize/rich/compare/v13.7.0...v13.7.1) Updates `typing-extensions` from 4.9.0 to 4.10.0 - [Release notes](https://github.com/python/typing_extensions/releases) - [Changelog](https://github.com/python/typing_extensions/blob/main/CHANGELOG.md) - [Commits](https://github.com/python/typing_extensions/compare/4.9.0...4.10.0) Updates `moto[ec2]` to 5.0.2 - [Release notes](https://github.com/getmoto/moto/releases) - [Changelog](https://github.com/getmoto/moto/blob/master/CHANGELOG.md) - [Commits](https://github.com/getmoto/moto/compare/4.2.13...5.0.2) Updates `pytest` to 8.0.2 - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/7.4.0...8.0.2) Updates `twine` to 5.0.0 - [Release notes](https://github.com/pypa/twine/releases) - [Changelog](https://github.com/pypa/twine/blob/main/docs/changelog.rst) - [Commits](https://github.com/pypa/twine/compare/4.0.0...5.0.0) --- updated-dependencies: - dependency-name: boto3 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: pip - dependency-name: importlib-resources dependency-type: direct:production update-type: version-update:semver-patch dependency-group: pip - dependency-name: pytz dependency-type: direct:production update-type: version-update:semver-major dependency-group: pip - dependency-name: rich dependency-type: direct:production update-type: version-update:semver-patch dependency-group: pip - dependency-name: typing-extensions dependency-type: direct:production update-type: version-update:semver-minor dependency-group: pip - dependency-name: moto[ec2] dependency-type: direct:production dependency-group: pip - dependency-name: pytest dependency-type: direct:production dependency-group: pip - dependency-name: twine dependency-type: direct:production dependency-group: pip ... Signed-off-by: dependabot[bot] --- pyproject.toml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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] From e0848ec5dff3ff88a9af1d914759b0f80ae9551b Mon Sep 17 00:00:00 2001 From: Oliver Mannion <125105+tekumara@users.noreply.github.com> Date: Sat, 9 Mar 2024 22:18:25 +1100 Subject: [PATCH 2/2] migrate to moto v5 --- src/aec/util/docgen.py | 4 ++-- tests/conftest.py | 24 ++++++++++++++++++++++++ tests/test_ami.py | 6 +----- tests/test_compute_optimizer.py | 8 +++----- tests/test_ec2.py | 9 +++------ tests/test_ssm.py | 6 +----- 6 files changed, 34 insertions(+), 23 deletions(-) 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", }