@@ -1532,38 +1532,69 @@ def test_update_model(
1532
1532
1533
1533
class TestApiGatewayApiRequestValidator :
1534
1534
@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 ):
1536
1536
response = apigw_create_rest_api (
1537
1537
name = f"test-api-{ short_uid ()} " ,
1538
1538
description = "my api" ,
1539
1539
)
1540
1540
snapshot .match ("create-rest-api" , response )
1541
1541
api_id = response ["id" ]
1542
1542
1543
+ # create a request validator for an API
1543
1544
response = apigateway_client .create_request_validator (
1544
1545
restApiId = api_id , name = f"test-validator-{ short_uid ()} "
1545
1546
)
1546
1547
snapshot .match ("create-request-validator" , response )
1548
+ validator_id = response ["id" ]
1547
1549
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
1553
1553
)
1554
- snapshot .match ("create-rest-api" , response )
1555
- api_id = response ["id" ]
1554
+ snapshot .match ("get-request-validator" , response )
1556
1555
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
1559
1566
)
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 )
1562
1576
1563
1577
response = apigateway_client .get_request_validator (
1564
1578
restApiId = api_id , requestValidatorId = validator_id
1565
1579
)
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 )
1567
1598
1568
1599
@pytest .mark .aws_validated
1569
1600
def test_invalid_get_request_validator (
@@ -1592,23 +1623,6 @@ def test_invalid_get_request_validator(
1592
1623
)
1593
1624
snapshot .match ("get-request-validators-invalid-validator-id" , e .value .response )
1594
1625
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
-
1612
1626
@pytest .mark .aws_validated
1613
1627
def test_invalid_get_request_validators (
1614
1628
self , apigateway_client , apigw_create_rest_api , snapshot
@@ -1617,32 +1631,6 @@ def test_invalid_get_request_validators(
1617
1631
apigateway_client .get_request_validators (restApiId = "api_id" )
1618
1632
snapshot .match ("get-invalid-request-validators" , e .value .response )
1619
1633
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
-
1646
1634
@pytest .mark .aws_validated
1647
1635
def test_invalid_delete_request_validator (
1648
1636
self , apigateway_client , apigw_create_rest_api , snapshot
@@ -1670,39 +1658,6 @@ def test_invalid_delete_request_validator(
1670
1658
)
1671
1659
snapshot .match ("delete-request-validator-invalid-validator-id" , e .value .response )
1672
1660
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
-
1706
1661
@pytest .mark .aws_validated
1707
1662
def test_create_request_validator_invalid_api_id (
1708
1663
self , apigateway_client , apigw_create_rest_api , snapshot
0 commit comments