Update conftest.py

This commit is contained in:
Dries Peeters
2025-11-14 21:34:33 +01:00
parent fdb43bf1e0
commit 07d9d13240
+19 -20
View File
@@ -360,26 +360,25 @@ def multiple_users(app):
@pytest.fixture
def test_client(app, user):
"""Create a test client (business client, not test client)."""
with app.app_context():
client_model = Client(
name='Test Client Corp',
description='Test client for integration tests',
contact_person='John Doe',
email='john@testclient.com',
phone='+1 (555) 123-4567',
address='123 Test Street, Test City, TC 12345',
default_hourly_rate=Decimal('85.00')
)
client_model.status = 'active' # Set after creation
db.session.add(client_model)
# Flush to assign primary key before commit to avoid expired attribute reloads
db.session.flush()
client_id = client_model.id
db.session.commit()
# Re-query to ensure we return a persistent instance without relying on refresh
persisted_client = Client.query.get(client_id) or Client.query.filter_by(id=client_id).first()
# Fallback to the original instance if re-query unexpectedly returns None
return persisted_client or client_model
client_model = Client(
name='Test Client Corp',
description='Test client for integration tests',
contact_person='John Doe',
email='john@testclient.com',
phone='+1 (555) 123-4567',
address='123 Test Street, Test City, TC 12345',
default_hourly_rate=Decimal('85.00')
)
client_model.status = 'active' # Set after creation
db.session.add(client_model)
# Flush to assign primary key before commit to avoid expired attribute reloads
db.session.flush()
client_id = client_model.id
db.session.commit()
# Re-query to ensure we return a persistent instance without relying on refresh
persisted_client = Client.query.get(client_id) or Client.query.filter_by(id=client_id).first()
# Fallback to the original instance if re-query unexpectedly returns None
return persisted_client or client_model
@pytest.fixture