Increase test coverage

This commit is contained in:
Gergely Polonkai 2015-10-20 11:16:58 +02:00
parent 2b2c91bab6
commit 77a5bf35de
2 changed files with 59 additions and 34 deletions

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8
from django.test import TestCase, Client from django.test import TestCase, Client
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.conf import settings from django.conf import settings
@ -70,10 +71,14 @@ class DuckClassTest(WebTest):
self.assertEqual(404, page.status_code) self.assertEqual(404, page.status_code)
def test_book_warn(self): def test_book_warn(self):
test_data = {
'competence': self.comp_bad.pk,
}
url = '/api/v1/ducks/%d/book/' % self.duck.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 doesnt have at all
test_data = {
'competence': comp_none.pk,
}
page = self.app.post(url, params=test_data, user=self.user) page = self.app.post(url, params=test_data, user=self.user)
self.assertEquals(200, page.status_code) self.assertEquals(200, page.status_code)
@ -81,6 +86,18 @@ class DuckClassTest(WebTest):
page_json = json.loads(page.content) page_json = json.loads(page.content)
self.assertEquals(page_json['status'], 'bad-comp') 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 test_data['force'] = 1
page = self.app.post(url, params=test_data, user=self.user) page = self.app.post(url, params=test_data, user=self.user)

View File

@ -271,29 +271,37 @@ class SimilarCompTest(TestCase):
class BookingTest(TestCase): class BookingTest(TestCase):
def setUp(self): def setUp(self):
spec = Species(name = 'test') spec = Species.objects.create(name='test')
spec.save()
loc = Location(name = 'test') loc = Location.objects.create(name='test')
loc.save()
user = User(username = 'test') self.user = User.objects.create_user(username='test')
user.save()
self.booked_duck = Duck(species = spec, location = loc, donated_by = user) self.booked_duck = Duck.objects.create(species=spec,
self.booked_duck.save() location=loc,
donated_by=self.user)
comp = Competence(name = 'test', added_by = user) self.comp = Competence.objects.create(name='test',
comp.save() added_by=self.user)
booking = Booking(duck = self.booked_duck, user = user, comp_req = comp) booking = Booking.objects.create(duck=self.booked_duck,
booking.save() user=self.user,
comp_req=self.comp)
self.unbooked_duck = Duck(species = spec, location = loc, donated_by = user) self.unbooked_duck = Duck.objects.create(species=spec,
self.unbooked_duck.save() location=loc,
donated_by=self.user)
def test_booked_duck(self): def test_booked_duck(self):
self.assertNotEqual(self.booked_duck.booked_by(), None) self.assertNotEqual(self.booked_duck.booked_by(), None)
def test_unbooked_duck(self): def test_unbooked_duck(self):
self.assertEqual(self.unbooked_duck.booked_by(), None) 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()