aboutsummaryrefslogtreecommitdiff
path: root/tests/conftest.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/conftest.py')
-rw-r--r--tests/conftest.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 8f7f77c..a203775 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,7 +1,10 @@
+import os
+import shutil
+from pathlib import Path
+
import alembic
import alembic.config
import alembic.command
-import os
from pyramid.paster import get_appsettings
from pyramid.scripting import prepare
from pyramid.testing import DummyRequest, testConfig
@@ -11,8 +14,8 @@ import webtest
from sqlalchemy import delete, select
-from fietsboek import main
-from fietsboek import models
+from fietsboek import main, models
+from fietsboek.data import DataManager
from fietsboek.models.meta import Base
@@ -48,6 +51,21 @@ def dbengine(app_settings, ini_file):
Base.metadata.drop_all(bind=engine)
alembic.command.stamp(alembic_cfg, None, purge=True)
+@pytest.fixture
+def data_manager(app_settings):
+ return DataManager(Path(app_settings["fietsboek.data_dir"]))
+
+@pytest.fixture(autouse=True)
+def _cleanup_data(app_settings):
+ yield
+ engine = models.get_engine(app_settings)
+ connection = engine.connect()
+ for table in reversed(Base.metadata.sorted_tables):
+ connection.execute(table.delete())
+ data_dir = Path(app_settings["fietsboek.data_dir"])
+ if (data_dir / "tracks").is_dir():
+ shutil.rmtree(data_dir / "tracks")
+
@pytest.fixture(scope='session')
def app(app_settings, dbengine, tmp_path_factory):
app_settings["fietsboek.data_dir"] = str(tmp_path_factory.mktemp("data"))