Skip to content
Snippets Groups Projects
Commit 8c17e2d5 authored by Carlos Vega's avatar Carlos Vega
Browse files

Issue #259 : added test to send mail with general appointment and appointment...

Issue #259 : added test to send mail with general appointment and appointment types: test_kit_request_send_mail_with_general_appointment
parent 3c27aa06
No related branches found
No related tags found
Loading
...@@ -5,12 +5,13 @@ from django.urls import reverse ...@@ -5,12 +5,13 @@ from django.urls import reverse
from web.models import Item, Appointment, AppointmentTypeLink from web.models import Item, Appointment, AppointmentTypeLink
from web.tests import LoggedInTestCase 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.kit import get_kit_requests
from web.views.notifications import get_today_midnight_date from web.views.notifications import get_today_midnight_date
class ViewFunctionsTests(LoggedInTestCase): class ViewFunctionsTests(LoggedInTestCase):
def test_kit_requests(self): def test_kit_requests(self):
response = self.client.get(reverse('web.views.kit_requests')) response = self.client.get(reverse('web.views.kit_requests'))
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
...@@ -25,7 +26,8 @@ class ViewFunctionsTests(LoggedInTestCase): ...@@ -25,7 +26,8 @@ class ViewFunctionsTests(LoggedInTestCase):
appointment = create_appointment() appointment = create_appointment()
appointment.datetime_when = get_today_midnight_date() + datetime.timedelta(days=2) appointment.datetime_when = get_today_midnight_date() + datetime.timedelta(days=2)
appointment.save() 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')) response = self.client.get(reverse('web.views.kit_requests'))
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
...@@ -43,7 +45,8 @@ class ViewFunctionsTests(LoggedInTestCase): ...@@ -43,7 +45,8 @@ class ViewFunctionsTests(LoggedInTestCase):
appointment.datetime_when = get_today_midnight_date() + datetime.timedelta(days=2) appointment.datetime_when = get_today_midnight_date() + datetime.timedelta(days=2)
appointment.status = Appointment.APPOINTMENT_STATUS_CANCELLED appointment.status = Appointment.APPOINTMENT_STATUS_CANCELLED
appointment.save() 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')) response = self.client.get(reverse('web.views.kit_requests'))
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
...@@ -60,7 +63,8 @@ class ViewFunctionsTests(LoggedInTestCase): ...@@ -60,7 +63,8 @@ class ViewFunctionsTests(LoggedInTestCase):
appointment = create_appointment() appointment = create_appointment()
appointment.datetime_when = get_today_midnight_date() + datetime.timedelta(days=2) appointment.datetime_when = get_today_midnight_date() + datetime.timedelta(days=2)
appointment.save() 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')) response = self.client.get(reverse('web.views.kit_requests'))
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
...@@ -79,17 +83,20 @@ class ViewFunctionsTests(LoggedInTestCase): ...@@ -79,17 +83,20 @@ class ViewFunctionsTests(LoggedInTestCase):
appointment1 = create_appointment(visit) appointment1 = create_appointment(visit)
appointment1.datetime_when = get_today_midnight_date() + datetime.timedelta(days=3) appointment1.datetime_when = get_today_midnight_date() + datetime.timedelta(days=3)
appointment1.save() 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 = create_appointment(visit)
appointment2.datetime_when = get_today_midnight_date() + datetime.timedelta(days=4) appointment2.datetime_when = get_today_midnight_date() + datetime.timedelta(days=4)
appointment2.save() 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 = create_appointment(visit)
appointment3.datetime_when = get_today_midnight_date() + datetime.timedelta(days=2) appointment3.datetime_when = get_today_midnight_date() + datetime.timedelta(days=2)
appointment3.save() 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) result = get_kit_requests(self.user)
self.assertEqual(appointment3, result['appointments'][0]) self.assertEqual(appointment3, result['appointments'][0])
...@@ -112,8 +119,10 @@ class ViewFunctionsTests(LoggedInTestCase): ...@@ -112,8 +119,10 @@ class ViewFunctionsTests(LoggedInTestCase):
appointment1 = create_appointment(visit) appointment1 = create_appointment(visit)
appointment1.datetime_when = get_today_midnight_date() + datetime.timedelta(days=3) appointment1.datetime_when = get_today_midnight_date() + datetime.timedelta(days=3)
appointment1.save() appointment1.save()
AppointmentTypeLink.objects.create(appointment=appointment1, appointment_type=appointment_type) AppointmentTypeLink.objects.create(
AppointmentTypeLink.objects.create(appointment=appointment1, appointment_type=appointment_type2) appointment=appointment1, appointment_type=appointment_type)
AppointmentTypeLink.objects.create(
appointment=appointment1, appointment_type=appointment_type2)
result = get_kit_requests(self.user) result = get_kit_requests(self.user)
...@@ -129,7 +138,8 @@ class ViewFunctionsTests(LoggedInTestCase): ...@@ -129,7 +138,8 @@ class ViewFunctionsTests(LoggedInTestCase):
appointment = create_appointment() appointment = create_appointment()
appointment.datetime_when = get_today_midnight_date() + datetime.timedelta(days=2) appointment.datetime_when = get_today_midnight_date() + datetime.timedelta(days=2)
appointment.save() 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', response = self.client.get(reverse('web.views.kit_requests_send_mail',
kwargs={'start_date': str(get_today_midnight_date().strftime("%Y-%m-%d"))})) kwargs={'start_date': str(get_today_midnight_date().strftime("%Y-%m-%d"))}))
...@@ -138,3 +148,20 @@ class ViewFunctionsTests(LoggedInTestCase): ...@@ -138,3 +148,20 @@ class ViewFunctionsTests(LoggedInTestCase):
self.assertTrue(item_name in response.content) self.assertTrue(item_name in response.content)
self.assertEqual(1, len(mail.outbox)) 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))
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