mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2026-02-13 22:17:38 +01:00
2152704dfc
Created person page and updated search bar in the header to search for persons
62 lines
1.8 KiB
Python
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()
|