def test_db_site_get_empty(self): site_db = SiteDB() # get all items result = site_db.get_all() assert list(result) == [] # try to get an inexistant item with pytest.raises(ItemNotFoundError): site_db.get_by_id('not_existing')
def test_db_space_create(self, init_floors): floor_ids = init_floors space_db = SpaceDB() # check that database is empty result = space_db.get_all() assert list(result) == [] # create an item space_occ = SpaceOccupancy(9, 20) space = Space('Space #0', floor_ids[0], 'OpenSpace', space_occ) new_space_id = space_db.create(space) assert new_space_id is not None assert new_space_id == space.id # check that database is not empty now result = space_db.get_all() spaces = list(result) assert len(spaces) == 1 assert spaces[0].id == space.id assert spaces[0].name == space.name assert spaces[0].description == space.description assert spaces[0].kind == space.kind assert spaces[0].occupancy.nb_max == space_occ.nb_max assert spaces[0].occupancy.nb_permanents == space_occ.nb_permanents assert spaces[0].floor_id == space.floor_id == floor_ids[0] #ensure we can access the parent site sites = SiteDB().get_all() assert space_db.get_parent( space.id) in [str(site.id) for site in sites]
def test_db_sensor_create(self, init_spaces): space_ids, _, _, _ = init_spaces sensor_db = SensorDB() # check that database is empty result = sensor_db.get_all() assert list(result) == [] # create an item sensor = Sensor('Sensor #0', localization=Localization(space_id=space_ids[0]), description='New sample sensor') new_sensor_id = sensor_db.create(sensor) assert new_sensor_id is not None assert new_sensor_id == sensor.id # check that database is not empty now result = sensor_db.get_all() sensors = list(result) assert len(sensors) == 1 assert sensors[0].id == sensor.id assert sensors[0].name == sensor.name assert sensors[0].description == sensor.description self._check_equal_localization(sensors[0].localization, sensor.localization) assert sensors[0].static == sensor.static assert sensors[0].system_id == sensor.system_id assert set(sensors[0].measures) == set(sensor.measures) # ensure we can access the parent site sites = SiteDB().get_all() assert sensor_db.get_parent(sensor.id) in [ str(site.id) for site in sites]
def init_sites(): geo_info = GeographicInfo(44.803652, -0.600954, altitude=20) sites = [ Site('Site #{}'.format(idx + 1), geo_info, id=site_id) for idx, site_id in enumerate(_get_site_ids()) ] return [SiteDB().create(site) for site in sites]
def test_db_window_create(self, init_facades): facade_ids = init_facades window_db = WindowDB() # check that database is empty result = window_db.get_all() assert list(result) == [] # create an item window = Window('Window #0', facade_ids[0], SurfaceInfo(3.3, 1.3, 0.09), covering='Curtain', glazing='DoubleGlazing', u_value=54.32) new_window_id = window_db.create(window) assert new_window_id is not None assert new_window_id == window.id # check that database is not empty now result = window_db.get_all() windows = list(result) assert len(windows) == 1 assert windows[0].id == window.id assert windows[0].name == window.name assert windows[0].description == window.description assert windows[0].surface_info.area == window.surface_info.area assert windows[0].surface_info.max_height ==\ window.surface_info.max_height assert windows[0].surface_info.width == window.surface_info.width assert windows[0].covering == window.covering assert windows[0].glazing.replace(" ", "") == window.glazing assert windows[0].facade_id == window.facade_id == facade_ids[0] assert windows[0].u_value == window.u_value # ensure we can access the parent site sites = SiteDB().get_all() assert window_db.get_parent(window.id) in\ [str(site.id) for site in sites] # test with wrong value for covering window = Window('Window #0', facade_ids[0], SurfaceInfo(3.3, 1.3, 0.09), covering='Cobain', glazing='DoubleGlazing', u_value=76.32) with pytest.raises(ValidationError): new_window_id = window_db.create(window) # test with wrong value for glazing window = Window('Window #0', facade_ids[0], SurfaceInfo(3.3, 1.3, 0.09), covering='Curtain', glazing='GFGRT') with pytest.raises(ValidationError): new_window_id = window_db.create(window)
def test_db_site_create(self): site_db = SiteDB() # check that database is empty result = site_db.get_all() assert list(result) == [] # create an item geo_info = GeographicInfo(44.803652, -0.600954, altitude=20) site = Site('Site #0', geo_info) new_site_id = site_db.create(site) assert new_site_id is not None assert new_site_id == site.id # check that database is not empty now result = site_db.get_all() sites = list(result) assert len(sites) == 1 assert sites[0].id == site.id assert sites[0].name == site.name assert sites[0].description == site.description assert sites[0].geographic_info.latitude == geo_info.latitude assert sites[0].geographic_info.longitude == geo_info.longitude assert sites[0].geographic_info.altitude == geo_info.altitude # ensure we can access the parent site assert site_db.get_parent(site.id) == str(site.id) # test filtering parent site in the query sites = site_db.get_all(sites=['afakeid', site.id]) assert {site_.id for site_ in sites} == {site.id}
def test_db_wall_create(self, init_spaces, get_created_building_ids): space_ids = init_spaces building_ids = get_created_building_ids facade_db = FacadeDB() # check that database is empty result = facade_db.get_all() assert list(result) == [] # create an item facade = Facade('Facade #0', space_ids[:1], SurfaceInfo(32.3, 23, 0.9), building_ids[1], 0.323, orientation='South', interior=True) new_facade_id = facade_db.create(facade) assert new_facade_id is not None assert new_facade_id == facade.id # check that database is not empty now result = facade_db.get_all() facades = list(result) assert len(facades) == 1 assert facades[0].id == facade.id assert facades[0].name == facade.name assert facades[0].description == facade.description assert facades[0].surface_info.area == facade.surface_info.area assert facades[0].surface_info.max_height ==\ facade.surface_info.max_height assert facades[0].surface_info.width == facade.surface_info.width assert facades[0].windows_wall_ratio == facade.windows_wall_ratio assert facades[0].orientation == facade.orientation assert facades[0].interior == facade.interior assert facades[0].building_id == facade.building_id == building_ids[1] # ensure we can access the parent site sites = SiteDB().get_all() assert facade_db.get_parent(facade.id) in\ [str(site.id) for site in sites]
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]
def test_db_site_get_update_delete(self, init_sites): site_ids = init_sites site_db = SiteDB() # get all items result = site_db.get_all() sites = list(result) assert len(sites) == 2 for cur_site in sites: assert cur_site.id in site_ids # get an item by its ID site = site_db.get_by_id(sites[0].id) # update item data new_description = 'updated by patator' new_altitude = 42 site.description = new_description site.geographic_info.altitude = new_altitude site_db.update(site.id, site) # check that item has really been updated in database updated_site = site_db.get_by_id(site.id) assert updated_site.id == site.id assert updated_site.name == site.name assert updated_site.description == new_description assert (updated_site.geographic_info.latitude == site.geographic_info.latitude) assert (updated_site.geographic_info.longitude == site.geographic_info.longitude) assert updated_site.geographic_info.altitude == new_altitude # delete an item by its ID site_db.remove(site.id) # get an item by its ID with pytest.raises(ItemNotFoundError): # it has been removed... site_db.get_by_id(site.id)