Spaces:
Paused
Paused
| #!/usr/bin/env python3 | |
| import sys | |
| import os | |
| sys.path.append('.') | |
| from sqlalchemy.orm import Session | |
| from app.db.session import SessionLocal | |
| from app.services.project_service import ProjectService | |
| from app.schemas.project_detail import ProjectDetailOut | |
| import json | |
| def test_project_detail(): | |
| """Test the enhanced project detail with nested data""" | |
| db: Session = SessionLocal() | |
| try: | |
| service = ProjectService(db) | |
| # Test with project 3 | |
| project_no = 3 | |
| print(f"Testing Project Detail for ProjectNo: {project_no}") | |
| print("=" * 50) | |
| # Get detailed project | |
| result = service.get_detailed(project_no) | |
| if result: | |
| # Convert to dict for pretty printing | |
| if hasattr(result, 'dict'): | |
| result_dict = result.dict() | |
| else: | |
| result_dict = result | |
| print("β Project Detail Retrieved Successfully!") | |
| print(json.dumps(result_dict, indent=2, default=str)) | |
| # Check key nested data | |
| print("\n" + "=" * 50) | |
| print("NESTED DATA SUMMARY:") | |
| print("=" * 50) | |
| if isinstance(result_dict, dict): | |
| customers = result_dict.get('customers', []) | |
| project_notes = result_dict.get('projectNotes', []) | |
| print(f"π Project: {result_dict.get('projectName', 'N/A')}") | |
| print(f"π₯ Customers: {len(customers)}") | |
| for i, customer in enumerate(customers): | |
| barrier_sizes = customer.get('barrierSizes', []) | |
| contacts = customer.get('contacts', []) | |
| bidder_notes = customer.get('bidderNotes', []) | |
| print(f" Customer {i+1}: {customer.get('customerName', 'N/A')}") | |
| print(f" π§ Barrier Sizes: {len(barrier_sizes)}") | |
| print(f" π Contacts: {len(contacts)}") | |
| print(f" π Bidder Notes: {len(bidder_notes)}") | |
| print(f"π Project Notes: {len(project_notes)}") | |
| else: | |
| print("β No project found") | |
| except Exception as e: | |
| print(f"β Error: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| finally: | |
| db.close() | |
| if __name__ == "__main__": | |
| test_project_detail() |