Skip to content
Snippets Groups Projects
Commit 4ecc10be authored by Piotr Gawron's avatar Piotr Gawron
Browse files

refactor of api tests

parent 52c47381
No related branches found
No related tags found
1 merge request!35performance on appointment list
# 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)
# 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)
......@@ -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)
......
# 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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment