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

tests for api

parent a5d10350
No related branches found
No related tags found
1 merge request!21tests for api
Pipeline #
# 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.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
__author__ = 'Piotr Gawron'
class TestApi(TestCase):
def setUp(self):
self.subject = create_subject()
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_cities(self):
city_name = "some city"
response = self.client.get(reverse('web.api.cities'))
self.assertEqual(response.status_code, 200)
cities = json.loads(response.content)['cities']
self.assertFalse(city_name in cities)
self.subject.city = city_name
self.subject.save()
response = self.client.get(reverse('web.api.cities'))
cities = json.loads(response.content)['cities']
self.assertTrue(city_name in cities)
def test_countries(self):
country_name = "some country"
response = self.client.get(reverse('web.api.countries'))
self.assertEqual(response.status_code, 200)
countries = json.loads(response.content)['countries']
self.assertFalse(country_name in countries)
self.subject.country = country_name
self.subject.save()
response = self.client.get(reverse('web.api.countries'))
countries = json.loads(response.content)['countries']
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"
response = self.client.get(reverse('web.api.referrals'))
self.assertEqual(response.status_code, 200)
referrals = json.loads(response.content)['referrals']
self.assertFalse(referral_name in referrals)
self.subject.referral = referral_name
self.subject.save()
response = self.client.get(reverse('web.api.referrals'))
referrals = json.loads(response.content)['referrals']
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)
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