8000 fix isCanaryRequest optionality + unit tests · localstack/localstack@4010c7c · GitHub
[go: up one dir, main page]

Skip to content

Commit 4010c7c

Browse files
committed
fix isCanaryRequest optionality + unit tests
1 parent 9e25ea5 commit 4010c7c

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

localstack-core/localstack/services/apigateway/next_gen/execute_api/context.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class RestApiInvocationContext(RequestContext):
9898
"""The Stage variables, also used in parameters mapping and mapping templates"""
9999
stage_configuration: Optional[Stage]
100100
"""The Stage configuration, containing canary deployment settings"""
101-
is_canary: bool = False
101+
is_canary: Optional[bool]
102102
"""If the current call was directed to a canary deployment"""
103103
context_variables: Optional[ContextVariables]
104104
"""The $context used in data models, authorizers, mapping templates, and CloudWatch access logging"""
@@ -131,6 +131,7 @@ def __init__(self, request: Request):
131131
self.integration = None
132132
self.stage_variables = None
133133
self.stage_configuration = None
134+
self.is_canary = None
134135
self.context_variables = None
135136
self.logging_context_variables = None
136137
self.integration_request = None

localstack-core/localstack/services/apigateway/next_gen/execute_api/handlers/parse.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,10 @@ def create_context_variables(context: RestApiInvocationContext) -> ContextVariab
171171
requestTime=timestamp(time=now, format=REQUEST_TIME_DATE_FORMAT),
172172
requestTimeEpoch=int(now.timestamp() * 1000),
173173
stage=context.stage,
174-
isCanaryRequest=context.is_canary,
175174
)
175+
if context.is_canary is not None:
176+
context_variables["isCanaryRequest"] = context.is_canary
177+
176178
return context_variables
177179

178180
@staticmethod

localstack-core/localstack/services/apigateway/next_gen/execute_api/router.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ def populate_rest_api_invocation_context(
102102
deployment_id = canary_settings["deploymentId"]
103103
frozen_deployment = self._global_store.internal_deployments[api_id][deployment_id]
104104
context.is_canary = True
105+
else:
106+
context.is_canary = False
105107

106108
context.deployment = frozen_deployment
107109
context.api_id = api_id

tests/unit/services/apigateway/test_handler_request.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
freeze_rest_api,
2121
parse_trace_id,
2222
)
23+
from localstack.services.apigateway.next_gen.execute_api.moto_helpers import get_stage_configuration
2324
from localstack.testing.config import TEST_AWS_ACCOUNT_ID, TEST_AWS_REGION_NAME
2425

2526
TEST_API_ID = "testapi"
@@ -64,6 +65,12 @@ def _create_context(request: Request) -> RestApiInvocationContext:
6465
context.stage = TEST_API_STAGE
6566
context.account_id = TEST_AWS_ACCOUNT_ID
6667
context.region = TEST_AWS_REGION_NAME
68+
context.stage_configuration = get_stage_configuration(
69+
account_id=TEST_AWS_ACCOUNT_ID,
70+
region=TEST_AWS_REGION_NAME,
71+
api_id=TEST_API_ID,
72+
stage_name=TEST_API_STAGE,
73+
)
6774
return context
6875

6976
return _create_context
@@ -72,7 +79,9 @@ def _create_context(request: Request) -> RestApiInvocationContext:
7279
@pytest.fixture
7380
def parse_handler_chain() -> RestApiGatewayHandlerChain:
7481
"""Returns a dummy chain for testing."""
75-
return RestApiGatewayHandlerChain(request_handlers=[InvocationRequestParser()])
82+
chain = RestApiGatewayHandlerChain(request_handlers=[InvocationRequestParser()])
83+
chain.raise_on_error = True
84+
return chain
7685

7786

7887
class TestParsingHandler:

0 commit comments

Comments
 (0)
0