Skip to content

Commit ec99118

Browse files
author
Joakim Nordling
committed
Revert "Improve tests by also adding a header"
This reverts commit df530a4. If you would call that route, you would get extra arguments that the function can not handle. I.e. if you use the approach of changing the signature, you should rather just remove optional parameters than trying to add more.
1 parent df530a4 commit ec99118

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

openapi_to_fastapi/tests/test_router.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -609,21 +609,13 @@ def handler_1(request, x_my_header: Optional[str] = Header(None)):
609609
def handler_2(request, x_my_header: Optional[str] = Header(None)):
610610
return {}
611611

612-
# Remove the header from handler_2 and add another header instead
612+
# Remove the header from handler_2
613613
sig = inspect.signature(handler_2)
614614
params = sig.parameters
615-
modified_params = [
615+
filtered_params = [
616616
param for param_name, param in params.items() if param_name != "x_my_header"
617617
]
618-
modified_params.append(
619-
inspect.Parameter(
620-
"x_other_header",
621-
kind=inspect.Parameter.KEYWORD_ONLY,
622-
annotation=Optional[str],
623-
default=Header(None),
624-
)
625-
)
626-
handler_2.__signature__ = sig.replace(parameters=modified_params)
618+
handler_2.__signature__ = sig.replace(parameters=filtered_params)
627619

628620
# Add handlers to router (non-decorator syntax)
629621
spec_router.post("/TestValidation_v0.1")(handler_1)
@@ -642,5 +634,5 @@ def handler_2(request, x_my_header: Optional[str] = Header(None)):
642634
headers_1 = {p.get("name") for p in parameters_1 if p.get("in") == "header"}
643635
headers_2 = {p.get("name") for p in parameters_2 if p.get("in") == "header"}
644636

645-
assert headers_1 == {"x-my-header"}
646-
assert headers_2 == {"x-other-header"}
637+
assert "x-my-header" in headers_1
638+
assert "x-my-header" not in headers_2

0 commit comments

Comments
 (0)