-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
52 lines (40 loc) · 1.62 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from datetime import date, datetime, timedelta, timezone
import pytest
from .models import GenerateDateSeries, GenerateDateTimeSeries, GenerateIntegerSeries
pytestmark = pytest.mark.django_db
def test_integer_series():
"""
Test basic integer series
"""
int_series = GenerateIntegerSeries.objects.all(start=2, stop=10, interval=2)
assert len(int_series) == 5
assert [obj.series for obj in int_series] == [2, 4, 6, 8, 10]
def test_date_series():
"""
Test basic date series generation
"""
date_series = GenerateDateSeries.objects.all(
start=date(2020, 1, 1),
stop=date(2020, 1, 31),
interval=timedelta(days=1),
)
assert len(date_series) == 31
assert date_series[0].date == date(2020, 1, 1)
assert date_series[1].date == date(2020, 1, 2)
assert date_series[29].date == date(2020, 1, 30)
assert date_series[30].date == date(2020, 1, 31)
def test_datetime_series():
"""
Test datetime series generation complete with timezone
"""
utc = timezone.utc
datetime_series = GenerateDateTimeSeries.objects.all(
start=datetime(2020, 1, 1, 9, 0, 0, tzinfo=utc),
stop=datetime(2020, 1, 1, 16, 0, 0, tzinfo=utc),
interval=timedelta(hours=1),
)
assert len(datetime_series) == 8
assert datetime_series[0].timestamptz == datetime(2020, 1, 1, 9, 0, 0, tzinfo=utc)
assert datetime_series[1].timestamptz == datetime(2020, 1, 1, 10, 0, 0, tzinfo=utc)
assert datetime_series[6].timestamptz == datetime(2020, 1, 1, 15, 0, 0, tzinfo=utc)
assert datetime_series[7].timestamptz == datetime(2020, 1, 1, 16, 0, 0, tzinfo=utc)