Skip to content

Commit a6e0eaa

Browse files
author
Fabien Coelho
committed
more tests
1 parent f228b7e commit a6e0eaa

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

docs/versions.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ please report any [issues](https://github.com/zx80/flask-tester/issues).
1414

1515
Slightly improve documentation.
1616
Add `setHook`.
17+
Add some tests.
1718

1819
## 4.3 on 2024-08-10
1920

tests/app.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ def get_admin(user: fsa.CurrentUser):
3939
def get_hello(lang: fsa.Cookie = "en"):
4040
return {"lang": lang, "hello": HELLO.get(lang, "Hi")}, 200
4141

42-
# json, pydantic and dataclasses tests
42+
#
43+
# further json, pydantic and dataclasses tests
44+
#
4345
import model
4446

4547
# FIXME could we drop fsa.jsonify?

tests/test_app.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ def test_client_fixture():
351351
def test_classes(api):
352352

353353
def thing_eq(ta, tb):
354+
ta = model.Thing1(**ta) if isinstance(ta, dict) else ta
354355
tb = model.Thing1(**tb) if isinstance(tb, dict) else tb
355356
return ta.tid == tb.tid and ta.name == tb.name and ta.owner == tb.owner
356357

@@ -364,17 +365,15 @@ def thing_eq(ta, tb):
364365
# check all combinations
365366
for path in ["/t0", "/t1", "/t2", "/t3"]:
366367
for param in [t0, t1, t2, t3]:
367-
for tclass in [model.Thing1, model.Thing2, model.Thing3]:
368+
for tclass in [dict, model.Thing1, model.Thing2, model.Thing3]:
368369
for method in ["GET", "POST"]:
369370
for mode in ["data", "json"]:
370371
n +=1
371372
parameter = {mode: {"t": param}}
372373
res = api.request(method, path, 200, **parameter)
373-
assert res.is_json
374-
json = res.json
375-
assert isinstance(json, dict)
376-
assert thing_eq(tclass(**json), param)
377-
assert n == 192
374+
assert res.is_json and isinstance(res.json, dict)
375+
assert thing_eq(tclass(**res.json), param)
376+
assert n == 256
378377

379378
# simple types translation
380379
assert api.get("/t0", 200, json={"t": None}).json is None

0 commit comments

Comments
 (0)