Skip to content
Snippets Groups Projects
Commit d6213112 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

kit requests appointments are ordered by date

parent 234530bf
No related branches found
No related tags found
1 merge request!47Resolve "Email to technician"
......@@ -3,8 +3,9 @@ import datetime
from django.core import mail
from django.urls import reverse
from functions import create_appointment_type, create_appointment
from functions import create_appointment_type, create_appointment, create_visit
from web.models import Item, Appointment, AppointmentTypeLink
from web.views.kit import get_kit_requests
from web.views.notifications import get_today_midnight_date
from . import LoggedInTestCase
......@@ -26,7 +27,6 @@ class ViewFunctionsTests(LoggedInTestCase):
appointment.save()
AppointmentTypeLink.objects.create(appointment=appointment, appointment_type=appointment_type)
response = self.client.get(reverse('web.views.kit_requests'))
self.assertEqual(response.status_code, 200)
......@@ -62,28 +62,57 @@ class ViewFunctionsTests(LoggedInTestCase):
appointment.save()
AppointmentTypeLink.objects.create(appointment=appointment, appointment_type=appointment_type)
response = self.client.get(reverse('web.views.kit_requests'))
self.assertEqual(response.status_code, 200)
self.assertTrue(item_name in response.content)
def test_kit_requests_send_email(self):
def test_kit_requests_order(self):
item_name = "Test item to be ordered"
item = Item.objects.create(disposable=True, name=item_name)
appointment_type = create_appointment_type()
appointment_type.required_equipment.add(item)
appointment_type.save()
appointment = create_appointment()
appointment.datetime_when = get_today_midnight_date() + datetime.timedelta(days=2)
appointment.save()
AppointmentTypeLink.objects.create(appointment=appointment, appointment_type=appointment_type)
visit = create_visit();
response = self.client.get(reverse('web.views.kit_requests_send_mail',
kwargs={'start_date': str(get_today_midnight_date().strftime("%Y-%m-%d"))}))
self.assertEqual(response.status_code, 200)
appointment1 = create_appointment(visit)
appointment1.datetime_when = get_today_midnight_date() + datetime.timedelta(days=3)
appointment1.save()
AppointmentTypeLink.objects.create(appointment=appointment1, appointment_type=appointment_type)
self.assertTrue(item_name in response.content)
appointment2 = create_appointment(visit)
appointment2.datetime_when = get_today_midnight_date() + datetime.timedelta(days=4)
appointment2.save()
AppointmentTypeLink.objects.create(appointment=appointment2, appointment_type=appointment_type)
appointment3 = create_appointment(visit)
appointment3.datetime_when = get_today_midnight_date() + datetime.timedelta(days=2)
appointment3.save()
AppointmentTypeLink.objects.create(appointment=appointment3, appointment_type=appointment_type)
result = get_kit_requests(self.user)
self.assertEqual(appointment3, result['appointments'][0])
self.assertEqual(appointment1, result['appointments'][1])
self.assertEqual(appointment2, result['appointments'][2])
def test_kit_requests_send_email(self):
item_name = "Test item to be ordered"
item = Item.objects.create(disposable=True, name=item_name)
appointment_type = create_appointment_type()
appointment_type.required_equipment.add(item)
appointment_type.save()
appointment = create_appointment()
appointment.datetime_when = get_today_midnight_date() + datetime.timedelta(days=2)
appointment.save()
AppointmentTypeLink.objects.create(appointment=appointment, appointment_type=appointment_type)
response = self.client.get(reverse('web.views.kit_requests_send_mail',
kwargs={'start_date': str(get_today_midnight_date().strftime("%Y-%m-%d"))}))
self.assertEqual(response.status_code, 200)
self.assertTrue(item_name in response.content)
self.assertEqual(1, len(mail.outbox))
self.assertEqual(1, len(mail.outbox))
......@@ -34,7 +34,8 @@ def get_kit_requests(user, start_date=None, end_date=None):
datetime_when__gt=start_date,
location__in=get_filter_locations(user),
status=Appointment.APPOINTMENT_STATUS_SCHEDULED,
)
).order_by('datetime_when')
if end_date is not None:
appointments = appointments.filter(datetime_when__lt=end_date)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment