def test_appointment_cancelled_by_practitioner_unbooked(self): user = User.objects.create_user(username='******', password='******', first_name="Robert", last_name="Greener", email="*****@*****.**") user.save() practitioner = Practitioner(user=user, mobile="+447476605233", bio="ABC", address_line_1="XXX", address_line_2="XXXXX", is_approved=True) practitioner.save() appointment = Appointment(practitioner=practitioner, patient=None, start_date_and_time=datetime(year=2018, month=4, day=17, hour=15, minute=10), length=timedelta(hours=1)) appointment.save() appointment_cancelled_by_practitioner(appointment) self.assertEqual(len(mail.outbox), 1)
def test_one_appointment(self): a1 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=14, minute=20), length=timedelta(hours=3)) a1.save() overlaps = Appointment._get_overlaps([a1]) self.assertEqual(len(overlaps), 0)
def test_four_spread_over_lapping(self): a1 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=14, minute=20), length=timedelta(hours=1)) a1.save() a2 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=14, minute=50), length=timedelta(hours=1)) a2.save() a3 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=15, minute=10), length=timedelta(hours=1)) a3.save() a4 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=16, minute=00), length=timedelta(hours=1)) a4.save() overlaps = Appointment._get_overlaps([a1, a2, a3, a4]) self.assertEquals(len(overlaps), 3)
def test_same_start_different_duration(self): a1 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=14, minute=20), length=timedelta(minutes=1)) a1.save() a2 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=14, minute=20), length=timedelta(minutes=2)) a2.save() a3 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=14, minute=20), length=timedelta(minutes=3)) a3.save() a4 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=14, minute=20), length=timedelta(minutes=4)) a4.save() overlaps = Appointment._get_overlaps([a4, a2, a3, a1]) self.assertEquals(len(overlaps), 3)
def test_over_lap(self): a1 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=14, minute=20), length=timedelta(hours=0, minutes=2)) a1.save() a2 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=14, minute=21), length=timedelta(hours=0, minutes=1)) a2.save() a3 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=14, minute=22), length=timedelta(hours=0, minutes=1)) a3.save() a4 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=14, minute=23), length=timedelta(hours=0, minutes=1)) a4.save() overlaps = Appointment._get_overlaps([a4, a2, a3, a1]) self.assertEquals(len(overlaps), 1)
def test_four_disjoint(self): a1 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=14, minute=20), length=timedelta(hours=1)) a1.save() a2 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=15, minute=30), length=timedelta(hours=1)) a2.save() a3 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=17, minute=00), length=timedelta(hours=1)) a3.save() a4 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=18, minute=10), length=timedelta(hours=1)) a4.save() overlaps = Appointment._get_overlaps([a4, a2, a3, a1]) self.assertEquals(len(overlaps), 0)
def test_three_consecutive_one_overlap(self): a1 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=14, minute=20), length=timedelta(hours=1)) a1.save() a2 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=15, minute=20), length=timedelta(hours=1)) a2.save() a3 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=16, minute=20), length=timedelta(hours=1)) a3.save() a4 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=17, minute=19), length=timedelta(hours=1)) a4.save() overlaps = Appointment._get_overlaps([a4, a2, a3, a1]) self.assertEquals(len(overlaps), 1)
def test_multiple_appointments_booked(self): user = User.objects.create_user(username='******', password='******', first_name="Robert", last_name="Greener", email="*****@*****.**") user.save() practitioner = Practitioner(user=user, mobile="+447476605233", bio="ABC", address_line_1="XXX", address_line_2="XXXXX", is_approved=True) practitioner.save() user2 = User.objects.create_user(username='******', password='******', first_name="Woof", last_name="Meow", email="*****@*****.**") user2.save() patient = Patient(user=user2, gender='M', mobile="+447476605233", date_of_birth=date(year=1995, month=1, day=1)) patient.save() appointment1 = Appointment(practitioner=practitioner, patient=patient, start_date_and_time=datetime(year=2018, month=4, day=17, hour=15, minute=10), length=timedelta(hours=1)) appointment1.save() appointment2 = Appointment(practitioner=practitioner, patient=patient, start_date_and_time=datetime(year=2018, month=4, day=19, hour=15, minute=10), length=timedelta(hours=1)) appointment2.save() multiple_appointments_booked((appointment1, appointment2)) self.assertEqual(len(mail.outbox), 4)
def test_split_merged_appointment_when_no_splits_should_happen(self): start_date_and_time = datetime(year=2018, month=3, day=11, hour=12, minute=00) appointment = Appointment(start_date_and_time=start_date_and_time, length=timedelta(minutes=30)) appointment.save() Appointment.split_merged_appointment(appointment) new_appointments = Appointment.objects.filter( start_date_and_time__gte=start_date_and_time, start_date_and_time__lte=start_date_and_time + timedelta(minutes=30)) self.assertEqual(len(new_appointments), 1) for appointment in new_appointments: self.assertEqual(appointment.length, timedelta(minutes=30))
def test_two_spread_over_lapping(self): a1 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=14, minute=20), length=timedelta(hours=1)) a1.save() a2 = Appointment(start_date_and_time=datetime(year=2018, month=3, day=2, hour=14, minute=40), length=timedelta(hours=1)) a2.save() overlaps = Appointment._get_overlaps([a1, a2]) self.assertEquals(len(overlaps), 1)
def test__str__(self): u = User(first_name="John", last_name="Smith") u.save() practitioner = Practitioner(user=u, address_line_1="My home", postcode="EC12 1CV", mobile="+447577293232", bio="Hello") practitioner.save() appointment = Appointment(practitioner=practitioner, start_date_and_time=datetime(year=2018, month=3, day=2, hour=15, minute=16), length=timedelta(hours=1)) appointment.save() self.assertEqual(str(appointment), 'John Smith - 2018-03-02 15:16:00 for 1:00:00')
def test_reminders(self): user = User.objects.create_user(username='******', password='******', first_name="Robert", last_name="Greener", email="*****@*****.**") user.save() practitioner = Practitioner(user=user, mobile="+447476605233", bio="ABC", address_line_1="XXX", address_line_2="XXXXX", is_approved=True) practitioner.save() user2 = User.objects.create_user(username='******', password='******', first_name="Woof", last_name="Meow", email="*****@*****.**") user2.save() patient = Patient(user=user2, gender='M', mobile="+447476605233", date_of_birth=date(year=1995, month=1, day=1)) patient.save() appointment1 = Appointment(practitioner=practitioner, patient=patient, start_date_and_time=timezone.now(), length=timedelta(hours=1)) appointment1.save() appointment2 = Appointment(practitioner=practitioner, patient=patient, start_date_and_time=timezone.now(), length=timedelta(minutes=30)) appointment2.save() reminders() self.assertEqual(len(mail.outbox), 4)
def test_split_merged_appointment_into_6(self): start_date_and_time = datetime(year=2018, month=3, day=11, hour=12, minute=00) appointment = Appointment(start_date_and_time=start_date_and_time, length=timedelta(hours=3)) appointment.save() Appointment.split_merged_appointment(appointment) new_appointments = Appointment.objects.filter( start_date_and_time__gte=start_date_and_time, start_date_and_time__lte=start_date_and_time + timedelta(hours=3)) self.assertEqual(len(new_appointments), 6) for appointment in new_appointments: self.assertEqual(appointment.length, timedelta(minutes=30)) self.assertEquals( appointment.price, Decimal(Appointment._meta.get_field('price').get_default()))
def test_is_live_when_too_early(self): u = User(first_name="John", last_name="Smith") u.save() patient = Patient(user=u, gender='M', mobile="+447476666555", date_of_birth=date(year=1995, month=1, day=1)) patient.save() practitioner = Practitioner(user=u, address_line_1="My home", postcode="EC12 1CV", mobile="+447577293232", bio="Hello") practitioner.save() appointment = Appointment(practitioner=practitioner, patient=patient, start_date_and_time=timezone.now() + timedelta(minutes=10), length=timedelta(hours=1)) appointment.save() self.assertFalse(appointment.is_live())