itplanning/tests/api/test_appointment.py

66 lines
2.4 KiB
Python
Raw Normal View History

2021-06-01 12:16:05 +00:00
from ..testBase import APITestBase
from pony.orm import db_session
class AppointmentTestCase(APITestBase):
def setUp(self):
super().setUp()
def test_get_appointement(self):
2021-06-13 19:03:49 +00:00
self.make_request("appointment/", 404)
2021-06-21 20:34:17 +00:00
self.make_request("appointment/1", 404)
current_date = datetime.now()
with db_session:
service = filldatabase.create_service()
customer = filldatabase.create_Customer()
planning = filldatabase.create_planning()
planning.services.add(service)
end_datetime = current_date + timedelta(
minutes=service.service_category.duration
)
appointment = Appointment(
book_datetime=current_date,
start_datetime=current_date,
end_datetime=end_datetime,
is_unavaillable=False,
service=service,
planning=planning,
customer=customer,
)
start_datetime2 = current_date + timedelta(days=2)
end_datetime2 = start_datetime2 + timedelta(
minutes=service.service_category.duration
)
appointment2 = Appointment(
book_datetime=current_date,
start_datetime=start_datetime2,
end_datetime=end_datetime2,
is_unavaillable=False,
service=service,
planning=planning,
customer=customer,
)
req, data = self.make_request("appointment/", 200)
self.assertEqual(len(data), 2)
req, data = self.make_request("appointment/1", 200)
self.assertEqual(len(data), 1)
filteringdate = (current_date + timedelta(days=1)).strftime("%Y-%m-%dT%H%M")
req, data = self.make_request("appointment/", 200, {"after": filteringdate})
self.assertEqual(len(data), 1)
req, data = self.make_request("appointment/", 200, {"before": filteringdate})
self.assertEqual(len(data), 1)
req, data = self.make_request("appointment/planning/", 404)
req, data = self.make_request("appointment/planning/1", 200)
req, data = self.make_request("appointment/service/1", 200)
req, data = self.make_request("appointment/customer/1", 200)
req, data = self.make_request("appointment/ticket/1", 200)