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.contrib.auth.models import User
from django.conf import settings
@ -18,31 +19,31 @@ class DuckClassTest(WebTest):
self.user = User.objects.create_user(username='test',
password='test')
spec = Species.objects.create(name = 'duck')
spec = Species.objects.create(name='duck')
loc = Location.objects.create(name = 'temp')
loc = Location.objects.create(name='temp')
self.comp_bad = Competence.objects.create(name = 'test1',
added_by = self.user)
self.comp_bad = Competence.objects.create(name='test1',
added_by=self.user)
self.comp_good = Competence.objects.create(name = 'test2',
added_by = self.user)
self.comp_good = Competence.objects.create(name='test2',
added_by=self.user)
self.duck = Duck.objects.create(species = spec,
self.duck = Duck.objects.create(species=spec,
name='test duck',
location = loc,
donated_by = self.user,
location=loc,
donated_by=self.user,
color='123456')
DuckCompetence.objects.create(duck = self.duck,
comp = self.comp_bad,
up_minutes = bad_minutes,
down_minutes = 0)
DuckCompetence.objects.create(duck=self.duck,
comp=self.comp_bad,
up_minutes=bad_minutes,
down_minutes=0)
DuckCompetence.objects.create(duck = self.duck,
comp = self.comp_good,
up_minutes = good_minutes,
down_minutes = 0)
DuckCompetence.objects.create(duck=self.duck,
comp=self.comp_good,
up_minutes=good_minutes,
down_minutes=0)
def test_book_nonlogged(self):
page = self.app.post('/api/v1/ducks/1/book/', expect_errors=True)
@ -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 doesnt 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)

View File

@ -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()