-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_validation.py
More file actions
180 lines (145 loc) · 4.74 KB
/
Copy pathtest_validation.py
File metadata and controls
180 lines (145 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
"""
Simple validation tests for the pet shop system.
Tests model validation, imports, and basic functionality.
"""
from pydantic import ValidationError
from models import (
BrowsePetsInput,
CheckOrderStatusInput,
CustomerInfo,
Order,
OrderItem,
OrderStatus,
Pet,
PetType,
PlaceOrderInput,
)
def test_pet_model():
"""Test Pet model validation"""
print("Testing Pet model...")
pet = Pet(
id="test001",
name="Test Dog",
type=PetType.DOG,
description="A test dog",
price=100.0,
age_months=6,
available=True,
)
assert pet.id == "test001"
assert pet.type == "dog" # Enum should be converted to value
assert pet.price == 100.0
print("✓ Pet model validation passed")
def test_order_model():
"""Test Order model validation"""
print("Testing Order model...")
customer = CustomerInfo(name="Test Customer", email="test@example.com", phone="555-0123", address="123 Test St")
item = OrderItem(pet_id="test001", pet_name="Test Dog", price=100.0)
order = Order(id="ORD-TEST", customer=customer, items=[item], total_amount=100.0, status=OrderStatus.PENDING)
assert order.id == "ORD-TEST"
assert order.customer.name == "Test Customer"
assert len(order.items) == 1
assert order.total_amount == 100.0
assert order.status == "pending"
print("✓ Order model validation passed")
def test_tool_input_models():
"""Test tool input models"""
print("Testing tool input models...")
# Test BrowsePetsInput
browse_input = BrowsePetsInput(pet_type=PetType.CAT, max_price=500.0)
assert browse_input.pet_type == "cat"
assert browse_input.max_price == 500.0
# Test PlaceOrderInput
place_order = PlaceOrderInput(
customer_name="Test",
customer_email="test@example.com",
customer_phone="555-0123",
delivery_address="123 Test St",
pet_ids=["pet001"],
)
assert len(place_order.pet_ids) == 1
# Test CheckOrderStatusInput
check_status = CheckOrderStatusInput(order_id="ORD-TEST")
assert check_status.order_id == "ORD-TEST"
print("✓ Tool input models validation passed")
def test_imports():
"""Test that all imports work"""
print("Testing imports...")
try:
# models symbols are imported at module level via 'from models import ...'
_pet = Pet(
id="import-test",
name="Import Test Pet",
type=PetType.DOG,
description="Import test",
price=1.0,
age_months=1,
available=True,
)
import tools
print("✓ models symbols imported successfully")
print("✓ tools.py imports successfully")
# Check tool definitions exist
assert len(tools.TOOLS_DEFINITIONS) == 3
assert len(tools.TOOLS_MAP) == 3
assert "browse_pets" in tools.TOOLS_MAP
assert "place_order" in tools.TOOLS_MAP
assert "check_order_status" in tools.TOOLS_MAP
print("✓ Tool definitions are complete")
except ImportError as e:
print(f"✗ Import error: {e}")
raise
def test_pydantic_validation():
"""Test Pydantic validation works"""
print("Testing Pydantic validation...")
try:
# Should fail - negative price
Pet(
id="test",
name="Test",
type=PetType.DOG,
description="Test",
price=-100.0, # Invalid
age_months=6,
available=True,
)
print("✗ Validation should have failed for negative price")
except ValidationError:
print("✓ Pydantic validation working (negative price rejected)")
try:
# Should fail - empty name
PlaceOrderInput(
customer_name="", # Invalid
customer_email="test@example.com",
customer_phone="555",
delivery_address="123 Test St",
pet_ids=["pet001"],
)
print("✗ Validation should have failed for empty name")
except ValidationError:
print("✓ Pydantic validation working (empty name rejected)")
def main():
"""Run all tests"""
print("\n" + "=" * 50)
print("Pet Shop System Validation Tests")
print("=" * 50 + "\n")
try:
test_imports()
print()
test_pet_model()
print()
test_order_model()
print()
test_tool_input_models()
print()
test_pydantic_validation()
print("\n" + "=" * 50)
print("✓ All validation tests passed!")
print("=" * 50 + "\n")
except Exception as e:
print("\n" + "=" * 50)
print(f"✗ Tests failed: {e}")
print("=" * 50 + "\n")
raise
if __name__ == "__main__":
main()