Skip to content

Commit 0cd8c0c

Browse files
author
Fabien Coelho
committed
v4.2 bug fix
1 parent 4a61f11 commit 0cd8c0c

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

FlaskTester.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,10 @@ def request(self, method: str, path: str, status: int|None = None, content: str|
378378
data_param[name] = "null"
379379
elif isinstance(val, (io.IOBase, tuple)):
380380
pass # file parameters?
381-
elif isinstance(val, (bool, int, float, str, list, dict)):
381+
elif isinstance(val, (bool, int, float, str)):
382+
# FIXME bool seems KO
383+
pass
384+
elif isinstance(val, (list, dict)):
382385
data_param[name] = json.dumps(val)
383386
elif "model_dump_json" in val.__dir__() and callable(val.model_dump_json):
384387
data_param[name] = val.model_dump_json()

docs/versions.md

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ please report any [issues](https://github.com/zx80/flask-tester/issues).
99

1010
Check whether data and json should be exclusive.
1111

12+
## 4.2 on 2024-07-28
13+
14+
Fix bug about string parameters introduced in 4.1.
15+
1216
## 4.1 on 2024-07-28
1317

1418
Add support for transparent dataclass and pydantic parameters.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "FlaskTester"
7-
version = "4.1"
7+
version = "4.2"
88
authors = [ { name = "Fabien Coelho", email = "[email protected]" } ]
99
description = "Pytest fixtures for Flask internal and external authenticated tests"
1010
readme = "README.md"

tests/test_app.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,18 @@ def thing_eq(ta, tb):
368368
assert thing_eq(tclass(**json), param)
369369
assert n == 192
370370

371-
# null translation
371+
# simple types translation
372372
assert api.get("/t0", 200, json={"t": None}).json is None
373373
assert api.get("/t0", 200, data={"t": None}).json is None
374+
assert api.get("/t0", 200, json={"t": True}).json == True
375+
assert api.get("/t0", 200, json={"t": False}).json == False
376+
# non working, bad JsonData conversion
377+
api.get("/t0", 400, data={"t": True})
378+
api.get("/t0", 400, data={"t": False})
379+
assert api.get("/t0", 200, json={"t": 2345}).json == 2345
380+
assert api.get("/t0", 200, data={"t": 5432}).json == 5432
381+
assert api.get("/t0", 200, json={"t": 23.45}).json == 23.45
382+
assert api.get("/t0", 200, data={"t": 54.32}).json == 54.32
383+
assert api.get("/t0", 200, json={"t": "Susie"}).json == "Susie"
384+
api.get("/t0", 400, data={"t": "Susie"}) # raw str is not JSON
385+
assert api.get("/t0", 200, data={"t": "\"Susie\""}).json == "Susie"

0 commit comments

Comments
 (0)