Esempio n. 1
0
    def test_db_slab_get_filter(self, init_floors):
        floor_ids, building_ids, _ = init_floors
        building_id = building_ids[0]
        slab_db = SlabDB()

        # check that database is empty
        result = slab_db.get_all(building_id=building_id)
        assert list(result) == []
        result = slab_db.get_all(space_id=floor_ids[0])
        assert list(result) == []

        # create an item
        slab_db.create(
            Slab('Slab #0', [floor_ids[0]],
                 SurfaceInfo(32.3, 23, 0.9),
                 building_id,
                 kind='Roof'))
        slab_db.create(
            Slab('Slab #1',
                 floor_ids,
                 SurfaceInfo(32.3, 23, 0.9),
                 building_id,
                 kind='FloorSlab'))
        result = slab_db.get_all(building_id=building_id)
        assert len(list(result)) == 2

        result = slab_db.get_all(floor_id=floor_ids[0])
        assert len(list(result)) == 2
        result = slab_db.get_all(floor_id=floor_ids[1])
        assert len(list(result)) == 1
Esempio n. 2
0
def _create_slabs(building_ids, floors):
    slabs_data = [
        {
            'name': 'slab_A',
            'kind': 'BaseSlab',
            'building_id': building_ids[0]
        },
        {
            'name': 'slab_B',
            'kind': 'FloorSlab',
            'building_id': building_ids[0]
        },
        {
            'name': 'slab_C',
            'building_id': building_ids[2]
        },
        {
            'name': 'slab_D',
            'kind': 'Roof',
            'building_id': building_ids[3]
        },
    ]

    nb_floors = randint(0, len(floors))
    f_floors = [str(floor_id) for floor_id in floors[:nb_floors]]

    f_surface_info = SurfaceInfo(area=100)

    return [
        db_accessor.create(
            Slab(floors=f_floors, surface_info=f_surface_info, **data))
        for data in slabs_data
    ]
Esempio n. 3
0
def init_slabs():
    floor_ids, building_ids, site_ids = init_floors()
    slabs = [
        Slab('Slab #{}'.format(idx+1), [floor_ids[0], floor_ids[1]],
             SurfaceInfo(25, 3.54, 0.012), building_ids[0],
             description='A sample slab', kind='FloorSlab', id=slab_id)
        for idx, slab_id in enumerate(_get_slab_ids())]
    slab_ids = [SlabDB().create(slab) for slab in slabs]
    return slab_ids, floor_ids, building_ids, site_ids
Esempio n. 4
0
    def test_db_slab_create(self, init_floors):

        floor_ids, building_ids, _ = init_floors
        slab_db = SlabDB()

        # check that database is empty
        result = slab_db.get_all()
        assert list(result) == []

        # create an item
        slab = Slab('Slab #0',
                    floor_ids[:1],
                    SurfaceInfo(32.3, 23, 0.9),
                    building_ids[1],
                    kind='Roof')
        new_slab_id = slab_db.create(slab)
        assert new_slab_id is not None
        assert new_slab_id == slab.id

        # check that database is not empty now
        result = slab_db.get_all()
        slabs = list(result)
        assert len(slabs) == 1
        assert slabs[0].id == slab.id
        assert slabs[0].name == slab.name
        assert slabs[0].description == slab.description
        assert slabs[0].surface_info.area == slab.surface_info.area
        assert slabs[0].surface_info.max_height ==\
            slab.surface_info.max_height
        assert set(slabs[0].floors) == set(slab.floors)
        assert slabs[0].kind == slab.kind
        assert slabs[0].building_id == slab.building_id == building_ids[1]

        # ensure we can access the parent site
        sites = SiteDB().get_all()
        assert slab_db.get_parent(slab.id) in\
            [str(site.id) for site in sites]