From af3ae62c02c8f04296a4b750900c9532d04a945a Mon Sep 17 00:00:00 2001 From: Fabien Coelho Date: Tue, 12 Mar 2024 21:08:12 +0100 Subject: [PATCH] test with default_login --- FlaskTester.py | 2 +- tests/test.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/FlaskTester.py b/FlaskTester.py index 91ff221..a8c9f30 100755 --- a/FlaskTester.py +++ b/FlaskTester.py @@ -246,7 +246,7 @@ def request(self, method: str, path: str, status: int|None = None, auth: str|Non if "login" in kwargs: login = kwargs["login"] del kwargs["login"] - else: # pragma: no cover + else: login = self._default_login self._auth.setAuth(login, kwargs, auth=auth) diff --git a/tests/test.py b/tests/test.py index be2b91a..aa8e31e 100644 --- a/tests/test.py +++ b/tests/test.py @@ -19,6 +19,8 @@ @pytest.fixture def api(ft_client): + # set a default + ft_client._default_login = "calvin" # bad password / token ft_client.setPass("moe", None) ft_client.setToken("moe", None) @@ -41,6 +43,15 @@ def api(ft_client): assert res.json["user"] == "hobbes" res = ft_client.get("/who-am-i", login="susie", status=200, auth="bearer") assert res.json["user"] == "susie" + # with defaults + res = ft_client.get("/who-am-i", auth="basic", status=200) + assert res.json["user"] == "calvin" + res = ft_client.get("/who-am-i", auth="param", status=200) + assert res.json["user"] == "calvin" + res = ft_client.get("/who-am-i", auth="bearer", status=200) + assert res.json["user"] == "calvin" + res = ft_client.get("/who-am-i", status=200) + assert res.json["user"] == "calvin" # add a bad password yield ft_client