def test_apig_methods(stubbed_session): gateway_stub = stubbed_session.stub('apigateway') gateway_stub.put_method( authorizationType='NONE', httpMethod='GET', resourceId='resource_id', restApiId='rest_api_id', requestParameters={'method.request.path.name': True}, ).returns({}) apig = APIGatewayMethods( stubbed_session.create_client('apigateway'), 'rest_api_id') stubbed_session.activate_stubs() apig.create_method_request('resource_id', 'GET', url_params=['name']) stubbed_session.verify_stubs()
def test_apig_methods(stubbed_session): gateway_stub = stubbed_session.stub('apigateway') gateway_stub.put_method( authorizationType='NONE', httpMethod='GET', resourceId='resource_id', restApiId='rest_api_id', requestParameters={ 'method.request.path.name': True }, ).returns({}) apig = APIGatewayMethods(stubbed_session.create_client('apigateway'), 'rest_api_id') stubbed_session.activate_stubs() apig.create_method_request('resource_id', 'GET', url_params=['name']) stubbed_session.verify_stubs()
def test_cors_adds_required_headers(stubbed_session): cors_route_entry = RouteEntry(None, 'index_view', '/', ['PUT'], cors=True, content_types=['application/json']) route_trie = { 'name': '', 'uri_path': '/', 'children': {}, 'resource_id': 'parent-id', 'parent_resource_id': None, 'is_route': True, 'route_entry': cors_route_entry, } gateway_client = stubbed_session.create_client('apigateway') gateway_stub = stubbed_session.stub('apigateway') lambda_stub = stubbed_session.stub('lambda') awsclient = TypedAWSClient(stubbed_session) g = APIGatewayResourceCreator(awsclient, APIGatewayMethods(gateway_client, 'rest-api-id'), 'arn:aws:lambda:us-west-2:123:function:name', random_id_generator=lambda: "random-id") gateway_stub.put_method( resourceId='parent-id', authorizationType='NONE', restApiId='rest-api-id', httpMethod='PUT', ).returns({}) gateway_stub.put_integration( httpMethod='PUT', integrationHttpMethod='POST', passthroughBehavior='WHEN_NO_MATCH', resourceId='parent-id', restApiId='rest-api-id', contentHandling='CONVERT_TO_TEXT', type='AWS_PROXY', uri=('arn:aws:apigateway:us-west-2:lambda:path' '/2015-03-31/functions/arn:aws:lambda:us-west' '-2:123:function:name/invocations')).returns({}) gateway_stub.put_method_response( httpMethod='PUT', resourceId='parent-id', responseModels={ 'application/json': 'Empty', }, restApiId='rest-api-id', statusCode='200', ).returns({}) gateway_stub.put_integration_response( httpMethod='PUT', resourceId='parent-id', responseTemplates={ 'application/json': '', }, restApiId='rest-api-id', statusCode='200', ).returns({}) gateway_stub.put_method( restApiId=ANY, resourceId=ANY, httpMethod='OPTIONS', authorizationType='NONE', ).returns({}) gateway_stub.put_integration(restApiId=ANY, resourceId=ANY, httpMethod='OPTIONS', type='MOCK', requestTemplates={ 'application/json': '{"statusCode": 200}' }).returns({}) gateway_stub.put_method_response( restApiId=ANY, resourceId=ANY, httpMethod='OPTIONS', statusCode='200', responseModels=ANY, responseParameters={ 'method.response.header.Access-Control-Allow-Origin': False, 'method.response.header.Access-Control-Allow-Methods': False, 'method.response.header.Access-Control-Allow-Headers': False, }).returns({}) gateway_stub.put_integration_response( restApiId=ANY, resourceId=ANY, httpMethod='OPTIONS', statusCode='200', responseTemplates=ANY, responseParameters={ 'method.response.header.Access-Control-Allow-Origin': "'*'", 'method.response.header.Access-Control-Allow-Methods': ("'PUT,OPTIONS'"), 'method.response.header.Access-Control-Allow-Headers': ("'Content-Type,X-Amz-Date,Authorization,X-Api-Key" ",X-Amz-Security-Token'"), }).returns({}) lambda_stub.get_policy(FunctionName='name').returns({'Policy': '{}'}) lambda_stub.add_permission( Action='lambda:InvokeFunction', FunctionName='name', Principal='apigateway.amazonaws.com', SourceArn='arn:aws:execute-api:us-west-2:123:rest-api-id/*', StatementId='random-id', ).returns({}) stubbed_session.activate_stubs() g.build_resources(route_trie) stubbed_session.verify_stubs()
def test_can_build_resource_routes_for_single_view(stubbed_session): route_trie = { 'name': '', 'uri_path': '/', 'children': {}, 'resource_id': 'parent-id', 'parent_resource_id': None, 'is_route': True, 'route_entry': RouteEntry(None, 'index_view', '/', ['POST'], content_types=['application/json']), } gateway_client = stubbed_session.create_client('apigateway') gateway_stub = stubbed_session.stub('apigateway') lambda_stub = stubbed_session.stub('lambda') awsclient = TypedAWSClient(stubbed_session) g = APIGatewayResourceCreator(awsclient, APIGatewayMethods(gateway_client, 'rest-api-id'), 'arn:aws:lambda:us-west-2:123:function:name', random_id_generator=lambda: "random-id") gateway_stub.put_method( resourceId='parent-id', authorizationType='NONE', restApiId='rest-api-id', httpMethod='POST', ).returns({}) gateway_stub.put_integration( httpMethod='POST', integrationHttpMethod='POST', passthroughBehavior='WHEN_NO_MATCH', resourceId='parent-id', restApiId='rest-api-id', type='AWS_PROXY', contentHandling='CONVERT_TO_TEXT', uri=('arn:aws:apigateway:us-west-2:lambda:path' '/2015-03-31/functions/arn:aws:lambda:us-west' '-2:123:function:name/invocations')).returns({}) gateway_stub.put_method_response( httpMethod='POST', resourceId='parent-id', responseModels={ 'application/json': 'Empty', }, restApiId='rest-api-id', statusCode='200', ).returns({}) gateway_stub.put_integration_response( httpMethod='POST', resourceId='parent-id', responseTemplates={ 'application/json': '', }, restApiId='rest-api-id', statusCode='200', ).returns({}) lambda_stub.get_policy(FunctionName='name').returns({'Policy': '{}'}) lambda_stub.add_permission( Action='lambda:InvokeFunction', FunctionName='name', Principal='apigateway.amazonaws.com', SourceArn='arn:aws:execute-api:us-west-2:123:rest-api-id/*', StatementId='random-id', ).returns({}) stubbed_session.activate_stubs() g.build_resources(route_trie) stubbed_session.verify_stubs()