Files
service-finder/archive/2026-03-29/backend/test_asset_schema.py
2026-03-30 06:32:22 +00:00

44 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""Test the AssetCreate schema changes"""
import sys
sys.path.insert(0, 'backend')
from app.schemas.asset import AssetCreate
from pydantic import ValidationError
print("Testing AssetCreate schema...")
# Test 1: Minimal payload with only license_plate
try:
data = {"license_plate": "ABC123"}
asset = AssetCreate(**data)
print(f"✓ Test 1 passed: Minimal payload accepted")
print(f" vin: {asset.vin}, catalog_id: {asset.catalog_id}, organization_id: {asset.organization_id}")
except ValidationError as e:
print(f"✗ Test 1 failed: {e}")
# Test 2: Payload with all optional fields None
try:
data = {"license_plate": "DEF456", "vin": None, "catalog_id": None, "organization_id": None}
asset = AssetCreate(**data)
print(f"✓ Test 2 passed: All optional fields can be None")
except ValidationError as e:
print(f"✗ Test 2 failed: {e}")
# Test 3: Full payload
try:
data = {"license_plate": "GHI789", "vin": "1HGBH41JXMN109186", "catalog_id": 1, "organization_id": 1}
asset = AssetCreate(**data)
print(f"✓ Test 3 passed: Full payload accepted")
except ValidationError as e:
print(f"✗ Test 3 failed: {e}")
# Test 4: Missing required license_plate (should fail)
try:
data = {"vin": "1HGBH41JXMN109186"}
asset = AssetCreate(**data)
print(f"✗ Test 4 failed: Should have required license_plate")
except ValidationError as e:
print(f"✓ Test 4 passed: Missing license_plate correctly rejected")
print("\nSchema validation tests completed.")