From 23bdcc795783f5992be7016fd3c6c3493935efec Mon Sep 17 00:00:00 2001 From: Philipp Rothmann Date: Fri, 29 Apr 2022 16:43:47 +0200 Subject: [PATCH] testytest --- Makefile | 2 +- app/authentik/api.py | 1 - app/consumer/wekan/api.py | 2 -- app/consumer/wekan/test_wekan.py | 11 ++++------- app/test_integration.py | 11 ++++------- app/test_main.py | 1 - 6 files changed, 9 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 3e243bd..63513b3 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ run: test: - ./env/bin/pytest --sw app + ./env/bin/pytest -s --sw app integration: ./env/bin/uvicorn app.main:app --reload --host 0.0.0.0 diff --git a/app/authentik/api.py b/app/authentik/api.py index aedaab8..dddf834 100644 --- a/app/authentik/api.py +++ b/app/authentik/api.py @@ -165,7 +165,6 @@ class Authentik: r = r["results"][0] if "pk" in r: - print(r) return User(**r) raise Exception(r) diff --git a/app/consumer/wekan/api.py b/app/consumer/wekan/api.py index 4104097..1eb6002 100644 --- a/app/consumer/wekan/api.py +++ b/app/consumer/wekan/api.py @@ -49,7 +49,6 @@ class WekanApi: raise Exception(r) if r == {}: return None - print(r) return User(**r) def get_all_users(self) -> List[UserBase]: @@ -75,6 +74,5 @@ class WekanApi: def delete_user(self, id: str): r = self.delete(f"users/{id}").json() - print(r) if "error" in r: raise Exception(r) diff --git a/app/consumer/wekan/test_wekan.py b/app/consumer/wekan/test_wekan.py index 58f6aa6..29f400a 100644 --- a/app/consumer/wekan/test_wekan.py +++ b/app/consumer/wekan/test_wekan.py @@ -25,12 +25,9 @@ def test_get_user(api: WekanApi): def test_get_users(api: WekanApi): assert True if "api" in [u.username for u in api.get_all_users()] else False -def test_create_user(api: WekanApi): - user = api.create_user("foo", "foo@32bar.com", "") +def test_create_and_delete_user(api: WekanApi): + user = api.create_user("foo", "foo42@bar.com", "") assert api.get_user("foo").username == "foo" assert type(user) is User - -def test_delete_user(api: WekanApi): - u = api.create_user("Bar", "foo@bar42.com", "") - api.delete_user(u.id) - assert api.get_user("Bar") == None + api.delete_user(user.id) + assert api.get_user("foo") == None diff --git a/app/test_integration.py b/app/test_integration.py index 4e44c12..9f9fb33 100644 --- a/app/test_integration.py +++ b/app/test_integration.py @@ -36,7 +36,7 @@ def authentik(settings: AuthentikSettings): r = a.create_web_hook( hook_endpoint="http://172.17.0.1:8000/authentik/hook/") # docker localhost except Exception as e: - logging.info(e) + logging.error(e) return a @@ -45,24 +45,21 @@ def authentik_user(authentik): user = authentik.create_user(User(username="foobar", name="Foo Bar", email="foo@bar.com")) yield user authentik.delete_user(user) - print("DELETING USER") -def test_create_user(mocker, authentik: Authentik, authentik_user: WekanUser, wekan: WekanApi): - # Actually this should already trigger the hook, but in authentik it doesn't trigger when come from api +def test_create_user(mocker, authentik_user: WekanUser, wekan: WekanApi): + # Actually authentik user creation should already trigger the hook, but in authentik it doesn't trigger when come from api # mock = mocker.patch("app.event_controller.EventController.handle_model_created_event") authentik_message = {"model": {"pk": authentik_user.pk, "app": "authentik_core", "name": authentik_user.name, "model_name": "user"}, "http_request": {"args": {}, "path": "/api/v3/core/users/", "method": "POST"}} response = client.post("/authentik/hook/", json=authentik_message) - print(response.text) assert response.status_code == 200 wu = wekan.get_user(authentik_user.username) assert not wu == None assert wu.username == authentik_user.username assert authentik_user.email in [i.address for i in wu.emails] - - wekan.delete_user(authentik_user.username) + wekan.delete_user(wu.id) @pytest.mark.skip() diff --git a/app/test_main.py b/app/test_main.py index 070cda8..18daa8f 100644 --- a/app/test_main.py +++ b/app/test_main.py @@ -21,7 +21,6 @@ def test_hook_fails_for_wrong_input(): "user_username": "akadmin" }""" response = client.post("/authentik/hook/", data=d) - print(response.text) assert response.status_code == 422 def test_hook_model_created(mocker):