def test_list_schemas_throws_exception_when_result_set_is_empty(self):
     max_items = 10
     schemas_api_caller = SchemasApiCaller(self.client)
     self.client.can_paginate.return_value = True
     self.client.get_paginator.return_value.paginate.return_value = []
     with self.assertRaises(ResourceNotFound) as ctx:
         schemas_api_caller.list_schemas("aws.events", None, max_items)
     msg = "No Schemas found for registry %s" % "aws.events"
     self.assertEqual(str(ctx.exception), msg)
 def test_list_schemas_raises_not_available_in_region_exception(self):
     max_items = 10
     schemas_api_caller = SchemasApiCaller(self.client)
     self.client.can_paginate.return_value = False
     self.client.get_paginator.return_value.paginate.side_effect = botocore.exceptions.EndpointConnectionError(
         endpoint_url="Not valid endpoint.")
     with self.assertRaises(NotAvailableInRegion) as ctx:
         schemas_api_caller.list_schemas("registry-name", "next_token",
                                         max_items)
     msg = (
         "EventBridge Schemas are not available in provided region. Please check "
         "AWS doc for Schemas supported regions.")
     self.assertEqual(str(ctx.exception), msg)
    def test_list_schemas_with_next_token(self):
        registry_name = "registry1"
        max_items = 10
        schemas_api_caller = SchemasApiCaller(self.client)
        self.client.can_paginate.return_value = True
        self.client.get_paginator.return_value.paginate.return_value = [{
            "ResponseMetadata": {
                "RequestId": "123",
                "HTTPHeaders": {
                    "x-amzn-requestid": "e28",
                    "x-amz-apigw-id": "CTqLRGCbPHcFiAg=",
                    "x-amzn-trace-id": "Root=1-350;Sampled=0",
                },
                "RetryAttempts": 0,
            },
            "NextToken":
            "1111111111",
            "Schemas": [{
                "LastModified": "LastModified",
                "SchemaName": "aws.autoscaling.AWSAPICallViaCloudTrail",
                "VersionCount": 1,
            }],
        }]

        list_schemas_response = schemas_api_caller.list_schemas(
            registry_name, "next_token", max_items)
        self.assertEqual(len(list_schemas_response["schemas"]), 1)
        self.assertEqual(list_schemas_response["schemas"],
                         ["aws.autoscaling.AWSAPICallViaCloudTrail"])
        self.assertEqual(list_schemas_response["next_token"], "1111111111")

        self.client.get_paginator.assert_called_once()
        self.client.get_paginator.assert_called_once_with("list_schemas")
        self.client.get_paginator.return_value.paginate.assert_called_once_with(
            RegistryName=registry_name,
            PaginationConfig={
                "StartingToken": "next_token",
                "MaxItems": max_items,
                "PageSize": max_items
            },
        )