mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-06-21 23:43:55 +02:00
Add a cli interface to choose a configuration (#163)
- [x] add a cli to the webserver to take env variables into account - [x] add a cli to the data processing that takes enviromental variable as a valid source into account - [x] rework the cli for the reset sql command - [x] rework the cli for the copying of sql data from one db to another
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
"""Test the transfer functions from mongodb to sql."""
|
||||
import random
|
||||
import string
|
||||
import sys
|
||||
from datetime import date
|
||||
from typing import Any
|
||||
|
||||
@ -8,13 +9,13 @@ import numpy as np
|
||||
import pandas as pd
|
||||
import pytest
|
||||
import sqlalchemy as sa
|
||||
from _pytest.monkeypatch import MonkeyPatch
|
||||
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
|
||||
|
||||
|
||||
@ -1025,7 +1026,9 @@ def test_add_annual_report_financial_key_error(full_db: Session) -> None:
|
||||
@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}) == {
|
||||
assert data_transfer.norm_capital(
|
||||
{"value": 5, "currency": currency, "type": capital_type}
|
||||
) == {
|
||||
"capital_value": 5.0,
|
||||
"capital_currency": CurrencyEnum("EUR"),
|
||||
"capital_type": CapitalTypeEnum(capital_type),
|
||||
@ -1036,7 +1039,7 @@ def test_norm_capital_eur(currency: str, capital_type: str) -> None:
|
||||
@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(
|
||||
assert data_transfer.norm_capital(
|
||||
capital={"value": 5, "currency": currency, "type": capital_type}
|
||||
) == {
|
||||
"capital_value": 2.56,
|
||||
@ -1047,7 +1050,7 @@ def test_norm_capital_dm(currency: str, capital_type: CapitalTypeEnum) -> None:
|
||||
|
||||
def test_norm_capital_fail() -> None:
|
||||
"""Tests if the entry is dropped if it isn't complete."""
|
||||
assert norm_capital({"something": "something"}) == {} # type: ignore
|
||||
assert data_transfer.norm_capital({"something": "something"}) == {} # type: ignore
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@ -1062,3 +1065,30 @@ def test_norm_capital_fail() -> None:
|
||||
)
|
||||
def test_get_geocodes(zip_code: str | None, results: dict) -> None:
|
||||
assert data_transfer.get_geocodes(zip_code) == results
|
||||
|
||||
|
||||
def test_transfer_data_cli(monkeypatch: MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(sys, "argv", [sys.argv[0]])
|
||||
with pytest.raises(SystemExit):
|
||||
data_transfer.transfer_data_cli()
|
||||
|
||||
|
||||
def test_transfer_data_cli_help(monkeypatch: MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(sys, "argv", [sys.argv[0], "-h"])
|
||||
with pytest.raises(SystemExit):
|
||||
data_transfer.transfer_data_cli()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("upper", [True, False])
|
||||
def test_transfer_data_cli_env(
|
||||
monkeypatch: MonkeyPatch, upper: bool, mocker: MockerFixture
|
||||
) -> None:
|
||||
monkeypatch.setattr(sys, "argv", [sys.argv[0], "ENV" if upper else "env"])
|
||||
mocker.patch(
|
||||
"aki_prj23_transparenzregister.utils.data_transfer.transfer_data", lambda _: _
|
||||
)
|
||||
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