diff options
author | 2016-10-17 14:56:11 +0200 | |
---|---|---|
committer | 2016-10-17 14:56:11 +0200 | |
commit | 61f00f4110b1d33827e3bd19ffef34f10be8273a (patch) | |
tree | 2c24ca2a8414eb1f40d5363e03d3c2b21e1fec32 /pharos-dashboard/src/booking/tests/test_views.py | |
parent | adafb09cb1f221259970d16886ea0e03169899a5 (diff) |
Add unit tests
JIRA: RELENG-12
This commit increases test statement coverage to 84%. It also fixes the bugs
that emerged while testing.
Change-Id: I696091f1a07f8b7647872c7cb15f4368a4690619
Signed-off-by: maxbr <maxbr@mi.fu-berlin.de>
Diffstat (limited to 'pharos-dashboard/src/booking/tests/test_views.py')
-rw-r--r-- | pharos-dashboard/src/booking/tests/test_views.py | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/pharos-dashboard/src/booking/tests/test_views.py b/pharos-dashboard/src/booking/tests/test_views.py index e568c15..c1da013 100644 --- a/pharos-dashboard/src/booking/tests/test_views.py +++ b/pharos-dashboard/src/booking/tests/test_views.py @@ -10,12 +10,10 @@ from datetime import timedelta -from django.contrib import auth from django.test import Client -from django.utils import timezone -from django.contrib.auth.models import Permission from django.test import TestCase from django.urls import reverse +from django.utils import timezone from django.utils.encoding import force_text from registration.forms import User @@ -37,9 +35,6 @@ class BookingViewTestCase(TestCase): self.user1profile = UserProfile.objects.create(user=self.user1) self.user1.save() - self.add_booking_perm = Permission.objects.get(codename='add_booking') - self.user1.user_permissions.add(self.add_booking_perm) - self.user1 = User.objects.get(pk=self.user1.id) @@ -78,4 +73,34 @@ class BookingViewTestCase(TestCase): self.assertIn('resource', response.context) + def test_booking_view(self): + start = timezone.now() + end = start + timedelta(weeks=1) + booking = Booking.objects.create(start=start, end=end, user=self.user1, resource=self.res1) + url = reverse('booking:detail', kwargs={'booking_id':0}) + response = self.client.get(url) + self.assertEqual(response.status_code, 404) + + url = reverse('booking:detail', kwargs={'booking_id':booking.id}) + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed('booking/booking_detail.html') + self.assertIn('booking', response.context) + + def test_booking_list_view(self): + start = timezone.now() - timedelta(weeks=2) + end = start + timedelta(weeks=1) + Booking.objects.create(start=start, end=end, user=self.user1, resource=self.res1) + + url = reverse('booking:list') + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed('booking/booking_list.html') + self.assertTrue(len(response.context['bookings']) == 0) + + start = timezone.now() + end = start + timedelta(weeks=1) + Booking.objects.create(start=start, end=end, user=self.user1, resource=self.res1) + response = self.client.get(url) + self.assertTrue(len(response.context['bookings']) == 1)
\ No newline at end of file |