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:
5
app.py
5
app.py
@@ -97,8 +97,9 @@ def index():
|
||||
|
||||
# vCard 4.0 erzeugen und speichern
|
||||
try:
|
||||
# generate vcard using helper
|
||||
generate_vcard(adresse, BASE_DIR)
|
||||
# determine base dir: prefer app.config, then app attribute, then module BASE_DIR
|
||||
base_dir = app.config.get('BASE_DIR') if app.config.get('BASE_DIR') else getattr(app, 'BASE_DIR', BASE_DIR)
|
||||
generate_vcard(adresse, base_dir)
|
||||
except Exception:
|
||||
# nicht kritisch: bei Fehlern nicht die ganze Anfrage abbrechen
|
||||
pass
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user