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/views.py | |
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/views.py')
-rw-r--r-- | tools/pharos-dashboard/src/booking/views.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/tools/pharos-dashboard/src/booking/views.py b/tools/pharos-dashboard/src/booking/views.py index 413573da..6fdca0e0 100644 --- a/tools/pharos-dashboard/src/booking/views.py +++ b/tools/pharos-dashboard/src/booking/views.py @@ -8,8 +8,6 @@ ############################################################################## -from datetime import timedelta - from django.conf import settings from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin @@ -45,7 +43,7 @@ def create_jira_ticket(user, booking): booking.save() -class BookingFormView(LoginRequiredMixin, FormView): +class BookingFormView(FormView): template_name = "booking/booking_calendar.html" form_class = BookingForm @@ -63,6 +61,11 @@ class BookingFormView(LoginRequiredMixin, FormView): return reverse('booking:create', kwargs=self.kwargs) def form_valid(self, form): + if not self.request.user.is_authenticated: + messages.add_message(self.request, messages.ERROR, + 'You need to be logged in to book a Pod.') + return super(BookingFormView, self).form_invalid(form) + user = self.request.user booking = Booking(start=form.cleaned_data['start'], end=form.cleaned_data['end'], @@ -75,9 +78,6 @@ class BookingFormView(LoginRequiredMixin, FormView): except ValueError as err: messages.add_message(self.request, messages.ERROR, err) return super(BookingFormView, self).form_invalid(form) - except PermissionError as err: - messages.add_message(self.request, messages.ERROR, err) - return super(BookingFormView, self).form_invalid(form) try: if settings.CREATE_JIRA_TICKET: create_jira_ticket(user, booking) @@ -101,6 +101,7 @@ class BookingView(TemplateView): context.update({'title': title, 'booking': booking}) return context + class BookingListView(TemplateView): template_name = "booking/booking_list.html" |