diff options
author | maxbr <maxbr@mi.fu-berlin.de> | 2016-10-17 14:56:11 +0200 |
---|---|---|
committer | maxbr <maxbr@mi.fu-berlin.de> | 2016-10-17 14:56:11 +0200 |
commit | af9b7ddeb637278a7705964ba98c8e6a2e7307f4 (patch) | |
tree | 503203445b0760bc5cd13c1e2d2347fe7fa069bf /tools/pharos-dashboard/src/booking/tests | |
parent | 7022542bc70c448f71fa56c06d90595e276d7dcc (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 'tools/pharos-dashboard/src/booking/tests')
-rw-r--r-- | tools/pharos-dashboard/src/booking/tests/test_models.py | 29 | ||||
-rw-r--r-- | tools/pharos-dashboard/src/booking/tests/test_views.py | 37 |
2 files changed, 39 insertions, 27 deletions
diff --git a/tools/pharos-dashboard/src/booking/tests/test_models.py b/tools/pharos-dashboard/src/booking/tests/test_models.py index 612b35c0..b4cd1133 100644 --- a/tools/pharos-dashboard/src/booking/tests/test_models.py +++ b/tools/pharos-dashboard/src/booking/tests/test_models.py @@ -10,12 +10,11 @@ from datetime import timedelta -from django.contrib.auth.models import User, Permission +from django.contrib.auth.models import Permission from django.test import TestCase from django.utils import timezone -from account.models import UserProfile -from booking.models import Booking +from booking.models import * from dashboard.models import Resource from jenkins.models import JenkinsSlave @@ -37,7 +36,10 @@ class BookingModelTestCase(TestCase): self.user1 = User.objects.get(pk=self.user1.id) - def test_start__end(self): + self.installer = Installer.objects.create(name='TestInstaller') + self.scenario = Scenario.objects.create(name='TestScenario') + + def test_start_end(self): """ if the start of a booking is greater or equal then the end, saving should raise a ValueException @@ -88,20 +90,5 @@ class BookingModelTestCase(TestCase): user=self.user1, resource=self.res1)) self.assertTrue( Booking.objects.create(start=start, end=end, - user=self.user1, resource=self.res2)) - - def test_authorization(self): - user = User.objects.create(username='user') - user.userprofile = UserProfile.objects.create(user=user) - self.assertRaises(PermissionError, Booking.objects.create, start=timezone.now(), - end=timezone.now() + timedelta(days=1), resource=self.res1, user=user) - self.res1.owner = user - self.assertTrue( - Booking.objects.create(start=timezone.now(), end=timezone.now() + timedelta(days=1), - resource=self.res1, user=user)) - self.res1.owner = self.owner - user.user_permissions.add(self.add_booking_perm) - user = User.objects.get(pk=user.id) - self.assertTrue( - Booking.objects.create(start=timezone.now(), end=timezone.now() + timedelta(days=1), - resource=self.res2, user=user)) + user=self.user1, resource=self.res2, scenario=self.scenario, + installer=self.installer))
\ No newline at end of file diff --git a/tools/pharos-dashboard/src/booking/tests/test_views.py b/tools/pharos-dashboard/src/booking/tests/test_views.py index e568c155..c1da013c 100644 --- a/tools/pharos-dashboard/src/booking/tests/test_views.py +++ b/tools/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 |