Add relations from finanical reports to SQL (#216)

This commit is contained in:
2023-10-19 19:21:33 +02:00
committed by GitHub
parent 41f590b2e8
commit 36a0bab6ff
4 changed files with 140 additions and 15 deletions

View File

@ -19,6 +19,7 @@ from aki_prj23_transparenzregister.models.company import (
CompanyRelationshipEnum,
CompanyTypeEnum,
CurrencyEnum,
RelationshipRoleEnum,
)
from aki_prj23_transparenzregister.utils import data_transfer
from aki_prj23_transparenzregister.utils.data_transfer import CompanyNotFoundError
@ -1054,6 +1055,94 @@ def test_add_annual_report(
)
@pytest.mark.parametrize("company_id", [2, 3])
@pytest.mark.parametrize("year", [2023, 2025, 2020])
def test_add_annual_report_auditors(
company_id: int,
year: int,
finance_statements: list[dict[str, Any]],
full_db: Session,
) -> None:
"""Tests the addition of annual financial records."""
data_transfer.add_annual_report(
company_id,
year,
{
"auditors": [{"name": "Max Musterauditor", "company": "Some Company GmbH"}],
"financials": {},
},
db=full_db,
)
full_db.commit()
added = full_db.query(entities.CompanyRelation).get(1)
assert added
assert added.company2_id == 1
assert added.company_id == company_id
assert added.date_from == date(
year,
1,
1,
)
assert added.date_to == date(
year,
12,
31,
)
assert added.relation == RelationshipRoleEnum.AUDITOR
@pytest.mark.parametrize("company_id", [1])
@pytest.mark.parametrize("year", [2023, 2025, 2020])
def test_add_annual_report_self_audit(
company_id: int,
year: int,
finance_statements: list[dict[str, Any]],
full_db: Session,
) -> None:
"""Tests the addition of annual financial records."""
data_transfer.add_annual_report(
company_id,
year,
{
"auditors": [{"name": "Max Musterauditor", "company": "Some Company GmbH"}],
"financials": {},
},
db=full_db,
)
full_db.commit()
assert full_db.query(entities.CompanyRelation).get(1) is None
@pytest.mark.parametrize("company_id", [1, 2, 3])
@pytest.mark.parametrize("number_of_years", [1, 4, 7])
def test_add_annual_report_unknown_audit(
company_id: int,
finance_statements: list[dict[str, Any]],
number_of_years: int,
full_db: Session,
) -> None:
"""Tests the addition of annual financial records."""
for year in range(2020, number_of_years + 2020, 1):
data_transfer.add_annual_report(
company_id,
year,
{
"auditors": [
{"name": "Max Musterauditor", "company": "Unknown Auditor GmbH"}
],
"financials": {},
},
db=full_db,
)
full_db.commit()
added = full_db.query(entities.MissingCompany).get("Unknown Auditor GmbH")
assert added, added.__dict__
assert added.name == "Unknown Auditor GmbH"
assert not added.zip_code
assert not added.city
assert added.number_of_links == number_of_years
def test_add_annual_report_financial_key_error(full_db: Session) -> None:
"""Tests if an error is thrown financial data is tried to be added with an unknown financial record type."""
with pytest.raises(