import time
from tests import unittest
import botocore.session
from botocore import exceptions
class TestApigateway(unittest.TestCase):
def setUp(self):
self.session = botocore.session.get_session()
self.client = self.session.create_client('apigateway', 'us-east-1')
self.api_name = 'mytestapi'
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':
raise unittest.SkipTest(
"Hit API gateway throttle limit, skipping test.")
raise
return api_id
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
def tearDown(self):
self.delete_api()
def test_put_integration(self):
path_resource_id = self.client.get_resources(
restApiId=self.api_id)['items'][0]['id']
self.client.put_method(
restApiId=self.api_id,
resourceId=path_resource_id,
httpMethod='GET',
authorizationType='None'
)
response = self.client.put_integration(
restApiId=self.api_id,
resourceId=path_resource_id,
httpMethod='GET',
type='HTTP',
integrationHttpMethod='GET',
uri='https://api.endpoint.com'
)
self.assertEqual(response['type'], 'HTTP')