[13323] | 1 | ## $Id: tests.py 13323 2015-10-14 19:50:00Z 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 | """ |
---|
| 19 | Tests for hostels and their UI components. |
---|
| 20 | """ |
---|
| 21 | import grok |
---|
| 22 | from datetime import datetime, timedelta |
---|
| 23 | from zope.event import notify |
---|
| 24 | from zope.testbrowser.testing import Browser |
---|
| 25 | from zope.catalog.interfaces import ICatalog |
---|
| 26 | from zope.component import queryUtility |
---|
| 27 | from waeup.kofa.hostels.vocabularies import NOT_OCCUPIED |
---|
| 28 | from waeup.kofa.students.accommodation import BedTicket |
---|
| 29 | from waeup.kofa.hostels.tests import HostelsFullSetup |
---|
| 30 | |
---|
| 31 | from waeup.uniben.testing import FunctionalLayer |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | class 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 |
---|