Skip to content

Commit

Permalink
re #51 Changed find_available_rooms to return the output of get_filte…
Browse files Browse the repository at this point in the history
…red(), which is more useful to the UI than just a list of IDs.
  • Loading branch information
mhrivnak committed Jan 19, 2012
1 parent 0764f7b commit 3619ce9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
7 changes: 4 additions & 3 deletions pr_services/resource_system/room_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,17 @@ def _create(self, auth_token, name, venue, capacity):
return r

@service_method
def get_available_rooms(self, auth_token, start, end, room_ids):
def get_available_rooms(self, auth_token, start, end, room_ids, requested_fields=None):
"""
Query rooms available (from a selected set of room IDs) during the specified timespan
@param auth_token The actor's authentication token
@param start Start time as ISO8601 string or datetime
@param end End time as ISO8601 string or datetime
@param room_ids Required list of room IDs to check
@return a filtered, simple list of available room IDs
@return a result set produced by get_filtered()
"""
requested_fields = requested_fields or []
test_room_ids = room_ids or [ ]

# convert time arguments from isoformat string to datetime, if not already
Expand Down Expand Up @@ -106,7 +107,7 @@ def get_available_rooms(self, auth_token, start, end, room_ids):
continue
auth.check_read_permissions(auth_token, pr_object, ['id'])
avail_ids.append(str(pr_object.id))
return avail_ids
return self.get_filtered(auth_token, {'member' : {'id' : avail_ids}}, requested_fields)


# vim:tabstop=4 shiftwidth=4 expandtab
18 changes: 10 additions & 8 deletions pr_svc_tests/tests_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,10 +896,11 @@ def test_get_available_rooms(self):
self.assertEquals(ret['status'], 'OK')
self.assertEquals(len(ret['value']), 3)
# make sure the busy rooms are NOT in this list
self.assertTrue(unicode(place_ids['v1_room1_id']) not in ret['value'])
self.assertTrue(unicode(place_ids['v1_room2_id']) in ret['value'])
self.assertTrue(unicode(place_ids['v2_room1_id']) in ret['value'])
self.assertTrue(unicode(place_ids['v2_room2_id']) in ret['value'])
room_ids = [room['id'] for room in ret['value']]
self.assertTrue(place_ids['v1_room1_id'] not in room_ids)
self.assertTrue(place_ids['v1_room2_id'] in room_ids)
self.assertTrue(place_ids['v2_room1_id'] in room_ids)
self.assertTrue(place_ids['v2_room2_id'] in room_ids)

# test without the conflicting IDs
test_room_ids = [
Expand Down Expand Up @@ -945,11 +946,12 @@ def test_get_available_rooms(self):
test_room_ids)
self.assertEquals(ret['status'], 'OK')
self.assertEquals(len(ret['value']), 2)
room_ids = [room['id'] for room in ret['value']]
# make sure rooms from blacked-out venue 1 are NOT in this list
self.assertTrue(unicode(place_ids['v1_room1_id']) not in ret['value'])
self.assertTrue(unicode(place_ids['v1_room2_id']) not in ret['value'])
self.assertTrue(unicode(place_ids['v2_room1_id']) in ret['value'])
self.assertTrue(unicode(place_ids['v2_room2_id']) in ret['value'])
self.assertTrue(place_ids['v1_room1_id'] not in room_ids)
self.assertTrue(place_ids['v1_room2_id'] not in room_ids)
self.assertTrue(place_ids['v2_room1_id'] in room_ids)
self.assertTrue(place_ids['v2_room2_id'] in room_ids)

class TestVenueManagerSvc(TestCase):
def test_get_available_venues(self):
Expand Down

0 comments on commit 3619ce9

Please sign in to comment.