source: main/waeup.uniben/trunk/src/waeup/uniben/hostels/tests.py @ 13418

Last change on this file since 13418 was 13323, checked in by Henrik Bettermann, 9 years ago

Add keyword Id.

  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1## $Id: tests.py 13323 2015-10-14 19:50:00Z henrik $
2##
3## Copyright (C) 2015 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""
19Tests for hostels and their UI components.
20"""
21import grok
22from datetime import datetime, timedelta
23from zope.event import notify
24from zope.testbrowser.testing import Browser
25from zope.catalog.interfaces import ICatalog
26from zope.component import queryUtility
27from waeup.kofa.hostels.vocabularies import NOT_OCCUPIED
28from waeup.kofa.students.accommodation import BedTicket
29from waeup.kofa.hostels.tests import HostelsFullSetup
30
31from waeup.uniben.testing import FunctionalLayer
32
33
34class HostelsContainerTests(HostelsFullSetup):
35
36    layer = FunctionalLayer
37
38    def test_release_expired_allocations(self):
39        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
40        cat = queryUtility(ICatalog, name='beds_catalog')
41        bedticket = BedTicket()
42        bedticket.booking_session = 2004
43        bedticket.bed_coordinates = u'anything'
44        self.student['accommodation'].addBedTicket(bedticket)
45        self.app[
46            'hostels']['hall-x']['hall_block_room_bed'].owner = self.student_id
47        notify(grok.ObjectModifiedEvent(
48            self.app['hostels']['hall-x']['hall_block_room_bed']))
49        results = cat.searchResults(owner=(self.student_id, self.student_id))
50        self.assertEqual(len(results), 1)
51        self.browser.open(self.container_path + '/releaseexpired')
52        self.assertTrue('No bed released' in self.browser.contents)
53        delta = timedelta(days=5)   # 4 days expiration time span in Uniben
54        bedticket.booking_date = datetime.utcnow() - delta
55        self.browser.open(self.container_path + '/releaseexpired')
56        self.assertTrue(
57            'Successfully released beds: hall_block_room_bed (B1000000)'
58            in self.browser.contents)
59        results = cat.searchResults(owner=(self.student_id, self.student_id))
60        self.assertEqual(len(results), 0)
61        self.assertMatches(bedticket.display_coordinates,
62            '-- booking expired (2015-10-14 08:35:38 WAT) --')
63        self.assertEqual(
64            self.app['hostels']['hall-x']['hall_block_room_bed'].owner,
65            NOT_OCCUPIED)
66        # Releasing is logged.
67        logcontent = open(self.logfile).read()
68        self.assertTrue(
69            'hostels.browser.CustomReleaseExpiredAllocationsPage - hostels - '
70            'released: hall_block_room_bed (B1000000)'
71            in logcontent)
72        return
Note: See TracBrowser for help on using the repository browser.