integrate/app/test_main.py

41 lines
1.3 KiB
Python
Raw Normal View History

2022-03-02 16:10:17 +01:00
from fastapi.testclient import TestClient
2022-04-22 18:34:48 +02:00
import pytest
2022-03-02 16:10:17 +01:00
2022-04-29 14:56:51 +02:00
from app.consumer.wekan.api import WekanApi
2022-03-03 16:36:08 +01:00
2022-03-06 15:51:27 +01:00
from .main import Authentik_Hook_Model, app
2022-03-02 16:10:17 +01:00
client = TestClient(app)
def test_read_main():
response = client.get("/")
assert response.status_code == 200
2022-03-02 16:22:11 +01:00
assert response.json() == {"message": "Hello World"}
2022-03-03 16:36:08 +01:00
2022-04-22 18:34:48 +02:00
def test_hook_fails_for_wrong_input():
2022-03-03 16:36:08 +01:00
d = """{
"body": "Test Notification from transport hook",
"severity": "notice",
"user_email": "root@localhost",
"user_username": "akadmin"
}"""
2022-03-06 15:29:00 +01:00
response = client.post("/authentik/hook/", data=d)
2022-04-22 18:34:48 +02:00
print(response.text)
2022-03-06 15:29:00 +01:00
assert response.status_code == 422
2022-03-03 16:36:08 +01:00
def test_hook_model_created(mocker):
2022-04-29 14:13:54 +02:00
mock = mocker.patch("app.event_controller.EventController.handle_model_created_event")
2022-03-03 16:36:08 +01:00
d = """
2022-03-04 18:51:33 +01:00
{"model": {"pk": 5, "app": "authentik_core", "name": "asd", "model_name": "user"}, "http_request": {"args": {}, "path": "/api/v3/core/users/", "method": "POST"}}
2022-03-03 16:36:08 +01:00
"""
2022-03-06 15:29:00 +01:00
response = client.post("/authentik/hook/", data=d, )
2022-03-03 16:36:08 +01:00
assert response.status_code == 200
2022-03-06 15:51:27 +01:00
assert len(mock.mock_calls) > 0
kall = mock.call_args
assert type(kall.args[0]) == Authentik_Hook_Model
model: Authentik_Hook_Model = kall.args[0]
assert model.pk == "5"
assert model.app == "authentik_core"
assert model.name == "asd"
2022-04-22 18:34:48 +02:00
assert model.model_name == "user"