Philipp Horstenkamp 0d4d1324d0
Simplification of layout selection (#384)
Removed the 2d/3d toggle and added that option into the layout dropdown.

---------

Co-authored-by: KM-R <129882581+KM-R@users.noreply.github.com>
2023-11-14 21:31:30 +00:00

208 lines
6.7 KiB
Python

"""Test for the Home Page."""
import datetime
from collections.abc import Generator
from unittest.mock import patch
import pandas as pd
import pytest
from sqlalchemy.orm import Session
from aki_prj23_transparenzregister.ui.pages import home
from aki_prj23_transparenzregister.ui.session_handler import SessionHandler
def test_import() -> None:
"""Checks if an import co company_stats_dash can be made."""
assert home is not None
def test_person_relation_type_filter() -> None:
with patch(
"aki_prj23_transparenzregister.ui.pages.home.get_all_person_relations"
) as mock_filter:
data = [
{"relation_type": "Eigentümer"},
{"relation_type": "Inhaber"},
{"relation_type": "Eigentümer"},
]
mock_filter.return_value = pd.DataFrame(data)
assert list(home.person_relation_type_filter()) == ["Eigentümer", "Inhaber"]
def test_company_relation_type_filter() -> None:
with patch(
"aki_prj23_transparenzregister.ui.pages.home.get_all_company_relations"
) as mock_filter:
data = [
{"relation_type": "Eigentümer"},
{"relation_type": "Inhaber"},
{"relation_type": "Eigentümer"},
]
mock_filter.return_value = pd.DataFrame(data)
assert list(home.company_relation_type_filter()) == ["Eigentümer", "Inhaber"]
def test_update_table() -> None:
metrics = pd.DataFrame(
[
{
"designation": "Mustermann, Max",
"category": "Person",
"centrality": 3.14,
"betweenness": 42,
},
{
"designation": "Musterfrau, Martina",
"category": "Person",
"centrality": 42,
"betweenness": 3.14,
},
]
)
selected_metric = "centrality"
expected_result_df = [
{
"designation": "Musterfrau, Martina",
"category": "Person",
"centrality": 42.0,
},
{
"designation": "Mustermann, Max",
"category": "Person",
"centrality": 3.14,
},
]
expected_result_columns = [
{"name": "designation", "id": "designation"},
{"name": "category", "id": "category"},
{"name": "centrality", "id": "centrality"},
]
result_df, result_columns = home.update_table(selected_metric, metrics)
assert result_df == expected_result_df
assert result_columns == expected_result_columns
@pytest.fixture(scope="session", autouse=True)
def _get_person_relations() -> Generator:
data = [
{
"id_company": 1,
"name_company": "0 10 24 Telefondienste GmbH",
"relation_type": "GESCHAEFTSFUEHRER",
"id_person": 1,
"lastname": "Tetau",
"firstname": "Nicolas",
"date_of_birth": datetime.date(1971, 1, 2),
},
{
"id_company": 1,
"name_company": "0 10 24 Telefondienste GmbH",
"relation_type": "PROKURIST",
"id_person": 2,
"lastname": "Dammast",
"firstname": "Lutz",
"date_of_birth": datetime.date(1966, 12, 6),
},
{
"id_company": 2,
"name_company": "1. Staiger Grundstücksverwaltung GmbH & Co. KG",
"relation_type": "KOMMANDITIST",
"id_person": 3,
"lastname": "Tutsch",
"firstname": "Rosemarie",
"date_of_birth": datetime.date(1941, 10, 9),
},
{
"id_company": 2,
"name_company": "1. Staiger Grundstücksverwaltung GmbH & Co. KG",
"relation_type": "HAFTENDER_GESELLSCHAFTER",
"id_person": 4,
"lastname": "Staiger",
"firstname": "Marc",
"date_of_birth": datetime.date(1969, 10, 22),
},
{
"id_company": 2,
"name_company": "1. Staiger Grundstücksverwaltung GmbH & Co. KG",
"relation_type": "HAFTENDER_GESELLSCHAFTER",
"id_person": 5,
"lastname": "Staiger",
"firstname": "Michaela",
"date_of_birth": datetime.date(1971, 3, 3),
},
]
with patch(
"aki_prj23_transparenzregister.ui.pages.home.get_all_person_relations"
) as mock_get_person_relations:
mock_get_person_relations.return_value = pd.DataFrame(data)
yield
@pytest.fixture(scope="session", autouse=True)
def _get_company_relations() -> Generator:
data = [
{
"id_company_to": 2,
"name_company_to": "1. Staiger Grundstücksverwaltung GmbH & Co. KG",
"relation_type": "GESCHAEFTSFUEHRER",
"name_company_from": "Staiger I. Verwaltung-GmbH",
"id_company_from": 3226,
},
{
"id_company_to": 3,
"name_company_to": "1 A Autenrieth Kunststofftechnik GmbH & Co. KG",
"relation_type": "GESCHAEFTSFUEHRER",
"name_company_from": "Autenrieth Verwaltungs-GmbH",
"id_company_from": 3324,
},
{
"id_company_to": 5,
"name_company_to": "2. Schaper Objekt GmbH & Co. Kiel KG",
"relation_type": "KOMMANDITIST",
"name_company_from": "Multi-Center Warenvertriebs GmbH",
"id_company_from": 2213,
},
{
"id_company_to": 6,
"name_company_to": "AASP Filmproduktionsgesellschaft mbH & Co. Leonie KG",
"relation_type": "INHABER",
"name_company_from": "ABN AMRO Structured Products Gesellschaft für Fondsbeteiligungen mbH",
"id_company_from": 3332,
},
{
"id_company_to": 6,
"name_company_to": "AASP Filmproduktionsgesellschaft mbH & Co. Leonie KG",
"relation_type": "KOMMANDITIST",
"name_company_from": "Kallang GmbH",
"id_company_from": 3316,
},
]
with patch(
"aki_prj23_transparenzregister.ui.pages.home.get_all_company_relations"
) as mock_get_person_relations:
mock_get_person_relations.return_value = pd.DataFrame(data)
yield
def test_update_graph_data() -> None:
graph_result, metrics_result, nodes_result, edges_result = home.update_graph_data(
frozenset({"HAFTENDER_GESELLSCHAFTER"}), frozenset("GESCHAEFTSFUEHRER")
)
assert graph_result is not None
@pytest.fixture()
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
@pytest.mark.usefixtures("_set_session")
def test_layout() -> None:
"""Checks if layout can be executed."""
home.layout()