From 183545208bdfec06b52ee01c5c472358de6bcfbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Krienb=C3=BChl?= Date: Fri, 28 Aug 2015 11:31:41 +0200 Subject: [PATCH] Adds a test for the romm allocation edit form --- onegov/town/forms/allocation.py | 4 +--- onegov/town/tests/test_forms.py | 38 +++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/onegov/town/forms/allocation.py b/onegov/town/forms/allocation.py index c0f76f9..6751f7c 100644 --- a/onegov/town/forms/allocation.py +++ b/onegov/town/forms/allocation.py @@ -302,7 +302,5 @@ def apply_dates(self, start, end): self.end_time.data = '{:%H:%M}'.format(end) def apply_model(self, model): - self.date.data = model.display_start().date() + self.apply_dates(model.display_start(), model.display_end()) self.as_whole_day.data = model.whole_day and 'yes' or 'no' - self.start_time.data = '{:%H:%M}'.format(model.display_start()) - self.end_time.data = '{:%H:%M}'.format(model.display_end()) diff --git a/onegov/town/tests/test_forms.py b/onegov/town/tests/test_forms.py index 762c09c..dcbd563 100644 --- a/onegov/town/tests/test_forms.py +++ b/onegov/town/tests/test_forms.py @@ -1,13 +1,14 @@ import pytest -from datetime import date, datetime, time +from datetime import date, datetime, time, timedelta from dateutil.rrule import MO, WE from libres.db.models import Allocation from onegov.core.utils import Bunch from onegov.town.forms import ( DaypassAllocationForm, ReservationForm, - RoomAllocationForm + RoomAllocationForm, + RoomAllocationEditForm ) from onegov.town.forms.allocation import AllocationFormHelpers @@ -250,3 +251,36 @@ def test_reservation_form_quota(): allocation.quota_limit = 0 form = ReservationForm.for_allocation(allocation)() assert hasattr(form, 'quota') + + +def test_edit_room_alllocation_form(): + + form = RoomAllocationEditForm() + form.apply_dates(datetime(2015, 1, 1, 12, 0), datetime(2015, 1, 1, 18, 0)) + + assert form.date.data == date(2015, 1, 1) + assert form.start_time.data == '12:00' + assert form.end_time.data == '18:00' + + form.as_whole_day.data = 'no' + assert form.dates == ( + datetime(2015, 1, 1, 12, 0), + datetime(2015, 1, 1, 18, 0) + ) + + form.as_whole_day.data = 'yes' + assert form.dates == ( + datetime(2015, 1, 1), + datetime(2015, 1, 2) - timedelta(microseconds=1) + ) + + form.apply_model(Bunch( + display_start=lambda: datetime(2015, 1, 1, 12), + display_end=lambda: datetime(2015, 1, 1, 18), + whole_day=False + )) + + assert form.dates == ( + datetime(2015, 1, 1, 12, 0), + datetime(2015, 1, 1, 18, 0) + )