mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-08-11 19:18:28 +02:00
test: Unit tests
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
"""Testing data_extraction/unternehmensregister/transform/common.py."""
|
||||
import pytest
|
||||
|
||||
from aki_prj23_transparenzregister.models.company import (
|
||||
CompanyRelationshipEnum,
|
||||
CompanyToCompanyRelationship,
|
||||
Location,
|
||||
RelationshipRoleEnum,
|
||||
)
|
||||
from aki_prj23_transparenzregister.utils.data_extraction.unternehmensregister.transform import (
|
||||
common,
|
||||
)
|
||||
|
||||
|
||||
def test_import_common() -> None:
|
||||
assert common
|
||||
|
||||
|
||||
def test_traversal() -> None:
|
||||
data = {"a": {"b": {"c": "d"}}}
|
||||
assert common.traversal(data, ["a", "b", "c"]) == "d"
|
||||
|
||||
|
||||
# def test_traversal_raises_key_error():
|
||||
# data = {"a": {"b": {"c": "d"}}}
|
||||
# try:
|
||||
# common.traversal(data, ["a", "b", "d"])
|
||||
# except KeyError:
|
||||
# assert True
|
||||
# else:
|
||||
# assert False
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("value", "expected_result"),
|
||||
[
|
||||
(None, None),
|
||||
("Ludwig-Ganghofer-Str.", "Ludwig-Ganghofer-Straße"),
|
||||
("Ludwig-Ganghofer-Strasse", "Ludwig-Ganghofer-Straße"),
|
||||
("Str. des Tests", "Straße des Tests"),
|
||||
],
|
||||
)
|
||||
def test_normalize_street(value: str, expected_result: str) -> None:
|
||||
result = common.normalize_street(value)
|
||||
assert result == expected_result
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("value", "expected_result"),
|
||||
[
|
||||
("", None),
|
||||
("Tag der ersten Eintragung: 01.05.2004", "2004-05-01"),
|
||||
("Tag der ersten Eintragung: 1.05.2004", "2004-05-01"),
|
||||
("Tag der ersten Eintragung: 1.5.2004", "2004-05-01"),
|
||||
("Tag der ersten Eintragung: 01.5.2004", "2004-05-01"),
|
||||
("Gesellschaftsvertrag vom 06.04.2016 Hallo Welt", "2016-04-06"),
|
||||
("Str. des Tests vom 1999-04-05", "1999-04-05"),
|
||||
("Once upon a midnight dreary while I pondered weak and weary...", None),
|
||||
(
|
||||
"This company was first founded in 2016-06-10 and then again on 1.5.2004",
|
||||
None,
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_extract_date_from_string(value: str, expected_result: str) -> None:
|
||||
result = common.extract_date_from_string(value)
|
||||
assert result == expected_result
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("value", "expected_result"),
|
||||
[
|
||||
(
|
||||
{
|
||||
"location": Location(
|
||||
"", "c/o Youco24 Business Center, Abc ffda", None, None
|
||||
),
|
||||
"relationships": [],
|
||||
},
|
||||
{
|
||||
"location": Location("", "Abc ffda", None, None),
|
||||
"relationships": [
|
||||
CompanyToCompanyRelationship(
|
||||
RelationshipRoleEnum.CARE_OF, # type: ignore
|
||||
Location("", "Abc ffda", None, None),
|
||||
CompanyRelationshipEnum.COMPANY,
|
||||
"Youco24 Business Center",
|
||||
)
|
||||
],
|
||||
},
|
||||
),
|
||||
(
|
||||
{
|
||||
"location": Location(
|
||||
"Iserlohn", "c/o Youco24 Business Center, Abc Str.", "42", "58644"
|
||||
),
|
||||
"relationships": [],
|
||||
},
|
||||
{
|
||||
"location": Location("Iserlohn", "Abc Str.", "42", "58644"),
|
||||
"relationships": [
|
||||
CompanyToCompanyRelationship(
|
||||
RelationshipRoleEnum.CARE_OF, # type: ignore
|
||||
Location("Iserlohn", "Abc Str.", "42", "58644"),
|
||||
CompanyRelationshipEnum.COMPANY,
|
||||
"Youco24 Business Center",
|
||||
)
|
||||
],
|
||||
},
|
||||
),
|
||||
(
|
||||
{
|
||||
"location": Location(
|
||||
"Iserlohn", "Abc Str., c/o Youco24 Business Center", "42", "58644"
|
||||
),
|
||||
"relationships": [],
|
||||
},
|
||||
{
|
||||
"location": Location("Iserlohn", "Abc Str.", "42", "58644"),
|
||||
"relationships": [
|
||||
CompanyToCompanyRelationship(
|
||||
RelationshipRoleEnum.CARE_OF, # type: ignore
|
||||
Location("Iserlohn", "Abc Str.", "42", "58644"),
|
||||
CompanyRelationshipEnum.COMPANY,
|
||||
"Youco24 Business Center",
|
||||
)
|
||||
],
|
||||
},
|
||||
),
|
||||
(
|
||||
{
|
||||
"location": Location("Iserlohn", "Abc Str., c/o", "42", "58644"),
|
||||
"relationships": [],
|
||||
},
|
||||
{
|
||||
"location": Location("Iserlohn", "Abc Str.", "42", "58644"),
|
||||
"relationships": [],
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_map_co_relation(value: dict, expected_result: dict) -> None:
|
||||
result = common.map_co_relation(value)
|
||||
assert result == expected_result
|
@@ -1,8 +1,6 @@
|
||||
"""Testing utils/data_extraction/unternehmensregister/transform.py."""
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from aki_prj23_transparenzregister.models.company import (
|
||||
Capital,
|
||||
CapitalTypeEnum,
|
||||
@@ -266,20 +264,6 @@ def test_loc_from_beteiligung_combine() -> None:
|
||||
assert transform.loc_from_beteiligung(data) == expected_result
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("value", "expected_result"),
|
||||
[
|
||||
(None, None),
|
||||
("Ludwig-Ganghofer-Str.", "Ludwig-Ganghofer-Straße"),
|
||||
("Ludwig-Ganghofer-Strasse", "Ludwig-Ganghofer-Straße"),
|
||||
("Str. des Tests", "Straße des Tests"),
|
||||
],
|
||||
)
|
||||
def test_normalize_street(value: str, expected_result: str) -> None:
|
||||
result = transform.normalize_street(value)
|
||||
assert result == expected_result
|
||||
|
||||
|
||||
def test_name_from_beteiligung() -> None:
|
||||
data = {
|
||||
"XJustiz_Daten": {
|
||||
@@ -582,28 +566,6 @@ def test_map_business_purpose_no_result() -> None:
|
||||
assert result is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("value", "expected_result"),
|
||||
[
|
||||
("", None),
|
||||
("Tag der ersten Eintragung: 01.05.2004", "2004-05-01"),
|
||||
("Tag der ersten Eintragung: 1.05.2004", "2004-05-01"),
|
||||
("Tag der ersten Eintragung: 1.5.2004", "2004-05-01"),
|
||||
("Tag der ersten Eintragung: 01.5.2004", "2004-05-01"),
|
||||
("Gesellschaftsvertrag vom 06.04.2016 Hallo Welt", "2016-04-06"),
|
||||
("Str. des Tests vom 1999-04-05", "1999-04-05"),
|
||||
("Once upon a midnight dreary while I pondered weak and weary...", None),
|
||||
(
|
||||
"This company was first founded in 2016-06-10 and then again on 1.5.2004",
|
||||
None,
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_extract_date_from_string(value: str, expected_result: str) -> None:
|
||||
result = transform.extract_date_from_string(value)
|
||||
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",
|
||||
@@ -690,83 +652,6 @@ def test_map_last_update() -> None:
|
||||
assert result == date
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("value", "expected_result"),
|
||||
[
|
||||
(
|
||||
{
|
||||
"location": Location(
|
||||
"", "c/o Youco24 Business Center, Abc ffda", None, None
|
||||
),
|
||||
"relationships": [],
|
||||
},
|
||||
{
|
||||
"location": Location("", "Abc ffda", None, None),
|
||||
"relationships": [
|
||||
CompanyToCompanyRelationship(
|
||||
RelationshipRoleEnum.CARE_OF, # type: ignore
|
||||
Location("", "Abc ffda", None, None),
|
||||
CompanyRelationshipEnum.COMPANY,
|
||||
"Youco24 Business Center",
|
||||
)
|
||||
],
|
||||
},
|
||||
),
|
||||
(
|
||||
{
|
||||
"location": Location(
|
||||
"Iserlohn", "c/o Youco24 Business Center, Abc Str.", "42", "58644"
|
||||
),
|
||||
"relationships": [],
|
||||
},
|
||||
{
|
||||
"location": Location("Iserlohn", "Abc Str.", "42", "58644"),
|
||||
"relationships": [
|
||||
CompanyToCompanyRelationship(
|
||||
RelationshipRoleEnum.CARE_OF, # type: ignore
|
||||
Location("Iserlohn", "Abc Str.", "42", "58644"),
|
||||
CompanyRelationshipEnum.COMPANY,
|
||||
"Youco24 Business Center",
|
||||
)
|
||||
],
|
||||
},
|
||||
),
|
||||
(
|
||||
{
|
||||
"location": Location(
|
||||
"Iserlohn", "Abc Str., c/o Youco24 Business Center", "42", "58644"
|
||||
),
|
||||
"relationships": [],
|
||||
},
|
||||
{
|
||||
"location": Location("Iserlohn", "Abc Str.", "42", "58644"),
|
||||
"relationships": [
|
||||
CompanyToCompanyRelationship(
|
||||
RelationshipRoleEnum.CARE_OF, # type: ignore
|
||||
Location("Iserlohn", "Abc Str.", "42", "58644"),
|
||||
CompanyRelationshipEnum.COMPANY,
|
||||
"Youco24 Business Center",
|
||||
)
|
||||
],
|
||||
},
|
||||
),
|
||||
(
|
||||
{
|
||||
"location": Location("Iserlohn", "Abc Str., c/o", "42", "58644"),
|
||||
"relationships": [],
|
||||
},
|
||||
{
|
||||
"location": Location("Iserlohn", "Abc Str.", "42", "58644"),
|
||||
"relationships": [],
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_map_co_relation(value: dict, expected_result: dict) -> None:
|
||||
result = transform.map_co_relation(value)
|
||||
assert result == expected_result
|
||||
|
||||
|
||||
@patch(
|
||||
"aki_prj23_transparenzregister.utils.data_extraction.unternehmensregister.transform.v1.v1.map_co_relation"
|
||||
)
|
||||
|
Reference in New Issue
Block a user