コード例 #1
0
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]}
コード例 #2
0
    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(
            '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)
コード例 #3
0
    def export_room(self, user):
        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)
コード例 #4
0
def test_get_with_data_errors():
    with pytest.raises(ValueError):
        Room.get_with_data(foo='bar')