mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-04-22 16:22:54 +02:00
196 lines
6.3 KiB
Python
196 lines
6.3 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 aki_prj23_transparenzregister.ui.pages import home
|
|
|
|
|
|
def test_import() -> None:
|
|
"""Checks if an import co company_stats_dash can be made."""
|
|
assert home is not None
|
|
|
|
|
|
@pytest.mark.tim()
|
|
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"]
|
|
|
|
|
|
@pytest.mark.tim()
|
|
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"]
|
|
|
|
|
|
@pytest.mark.tim()
|
|
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
|
|
|
|
|
|
@pytest.mark.tim()
|
|
def test_update_graph_data() -> None:
|
|
graph_result, metrics_result, nodes_result, edges_result = home.update_graph_data(
|
|
"HAFTENDER_GESELLSCHAFTER", "GESCHAEFTSFUEHRER"
|
|
)
|
|
assert graph_result is not None
|