Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tcsocket/app/views/appointments.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ async def appointment_webhook_delete(request):

async def appointment_webhook_clear(request):
conn = await request['conn_manager'].get_connection()
v = await conn.execute(sa_appointments.delete().where(ser_c.company == request['company'].id))
r = await conn.execute(sa_services.delete().where(ser_c.company == request['company'].id))
services = await conn.execute(select([ser_c.id]).where(ser_c.company == request['company'].id))
ids = [s[0] async for s in services]
v = await conn.execute(sa_appointments.delete().where(apt_c.service.in_(ids)))
r = await conn.execute(sa_services.delete().where(ser_c.id.in_(ids)))
return json_response(request, status='success' if r.rowcount or v.rowcount else 'appointments not found')


Expand Down
1 change: 1 addition & 0 deletions tcsocket/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ SQLAlchemy==1.3.23
aiodns==2.0.0
aiohttp==3.7.4.post0
aiopg==1.1.0
aioredis==1.3.1
arq==0.21
boto3==1.17.62
cchardet==2.1.7
Expand Down
40 changes: 36 additions & 4 deletions tests/test_appointments_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,25 @@ async def test_delete_old_appointments(db_conn, company, settings):


async def test_clear_apts(cli, db_conn, company):
company2 = await create_company(db_conn, 'compan2_public', 'compan2_private', name='company2')
await db_conn.execute(
sa_services.insert().values(
**dict(
id=2,
company=company2.id,
name='testing service',
extra_attributes=[
{
'name': 'Foobar',
'type': 'text_short',
'machine_name': 'foobar',
'value': 'this is the value of foobar',
}
],
colour='#abc',
)
)
)
await create_appointment(db_conn, company, appointment_extra={'id': 1})
for i in range(10):
await create_appointment(
Expand All @@ -187,16 +206,29 @@ async def test_clear_apts(cli, db_conn, company):
),
)

assert 11 == await count(db_conn, sa_appointments)
assert 1 == await count(db_conn, sa_services)
for i in range(11, 21):
await create_appointment(
db_conn,
company2,
create_service=False,
appointment_extra=dict(
id=i + 2,
start=datetime(2032, 1, 1, 12, 0, 0) + timedelta(days=i + 1),
finish=datetime(2032, 1, 1, 13, 0, 0) + timedelta(days=i + 1),
),
service_extra=dict(id=2),
)

assert 21 == await count(db_conn, sa_appointments)
assert 2 == await count(db_conn, sa_services)

url = cli.server.app.router['webhook-appointment-clear'].url_for(company='thepublickey')
r = await signed_request(cli, url, method_='DELETE')
assert r.status == 200
assert {'status': 'success'} == await r.json()

assert 0 == await count(db_conn, sa_appointments)
assert 0 == await count(db_conn, sa_services)
assert 10 == await count(db_conn, sa_appointments)
assert 1 == await count(db_conn, sa_services)


async def test_mass_apts(cli, db_conn, company):
Expand Down