Initial Commit: Status Testing
This commit is contained in:
1 parent
1eff675f05
commit
42dd1f2d4a
286 files changed
+64800
-369
No files matched your search
@@ -0,0 +1,62 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""Gemeinsame Test-Hilfen.
|
||||
|
||||
Tests mit dem Marker `db` laufen nur, wenn SURVEYBOX_TEST_DB=1 gesetzt ist
|
||||
und die SURVEYBOX_DB_*-Variablen auf eine Wegwerf-Datenbank zeigen (CI).
|
||||
Die Datenbank wird dabei geleert!
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]) -> None:
|
||||
if os.environ.get("SURVEYBOX_TEST_DB") == "1":
|
||||
return
|
||||
skip = pytest.mark.skip(reason="SURVEYBOX_TEST_DB=1 nicht gesetzt")
|
||||
for item in items:
|
||||
if "db" in item.keywords:
|
||||
item.add_marker(skip)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def db_settings(tmp_path, monkeypatch: pytest.MonkeyPatch): # type: ignore[no-untyped-def]
|
||||
"""Einstellungen mit leerem Datenverzeichnis und frischem Schema."""
|
||||
pytest.importorskip("sqlalchemy")
|
||||
from sqlalchemy import text
|
||||
|
||||
from surveybox import db
|
||||
from surveybox import settings as settings_mod
|
||||
|
||||
monkeypatch.setenv("SURVEYBOX_DATA_DIR", str(tmp_path / "data"))
|
||||
settings_mod.get_settings.cache_clear()
|
||||
db.get_engine.cache_clear()
|
||||
engine = db.get_engine()
|
||||
with engine.begin() as conn:
|
||||
conn.execute(text(f"DROP SCHEMA IF EXISTS {db.DB_SCHEMA} CASCADE"))
|
||||
yield settings_mod.get_settings()
|
||||
engine.dispose()
|
||||
settings_mod.get_settings.cache_clear()
|
||||
db.get_engine.cache_clear()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app(db_settings): # type: ignore[no-untyped-def]
|
||||
"""Web-Anwendung auf frisch migrierter Datenbank."""
|
||||
from surveybox import db
|
||||
from surveybox.upgrade import run_upgrade
|
||||
from surveybox.web.app import create_app
|
||||
|
||||
run_upgrade(db_settings, db.get_engine())
|
||||
return create_app()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(app): # type: ignore[no-untyped-def]
|
||||
from helpers import new_client
|
||||
|
||||
with new_client(app) as c:
|
||||
yield c
|
||||
Reference in new issue
Block a user