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:
2023-10-02 20:31:42 +02:00
committed by GitHub
parent 2abe12f027
commit d2d4a436f8
22 changed files with 650 additions and 304 deletions

View File

@@ -1,13 +1,20 @@
"""Test if the sql db can be copied."""
import os
import sys
from collections.abc import Generator
import pandas as pd
import pytest
from _pytest.monkeypatch import MonkeyPatch
from sqlalchemy.engine import Engine
from sqlalchemy.orm import Session
from sqlalchemy.orm import Session, sessionmaker
from aki_prj23_transparenzregister.utils.sql.connector import Base, get_session, init_db
from aki_prj23_transparenzregister.config.config_template import SQLiteConnectionString
from aki_prj23_transparenzregister.utils.sql.connector import (
Base,
get_engine,
init_db,
)
from aki_prj23_transparenzregister.utils.sql.copy_sql import (
copy_db_cli,
transfer_db_function,
@@ -19,7 +26,13 @@ def destination_db() -> Generator[Session, None, None]:
"""Generates a db Session to a sqlite db to copy data to."""
if os.path.exists("secondary.db"):
os.remove("secondary.db")
db = get_session("sqlite:///secondary.db")
db = sessionmaker(
autocommit=False,
autoflush=False,
bind=get_engine(SQLiteConnectionString("secondary.db")),
)()
init_db(db)
yield db
db.close()
@@ -44,13 +57,15 @@ def test_transfer_db(full_db: Session, destination_db: Session) -> None:
)
def test_copy_db_cli_help1() -> None:
def test_copy_db_cli_help1(monkeypatch: MonkeyPatch) -> None:
"""Tests if the help argument exits the software gracefully."""
with pytest.raises(SystemExit):
copy_db_cli(["-h"])
with monkeypatch.context() as m, pytest.raises(SystemExit): # noqa: PT012
m.setattr(sys, "argv", [sys.argv[0], "-h"])
copy_db_cli()
def test_copy_db_cli_help2() -> None:
def test_copy_db_cli_help2(monkeypatch: MonkeyPatch) -> None:
"""Tests if the help argument exits the software gracefully."""
with pytest.raises(SystemExit):
copy_db_cli(["eskse", "-h", "asdf"])
with monkeypatch.context() as m, pytest.raises(SystemExit): # noqa: PT012
m.setattr(sys, "argv", [sys.argv[0], "eskse", "-h", "asdf"])
copy_db_cli()