Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/onegov/onegov.town
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krienbühl committed May 14, 2016
2 parents 7f9953a + 7081bbc commit d174eef
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
35 changes: 35 additions & 0 deletions onegov/town/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytz

from datetime import datetime, date
from freezegun import freeze_time
from io import BytesIO
from onegov.core.request import CoreRequest
from onegov.core.utils import module_path, rchop
Expand All @@ -13,6 +14,7 @@
ImageCollection,
SiteCollection
)
from onegov.town.models.resource import SharedMethods
from unittest.mock import Mock, patch


Expand Down Expand Up @@ -270,3 +272,36 @@ def __init__(self, mod_time):
assert groups[2][1] == images[5:6]
assert groups[3][0] == 'Older'
assert groups[3][1] == images[6:]


def test_calendar_date_range():
resource = SharedMethods()
utc = pytz.timezone('UTC')

resource.date = None
resource.timezone = utc

resource.view = 'month'
with freeze_time(datetime(2016, 5, 14, tzinfo=utc)):
assert resource.calendar_date_range == (
datetime(2016, 5, 1, tzinfo=utc),
datetime(2016, 5, 31, 23, 59, 59, 999999, tzinfo=utc)
)

resource.date = date(2016, 5, 14)
assert resource.calendar_date_range == (
datetime(2016, 5, 1, tzinfo=utc),
datetime(2016, 5, 31, 23, 59, 59, 999999, tzinfo=utc)
)

resource.view = 'agendaWeek'
assert resource.calendar_date_range == (
datetime(2016, 5, 9, tzinfo=utc),
datetime(2016, 5, 15, 23, 59, 59, 999999, tzinfo=utc)
)

resource.view = 'agendaDay'
assert resource.calendar_date_range == (
datetime(2016, 5, 14, tzinfo=utc),
datetime(2016, 5, 14, 23, 59, 59, 999999, tzinfo=utc)
)
50 changes: 50 additions & 0 deletions onegov/town/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,56 @@ def test_occupancy_view(town_app):
assert len(occupancy.pyquery('.occupancy-block')) == 1


def test_reservation_export_view(town_app):

# prepate the required data
resources = ResourceCollection(town_app.libres_context)
resource = resources.by_name('sbb-tageskarte')
resource.definition = "Vorname *= ___\nNachname *= ___"

scheduler = resource.get_scheduler(town_app.libres_context)

allocations = scheduler.allocate(
dates=(datetime(2015, 8, 28), datetime(2015, 8, 28)),
whole_day=True
)

client = Client(town_app)
reserve = bound_reserve(client, allocations[0])
transaction.commit()

client.login_admin()

# create a reservation
assert reserve().json == {'success': True}
formular = client.get('/ressource/sbb-tageskarte/formular')
formular.form['email'] = 'info@example.org'
formular.form['vorname'] = 'Charlie'
formular.form['nachname'] = 'Carson'
formular.form.submit().follow().click('Abschliessen')

ticket = client.get('/tickets/ALL/open').click('Annehmen').follow()

# at this point, the reservation won't show up in the export
export = client.get('/ressource/sbb-tageskarte/export')
export.form['start'] = date(2015, 8, 28)
export.form['end'] = date(2015, 8, 28)
export.form['file_format'] = 'json'
assert not export.form.submit().json

# until we confirm the reservation
ticket.click('Alle Reservationen annehmen')
charlie = export.form.submit().json[0]

assert charlie['email'] == 'info@example.org'
assert charlie['title'] == 'info@example.org, Charlie, Carson'
assert charlie['start'] == '2015-08-28T00:00:00+02:00'
assert charlie['end'] == '2015-08-29T00:00:00+02:00'
assert charlie['ticket'].startswith('RSV-')
assert charlie['quota'] == 1
assert charlie['form'] == {'vorname': 'Charlie', 'nachname': 'Carson'}


def test_reserve_session_separation(town_app):
c1 = Client(town_app)
c1.login_admin()
Expand Down

0 comments on commit d174eef

Please sign in to comment.