From b8e0d18307bf286acc765517131db109b0ad8ce5 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Fri, 31 Mar 2017 18:06:32 +0200
Subject: [PATCH] test for api get locations

---
 smash/web/tests/test_api.py | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/smash/web/tests/test_api.py b/smash/web/tests/test_api.py
index 7772b9a2..fd6128ce 100644
--- a/smash/web/tests/test_api.py
+++ b/smash/web/tests/test_api.py
@@ -1,15 +1,12 @@
 # coding=utf-8
-import datetime
 import json
 
 from django.contrib.auth.models import User
-from django.test import TestCase
 from django.test import Client
+from django.test import TestCase
 from django.urls import reverse
 
-from web.models import Visit
-from web.api_views import cities
-from web.tests.functions import create_subject, create_worker, create_appointment_type
+from web.tests.functions import create_subject, create_worker, create_appointment_type, create_location
 
 __author__ = 'Piotr Gawron'
 
@@ -43,6 +40,24 @@ class TestApi(TestCase):
 
         self.assertTrue(city_name in cities)
 
+    def test_locations(self):
+        location_name = "some location"
+
+        response = self.client.get(reverse('web.api.locations'))
+        self.assertEqual(response.status_code, 200)
+
+        location = create_location(location_name)
+
+        response = self.client.get(reverse('web.api.locations'))
+        appointment_types = json.loads(response.content)['locations']
+
+        found = False
+        for type in appointment_types:
+            if type['name'] == location_name:
+                found = True
+
+        self.assertTrue(found)
+
     def test_countries(self):
         country_name = "some country"
 
@@ -130,7 +145,7 @@ class TestApi(TestCase):
 
         found = False
         for type in appointment_types:
-            if type['type']==type_name:
+            if type['type'] == type_name:
                 found = True
 
         self.assertTrue(found)
-- 
GitLab