def test_get_with_data(db, create_room, create_equipment_type, only_active): eq = create_equipment_type(u'eq') rooms = { 'inactive': { 'room': create_room(is_deleted=True), 'equipment': [] }, 'no_eq': { 'room': create_room(), 'equipment': [] }, 'all_eq': { 'room': create_room(), 'equipment': [eq] } } room_types = { room_data['room']: type_ for type_, room_data in rooms.iteritems() } for room in rooms.itervalues(): room['room'].available_equipment = room['equipment'] db.session.flush() results = list(Room.get_with_data(only_active=only_active)) assert len(results) == len(rooms) - only_active for row in results: room = row.pop('room') room_type = room_types[room] if room_type == 'inactive': assert not only_active
def test_get_with_data(db, create_room, create_equipment_type, only_active, data): eq = create_equipment_type(u'eq') vc = create_equipment_type(u'Video conference') vc1 = create_equipment_type(u'vc1') vc2 = create_equipment_type(u'vc2') vc.children.append(vc1) vc.children.append(vc2) rooms = { 'inactive': { 'room': create_room(is_active=False), 'equipment': set(), 'vc_equipment': set(), 'non_vc_equipment': set() }, 'no_eq': { 'room': create_room(), 'equipment': set(), 'vc_equipment': set(), 'non_vc_equipment': set() }, 'non_vc_eq': { 'room': create_room(), 'equipment': {eq}, 'vc_equipment': set(), 'non_vc_equipment': {eq} }, 'vc_eq': { 'room': create_room(), 'equipment': {vc, vc1, vc2}, 'vc_equipment': {vc1, vc2}, 'non_vc_equipment': {vc} }, 'all_eq': { 'room': create_room(), 'equipment': {eq, vc, vc1, vc2}, 'vc_equipment': {vc1, vc2}, 'non_vc_equipment': {vc, eq} } } room_types = { room_data['room']: type_ for type_, room_data in rooms.iteritems() } for room in rooms.itervalues(): room['room'].available_equipment = room['equipment'] db.session.flush() results = list(Room.get_with_data(*data, only_active=only_active)) assert len(results) == len(rooms) - only_active for row in results: room = row.pop('room') assert set(row.viewkeys()) == set(data) room_type = room_types[room] if room_type == 'inactive': assert not only_active for key in data: assert set(row[key]) == {x.name for x in rooms[room_type][key]}
def export_roomName(self, aw): loc = Location.find_first(name=self._location) if loc is None: return search_str = '%{}%'.format(self._room_name) rooms_data = Room.get_with_data('vc_equipment', 'non_vc_equipment', filters=[Room.location_id == loc.id, Room.name.ilike(search_str)]) for result in rooms_data: yield _serializable_room(result)
def export_roomName(self, user): loc = Location.find_first(name=self._location) if loc is None: return search_str = '%{}%'.format(self._room_name) rooms_data = Room.get_with_data(filters=[ Room.location_id == loc.id, or_(Room.name.ilike(search_str), Room.verbose_name.ilike( search_str)) ]) for result in rooms_data: yield _serializable_room(result)
def export_roomName(self, user): loc = Location.query.filter_by(name=self._location, is_deleted=False).first() if loc is None: return search_str = f'%{self._room_name}%' rooms_data = Room.get_with_data(filters=[ Room.location_id == loc.id, or_(Room.name.ilike(search_str), Room.verbose_name.ilike( search_str)) ]) for result in rooms_data: yield _serializable_room(result)
def export_roomName(self, user): loc = Location.query.filter_by(name=self._location, is_deleted=False).first() if loc is None: return search_str = '%{}%'.format(self._room_name) rooms_data = Room.get_with_data( filters=[ Room.location_id == loc.id, or_(Room.name.ilike(search_str), Room.verbose_name.ilike(search_str)) ]) for result in rooms_data: yield _serializable_room(result)
def export_roomName(self, aw): loc = Location.find_first(name=self._location) if loc is None: return search_str = '%{}%'.format(self._room_name) rooms_data = Room.get_with_data( 'vc_equipment', 'non_vc_equipment', filters=[ Room.location_id == loc.id, or_((Room.building + '-' + Room.floor + '-' + Room.number).ilike(search_str), Room.name.ilike(search_str)) ]) for result in rooms_data: yield _serializable_room(result)
def export_room(self, user): loc = Location.query.filter_by(name=self._location, is_deleted=False).first() if loc is None: return # Retrieve rooms rooms_data = list(Room.get_with_data(filters=[Room.id.in_(self._ids), Room.location_id == loc.id])) # Retrieve reservations reservations = None if self._detail == 'reservations': reservations = OrderedMultiDict(_export_reservations(self, True, False, [ Reservation.room_id.in_(x['room'].id for x in rooms_data) ])) for result in rooms_data: yield _serializable_room(result, reservations)
def export_room(self, user): loc = Location.query.filter_by(name=self._location, is_deleted=False) if loc is None: return # Retrieve rooms rooms_data = list(Room.get_with_data(filters=[Room.id.in_(self._ids), Room.location_id == loc.id])) # Retrieve reservations reservations = None if self._detail == 'reservations': reservations = OrderedMultiDict(_export_reservations(self, True, False, [ Reservation.room_id.in_(x['room'].id for x in rooms_data) ])) for result in rooms_data: yield _serializable_room(result, reservations)
def export_room(self, aw): loc = Location.find_first(name=self._location) if loc is None: return # Retrieve rooms rooms_data = list(Room.get_with_data('vc_equipment', 'non_vc_equipment', filters=[Room.id.in_(self._ids), Room.location_id == loc.id])) # Retrieve reservations reservations = None if self._detail == 'reservations': reservations = OrderedMultiDict(_export_reservations(self, True, False, [ Reservation.room_id.in_(x['room'].id for x in rooms_data) ])) for result in rooms_data: yield _serializable_room(result, reservations)
def test_get_with_data(db, create_room, create_equipment_type, only_active, data): eq = create_equipment_type(u'eq') vc = create_equipment_type(u'Video conference') vc1 = create_equipment_type(u'vc1') vc2 = create_equipment_type(u'vc2') vc.children.append(vc1) vc.children.append(vc2) rooms = { 'inactive': {'room': create_room(is_active=False), 'equipment': set(), 'vc_equipment': set(), 'non_vc_equipment': set()}, 'no_eq': {'room': create_room(), 'equipment': set(), 'vc_equipment': set(), 'non_vc_equipment': set()}, 'non_vc_eq': {'room': create_room(), 'equipment': {eq}, 'vc_equipment': set(), 'non_vc_equipment': {eq}}, 'vc_eq': {'room': create_room(), 'equipment': {vc, vc1, vc2}, 'vc_equipment': {vc1, vc2}, 'non_vc_equipment': {vc}}, 'all_eq': {'room': create_room(), 'equipment': {eq, vc, vc1, vc2}, 'vc_equipment': {vc1, vc2}, 'non_vc_equipment': {vc, eq}} } room_types = {room_data['room']: type_ for type_, room_data in rooms.iteritems()} for room in rooms.itervalues(): room['room'].available_equipment = room['equipment'] db.session.flush() results = list(Room.get_with_data(*data, only_active=only_active)) assert len(results) == len(rooms) - only_active for row in results: room = row.pop('room') assert row.viewkeys() == set(data) room_type = room_types[room] if room_type == 'inactive': assert not only_active for key in data: assert set(row[key]) == {x.name for x in rooms[room_type][key]}
def test_get_with_data(db, create_room, create_equipment_type, only_active, data): eq = create_equipment_type(u"eq") vc = create_equipment_type(u"Video conference") vc1 = create_equipment_type(u"vc1") vc2 = create_equipment_type(u"vc2") vc.children.append(vc1) vc.children.append(vc2) rooms = { "inactive": { "room": create_room(is_active=False), "equipment": set(), "vc_equipment": set(), "non_vc_equipment": set(), }, "no_eq": {"room": create_room(), "equipment": set(), "vc_equipment": set(), "non_vc_equipment": set()}, "non_vc_eq": {"room": create_room(), "equipment": {eq}, "vc_equipment": set(), "non_vc_equipment": {eq}}, "vc_eq": { "room": create_room(), "equipment": {vc, vc1, vc2}, "vc_equipment": {vc1, vc2}, "non_vc_equipment": {vc}, }, "all_eq": { "room": create_room(), "equipment": {eq, vc, vc1, vc2}, "vc_equipment": {vc1, vc2}, "non_vc_equipment": {vc, eq}, }, } room_types = {room_data["room"]: type_ for type_, room_data in rooms.iteritems()} for room in rooms.itervalues(): room["room"].available_equipment = room["equipment"] db.session.flush() results = list(Room.get_with_data(*data, only_active=only_active)) assert len(results) == len(rooms) - only_active for row in results: room = row.pop("room") assert row.viewkeys() == set(data) room_type = room_types[room] if room_type == "inactive": assert not only_active for key in data: assert set(row[key]) == {x.name for x in rooms[room_type][key]}
def test_get_with_data(db, create_room, create_equipment_type, only_active): eq = create_equipment_type(u'eq') rooms = { 'inactive': {'room': create_room(is_deleted=True), 'equipment': []}, 'no_eq': {'room': create_room(), 'equipment': []}, 'all_eq': {'room': create_room(), 'equipment': [eq]} } room_types = {room_data['room']: type_ for type_, room_data in rooms.iteritems()} for room in rooms.itervalues(): room['room'].available_equipment = room['equipment'] db.session.flush() results = list(Room.get_with_data(only_active=only_active)) assert len(results) == len(rooms) - only_active for row in results: room = row.pop('room') room_type = room_types[room] if room_type == 'inactive': assert not only_active
def test_get_with_data_errors(): with pytest.raises(ValueError): Room.get_with_data(foo='bar')