import os os.environ["SECRET_KEY"] = os.getenv("TEST_SECRET_KEY", "test-secret-key-for-testing-only") from app import create_app, db from app.models import User, Quotation from datetime import datetime, date def test_user_quotation_relationship(): app = create_app() with app.app_context(): # Create a test user test_user = User( username='testuser', email='test@example.com', password_hash='test_hash' ) db.session.add(test_user) db.session.commit() print(f"Created test user: {test_user}") # Create a test quotation test_quotation = Quotation( user_id=test_user.id, mold_shop_name='Test Shop', model_name='Test Model', tooling_id='12345', season='Spring', stage='Development', country='USA', issue_date=date.today(), approver='Test Approver', approval_date=date.today(), mold_main_type='Injection', mold_sub_type='Standard', sliders_count=2, cavity_count=1, digital_texture_type='Basic', base_price=1000.0, total_cost=1100.0 ) db.session.add(test_quotation) db.session.commit() print(f"Created test quotation: {test_quotation}") # Test the relationship from User to Quotation user_quotations = test_user.quotations print(f"\nUser's quotations: {user_quotations}") print(f"Number of quotations: {len(user_quotations)}") # Test the relationship from Quotation to User quotation_user = test_quotation.user print(f"\nQuotation's user: {quotation_user}") print(f"User ID matches: {quotation_user.id == test_user.id}") # Clean up db.session.delete(test_quotation) db.session.delete(test_user) db.session.commit() print("\nTest completed successfully!") if __name__ == '__main__': test_user_quotation_relationship()