From c049563ac5a6993214140876f587d988b8dcc340 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Mon, 4 Dec 2017 18:15:51 +0100
Subject: [PATCH] unit tests for filtering subject data

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

diff --git a/smash/web/tests/api_views/test_subject.py b/smash/web/tests/api_views/test_subject.py
index 0cfe69f5..b3da6195 100644
--- a/smash/web/tests/api_views/test_subject.py
+++ b/smash/web/tests/api_views/test_subject.py
@@ -10,7 +10,7 @@ from django.urls import reverse
 
 from web.api_views.subject import get_subjects_order, get_subjects_filtered, serialize_subject
 from web.models import StudySubject, Appointment, Study
-from web.models.constants import GLOBAL_STUDY_ID
+from web.models.constants import GLOBAL_STUDY_ID, SUBJECT_TYPE_CHOICES_PATIENT, SUBJECT_TYPE_CHOICES_CONTROL
 from web.models.study_subject_list import SUBJECT_LIST_GENERIC, SUBJECT_LIST_NO_VISIT, SUBJECT_LIST_REQUIRE_CONTACT, \
     StudySubjectList
 from web.tests.functions import create_study_subject, create_worker, create_get_suffix, create_visit, \
@@ -355,11 +355,44 @@ class TestApi(TestCase):
         self.check_subject_filtered([["default_location", str(subject.default_location.id)]], [subject])
         self.check_subject_filtered([["default_location", "-1"]], [])
 
+    def test_subjects_filter_flying_team(self):
+        subject = self.study_subject
+        subject.flying_team = create_flying_team()
+        subject.save()
+
+        self.check_subject_filtered([["flying_team", str(subject.flying_team.id)]], [subject])
+        self.check_subject_filtered([["flying_team", "-1"]], [])
+
+    def test_subjects_filter_information_sent(self):
+        subject = self.study_subject
+        subject.information_sent = True
+        subject.save()
+
+        self.check_subject_filtered([["information_sent", "true"]], [subject])
+        self.check_subject_filtered([["information_sent", "false"]], [])
+
+    def test_subjects_filter_referral(self):
+        subject = self.study_subject
+        subject.referral = "xyz"
+        subject.save()
+
+        self.check_subject_filtered([["referral", "xyz"]], [subject])
+        self.check_subject_filtered([["referral", "false"]], [])
+
+    def test_subjects_filter_type(self):
+        subject = self.study_subject
+        subject.type = SUBJECT_TYPE_CHOICES_PATIENT
+        subject.save()
+
+        self.check_subject_filtered([["type", SUBJECT_TYPE_CHOICES_PATIENT]], [subject])
+        self.check_subject_filtered([["type", SUBJECT_TYPE_CHOICES_CONTROL]], [])
+
     def test_subjects_filter_unknown(self):
         subject = self.study_subject
 
         self.check_subject_filtered([["some_unknown", "unknown data"]], [subject])
         self.check_subject_filtered([["", ""]], [subject])
+        self.check_subject_filtered([["", None]], [subject])
 
     def test_serialize_subject(self):
         study_subject = self.study_subject
-- 
GitLab