2026.03.29 20:00 Gitea_manager javítás előtt
This commit is contained in:
44
backend/test_asset_schema.py
Normal file
44
backend/test_asset_schema.py
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/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.")
|
||||
Reference in New Issue
Block a user