Skip to content

Commit

Permalink
fix(event-handler): return dict on missing multi_value_headers (#3824)
Browse files Browse the repository at this point in the history
* fix(parameters): make cache aware of single vs multiple calls

Signed-off-by: heitorlessa <[email protected]>

* chore: cleanup, add test for single and nested

Signed-off-by: heitorlessa <[email protected]>

* fix(event-handler): return dict on missing multi_value_headers

Signed-off-by: heitorlessa <[email protected]>

* chore: default dict for multi query strings too

Signed-off-by: heitorlessa <[email protected]>

* revert: path_parameters and stage_variables unrelated to the issue

---------

Signed-off-by: heitorlessa <[email protected]>
  • Loading branch information
heitorlessa authored Feb 21, 2024
1 parent 812ab3f commit b89f9ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ def resource(self) -> str:

@property
def multi_value_headers(self) -> Dict[str, List[str]]:
return self["multiValueHeaders"]
return self.get("multiValueHeaders") or {}

@property
def multi_value_query_string_parameters(self) -> Optional[Dict[str, List[str]]]:
return self.get("multiValueQueryStringParameters")
def multi_value_query_string_parameters(self) -> Dict[str, List[str]]:
return self.get("multiValueQueryStringParameters") or {}

@property
def resolved_query_string_parameters(self) -> Dict[str, List[str]]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1108,3 +1108,23 @@ def my_path(
# THEN the handler should be invoked and return 200
result = app(gw_event_http, {})
assert result["statusCode"] == 200


def test_validate_with_minimal_event():
# GIVEN an APIGatewayRestResolver with validation enabled
app = APIGatewayRestResolver(enable_validation=True)

# WHEN a handler is defined with a default scalar parameter
@app.get("/users/<user_id>")
def handler(user_id: int = 123):
print(user_id)

minimal_event = {
"path": "/users/123",
"httpMethod": "GET",
"requestContext": {"requestId": "227b78aa-779d-47d4-a48e-ce62120393b8"}, # correlation ID
}

# THEN the handler should be invoked and return 200
result = app(minimal_event, {})
assert result["statusCode"] == 200

0 comments on commit b89f9ad

Please sign in to comment.