Refactor: extract vCard generator to utils; make BASE_DIR configurable for tests; add unit and integration tests for vcard export; update app to use utils

This commit is contained in:
Albert
2025-11-09 19:56:46 +01:00
parent 998574f26a
commit 62613a2f39
2 changed files with 9 additions and 5 deletions

View File

@@ -5,7 +5,7 @@ from app import app, db, Frage
@pytest.fixture
def client(tmp_path, monkeypatch):
def client(tmp_path):
# Use a temporary directory for vcards and a temporary sqlite db
# temp DB file
db_file = tmp_path / "test.db"
@@ -25,12 +25,14 @@ def client(tmp_path, monkeypatch):
q = Frage(text='Testfrage?')
db.session.add(q)
db.session.commit()
# record question id for use in test POST data
app.config['TEST_QUESTION_ID'] = q.id
with app.test_client() as test_client:
yield test_client
def test_vcard_created_after_submit(client, tmp_path):
def test_vcard_created_after_submit(client):
data = {
'vorname': 'Max',
'nachname': 'Mustermann',
@@ -42,7 +44,8 @@ def test_vcard_created_after_submit(client, tmp_path):
'telefon_vorwahl': '49',
'telefon_nummer': '1234567',
'email': 'max@example.com',
'frage_1': 'Antwort'
# question id set in fixture
f'frage_{app.config.get("TEST_QUESTION_ID")}': 'Antwort'
}
# Submit the form