From 5ecbf00f29756257f65c4f5bec189dadc07375b0 Mon Sep 17 00:00:00 2001 From: Robbe Sneyders Date: Sat, 18 Feb 2023 00:44:07 +0100 Subject: [PATCH] Add test for multiple float path parameters --- examples/helloworld/spec/openapi.yaml | 5 +++++ tests/api/test_parameters.py | 13 +++++++++++++ tests/fakeapi/hello/__init__.py | 4 ++++ tests/fixtures/simple/openapi.yaml | 18 ++++++++++++++++++ tests/fixtures/simple/swagger.yaml | 17 +++++++++++++++++ 5 files changed, 57 insertions(+) diff --git a/examples/helloworld/spec/openapi.yaml b/examples/helloworld/spec/openapi.yaml index 1b94d288b..476b30d12 100644 --- a/examples/helloworld/spec/openapi.yaml +++ b/examples/helloworld/spec/openapi.yaml @@ -28,3 +28,8 @@ paths: schema: type: string example: "dave" + requestBody: + content: + application/json: + schema: + type: object diff --git a/tests/api/test_parameters.py b/tests/api/test_parameters.py index af7978151..fcbb4460c 100644 --- a/tests/api/test_parameters.py +++ b/tests/api/test_parameters.py @@ -181,6 +181,19 @@ def test_path_parameter_somefloat(simple_app, arg, result): assert resp.text == f'"{result}"\n' +@pytest.mark.parametrize( + "arg, arg2, result", + [ + ["-0.000000001", "0.3", "float -1e-09, 0.3"], + ], +) +def test_path_parameter_doublefloat(simple_app, arg, arg2, result): + assert isinstance(arg, str) and isinstance(arg2, str) # sanity check + app_client = simple_app.test_client() + resp = app_client.get(f"/v1.0/test-float-path/{arg}/{arg2}") + assert resp.text == f'"{result}"\n' + + def test_path_parameter_somefloat__bad(simple_app): # non-float values will not match Flask route app_client = simple_app.test_client() diff --git a/tests/fakeapi/hello/__init__.py b/tests/fakeapi/hello/__init__.py index db6c76cd2..3b1514c23 100644 --- a/tests/fakeapi/hello/__init__.py +++ b/tests/fakeapi/hello/__init__.py @@ -280,6 +280,10 @@ def test_get_somefloat(somefloat): return f"{type(somefloat).__name__} {somefloat:g}" +def test_get_doublefloat(somefloat, someotherfloat): + return f"{type(somefloat).__name__} {somefloat:g}, {someotherfloat}" + + def test_default_param(name): return {"app_name": name} diff --git a/tests/fixtures/simple/openapi.yaml b/tests/fixtures/simple/openapi.yaml index 5833f1e3e..fdc569e36 100644 --- a/tests/fixtures/simple/openapi.yaml +++ b/tests/fixtures/simple/openapi.yaml @@ -526,6 +526,24 @@ paths: responses: '200': description: OK + '/test-float-path/{somefloat}/{someotherfloat}': + get: + summary: Test type casting of path parameter + operationId: fakeapi.hello.test_get_doublefloat + parameters: + - name: somefloat + in: path + required: true + schema: + type: number + - name: someotherfloat + in: path + required: true + schema: + type: number + responses: + '200': + description: OK /test-default-query-parameter: get: summary: Test if default parameter is passed to function diff --git a/tests/fixtures/simple/swagger.yaml b/tests/fixtures/simple/swagger.yaml index 0ac7b95fa..329ca4143 100644 --- a/tests/fixtures/simple/swagger.yaml +++ b/tests/fixtures/simple/swagger.yaml @@ -394,6 +394,23 @@ paths: 200: description: OK + /test-float-path/{somefloat}/{someotherfloat}: + get: + summary: Test type casting of path parameter + operationId: fakeapi.hello.test_get_doublefloat + parameters: + - name: somefloat + in: path + type: number + required: true + - name: someotherfloat + in: path + type: number + required: true + responses: + 200: + description: O + /test-default-query-parameter: get: summary: Test if default parameter is passed to function