2022-04-22 18:34:48 +02:00
|
|
|
from app.authentik.models import User
|
|
|
|
from pytest_mock import MockerFixture
|
2022-04-23 18:49:28 +02:00
|
|
|
from .event_controller import Authentik_Hook_Model, EventController
|
2022-04-22 18:34:48 +02:00
|
|
|
import pytest
|
|
|
|
|
2022-04-29 14:56:51 +02:00
|
|
|
@pytest.fixture()
|
|
|
|
def mock_user():
|
|
|
|
return User(pk="5", username="asd", name="asd", email="asd@example.org")
|
2022-04-22 18:34:48 +02:00
|
|
|
|
2022-04-29 14:56:51 +02:00
|
|
|
|
|
|
|
def test_handle_model_created_event(mocker: MockerFixture, mock_user: User):
|
2022-04-22 18:34:48 +02:00
|
|
|
wekan_mock = mocker.MagicMock()
|
|
|
|
wekan_mock.get_user.return_value = None
|
2022-04-29 14:56:51 +02:00
|
|
|
nextcloud_mock = mocker.MagicMock()
|
|
|
|
wekan_mock.get_user.return_value = None
|
2022-04-22 18:34:48 +02:00
|
|
|
authentik_mock = mocker.MagicMock()
|
|
|
|
authentik_mock.get_user_by_pk.return_value = mock_user
|
2022-04-29 14:56:51 +02:00
|
|
|
|
2022-04-22 18:34:48 +02:00
|
|
|
model = Authentik_Hook_Model(pk=mock_user.pk, app="authentik_core", name=mock_user.name, model_name="user")
|
2022-04-29 14:56:51 +02:00
|
|
|
|
2022-04-29 14:13:54 +02:00
|
|
|
ec = EventController(authentik_mock)
|
2022-04-29 14:56:51 +02:00
|
|
|
ec.register_api(authentik_mock, [wekan_mock, nextcloud_mock])
|
2022-04-22 18:34:48 +02:00
|
|
|
ec.handle_model_created_event(model)
|
2022-04-29 14:13:54 +02:00
|
|
|
ec._authentik.get_user_by_pk.assert_called()
|
|
|
|
ec._authentik.get_user_by_pk.assert_called_with("5")
|
|
|
|
|
|
|
|
wekan_mock.create_user.assert_called()
|
|
|
|
wekan_mock.create_user.assert_called_with(mock_user)
|
2022-04-29 14:56:51 +02:00
|
|
|
|
|
|
|
nextcloud_mock.create_user.assert_called()
|
|
|
|
nextcloud_mock.create_user.assert_called_with(mock_user)
|