Commit 40cd9a8b authored by Paris Stentoumis's avatar Paris Stentoumis
Browse files

feat: setting envs in one place. removing .env from dockerfile

parent b42a5513
Loading
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ WORKDIR /app

COPY --from=builder /app/.venv /app/.venv
COPY src/ ./src/
COPY .env ./

ENV PATH="/app/.venv/bin:$PATH"
ENV PYTHONPATH="/app/src"
+21 −13
Original line number Diff line number Diff line
@@ -14,6 +14,14 @@ from srm.adapters.database.sql import get_metadata
from srm.config import get_settings
from srm.main import create_app

TEST_SETTINGS_ENV = {
    "APP_NAME": "test-srm",
    "APP_VERSION": "0.0.1",
    "APP_DESCRIPTION": "Test SRM",
    "POSTGRES_SETTINGS__ECHO": "true",
    "POSTGRES_SETTINGS__CREATE_SCHEMA_ON_STARTUP": "true",
}


@pytest.fixture(autouse=True)
def clear_settings_cache() -> Generator[None, None, None]:
@@ -30,6 +38,12 @@ def _as_asyncpg_url(url: str) -> str:
    raise ValueError(f"Unsupported postgres URL: {url}")


def _set_test_settings_env(monkeypatch: pytest.MonkeyPatch, *, postgres_url: str) -> None:
    for key, value in TEST_SETTINGS_ENV.items():
        monkeypatch.setenv(key, value)
    monkeypatch.setenv("POSTGRES_SETTINGS__URL", postgres_url)


@pytest.fixture(scope="session")
def postgres_container() -> Iterator[PostgresContainer]:
    try:
@@ -45,14 +59,10 @@ def app_with_db(
    postgres_container: PostgresContainer,
    clean_db: None,
) -> FastAPI:
    monkeypatch.setenv("APP_NAME", "test-srm")
    monkeypatch.setenv("APP_VERSION", "0.0.1")
    monkeypatch.setenv("APP_DESCRIPTION", "Test SRM")
    monkeypatch.setenv(
        "POSTGRES_SETTINGS__URL", _as_asyncpg_url(postgres_container.get_connection_url())
    _set_test_settings_env(
        monkeypatch,
        postgres_url=_as_asyncpg_url(postgres_container.get_connection_url()),
    )
    monkeypatch.setenv("POSTGRES_SETTINGS__ECHO", "true")
    monkeypatch.setenv("POSTGRES_SETTINGS__CREATE_SCHEMA_ON_STARTUP", "true")
    return create_app()


@@ -78,12 +88,10 @@ async def clean_db(postgres_container: PostgresContainer) -> AsyncIterator[None]

@pytest.fixture
def app(monkeypatch: pytest.MonkeyPatch) -> FastAPI:
    monkeypatch.setenv("APP_NAME", "test-srm")
    monkeypatch.setenv("APP_VERSION", "0.0.1")
    monkeypatch.setenv("APP_DESCRIPTION", "Test SRM")
    monkeypatch.setenv("POSTGRES_SETTINGS__URL", "url")
    monkeypatch.setenv("POSTGRES_SETTINGS__ECHO", "true")
    monkeypatch.setenv("POSTGRES_SETTINGS__CREATE_SCHEMA_ON_STARTUP", "true")
    _set_test_settings_env(
        monkeypatch,
        postgres_url="postgresql+asyncpg://postgres:postgres@localhost:5432/srm",
    )
    return create_app()