Exemplo n.º 1
0
    def test_add_two_appointments_same_service(self):
        """
        if the person is not the same as the user's person save should fail
        """
        params = {
            'start': next_tuesday().replace(hour=9, minute=0),
            'service_id': 1,
            'customer_id': 2001,
            'employee_id': 1,
            'owner_id': 1
        }

        request = get_current()  # Get request
        request.add_appointment(**params)  # Adds appointment
        # Adds a new appointment with the same service for another time
        params['start'] = next_tuesday().replace(hour=11,
                                                 minute=0,
                                                 second=0,
                                                 microsecond=0)
        request.add_appointment(**params)

        # Make sure there's a single appointment in the request
        self.assertEqual(len(request.appointment_set.all()), 1)
        # Make sure the date is related to the last appointment booked
        self.assertEqual(request.appointment_set.first().start,
                         params['start'])
Exemplo n.º 2
0
    def test_admin_update_overlapping_ignore_availability(self):
        """
        When creating overlapping appointments
        the server should return 422 error
        """
        emp, customer, service = emp_customer_service()

        self._auth_as_admin()

        # Create appointment at 10 am finishing at 10:30
        d1 = create_apt_data(emp, customer, service,
                             util.next_tuesday().replace(hour=10, minute=0))
        r1 = self.client.post(self.list_url, d1, format='json')
        self.assertEqual(r1.status_code, status.HTTP_201_CREATED)

        # Create appointment at 10:40 (not overlapping)
        d2 = create_apt_data(emp, customer, service,
                             util.next_tuesday().replace(hour=10, minute=40))
        r2 = self.client.post(self.list_url, d2, format='json')
        self.assertEqual(r2.status_code, status.HTTP_201_CREATED)

        # Update previous to overlap with first
        d3 = create_apt_data(emp, customer, service,
                             util.next_tuesday().replace(hour=10, minute=15))
        d3['ignore_availability'] = True
        r3 = self.client.patch(self.detail_url(r2.data['id']),
                               d3,
                               format='json')
        self.assertEqual(r3.status_code, status.HTTP_200_OK)
Exemplo n.º 3
0
    def test_book_appointment_without_service(self):
        """Only self appointment can be created without services"""
        data = self.data()
        data['start'] = next_tuesday().replace(hour=9, minute=0)
        data['end'] = next_tuesday().replace(hour=10, minute=0)
        del (data['service'])

        self.assertRaises(ValidationError, book_appointment, **data)
Exemplo n.º 4
0
 def test_book_self_appointment(self):
     """self appointment should be possible, when this happens the service field will be null"""
     employee = self.data()['employee']
     appointment = Appointment.objects.create(
         start=next_tuesday().replace(hour=9, minute=0),
         end=next_tuesday().replace(hour=10, minute=0),
         employee=employee,
         owner=employee.owner)
     self.assertIsInstance(appointment, Appointment)
Exemplo n.º 5
0
    def test_shift_with_break(self):
        appointment_1_date = util.next_tuesday().replace(hour=15, minute=30)
        self.book_appointment(appointment_1_date)
        slots = self.get_slots_for_emp(util.next_tuesday())

        for slot in slots:
            self.assertEqual(slot.duration(), self.service.duration)

        self.assertEqual(len(slots), 13)
Exemplo n.º 6
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)
Exemplo n.º 7
0
    def test_slot_(self):
        appointment_1_date = util.next_tuesday().replace(hour=9, minute=0)
        appointment_2_date = util.next_tuesday().replace(hour=10, minute=0)
        self.book_appointment(appointment_1_date)
        self.book_appointment(appointment_2_date)
        slots = self.get_slots_for_emp(util.next_tuesday())

        for slot in slots:
            self.assertEqual(slot.duration(), self.service.duration)

        self.assertEqual(len(slots), 12)
Exemplo n.º 8
0
    def test_employee_create_self_appointment(self):
        emp, customer, service = emp_customer_service()
        emp.user = test_user(emp)
        data = create_self_apt_data(
            emp,
            util.next_tuesday().replace(hour=10, minute=0),
            util.next_tuesday().replace(hour=11, minute=0))

        self.client.force_authenticate(user=emp.user)
        response = self.client.post(self.list_url, data, format='json')

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    def test_admin_view_self_appointment_multiple_days(self):
        emp, customer, service = emp_customer_service()
        start_date = util.next_tuesday().replace(hour=10,
                                                 minute=0) + util.timedelta(7)
        end_date = util.next_tuesday().replace(hour=11,
                                               minute=0) + util.timedelta(14)
        data = create_self_apt_data(emp, start_date, end_date)

        self._auth_as_admin()

        # Create an appointment that has 7 days of length
        response = self.client.post(self.list_url + 'lock/',
                                    data,
                                    format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        apt_id = response.data['id']
        for i in range(8):
            # Goes through all the dates the appointment is booked and checks that the appointment is being retrieved
            # in the results
            date = start_date + util.timedelta(i)
            q_data = {
                'from_date': date.strftime('%Y-%m-%dT00:00'),
                'to_date': date.strftime('%Y-%m-%dT23:59')
            }
            q = self.client.get(self.list_url, q_data, format='json')
            self.assertEqual(q.status_code, status.HTTP_200_OK)
            result_id = q.data['results'][0]['id']
            self.assertEqual(result_id, apt_id)

        # The appointment shouldn't be showing on the day before
        d_before = start_date - util.timedelta(1)
        q_before_data = {
            'from_date': d_before.strftime('%Y-%m-%dT00:00'),
            'to_date': d_before.strftime('%Y-%m-%dT23:59')
        }
        q_before = self.client.get(self.list_url, q_before_data, format='json')
        self.assertEqual(q_before.status_code, status.HTTP_200_OK)
        results = q_before.data['results']
        self.assertEqual(len(results), 0)

        # The appointment shouldn't be showing on the day after
        d_after = start_date + util.timedelta(8)
        q_after_data = {
            'from_date': d_after.strftime('%Y-%m-%dT00:00'),
            'to_date': d_after.strftime('%Y-%m-%dT23:59')
        }
        q_after = self.client.get(self.list_url, q_after_data, format='json')
        self.assertEqual(q_after.status_code, status.HTTP_200_OK)
        results = q_after.data['results']
        self.assertEqual(len(results), 0)
Exemplo n.º 11
0
    def test_appointment_end_a_minute_after_next_starts(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)
        self.assertRaises(ValidationError, book_appointment, **data)
Exemplo n.º 12
0
    def test_admin_create_self_appointment(self):
        emp, customer, service = emp_customer_service()

        data = create_self_apt_data(
            emp,
            util.next_tuesday().replace(hour=10, minute=0),
            util.next_tuesday().replace(hour=11, minute=0))

        self._auth_as_admin()
        response = self.client.post(self.list_url + 'lock/',
                                    data,
                                    format='json')

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
    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)
Exemplo n.º 15
0
    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)
Exemplo n.º 16
0
    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)
Exemplo n.º 17
0
    def test_day_with_one_appointment_start_of_shift(self):
        appointment_1_date = util.next_tuesday().replace(hour=9, minute=00)
        self.book_appointment(appointment_1_date)
        slots = self.get_slots_for_emp(appointment_1_date)

        for slot in slots:
            self.assertEqual(slot.duration(), self.service.duration)
Exemplo n.º 18
0
    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)
Exemplo n.º 19
0
    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()
Exemplo n.º 20
0
 def test_add_appointment_scheduled_day_incorrect_time(self):
     """
     trying to schedule a 30 minutes job at 8 am when the schedule starts at 9 am
     this should throw an exception and not schedule anything
     """
     data = self.data()
     data['start'] = next_tuesday().replace(hour=8, minute=0)
     self.assertRaises(ValidationError, book_appointment, **data)
Exemplo n.º 21
0
    def test_rejected_appointment(self):
        appointment_1_date = util.next_tuesday().replace(hour=9, minute=15)
        appointment = self.book_appointment(appointment_1_date)

        util.reject_appointment(appointment)

        slots = self.get_slots_for_emp(appointment_1_date)
        self.assertEqual(len(slots), 14)
Exemplo n.º 22
0
    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)
Exemplo n.º 23
0
    def test_admin_create_self_appointment_overlapping(self):
        self._auth_as_admin()

        emp, customer, service = emp_customer_service()

        d1 = create_self_apt_data(
            emp,
            util.next_tuesday().replace(hour=10, minute=0),
            util.next_tuesday().replace(hour=12, minute=0))
        r1 = self.client.post(self.list_url + 'lock/', d1, format='json')
        self.assertEqual(r1.status_code, status.HTTP_201_CREATED)

        d2 = create_self_apt_data(
            emp,
            util.next_tuesday().replace(hour=11, minute=0),
            util.next_tuesday().replace(hour=13, minute=0))
        r2 = self.client.post(self.list_url + 'lock/', d2, format='json')
        self.assertEqual(r2.status_code, status.HTTP_422_UNPROCESSABLE_ENTITY)
Exemplo n.º 24
0
    def test_accept(self):
        params = {
            'start': next_tuesday().replace(hour=9, minute=0),
            'service_id': 1,
            'customer_id': 2001,
            'employee_id': 1,
            'owner_id': 1
        }
        request = get_current()  # Get request
        request.add_appointment(**params)  # Adds appointment
        params.update({
            'service_id': 2,
            'start': next_tuesday().replace(hour=11)
        })

        self.assert_request_status(request, Appointment.PENDING)
        request.accept()
        self.assert_request_status(request, Appointment.ACCEPTED)
Exemplo n.º 25
0
    def test_appointment_with_customer_and_employees_on_different_owner(self):
        """
        An error should be raised when creating an appointment where the service and the employee have different owners
        """
        data = self.data()
        data['start'] = next_tuesday().replace(hour=9, minute=0)
        data['customer'] = Customer.objects.get(pk=1003)

        self.assertRaises(ValidationError, book_appointment, **data)
Exemplo n.º 26
0
    def test_customer_create_pending(self):
        emp, service = emp_service()
        user = test_user()
        data = create_apt_data(emp, user.person, service,
                               util.next_tuesday().replace(hour=10, minute=0))

        self.client.force_authenticate(user=user)  # authenticates as customer
        response = self.client.post(self.list_url, data, format='json')

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Exemplo n.º 27
0
    def test_admin_create_different_company(self):
        emp, customer, service = emp_customer_service_company_2()
        data = create_apt_data(emp, customer, service,
                               util.next_tuesday().replace(hour=10, minute=0))

        self._auth_as_admin()
        response = self.client.post(self.list_url, data, format='json')

        self.assertEqual(response.status_code,
                         status.HTTP_422_UNPROCESSABLE_ENTITY)
Exemplo n.º 28
0
 def test_add_appointment_no_employee(self):
     """
     requests can have appointments without an employee id
     """
     r1 = get_current()
     r1.add_appointment(start=next_tuesday().replace(hour=9, minute=0),
                        service_id=1,
                        customer_id=2001,
                        owner_id=1)
     self.assertEqual(len(r1.appointment_set.all()), 1)
Exemplo n.º 29
0
    def test_create_appointment_omitting_employee(self):
        emp, service = emp_service()
        user = User.objects.get(pk=2)
        data = create_apt_data(emp, service, util.next_tuesday().replace(hour=10, minute=0))
        data.pop('employee')

        self.client.force_authenticate(user=user)
        response = self.client.post(self.list_url + 'add/', data, format='json')

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Exemplo n.º 30
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)