Increase test coverage
This commit is contained in:
parent
2b2c91bab6
commit
77a5bf35de
23
api/tests.py
23
api/tests.py
@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8
|
||||
from django.test import TestCase, Client
|
||||
from django.contrib.auth.models import User
|
||||
from django.conf import settings
|
||||
@ -70,10 +71,14 @@ class DuckClassTest(WebTest):
|
||||
self.assertEqual(404, page.status_code)
|
||||
|
||||
def test_book_warn(self):
|
||||
test_data = {
|
||||
'competence': self.comp_bad.pk,
|
||||
}
|
||||
url = '/api/v1/ducks/%d/book/' % self.duck.pk
|
||||
comp_none = Competence.objects.create(name='test3',
|
||||
added_by=self.user)
|
||||
|
||||
# Book for a competence the duck doesn’t have at all
|
||||
test_data = {
|
||||
'competence': comp_none.pk,
|
||||
}
|
||||
|
||||
page = self.app.post(url, params=test_data, user=self.user)
|
||||
self.assertEquals(200, page.status_code)
|
||||
@ -81,6 +86,18 @@ class DuckClassTest(WebTest):
|
||||
page_json = json.loads(page.content)
|
||||
self.assertEquals(page_json['status'], 'bad-comp')
|
||||
|
||||
# Book for a competence with low level
|
||||
test_data = {
|
||||
'competence': self.comp_bad.pk,
|
||||
}
|
||||
|
||||
page = self.app.post(url, params=test_data, user=self.user)
|
||||
self.assertEquals(200, page.status_code)
|
||||
|
||||
page_json = json.loads(page.content)
|
||||
self.assertEquals(page_json['status'], 'bad-comp')
|
||||
|
||||
# Forcibly book for a competence with low level
|
||||
test_data['force'] = 1
|
||||
|
||||
page = self.app.post(url, params=test_data, user=self.user)
|
||||
|
@ -271,29 +271,37 @@ class SimilarCompTest(TestCase):
|
||||
|
||||
class BookingTest(TestCase):
|
||||
def setUp(self):
|
||||
spec = Species(name = 'test')
|
||||
spec.save()
|
||||
spec = Species.objects.create(name='test')
|
||||
|
||||
loc = Location(name = 'test')
|
||||
loc.save()
|
||||
loc = Location.objects.create(name='test')
|
||||
|
||||
user = User(username = 'test')
|
||||
user.save()
|
||||
self.user = User.objects.create_user(username='test')
|
||||
|
||||
self.booked_duck = Duck(species = spec, location = loc, donated_by = user)
|
||||
self.booked_duck.save()
|
||||
self.booked_duck = Duck.objects.create(species=spec,
|
||||
location=loc,
|
||||
donated_by=self.user)
|
||||
|
||||
comp = Competence(name = 'test', added_by = user)
|
||||
comp.save()
|
||||
self.comp = Competence.objects.create(name='test',
|
||||
added_by=self.user)
|
||||
|
||||
booking = Booking(duck = self.booked_duck, user = user, comp_req = comp)
|
||||
booking.save()
|
||||
booking = Booking.objects.create(duck=self.booked_duck,
|
||||
user=self.user,
|
||||
comp_req=self.comp)
|
||||
|
||||
self.unbooked_duck = Duck(species = spec, location = loc, donated_by = user)
|
||||
self.unbooked_duck.save()
|
||||
self.unbooked_duck = Duck.objects.create(species=spec,
|
||||
location=loc,
|
||||
donated_by=self.user)
|
||||
|
||||
def test_booked_duck(self):
|
||||
self.assertNotEqual(self.booked_duck.booked_by(), None)
|
||||
|
||||
def test_unbooked_duck(self):
|
||||
self.assertEqual(self.unbooked_duck.booked_by(), None)
|
||||
|
||||
def test_multiple_booking(self):
|
||||
Booking.objects.create(duck=self.booked_duck,
|
||||
user=self.user,
|
||||
comp_req=self.comp)
|
||||
|
||||
with self.assertRaises(RuntimeError):
|
||||
self.booked_duck.booked_by()
|
||||
|
Loading…
Reference in New Issue
Block a user