Add a function to convert DM to EUR (#168)

The function is ment to transform the captial dict into a format that
can be added as a kwarg (**norm_capital(capital_dict) to the company
entities.
This PR only contains the function itself.
This commit is contained in:
2023-10-02 19:46:17 +02:00
committed by GitHub
parent 05472cc16a
commit 2abe12f027
5 changed files with 141 additions and 26 deletions

View File

@ -12,7 +12,9 @@ from pytest_mock import MockerFixture
from sqlalchemy.engine import Engine
from sqlalchemy.orm import Session
from aki_prj23_transparenzregister.models.company import CapitalTypeEnum, CurrencyEnum
from aki_prj23_transparenzregister.utils import data_transfer
from aki_prj23_transparenzregister.utils.data_transfer import norm_capital
from aki_prj23_transparenzregister.utils.sql import entities
@ -1019,7 +1021,35 @@ def test_add_annual_report_financial_key_error(full_db: Session) -> None:
)
@pytest.mark.working_on()
@pytest.mark.parametrize("capital_type", [_.value for _ in CapitalTypeEnum])
@pytest.mark.parametrize("currency", ["", "EUR"])
def test_norm_capital_eur(currency: str, capital_type: str) -> None:
"""Tests if eur entries can be converted / normed correctly."""
assert norm_capital({"value": 5, "currency": currency, "type": capital_type}) == {
"capital_value": 5.0,
"capital_currency": CurrencyEnum("EUR"),
"capital_type": CapitalTypeEnum(capital_type),
}
@pytest.mark.parametrize("capital_type", list(CapitalTypeEnum))
@pytest.mark.parametrize("currency", ["DM", "DEM"])
def test_norm_capital_dm(currency: str, capital_type: CapitalTypeEnum) -> None:
"""Tests if dm entries can be converted / normed correctly."""
assert norm_capital(
capital={"value": 5, "currency": currency, "type": capital_type}
) == {
"capital_value": 2.56,
"capital_currency": CurrencyEnum("DM"),
"capital_type": CapitalTypeEnum(capital_type),
}
def test_norm_capital_fail() -> None:
"""Tests if the entry is dropped if it isn't complete."""
assert norm_capital({"something": "something"}) == {} # type: ignore
@pytest.mark.parametrize(
("zip_code", "results"),
[