-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_test_data.py
More file actions
162 lines (137 loc) · 5.21 KB
/
setup_test_data.py
File metadata and controls
162 lines (137 loc) · 5.21 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
#!/usr/bin/env python3
"""
Setup test data for the appointment system.
Creates a sample owner with services for testing.
"""
import sys
import os
sys.path.append(os.path.dirname(__file__))
from datetime import time, datetime
from app.db import SessionLocal
from app.models import (
Owner, OwnerSetting, Service, Availability,
IntentMode
)
def create_test_owner():
"""Create a test business owner with services."""
db = SessionLocal()
try:
# Check if owner already exists
existing_owner = db.query(Owner).filter(Owner.phone == "+972501234567").first()
if existing_owner:
print(f"✅ Owner already exists: {existing_owner.name}")
return existing_owner
# Create owner
owner = Owner(
phone="+972501234567",
name="David's Barbershop",
timezone="Asia/Jerusalem",
default_intent=IntentMode.BALANCED,
quiet_hours_start=time(22, 0),
quiet_hours_end=time(8, 0)
)
db.add(owner)
db.flush() # Get the ID
# Create owner settings
settings = OwnerSetting(
owner_id=owner.id,
lead_time_min=60,
cancel_window_hr=24,
reminder_hours=[24, 2],
max_outreach_per_gap=5
)
db.add(settings)
# Create availability (Monday-Friday, 9-17)
for weekday in range(5): # 0=Monday, 4=Friday
availability = Availability(
owner_id=owner.id,
weekday=weekday,
start_time=time(9, 0),
end_time=time(17, 0),
active=True
)
db.add(availability)
# Create services
services_data = [
{"name": "Haircut", "duration": 30, "price": 5000, "buffer": 10}, # $50
{"name": "Haircut + Beard", "duration": 45, "price": 7000, "buffer": 15}, # $70
{"name": "Beard Trim", "duration": 20, "price": 3000, "buffer": 10}, # $30
{"name": "Hair Wash", "duration": 15, "price": 2000, "buffer": 5}, # $20
]
for service_data in services_data:
service = Service(
owner_id=owner.id,
name=service_data["name"],
duration_min=service_data["duration"],
price_cents=service_data["price"],
buffer_min=service_data["buffer"],
active=True
)
db.add(service)
db.commit()
print(f"✅ Created test owner: {owner.name}")
print(f" Phone: {owner.phone}")
print(f" Services: {len(services_data)}")
print(f" Availability: Monday-Friday 9:00-17:00")
return owner
except Exception as e:
db.rollback()
print(f"❌ Error creating test owner: {e}")
raise
finally:
db.close()
def show_test_data():
"""Show existing test data."""
db = SessionLocal()
try:
owners = db.query(Owner).all()
if not owners:
print("📭 No owners found in database")
return
for owner in owners:
print(f"\n👔 Owner: {owner.name}")
print(f" Phone: {owner.phone}")
print(f" Timezone: {owner.timezone}")
print(f" Intent: {owner.default_intent.value}")
# Show services
services = db.query(Service).filter(
Service.owner_id == owner.id,
Service.active == True
).all()
print(f"\n💼 Services ({len(services)}):")
for service in services:
price = f"${service.price_cents / 100:.0f}"
duration = f"{service.duration_min}min"
buffer = f"+{service.buffer_min}min buffer" if service.buffer_min > 0 else ""
print(f" • {service.name} - {duration} - {price} {buffer}")
# Show availability
availabilities = db.query(Availability).filter(
Availability.owner_id == owner.id,
Availability.active == True
).all()
if availabilities:
print(f"\n📅 Availability:")
weekdays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
for avail in availabilities:
day = weekdays[avail.weekday]
print(f" • {day}: {avail.start_time.strftime('%H:%M')}-{avail.end_time.strftime('%H:%M')}")
except Exception as e:
print(f"❌ Error showing test data: {e}")
finally:
db.close()
def main():
"""Main function."""
print("🔧 Test Data Setup")
print("=" * 30)
if len(sys.argv) > 1 and sys.argv[1] == "show":
show_test_data()
else:
create_test_owner()
print("\n" + "=" * 30)
show_test_data()
print(f"\n💡 Tips:")
print(f" • Use phone +972501234567 to test as owner")
print(f" • Use any other phone to test as client")
print(f" • Run 'python setup_test_data.py show' to view data")
if __name__ == "__main__":
main()