-
Notifications
You must be signed in to change notification settings - Fork 403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(test): make CORS test consistent with expected behavior #4882
Changes from 2 commits
946a620
1f5d2c9
0ba6cbf
d6386b8
ac74e4d
792779c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -331,7 +331,7 @@ def test_cors(): | |
def with_cors() -> Response: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we can remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I will check and test some other places to. |
||
return Response(200, content_types.TEXT_HTML, "test") | ||
|
||
@app.get("/without-cors") | ||
@app.get("/without-cors", cors=False) | ||
def without_cors() -> Response: | ||
return Response(200, content_types.TEXT_HTML, "test") | ||
|
||
|
@@ -350,17 +350,17 @@ def handler(event, context): | |
assert headers["Access-Control-Allow-Headers"] == [",".join(sorted(CORSConfig._REQUIRED_HEADERS))] | ||
|
||
# THEN for routes without cors flag return no cors headers | ||
mock_event = {"path": "/my/request", "httpMethod": "GET"} | ||
mock_event = {"path": "/without-cors", "httpMethod": "GET"} | ||
result = handler(mock_event, None) | ||
assert "Access-Control-Allow-Origin" not in result["multiValueHeaders"] | ||
|
||
|
||
def test_cors_no_request_origin(): | ||
# GIVEN a function with cors=True | ||
# GIVEN a function | ||
# AND http method set to GET | ||
app = ApiGatewayResolver() | ||
app = ApiGatewayResolver(cors=CORSConfig()) | ||
|
||
@app.get("/my/path", cors=True) | ||
@app.get("/my/path") | ||
def with_cors() -> Response: | ||
return Response(200, content_types.TEXT_HTML, "test") | ||
|
||
|
@@ -381,7 +381,7 @@ def handler(event, context): | |
|
||
|
||
def test_cors_allow_all_request_origins(): | ||
# GIVEN a function with cors=True | ||
# GIVEN a function | ||
# AND http method set to GET | ||
app = ApiGatewayResolver( | ||
cors=CORSConfig( | ||
|
@@ -390,11 +390,11 @@ def test_cors_allow_all_request_origins(): | |
), | ||
) | ||
|
||
@app.get("/my/path", cors=True) | ||
@app.get("/my/path") | ||
def with_cors() -> Response: | ||
return Response(200, content_types.TEXT_HTML, "test") | ||
|
||
@app.get("/without-cors") | ||
@app.get("/without-cors", cors=False) | ||
def without_cors() -> Response: | ||
return Response(200, content_types.TEXT_HTML, "test") | ||
|
||
|
@@ -413,7 +413,7 @@ def handler(event, context): | |
assert headers["Access-Control-Allow-Headers"] == [",".join(sorted(CORSConfig._REQUIRED_HEADERS))] | ||
|
||
# THEN for routes without cors flag return no cors headers | ||
mock_event = {"path": "/my/request", "httpMethod": "GET"} | ||
mock_event = {"path": "/without-cors", "httpMethod": "GET"} | ||
result = handler(mock_event, None) | ||
assert "Access-Control-Allow-Origin" not in result["multiValueHeaders"] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
low hanging fruit to test the UserWarnings and reduce noise in the pytest output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great attention to details @Wurstnase! Thank you so much!! ❤️