-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_test_data.py
More file actions
204 lines (168 loc) Β· 9.21 KB
/
add_test_data.py
File metadata and controls
204 lines (168 loc) Β· 9.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/env python3
"""
Add comprehensive test data for testing all features.
"""
import sys
import os
sys.path.append(os.path.dirname(__file__))
from datetime import datetime, date, time, timedelta
from sqlalchemy.orm import Session
from app.db import SessionLocal, engine
from app.models import (
Owner, OwnerSetting, Service, Availability, Block,
Client, Appointment, Waitlist, AuditLog,
IntentMode, AppointmentStatus, AuditActor
)
from app.utils.time import to_utc, get_owner_timezone
def add_test_data():
"""Add comprehensive test data."""
db = SessionLocal()
try:
print("π Adding test data...")
# Get existing owner or create if needed
owner = db.query(Owner).first()
if not owner:
print("β No owner found. Please run the database migration first.")
return
print(f"β
Using owner: {owner.name}")
# Add more services
services_data = [
{"name": "Quick Trim", "duration_min": 15, "buffer_min": 5, "price_cents": 1500},
{"name": "Deluxe Package", "duration_min": 90, "buffer_min": 15, "price_cents": 7500},
{"name": "Beard Styling", "duration_min": 20, "buffer_min": 5, "price_cents": 2000},
{"name": "Hair Wash", "duration_min": 10, "buffer_min": 5, "price_cents": 1000},
]
for service_data in services_data:
existing = db.query(Service).filter(
Service.owner_id == owner.id,
Service.name == service_data["name"]
).first()
if not existing:
service = Service(owner_id=owner.id, **service_data)
db.add(service)
print(f" β Added service: {service_data['name']}")
db.commit()
# Add test clients
clients_data = [
{"name": "John Smith", "phone": "+1234567890"},
{"name": "Sarah Johnson", "phone": "+1234567891"},
{"name": "Mike Wilson", "phone": "+1234567892"},
{"name": "Emma Davis", "phone": "+1234567893"},
{"name": "Alex Brown", "phone": "+1234567894"},
{"name": "Lisa Garcia", "phone": "+1234567895"},
]
for client_data in clients_data:
existing = db.query(Client).filter(
Client.owner_id == owner.id,
Client.phone == client_data["phone"]
).first()
if not existing:
client = Client(owner_id=owner.id, **client_data)
db.add(client)
print(f" β Added client: {client_data['name']}")
db.commit()
# Add test appointments (mix of today, tomorrow, and future)
services = db.query(Service).filter(Service.owner_id == owner.id).all()
clients = db.query(Client).filter(Client.owner_id == owner.id).all()
if services and clients:
today = date.today()
appointments_data = [
# Today's appointments
{"date": today, "time": time(10, 0), "service_idx": 0, "client_idx": 0, "status": AppointmentStatus.CONFIRMED},
{"date": today, "time": time(14, 0), "service_idx": 1, "client_idx": 1, "status": AppointmentStatus.CONFIRMED},
{"date": today, "time": time(16, 0), "service_idx": 2, "client_idx": 2, "status": AppointmentStatus.PENDING},
# Tomorrow's appointments
{"date": today + timedelta(days=1), "time": time(9, 0), "service_idx": 0, "client_idx": 3, "status": AppointmentStatus.CONFIRMED},
{"date": today + timedelta(days=1), "time": time(11, 0), "service_idx": 3, "client_idx": 4, "status": AppointmentStatus.CONFIRMED},
{"date": today + timedelta(days=1), "time": time(15, 0), "service_idx": 1, "client_idx": 5, "status": AppointmentStatus.CONFIRMED},
# Future appointments
{"date": today + timedelta(days=3), "time": time(10, 0), "service_idx": 2, "client_idx": 0, "status": AppointmentStatus.CONFIRMED},
{"date": today + timedelta(days=5), "time": time(13, 0), "service_idx": 0, "client_idx": 1, "status": AppointmentStatus.CONFIRMED},
]
for apt_data in appointments_data:
service = services[apt_data["service_idx"] % len(services)]
client = clients[apt_data["client_idx"] % len(clients)]
start_dt_local = datetime.combine(apt_data["date"], apt_data["time"])
start_dt_utc = to_utc(start_dt_local, owner.timezone)
end_dt_utc = start_dt_utc + timedelta(minutes=service.duration_min + service.buffer_min)
# Check if appointment already exists
existing = db.query(Appointment).filter(
Appointment.owner_id == owner.id,
Appointment.start_dt == start_dt_utc
).first()
if not existing:
appointment = Appointment(
owner_id=owner.id,
client_id=client.id,
service_id=service.id,
start_dt=start_dt_utc,
end_dt=end_dt_utc,
status=apt_data["status"],
channel="Test Data",
notes=f"Test appointment for {client.name}"
)
db.add(appointment)
print(f" π
Added appointment: {client.name} - {service.name} on {apt_data['date']}")
db.commit()
# Add waitlist entries
if services and clients:
tomorrow = today + timedelta(days=1)
next_week = today + timedelta(days=7)
waitlist_data = [
{"client_idx": 2, "service_idx": 0, "window_start": datetime.combine(tomorrow, time(9, 0)), "window_end": datetime.combine(tomorrow, time(17, 0))},
{"client_idx": 3, "service_idx": 1, "window_start": datetime.combine(next_week, time(10, 0)), "window_end": datetime.combine(next_week, time(16, 0))},
{"client_idx": 4, "service_idx": 2, "window_start": datetime.combine(tomorrow, time(12, 0)), "window_end": datetime.combine(tomorrow, time(18, 0))},
]
for wait_data in waitlist_data:
service = services[wait_data["service_idx"] % len(services)]
client = clients[wait_data["client_idx"] % len(clients)]
window_start_utc = to_utc(wait_data["window_start"], owner.timezone)
window_end_utc = to_utc(wait_data["window_end"], owner.timezone)
existing = db.query(Waitlist).filter(
Waitlist.client_id == client.id,
Waitlist.service_id == service.id
).first()
if not existing:
waitlist = Waitlist(
owner_id=owner.id,
client_id=client.id,
service_id=service.id,
window_start_dt=window_start_utc,
window_end_dt=window_end_utc,
priority=1 if wait_data["client_idx"] == 2 else 0,
notify_count=0
)
db.add(waitlist)
print(f" π Added waitlist: {client.name} for {service.name}")
db.commit()
# Add some blocks (owner unavailable times)
tomorrow = today + timedelta(days=1)
blocks_data = [
{"date": today, "start_time": time(12, 0), "end_time": time(13, 0), "reason": "Lunch Break"},
{"date": tomorrow, "start_time": time(12, 30), "end_time": time(13, 30), "reason": "Personal Appointment"},
]
for block_data in blocks_data:
existing = db.query(Block).filter(
Block.owner_id == owner.id,
Block.date == block_data["date"],
Block.start_time == block_data["start_time"]
).first()
if not existing:
block = Block(owner_id=owner.id, **block_data)
db.add(block)
print(f" π« Added block: {block_data['reason']} on {block_data['date']}")
db.commit()
print("β
Test data added successfully!")
print("\nπ Summary:")
print(f" β’ Services: {db.query(Service).filter(Service.owner_id == owner.id).count()}")
print(f" β’ Clients: {db.query(Client).filter(Client.owner_id == owner.id).count()}")
print(f" β’ Appointments: {db.query(Appointment).filter(Appointment.owner_id == owner.id).count()}")
print(f" β’ Waitlist entries: {db.query(Waitlist).filter(Waitlist.owner_id == owner.id).count()}")
print(f" β’ Blocks: {db.query(Block).filter(Block.owner_id == owner.id).count()}")
except Exception as e:
print(f"β Error adding test data: {e}")
db.rollback()
finally:
db.close()
if __name__ == "__main__":
add_test_data()