Skip to content

Commit

Permalink
Techdebt: Verify minimum boto3-version, up minimum responses version (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers committed Jan 27, 2024
1 parent f834d98 commit 16ba3de
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 51 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test_outdated_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ jobs:
strategy:
fail-fast: false
matrix:
botocore: ["--upgrade boto3 botocore", "boto3==1.11.0 botocore==1.14.0"]
python-version: [ "3.11" ]
responses-version: ["0.13.0", "0.15.0", "0.17.0", "0.19.0", "0.20.0" ]
responses-version: ["0.15.0", "0.17.0", "0.19.0", "0.20.0" ]
werkzeug-version: ["2.0.1", "2.1.1", "2.2.2"]
openapi-spec-validator-version: ["0.5.0"]

Expand All @@ -38,6 +39,7 @@ jobs:
pip install flask==${{ matrix.werkzeug-version }}
pip install werkzeug==${{ matrix.werkzeug-version }}
pip install openapi-spec-validator==${{ matrix.openapi-spec-validator-version }}
pip install ${{ matrix.botocore }}
- name: Run tests
run: |
Expand Down Expand Up @@ -65,6 +67,6 @@ jobs:
if: always()
uses: actions/upload-artifact@v4
with:
name: test-${{ matrix.responses-version }}-${{ matrix.werkzeug-version }}-${{ matrix.werkzeug-version }}-${{ matrix.openapi-spec-validator-version }}
name: test-${{ matrix.responses-version }}-${{ matrix.werkzeug-version }}-${{ matrix.werkzeug-version }}-${{ matrix.openapi-spec-validator-version }}-${{ matrix.botocore }}
path: |
serverlogs/*
15 changes: 0 additions & 15 deletions moto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,3 @@

__title__ = "moto"
__version__ = "4.2.15.dev"


try:
# Need to monkey-patch botocore requests back to underlying urllib3 classes
from botocore.awsrequest import ( # type: ignore[attr-defined]
HTTPConnection,
HTTPConnectionPool,
HTTPSConnectionPool,
VerifiedHTTPSConnection,
)
except ImportError:
pass
else:
HTTPSConnectionPool.ConnectionCls = VerifiedHTTPSConnection
HTTPConnectionPool.ConnectionCls = HTTPConnection
4 changes: 4 additions & 0 deletions moto/core/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ def is_responses_0_17_x() -> bool:
return LooseVersion(RESPONSES_VERSION) >= LooseVersion("0.17.0")


def is_werkzeug_2_0_x_or_older() -> bool:
return LooseVersion(WERKZEUG_VERSION) < LooseVersion("2.1.0")


def is_werkzeug_2_3_x() -> bool:
return LooseVersion(WERKZEUG_VERSION) >= LooseVersion("2.3.0")
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ project_urls =
python_requires = >=3.8
install_requires =
boto3>=1.9.201
botocore>=1.13.46
botocore>=1.14.0
cryptography>=3.3.1
requests>=2.5
xmltodict
werkzeug>=0.5,!=2.2.0,!=2.2.1
python-dateutil<3.0.0,>=2.1
responses>=0.13.0
responses>=0.15.0
Jinja2>=2.10.1
package_dir =
moto = moto
Expand Down
51 changes: 37 additions & 14 deletions tests/test_awslambda/test_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import hashlib
import json
import os
import sys
from unittest import SkipTest, mock
from uuid import uuid4

Expand All @@ -12,6 +13,7 @@

from moto import mock_aws, settings
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
from moto.utilities.distutils_version import LooseVersion
from tests.test_ecr.test_ecr_helpers import _create_image_manifest

from . import lambda_aws_verified
Expand All @@ -28,13 +30,17 @@
LAMBDA_FUNC_NAME = "test"
_lambda_region = "us-west-2"

boto3_version = sys.modules["botocore"].__version__


@mock.patch.dict("os.environ", {"MOTO_ENABLE_ISO_REGIONS": "true"})
@pytest.mark.parametrize("region", ["us-west-2", "cn-northwest-1", "us-isob-east-1"])
@mock_aws
def test_lambda_regions(region):
if not settings.TEST_DECORATOR_MODE:
raise SkipTest("Can only set EnvironVars in DecoratorMode")
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("ISO-region not available in older versions")
client = boto3.client("lambda", region_name=region)
resp = client.list_functions()
assert resp["ResponseMetadata"]["HTTPStatusCode"] == 200
Expand All @@ -43,6 +49,8 @@ def test_lambda_regions(region):
@pytest.mark.aws_verified
@lambda_aws_verified
def test_list_functions(iam_role_arn=None):
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
sts = boto3.client("sts", "eu-west-2")
account_id = sts.get_caller_identity()["Account"]

Expand Down Expand Up @@ -70,7 +78,9 @@ def test_list_functions(iam_role_arn=None):
func_list = conn.list_functions()["Functions"]
our_functions = [f for f in func_list if f["FunctionName"] == function_name]
assert len(our_functions) == 1
assert our_functions[0]["PackageType"] == "Zip"
if LooseVersion(boto3_version) > LooseVersion("1.29.0"):
# PackageType only available in new versions
assert our_functions[0]["PackageType"] == "Zip"

# FunctionVersion=ALL means we should get a list of all versions
full_list = conn.list_functions(FunctionVersion="ALL")["Functions"]
Expand Down Expand Up @@ -127,6 +137,8 @@ def test_create_based_on_s3_with_missing_bucket():
@mock_aws
@freeze_time("2015-01-01 00:00:00")
def test_create_function_from_aws_bucket():
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
bucket_name = str(uuid4())
s3_conn = boto3.client("s3", _lambda_region)
s3_conn.create_bucket(
Expand Down Expand Up @@ -169,6 +181,8 @@ def test_create_function_from_aws_bucket():
@mock_aws
@freeze_time("2015-01-01 00:00:00")
def test_create_function_from_zipfile():
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
conn = boto3.client("lambda", _lambda_region)
zip_content = get_test_zip_file1()
function_name = str(uuid4())[0:6]
Expand Down Expand Up @@ -218,6 +232,8 @@ def test_create_function_from_zipfile():

@mock_aws
def test_create_function_from_image():
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
conn = boto3.client("lambda", _lambda_region)
function_name = str(uuid4())[0:6]
image_uri = f"{ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/testlambdaecr:prod"
Expand All @@ -237,9 +253,6 @@ def test_create_function_from_image():
Description="test lambda function",
ImageConfig=image_config,
PackageType="Image",
Timeout=3,
MemorySize=128,
Publish=True,
)

result = conn.get_function(FunctionName=function_name)
Expand All @@ -250,6 +263,8 @@ def test_create_function_from_image():

@mock_aws
def test_create_function_from_image_default_working_directory():
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
conn = boto3.client("lambda", _lambda_region)
function_name = str(uuid4())[0:6]
image_uri = f"{ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/testlambdaecr:prod"
Expand All @@ -268,9 +283,6 @@ def test_create_function_from_image_default_working_directory():
Description="test lambda function",
ImageConfig=image_config,
PackageType="Image",
Timeout=3,
MemorySize=128,
Publish=True,
)

result = conn.get_function(FunctionName=function_name)
Expand All @@ -281,6 +293,8 @@ def test_create_function_from_image_default_working_directory():

@mock_aws
def test_create_function_error_bad_architecture():
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
conn = boto3.client("lambda", _lambda_region)
function_name = str(uuid4())[0:6]
image_uri = f"{ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/testlambdaecr:prod"
Expand All @@ -291,10 +305,6 @@ def test_create_function_error_bad_architecture():
FunctionName=function_name,
Role=get_role_name(),
Code={"ImageUri": image_uri},
Description="test lambda function",
Timeout=3,
MemorySize=128,
Publish=True,
)

err = exc.value.response
Expand All @@ -310,6 +320,8 @@ def test_create_function_error_bad_architecture():

@mock_aws
def test_create_function_error_ephemeral_too_big():
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
conn = boto3.client("lambda", _lambda_region)
function_name = str(uuid4())[0:6]
image_uri = f"{ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/testlambdaecr:prod"
Expand Down Expand Up @@ -405,6 +417,8 @@ def ecr_repo_fixture():

@mock_aws
def test_create_function_from_stubbed_ecr():
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
lambda_client = boto3.client("lambda", "us-east-1")
fn_name = str(uuid4())[0:6]
image_uri = "111122223333.dkr.ecr.us-east-1.amazonaws.com/testlambda:latest"
Expand Down Expand Up @@ -440,6 +454,8 @@ def test_create_function_from_stubbed_ecr():
def test_create_function_from_mocked_ecr_image_tag(
with_ecr_mock,
): # pylint: disable=unused-argument
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
if not settings.TEST_DECORATOR_MODE:
raise SkipTest(
"Envars not easily set in server mode, feature off by default, skipping..."
Expand Down Expand Up @@ -482,6 +498,8 @@ def test_create_function_from_mocked_ecr_image_tag(
def test_create_function_from_mocked_ecr_image_digest(
with_ecr_mock,
): # pylint: disable=unused-argument
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
if not settings.TEST_DECORATOR_MODE:
raise SkipTest(
"Envars not easily set in server mode, feature off by default, skipping..."
Expand Down Expand Up @@ -509,6 +527,8 @@ def test_create_function_from_mocked_ecr_image_digest(
def test_create_function_from_mocked_ecr_missing_image(
with_ecr_mock,
): # pylint: disable=unused-argument
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
if not settings.TEST_DECORATOR_MODE:
raise SkipTest(
"Envars not easily set in server mode, feature off by default, skipping..."
Expand Down Expand Up @@ -696,6 +716,8 @@ def test_get_function_configuration(key):
@pytest.mark.parametrize("key", ["FunctionName", "FunctionArn"])
@mock_aws
def test_get_function_code_signing_config(key):
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
bucket_name = str(uuid4())
s3_conn = boto3.client("s3", _lambda_region)
s3_conn.create_bucket(
Expand Down Expand Up @@ -929,6 +951,8 @@ def test_list_create_list_get_delete_list():
test `list -> create -> list -> get -> delete -> list` integration
"""
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
bucket_name = str(uuid4())
s3_conn = boto3.client("s3", _lambda_region)
s3_conn.create_bucket(
Expand Down Expand Up @@ -1055,9 +1079,6 @@ def test_get_function_created_with_zipfile():
Handler="lambda_function.handler",
Code={"ZipFile": zip_content},
Description="test lambda function",
Timeout=3,
MemorySize=128,
Publish=True,
)

response = conn.get_function(FunctionName=function_name)
Expand Down Expand Up @@ -1503,6 +1524,8 @@ def test_update_function_s3():

@mock_aws
def test_update_function_ecr():
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
conn = boto3.client("lambda", _lambda_region)
function_name = str(uuid4())[0:6]
image_uri = f"{ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/testlambdaecr:prod"
Expand Down
13 changes: 13 additions & 0 deletions tests/test_awslambda/test_lambda_function_urls.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import sys
from unittest import SkipTest
from uuid import uuid4

import boto3
import pytest
from botocore.exceptions import ClientError

from moto import mock_aws
from moto.utilities.distutils_version import LooseVersion

from .utilities import get_role_name, get_test_zip_file1

PYTHON_VERSION = "python3.11"

boto3_version = sys.modules["botocore"].__version__


@mock_aws
@pytest.mark.parametrize("key", ["FunctionName", "FunctionArn"])
def test_create_function_url_config(key):
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
client = boto3.client("lambda", "us-east-2")
function_name = str(uuid4())[0:6]
fxn = client.create_function(
Expand All @@ -40,6 +47,8 @@ def test_create_function_url_config(key):

@mock_aws
def test_create_function_url_config_with_cors():
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
client = boto3.client("lambda", "us-east-2")
function_name = str(uuid4())[0:6]
fxn = client.create_function(
Expand Down Expand Up @@ -75,6 +84,8 @@ def test_create_function_url_config_with_cors():

@mock_aws
def test_update_function_url_config_with_cors():
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
client = boto3.client("lambda", "us-east-2")
function_name = str(uuid4())[0:6]
fxn = client.create_function(
Expand Down Expand Up @@ -108,6 +119,8 @@ def test_update_function_url_config_with_cors():
@mock_aws
@pytest.mark.parametrize("key", ["FunctionName", "FunctionArn"])
def test_delete_function_url_config(key):
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
client = boto3.client("lambda", "us-east-2")
function_name = str(uuid4())[0:6]
fxn = client.create_function(
Expand Down
8 changes: 8 additions & 0 deletions tests/test_awslambda/test_lambda_layers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
from unittest import SkipTest, mock
from uuid import uuid4

Expand All @@ -9,12 +10,15 @@

from moto import mock_aws, settings
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
from moto.utilities.distutils_version import LooseVersion

from .utilities import get_role_name, get_test_zip_file1

PYTHON_VERSION = "python3.11"
_lambda_region = "us-west-2"

boto3_version = sys.modules["botocore"].__version__


@mock_aws
def test_publish_lambda_layers__without_content():
Expand Down Expand Up @@ -50,6 +54,8 @@ def test_publish_layer_with_unknown_s3_file():
@mock_aws
@freeze_time("2015-01-01 00:00:00")
def test_get_lambda_layers():
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
bucket_name = str(uuid4())
s3_conn = boto3.client("s3", _lambda_region)
s3_conn.create_bucket(
Expand Down Expand Up @@ -152,6 +158,8 @@ def test_get_lambda_layers():

@mock_aws
def test_get_layer_version():
if LooseVersion(boto3_version) < LooseVersion("1.29.0"):
raise SkipTest("Parameters only available in newer versions")
bucket_name = str(uuid4())
s3_conn = boto3.client("s3", _lambda_region)
s3_conn.create_bucket(
Expand Down
Loading

0 comments on commit 16ba3de

Please sign in to comment.