コード例 #1
0
def test_his_write_with_args(mock):
    # GIVEN
    """
    Args:
        mock:
    """
    envs = {'HAYSTACK_PROVIDER': 'shaystack.providers.ping'}
    time_serie = [
        (datetime(2020, 1, 1, tzinfo=pytz.utc).isoformat() + " UTC", 100),
        (datetime(2020, 1, 2, tzinfo=pytz.utc).isoformat() + " UTC", 200)]
    mock.return_value = ping._PingGrid
    mime_type = DEFAULT_MIME_TYPE
    request = HaystackHttpRequest()
    request.args['id'] = str(Ref("1234"))
    request.args['ts'] = str(time_serie)

    # WHEN
    response = shaystack.his_write(envs, request, "dev")

    # THEN
    result_ts = Grid(version=VER_3_0, columns=["date", "val"])
    result_ts.extend([{"date": parse_hs_datetime_format(d, pytz.UTC), "val": v} for d, v in time_serie])
    mock.assert_called_once_with(Ref("1234"), result_ts, None)
    assert response.status_code == 200
    assert response.headers["Content-Type"].startswith(mime_type)
    assert shaystack.parse(response.body, mime_type) is not None
コード例 #2
0
def test_merge_timeseries_olds_values():
    """The destination has old data. Reinject the history"""
    source = Grid(columns=["ts", "value"])
    source.append({
        "ts": datetime(2020, 1, 1, 0, 0, 2, 0, tzinfo=pytz.UTC),
        "value": 100
    })
    destination = Grid(columns=["ts", "value"])
    destination.extend([
        {
            "ts": datetime(2020, 2, 1, 0, 0, 2, 0, tzinfo=pytz.UTC),
            "value": 100
        },
        {
            "ts": datetime(2020, 3, 1, 0, 0, 2, 0, tzinfo=pytz.UTC),
            "value": 100
        },
    ])
    expected_grid = Grid(columns=["ts", "value"])
    expected_grid.extend([
        {
            "ts": datetime(2020, 1, 1, 0, 0, 2, 0, tzinfo=pytz.UTC),
            "value": 100
        },
        {
            "ts": datetime(2020, 2, 1, 0, 0, 2, 0, tzinfo=pytz.UTC),
            "value": 100
        },
        {
            "ts": datetime(2020, 3, 1, 0, 0, 2, 0, tzinfo=pytz.UTC),
            "value": 100
        },
    ])
    result_grid = merge_timeseries(source, destination)
    assert result_grid == expected_grid
コード例 #3
0
ファイル: test_graphql.py プロジェクト: flzara/shaystack
def test_his_read_with_boolean(mock_s3, mock_get_url):
    """
    Args:
        mock_s3:
        mock_get_url:
    """
    mock_s3.return_value = _get_mock_s3()
    his = Grid(version=VER_3_0, columns=["ts", "val"])
    his.extend([
        {
            "ts": datetime(2020, 1, 1, tzinfo=pytz.utc),
            "val": MARKER
        },
        {
            "ts": datetime(2020, 1, 1, tzinfo=pytz.utc),
            "val": False
        },
        {
            "ts": datetime(2020, 1, 1, tzinfo=pytz.utc),
            "val": 1
        },
        {
            "ts": datetime(2020, 1, 1, tzinfo=pytz.utc),
            "val": 1.0
        },
        {
            "ts": datetime(2020, 1, 1, tzinfo=pytz.utc),
            "val": ""
        },
    ])
    mock_s3.return_value.history = his
    mock_get_url.return_value = "s3://bucket/grid.zinc"

    envs = {'HAYSTACK_PROVIDER': "shaystack.providers.url"}
    with get_provider("shaystack.providers.url", envs) as _:
        client = Client(schema)
        executed = client.execute('''
        { 
            haystack
            { 
                histories(ids:"@id1")
                {
                    ts
                    val
                    bool
                }
            }
        }
        ''')
        assert executed == \
               {'data': {'haystack':
                             {'histories': [[{'ts': '2020-01-01T00:00:00+00:00 UTC', 'val': 'm:', 'bool': True},
                                             {'ts': '2020-01-01T00:00:00+00:00 UTC', 'val': False,
                                              'bool': False},
                                             {'ts': '2020-01-01T00:00:00+00:00 UTC', 'val': 'n:1.000000',
                                              'bool': True},
                                             {'ts': '2020-01-01T00:00:00+00:00 UTC', 'val': 'n:1.000000',
                                              'bool': True},
                                             {'ts': '2020-01-01T00:00:00+00:00 UTC', 'val': 's:',
                                              'bool': False}]]}}}
コード例 #4
0
def test_merge_timeseries_source_overflow():
    source = Grid(columns=["ts", "value"])
    source.append({
        "ts": datetime(2020, 2, 1, 0, 0, 2, 0, tzinfo=pytz.UTC),
        "value": 100
    })
    destination = Grid(columns=["ts", "value"])
    destination.extend([
        {
            "ts": datetime(2020, 1, 1, 0, 0, 2, 0, tzinfo=pytz.UTC),
            "value": 100
        },
        {
            "ts": datetime(2020, 3, 1, 0, 0, 2, 0, tzinfo=pytz.UTC),
            "value": 100
        },
    ])
    result_grid = merge_timeseries(source, destination)
    assert destination == result_grid