60 lines
2.2 KiB
Python
60 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test that the optimized asset router maintains schema compatibility.
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
from pydantic import ValidationError
|
|
from schemas.asset import AssetListResponse, AssetResponse
|
|
|
|
def test_schema_compatibility():
|
|
BASE_URL = 'http://localhost:8000'
|
|
|
|
# Login
|
|
login_response = requests.post(f'{BASE_URL}/auth/login', json={'email': 'admin@vfx.com', 'password': 'admin123'})
|
|
if login_response.status_code != 200:
|
|
print("❌ Login failed")
|
|
return
|
|
|
|
token = login_response.json()['access_token']
|
|
headers = {'Authorization': f'Bearer {token}'}
|
|
|
|
print('Testing schema compatibility...')
|
|
|
|
# Test list assets schema
|
|
response = requests.get(f'{BASE_URL}/assets/?project_id=2', headers=headers)
|
|
if response.status_code == 200:
|
|
assets_data = response.json()
|
|
|
|
try:
|
|
# Validate each asset against AssetListResponse schema
|
|
for asset_data in assets_data:
|
|
asset = AssetListResponse.model_validate(asset_data)
|
|
# If we get here, validation passed
|
|
|
|
print(f'✅ List assets schema validation passed for {len(assets_data)} assets')
|
|
|
|
# Test single asset schema if we have assets
|
|
if assets_data:
|
|
asset_id = assets_data[0]['id']
|
|
response = requests.get(f'{BASE_URL}/assets/{asset_id}', headers=headers)
|
|
|
|
if response.status_code == 200:
|
|
asset_data = response.json()
|
|
|
|
try:
|
|
asset = AssetResponse.model_validate(asset_data)
|
|
print('✅ Single asset schema validation passed')
|
|
except ValidationError as e:
|
|
print(f'❌ Single asset schema validation failed: {e}')
|
|
else:
|
|
print(f'❌ Failed to get single asset: {response.status_code}')
|
|
|
|
except ValidationError as e:
|
|
print(f'❌ List assets schema validation failed: {e}')
|
|
else:
|
|
print(f'❌ Failed to get assets: {response.status_code}')
|
|
|
|
if __name__ == "__main__":
|
|
test_schema_compatibility() |