testytest

This commit is contained in:
Philipp Rothmann 2022-04-29 16:43:47 +02:00
parent 3034bb3b69
commit 23bdcc7957
6 changed files with 9 additions and 19 deletions

View file

@ -19,7 +19,7 @@ run:
test: test:
./env/bin/pytest --sw app ./env/bin/pytest -s --sw app
integration: integration:
./env/bin/uvicorn app.main:app --reload --host 0.0.0.0 ./env/bin/uvicorn app.main:app --reload --host 0.0.0.0

View file

@ -165,7 +165,6 @@ class Authentik:
r = r["results"][0] r = r["results"][0]
if "pk" in r: if "pk" in r:
print(r)
return User(**r) return User(**r)
raise Exception(r) raise Exception(r)

View file

@ -49,7 +49,6 @@ class WekanApi:
raise Exception(r) raise Exception(r)
if r == {}: if r == {}:
return None return None
print(r)
return User(**r) return User(**r)
def get_all_users(self) -> List[UserBase]: def get_all_users(self) -> List[UserBase]:
@ -75,6 +74,5 @@ class WekanApi:
def delete_user(self, id: str): def delete_user(self, id: str):
r = self.delete(f"users/{id}").json() r = self.delete(f"users/{id}").json()
print(r)
if "error" in r: if "error" in r:
raise Exception(r) raise Exception(r)

View file

@ -25,12 +25,9 @@ def test_get_user(api: WekanApi):
def test_get_users(api: WekanApi): def test_get_users(api: WekanApi):
assert True if "api" in [u.username for u in api.get_all_users()] else False assert True if "api" in [u.username for u in api.get_all_users()] else False
def test_create_user(api: WekanApi): def test_create_and_delete_user(api: WekanApi):
user = api.create_user("foo", "foo@32bar.com", "") user = api.create_user("foo", "foo42@bar.com", "")
assert api.get_user("foo").username == "foo" assert api.get_user("foo").username == "foo"
assert type(user) is User assert type(user) is User
api.delete_user(user.id)
def test_delete_user(api: WekanApi): assert api.get_user("foo") == None
u = api.create_user("Bar", "foo@bar42.com", "")
api.delete_user(u.id)
assert api.get_user("Bar") == None

View file

@ -36,7 +36,7 @@ def authentik(settings: AuthentikSettings):
r = a.create_web_hook( r = a.create_web_hook(
hook_endpoint="http://172.17.0.1:8000/authentik/hook/") # docker localhost hook_endpoint="http://172.17.0.1:8000/authentik/hook/") # docker localhost
except Exception as e: except Exception as e:
logging.info(e) logging.error(e)
return a return a
@ -45,24 +45,21 @@ def authentik_user(authentik):
user = authentik.create_user(User(username="foobar", name="Foo Bar", email="foo@bar.com")) user = authentik.create_user(User(username="foobar", name="Foo Bar", email="foo@bar.com"))
yield user yield user
authentik.delete_user(user) authentik.delete_user(user)
print("DELETING USER")
def test_create_user(mocker, authentik: Authentik, authentik_user: WekanUser, wekan: WekanApi): def test_create_user(mocker, authentik_user: WekanUser, wekan: WekanApi):
# Actually this should already trigger the hook, but in authentik it doesn't trigger when come from api # 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") # 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, 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"}} "model_name": "user"}, "http_request": {"args": {}, "path": "/api/v3/core/users/", "method": "POST"}}
response = client.post("/authentik/hook/", json=authentik_message) response = client.post("/authentik/hook/", json=authentik_message)
print(response.text)
assert response.status_code == 200 assert response.status_code == 200
wu = wekan.get_user(authentik_user.username) wu = wekan.get_user(authentik_user.username)
assert not wu == None assert not wu == None
assert wu.username == authentik_user.username assert wu.username == authentik_user.username
assert authentik_user.email in [i.address for i in wu.emails] assert authentik_user.email in [i.address for i in wu.emails]
wekan.delete_user(wu.id)
wekan.delete_user(authentik_user.username)
@pytest.mark.skip() @pytest.mark.skip()

View file

@ -21,7 +21,6 @@ def test_hook_fails_for_wrong_input():
"user_username": "akadmin" "user_username": "akadmin"
}""" }"""
response = client.post("/authentik/hook/", data=d) response = client.post("/authentik/hook/", data=d)
print(response.text)
assert response.status_code == 422 assert response.status_code == 422
def test_hook_model_created(mocker): def test_hook_model_created(mocker):