diff --git a/docs/versions.md b/docs/versions.md index 2a2cbd0..3c0d756 100644 --- a/docs/versions.md +++ b/docs/versions.md @@ -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 diff --git a/tests/app.py b/tests/app.py index d2698df..6bf7840 100644 --- a/tests/app.py +++ b/tests/app.py @@ -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? diff --git a/tests/test_app.py b/tests/test_app.py index 33b43ef..092bf94 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -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 @@ -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