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

Last change on this file since 17497 was 15251, checked in by Henrik Bettermann, 6 years ago

Adjust components to changes made in r15250.

  • Property svn:keywords set to Id
File size: 3.2 KB
RevLine 
[13323]1## $Id: tests.py 15251 2018-11-23 11:18:45Z henrik $
[13322]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):
[15251]39        self.app['hostels'].allocation_expiration = 7
40        config = self.app['configuration']
[13550]41        config.maintmode_enabled_by = u'any_user'
[13322]42        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
43        cat = queryUtility(ICatalog, name='beds_catalog')
44        bedticket = BedTicket()
45        bedticket.booking_session = 2004
46        bedticket.bed_coordinates = u'anything'
47        self.student['accommodation'].addBedTicket(bedticket)
48        self.app[
49            'hostels']['hall-x']['hall_block_room_bed'].owner = self.student_id
50        notify(grok.ObjectModifiedEvent(
51            self.app['hostels']['hall-x']['hall_block_room_bed']))
52        results = cat.searchResults(owner=(self.student_id, self.student_id))
53        self.assertEqual(len(results), 1)
54        self.browser.open(self.container_path + '/releaseexpired')
55        self.assertTrue('No bed released' in self.browser.contents)
[15249]56        delta = timedelta(days=8)   # 7 days expiration time span in Uniben
[13322]57        bedticket.booking_date = datetime.utcnow() - delta
58        self.browser.open(self.container_path + '/releaseexpired')
59        self.assertTrue(
60            'Successfully released beds: hall_block_room_bed (B1000000)'
61            in self.browser.contents)
62        results = cat.searchResults(owner=(self.student_id, self.student_id))
63        self.assertEqual(len(results), 0)
64        self.assertMatches(bedticket.display_coordinates,
65            '-- booking expired (2015-10-14 08:35:38 WAT) --')
66        self.assertEqual(
67            self.app['hostels']['hall-x']['hall_block_room_bed'].owner,
68            NOT_OCCUPIED)
69        # Releasing is logged.
70        logcontent = open(self.logfile).read()
71        self.assertTrue(
[15251]72            'hostels.browser.ReleaseExpiredAllocationsPage - hostels - '
[13322]73            'released: hall_block_room_bed (B1000000)'
74            in logcontent)
75        return
Note: See TracBrowser for help on using the repository browser.