Exemplo n.º 1
0
def test_find_with_filters(db, dummy_room, create_room, dummy_user,
                           create_equipment_type, create_room_attribute,
                           dummy_reservation):
    # Simple testcase that ensures we find the room when many filters are used
    other_room = create_room()
    assert set(Room.find_with_filters({},
                                      dummy_user)) == {dummy_room, other_room}
    create_room_attribute(u'attr')
    eq = create_equipment_type(u'eq')
    dummy_room.capacity = 100
    dummy_room.is_reservable = True
    dummy_room.available_equipment.append(eq)
    dummy_room.set_attribute_value(u'attr', u'meowmeow')
    db.session.flush()
    filters = {
        'available_equipment': {eq},
        'capacity': 90,
        'only_public': True,
        'is_only_my_rooms': True,
        'details': u'meow',
        'available': 0,
        'repeatability': 'None',
        'start_dt': dummy_reservation.start_dt,
        'end_dt': dummy_reservation.end_dt
    }
    assert set(Room.find_with_filters(filters, dummy_user)) == {dummy_room}
Exemplo n.º 2
0
def test_find_with_filters_details_cols(db, dummy_room, create_room, col):
    create_room()  # some room we won't find!
    assert set(Room.find_with_filters({}, None)) == set(Room.find_all())
    assert not Room.find_with_filters({'details': u'meow'}, None)
    setattr(dummy_room, col, u'meow')
    db.session.flush()
    assert set(Room.find_with_filters({'details': u'meow'},
                                      None)) == {dummy_room}
Exemplo n.º 3
0
def test_find_with_filters_only_my_rooms(dummy_room, create_user, owner_id,
                                         match):
    user = create_user(owner_id, legacy=True)
    if match:
        assert set(Room.find_with_filters({'is_only_my_rooms': True},
                                          user)) == {dummy_room}
    else:
        assert not Room.find_with_filters({'is_only_my_rooms': True}, user)
Exemplo n.º 4
0
def test_find_with_filters_availability_error():
    with pytest.raises(ValueError):
        filters = {
            'available': 123,
            'repeatability': 'None',
            'start_dt': datetime.now(),
            'end_dt': datetime.now()
        }
        Room.find_with_filters(filters, None)
Exemplo n.º 5
0
def test_find_with_filters_details_values(db, dummy_room, create_room, value,
                                          search_value, other_value):
    other_room = create_room()
    assert set(Room.find_with_filters({}, None)) == set(Room.find_all())
    assert not Room.find_with_filters({'details': search_value}, None)
    dummy_room.comments = value
    other_room.comments = other_value
    db.session.flush()
    assert set(Room.find_with_filters({'details': search_value},
                                      None)) == {dummy_room}
Exemplo n.º 6
0
def test_find_with_filters_only_public(dummy_room, create_room_attribute,
                                       is_reservable, booking_group, match):
    create_room_attribute(u'allowed-booking-group')
    dummy_room.is_reservable = is_reservable
    dummy_room.set_attribute_value(u'allowed-booking-group', booking_group)
    if match:
        assert set(Room.find_with_filters({'is_only_public': True},
                                          None)) == {dummy_room}
    else:
        assert not Room.find_with_filters({'is_only_public': True}, None)
Exemplo n.º 7
0
def test_find_with_filters_details_attrs(dummy_room, create_room,
                                         create_room_attribute, value,
                                         search_value, other_value):
    other_room = create_room()
    assert set(Room.find_with_filters({}, None)) == set(Room.find_all())
    assert not Room.find_with_filters({'details': search_value}, None)
    create_room_attribute(u'foo')
    assert not Room.find_with_filters({'details': search_value}, None)
    dummy_room.set_attribute_value(u'foo', value)
    other_room.set_attribute_value(u'foo', other_value)
    assert set(Room.find_with_filters({'details': search_value},
                                      None)) == {dummy_room}
Exemplo n.º 8
0
def test_find_with_filters_capacity(db, dummy_room, create_room, capacity,
                                    other_capacity, search_capacity, match,
                                    match_other):
    other_room = create_room()
    assert set(Room.find_with_filters({}, None)) == set(Room.find_all())
    dummy_room.capacity = capacity
    other_room.capacity = other_capacity
    db.session.flush()
    expected = set()
    if match:
        expected.add(dummy_room)
    if match_other:
        expected.add(other_room)
    assert set(Room.find_with_filters({'capacity': search_capacity},
                                      None)) == expected
Exemplo n.º 9
0
def test_find_with_filters_availability(dummy_room, dummy_reservation,
                                        available):
    if available:
        start_dt = dummy_reservation.end_dt + timedelta(days=1)
        end_dt = start_dt + timedelta(days=1)
    else:
        start_dt = dummy_reservation.start_dt
        end_dt = dummy_reservation.end_dt
    filters = {
        'available': int(available),
        'repeatability': 'None',
        'start_dt': start_dt,
        'end_dt': end_dt
    }
    assert set(Room.find_with_filters(filters, None)) == {dummy_room}
Exemplo n.º 10
0
def test_find_with_filters_equipment(db, dummy_room, create_room,
                                     create_equipment_type):
    other_room = create_room()
    assert set(Room.find_with_filters({}, None)) == set(Room.find_all())
    eq1 = create_equipment_type(u'eq1')
    eq2 = create_equipment_type(u'eq2')
    assert not Room.find_with_filters({'available_equipment': {eq1}}, None)
    dummy_room.available_equipment.append(eq1)
    db.session.flush()
    assert set(Room.find_with_filters({'available_equipment': {eq1}},
                                      None)) == {dummy_room}
    assert not Room.find_with_filters({'available_equipment': {eq1, eq2}},
                                      None)
    dummy_room.available_equipment.append(eq2)
    other_room.available_equipment.append(eq2)
    db.session.flush()
    assert set(Room.find_with_filters({'available_equipment': {eq1}},
                                      None)) == {dummy_room}
    assert set(Room.find_with_filters({'available_equipment': {eq2}},
                                      None)) == {dummy_room, other_room}
    assert set(
        Room.find_with_filters({'available_equipment': {eq1, eq2}},
                               None)) == {dummy_room}