itplanning/tests/api/test_appointment.py

87 lines
3.1 KiB
Python
Raw Permalink Normal View History

2021-06-21 20:34:59 +00:00
from datetime import datetime, timedelta
2021-06-01 12:16:05 +00:00
from pony.orm import db_session
2021-06-21 20:34:59 +00:00
from ITPlanning.db import Appointment
from json import loads
from ..testBase import APITestBase
from ..assets.filldb import filldatabase
2021-06-01 12:16:05 +00:00
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)
2021-06-21 20:34:59 +00:00
def test_post_appointment(self):
with db_session:
service = filldatabase.create_service()
customer = filldatabase.create_Customer()
planning = filldatabase.create_planning()
planning.services.add(service)
req = self.make_request(
"appointment",
201,
{
"start_datetime": datetime.now().strftime("%Y-%m-%dT%H%M"),
"planning": planning.id,
"service": service.id,
},
"post",
)
print(req)