8000 resolve comments on the PR · localstack/localstack@92676e7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 92676e7

Browse files
committed
resolve comments on the PR
1 parent 6d97043 commit 92676e7

File tree

4 files changed

+114
-334
lines changed

4 files changed

+114
-334
lines changed

localstack/services/apigateway/provider.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,12 +1081,12 @@ def update_request_validator(
10811081
f"Validator {request_validator_id} for API Gateway {rest_api_id} not found"
10821082
)
10831083

1084-
for operation in patch_operations:
1085-
path = operation.get("path")
1086-
operation_performed = operation.get("op")
1087-
if operation_performed != "replace":
1084+
for patch_operation in patch_operations:
1085+
path = patch_operation.get("path")
1086+
operation = patch_operation.get("op")
1087+
if operation != "replace":
10881088
raise BadRequestException(
1089-
f"Invalid patch path '{path}' specified for op '{operation_performed}'. "
1089+
f"Invalid patch path '{path}' specified for op '{operation}'. "
10901090
f"Please choose supported operations"
10911091
)
10921092
if path not in ("/name", "/validateRequestBody", "/validateRequestParameters"):
@@ -1096,15 +1096,12 @@ def update_request_validator(
10961096
)
10971097

10981098
key = path[1:]
1099-
value = operation.get("value")
1099+
value = patch_operation.get("value")
11001100
if key == "name" and not value:
11011101
raise BadRequestException("Request Validator name cannot be blank")
11021102

1103-
if key in ["validateRequestParameters", "validateRequestBody"]:
1104-
if value.lower() == "true":
1105-
value = True
1106-
else:
1107-
value = False
1103+
elif key in ("validateRequestParameters", "validateRequestBody"):
1104+
value = value and value.lower() == "true" or False
11081105

11091106
rest_api_container.validators[request_validator_id][key] = value
11101107

tests/integration/apigateway/test_apigateway_api.py

Lines changed: 44 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,38 +1532,69 @@ def test_update_model(
15321532

15331533
class TestApiGatewayApiRequestValidator:
15341534
@pytest.mark.aws_validated
1535-
def test_create_request_validator(self, apigateway_client, apigw_create_rest_api, snapshot):
1535+
def test_request_validator_lifecycle(self, apigateway_client, apigw_create_rest_api, snapshot):
15361536
response = apigw_create_rest_api(
15371537
name=f"test-api-{short_uid()}",
15381538
description="my api",
15391539
)
15401540
snapshot.match("create-rest-api", response)
15411541
api_id = response["id"]
15421542

1543+
# create a request validator for an API
15431544
response = apigateway_client.create_request_validator(
15441545
restApiId=api_id, name=f"test-validator-{short_uid()}"
15451546
)
15461547
snapshot.match("create-request-validator", response)
1548+
validator_id = response["id"]
15471549

1548-
@pytest.mark.aws_validated
1549-
def test_get_request_validator(self, apigateway_client, apigw_create_rest_api, snapshot):
1550-
response = apigw_create_rest_api(
1551-
name=f"test-api-{short_uid()}",
1552-
description="my api",
1550+
# get detail of a specific request validator corresponding to an API
1551+
response = apigateway_client.get_request_validator(
1552+
restApiId=api_id, requestValidatorId=validator_id
15531553
)
1554-
snapshot.match("create-rest-api", response)
1555-
api_id = response["id"]
1554+
snapshot.match("get-request-validator", response)
15561555

1557-
response = apigateway_client.create_request_validator(
1558-
restApiId=api_id, name=f"test-validator-{short_uid()}"
1556+
# get list of all request validators in the API
1557+
response = apigateway_client.get_request_validators(restApiId=api_id)
1558+
snapshot.match("get-request-validators", response)
1559+
1560+
# update request validators with different set of patch operations
1561+
patch_operations = [
1562+
{"op": "replace", "path": "/validateRequestBody", "value": "true"},
1563+
]
1564+
response = apigateway_client.update_request_validator(
1565+
restApiId=api_id, requestValidatorId=validator_id, patchOperations=patch_operations
15591566
)
1560-
snapshot.match("create-request-validator", response)
1561-
validator_id = response["id"]
1567+
snapshot.match("update-request-validator-with-value", response)
1568+
1569+
patch_operations = [
1570+
{"op": "replace", "path": "/validateRequestBody"},
1571+
]
1572+
response = apigateway_client.update_request_validator(
1573+
restApiId=api_id, requestValidatorId=validator_id, patchOperations=patch_operations
1574+
)
1575+
snapshot.match("update-request-validator-without-value", response)
15621576

15631577
response = apigateway_client.get_request_validator(
15641578
restApiId=api_id, requestValidatorId=validator_id
15651579
)
1566-
snapshot.match("get-request-validators", response)
1580+
snapshot.match("get-request-validators-after-update-operation", response)
1581+
1582+
# delete request validator
1583+
response = apigateway_client.delete_request_validator(
1584+
restApiId=api_id, requestValidatorId=validator_id
1585+
)
1586+
snapshot.match("delete-request-validator", response)
1587+
1588+
# try fetching details of the deleted request validator
1589+
with pytest.raises(ClientError) as e:
1590+
apigateway_client.get_request_validator(
1591+
restApiId=api_id, requestValidatorId=validator_id
1592+
)
1593+
snapshot.match("get-deleted-request-validator", e.value.response)
1594+
1595+
# check list of all request validators in the API
1596+
response = apigateway_client.get_request_validators(restApiId=api_id)
1597+
snapshot.match("get-request-validators-after-delete", response)
15671598

15681599
@pytest.mark.aws_validated
15691600
def test_invalid_get_request_validator(
@@ -1592,23 +1623,6 @@ def test_invalid_get_request_validator(
15921623
)
15931624
snapshot.match("get-request-validators-invalid-validator-id", e.value.response)
15941625

1595-
@pytest.mark.aws_validated
1596-
def test_get_request_validators(self, apigateway_client, apigw_create_rest_api, snapshot):
1597-
response = apigw_create_rest_api(
1598-
name=f"test-api-{short_uid()}",
1599-
description="my api",
1600-
)
1601-
snapshot.match("create-rest-api", response)
1602-
api_id = response["id"]
1603-
1604-
response = apigateway_client.create_request_validator(
1605-
restApiId=api_id, name=f"test-validator-{short_uid()}"
1606-
)
1607-
snapshot.match("create-request-validator", response)
1608-
1609-
response = apigateway_client.get_request_validators(restApiId=api_id)
1610-
snapshot.match("get-request-validators", response)
1611-
16121626
@pytest.mark.aws_validated
16131627
def test_invalid_get_request_validators(
16141628
self, apigateway_client, apigw_create_rest_api, snapshot
@@ -1617,32 +1631,6 @@ def test_invalid_get_request_validators(
16171631
apigateway_client.get_request_validators(restApiId="api_id")
16181632
snapshot.match("get-invalid-request-validators", e.value.response)
16191633

1620-
@pytest.mark.aws_validated
1621-
def test_delete_request_validator(self, apigateway_client, apigw_create_rest_api, snapshot):
1622-
response = apigw_create_rest_api(
1623-
name=f"test-api-{short_uid()}",
1624-
description="my api",
1625-
)
1626-
snapshot.match("create-rest-api", response)
1627-
api_id = response["id"]
1628-
1629-
response = apigateway_client.create_request_validator(
1630-
restApiId=api_id, name=f"test-validator-{short_uid()}"
1631-
)
1632-
snapshot.match("create-request-validator", response)
1633-
validator_id = response["id"]
1634-
1635-
response = apigateway_client.get_request_validators(restApiId=api_id)
1636-
snapshot.match("get-request-validators-before-delete", response)
1637-
1638-
response = apigateway_client.delete_request_validator(
1639-
restApiId=api_id, requestValidatorId=validator_id
1640-
)
1641-
snapshot.match("delete-request-validator", response)
1642-
1643-
response = apigateway_client.get_request_validators(restApiId=api_id)
1644-
snapshot.match("get-request-validators-after-delete", response)
1645-
16461634
@pytest.mark.aws_validated
16471635
def test_invalid_delete_request_validator(
16481636
self, apigateway_client, apigw_create_rest_api, snapshot
@@ -1670,39 +1658,6 @@ def test_invalid_delete_request_validator(
16701658
)
16711659
snapshot.match("delete-request-validator-invalid-validator-id", e.value.response)
16721660

1673-
@pytest.mark.aws_validated
1674-
def test_update_request_validator(self, apigateway_client, apigw_create_rest_api, snapshot):
1675-
response = apigw_create_rest_api(
1676-
name=f"test-api-{short_uid()}",
1677-
description="my api",
1678-
)
1679-
snapshot.match("create-rest-api", response)
1680-
api_id = response["id"]
1681-
1682-
response = apigateway_client.create_request_validator(
1683-
restApiId=api_id, name=f"test-validator-{short_uid()}"
1684-
)
1685-
snapshot.match("create-request-validator", response)
1686-
validator_id = response["id"]
1687-
1688-
response = apigateway_client.get_request_validator(
1689-
restApiId=api_id, requestValidatorId=validator_id
1690-
)
1691-
snapshot.match("get-request-validators-before-update", response)
1692-
1693-
patch_operations = [
1694-
{"op": "replace", "path": "/validateRequestBody", "value": "true"},
1695-
]
1696-
response = apigateway_client.update_request_validator(
1697-
restApiId=api_id, requestValidatorId=validator_id, patchOperations=patch_operations
1698-
)
1699-
snapshot.match("update-request-validator", response)
1700-
1701-
response = apigateway_client.get_request_validator(
1702-
restApiId=api_id, requestValidatorId=validator_id
1703-
)
1704-
snapshot.match("get-request-validators-after-update", response)
1705-
17061661
@pytest.mark.aws_validated
17071662
def test_create_request_validator_invalid_api_id(
17081663
self, apigateway_client, apigw_create_rest_api, snapshot

0 commit comments

Comments
 (0)
0