Changeset 13483
- Timestamp:
- 19 Nov 2015, 10:24:46 (9 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/hostels
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/hostels/container.py
r13319 r13483 23 23 from datetime import datetime 24 24 from zope.catalog.interfaces import ICatalog 25 from zope.component import queryUtility 26 from waeup.kofa.hostels.interfaces import IHostelsContainer, IHostel 25 from zope.component import queryUtility, getUtility, ComponentLookupError 26 from waeup.kofa.hostels.interfaces import ( 27 IHostelsContainer, IHostel, IHostelsUtils) 27 28 from waeup.kofa.utils.logger import Logger 28 29 from waeup.kofa.utils.helpers import attrs_to_fields … … 79 80 return False 80 81 82 @property 83 def statistics(self): 84 try: 85 statistics = getUtility( 86 IHostelsUtils).getBedStatistics() 87 except ComponentLookupError: # happens in unit tests 88 return 89 return statistics 90 81 91 logger_name = 'waeup.kofa.${sitename}.hostels' 82 92 logger_filename = 'hostels.log' -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/interfaces.py
r13475 r13483 20 20 from zope.component import getUtility 21 21 from zope.catalog.interfaces import ICatalog 22 from zope.interface import invariant, Invalid, Attribute 22 from zope.interface import invariant, Invalid, Attribute, Interface 23 23 from zope import schema 24 24 from waeup.kofa.interfaces import ( … … 43 43 44 44 expired = Attribute('True if current datetime is in application period.') 45 statistics = Attribute('Bed category statistics') 45 46 46 47 startdate = schema.Datetime( … … 295 296 """Add an INFO message to hostels.log. 296 297 """ 298 299 class IHostelsUtils(Interface): 300 """A collection of methods which are subject to customization. 301 """ 302 303 def getBedStatistics(): 304 """Return bed statistics. 305 """ -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/tests.py
r13445 r13483 31 31 from zope.security.interfaces import Unauthorized 32 32 from zope.catalog.interfaces import ICatalog 33 from zope.component import queryUtility 33 from zope.component import queryUtility, getUtility 34 34 from waeup.kofa.app import University 35 35 from waeup.kofa.hostels.interfaces import ( 36 IHostelsContainer, IHostel, IBed )36 IHostelsContainer, IHostel, IBed, IHostelsUtils) 37 37 from waeup.kofa.hostels.vocabularies import NOT_OCCUPIED 38 38 from waeup.kofa.hostels.container import HostelsContainer … … 162 162 bed.bed_id = u'hall_block_room_bed' 163 163 bed.bed_number = 1 164 bed.bed_type = u' a_b_c'164 bed.bed_type = u'regular_male_fr' 165 165 self.app['hostels'][hostel.hostel_id][bed.bed_id] = bed 166 166 … … 230 230 return 231 231 232 def test_bed_statistics(self): 233 utils = getUtility(IHostelsUtils) 234 self.app['hostels']['hall-x'][ 235 'hall_block_room_bed'].owner = NOT_OCCUPIED 236 notify(grok.ObjectModifiedEvent( 237 self.app['hostels']['hall-x']['hall_block_room_bed'])) 238 stats = utils.getBedStatistics() 239 self.assertEqual(stats, 240 {'regular_male_fr': (1, 1), 241 'regular_female_fi': (0, 0), 242 'regular_male_re': (0, 0), 243 'regular_female_fr': (0, 0), 244 'regular_female_all': (0, 0), 245 'regular_female_re': (0, 0), 246 'regular_male_fi': (0, 0), 247 'regular_male_all': (0, 0)} 248 ) 249 self.app[ 250 'hostels']['hall-x']['hall_block_room_bed'].owner = self.student_id 251 notify(grok.ObjectModifiedEvent( 252 self.app['hostels']['hall-x']['hall_block_room_bed'])) 253 stats = utils.getBedStatistics() 254 self.assertEqual(stats, 255 {'regular_male_fr': (0, 1), 256 'regular_female_fi': (0, 0), 257 'regular_male_re': (0, 0), 258 'regular_female_fr': (0, 0), 259 'regular_female_all': (0, 0), 260 'regular_female_re': (0, 0), 261 'regular_male_fi': (0, 0), 262 'regular_male_all': (0, 0)} 263 ) 264 232 265 class BedCatalogTests(HostelsFullSetup): 233 266 … … 242 275 # We can find a certain bed 243 276 cat = queryUtility(ICatalog, name='beds_catalog') 244 results = cat.searchResults(bed_type=(u'a_b_c', u'a_b_c')) 277 results = cat.searchResults( 278 bed_type=(u'regular_male_fr', u'regular_male_fr')) 245 279 results = [x for x in results] # Turn results generator into list 246 280 assert len(results) == 1 … … 531 565 result, 532 566 'bed_id,bed_number,bed_type,owner,hall,block,room,bed,' 533 'special_handling,sex,bt\r\nhall_block_room_bed,1, a_b_c,,'534 'hall,block,room,bed, a,b,c\r\n'567 'special_handling,sex,bt\r\nhall_block_room_bed,1,regular_male_fr,,' 568 'hall,block,room,bed,regular,male,fr\r\n' 535 569 ) 536 570 return
Note: See TracChangeset for help on using the changeset viewer.