Skip to content

Commit

Permalink
Admin: Improve scaffolding and AWS tests (#7981)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers authored Aug 15, 2024
1 parent 919cbdd commit 459be00
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
5 changes: 4 additions & 1 deletion scripts/scaffold.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,8 @@ def insert_url(service, operation, api_protocol): # pylint: disable=too-many-lo
list(client._service_model._service_description["operations"].keys()),
)
uri = client._service_model.operation_model(aws_operation_name).http["requestUri"]
if "?" in uri:
uri = uri.split("?")[0]

path = os.path.join(
os.path.dirname(__file__), "..", "moto", get_escaped_service(service), "urls.py"
Expand All @@ -578,6 +580,7 @@ def insert_url(service, operation, api_protocol): # pylint: disable=too-many-lo

if any(_ for _ in lines if re.match(uri, _)):
return
uri = BaseResponse.uri_to_regexp(uri)[1:-1]

url_paths_found = False
last_elem_line_index = -1
Expand All @@ -593,7 +596,7 @@ def insert_url(service, operation, api_protocol): # pylint: disable=too-many-lo

# generate url pattern
if api_protocol == "rest-json":
new_line = f' "{0}/.*$": {service_class}Response.dispatch,'
new_line = f' "{{0}}{uri}$": {service_class}Response.dispatch,'
elif api_protocol == "rest-xml":
new_line = f' "{{0}}{uri}$": {service_class}Response.{operation},'
else:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_dynamodb/test_dynamodb_resource_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ def put_resource_policy(ddb, table_arn, action="dynamodb:*", revision_id=None):
try:
policy = ddb.get_resource_policy(ResourceArn=table_arn)
assert policy["RevisionId"] == revision_id
if allow_aws_request():
# Policy is supposedly ready- but may still complain that a ResourcePolicy update is in progress
# Hopefully AWS is ready afterwards
sleep(1)
return revision_id
except (ClientError, AssertionError):
# Policy is not ready yet
Expand Down
12 changes: 4 additions & 8 deletions tests/test_stepfunctions/parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import os
from functools import wraps
from time import sleep
from typing import TYPE_CHECKING, Callable, TypeVar
Expand All @@ -10,6 +9,7 @@

from moto import mock_aws, settings
from tests import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
from tests import allow_aws_request
from tests.test_stepfunctions.parser.templates.templates import load_template

if TYPE_CHECKING:
Expand All @@ -31,11 +31,7 @@ def aws_verified(func):

@wraps(func)
def pagination_wrapper():
allow_aws_request = (
os.environ.get("MOTO_TEST_ALLOW_AWS_REQUEST", "false").lower() == "true"
)

if allow_aws_request:
if allow_aws_request():
return func()
else:
with mock_aws():
Expand Down Expand Up @@ -74,7 +70,7 @@ def verify_execution_result(
execution_arn, state_machine_arn = _start_execution(
client, load_template(tmpl_name), exec_input, sfn_role
)
for _ in range(10):
for _ in range(20):
execution = client.describe_execution(executionArn=execution_arn)
if expected_status is None or execution["status"] == expected_status:
result = _verify_result(client, execution, execution_arn)
Expand All @@ -85,7 +81,7 @@ def verify_execution_result(
)
iam.delete_role(RoleName=role_name)
break
sleep(0.1)
sleep(1 if allow_aws_request() else 0.1)
else:
client.delete_state_machine(stateMachineArn=state_machine_arn)
iam.delete_role_policy(RoleName=role_name, PolicyName="allowLambdaInvoke")
Expand Down

0 comments on commit 459be00

Please sign in to comment.