diff --git a/app.py b/app.py index 5bd526c..222ee72 100644 --- a/app.py +++ b/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 diff --git a/tests/test_vcard_export.py b/tests/test_vcard_export.py index 94fdc1b..0802757 100644 --- a/tests/test_vcard_export.py +++ b/tests/test_vcard_export.py @@ -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