diff --git a/smash/web/tests/test_api_appointment_type.py b/smash/web/tests/test_api_appointment_type.py new file mode 100644 index 0000000000000000000000000000000000000000..24b06c1feda1ac4e0f6b20237fcd38147f00b529 --- /dev/null +++ b/smash/web/tests/test_api_appointment_type.py @@ -0,0 +1,40 @@ +# coding=utf-8 +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.tests.functions import create_worker, create_appointment_type + + +class TestApi(TestCase): + def setUp(self): + self.client = Client() + username = 'piotr' + password = 'top_secret' + self.user = User.objects.create_user( + username=username, email='jacob@bla', password=password) + self.worker = create_worker(self.user) + self.client.login(username=username, password=password) + + def test_appointment_types(self): + type_name = "some type name" + + response = self.client.get(reverse('web.api.appointment_types')) + self.assertEqual(response.status_code, 200) + + self.appointment_type = create_appointment_type() + self.appointment_type.code = type_name + self.appointment_type.save() + + response = self.client.get(reverse('web.api.appointment_types')) + appointment_types = json.loads(response.content)['appointment_types'] + + found = False + for type in appointment_types: + if type['type'] == type_name: + found = True + + self.assertTrue(found) diff --git a/smash/web/tests/test_api_location.py b/smash/web/tests/test_api_location.py new file mode 100644 index 0000000000000000000000000000000000000000..cd7c55167b75022e929324430344271ad8fac5de --- /dev/null +++ b/smash/web/tests/test_api_location.py @@ -0,0 +1,38 @@ +# coding=utf-8 +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.tests.functions import create_worker, create_location + + +class TestApi(TestCase): + def setUp(self): + self.client = Client() + username = 'piotr' + password = 'top_secret' + self.user = User.objects.create_user( + username=username, email='jacob@bla', password=password) + self.worker = create_worker(self.user) + self.client.login(username=username, password=password) + + def test_locations(self): + location_name = "some location" + + response = self.client.get(reverse('web.api.locations')) + self.assertEqual(response.status_code, 200) + + create_location(location_name) + + response = self.client.get(reverse('web.api.locations')) + locations = json.loads(response.content)['locations'] + + found = False + for location in locations: + if location['name'] == location_name: + found = True + + self.assertTrue(found) diff --git a/smash/web/tests/test_api.py b/smash/web/tests/test_api_subject.py similarity index 80% rename from smash/web/tests/test_api.py rename to smash/web/tests/test_api_subject.py index b90f1c354301eaa6b283b26bebbd09e11acc001c..3e23b592b4f3603870ffee66952a9879df3c5546 100644 --- a/smash/web/tests/test_api.py +++ b/smash/web/tests/test_api_subject.py @@ -43,24 +43,6 @@ 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" @@ -79,42 +61,6 @@ class TestApi(TestCase): self.assertTrue(country_name in countries) - def test_specializations(self): - specialization_name = "some spec" - - response = self.client.get(reverse('web.api.specializations')) - self.assertEqual(response.status_code, 200) - - specializations = json.loads(response.content)['specializations'] - - self.assertFalse(specialization_name in specializations) - - self.worker.specialization = specialization_name - self.worker.save() - - response = self.client.get(reverse('web.api.specializations')) - specializations = json.loads(response.content)['specializations'] - - self.assertTrue(specialization_name in specializations) - - def test_units(self): - unit_name = "some unit" - - response = self.client.get(reverse('web.api.units')) - self.assertEqual(response.status_code, 200) - - units = json.loads(response.content)['units'] - - self.assertFalse(unit_name in units) - - self.worker.unit = unit_name - self.worker.save() - - response = self.client.get(reverse('web.api.units')) - units = json.loads(response.content)['units'] - - self.assertTrue(unit_name in units) - def test_referrals(self): referral_name = "some referral" @@ -133,26 +79,6 @@ class TestApi(TestCase): self.assertTrue(referral_name in referrals) - def test_appointment_types(self): - type_name = "some type name" - - response = self.client.get(reverse('web.api.appointment_types')) - self.assertEqual(response.status_code, 200) - - self.appointment_type = create_appointment_type() - self.appointment_type.code = type_name - self.appointment_type.save() - - response = self.client.get(reverse('web.api.appointment_types')) - appointment_types = json.loads(response.content)['appointment_types'] - - found = False - for type in appointment_types: - if type['type'] == type_name: - found = True - - self.assertTrue(found) - def test_subjects_general(self): response = self.client.get(reverse('web.api.subjects', kwargs={'type': SUBJECT_LIST_GENERIC})) self.assertEqual(response.status_code, 200) diff --git a/smash/web/tests/test_api_worker.py b/smash/web/tests/test_api_worker.py new file mode 100644 index 0000000000000000000000000000000000000000..f3f353d3b4fbd2a45dd4703545dc8269b5f2c617 --- /dev/null +++ b/smash/web/tests/test_api_worker.py @@ -0,0 +1,56 @@ +# coding=utf-8 +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.tests.functions import create_subject, create_worker + + +class TestApi(TestCase): + def setUp(self): + self.client = Client() + username = 'piotr' + password = 'top_secret' + self.user = User.objects.create_user( + username=username, email='jacob@bla', password=password) + self.worker = create_worker(self.user) + self.client.login(username=username, password=password) + + def test_specializations(self): + specialization_name = "some spec" + + response = self.client.get(reverse('web.api.specializations')) + self.assertEqual(response.status_code, 200) + + specializations = json.loads(response.content)['specializations'] + + self.assertFalse(specialization_name in specializations) + + self.worker.specialization = specialization_name + self.worker.save() + + response = self.client.get(reverse('web.api.specializations')) + specializations = json.loads(response.content)['specializations'] + + self.assertTrue(specialization_name in specializations) + + def test_units(self): + unit_name = "some unit" + + response = self.client.get(reverse('web.api.units')) + self.assertEqual(response.status_code, 200) + + units = json.loads(response.content)['units'] + + self.assertFalse(unit_name in units) + + self.worker.unit = unit_name + self.worker.save() + + response = self.client.get(reverse('web.api.units')) + units = json.loads(response.content)['units'] + + self.assertTrue(unit_name in units)