KM-R 2152704dfc
175 create person page (#178)
Created person page and updated search bar in the header to search for persons
2023-10-05 18:00:31 +02:00

62 lines
1.8 KiB
Python

"""Test for the main app dashboard."""
import sys
from collections.abc import Generator
from unittest.mock import MagicMock
import pytest
from _pytest.monkeypatch import MonkeyPatch
from pytest_mock import MockerFixture
from sqlalchemy.orm import Session
from aki_prj23_transparenzregister.ui import app
from aki_prj23_transparenzregister.ui.session_handler import SessionHandler
@pytest.fixture(autouse=True)
def _set_session(full_db: Session) -> Generator[None, None, None]:
"""Sets a session for the dash application to be used."""
SessionHandler.session = full_db
yield
SessionHandler.session = None
def test_import() -> None:
"""Checks if an import of the dash app can be made."""
assert app is not None
def test_go_to_home() -> None:
"""Checks if the go_to_home callback yields a result."""
output = app.go_to_home(1)
assert output == "/"
def test_go_to_detail_page() -> None:
"""Checks if the go_to_detail_page callback yields a result."""
output = app.go_to_detail_page("c_1")
assert output == "/Unternehmensdetails/1"
def test_main_of_app(monkeypatch: MonkeyPatch) -> None:
monkeypatch.setattr(sys, "argv", [sys.argv[0]])
with pytest.raises(SystemExit):
app.main()
def test_main_of_app_help(monkeypatch: MonkeyPatch) -> None:
monkeypatch.setattr(sys, "argv", [sys.argv[0], "-h"])
with pytest.raises(SystemExit):
app.main()
@pytest.mark.parametrize("upper", [True, False])
def test_main_of_app_env(
monkeypatch: MonkeyPatch, upper: bool, mocker: MockerFixture
) -> None:
MagicMock()
monkeypatch.setattr(sys, "argv", [sys.argv[0], "ENV" if upper else "env"])
mocked = mocker.patch("aki_prj23_transparenzregister.ui.app.Dash.run")
mocked.return_value = None
app.main()
mocked.assert_called_once()