diff --git a/tests/test_invoice_currency_fix.py b/tests/test_invoice_currency_fix.py index 8771af1..36b1153 100644 --- a/tests/test_invoice_currency_fix.py +++ b/tests/test_invoice_currency_fix.py @@ -52,6 +52,7 @@ def test_user(app): user = User(username='testuser', role='admin', email='test@example.com') db.session.add(user) db.session.commit() + db.session.refresh(user) # Refresh to keep object in session return user @@ -59,13 +60,15 @@ def test_user(app): def test_client_model(app, test_user): """Create a test client""" with app.app_context(): + # Re-query user to get it in this session + user = db.session.get(User, test_user.id) client = Client( name='Test Client', - email='client@example.com', - created_by=test_user.id + email='client@example.com' ) db.session.add(client) db.session.commit() + db.session.refresh(client) # Refresh to keep object in session return client @@ -73,16 +76,20 @@ def test_client_model(app, test_user): def test_project(app, test_user, test_client_model): """Create a test project""" with app.app_context(): + # Re-query user and client to get them in this session + user = db.session.get(User, test_user.id) + client = db.session.get(Client, test_client_model.id) project = Project( name='Test Project', - client_id=test_client_model.id, - created_by=test_user.id, + client_id=client.id, billable=True, - hourly_rate=Decimal('100.00'), - status='active' + hourly_rate=Decimal('100.00') ) + project.created_by = user.id + project.status = 'active' db.session.add(project) db.session.commit() + db.session.refresh(project) # Refresh to keep object in session return project diff --git a/tests/test_invoice_currency_smoke.py b/tests/test_invoice_currency_smoke.py index 3b04c53..77db9d9 100644 --- a/tests/test_invoice_currency_smoke.py +++ b/tests/test_invoice_currency_smoke.py @@ -37,19 +37,22 @@ def test_invoice_currency_smoke(app): # Setup: Create user, client, project user = User(username='smokeuser', role='admin', email='smoke@example.com') db.session.add(user) + db.session.flush() # Flush to get user.id - client = Client(name='Smoke Client', email='client@example.com', created_by=1) + client = Client(name='Smoke Client', email='client@example.com') db.session.add(client) + db.session.flush() # Flush to get client.id project = Project( name='Smoke Project', - client_id=1, - created_by=1, + client_id=client.id, billable=True, - hourly_rate=Decimal('100.00'), - status='active' + hourly_rate=Decimal('100.00') ) + project.created_by = user.id + project.status = 'active' db.session.add(project) + db.session.flush() # Flush to get project.id # Set currency in settings settings = Settings.get_settings() @@ -82,19 +85,22 @@ def test_pdf_generator_uses_settings_currency(app): # Setup user = User(username='pdfuser', role='admin', email='pdf@example.com') db.session.add(user) + db.session.flush() # Flush to get user.id - client = Client(name='PDF Client', email='pdf@example.com', created_by=1) + client = Client(name='PDF Client', email='pdf@example.com') db.session.add(client) + db.session.flush() # Flush to get client.id project = Project( name='PDF Project', - client_id=1, - created_by=1, + client_id=client.id, billable=True, - hourly_rate=Decimal('150.00'), - status='active' + hourly_rate=Decimal('150.00') ) + project.created_by = user.id + project.status = 'active' db.session.add(project) + db.session.flush() # Flush to get project.id settings = Settings.get_settings() settings.currency = 'SEK'