from datetime import datetime, timedelta from pony.orm import db_session from ITPlanning.db import Appointment from json import loads from ..testBase import APITestBase from ..assets.filldb import filldatabase class AppointmentTestCase(APITestBase): def setUp(self): super().setUp() def test_get_appointement(self): self.make_request("appointment/", 404) 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) 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)