Пример #1
0
def test_influx_load_series_dry_run_raises():
    ds = InfluxDataProvider(measurement="sensors", value_name="Value", client=None)
    from_ts = dateutil.parser.isoparse("2016-01-01T09:11:00+00:00")
    to_ts = dateutil.parser.isoparse("2016-01-01T10:30:00+00:00")
    tag_list = tu.SENSORTAG_LIST
    with pytest.raises(NotImplementedError):
        ds.load_series(from_ts=from_ts, to_ts=to_ts, tag_list=tag_list, dry_run=True)
Пример #2
0
def test_get_list_of_tags(influxdb):
    ds = InfluxDataProvider(
        measurement="sensors",
        value_name="Value",
        client=influx_client_from_uri(uri=tu.INFLUXDB_URI, dataframe_client=True),
    )
    expected_tags = set(tu.SENSORS_STR_LIST)

    tags = set(ds.get_list_of_tags())
    assert expected_tags == tags

    # The cache does not screw stuff up
    tags = set(ds.get_list_of_tags())
    assert expected_tags == tags
def test__list_of_tags_from_influx_validate_tag_names(influxdb):
    """
    Test expected tags in influx match the ones actually in influx.
    """
    ds = InfluxDataProvider(
        measurement="sensors",
        value_name="Value",
        client=influx_client_from_uri(uri=tu.INFLUXDB_URI,
                                      dataframe_client=True),
    )
    list_of_tags = ds._list_of_tags_from_influx()
    expected_tags = tu.SENSORS_STR_LIST
    tags = set(list_of_tags)
    assert set(expected_tags) == tags, (f"Expected tags = {expected_tags}"
                                        f"outputted {tags}")
Пример #4
0
def test_read_single_sensor_empty_data_invalid_tag_name_valueerror(influxdb):
    """
    Asserts that a ValueError is raised because the tag name inputted is invalid
    """
    from_ts = dateutil.parser.isoparse("2016-01-01T09:11:00+00:00")
    to_ts = dateutil.parser.isoparse("2016-01-01T10:30:00+00:00")

    ds = InfluxDataProvider(
        measurement="sensors",
        value_name="Value",
        client=influx_client_from_uri(uri=tu.INFLUXDB_URI, dataframe_client=True),
    )
    with pytest.raises(ValueError):
        ds.read_single_sensor(
            from_ts=from_ts,
            to_ts=to_ts,
            tag="tag-does-not-exist",
            measurement="sensors",
        )
Пример #5
0
def test_read_single_sensor_empty_data_time_range_indexerror(influxdb, caplog):
    """
    Asserts that an IndexError is raised because the dates requested are outside the existing time period
    """
    from_ts = dateutil.parser.isoparse("2017-01-01T09:11:00+00:00")
    to_ts = dateutil.parser.isoparse("2017-01-01T10:30:00+00:00")

    ds = InfluxDataProvider(
        measurement="sensors",
        value_name="Value",
        client=influx_client_from_uri(uri=tu.INFLUXDB_URI, dataframe_client=True),
    )

    with caplog.at_level(logging.CRITICAL):
        with pytest.raises(IndexError):
            ds.read_single_sensor(
                from_ts=from_ts,
                to_ts=to_ts,
                tag=tu.SENSORS_STR_LIST[0],
                measurement="sensors",
            )
Пример #6
0
def run_server_cli(
    host: str,
    port: int,
    src_influx_host: str,
    src_influx_port: int,
    src_influx_username: str,
    src_influx_password: str,
    src_influx_database: str,
    src_influx_path: str,
    src_influx_measurement: str,
    src_influx_value: str,
    src_influx_api_key: str,
    src_influx_api_key_header: str,
):

    # We have have a hostname, then we make a data provider
    if src_influx_host:
        influx_config = {
            "host": src_influx_host,
            "port": src_influx_port,
            "username": src_influx_username,
            "password": src_influx_password,
            "database": src_influx_database,
            "proxies": {
                "http": "",
                "https": ""
            },
            "ssl": True,
            "path": src_influx_path,
            "timeout": 20,
            "retries": 10,
        }

        provider = InfluxDataProvider(
            measurement=src_influx_measurement,
            value_name=src_influx_value,
            api_key=src_influx_api_key,
            api_key_header=src_influx_api_key_header,
            **influx_config,
        )
    else:
        provider = None  # type: ignore

    server.run_server(host, port, data_provider=provider)
Пример #7
0
def test_influx_dataset_attrs(influxdb):
    """
    Test expected attributes
    """
    from_ts = dateutil.parser.isoparse("2016-01-01T09:11:00+00:00")
    to_ts = dateutil.parser.isoparse("2016-01-01T10:30:00+00:00")
    tag_list = tu.SENSORTAG_LIST
    config = {
        "type": "TimeSeriesDataset",
        "from_ts": from_ts,
        "to_ts": to_ts,
        "tag_list": tag_list,
    }
    config["data_provider"] = InfluxDataProvider(
        measurement="sensors",
        value_name="Value",
        client=influx_client_from_uri(uri=tu.INFLUXDB_URI, dataframe_client=True),
    )
    dataset = _get_dataset(config)
    assert hasattr(dataset, "get_metadata")

    metadata = dataset.get_metadata()
    assert isinstance(metadata, dict)
Пример #8
0
                    "model-name": "test-model",
                    "machine-name": "machine-1",
                },
            },
        )
        yield tmp_dir


@pytest.fixture(
    # Data Provider(s) per test requiring this client
    params=[
        InfluxDataProvider(
            measurement="sensors",
            value_name="Value",
            proxies={
                "https": "",
                "http": ""
            },
            uri=tu.INFLUXDB_URI,
        )
    ],
    scope="session",
)
def gordo_ml_server_client(request, trained_model_directory):

    with tu.temp_env_vars(MODEL_LOCATION=trained_model_directory):

        app = server.build_app(data_provider=request.param)
        app.testing = True

        yield app.test_client()