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

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

Add application categories and types.

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