Skip to content

Commit

Permalink
APIGateway: Use new OpenAPISpecValidator API (getmoto#6951)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers authored and toshyak committed Oct 26, 2023
1 parent 2b998e1 commit e8e8c2e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
12 changes: 9 additions & 3 deletions moto/apigateway/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
import requests
import responses

from openapi_spec_validator import validate_spec
try:
# Recommended as of 0.7.x
from openapi_spec_validator import validate # type: ignore
except ImportError:
# Only used in < 0.7.x
# (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
Expand Down Expand Up @@ -1567,7 +1573,7 @@ def import_rest_api(
"""
if fail_on_warnings:
try:
validate_spec(api_doc) # type: ignore[arg-type]
validate(api_doc) # type: ignore[arg-type]
except OpenAPIValidationError as e:
raise InvalidOpenAPIDocumentException(e)
except AttributeError:
Expand Down Expand Up @@ -1642,7 +1648,7 @@ def put_rest_api(

if fail_on_warnings:
try:
validate_spec(api_doc) # type: ignore[arg-type]
validate(api_doc) # type: ignore[arg-type]
except OpenAPIValidationError as e:
raise InvalidOpenAPIDocumentException(e)
except AttributeError:
Expand Down
18 changes: 10 additions & 8 deletions tests/test_s3/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3413,11 +3413,10 @@ def test_delete_objects_with_empty_keyname():
assert "Contents" not in client.list_objects(Bucket=bucket_name)


@mock_s3
def test_delete_objects_percent_encoded():
@pytest.mark.aws_verified
@s3_aws_verified
def test_delete_objects_percent_encoded(bucket_name=None):
client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
bucket_name = "testbucket-encoded"
client.create_bucket(Bucket=bucket_name)

object_key_1 = "a%2Fb"
object_key_2 = "a/%F0%9F%98%80"
Expand All @@ -3427,8 +3426,9 @@ def test_delete_objects_percent_encoded():
)
list_objs = client.list_objects(Bucket=bucket_name)
assert len(list_objs["Contents"]) == 2
assert list_objs["Contents"][0]["Key"] == object_key_1
assert list_objs["Contents"][1]["Key"] == object_key_2
keys = [o["Key"] for o in list_objs["Contents"]]
assert object_key_1 in keys
assert object_key_2 in keys

delete_objects = client.delete_objects(
Bucket=bucket_name,
Expand All @@ -3439,8 +3439,10 @@ def test_delete_objects_percent_encoded():
],
},
)
assert delete_objects["Deleted"][0] == {"Key": object_key_1}
assert delete_objects["Deleted"][1] == {"Key": object_key_2}
assert len(delete_objects["Deleted"]) == 2
deleted_keys = [o for o in delete_objects["Deleted"]]
assert {"Key": object_key_1} in deleted_keys
assert {"Key": object_key_2} in deleted_keys
assert "Contents" not in client.list_objects(Bucket=bucket_name)


Expand Down

0 comments on commit e8e8c2e

Please sign in to comment.