ab-ms-core / tests /unit /test_project_detail.py
PupaClic
Add comprehensive unit tests for various endpoints and features
7ff20d3
#!/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()