Пример #1
0
def test_round_range():
    start, end, interval = get_date_range({"statsPeriod": "2d"})
    assert start == datetime(2018, 12, 9, 4, tzinfo=pytz.utc)
    assert end == datetime(2018, 12, 11, 4, tzinfo=pytz.utc)

    start, end, interval = get_date_range({
        "statsPeriod": "2d",
        "interval": "1d"
    })
    assert start == datetime(2018, 12, 10, tzinfo=pytz.utc)
    assert end == datetime(2018, 12, 12, 0, 0, tzinfo=pytz.utc)
Пример #2
0
def test_timestamps():
    start, end, interval = get_date_range({
        "statsPeriod": "1d",
        "interval": "12h"
    })
    assert start == datetime(2020, 12, 17, 12, tzinfo=pytz.utc)
    assert end == datetime(2020, 12, 18, 12, tzinfo=pytz.utc)
    assert interval == 12 * 60 * 60
Пример #3
0
def test_exclusive_end():
    start, end, interval = get_date_range(
        {
            "start": "2021-02-24T00:00:00",
            "end": "2021-02-25T00:00:00",
            "interval": "1h"
        }, )
    assert start == datetime(2021, 2, 24, tzinfo=pytz.utc)
    assert end == datetime(2021, 2, 25, 0, tzinfo=pytz.utc)
Пример #4
0
def test_round_exact():
    start, end, interval = get_date_range(
        {
            "start": "2021-01-12T04:06:16",
            "end": "2021-01-17T08:26:13",
            "interval": "1d"
        }, )
    assert start == datetime(2021, 1, 12, tzinfo=pytz.utc)
    assert end == datetime(2021, 1, 18, tzinfo=pytz.utc)
Пример #5
0
def test_interval_restrictions():
    # making sure intervals are cleanly divisible
    with pytest.raises(
            InvalidParams,
            match="The interval should divide one day without a remainder."):
        get_date_range({"statsPeriod": "6h", "interval": "59m"})

    with pytest.raises(
            InvalidParams,
            match="The interval should divide one day without a remainder."):
        get_date_range({"statsPeriod": "4d", "interval": "5h"})

    with pytest.raises(
            InvalidParams,
            match=
            "The interval has to be a multiple of the minimum interval of ten seconds.",
    ):
        get_date_range({"statsPeriod": "1h", "interval": "9s"})

    with pytest.raises(
            InvalidParams,
            match="Your interval and date range would create too many results."
    ):
        get_date_range({"statsPeriod": "90d", "interval": "10s"})
Пример #6
0
def test_invalid_interval():
    with pytest.raises(InvalidParams):
        start, end, interval = get_date_range({"interval": "0d"})