duck-booking-tool/api/tests.py

45 lines
1.2 KiB
Python
Raw Normal View History

from django.test import TestCase, Client
from django.core.urlresolvers import reverse
2014-12-23 08:56:04 +00:00
from django.contrib.auth.models import User
from booking.models import Species, Location, Duck, Competence, DuckCompetence
class ReverseTest(TestCase):
def setUp(self):
self.client = Client()
def test_reverse_js(self):
response = self.client.get(reverse('api:js_reverse'))
self.assertEqual(response.status_code, 200)
2014-12-23 08:56:04 +00:00
class ApiTest(TestCase):
def setUp(self):
self.client = Client()
species = Species(name = 'duck')
species.save()
loc = Location(name = 'test')
loc.save()
user = User()
user.save()
2015-01-05 15:13:08 +00:00
self.duck = Duck(
species = species,
location = loc,
donated_by = user)
2014-12-23 08:56:04 +00:00
self.duck.save()
comp = Competence(name = 'test', added_by = user)
comp.save()
duckcomp = DuckCompetence(duck = self.duck, comp = comp)
duckcomp.save()
def test_duck_comp_list(self):
response = self.client.get('/api/duck/1/competence.json')
self.assertEqual(response.status_code, 200)
2015-01-05 15:13:08 +00:00
self.assertEqual(len(response.context['comp_list']), 1)