mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-06-22 04:43:54 +02:00
test(data-ingestion): Test Bundesanzeiger wrapper
This commit is contained in:
@ -1,11 +1,29 @@
|
|||||||
|
from unittest.mock import Mock
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from aki_prj23_transparenzregister.models.company import FinancialKPIEnum
|
||||||
from aki_prj23_transparenzregister.utils.data_extraction.bundesanzeiger import (
|
from aki_prj23_transparenzregister.utils.data_extraction.bundesanzeiger import (
|
||||||
Bundesanzeiger,
|
Bundesanzeiger,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def mock_bundesanzeiger(mocker: Mock) -> Mock:
|
||||||
|
mock = Mock()
|
||||||
|
mocker.patch(
|
||||||
|
"deutschland.bundesanzeiger",
|
||||||
|
return_value=mock,
|
||||||
|
)
|
||||||
|
return mock
|
||||||
|
|
||||||
|
|
||||||
def test_extract_auditor_company_no_hits() -> None:
|
def test_extract_auditor_company_no_hits() -> None:
|
||||||
input_data = """
|
input_data = """
|
||||||
Nothing to see here \O_O/
|
<b>
|
||||||
|
Nothing to see here
|
||||||
|
</b>
|
||||||
"""
|
"""
|
||||||
ba = Bundesanzeiger()
|
ba = Bundesanzeiger()
|
||||||
result = ba.extract_auditor_company(input_data)
|
result = ba.extract_auditor_company(input_data)
|
||||||
@ -24,3 +42,55 @@ def test_extract_auditor_company() -> None:
|
|||||||
ba = Bundesanzeiger()
|
ba = Bundesanzeiger()
|
||||||
result = ba.extract_auditor_company(input_data)
|
result = ba.extract_auditor_company(input_data)
|
||||||
assert result == company_name
|
assert result == company_name
|
||||||
|
|
||||||
|
|
||||||
|
def test_extract_kpis() -> None:
|
||||||
|
input_data = """
|
||||||
|
Die Prj23_Transparenzregister GmbH erwirtschaftete einen Jahresüberschuss 10.000,43 €.
|
||||||
|
Des Weiteren sanken die Gesamtverbindlichkeiten 42,00 €
|
||||||
|
"""
|
||||||
|
ba = Bundesanzeiger()
|
||||||
|
result = ba.__extract_kpis__(input_data)
|
||||||
|
|
||||||
|
net_income = 10000.43
|
||||||
|
liabilities = 42.00
|
||||||
|
|
||||||
|
assert result[FinancialKPIEnum.NET_INCOME.value] == net_income
|
||||||
|
assert result[FinancialKPIEnum.LIABILITIES.value] == liabilities
|
||||||
|
|
||||||
|
|
||||||
|
def test_extracct_financial_results() -> None:
|
||||||
|
input_data = """
|
||||||
|
<br>
|
||||||
|
Die Prj23_Transparenzregister GmbH erwirtschaftete einen Jahresüberschuss 10.000,43 €.
|
||||||
|
</br>
|
||||||
|
<h2>Dies ist ein Platzhalter, der ignoriert werden soll</h2>
|
||||||
|
<b>Des Weiteren sanken die Gesamtverbindlichkeiten 42,00 €</b>
|
||||||
|
"""
|
||||||
|
ba = Bundesanzeiger()
|
||||||
|
result = ba.extract_financial_results(input_data)
|
||||||
|
|
||||||
|
net_income = 10000.43
|
||||||
|
liabilities = 42.00
|
||||||
|
|
||||||
|
assert result[FinancialKPIEnum.NET_INCOME.value] == net_income
|
||||||
|
assert result[FinancialKPIEnum.LIABILITIES.value] == liabilities
|
||||||
|
|
||||||
|
|
||||||
|
def test_filter_reports() -> None:
|
||||||
|
test_data = [
|
||||||
|
{"name": "Bedienungsanleitung", "report": ""},
|
||||||
|
{"name": "Jahresabschluss 1998", "report": ""},
|
||||||
|
]
|
||||||
|
test_df = pd.DataFrame(test_data)
|
||||||
|
ba = Bundesanzeiger()
|
||||||
|
result = ba.filter_reports(test_df)
|
||||||
|
assert len(result) == 1
|
||||||
|
assert result.iloc[0].jahr == "1998"
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_information(mock_bundesanzeiger: Mock) -> None:
|
||||||
|
mock_bundesanzeiger.get_reports.return_value = [{}, {}]
|
||||||
|
ba = Bundesanzeiger()
|
||||||
|
result = ba.get_information("PRJ 23 Transparenzregister GmbH", "Iserlohn")
|
||||||
|
assert result is not None
|
||||||
|
Reference in New Issue
Block a user