def test_db_sensor_filter(self, init_spaces): space_ids, _, building_ids, _ = init_spaces sensor_db = SensorDB() # check that database is empty result = sensor_db.get_all(building_id=building_ids[0]) assert list(result) == [] result = sensor_db.get_all(space_id=space_ids[0]) assert list(result) == [] # create an item sensor_db.create( Sensor( 'Sensor #0', localization=Localization(space_id=space_ids[0]), description='New sample sensor')) sensor_db.create( Sensor( 'Sensor #1', localization=Localization(space_id=space_ids[1]), description='New sample sensor')) # result = sensor_db.get_all(building_id=building_id) # assert len(list(result)) == 2 sensors = list(sensor_db.get_all(space_id=space_ids[0])) assert len(sensors) == 1 result = sensor_db.get_all(space_id=space_ids[1]) assert len(list(result)) == 1 assert sensors[0].localization.site_id and \ sensors[0].localization.building_id and \ sensors[0].localization.floor_id and \ sensors[0].localization.space_id
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 _create_sensors(site_ids, building_ids, floor_ids, space_ids): localization = [ Localization(site_id=site_ids[0]), Localization(building_id=building_ids[0]), Localization(space_id=space_ids[2]), Localization(floor_id=floor_ids[3]), ] sensors_data = [ { 'name': 'sensor_A', 'description': 'sensor version A' }, { 'name': 'sensor_B', 'description': 'sensor version B', 'static': 'False' }, { 'name': 'sensor_C', 'description': 'sensor version C' }, { 'name': 'sensor_D', 'description': 'sensor version D' }, ] return [ db_accessor.create(Sensor(**data, localization=localization[idx])) for idx, data in enumerate(sensors_data) ]
def init_sensors(): space_ids = init_spaces() sensors = [ Sensor('Sensor #{}'.format(idx + 1), localization=Localization(space_id=space_ids[1]), description='A sample sensor') for idx, _ in enumerate(_get_sensor_ids()) ] return [SensorDB().create(sensor) for sensor in sensors]