create methods

This commit is contained in:
Steve Pulec 2016-03-01 18:50:06 -05:00
commit a737fbed48
5 changed files with 315 additions and 5 deletions

View file

@ -56,3 +56,134 @@ def test_list_and_delete_apis():
response = client.get_rest_apis()
len(response['items']).should.equal(1)
@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)
root_id = [resource for resource in resources['items'] if resource['path'] == '/'][0]['id']
root_resource = client.get_resource(
restApiId=api_id,
resourceId=root_id,
)
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)
non_root_resource = [resource for resource in resources if resource['path'] != '/'][0]
response = client.delete_resource(
restApiId=api_id,
resourceId=non_root_resource['id']
)
len(client.get_resources(restApiId=api_id)['items']).should.equal(1)
@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)
root_id = [resource for resource in resources['items'] if resource['path'] == '/'][0]['id']
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.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)
root_id = [resource for resource in resources['items'] if resource['path'] == '/'][0]['id']
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',
)
response.should.equal({
'ResponseMetadata': {'HTTPStatusCode': 200},
'statusCode': '200'
})
response = client.get_method_response(
restApiId=api_id,
resourceId=root_id,
httpMethod='GET',
statusCode='200',
)
response.should.equal({
'ResponseMetadata': {'HTTPStatusCode': 200},
'statusCode': '200'
})
response = client.delete_method_response(
restApiId=api_id,
resourceId=root_id,
httpMethod='GET',
statusCode='200',
)
response.should.equal({'ResponseMetadata': {'HTTPStatusCode': 200}})