def test_two_appointments_not_overlapping(self):
        """
        Two appointments where the start and end time are not overlapping and not close to each other should not
        cause issues
        """
        data = self.data()
        data['start'] = next_tuesday().replace(hour=9, minute=0)
        appointment = book_appointment(**data)
        self.assertIsInstance(appointment, Appointment)

        data['start'] = next_tuesday().replace(hour=9, minute=45)
        appointment = book_appointment(**data)
        self.assertIsInstance(appointment, Appointment)
    def test_two_appointments_start_on_end_of_previous(self):
        """
        Appointment starts on the same minute another one has finished
        Should create Appointment
        """
        data = self.data()
        # Starts at 9 finishes at 9:30
        data['start'] = next_tuesday().replace(hour=9, minute=0)
        appointment = book_appointment(**data)
        self.assertIsInstance(appointment, Appointment)

        # Starts at 9:30 (the end of previous appointment)
        data['start'] = next_tuesday().replace(hour=9, minute=30)
        appointment = book_appointment(**data)
        self.assertIsInstance(appointment, Appointment)
    def test_appointment_finishing_in_middle_of_another_canceled(self):
        """
        Booking an appointment that starts at another end and finishes at another start
        :return:
        """
        data = self.data()

        data['start'] = next_tuesday().replace(hour=9, minute=30)
        appointment = book_appointment(**data)
        self.assertIsInstance(appointment, Appointment)

        reject_appointment(appointment)

        data['start'] = next_tuesday().replace(hour=9, minute=15)
        self.assertIsInstance(book_appointment(**data), Appointment)
    def test_two_appointments_end_on_start_of_previous(self):
        """
        When a appointment ends on the same minute another one has started
        this should not fail
        """
        data = self.data()
        # Start at 9:45
        data['start'] = next_tuesday().replace(hour=9, minute=45)
        appointment = book_appointment(**data)
        self.assertIsInstance(appointment, Appointment)

        # Starts at 9:15 finishes at 9:45 (start of previous appointment)
        data['start'] = next_tuesday().replace(hour=9, minute=15)
        appointment = book_appointment(**data)
        self.assertIsInstance(appointment, Appointment)
    def test_appointment_between_2_appointments_exact_times(self):
        """
        Booking an appointment that starts at another end and finishes at another start
        :return:
        """
        print('test_appointment_between_2_appointments_exact_times')
        data = self.data()

        data['start'] = next_tuesday().replace(hour=9, minute=0)
        self.assertIsInstance(book_appointment(**data), Appointment)

        data['start'] = next_tuesday().replace(hour=10, minute=0)
        self.assertIsInstance(book_appointment(**data), Appointment)

        data['start'] = next_tuesday().replace(hour=9, minute=30)
        self.assertIsInstance(book_appointment(**data), Appointment)
    def test_appointment_end_a_minute_after_next_starts_ignore_availability_true(
            self):
        """
        Two appointments where the second finishes a minute after the previous started
        Should raise Validation Error
        """
        data = self.data()
        # Start at 9:45
        data['start'] = next_tuesday().replace(hour=9, minute=45)
        appointment = book_appointment(**data)
        self.assertIsInstance(appointment, Appointment)

        # Starts at 9:16 finishes at 9:46 (a minute after previous started)
        data['start'] = next_tuesday().replace(hour=9, minute=16)
        appointment = book_appointment(**data, ignore_availability=True)
        self.assertIsInstance(appointment, Appointment)
    def test_two_appointments_start_a_minute_before_end_of_previous_ignore_availability_true(
            self):
        """
        Appointment starts a minute before previous appointment has finished
        with ignore_availability set to True
        Should create appointment
        """
        data = self.data()
        # Starts at 9 finishes at 9:30
        data['start'] = next_tuesday().replace(hour=9, minute=0)
        appointment = book_appointment(**data)
        self.assertIsInstance(appointment, Appointment)

        # Starts at 9:29 (the end of previous appointment)
        data['start'] = next_tuesday().replace(hour=9, minute=29)
        appointment = book_appointment(**data, ignore_availability=True)
        self.assertIsInstance(appointment, Appointment)
    def test_soft_delete_appointment_overlapping(self):
        """
        Two appointments where the second finishes a minute after the previous started
        Should raise Validation Error
        """
        data = self.data()
        # Start at 9:45
        data['start'] = next_tuesday().replace(hour=9, minute=45)
        a1 = book_appointment(**data)
        self.assertIsInstance(a1, Appointment)

        # Starts at 9:16 finishes at 9:46 (a minute after previous started)
        data['start'] = next_tuesday().replace(hour=9, minute=16)
        a2 = book_appointment(**data, ignore_availability=True)
        self.assertIsInstance(a2, Appointment)
        # the bellow should not throw an error
        a2.delete()
Beispiel #9
0
 def test_get_inside_locked_period(self):
     """
     When an employee has a locked period that ranges for days, no slots should be retrieved for the full range.
     """
     lock = util.book_appointment(
         self.emp,
         start=util.next_tuesday().replace(hour=9, minute=15),
         end=util.next_tuesday(7).replace(hour=9, minute=15))
     slots = self.get_slots_for_emp(util.next_wednesday())
     self.assertEqual(len(slots), 0)
    def test_two_appointments_same_time(self):
        """
        Two appointments on the exact same start / end time, the second should error and not create
        """
        data = self.data()
        data['start'] = next_tuesday().replace(hour=9, minute=0)
        appointment = book_appointment(**data)
        self.assertIsInstance(appointment, Appointment)

        self.assertRaises(ValidationError, book_appointment, **data)
    def test_two_appointments_start_a_minute_before_end_of_previous(self):
        """
        Appointment starts a minute before previous appointment has finished
        Should Fail
        """
        data = self.data()
        # Starts at 9 finishes at 9:30
        data['start'] = next_tuesday().replace(hour=9, minute=0)
        appointment = book_appointment(**data)
        self.assertIsInstance(appointment, Appointment)

        # Starts at 9:29 (the end of previous appointment)
        data['start'] = next_tuesday().replace(hour=9, minute=29)
        self.assertRaises(ValidationError, book_appointment, **data)
 def test_delete_appointments_should_not_show_on_all_queryset(self):
     """
     The normal objects.all should not return safe deleted appointments
     :return:
     """
     before = [*Appointment.objects.all()]
     data = self.data()
     data['start'] = next_tuesday().replace(hour=9, minute=0)
     created = book_appointment(**data)
     after_create = [*Appointment.objects.all()]
     self.assertEqual(len(before) + 1, len(after_create))
     created.delete()
     after_delete = [*Appointment.objects.all()]
     self.assertEqual(len(before), len(after_delete))
Beispiel #13
0
 def lock_period(self, start, end):
     return util.book_appointment(self.emp,
                                  start=start,
                                  end=end,
                                  ignore_availability=True)
Beispiel #14
0
 def book_appointment(self, date):
     return util.book_appointment(self.emp, self.customer, date,
                                  self.service)
 def test_add_appointment_scheduled_day_correct_time(self):
     data = self.data()
     data['start'] = next_tuesday().replace(hour=9, minute=0)
     appointment = book_appointment(**data)
     self.assertIsInstance(appointment, Appointment)