From 0dbdadcc670ea8d73f949be534469e677601bcd1 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Thu, 7 Dec 2017 15:15:44 +0100
Subject: [PATCH] unit test checking if column list generation is done properly

---
 smash/web/tests/api_views/test_appointment.py | 36 ++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/smash/web/tests/api_views/test_appointment.py b/smash/web/tests/api_views/test_appointment.py
index 0fafe6c6..ddfa8eeb 100644
--- a/smash/web/tests/api_views/test_appointment.py
+++ b/smash/web/tests/api_views/test_appointment.py
@@ -1,13 +1,14 @@
 # coding=utf-8
 
 import datetime
+import json
 
 from django.contrib.auth.models import User
 from django.test import Client
 from django.test import TestCase
 from django.urls import reverse
 
-from web.models import AppointmentTypeLink
+from web.models import AppointmentTypeLink, AppointmentList
 from web.tests.functions import create_study_subject, create_worker, create_visit, create_appointment, \
     create_appointment_type, create_get_suffix, create_flying_team
 from web.views.appointment import APPOINTMENT_LIST_GENERIC, APPOINTMENT_LIST_APPROACHING, APPOINTMENT_LIST_UNFINISHED
@@ -115,3 +116,36 @@ class TestAppointmentApi(TestCase):
 
         self.assertEqual(response.status_code, 200)
         self.assertTrue(name in response.content)
+
+    def test_get_columns(self):
+        response = self.client.get(
+            reverse('web.api.appointments.columns', kwargs={'appointment_list_type': APPOINTMENT_LIST_GENERIC}))
+        self.assertEqual(response.status_code, 200)
+
+        columns = json.loads(response.content)['columns']
+        visible_columns = 0
+        for column in columns:
+            if column["visible"]:
+                visible_columns += 1
+        self.assertTrue(visible_columns > 0)
+
+    def test_get_columns_for_require_contact(self):
+        response = self.client.get(
+            reverse('web.api.appointments.columns', kwargs={'appointment_list_type': APPOINTMENT_LIST_UNFINISHED}))
+        self.assertEqual(response.status_code, 200)
+
+        columns = json.loads(response.content)['columns']
+        visible_columns = 0
+        for column in columns:
+            if column["visible"]:
+                visible_columns += 1
+        self.assertTrue(visible_columns > 0)
+
+    def test_get_columns_when_no_list_is_available(self):
+        AppointmentList.objects.all().delete()
+        response = self.client.get(
+            reverse('web.api.appointments.columns', kwargs={'appointment_list_type': APPOINTMENT_LIST_GENERIC}))
+        self.assertEqual(response.status_code, 200)
+
+        columns = json.loads(response.content)['columns']
+        self.assertTrue(len(columns) > 0)
-- 
GitLab