From bcf61d0b09d9c082efed1fbfe2863d96b922c950 Mon Sep 17 00:00:00 2001 From: usmangani1 Date: Tue, 1 Sep 2020 12:55:59 +0530 Subject: [PATCH] Fix: Api-Gateway ApiKeyAlreadyExists headers change. (#3162) * Fix: Api-Gateway ApiKeyAlreadyExists headers change. * Added test for non decorator * Fixed cli errors * Fix:fixed build errors * Fix: assert only in case of non server mode Co-authored-by: usmankb --- moto/apigateway/responses.py | 2 +- tests/test_apigateway/test_apigateway.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/moto/apigateway/responses.py b/moto/apigateway/responses.py index d8f3ed505..0454ae58e 100644 --- a/moto/apigateway/responses.py +++ b/moto/apigateway/responses.py @@ -449,7 +449,7 @@ class APIGatewayResponse(BaseResponse): except ApiKeyAlreadyExists as error: return ( error.code, - self.headers, + {}, '{{"message":"{0}","code":"{1}"}}'.format( error.message, error.error_type ), diff --git a/tests/test_apigateway/test_apigateway.py b/tests/test_apigateway/test_apigateway.py index d79851ab0..c58d644fa 100644 --- a/tests/test_apigateway/test_apigateway.py +++ b/tests/test_apigateway/test_apigateway.py @@ -1858,6 +1858,23 @@ def test_create_api_key(): client.create_api_key.when.called_with(**payload).should.throw(ClientError) +@mock_apigateway +def test_create_api_headers(): + region_name = "us-west-2" + client = boto3.client("apigateway", region_name=region_name) + + apikey_value = "12345" + apikey_name = "TESTKEY1" + payload = {"value": apikey_value, "name": apikey_name} + + client.create_api_key(**payload) + with assert_raises(ClientError) as ex: + client.create_api_key(**payload) + ex.exception.response["Error"]["Code"].should.equal("ConflictException") + if not settings.TEST_SERVER_MODE: + ex.exception.response["ResponseMetadata"]["HTTPHeaders"].should.equal({}) + + @mock_apigateway def test_api_keys(): region_name = "us-west-2"