Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien Coelho committed Sep 15, 2024
1 parent f228b7e commit a6e0eaa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ please report any [issues](https://github.com/zx80/flask-tester/issues).

Slightly improve documentation.
Add `setHook`.
Add some tests.

## 4.3 on 2024-08-10

Expand Down
4 changes: 3 additions & 1 deletion tests/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def get_admin(user: fsa.CurrentUser):
def get_hello(lang: fsa.Cookie = "en"):
return {"lang": lang, "hello": HELLO.get(lang, "Hi")}, 200

# json, pydantic and dataclasses tests
#
# further json, pydantic and dataclasses tests
#
import model

# FIXME could we drop fsa.jsonify?
Expand Down
11 changes: 5 additions & 6 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ def test_client_fixture():
def test_classes(api):

def thing_eq(ta, tb):
ta = model.Thing1(**ta) if isinstance(ta, dict) else ta
tb = model.Thing1(**tb) if isinstance(tb, dict) else tb
return ta.tid == tb.tid and ta.name == tb.name and ta.owner == tb.owner

Expand All @@ -364,17 +365,15 @@ def thing_eq(ta, tb):
# check all combinations
for path in ["/t0", "/t1", "/t2", "/t3"]:
for param in [t0, t1, t2, t3]:
for tclass in [model.Thing1, model.Thing2, model.Thing3]:
for tclass in [dict, model.Thing1, model.Thing2, model.Thing3]:
for method in ["GET", "POST"]:
for mode in ["data", "json"]:
n +=1
parameter = {mode: {"t": param}}
res = api.request(method, path, 200, **parameter)
assert res.is_json
json = res.json
assert isinstance(json, dict)
assert thing_eq(tclass(**json), param)
assert n == 192
assert res.is_json and isinstance(res.json, dict)
assert thing_eq(tclass(**res.json), param)
assert n == 256

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

0 comments on commit a6e0eaa

Please sign in to comment.