From 8c17e2d513af8edf411bb149f34536f7c6eef0bd Mon Sep 17 00:00:00 2001
From: Carlos Vega <carlos.vega@uni.lu>
Date: Tue, 30 Oct 2018 11:57:19 +0100
Subject: [PATCH] Issue #259 : added test to send mail with general appointment
 and appointment types: test_kit_request_send_mail_with_general_appointment

---
 smash/web/tests/view/test_kit_request.py | 47 +++++++++++++++++++-----
 1 file changed, 37 insertions(+), 10 deletions(-)

diff --git a/smash/web/tests/view/test_kit_request.py b/smash/web/tests/view/test_kit_request.py
index e1c4a1e7..387001f3 100644
--- a/smash/web/tests/view/test_kit_request.py
+++ b/smash/web/tests/view/test_kit_request.py
@@ -5,12 +5,13 @@ from django.urls import reverse
 
 from web.models import Item, Appointment, AppointmentTypeLink
 from web.tests import LoggedInTestCase
-from web.tests.functions import create_appointment_type, create_appointment, create_visit
+from web.tests.functions import create_appointment_type, create_appointment, create_visit, create_appointment_without_visit
 from web.views.kit import get_kit_requests
 from web.views.notifications import get_today_midnight_date
 
 
 class ViewFunctionsTests(LoggedInTestCase):
+
     def test_kit_requests(self):
         response = self.client.get(reverse('web.views.kit_requests'))
         self.assertEqual(response.status_code, 200)
@@ -25,7 +26,8 @@ class ViewFunctionsTests(LoggedInTestCase):
         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)
+        AppointmentTypeLink.objects.create(
+            appointment=appointment, appointment_type=appointment_type)
 
         response = self.client.get(reverse('web.views.kit_requests'))
         self.assertEqual(response.status_code, 200)
@@ -43,7 +45,8 @@ class ViewFunctionsTests(LoggedInTestCase):
         appointment.datetime_when = get_today_midnight_date() + datetime.timedelta(days=2)
         appointment.status = Appointment.APPOINTMENT_STATUS_CANCELLED
         appointment.save()
-        AppointmentTypeLink.objects.create(appointment=appointment, appointment_type=appointment_type)
+        AppointmentTypeLink.objects.create(
+            appointment=appointment, appointment_type=appointment_type)
 
         response = self.client.get(reverse('web.views.kit_requests'))
         self.assertEqual(response.status_code, 200)
@@ -60,7 +63,8 @@ class ViewFunctionsTests(LoggedInTestCase):
         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)
+        AppointmentTypeLink.objects.create(
+            appointment=appointment, appointment_type=appointment_type)
 
         response = self.client.get(reverse('web.views.kit_requests'))
         self.assertEqual(response.status_code, 200)
@@ -79,17 +83,20 @@ class ViewFunctionsTests(LoggedInTestCase):
         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)
+        AppointmentTypeLink.objects.create(
+            appointment=appointment1, appointment_type=appointment_type)
 
         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)
+        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)
+        AppointmentTypeLink.objects.create(
+            appointment=appointment3, appointment_type=appointment_type)
 
         result = get_kit_requests(self.user)
         self.assertEqual(appointment3, result['appointments'][0])
@@ -112,8 +119,10 @@ class ViewFunctionsTests(LoggedInTestCase):
         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)
-        AppointmentTypeLink.objects.create(appointment=appointment1, appointment_type=appointment_type2)
+        AppointmentTypeLink.objects.create(
+            appointment=appointment1, appointment_type=appointment_type)
+        AppointmentTypeLink.objects.create(
+            appointment=appointment1, appointment_type=appointment_type2)
 
         result = get_kit_requests(self.user)
 
@@ -129,7 +138,8 @@ class ViewFunctionsTests(LoggedInTestCase):
         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)
+        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"))}))
@@ -138,3 +148,20 @@ class ViewFunctionsTests(LoggedInTestCase):
         self.assertTrue(item_name in response.content)
 
         self.assertEqual(1, len(mail.outbox))
+
+    def test_kit_request_send_mail_with_general_appointment(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_without_visit()
+        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))
-- 
GitLab