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

unit test for appointments api

parent 3a9de20c
No related branches found
No related tags found
1 merge request!35performance on appointment list
Pipeline #
# coding=utf-8 # coding=utf-8
import datetime
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.test import Client from django.test import Client
from django.test import TestCase from django.test import TestCase
from django.urls import reverse from django.urls import reverse
from web.tests.functions import create_subject, create_worker, create_visit, create_appointment from web.tests.functions import create_subject, create_worker, create_visit, create_appointment, \
from web.views.appointment import APPOINTMENT_LIST_GENERIC create_appointment_type, create_get_suffix
from web.views.appointment import APPOINTMENT_LIST_GENERIC, APPOINTMENT_LIST_APPROACHING, APPOINTMENT_LIST_UNFINISHED
from web.views.notifications import get_today_midnight_date
class TestApi(TestCase): class TestApi(TestCase):
...@@ -30,8 +34,9 @@ class TestApi(TestCase): ...@@ -30,8 +34,9 @@ class TestApi(TestCase):
self.subject.save() self.subject.save()
visit = create_visit(self.subject) visit = create_visit(self.subject)
create_appointment(visit) create_appointment(visit)
appointment2 = create_appointment(visit) appointment2 = create_appointment(visit, get_today_midnight_date())
appointment2.visit = None appointment2.visit = None
appointment2.appointment_types.add(create_appointment_type())
appointment2.save() appointment2.save()
url = reverse('web.api.appointments', kwargs={'type': APPOINTMENT_LIST_GENERIC}) url = reverse('web.api.appointments', kwargs={'type': APPOINTMENT_LIST_GENERIC})
...@@ -39,3 +44,57 @@ class TestApi(TestCase): ...@@ -39,3 +44,57 @@ class TestApi(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTrue(name in response.content) self.assertTrue(name in response.content)
def test_appointments_approaching(self):
name = "Piotrek"
self.subject.first_name = name
self.subject.save()
visit = create_visit(self.subject)
create_appointment(visit, get_today_midnight_date() + datetime.timedelta(days=2))
url = reverse('web.api.appointments', kwargs={'type': APPOINTMENT_LIST_APPROACHING})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertTrue(name in response.content)
def test_appointments_unfinished(self):
name = "Piotrek"
self.subject.first_name = name
self.subject.save()
visit = create_visit(self.subject)
create_appointment(visit, get_today_midnight_date() + datetime.timedelta(days=-12))
url = reverse('web.api.appointments', kwargs={'type': APPOINTMENT_LIST_UNFINISHED})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertTrue(name in response.content)
def test_get_calendar_appointments(self):
name = "Peter"
self.subject.first_name = name
self.subject.save()
visit = create_visit(self.subject)
appointment = create_appointment(visit, get_today_midnight_date())
appointment.appointment_types.add(create_appointment_type())
appointment.save()
params = {
"start_date": (get_today_midnight_date() + datetime.timedelta(days=2)).strftime("%Y-%m-%d"),
"end_date": (get_today_midnight_date() + datetime.timedelta(days=3)).strftime("%Y-%m-%d"),
}
url = ("%s" + create_get_suffix(params)) % reverse('web.api.appointments',
kwargs={'type': APPOINTMENT_LIST_GENERIC})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertFalse(name in response.content)
params["start_date"] = (get_today_midnight_date() + datetime.timedelta(days=-2)).strftime("%Y-%m-%d")
url = ("%s" + create_get_suffix(params)) % reverse('web.api.appointments',
kwargs={'type': APPOINTMENT_LIST_GENERIC})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertTrue(name in response.content)
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