mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-06-21 23:53:55 +02:00
test(data-extraction): Cover transform.py
This commit is contained in:
@ -1,10 +1,18 @@
|
||||
import json
|
||||
import os
|
||||
from tempfile import TemporaryDirectory
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from aki_prj23_transparenzregister.models.company import (
|
||||
Capital,
|
||||
CapitalTypeEnum,
|
||||
Company,
|
||||
CompanyID,
|
||||
CompanyRelationshipEnum,
|
||||
CompanyToCompanyRelationship,
|
||||
CompanyTypeEnum,
|
||||
CurrencyEnum,
|
||||
DistrictCourt,
|
||||
Location,
|
||||
PersonName,
|
||||
PersonToCompanyRelationship,
|
||||
@ -206,3 +214,392 @@ def test_map_rechtsform_from_name() -> None:
|
||||
|
||||
for company_name, expected_result in data:
|
||||
assert transform.map_rechtsform(company_name, {}) == expected_result
|
||||
|
||||
|
||||
def test_map_capital_kg_single() -> None:
|
||||
capital = Capital(
|
||||
currency=CurrencyEnum.EURO, value=69000, type=CapitalTypeEnum.HAFTEINLAGE # type: ignore
|
||||
)
|
||||
data = {
|
||||
"XJustiz_Daten": {
|
||||
"Fachdaten_Register": {
|
||||
"Zusatzangaben": {
|
||||
"Personengesellschaft": {
|
||||
"Zusatz_KG": {
|
||||
"Daten_Kommanditist": {
|
||||
"Hafteinlage": {
|
||||
"Zahl": str(capital.value),
|
||||
"Waehrung": capital.currency,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = transform.map_capital(data, CompanyTypeEnum.KG) # type: ignore
|
||||
assert result == capital
|
||||
|
||||
|
||||
def test_map_capital_kg_sum() -> None:
|
||||
capital = Capital(
|
||||
currency=CurrencyEnum.EURO, value=20000, type=CapitalTypeEnum.HAFTEINLAGE # type: ignore
|
||||
)
|
||||
data = {
|
||||
"XJustiz_Daten": {
|
||||
"Fachdaten_Register": {
|
||||
"Zusatzangaben": {
|
||||
"Personengesellschaft": {
|
||||
"Zusatz_KG": {
|
||||
"Daten_Kommanditist": [
|
||||
{
|
||||
"Hafteinlage": {
|
||||
"Zahl": str(10000),
|
||||
"Waehrung": capital.currency,
|
||||
}
|
||||
},
|
||||
{
|
||||
"Hafteinlage": {
|
||||
"Zahl": str(10000),
|
||||
"Waehrung": capital.currency,
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = transform.map_capital(data, CompanyTypeEnum.KG) # type: ignore
|
||||
assert result == capital
|
||||
|
||||
|
||||
def test_map_capital_no_fachdaten() -> None:
|
||||
data = {"XJustiz_Daten": {"Fachdaten_Register": {}}} # type: ignore
|
||||
|
||||
result = transform.map_capital(data, CompanyTypeEnum.KG) # type: ignore
|
||||
assert result is None
|
||||
|
||||
|
||||
def test_map_capital_gmbh() -> None:
|
||||
capital = Capital(
|
||||
currency=CurrencyEnum.DEUTSCHE_MARK, value=42, type=CapitalTypeEnum.STAMMKAPITAL # type: ignore
|
||||
)
|
||||
data = {
|
||||
"XJustiz_Daten": {
|
||||
"Fachdaten_Register": {
|
||||
"Zusatzangaben": {
|
||||
"Kapitalgesellschaft": {
|
||||
"Zusatz_GmbH": {
|
||||
"Stammkapital": {
|
||||
"Zahl": str(capital.value),
|
||||
"Waehrung": capital.currency,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = transform.map_capital(data, CompanyTypeEnum.GMBH) # type: ignore
|
||||
assert result == capital
|
||||
|
||||
|
||||
def test_map_capital_ag() -> None:
|
||||
capital = Capital(
|
||||
currency=CurrencyEnum.DEUTSCHE_MARK, value=42, type=CapitalTypeEnum.GRUNDKAPITAL # type: ignore
|
||||
)
|
||||
data = {
|
||||
"XJustiz_Daten": {
|
||||
"Fachdaten_Register": {
|
||||
"Zusatzangaben": {
|
||||
"Kapitalgesellschaft": {
|
||||
"Zusatz_Aktiengesellschaft": {
|
||||
"Grundkapital": {
|
||||
"Hoehe": {
|
||||
"Zahl": str(capital.value),
|
||||
"Waehrung": capital.currency,
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = transform.map_capital(data, CompanyTypeEnum.SE) # type: ignore
|
||||
assert result == capital
|
||||
|
||||
|
||||
def test_map_capital_personengesellschaft() -> None:
|
||||
capital = Capital(
|
||||
currency=CurrencyEnum.DEUTSCHE_MARK, value=42, type=CapitalTypeEnum.STAMMKAPITAL # type: ignore
|
||||
)
|
||||
data = {
|
||||
"XJustiz_Daten": {
|
||||
"Fachdaten_Register": {
|
||||
"Zusatzangaben": {
|
||||
"Personengesellschaft": {
|
||||
"Zusatz_GmbH": {
|
||||
"Stammkapital": {
|
||||
"Zahl": str(capital.value),
|
||||
"Waehrung": capital.currency,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = transform.map_capital(data, CompanyTypeEnum.OHG) # type: ignore
|
||||
assert result == capital
|
||||
|
||||
|
||||
def test_map_capital_einzelkaufmann() -> None:
|
||||
capital = Capital(
|
||||
currency=CurrencyEnum.DEUTSCHE_MARK, value=42, type=CapitalTypeEnum.STAMMKAPITAL # type: ignore
|
||||
)
|
||||
data = {
|
||||
"XJustiz_Daten": {
|
||||
"Fachdaten_Register": {
|
||||
"Zusatzangaben": {
|
||||
"Personengesellschaft": {
|
||||
"Zusatz_GmbH": {
|
||||
"Stammkapital": {
|
||||
"Zahl": str(capital.value),
|
||||
"Waehrung": capital.currency,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = transform.map_capital(data, CompanyTypeEnum.EINZELKAUFMANN) # type: ignore
|
||||
assert result is None
|
||||
|
||||
|
||||
def test_map_capital_partial_null_values() -> None:
|
||||
capital = Capital(
|
||||
currency=CurrencyEnum.DEUTSCHE_MARK, value=42, type=CapitalTypeEnum.STAMMKAPITAL # type: ignore
|
||||
)
|
||||
data = {
|
||||
"XJustiz_Daten": {
|
||||
"Fachdaten_Register": {
|
||||
"Zusatzangaben": {
|
||||
"Personengesellschaft": {
|
||||
"Zusatz_GmbH": {
|
||||
"Stammkapital": {
|
||||
"Zahl": None,
|
||||
"Waehrung": capital.currency,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = transform.map_capital(data, CompanyTypeEnum.OHG) # type: ignore
|
||||
assert result is None
|
||||
|
||||
|
||||
def test_map_business_purpose() -> None:
|
||||
business_purpose = "Handel mit Betäubungsmitteln aller Art"
|
||||
data = {
|
||||
"XJustiz_Daten": {
|
||||
"Fachdaten_Register": {
|
||||
"Basisdaten_Register": {
|
||||
"Gegenstand_oder_Geschaeftszweck": business_purpose
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = transform.map_business_purpose(data)
|
||||
assert result == business_purpose
|
||||
|
||||
|
||||
def test_map_business_purpose_no_result() -> None:
|
||||
data: dict = {"XJustiz_Daten": {}}
|
||||
|
||||
result = transform.map_business_purpose(data)
|
||||
assert result is None
|
||||
|
||||
|
||||
def test_transform_date_to_iso() -> None:
|
||||
date = "10.10.1111"
|
||||
expected_result = "1111-10-10"
|
||||
result = transform.transform_date_to_iso(date)
|
||||
assert result == expected_result
|
||||
|
||||
|
||||
def test_transform_date_to_iso_2_char_year() -> None:
|
||||
date = "10.10.98"
|
||||
expected_result = "1998-10-10"
|
||||
result = transform.transform_date_to_iso(date)
|
||||
assert result == expected_result
|
||||
|
||||
|
||||
def test_map_founding_date_from_tag_der_ersten_eintragung() -> None:
|
||||
data = {
|
||||
"some entry": "Tag der ersten Eintragung: 01.05.2004",
|
||||
"some other entry": "hfjdoöiashföahöf iodsazo8 5z4o fdsha8oü gfdsö",
|
||||
}
|
||||
expected_result = "2004-05-01"
|
||||
result = transform.map_founding_date(data)
|
||||
assert result == expected_result
|
||||
|
||||
|
||||
def test_map_founding_date_from_gesellschaftsvertrag() -> None:
|
||||
data = {
|
||||
"some entry": "hfjdoöiashföahöf iodsazo8 5z4o fdsha8oü gfdsö",
|
||||
"some other entry": "Das Wesen der Rekursion ist der Selbstaufruf Gesellschaftsvertrag vom 22.12.1996 Hallo Welt",
|
||||
}
|
||||
expected_result = "1996-12-22"
|
||||
result = transform.map_founding_date(data)
|
||||
assert result == expected_result
|
||||
|
||||
|
||||
def test_map_founding_date_from_gruendungsdatum() -> None:
|
||||
data = {
|
||||
"XJustiz_Daten": {
|
||||
"Fachdaten_Register": {
|
||||
"Basisdaten_Register": {
|
||||
"Gruendungsmetadaten": {"Gruendungsdatum": "1998-01-01"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
expected_result = "1998-01-01"
|
||||
result = transform.map_founding_date(data)
|
||||
assert result == expected_result
|
||||
|
||||
|
||||
def test_map_founding_date_no_result() -> None:
|
||||
data: dict = {"XJustiz_Daten": {"Fachdaten_Register": {"Basisdaten_Register": {}}}}
|
||||
result = transform.map_founding_date(data)
|
||||
assert result is None
|
||||
|
||||
|
||||
def test_map_company_id() -> None:
|
||||
district_court = DistrictCourt("Amtsgericht Ulm", "Ulm")
|
||||
company_id = CompanyID(district_court, "HRA 4711")
|
||||
data = {
|
||||
"XJustiz_Daten": {
|
||||
"Grunddaten": {
|
||||
"@XJustizVersion": "1.20.0",
|
||||
"Verfahrensdaten": {
|
||||
"Instanzdaten": {
|
||||
"Aktenzeichen": company_id.hr_number,
|
||||
},
|
||||
"Beteiligung": [
|
||||
{},
|
||||
{
|
||||
"Beteiligter": {
|
||||
"Organisation": {
|
||||
"Bezeichnung": {
|
||||
"Bezeichnung_Aktuell": district_court.name
|
||||
},
|
||||
"Sitz": {
|
||||
"Ort": district_court.city,
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
result = transform.map_company_id(data)
|
||||
assert result == company_id
|
||||
|
||||
|
||||
def test_map_last_update() -> None:
|
||||
date = "2024-01-01"
|
||||
data = {
|
||||
"XJustiz_Daten": {"Fachdaten_Register": {"Auszug": {"letzte_Eintragung": date}}}
|
||||
}
|
||||
result = transform.map_last_update(data)
|
||||
assert result == date
|
||||
|
||||
|
||||
@patch(
|
||||
"aki_prj23_transparenzregister.utils.data_extraction.unternehmensregister.transform.map_company_id"
|
||||
)
|
||||
@patch(
|
||||
"aki_prj23_transparenzregister.utils.data_extraction.unternehmensregister.transform.name_from_beteiligung"
|
||||
)
|
||||
@patch(
|
||||
"aki_prj23_transparenzregister.utils.data_extraction.unternehmensregister.transform.loc_from_beteiligung"
|
||||
)
|
||||
@patch(
|
||||
"aki_prj23_transparenzregister.utils.data_extraction.unternehmensregister.transform.map_last_update"
|
||||
)
|
||||
@patch(
|
||||
"aki_prj23_transparenzregister.utils.data_extraction.unternehmensregister.transform.map_rechtsform"
|
||||
)
|
||||
@patch(
|
||||
"aki_prj23_transparenzregister.utils.data_extraction.unternehmensregister.transform.map_capital"
|
||||
)
|
||||
@patch(
|
||||
"aki_prj23_transparenzregister.utils.data_extraction.unternehmensregister.transform.map_business_purpose"
|
||||
)
|
||||
@patch(
|
||||
"aki_prj23_transparenzregister.utils.data_extraction.unternehmensregister.transform.map_founding_date"
|
||||
)
|
||||
@patch(
|
||||
"aki_prj23_transparenzregister.utils.data_extraction.unternehmensregister.transform.parse_stakeholder"
|
||||
)
|
||||
def test_map_unternehmensregister_json( # noqa: PLR0913
|
||||
mock_map_parse_stakeholder: Mock,
|
||||
mock_map_founding_date: Mock,
|
||||
mock_map_business_purpose: Mock,
|
||||
mock_map_capital: Mock,
|
||||
mock_map_rechtsform: Mock,
|
||||
mock_map_last_update: Mock,
|
||||
mock_loc_from_beteiligung: Mock,
|
||||
mock_map_name_from_beteiligung: Mock,
|
||||
mock_map_company_id: Mock,
|
||||
) -> None:
|
||||
expected_result = Company(
|
||||
**{
|
||||
"id": Mock(), # type: ignore
|
||||
"name": Mock(),
|
||||
"location": Mock(),
|
||||
"last_update": Mock(),
|
||||
"company_type": Mock(),
|
||||
"capital": Mock(),
|
||||
"business_purpose": Mock(),
|
||||
"founding_date": Mock(),
|
||||
"relationships": [Mock()],
|
||||
}
|
||||
)
|
||||
|
||||
mock_map_company_id.return_value = expected_result.id
|
||||
mock_map_name_from_beteiligung.return_value = expected_result.name
|
||||
mock_loc_from_beteiligung.return_value = expected_result.location
|
||||
mock_map_last_update.return_value = expected_result.last_update
|
||||
mock_map_rechtsform.return_value = expected_result.company_type
|
||||
mock_map_capital.return_value = expected_result.capital
|
||||
mock_map_business_purpose.return_value = expected_result.business_purpose
|
||||
mock_map_founding_date.return_value = expected_result.founding_date
|
||||
mock_map_parse_stakeholder.return_value = expected_result.relationships[0]
|
||||
|
||||
data: dict = {
|
||||
"XJustiz_Daten": {
|
||||
"Grunddaten": {"Verfahrensdaten": {"Beteiligung": [{}, {}, {}]}}
|
||||
}
|
||||
}
|
||||
|
||||
result = transform.map_unternehmensregister_json(data)
|
||||
assert result == expected_result
|
||||
|
Reference in New Issue
Block a user