@@ -1528,3 +1528,196 @@ def test_update_model(
1528
1528
patchOperations = patch_operations ,
1529
1529
)
1530
1530
snapshot .match ("update-model-empty-schema" , e .value .response )
1531
+
1532
+
1533
+ class TestApiGatewayApiRequestValidator :
1534
+ @pytest .mark .aws_validated
1535
+ def test_request_validator_lifecycle (self , apigateway_client , apigw_create_rest_api , snapshot ):
1536
+ response = apigw_create_rest_api (
1537
+ name = f"test-api-{ short_uid ()} " ,
1538
+ description = "my api" ,
1539
+ )
1540
+ snapshot .match ("create-rest-api" , response )
1541
+ api_id = response ["id" ]
1542
+
1543
+ # create a request validator for an API
1544
+ response = apigateway_client .create_request_validator (
1545
+ restApiId = api_id , name = f"test-validator-{ short_uid ()} "
1546
+ )
1547
+ snapshot .match ("create-request-validator" , response )
1548
+ validator_id = response ["id" ]
1549
+
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
+ )
1554
+ snapshot .match ("get-request-validator" , response )
1555
+
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
1566
+ )
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 )
1576
+
1577
+ response = apigateway_client .get_request_validator (
1578
+ restApiId = api_id , requestValidatorId = validator_id
1579
+ )
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 )
1598
+
1599
+ @pytest .mark .aws_validated
1600
+ def test_invalid_get_request_validator (
1601
+ self , apigateway_client , apigw_create_rest_api , snapshot
1602
+ ):
1603
+ response = apigw_create_rest_api (
1604
+ name = f"test-api-{ short_uid ()} " ,
1605
+ description = "my api" ,
1606
+ )
1607
+ api_id = response ["id" ]
1608
+
1609
+ response = apigateway_client .create_request_validator (
1610
+ restApiId = api_id , name = f"test-validator-{ short_uid ()} "
1611
+ )
1612
+ validator_id = response ["id" ]
1613
+
1614
+ with pytest .raises (ClientError ) as e :
1615
+ apigateway_client .get_request_validator (
1616
+ restApiId = "api_id" , requestValidatorId = validator_id
1617
+ )
1618
+ snapshot .match ("get-request-validators-invalid-api-id" , e .value .response )
1619
+
1620
+ with pytest .raises (ClientError ) as e :
1621
+ apigateway_client .get_request_validator (
1622
+ restApiId = api_id , requestValidatorId = "validator_id"
1623
+ )
1624
+ snapshot .match ("get-request-validators-invalid-validator-id" , e .value .response )
1625
+
1626
+ @pytest .mark .aws_validated
1627
+ def test_invalid_get_request_validators (
1628
+ self , apigateway_client , apigw_create_rest_api , snapshot
1629
+ ):
1630
+ with pytest .raises (ClientError ) as e :
1631
+ apigateway_client .get_request_validators (restApiId = "api_id" )
1632
+ snapshot .match ("get-invalid-request-validators" , e .value .response )
1633
+
1634
+ @pytest .mark .aws_validated
1635
+ def test_invalid_delete_request_validator (
1636
+ self , apigateway_client , apigw_create_rest_api , snapshot
1637
+ ):
1638
+ response = apigw_create_rest_api (
1639
+ name = f"test-api-{ short_uid ()} " ,
1640
+ description = "my api" ,
1641
+ )
1642
+ api_id = response ["id" ]
1643
+
1644
+ response = apigateway_client .create_request_validator (
1645
+ restApiId = api_id , name = f"test-validator-{ short_uid ()} "
1646
+ )
1647
+ validator_id = response ["id" ]
1648
+
1649
+ with pytest .raises (ClientError ) as e :
1650
+ apigateway_client .delete_request_validator (
1651
+ restApiId = "api_id" , requestValidatorId = validator_id
1652
+ )
1653
+ snapshot .match ("delete-request-validator-invalid-api-id" , e .value .response )
1654
+
1655
+ with pytest .raises (ClientError ) as e :
1656
+ apigateway_client .delete_request_validator (
1657
+ restApiId = api_id , requestValidatorId = "validator_id"
1658
+ )
1659
+ snapshot .match ("delete-request-validator-invalid-validator-id" , e .value .response )
1660
+
1661
+ @pytest .mark .aws_validated
1662
+ def test_create_request_validator_invalid_api_id (
1663
+ self , apigateway_client , apigw_create_rest_api , snapshot
1664
+ ):
1665
+ with pytest .raises (ClientError ) as e :
1666
+ apigateway_client .create_request_validator (
1667
+ restApiId = "api_id" , name = f"test-validator-{ short_uid ()} "
1668
+ )
1669
+ snapshot .match ("invalid-create-request-validator" , e .value .response )
1670
+
1671
+ @pytest .mark .aws_validated
1672
+ def test_invalid_update_request_validator_operations (
1673
+ self , apigateway_client , apigw_create_rest_api , snapshot
1674
+ ):
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
+ patch_operations = [
1689
+ {"op" : "add" , "path" : "/validateRequestBody" , "value" : "true" },
1690
+ ]
1691
+ with pytest .raises (ClientError ) as e :
1692
+ apigateway_client .update_request_validator (
1693
+ restApiId = api_id , requestValidatorId = validator_id , patchOperations = patch_operations
1694
+ )
1695
+ snapshot .match ("update-request-validator-invalid-add-operation" , e .value .response )
1696
+
1697
+ patch_operations = [
1698
+ {"op" : "remove" , "path" : "/validateRequestBody" , "value" : "true" },
1699
+ ]
1700
+ with pytest .raises (ClientError ) as e :
1701
+ apigateway_client .update_request_validator (
1702
+ restApiId = api_id , requestValidatorId = validator_id , patchOperations = patch_operations
1703
+ )
1704
+ snapshot .match ("update-request-validator-invalid-remove-operation" , e .value .response )
1705
+
1706
+ patch_operations = [
1707
+ {"op" : "replace" , "path" : "/invalidPath" , "value" : "true" },
1708
+ ]
1709
+ with pytest .raises (ClientError ) as e :
1710
+ apigateway_client .update_request_validator (
1711
+ restApiId = api_id , requestValidatorId = validator_id , patchOperations = patch_operations
1712
+ )
1713
+ snapshot .match ("update-request-validator-invalid-path" , e .value .response )
1714
+
1715
+ patch_operations = [
1716
+ {"op" : "replace" , "path" : "/name" },
1717
+ ]
1718
+
1719
+ with pytest .raises (ClientError ) as e :
1720
+ apigateway_client .update_request_validator (
1721
+ restApiId = api_id , requestValidatorId = validator_id , patchOperations = patch_operations
1722
+ )
1723
+ snapshot .match ("update-request-validator-empty-name-value" , e .value .response )
0 commit comments