Skip to content

Commit 7612bd5

Browse files
committed
Mass apt changes
1 parent 6e1e686 commit 7612bd5

File tree

3 files changed

+62
-53
lines changed

3 files changed

+62
-53
lines changed

tcsocket/app/validation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def val_upstream_http_referrer(cls, v):
189189

190190

191191
class AppointmentModel(BaseModel):
192+
id: int
192193
service_id: int
193194
service_name: str
194195
extra_attributes: List[ExtraAttributeModel]

tcsocket/app/views/appointments.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ async def appointment_webhook(request):
8080
async def appointment_webhook_mass(request):
8181
conn = await request['conn_manager'].get_connection()
8282
data = await request.json()
83-
if data['_request_time']:
84-
del data['_request_time']
85-
for apt_id, apt in data.items():
83+
for apt in data['appointments']:
8684
if apt['ss_method'] == 'POST':
8785
appointment = AppointmentModel(**apt)
8886

@@ -128,16 +126,16 @@ async def appointment_webhook_mass(request):
128126

129127
await conn.execute(
130128
pg_insert(sa_appointments)
131-
.values(id=apt_id, service=appointment.service_id, **apt_insert_update)
129+
.values(id=appointment.id, service=appointment.service_id, **apt_insert_update)
132130
.on_conflict_do_update(
133131
index_elements=[apt_c.id],
134-
where=apt_c.id == apt_id,
132+
where=apt_c.id == appointment.id,
135133
set_=apt_insert_update,
136134
)
137135
)
138136
elif apt['ss_method'] == 'DELETE':
139137
await conn.execute(
140-
sa_appointments.delete().where(and_(apt_c.id == apt_id, ser_c.company == request['company'].id))
138+
sa_appointments.delete().where(and_(apt_c.id == apt['id'], ser_c.company == request['company'].id))
141139
)
142140
else:
143141
return

tests/test_appointments_set.py

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
async def create_apt(cli, company, url=None, **kwargs):
1010
data = dict(
11+
id=123,
1112
service_id=123,
1213
service_name='testing service',
1314
extra_attributes=[],
@@ -203,22 +204,25 @@ async def test_mass_apts(cli, db_conn, company):
203204
assert 1 == await count(db_conn, sa_appointments)
204205
assert 1 == await count(db_conn, sa_services)
205206

206-
data = dict()
207+
data = {'appointments': []}
207208
for i in range(10):
208-
data[str(i + 2)] = dict(
209-
service_id=1,
210-
service_name='test service',
211-
extra_attributes=[],
212-
colour='#000000',
213-
appointment_topic='testing appointment',
214-
attendees_max=42,
215-
attendees_count=4,
216-
attendees_current_ids=[1, 2, 3],
217-
start=str(datetime(2032, 1, 1, 12, 0, 0) + timedelta(days=i + 1)),
218-
finish=str(datetime(2032, 1, 1, 13, 0, 0) + timedelta(days=i + 1)),
219-
price=123.45,
220-
location='Whatever',
221-
ss_method='POST',
209+
data['appointments'].append(
210+
dict(
211+
id=i + 2,
212+
service_id=1,
213+
service_name='test service',
214+
extra_attributes=[],
215+
colour='#000000',
216+
appointment_topic='testing appointment',
217+
attendees_max=42,
218+
attendees_count=4,
219+
attendees_current_ids=[1, 2, 3],
220+
start=str(datetime(2032, 1, 1, 12, 0, 0) + timedelta(days=i + 1)),
221+
finish=str(datetime(2032, 1, 1, 13, 0, 0) + timedelta(days=i + 1)),
222+
price=123.45,
223+
location='Whatever',
224+
ss_method='POST',
225+
)
222226
)
223227
url = cli.server.app.router['webhook-appointment-mass'].url_for(company='thepublickey')
224228
r = await signed_request(cli, url, **data)
@@ -228,25 +232,28 @@ async def test_mass_apts(cli, db_conn, company):
228232
assert 11 == await count(db_conn, sa_appointments)
229233
assert 1 == await count(db_conn, sa_services)
230234

231-
data = dict()
235+
data = {'appointments': []}
232236
for i in range(9):
233-
data[str(i + 2)] = dict(
234-
service_id=1,
235-
service_name='test service',
236-
extra_attributes=[],
237-
colour='#000000',
238-
appointment_topic='testing appointment',
239-
attendees_max=42,
240-
attendees_count=4,
241-
attendees_current_ids=[1, 2, 3],
242-
start=str(datetime(2032, 1, 1, 12, 0, 0) + timedelta(days=i + 1)),
243-
finish=str(datetime(2032, 1, 1, 13, 0, 0) + timedelta(days=i + 1)),
244-
price=123.45,
245-
location='Whatever',
246-
ss_method='POST',
237+
data['appointments'].append(
238+
dict(
239+
id=i + 2,
240+
service_id=1,
241+
service_name='test service',
242+
extra_attributes=[],
243+
colour='#000000',
244+
appointment_topic='testing appointment',
245+
attendees_max=42,
246+
attendees_count=4,
247+
attendees_current_ids=[1, 2, 3],
248+
start=str(datetime(2032, 1, 1, 12, 0, 0) + timedelta(days=i + 1)),
249+
finish=str(datetime(2032, 1, 1, 13, 0, 0) + timedelta(days=i + 1)),
250+
price=123.45,
251+
location='Whatever',
252+
ss_method='POST',
253+
)
247254
)
248-
data['10'] = {'ss_method': 'DELETE'}
249-
data['11'] = {'ss_method': 'DELETE'}
255+
data['appointments'].append({'id': 10, 'ss_method': 'DELETE'})
256+
data['appointments'].append({'id': 11, 'ss_method': 'DELETE'})
250257
url = cli.server.app.router['webhook-appointment-mass'].url_for(company='thepublickey')
251258
r = await signed_request(cli, url, **data)
252259
assert r.status == 200
@@ -261,22 +268,25 @@ async def test_mass_apts_and_services(cli, db_conn, company):
261268
assert 1 == await count(db_conn, sa_appointments)
262269
assert 1 == await count(db_conn, sa_services)
263270

264-
data = dict()
271+
data = {'appointments': []}
265272
for i in range(10):
266-
data[str(i + 2)] = dict(
267-
service_id=i + 2,
268-
service_name='test service',
269-
extra_attributes=[],
270-
colour='#000000',
271-
appointment_topic='testing appointment',
272-
attendees_max=42,
273-
attendees_count=4,
274-
attendees_current_ids=[1, 2, 3],
275-
start=str(datetime(2032, 1, 1, 12, 0, 0) + timedelta(days=i + 1)),
276-
finish=str(datetime(2032, 1, 1, 13, 0, 0) + timedelta(days=i + 1)),
277-
price=123.45,
278-
location='Whatever',
279-
ss_method='POST',
273+
data['appointments'].append(
274+
dict(
275+
id=i + 2,
276+
service_id=i + 2,
277+
service_name='test service',
278+
extra_attributes=[],
279+
colour='#000000',
280+
appointment_topic='testing appointment',
281+
attendees_max=42,
282+
attendees_count=4,
283+
attendees_current_ids=[1, 2, 3],
284+
start=str(datetime(2032, 1, 1, 12, 0, 0) + timedelta(days=i + 1)),
285+
finish=str(datetime(2032, 1, 1, 13, 0, 0) + timedelta(days=i + 1)),
286+
price=123.45,
287+
location='Whatever',
288+
ss_method='POST',
289+
)
280290
)
281291
url = cli.server.app.router['webhook-appointment-mass'].url_for(company='thepublickey')
282292
r = await signed_request(cli, url, **data)

0 commit comments

Comments
 (0)