示例#1
0
def test_his_read_with_range_today(mock) -> None:
    # GIVEN
    """
    Args:
        mock:
    """
    envs = {'HAYSTACK_PROVIDER': 'shaystack.providers.ping'}
    mock.return_value = ping._PingGrid
    mime_type = shaystack.MODE_ZINC
    request = HaystackHttpRequest()
    grid = shaystack.Grid(columns=['id', 'range'])
    grid.append({"id": Ref("1234"), "range": "today"})
    request.headers["Content-Type"] = mime_type
    request.headers["Accept"] = mime_type
    request.body = shaystack.dump(grid, mode=mime_type)

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

    # THEN
    today = datetime.combine(date.today(), datetime.min.time()).replace(tzinfo=get_localzone())
    mock.assert_called_once_with(Ref("1234"),
                                 (today,
                                  today + timedelta(days=1)
                                  ), 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_his_read_with_range_one_datetime(mock) -> None:
    # GIVEN
    """
    Args:
        mock:
    """
    envs = {'HAYSTACK_PROVIDER': 'shaystack.providers.ping'}
    mock.return_value = ping._PingGrid
    mime_type = shaystack.MODE_ZINC
    request = HaystackHttpRequest()
    grid = shaystack.Grid(columns=['id', 'range'])
    datetime_1 = datetime(2020, 1, 1, 0, 0, 0, tzinfo=pytz.UTC)
    grid.append({"id": Ref("1234"), "range": datetime_1.isoformat()})
    request.headers["Content-Type"] = mime_type
    request.headers["Accept"] = mime_type
    request.body = shaystack.dump(grid, mode=mime_type)

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

    # THEN
    cur_datetime = datetime.combine(datetime_1, datetime.min.time()).replace(tzinfo=pytz.UTC)
    mock.assert_called_once_with(Ref("1234"),
                                 (cur_datetime,
                                  datetime.max.replace(tzinfo=pytz.UTC)
                                  ), None)
    assert response.status_code == 200
    assert response.headers["Content-Type"].startswith(mime_type)
    assert shaystack.parse(response.body, mime_type) is not None
示例#3
0
def test_his_read_with_zinc(mock, no_cache) -> None:
    # GIVEN
    """
    Args:
        mock:
        no_cache:
    """
    envs = {'HAYSTACK_PROVIDER': 'shaystack.providers.ping'}
    mock.return_value = ping._PingGrid
    no_cache.return_value = True
    mime_type = shaystack.MODE_ZINC
    request = HaystackHttpRequest()
    grid = shaystack.Grid(columns={'id': {}})
    grid.append({"id": Ref("1234")})
    request.headers["Content-Type"] = mime_type
    request.headers["Accept"] = mime_type
    request.body = shaystack.dump(grid, mode=mime_type)

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

    # THEN
    mock.assert_called_once_with(Ref("1234"),
                                 (datetime.min.replace(tzinfo=pytz.UTC),
                                  datetime.max.replace(tzinfo=pytz.UTC)), None)
    assert response.status_code == 200
    assert response.headers["Content-Type"].startswith(mime_type)
    assert shaystack.parse(response.body, mime_type) is not None
示例#4
0
def test_his_read_with_args(mock) -> None:
    # GIVEN
    """
    Args:
        mock:
    """
    envs = {'HAYSTACK_PROVIDER': 'shaystack.providers.ping'}
    mock.return_value = ping._PingGrid
    mime_type = DEFAULT_MIME_TYPE
    request = HaystackHttpRequest()
    request.args['id'] = str(Ref("1234"))

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

    # THEN
    mock.assert_called_once_with(Ref("1234"),
                                 (datetime.min.replace(tzinfo=pytz.UTC),
                                  datetime.max.replace(tzinfo=pytz.UTC)),
                                 None)
    assert response.status_code == 200
    assert response.headers["Content-Type"].startswith(mime_type)
    assert shaystack.parse(response.body, mime_type) is not None