From f6f913ec7923a3db48086af2e82393af9b08070c Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Fri, 8 Dec 2017 13:06:44 +0100
Subject: [PATCH] unit tests for voucher_type view

---
 smash/web/tests/functions.py              |  7 ++++-
 smash/web/tests/view/test_voucher_type.py | 32 +++++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 smash/web/tests/view/test_voucher_type.py

diff --git a/smash/web/tests/functions.py b/smash/web/tests/functions.py
index 7b5d331d..cfd5cf42 100644
--- a/smash/web/tests/functions.py
+++ b/smash/web/tests/functions.py
@@ -5,7 +5,8 @@ import os
 from django.contrib.auth.models import User
 
 from web.models import Location, AppointmentType, StudySubject, Worker, Visit, Appointment, ConfigurationItem, \
-    Language, ContactAttempt, FlyingTeam, Availability, Subject, Study, StudyColumns, StudyNotificationParameters
+    Language, ContactAttempt, FlyingTeam, Availability, Subject, Study, StudyColumns, StudyNotificationParameters, \
+    VoucherType
 from web.models.constants import REDCAP_TOKEN_CONFIGURATION_TYPE, REDCAP_BASE_URL_CONFIGURATION_TYPE, \
     SEX_CHOICES_MALE, SUBJECT_TYPE_CHOICES_CONTROL, CONTACT_TYPES_PHONE, \
     MONDAY_AS_DAY_OF_WEEK, COUNTRY_AFGHANISTAN_ID
@@ -26,6 +27,10 @@ def create_location(name="test"):
     return Location.objects.create(name=name)
 
 
+def create_voucher_type():
+    return VoucherType.objects.create(code="X", study=get_test_study())
+
+
 def create_empty_study_columns():
     study_columns = StudyColumns.objects.create(
         postponed=False,
diff --git a/smash/web/tests/view/test_voucher_type.py b/smash/web/tests/view/test_voucher_type.py
new file mode 100644
index 00000000..a3aa36ae
--- /dev/null
+++ b/smash/web/tests/view/test_voucher_type.py
@@ -0,0 +1,32 @@
+import logging
+
+from django.urls import reverse
+
+from web.models import VoucherType
+from web.models.constants import GLOBAL_STUDY_ID
+from web.tests.functions import create_voucher_type
+from .. import LoggedInTestCase
+
+logger = logging.getLogger(__name__)
+
+
+class VoucherTypeViewTests(LoggedInTestCase):
+    def test_render_add_voucher_type_request(self):
+        response = self.client.get(reverse('web.views.voucher_type_add'))
+        self.assertEqual(response.status_code, 200)
+
+    def test_render_edit_voucher_type_request(self):
+        voucher_type = create_voucher_type()
+        response = self.client.get(reverse('web.views.voucher_type_edit', kwargs={'pk': voucher_type.id}))
+        self.assertEqual(response.status_code, 200)
+
+    def test_add_voucher_type(self):
+        form_data = {
+            'code': "X",
+            'description': "y",
+            'study': str(GLOBAL_STUDY_ID),
+        }
+        response = self.client.post(reverse('web.views.voucher_type_add'), data=form_data)
+        self.assertEqual(response.status_code, 302)
+
+        self.assertEqual(1, VoucherType.objects.all().count())
-- 
GitLab