2015-11-24 12:34:53 +01:00
|
|
|
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
|
|
# may not use this file except in compliance with the License. A copy of
|
|
|
|
# the License is located at
|
|
|
|
#
|
|
|
|
# http://aws.amazon.com/apache2.0/
|
|
|
|
#
|
|
|
|
# or in the "license" file accompanying this file. This file is
|
|
|
|
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
|
|
# ANY KIND, either express or implied. See the License for the specific
|
|
|
|
# language governing permissions and limitations under the License.
|
2017-02-02 09:27:08 +01:00
|
|
|
import time
|
|
|
|
|
2015-11-24 12:34:53 +01:00
|
|
|
import botocore.session
|
2016-10-11 02:22:54 +02:00
|
|
|
from botocore import exceptions
|
2022-05-26 00:10:07 +02:00
|
|
|
from tests import unittest
|
2015-11-24 12:34:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestApigateway(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.session = botocore.session.get_session()
|
|
|
|
self.client = self.session.create_client('apigateway', 'us-east-1')
|
|
|
|
|
2017-02-02 09:27:08 +01:00
|
|
|
# Create a resource to use with this client.
|
2015-11-24 12:34:53 +01:00
|
|
|
self.api_name = 'mytestapi'
|
2016-10-11 02:22:54 +02:00
|
|
|
self.api_id = self.create_rest_api_or_skip()
|
|
|
|
|
|
|
|
def create_rest_api_or_skip(self):
|
|
|
|
try:
|
|
|
|
api_id = self.client.create_rest_api(name=self.api_name)['id']
|
|
|
|
except exceptions.ClientError as e:
|
|
|
|
if e.response['Error']['Code'] == 'TooManyRequestsException':
|
2017-02-02 09:27:08 +01:00
|
|
|
raise unittest.SkipTest(
|
2022-05-26 00:10:07 +02:00
|
|
|
"Hit API gateway throttle limit, skipping test."
|
|
|
|
)
|
2017-02-02 09:27:08 +01:00
|
|
|
raise
|
2016-10-11 02:22:54 +02:00
|
|
|
return api_id
|
2015-11-24 12:34:53 +01:00
|
|
|
|
2017-02-02 09:27:08 +01:00
|
|
|
def delete_api(self):
|
|
|
|
retries = 0
|
|
|
|
while retries < 10:
|
|
|
|
try:
|
|
|
|
self.client.delete_rest_api(restApiId=self.api_id)
|
|
|
|
break
|
|
|
|
except exceptions.ClientError as e:
|
|
|
|
if e.response['Error']['Code'] == 'TooManyRequestsException':
|
|
|
|
retries += 1
|
|
|
|
time.sleep(5)
|
|
|
|
else:
|
|
|
|
raise
|
|
|
|
|
2015-11-24 12:34:53 +01:00
|
|
|
def tearDown(self):
|
2017-02-02 09:27:08 +01:00
|
|
|
self.delete_api()
|
2015-11-24 12:34:53 +01:00
|
|
|
|
|
|
|
def test_put_integration(self):
|
|
|
|
# The only resource on a brand new api is the path. So use that ID.
|
2022-05-26 00:10:07 +02:00
|
|
|
path_resource_id = self.client.get_resources(restApiId=self.api_id)[
|
|
|
|
'items'
|
|
|
|
][0]['id']
|
2015-11-24 12:34:53 +01:00
|
|
|
|
|
|
|
# Create a method for the resource.
|
|
|
|
self.client.put_method(
|
|
|
|
restApiId=self.api_id,
|
|
|
|
resourceId=path_resource_id,
|
|
|
|
httpMethod='GET',
|
2022-05-26 00:10:07 +02:00
|
|
|
authorizationType='None',
|
2015-11-24 12:34:53 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
# Put an integration on the method.
|
|
|
|
response = self.client.put_integration(
|
|
|
|
restApiId=self.api_id,
|
|
|
|
resourceId=path_resource_id,
|
|
|
|
httpMethod='GET',
|
|
|
|
type='HTTP',
|
|
|
|
integrationHttpMethod='GET',
|
2022-05-26 00:10:07 +02:00
|
|
|
uri='https://api.endpoint.com',
|
2015-11-24 12:34:53 +01:00
|
|
|
)
|
|
|
|
# Assert the response was successful by checking the integration type
|
|
|
|
self.assertEqual(response['type'], 'HTTP')
|