| 
									
										
										
										
											2016-03-01 12:03:59 -05:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-01 12:03:59 -05:00
										 |  |  | import boto3 | 
					
						
							|  |  |  | from freezegun import freeze_time | 
					
						
							| 
									
										
										
										
											2016-03-05 10:54:19 -05:00
										 |  |  | import requests | 
					
						
							| 
									
										
										
										
											2016-03-01 12:03:59 -05:00
										 |  |  | import sure  # noqa | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  | from botocore.exceptions import ClientError | 
					
						
							| 
									
										
										
										
											2016-03-01 12:03:59 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-05 16:57:43 -04:00
										 |  |  | import responses | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  | from moto import mock_apigateway, settings | 
					
						
							| 
									
										
										
										
											2016-03-01 12:03:59 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @freeze_time("2015-01-01") | 
					
						
							|  |  |  | @mock_apigateway | 
					
						
							|  |  |  | def test_create_and_get_rest_api(): | 
					
						
							|  |  |  |     client = boto3.client('apigateway', region_name='us-west-2') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.create_rest_api( | 
					
						
							|  |  |  |         name='my_api', | 
					
						
							|  |  |  |         description='this is my api', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     api_id = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_rest_api( | 
					
						
							|  |  |  |         restApiId=api_id | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.pop('ResponseMetadata') | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  |     response.pop('createdDate') | 
					
						
							| 
									
										
										
										
											2016-03-01 12:03:59 -05:00
										 |  |  |     response.should.equal({ | 
					
						
							|  |  |  |         'id': api_id, | 
					
						
							|  |  |  |         'name': 'my_api', | 
					
						
							|  |  |  |         'description': 'this is my api', | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_apigateway | 
					
						
							|  |  |  | def test_list_and_delete_apis(): | 
					
						
							|  |  |  |     client = boto3.client('apigateway', region_name='us-west-2') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.create_rest_api( | 
					
						
							|  |  |  |         name='my_api', | 
					
						
							|  |  |  |         description='this is my api', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     api_id = response['id'] | 
					
						
							|  |  |  |     client.create_rest_api( | 
					
						
							|  |  |  |         name='my_api2', | 
					
						
							|  |  |  |         description='this is my api2', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_rest_apis() | 
					
						
							|  |  |  |     len(response['items']).should.equal(2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.delete_rest_api( | 
					
						
							|  |  |  |         restApiId=api_id | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_rest_apis() | 
					
						
							|  |  |  |     len(response['items']).should.equal(1) | 
					
						
							| 
									
										
										
										
											2016-03-01 18:50:06 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_apigateway | 
					
						
							|  |  |  | def test_create_resource(): | 
					
						
							|  |  |  |     client = boto3.client('apigateway', region_name='us-west-2') | 
					
						
							|  |  |  |     response = client.create_rest_api( | 
					
						
							|  |  |  |         name='my_api', | 
					
						
							|  |  |  |         description='this is my api', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     api_id = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resources = client.get_resources(restApiId=api_id) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     root_id = [resource for resource in resources[ | 
					
						
							|  |  |  |         'items'] if resource['path'] == '/'][0]['id'] | 
					
						
							| 
									
										
										
										
											2016-03-01 18:50:06 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     root_resource = client.get_resource( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     root_resource['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     root_resource['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-03-01 18:50:06 -05:00
										 |  |  |     root_resource.should.equal({ | 
					
						
							|  |  |  |         'path': '/', | 
					
						
							|  |  |  |         'id': root_id, | 
					
						
							|  |  |  |         'ResponseMetadata': {'HTTPStatusCode': 200}, | 
					
						
							|  |  |  |         'resourceMethods': { | 
					
						
							|  |  |  |             'GET': {} | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.create_resource( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         parentId=root_id, | 
					
						
							|  |  |  |         pathPart='/users', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resources = client.get_resources(restApiId=api_id)['items'] | 
					
						
							|  |  |  |     len(resources).should.equal(2) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     non_root_resource = [ | 
					
						
							|  |  |  |         resource for resource in resources if resource['path'] != '/'][0] | 
					
						
							| 
									
										
										
										
											2016-03-01 18:50:06 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = client.delete_resource( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=non_root_resource['id'] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     len(client.get_resources(restApiId=api_id)['items']).should.equal(1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-05 10:54:19 -05:00
										 |  |  | @mock_apigateway | 
					
						
							|  |  |  | def test_child_resource(): | 
					
						
							|  |  |  |     client = boto3.client('apigateway', region_name='us-west-2') | 
					
						
							|  |  |  |     response = client.create_rest_api( | 
					
						
							|  |  |  |         name='my_api', | 
					
						
							|  |  |  |         description='this is my api', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     api_id = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resources = client.get_resources(restApiId=api_id) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     root_id = [resource for resource in resources[ | 
					
						
							|  |  |  |         'items'] if resource['path'] == '/'][0]['id'] | 
					
						
							| 
									
										
										
										
											2016-03-05 10:54:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = client.create_resource( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         parentId=root_id, | 
					
						
							|  |  |  |         pathPart='users', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     users_id = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.create_resource( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         parentId=users_id, | 
					
						
							|  |  |  |         pathPart='tags', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     tags_id = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     child_resource = client.get_resource( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=tags_id, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     child_resource['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     child_resource['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-03-05 10:54:19 -05:00
										 |  |  |     child_resource.should.equal({ | 
					
						
							|  |  |  |         'path': '/users/tags', | 
					
						
							|  |  |  |         'pathPart': 'tags', | 
					
						
							|  |  |  |         'parentId': users_id, | 
					
						
							|  |  |  |         'id': tags_id, | 
					
						
							|  |  |  |         'ResponseMetadata': {'HTTPStatusCode': 200}, | 
					
						
							|  |  |  |         'resourceMethods': {'GET': {}}, | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-01 18:50:06 -05:00
										 |  |  | @mock_apigateway | 
					
						
							|  |  |  | def test_create_method(): | 
					
						
							|  |  |  |     client = boto3.client('apigateway', region_name='us-west-2') | 
					
						
							|  |  |  |     response = client.create_rest_api( | 
					
						
							|  |  |  |         name='my_api', | 
					
						
							|  |  |  |         description='this is my api', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     api_id = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resources = client.get_resources(restApiId=api_id) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     root_id = [resource for resource in resources[ | 
					
						
							|  |  |  |         'items'] if resource['path'] == '/'][0]['id'] | 
					
						
							| 
									
										
										
										
											2016-03-01 18:50:06 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     client.put_method( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |         authorizationType='none', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_method( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET' | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-03-01 18:50:06 -05:00
										 |  |  |     response.should.equal({ | 
					
						
							|  |  |  |         'httpMethod': 'GET', | 
					
						
							|  |  |  |         'authorizationType': 'none', | 
					
						
							|  |  |  |         'ResponseMetadata': {'HTTPStatusCode': 200} | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_apigateway | 
					
						
							|  |  |  | def test_create_method_response(): | 
					
						
							|  |  |  |     client = boto3.client('apigateway', region_name='us-west-2') | 
					
						
							|  |  |  |     response = client.create_rest_api( | 
					
						
							|  |  |  |         name='my_api', | 
					
						
							|  |  |  |         description='this is my api', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     api_id = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resources = client.get_resources(restApiId=api_id) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     root_id = [resource for resource in resources[ | 
					
						
							|  |  |  |         'items'] if resource['path'] == '/'][0]['id'] | 
					
						
							| 
									
										
										
										
											2016-03-01 18:50:06 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     client.put_method( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |         authorizationType='none', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_method( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET' | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.put_method_response( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |         statusCode='200', | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-03-01 18:50:06 -05:00
										 |  |  |     response.should.equal({ | 
					
						
							|  |  |  |         'ResponseMetadata': {'HTTPStatusCode': 200}, | 
					
						
							|  |  |  |         'statusCode': '200' | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_method_response( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |         statusCode='200', | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-03-01 18:50:06 -05:00
										 |  |  |     response.should.equal({ | 
					
						
							|  |  |  |         'ResponseMetadata': {'HTTPStatusCode': 200}, | 
					
						
							|  |  |  |         'statusCode': '200' | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.delete_method_response( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |         statusCode='200', | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-03-01 18:50:06 -05:00
										 |  |  |     response.should.equal({'ResponseMetadata': {'HTTPStatusCode': 200}}) | 
					
						
							| 
									
										
										
										
											2016-03-02 15:18:11 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_apigateway | 
					
						
							|  |  |  | def test_integrations(): | 
					
						
							|  |  |  |     client = boto3.client('apigateway', region_name='us-west-2') | 
					
						
							|  |  |  |     response = client.create_rest_api( | 
					
						
							|  |  |  |         name='my_api', | 
					
						
							|  |  |  |         description='this is my api', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     api_id = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resources = client.get_resources(restApiId=api_id) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     root_id = [resource for resource in resources[ | 
					
						
							|  |  |  |         'items'] if resource['path'] == '/'][0]['id'] | 
					
						
							| 
									
										
										
										
											2016-03-02 15:18:11 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     client.put_method( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |         authorizationType='none', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.put_method_response( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |         statusCode='200', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.put_integration( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |         type='HTTP', | 
					
						
							|  |  |  |         uri='http://httpbin.org/robots.txt', | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-03-04 18:02:07 -05:00
										 |  |  |     response.should.equal({ | 
					
						
							| 
									
										
										
										
											2016-03-05 09:48:37 -05:00
										 |  |  |         'ResponseMetadata': {'HTTPStatusCode': 200}, | 
					
						
							|  |  |  |         'httpMethod': 'GET', | 
					
						
							|  |  |  |         'integrationResponses': { | 
					
						
							|  |  |  |             '200': { | 
					
						
							|  |  |  |                 'responseTemplates': { | 
					
						
							|  |  |  |                     'application/json': None | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |                 'statusCode': 200 | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-03-04 18:02:07 -05:00
										 |  |  |         'type': 'HTTP', | 
					
						
							| 
									
										
										
										
											2016-03-05 09:48:37 -05:00
										 |  |  |         'uri': 'http://httpbin.org/robots.txt' | 
					
						
							| 
									
										
										
										
											2016-03-04 18:02:07 -05:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_integration( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET' | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-03-04 18:02:07 -05:00
										 |  |  |     response.should.equal({ | 
					
						
							| 
									
										
										
										
											2016-03-05 09:48:37 -05:00
										 |  |  |         'ResponseMetadata': {'HTTPStatusCode': 200}, | 
					
						
							|  |  |  |         'httpMethod': 'GET', | 
					
						
							|  |  |  |         'integrationResponses': { | 
					
						
							|  |  |  |             '200': { | 
					
						
							|  |  |  |                 'responseTemplates': { | 
					
						
							|  |  |  |                     'application/json': None | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |                 'statusCode': 200 | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-03-04 18:02:07 -05:00
										 |  |  |         'type': 'HTTP', | 
					
						
							| 
									
										
										
										
											2016-03-05 09:48:37 -05:00
										 |  |  |         'uri': 'http://httpbin.org/robots.txt' | 
					
						
							| 
									
										
										
										
											2016-03-04 18:02:07 -05:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_resource( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-03-04 18:02:07 -05:00
										 |  |  |     response['resourceMethods']['GET']['methodIntegration'].should.equal({ | 
					
						
							| 
									
										
										
										
											2016-03-05 09:48:37 -05:00
										 |  |  |         'httpMethod': 'GET', | 
					
						
							|  |  |  |         'integrationResponses': { | 
					
						
							|  |  |  |             '200': { | 
					
						
							|  |  |  |                 'responseTemplates': { | 
					
						
							|  |  |  |                     'application/json': None | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |                 'statusCode': 200 | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-03-04 18:02:07 -05:00
										 |  |  |         'type': 'HTTP', | 
					
						
							|  |  |  |         'uri': 'http://httpbin.org/robots.txt' | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.delete_integration( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET' | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_resource( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response['resourceMethods']['GET'].shouldnt.contain("methodIntegration") | 
					
						
							| 
									
										
										
										
											2016-03-04 18:35:03 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-10 13:55:59 +10:00
										 |  |  |     # Create a new integration with a requestTemplates config | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.put_method( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='POST', | 
					
						
							|  |  |  |         authorizationType='none', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     templates = { | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         # example based on | 
					
						
							|  |  |  |         # http://docs.aws.amazon.com/apigateway/latest/developerguide/api-as-kinesis-proxy-export-swagger-with-extensions.html | 
					
						
							| 
									
										
										
										
											2016-08-10 13:55:59 +10:00
										 |  |  |         'application/json': "{\n    \"StreamName\": \"$input.params('stream-name')\",\n    \"Records\": []\n}" | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     test_uri = 'http://example.com/foobar.txt' | 
					
						
							|  |  |  |     response = client.put_integration( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='POST', | 
					
						
							|  |  |  |         type='HTTP', | 
					
						
							|  |  |  |         uri=test_uri, | 
					
						
							|  |  |  |         requestTemplates=templates | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-08-10 13:55:59 +10:00
										 |  |  |     response['ResponseMetadata'].should.equal({'HTTPStatusCode': 200}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_integration( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='POST' | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response['uri'].should.equal(test_uri) | 
					
						
							|  |  |  |     response['requestTemplates'].should.equal(templates) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-04 18:35:03 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-05 09:48:37 -05:00
										 |  |  | @mock_apigateway | 
					
						
							|  |  |  | def test_integration_response(): | 
					
						
							|  |  |  |     client = boto3.client('apigateway', region_name='us-west-2') | 
					
						
							|  |  |  |     response = client.create_rest_api( | 
					
						
							|  |  |  |         name='my_api', | 
					
						
							|  |  |  |         description='this is my api', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     api_id = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resources = client.get_resources(restApiId=api_id) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     root_id = [resource for resource in resources[ | 
					
						
							|  |  |  |         'items'] if resource['path'] == '/'][0]['id'] | 
					
						
							| 
									
										
										
										
											2016-03-05 09:48:37 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     client.put_method( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |         authorizationType='none', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.put_method_response( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |         statusCode='200', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.put_integration( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |         type='HTTP', | 
					
						
							|  |  |  |         uri='http://httpbin.org/robots.txt', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.put_integration_response( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |         statusCode='200', | 
					
						
							|  |  |  |         selectionPattern='foobar', | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-03-05 09:48:37 -05:00
										 |  |  |     response.should.equal({ | 
					
						
							|  |  |  |         'statusCode': '200', | 
					
						
							|  |  |  |         'selectionPattern': 'foobar', | 
					
						
							|  |  |  |         'ResponseMetadata': {'HTTPStatusCode': 200}, | 
					
						
							|  |  |  |         'responseTemplates': { | 
					
						
							|  |  |  |             'application/json': None | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_integration_response( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |         statusCode='200', | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-03-05 09:48:37 -05:00
										 |  |  |     response.should.equal({ | 
					
						
							|  |  |  |         'statusCode': '200', | 
					
						
							|  |  |  |         'selectionPattern': 'foobar', | 
					
						
							|  |  |  |         'ResponseMetadata': {'HTTPStatusCode': 200}, | 
					
						
							|  |  |  |         'responseTemplates': { | 
					
						
							|  |  |  |             'application/json': None | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_method( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-03-05 09:48:37 -05:00
										 |  |  |     response['methodIntegration']['integrationResponses'].should.equal({ | 
					
						
							|  |  |  |         '200': { | 
					
						
							|  |  |  |             'responseTemplates': { | 
					
						
							|  |  |  |                 'application/json': None | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             'selectionPattern': 'foobar', | 
					
						
							|  |  |  |             'statusCode': '200' | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.delete_integration_response( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |         statusCode='200', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_method( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response['methodIntegration']['integrationResponses'].should.equal({}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  | @mock_apigateway | 
					
						
							|  |  |  | def test_update_stage_configuration(): | 
					
						
							|  |  |  |     client = boto3.client('apigateway', region_name='us-west-2') | 
					
						
							|  |  |  |     stage_name = 'staging' | 
					
						
							|  |  |  |     response = client.create_rest_api( | 
					
						
							|  |  |  |         name='my_api', | 
					
						
							|  |  |  |         description='this is my api', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     api_id = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.create_deployment( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         stageName=stage_name, | 
					
						
							|  |  |  |         description="1.0.1" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     deployment_id = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_deployment( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         deploymentId=deployment_id, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # createdDate is hard to match against, remove it | 
					
						
							|  |  |  |     response.pop('createdDate', None) | 
					
						
							|  |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |     response.should.equal({ | 
					
						
							|  |  |  |         'id': deployment_id, | 
					
						
							|  |  |  |         'ResponseMetadata': {'HTTPStatusCode': 200}, | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         'description': '1.0.1' | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.create_deployment( | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         stageName=stage_name, | 
					
						
							|  |  |  |         description="1.0.2" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |     deployment_id2 = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     stage = client.get_stage( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         stageName=stage_name | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     stage['stageName'].should.equal(stage_name) | 
					
						
							|  |  |  |     stage['deploymentId'].should.equal(deployment_id2) | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |     stage.shouldnt.have.key('cacheClusterSize') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     client.update_stage(restApiId=api_id, stageName=stage_name, | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |                         patchOperations=[ | 
					
						
							|  |  |  |                             { | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |                                 "op": "replace", | 
					
						
							|  |  |  |                                 "path": "/cacheClusterEnabled", | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |                                 "value": "True" | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                         ]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     stage = client.get_stage( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         stageName=stage_name | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     stage.should.have.key('cacheClusterSize').which.should.equal("0.5") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     client.update_stage(restApiId=api_id, stageName=stage_name, | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |                         patchOperations=[ | 
					
						
							|  |  |  |                             { | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |                                 "op": "replace", | 
					
						
							|  |  |  |                                 "path": "/cacheClusterSize", | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |                                 "value": "1.6" | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                         ]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     stage = client.get_stage( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         stageName=stage_name | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     stage.should.have.key('cacheClusterSize').which.should.equal("1.6") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     client.update_stage(restApiId=api_id, stageName=stage_name, | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |                         patchOperations=[ | 
					
						
							|  |  |  |                             { | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |                                 "op": "replace", | 
					
						
							|  |  |  |                                 "path": "/deploymentId", | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |                                 "value": deployment_id | 
					
						
							|  |  |  |                             }, | 
					
						
							|  |  |  |                             { | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |                                 "op": "replace", | 
					
						
							|  |  |  |                                 "path": "/variables/environment", | 
					
						
							|  |  |  |                                 "value": "dev" | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |                             }, | 
					
						
							|  |  |  |                             { | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |                                 "op": "replace", | 
					
						
							|  |  |  |                                 "path": "/variables/region", | 
					
						
							|  |  |  |                                 "value": "eu-west-1" | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |                             }, | 
					
						
							|  |  |  |                             { | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |                                 "op": "replace", | 
					
						
							|  |  |  |                                 "path": "/*/*/caching/dataEncrypted", | 
					
						
							|  |  |  |                                 "value": "True" | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |                             }, | 
					
						
							|  |  |  |                             { | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |                                 "op": "replace", | 
					
						
							|  |  |  |                                 "path": "/cacheClusterEnabled", | 
					
						
							|  |  |  |                                 "value": "True" | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |                             }, | 
					
						
							|  |  |  |                             { | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |                                 "op": "replace", | 
					
						
							|  |  |  |                                 "path": "/description", | 
					
						
							|  |  |  |                                 "value": "stage description update" | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |                             }, | 
					
						
							|  |  |  |                             { | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |                                 "op": "replace", | 
					
						
							|  |  |  |                                 "path": "/cacheClusterSize", | 
					
						
							|  |  |  |                                 "value": "1.6" | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |                             } | 
					
						
							|  |  |  |                         ]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     client.update_stage(restApiId=api_id, stageName=stage_name, | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |                         patchOperations=[ | 
					
						
							|  |  |  |                             { | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |                                 "op": "remove", | 
					
						
							|  |  |  |                                 "path": "/variables/region", | 
					
						
							|  |  |  |                                 "value": "eu-west-1" | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |                             } | 
					
						
							|  |  |  |                         ]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     stage = client.get_stage(restApiId=api_id, stageName=stage_name) | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     stage['description'].should.match('stage description update') | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |     stage['cacheClusterSize'].should.equal("1.6") | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |     stage['variables']['environment'].should.match('dev') | 
					
						
							|  |  |  |     stage['variables'].should_not.have.key('region') | 
					
						
							|  |  |  |     stage['cacheClusterEnabled'].should.be.true | 
					
						
							|  |  |  |     stage['deploymentId'].should.match(deployment_id) | 
					
						
							|  |  |  |     stage['methodSettings'].should.have.key('*/*') | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     stage['methodSettings'][ | 
					
						
							|  |  |  |         '*/*'].should.have.key('cacheDataEncrypted').which.should.be.true | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     try: | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         client.update_stage(restApiId=api_id, stageName=stage_name, | 
					
						
							|  |  |  |                             patchOperations=[ | 
					
						
							|  |  |  |                                 { | 
					
						
							|  |  |  |                                     "op": "add", | 
					
						
							|  |  |  |                                     "path": "/notasetting", | 
					
						
							|  |  |  |                                     "value": "eu-west-1" | 
					
						
							|  |  |  |                                 } | 
					
						
							|  |  |  |                             ]) | 
					
						
							|  |  |  |         assert False.should.be.ok  # Fail, should not be here | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |     except Exception: | 
					
						
							|  |  |  |         assert True.should.be.ok | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  | @mock_apigateway | 
					
						
							|  |  |  | def test_non_existent_stage(): | 
					
						
							|  |  |  |     client = boto3.client('apigateway', region_name='us-west-2') | 
					
						
							|  |  |  |     response = client.create_rest_api( | 
					
						
							|  |  |  |         name='my_api', | 
					
						
							|  |  |  |         description='this is my api', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     api_id = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     client.get_stage.when.called_with( | 
					
						
							|  |  |  |         restApiId=api_id, stageName='xxx').should.throw(ClientError) | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_apigateway | 
					
						
							|  |  |  | def test_create_stage(): | 
					
						
							|  |  |  |     client = boto3.client('apigateway', region_name='us-west-2') | 
					
						
							|  |  |  |     stage_name = 'staging' | 
					
						
							|  |  |  |     response = client.create_rest_api( | 
					
						
							|  |  |  |         name='my_api', | 
					
						
							|  |  |  |         description='this is my api', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     api_id = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.create_deployment( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         stageName=stage_name, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     deployment_id = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_deployment( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         deploymentId=deployment_id, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # createdDate is hard to match against, remove it | 
					
						
							|  |  |  |     response.pop('createdDate', None) | 
					
						
							|  |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |     response.should.equal({ | 
					
						
							|  |  |  |         'id': deployment_id, | 
					
						
							|  |  |  |         'ResponseMetadata': {'HTTPStatusCode': 200}, | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         'description': '' | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.create_deployment( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         stageName=stage_name, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     deployment_id2 = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_deployments( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response['items'][0].pop('createdDate') | 
					
						
							|  |  |  |     response['items'][1].pop('createdDate') | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     response['items'][0]['id'].should.match( | 
					
						
							|  |  |  |         r"{0}|{1}".format(deployment_id2, deployment_id)) | 
					
						
							|  |  |  |     response['items'][1]['id'].should.match( | 
					
						
							|  |  |  |         r"{0}|{1}".format(deployment_id2, deployment_id)) | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     new_stage_name = 'current' | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     response = client.create_stage( | 
					
						
							|  |  |  |         restApiId=api_id, stageName=new_stage_name, deploymentId=deployment_id2) | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response.should.equal({ | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         'stageName': new_stage_name, | 
					
						
							|  |  |  |         'deploymentId': deployment_id2, | 
					
						
							|  |  |  |         'methodSettings': {}, | 
					
						
							|  |  |  |         'variables': {}, | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |         'ResponseMetadata': {'HTTPStatusCode': 200}, | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         'description': '', | 
					
						
							|  |  |  |         'cacheClusterEnabled': False | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |     stage = client.get_stage( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         stageName=new_stage_name | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     stage['stageName'].should.equal(new_stage_name) | 
					
						
							|  |  |  |     stage['deploymentId'].should.equal(deployment_id2) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |     new_stage_name_with_vars = 'stage_with_vars' | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     response = client.create_stage(restApiId=api_id, stageName=new_stage_name_with_vars, deploymentId=deployment_id2, variables={ | 
					
						
							|  |  |  |         "env": "dev" | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response.should.equal({ | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         'stageName': new_stage_name_with_vars, | 
					
						
							|  |  |  |         'deploymentId': deployment_id2, | 
					
						
							|  |  |  |         'methodSettings': {}, | 
					
						
							|  |  |  |         'variables': {"env": "dev"}, | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |         'ResponseMetadata': {'HTTPStatusCode': 200}, | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         'description': '', | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |         'cacheClusterEnabled': False | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     stage = client.get_stage( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |         stageName=new_stage_name_with_vars | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |     stage['stageName'].should.equal(new_stage_name_with_vars) | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |     stage['deploymentId'].should.equal(deployment_id2) | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |     stage['variables'].should.have.key('env').which.should.match("dev") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     new_stage_name = 'stage_with_vars_and_cache_settings' | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     response = client.create_stage(restApiId=api_id, stageName=new_stage_name, deploymentId=deployment_id2, variables={ | 
					
						
							|  |  |  |         "env": "dev" | 
					
						
							|  |  |  |     }, cacheClusterEnabled=True, description="hello moto") | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response.should.equal({ | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         'stageName': new_stage_name, | 
					
						
							|  |  |  |         'deploymentId': deployment_id2, | 
					
						
							|  |  |  |         'methodSettings': {}, | 
					
						
							|  |  |  |         'variables': {"env": "dev"}, | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |         'ResponseMetadata': {'HTTPStatusCode': 200}, | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         'description': 'hello moto', | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |         'cacheClusterEnabled': True, | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         'cacheClusterSize': "0.5" | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     stage = client.get_stage( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |         stageName=new_stage_name | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     stage['cacheClusterSize'].should.equal("0.5") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     new_stage_name = 'stage_with_vars_and_cache_settings_and_size' | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     response = client.create_stage(restApiId=api_id, stageName=new_stage_name, deploymentId=deployment_id2, variables={ | 
					
						
							|  |  |  |         "env": "dev" | 
					
						
							|  |  |  |     }, cacheClusterEnabled=True, cacheClusterSize="1.6", description="hello moto") | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response.should.equal({ | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         'stageName': new_stage_name, | 
					
						
							|  |  |  |         'deploymentId': deployment_id2, | 
					
						
							|  |  |  |         'methodSettings': {}, | 
					
						
							|  |  |  |         'variables': {"env": "dev"}, | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |         'ResponseMetadata': {'HTTPStatusCode': 200}, | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         'description': 'hello moto', | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |         'cacheClusterEnabled': True, | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         'cacheClusterSize': "1.6" | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     stage = client.get_stage( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         stageName=new_stage_name | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     stage['stageName'].should.equal(new_stage_name) | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |     stage['deploymentId'].should.equal(deployment_id2) | 
					
						
							|  |  |  |     stage['variables'].should.have.key('env').which.should.match("dev") | 
					
						
							| 
									
										
										
										
											2016-09-14 10:04:51 +01:00
										 |  |  |     stage['cacheClusterSize'].should.equal("1.6") | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-04 18:35:03 -05:00
										 |  |  | @mock_apigateway | 
					
						
							|  |  |  | def test_deployment(): | 
					
						
							|  |  |  |     client = boto3.client('apigateway', region_name='us-west-2') | 
					
						
							| 
									
										
										
										
											2016-08-11 16:14:13 +10:00
										 |  |  |     stage_name = 'staging' | 
					
						
							| 
									
										
										
										
											2016-03-04 18:35:03 -05:00
										 |  |  |     response = client.create_rest_api( | 
					
						
							|  |  |  |         name='my_api', | 
					
						
							|  |  |  |         description='this is my api', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     api_id = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.create_deployment( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							| 
									
										
										
										
											2016-08-11 16:14:13 +10:00
										 |  |  |         stageName=stage_name, | 
					
						
							| 
									
										
										
										
											2016-03-04 18:35:03 -05:00
										 |  |  |     ) | 
					
						
							|  |  |  |     deployment_id = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_deployment( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         deploymentId=deployment_id, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # createdDate is hard to match against, remove it | 
					
						
							|  |  |  |     response.pop('createdDate', None) | 
					
						
							|  |  |  |     # this is hard to match against, so remove it | 
					
						
							|  |  |  |     response['ResponseMetadata'].pop('HTTPHeaders', None) | 
					
						
							| 
									
										
										
										
											2016-10-16 21:50:21 -07:00
										 |  |  |     response['ResponseMetadata'].pop('RetryAttempts', None) | 
					
						
							| 
									
										
										
										
											2016-03-04 18:35:03 -05:00
										 |  |  |     response.should.equal({ | 
					
						
							|  |  |  |         'id': deployment_id, | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |         'ResponseMetadata': {'HTTPStatusCode': 200}, | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         'description': '' | 
					
						
							| 
									
										
										
										
											2016-03-04 18:35:03 -05:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_deployments( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response['items'][0].pop('createdDate') | 
					
						
							| 
									
										
										
										
											2016-03-04 18:35:03 -05:00
										 |  |  |     response['items'].should.equal([ | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |         {'id': deployment_id, 'description': ''} | 
					
						
							| 
									
										
										
										
											2016-03-04 18:35:03 -05:00
										 |  |  |     ]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.delete_deployment( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         deploymentId=deployment_id, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_deployments( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     len(response['items']).should.equal(0) | 
					
						
							| 
									
										
										
										
											2016-03-05 10:54:19 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-11 16:14:13 +10:00
										 |  |  |     # test deployment stages | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     stage = client.get_stage( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         stageName=stage_name | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     stage['stageName'].should.equal(stage_name) | 
					
						
							|  |  |  |     stage['deploymentId'].should.equal(deployment_id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     stage = client.update_stage( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         stageName=stage_name, | 
					
						
							|  |  |  |         patchOperations=[ | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 'op': 'replace', | 
					
						
							| 
									
										
										
										
											2016-09-13 12:44:17 +01:00
										 |  |  |                 'path': '/description', | 
					
						
							| 
									
										
										
										
											2016-08-11 16:14:13 +10:00
										 |  |  |                 'value': '_new_description_' | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     stage = client.get_stage( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         stageName=stage_name | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     stage['stageName'].should.equal(stage_name) | 
					
						
							|  |  |  |     stage['deploymentId'].should.equal(deployment_id) | 
					
						
							|  |  |  |     stage['description'].should.equal('_new_description_') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-05 10:54:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_apigateway | 
					
						
							|  |  |  | def test_http_proxying_integration(): | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  |     responses.add( | 
					
						
							|  |  |  |         responses.GET, "http://httpbin.org/robots.txt", body='a fake response' | 
					
						
							| 
									
										
										
										
											2016-03-05 10:54:19 -05:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     region_name = 'us-west-2' | 
					
						
							|  |  |  |     client = boto3.client('apigateway', region_name=region_name) | 
					
						
							|  |  |  |     response = client.create_rest_api( | 
					
						
							|  |  |  |         name='my_api', | 
					
						
							|  |  |  |         description='this is my api', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     api_id = response['id'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resources = client.get_resources(restApiId=api_id) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     root_id = [resource for resource in resources[ | 
					
						
							|  |  |  |         'items'] if resource['path'] == '/'][0]['id'] | 
					
						
							| 
									
										
										
										
											2016-03-05 10:54:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     client.put_method( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |         authorizationType='none', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.put_method_response( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |         statusCode='200', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.put_integration( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         resourceId=root_id, | 
					
						
							|  |  |  |         httpMethod='GET', | 
					
						
							|  |  |  |         type='HTTP', | 
					
						
							|  |  |  |         uri='http://httpbin.org/robots.txt', | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     stage_name = 'staging' | 
					
						
							|  |  |  |     client.create_deployment( | 
					
						
							|  |  |  |         restApiId=api_id, | 
					
						
							|  |  |  |         stageName=stage_name, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     deploy_url = "https://{api_id}.execute-api.{region_name}.amazonaws.com/{stage_name}".format( | 
					
						
							|  |  |  |         api_id=api_id, region_name=region_name, stage_name=stage_name) | 
					
						
							| 
									
										
										
										
											2016-03-05 10:54:19 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  |     if not settings.TEST_SERVER_MODE: | 
					
						
							|  |  |  |         requests.get(deploy_url).content.should.equal(b"a fake response") | 
					
						
							| 
									
										
										
										
											2018-03-21 17:11:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_apigateway | 
					
						
							|  |  |  | def test_api_keys(): | 
					
						
							|  |  |  |     region_name = 'us-west-2' | 
					
						
							|  |  |  |     client = boto3.client('apigateway', region_name=region_name) | 
					
						
							|  |  |  |     response = client.get_api_keys() | 
					
						
							|  |  |  |     len(response['items']).should.equal(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     apikey_value = '12345' | 
					
						
							|  |  |  |     apikey_name = 'TESTKEY1' | 
					
						
							|  |  |  |     payload = {'value': apikey_value, 'name': apikey_name} | 
					
						
							|  |  |  |     response = client.create_api_key(**payload) | 
					
						
							| 
									
										
										
										
											2018-03-30 15:09:02 +02:00
										 |  |  |     apikey = client.get_api_key(apiKey=response['id']) | 
					
						
							| 
									
										
										
										
											2018-03-21 17:11:49 +01:00
										 |  |  |     apikey['name'].should.equal(apikey_name) | 
					
						
							|  |  |  |     apikey['value'].should.equal(apikey_value) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     apikey_name = 'TESTKEY2' | 
					
						
							| 
									
										
										
										
											2018-07-13 12:53:00 +01:00
										 |  |  |     payload = {'name': apikey_name } | 
					
						
							| 
									
										
										
										
											2018-03-21 17:11:49 +01:00
										 |  |  |     response = client.create_api_key(**payload) | 
					
						
							| 
									
										
										
										
											2018-03-30 15:09:02 +02:00
										 |  |  |     apikey_id = response['id'] | 
					
						
							|  |  |  |     apikey = client.get_api_key(apiKey=apikey_id) | 
					
						
							| 
									
										
										
										
											2018-03-21 17:11:49 +01:00
										 |  |  |     apikey['name'].should.equal(apikey_name) | 
					
						
							|  |  |  |     len(apikey['value']).should.equal(40) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_api_keys() | 
					
						
							|  |  |  |     len(response['items']).should.equal(2) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-30 15:09:02 +02:00
										 |  |  |     client.delete_api_key(apiKey=apikey_id) | 
					
						
							| 
									
										
										
										
											2018-03-21 17:11:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_api_keys() | 
					
						
							|  |  |  |     len(response['items']).should.equal(1) | 
					
						
							| 
									
										
										
										
											2018-07-10 14:58:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_apigateway | 
					
						
							|  |  |  | def test_usage_plans(): | 
					
						
							|  |  |  |     region_name = 'us-west-2' | 
					
						
							|  |  |  |     client = boto3.client('apigateway', region_name=region_name) | 
					
						
							|  |  |  |     response = client.get_usage_plans() | 
					
						
							|  |  |  |     len(response['items']).should.equal(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     usage_plan_name = 'TEST-PLAN' | 
					
						
							|  |  |  |     payload = {'name': usage_plan_name} | 
					
						
							|  |  |  |     response = client.create_usage_plan(**payload) | 
					
						
							|  |  |  |     usage_plan = client.get_usage_plan(usagePlanId=response['id']) | 
					
						
							|  |  |  |     usage_plan['name'].should.equal(usage_plan_name) | 
					
						
							|  |  |  |     usage_plan['apiStages'].should.equal([]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     usage_plan_name = 'TEST-PLAN-2' | 
					
						
							|  |  |  |     usage_plan_description = 'Description' | 
					
						
							|  |  |  |     usage_plan_quota = {'limit': 10, 'period': 'DAY', 'offset': 0} | 
					
						
							|  |  |  |     usage_plan_throttle = {'rateLimit': 2, 'burstLimit': 1} | 
					
						
							|  |  |  |     usage_plan_api_stages = [{'apiId': 'foo', 'stage': 'bar'}] | 
					
						
							|  |  |  |     payload = {'name': usage_plan_name, 'description': usage_plan_description, 'quota': usage_plan_quota, 'throttle': usage_plan_throttle, 'apiStages': usage_plan_api_stages} | 
					
						
							|  |  |  |     response = client.create_usage_plan(**payload) | 
					
						
							|  |  |  |     usage_plan_id = response['id'] | 
					
						
							|  |  |  |     usage_plan = client.get_usage_plan(usagePlanId=usage_plan_id) | 
					
						
							|  |  |  |     usage_plan['name'].should.equal(usage_plan_name) | 
					
						
							|  |  |  |     usage_plan['description'].should.equal(usage_plan_description) | 
					
						
							|  |  |  |     usage_plan['apiStages'].should.equal(usage_plan_api_stages) | 
					
						
							|  |  |  |     usage_plan['throttle'].should.equal(usage_plan_throttle) | 
					
						
							|  |  |  |     usage_plan['quota'].should.equal(usage_plan_quota) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_usage_plans() | 
					
						
							|  |  |  |     len(response['items']).should.equal(2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.delete_usage_plan(usagePlanId=usage_plan_id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_usage_plans() | 
					
						
							|  |  |  |     len(response['items']).should.equal(1) | 
					
						
							| 
									
										
										
										
											2018-07-11 17:17:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_apigateway | 
					
						
							|  |  |  | def test_usage_plan_keys(): | 
					
						
							|  |  |  |     region_name = 'us-west-2' | 
					
						
							|  |  |  |     usage_plan_id = 'test_usage_plan_id' | 
					
						
							|  |  |  |     client = boto3.client('apigateway', region_name=region_name) | 
					
						
							|  |  |  |     usage_plan_id = "test" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create an API key so we can use it | 
					
						
							|  |  |  |     key_name = 'test-api-key' | 
					
						
							|  |  |  |     response = client.create_api_key(name=key_name) | 
					
						
							|  |  |  |     key_id = response["id"] | 
					
						
							|  |  |  |     key_value = response["value"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Get current plan keys (expect none) | 
					
						
							|  |  |  |     response = client.get_usage_plan_keys(usagePlanId=usage_plan_id) | 
					
						
							|  |  |  |     len(response['items']).should.equal(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create usage plan key | 
					
						
							|  |  |  |     key_type = 'API_KEY' | 
					
						
							|  |  |  |     payload = {'usagePlanId': usage_plan_id, 'keyId': key_id, 'keyType': key_type } | 
					
						
							|  |  |  |     response = client.create_usage_plan_key(**payload) | 
					
						
							|  |  |  |     usage_plan_key_id = response["id"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Get current plan keys (expect 1) | 
					
						
							|  |  |  |     response = client.get_usage_plan_keys(usagePlanId=usage_plan_id) | 
					
						
							|  |  |  |     len(response['items']).should.equal(1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Get a single usage plan key and check it matches the created one | 
					
						
							|  |  |  |     usage_plan_key = client.get_usage_plan_key(usagePlanId=usage_plan_id, keyId=usage_plan_key_id) | 
					
						
							|  |  |  |     usage_plan_key['name'].should.equal(key_name) | 
					
						
							|  |  |  |     usage_plan_key['id'].should.equal(key_id) | 
					
						
							|  |  |  |     usage_plan_key['type'].should.equal(key_type) | 
					
						
							|  |  |  |     usage_plan_key['value'].should.equal(key_value) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Delete usage plan key | 
					
						
							|  |  |  |     client.delete_usage_plan_key(usagePlanId=usage_plan_id, keyId=key_id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Get current plan keys (expect none) | 
					
						
							|  |  |  |     response = client.get_usage_plan_keys(usagePlanId=usage_plan_id) | 
					
						
							|  |  |  |     len(response['items']).should.equal(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_apigateway | 
					
						
							|  |  |  | def test_create_usage_plan_key_non_existent_api_key(): | 
					
						
							|  |  |  |     region_name = 'us-west-2' | 
					
						
							|  |  |  |     usage_plan_id = 'test_usage_plan_id' | 
					
						
							|  |  |  |     client = boto3.client('apigateway', region_name=region_name) | 
					
						
							|  |  |  |     usage_plan_id = "test" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Attempt to create a usage plan key for a API key that doesn't exists | 
					
						
							|  |  |  |     payload = {'usagePlanId': usage_plan_id, 'keyId': 'non-existent', 'keyType': 'API_KEY' } | 
					
						
							|  |  |  |     client.create_usage_plan_key.when.called_with(**payload).should.throw(ClientError) |