From a46a84fa059b63229596ae037458d95a4645a45c Mon Sep 17 00:00:00 2001 From: ksauder Date: Sun, 18 Aug 2024 11:47:38 -0400 Subject: [PATCH] moved statements to a new test and added override checks --- tests/test_response_params.py | 43 ++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/tests/test_response_params.py b/tests/test_response_params.py index 08a4b254..7196c655 100644 --- a/tests/test_response_params.py +++ b/tests/test_response_params.py @@ -37,11 +37,18 @@ def op_exclude_none(request): router_exc_unset = Router(operation_defaults={"exclude_unset": True}) -@router_exc_unset.get("/r1-test-unset", response=SomeResponse, exclude_unset=True) +@router_exc_unset.get("/r1-test-unset", response=SomeResponse) def r1_op_exclude_unset(request): return {"field3": 10} +@router_exc_unset.get( + "/r1-test-unset-override", response=SomeResponse, exclude_unset=False +) +def r1_op_exclude_unset_override(request): + return {"field3": 10} + + router_exc_defaults = Router(operation_defaults={"exclude_defaults": True}) @@ -51,6 +58,14 @@ def r2_op_exclude_defaults(request): return {"field1": 3, "field2": "default value"} +@router_exc_defaults.get( + "/r2-test-defaults-override", response=SomeResponse, exclude_defaults=False +) +def r2_op_exclude_defaults_override(request): + # changing only field1 + return {"field1": 3, "field2": "default value"} + + router_exc_none = Router(operation_defaults={"exclude_none": True}) @@ -60,6 +75,14 @@ def r3_op_exclude_none(request): return {"field1": None, "field2": "default value"} +@router_exc_none.get( + "/r3-test-none-override", response=SomeResponse, exclude_none=False +) +def r3_op_exclude_none_override(request): + # setting field1 to None to exclude + return {"field1": None, "field2": "default value"} + + api.add_router("", router_exc_unset) api.add_router("", router_exc_defaults) api.add_router("", router_exc_none) @@ -78,6 +101,24 @@ def test_arguments(): assert client.get("/test-defaults").json() == {"field1": 3} assert client.get("/test-none").json() == {"field2": "default value"} + +def test_default_arguments(): + """Testing default operation arguments set on the Router""" assert client.get("/r1-test-unset").json() == {"field3": 10} + assert client.get("/r1-test-unset-override").json() == { + "field1": 1, + "field2": "default value", + "field3": 10, + } assert client.get("/r2-test-defaults").json() == {"field1": 3} + assert client.get("/r2-test-defaults-override").json() == { + "field1": 3, + "field2": "default value", + "field3": None, + } assert client.get("/r3-test-none").json() == {"field2": "default value"} + assert client.get("/r3-test-none-override").json() == { + "field1": None, + "field2": "default value", + "field3": None, + }