File: test_apigateway.py

package info (click to toggle)
python-botocore 1.12.103%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 41,552 kB
  • sloc: python: 43,119; xml: 15,052; makefile: 131
file content (79 lines) | stat: -rw-r--r-- 2,762 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# 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.
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')

        # Create a resource to use with this client.
        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):
        # The only resource on a brand new api is the path. So use that ID.
        path_resource_id = self.client.get_resources(
            restApiId=self.api_id)['items'][0]['id']

        # Create a method for the resource.
        self.client.put_method(
            restApiId=self.api_id,
            resourceId=path_resource_id,
            httpMethod='GET',
            authorizationType='None'
        )

        # 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',
            uri='https://api.endpoint.com'
        )
        # Assert the response was successful by checking the integration type
        self.assertEqual(response['type'], 'HTTP')