mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-06-21 23:33:54 +02:00
SQL fixes after new mongo ingest (#199)
This commit is contained in:
@ -16,10 +16,12 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from aki_prj23_transparenzregister.models.company import (
|
||||
CapitalTypeEnum,
|
||||
CompanyRelationshipEnum,
|
||||
CompanyTypeEnum,
|
||||
CurrencyEnum,
|
||||
)
|
||||
from aki_prj23_transparenzregister.utils import data_transfer
|
||||
from aki_prj23_transparenzregister.utils.data_transfer import CompanyNotFoundError
|
||||
from aki_prj23_transparenzregister.utils.sql import entities
|
||||
|
||||
|
||||
@ -219,7 +221,7 @@ def test_get_company_id_not_found(
|
||||
full_db: Session,
|
||||
) -> None:
|
||||
"""Test the accessing of missing companies."""
|
||||
with pytest.raises(KeyError):
|
||||
with pytest.raises(CompanyNotFoundError):
|
||||
data_transfer.get_company_id(name, zip_code, city, full_db)
|
||||
|
||||
|
||||
@ -431,35 +433,21 @@ def test_add_companies_corrupted_data(
|
||||
assert spy_debug.call_count == len(companies) - 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("company_id", list(range(5)))
|
||||
def test_add_relationship_no_relation(company_id: int, full_db: Session) -> None:
|
||||
"""Tests if an error is thrown if the relation type/role is not defined."""
|
||||
with pytest.raises(ValueError, match="A relation type needs to be given."):
|
||||
data_transfer.add_relationship({}, company_id, full_db)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("company_id", list(range(5)))
|
||||
def test_add_relationship_unknown_relation(company_id: int, full_db: Session) -> None:
|
||||
"""Tests if an error is thrown if the relation type/role is unknown."""
|
||||
with pytest.raises(ValueError, match="Relation type .* is not yet implemented!"):
|
||||
data_transfer.add_relationship(
|
||||
{"role": "something strange"}, company_id, full_db
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("company_id", [1, 2, 3])
|
||||
@pytest.mark.parametrize(
|
||||
("firstname", "surname", "date_of_birth"),
|
||||
("firstname", "lastname", "date_of_birth"),
|
||||
[
|
||||
("Max", "Mustermann", "2023-01-01"),
|
||||
("Some Firstname", "Some Surname", "2023-01-01"),
|
||||
("Other Firstname", "Other Surname", "1900-01-02"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("role", ["Partner", "direktor", "liquidator"])
|
||||
@pytest.mark.parametrize(
|
||||
"role", ["Prokurist(in)", "Geschäftsführer(in)", "Geschäftsführer"]
|
||||
)
|
||||
def test_add_relationship_person( # noqa: PLR0913
|
||||
firstname: str,
|
||||
surname: str,
|
||||
lastname: str,
|
||||
date_of_birth: str,
|
||||
full_db: Session,
|
||||
company_id: int,
|
||||
@ -469,8 +457,9 @@ def test_add_relationship_person( # noqa: PLR0913
|
||||
relation = {
|
||||
"name": {
|
||||
"firstname": firstname,
|
||||
"lastname": surname,
|
||||
"lastname": lastname,
|
||||
},
|
||||
"type": CompanyRelationshipEnum.PERSON.value,
|
||||
"date_of_birth": date.fromisoformat(date_of_birth),
|
||||
"role": role,
|
||||
}
|
||||
@ -483,7 +472,6 @@ def test_add_relationship_person( # noqa: PLR0913
|
||||
[
|
||||
("Max", None, "2023-01-01"),
|
||||
(None, "Some Surname", "2023-01-01"),
|
||||
("Other Firstname", "Other Surname", None),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("role", ["Partner"])
|
||||
@ -505,6 +493,7 @@ def test_add_relationship_person_missing_data( # noqa: PLR0913
|
||||
},
|
||||
"date_of_birth": date_of_birth if date_of_birth else None,
|
||||
"role": role,
|
||||
"type": CompanyRelationshipEnum.PERSON.value,
|
||||
}
|
||||
with pytest.raises(
|
||||
data_transfer.DataInvalidError, match="At least one of the three values name:"
|
||||
@ -534,12 +523,13 @@ def test_add_relationship_company(
|
||||
"""Tests if a relationship to another company can be added."""
|
||||
data_transfer.add_relationship(
|
||||
{
|
||||
"description": company_name,
|
||||
"name": company_name,
|
||||
"location": {
|
||||
"zip_code": zip_code,
|
||||
"city": city,
|
||||
},
|
||||
"role": "organisation",
|
||||
"type": CompanyRelationshipEnum.COMPANY.value,
|
||||
},
|
||||
company_id,
|
||||
full_db,
|
||||
@ -569,12 +559,13 @@ def test_add_relationship_company_self_reference(
|
||||
):
|
||||
data_transfer.add_relationship(
|
||||
{
|
||||
"description": company_name,
|
||||
"name": company_name,
|
||||
"location": {
|
||||
"zip_code": zip_code,
|
||||
"city": city,
|
||||
},
|
||||
"role": "organisation",
|
||||
"type": CompanyRelationshipEnum.COMPANY.value,
|
||||
},
|
||||
company_id,
|
||||
full_db,
|
||||
@ -597,7 +588,7 @@ def test_add_relationship_company_unknown(
|
||||
mocker: MockerFixture,
|
||||
) -> None:
|
||||
"""Tests if a relationship to another company can be added."""
|
||||
spy_warning = mocker.spy(data_transfer.logger, "warning")
|
||||
spy_debug = mocker.spy(data_transfer.logger, "debug")
|
||||
spy_info = mocker.spy(data_transfer.logger, "info")
|
||||
data_transfer.add_relationship(
|
||||
{
|
||||
@ -607,11 +598,13 @@ def test_add_relationship_company_unknown(
|
||||
"city": city,
|
||||
},
|
||||
"role": "organisation",
|
||||
"type": CompanyRelationshipEnum.COMPANY.value,
|
||||
"name": "company name",
|
||||
},
|
||||
company_id,
|
||||
full_db,
|
||||
)
|
||||
spy_warning.assert_called_once()
|
||||
spy_debug.assert_called_once()
|
||||
spy_info.assert_not_called()
|
||||
|
||||
|
||||
@ -622,6 +615,7 @@ def test_add_relationships_none(empty_relations: list, full_db: Session) -> None
|
||||
|
||||
|
||||
# noinspection SpellCheckingInspection
|
||||
@pytest.mark.working_on()
|
||||
@pytest.mark.parametrize(
|
||||
"documents",
|
||||
[
|
||||
@ -649,28 +643,33 @@ def test_add_relationships_none(empty_relations: list, full_db: Session) -> None
|
||||
"date_of_birth": "1961-02-09",
|
||||
"location": {"city": "Stuttgart"},
|
||||
"role": "Geschäftsführer",
|
||||
"type": CompanyRelationshipEnum.PERSON.value,
|
||||
},
|
||||
{
|
||||
"name": {"firstname": "First Person", "lastname": "Jifpa"},
|
||||
"date_of_birth": "1976-04-20",
|
||||
"location": {"city": "Stuttgart"},
|
||||
"role": "Geschäftsführer",
|
||||
"type": CompanyRelationshipEnum.PERSON.value,
|
||||
},
|
||||
{
|
||||
"name": {"firstname": "", "lastname": "Jiapa"},
|
||||
"date_of_birth": "1976-04-20",
|
||||
"location": {"city": "Stuttgart"},
|
||||
"role": "Geschäftsführer",
|
||||
"type": CompanyRelationshipEnum.PERSON.value,
|
||||
},
|
||||
{
|
||||
"name": {"firstname": "Something", "lastname": ""},
|
||||
"date_of_birth": "12i3u",
|
||||
"location": {"city": "Stuttgart"},
|
||||
"role": "Geschäftsführer",
|
||||
"type": CompanyRelationshipEnum.PERSON.value,
|
||||
},
|
||||
{
|
||||
"name": {"firstname": "First Person", "lastname": "Jipha"},
|
||||
"name": {"lastname": "Jipha"},
|
||||
"date_of_birth": "1976-04-20",
|
||||
"type": CompanyRelationshipEnum.PERSON.value,
|
||||
},
|
||||
],
|
||||
"yearly_results": {},
|
||||
@ -730,7 +729,7 @@ def test_relationships(documents: list[dict[str, Any]], full_db: Session) -> Non
|
||||
"company_id": {0: 1, 1: 1},
|
||||
"date_from": {0: pd.NaT, 1: pd.NaT},
|
||||
"date_to": {0: pd.NaT, 1: pd.NaT},
|
||||
"relation": {0: "GESCHAEFTSFUEHRER", 1: "GESCHAEFTSFUEHRER"},
|
||||
"relation": {0: "Geschäftsführer", 1: "Geschäftsführer"},
|
||||
}
|
||||
),
|
||||
)
|
||||
@ -739,7 +738,7 @@ def test_relationships(documents: list[dict[str, Any]], full_db: Session) -> Non
|
||||
pd.DataFrame(
|
||||
{
|
||||
"id": {0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7},
|
||||
"name": {
|
||||
"firstname": {
|
||||
0: "Max",
|
||||
1: "Sabine",
|
||||
2: "Some Firstname",
|
||||
@ -748,7 +747,7 @@ def test_relationships(documents: list[dict[str, Any]], full_db: Session) -> Non
|
||||
5: "Second person",
|
||||
6: "First Person",
|
||||
},
|
||||
"surname": {
|
||||
"lastname": {
|
||||
0: "Mustermann",
|
||||
1: "Mustermann",
|
||||
2: "Some Surname",
|
||||
@ -766,15 +765,7 @@ def test_relationships(documents: list[dict[str, Any]], full_db: Session) -> Non
|
||||
5: pd.Timestamp("1961-02-09 00:00:00"),
|
||||
6: pd.Timestamp("1976-04-20 00:00:00"),
|
||||
},
|
||||
"works_for": {
|
||||
0: None,
|
||||
1: None,
|
||||
2: None,
|
||||
3: None,
|
||||
4: None,
|
||||
5: None,
|
||||
6: None,
|
||||
},
|
||||
"works_for": {_: None for _ in range(7)},
|
||||
}
|
||||
),
|
||||
)
|
||||
@ -1203,6 +1194,5 @@ def test_transfer_data_cli_env(
|
||||
)
|
||||
spy = mocker.spy(data_transfer, "transfer_data")
|
||||
|
||||
# with pytest.raises(KeyError):
|
||||
data_transfer.transfer_data_cli()
|
||||
spy.assert_called_once()
|
||||
|
Reference in New Issue
Block a user