示例#1
0
    def test_db_measure_update(self, init_measures, get_created_building_ids):

        measure_ids = init_measures
        building_ids = get_created_building_ids
        measure_db = MeasureDB()

        # get all items
        result = measure_db.get_all()
        measures = list(result)
        assert len(measures) == 2
        for cur_measure in measures:
            assert cur_measure.id in measure_ids

        # get an item by its ID
        measure = measure_db.get_by_id(measures[0].id)
        old_sensor_id = measure.sensor_id
        old_locations = measure.associated_locations

        # update item data
        new_description = 'updated by patator'
        new_locations = [str(building_ids[0])]
        new_frequency = 12
        measure.description = new_description
        measure.associated_locations = new_locations
        measure.on_index = True
        material_pties = MeasureValueProperties(frequency=new_frequency)
        measure.value_properties = material_pties
        measure_db.update(measure.id, measure)
        #
        # # check that item has really been updated in database
        updated_measure = measure_db.get_by_id(measure.id)
        assert updated_measure.id == measure.id
        assert updated_measure.description == new_description
        for loc_type in ['building', 'site']:
            assert len([
                loc for loc in updated_measure.associated_locations
                if loc.type == loc_type
            ]) == 1
        for loc_type in ['space', 'floor']:
            assert len([
                loc for loc in updated_measure.associated_locations
                if loc.type == loc_type
            ]) == 0
        assert [
            loc.id for loc in updated_measure.associated_locations
            if loc.type == 'building'
        ] == [building_ids[0]]
        assert updated_measure.on_index
        assert updated_measure.sensor_id == old_sensor_id
        assert set(updated_measure.associated_locations) != set(old_locations)
        assert updated_measure.value_properties.frequency == new_frequency

        # delete an item by its ID
        measure_db.remove(measure.id)

        # get an item by its ID
        with pytest.raises(ItemNotFoundError):
            # it has been removed...
            measure_db.get_by_id(measure.id)
示例#2
0
    def test_db_measure_get_empty(self):

        measure_db = MeasureDB()

        # get all items
        result = measure_db.get_all()
        assert list(result) == []

        # try to get an inexistant item
        with pytest.raises(ItemNotFoundError):
            measure_db.get_by_id('not_existing')