From 810003eeb193bdeecf162da954f80dcd65d8564e Mon Sep 17 00:00:00 2001 From: gjclark Date: Wed, 11 Sep 2024 13:04:26 -0800 Subject: [PATCH 1/2] Use `~=` instead of `==` in Python requirements files --- requirements-dev.txt | 12 ++++++------ requirements.txt | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 160e7d1..24cdff1 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,6 @@ -boto3==1.20.54 -hypothesis==6.39.1 -moto==3.0.3 -pytest-cov==3.0.0 -pytest-mock==3.7.0 -pytest==7.0.1 +boto3~=1.0 +hypothesis~=6.0 +moto~=3.0 +pytest-cov~=5.0 +pytest-mock~=3.0 +pytest~=8.0 diff --git a/requirements.txt b/requirements.txt index 4a38a89..246de4e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ -cachetools==5.0.0 -jinja2>=3.0.0 -netaddr>=0.8.0 -pyjwt[crypto]>=1.6.0 -pyyaml>=5.1 +cachetools~=5.0 +jinja2~=3.0 +netaddr~=1.0 +pyjwt[crypto]~=2.0 +pyyaml~=6.0 -pip>=19.2 # not directly required, pinned by Snyk to avoid a vulnerability +pip~=24.0 # not directly required, pinned by Snyk to avoid a vulnerability From e8025453f5923dccb018a0663d4d826dfde76d80 Mon Sep 17 00:00:00 2001 From: gjclark Date: Thu, 12 Sep 2024 15:03:16 -0800 Subject: [PATCH 2/2] Bump dev requirements --- requirements-dev.txt | 12 ++++++------ tests/test_aws_util.py | 38 ++++++++++++++++++++------------------ tests/test_view_util.py | 12 ++++++------ 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 24cdff1..e1d0a6e 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,6 @@ -boto3~=1.0 -hypothesis~=6.0 -moto~=3.0 -pytest-cov~=5.0 -pytest-mock~=3.0 -pytest~=8.0 +boto3==1.35.18 +hypothesis==6.112.0 +moto==5.0.14 +pytest-cov==5.0.0 +pytest-mock==3.14.0 +pytest==8.3.3 diff --git a/tests/test_aws_util.py b/tests/test_aws_util.py index e895e4f..d7096a0 100644 --- a/tests/test_aws_util.py +++ b/tests/test_aws_util.py @@ -3,8 +3,8 @@ import boto3 import botocore -import moto import pytest +from moto import mock_aws from netaddr import IPNetwork from rain_api_core.aws_util import ( @@ -38,7 +38,7 @@ def test_get_region_cache(mock_region_name): mock_region_name.assert_called_once() -@moto.mock_secretsmanager +@mock_aws def test_retrieve_secret(): client = boto3.client("secretsmanager") client.create_secret(Name="secret_name", SecretString='{"foo": "bar"}') @@ -46,7 +46,7 @@ def test_retrieve_secret(): assert retrieve_secret("secret_name") == {"foo": "bar"} -@moto.mock_secretsmanager +@mock_aws def test_retrieve_secret_binary(): client = boto3.client("secretsmanager") client.create_secret(Name="binary_secret_name", SecretBinary=b"foobar") @@ -66,20 +66,20 @@ def test_retrieve_secret_cached(mock_botosess): client.get_secret_value.assert_called_once() -@moto.mock_secretsmanager +@mock_aws def test_retrieve_secret_nonexistent(): with pytest.raises(botocore.exceptions.ClientError): assert retrieve_secret("does_not_exist") == {"foo": "bar"} -@moto.mock_s3 +@mock_aws def test_get_s3_resource_cached(monkeypatch): monkeypatch.setenv("S3_SIGNATURE_VERSION", "v2") assert get_s3_resource() is get_s3_resource() -@moto.mock_s3 +@mock_aws def test_read_s3(): resource = boto3.resource("s3") bucket = resource.Bucket("test_bucket") @@ -90,7 +90,7 @@ def test_read_s3(): assert read_s3("test_bucket", "test_file") == "foobar" -@moto.mock_s3 +@mock_aws def test_read_s3_nonexistent(): resource = boto3.resource("s3") @@ -98,7 +98,7 @@ def test_read_s3_nonexistent(): assert read_s3("nonexistent", "test_file", resource) -@moto.mock_s3 +@mock_aws def test_get_yaml(data): resource = boto3.resource("s3") bucket = resource.Bucket("test_bucket") @@ -109,13 +109,13 @@ def test_get_yaml(data): assert get_yaml("test_bucket", "sample.yaml") == {"key": ["value1", "value2"]} -@moto.mock_s3 +@mock_aws def test_get_yaml_nonexistent(): with pytest.raises(botocore.exceptions.ClientError): assert get_yaml("nonexistent", "sample.yaml") -@moto.mock_s3 +@mock_aws def test_get_yaml_file(data): resource = boto3.resource("s3") bucket = resource.Bucket("test_bucket") @@ -126,14 +126,14 @@ def test_get_yaml_file(data): assert get_yaml_file("test_bucket", "sample.yaml") == {"key": ["value1", "value2"]} -@moto.mock_s3 +@mock_aws def test_get_yaml_file_nonexistent(): assert get_yaml_file("nonexistent", "") == {} with pytest.raises(botocore.exceptions.ClientError): get_yaml_file("nonexistent", "sample.yaml") -@moto.mock_sts +@mock_aws def test_get_role_creds(monkeypatch): monkeypatch.setenv("EGRESS_APP_DOWNLOAD_ROLE_ARN", "egress_app_download_role_arn") monkeypatch.setitem(role_creds_cache, "egress_app_download_role_arn", {}) @@ -153,17 +153,19 @@ def test_get_role_creds(monkeypatch): "PackedPolicySize": 6, "ResponseMetadata": { "HTTPHeaders": { - "server": "amazon.com" + "date": mock.ANY, + "server": "amazon.com", + "x-amzn-requestid": mock.ANY, }, "HTTPStatusCode": 200, - "RequestId": "c6104cbe-af31-11e0-8154-cbc7ccf896c7", - "RetryAttempts": 0 - } + "RequestId": mock.ANY, + "RetryAttempts": 0, + }, } assert session_offset == 0 -@moto.mock_sts +@mock_aws @mock.patch(f"{MODULE}.time", autospec=True) def test_get_role_creds_cached(mock_time, monkeypatch): monkeypatch.setenv("EGRESS_APP_DOWNLOAD_ROLE_ARN", "egress_app_download_role_arn") @@ -182,7 +184,7 @@ def test_get_role_creds_cached(mock_time, monkeypatch): assert session1 != session3 -@moto.mock_sts +@mock_aws def test_get_role_session_cached(monkeypatch): monkeypatch.setenv("EGRESS_APP_DOWNLOAD_ROLE_ARN", "egress_app_download_role_arn") monkeypatch.setitem(role_creds_cache, "egress_app_download_role_arn", {}) diff --git a/tests/test_view_util.py b/tests/test_view_util.py index 86da6d0..874a047 100644 --- a/tests/test_view_util.py +++ b/tests/test_view_util.py @@ -5,10 +5,10 @@ import boto3 import jwt -import moto import pytest from hypothesis import assume, given, note from hypothesis import strategies as st +from moto import mock_aws from rain_api_core.view_util import ( TemplateManager, @@ -71,7 +71,7 @@ def test_get_jwt_keys_error(mock_retrieve_secret): _ = get_jwt_keys() -@moto.mock_s3 +@mock_aws def test_download_templates(local_cachedir): bucket = "test_bucket" template_dir = "templates/" @@ -90,7 +90,7 @@ def test_download_templates(local_cachedir): assert f.read() == contents -@moto.mock_s3 +@mock_aws def test_download_templates_none_available(local_cachedir): bucket = "test_bucket" client = boto3.client("s3") @@ -102,7 +102,7 @@ def test_download_templates_none_available(local_cachedir): assert list(local_cachedir.iterdir()) == [] -@moto.mock_s3 +@mock_aws def test_download_templates_missing_bucket(local_cachedir): manager = TemplateManager("does_not_exist", "templates", cache_dir=local_cachedir) manager.download_templates() @@ -110,7 +110,7 @@ def test_download_templates_missing_bucket(local_cachedir): assert list(local_cachedir.iterdir()) == [] -@moto.mock_s3 +@mock_aws def test_download_templates_missing_template_dir(local_cachedir): manager = TemplateManager("does_not_exist", "", cache_dir=local_cachedir) manager.download_templates() @@ -132,7 +132,7 @@ def test_render_missing_template(template_dir): assert rendered == "Cannot find the HTML template directory" -@moto.mock_s3 +@mock_aws def test_render_wait_for_templates(local_cachedir): bucket = "test_bucket" template_dir = "templates/"