/
test_origin_breakdown.py
135 lines (109 loc) · 3.77 KB
/
test_origin_breakdown.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from datetime import datetime
from vortexasdk import OriginBreakdown
from tests.testcases import TestCaseUsingRealAPI
class TestOriginBreakdownReal(TestCaseUsingRealAPI):
def test_search_returns_one_day(self):
date = datetime(2019, 11, 10)
result = OriginBreakdown().search(
filter_activity="loading_state",
breakdown_geography="country",
breakdown_unit="b",
filter_time_min=date,
filter_time_max=date,
)
assert len(result["data"]) == 5
def test_search_returns_multiple_breakdowns(self):
start = datetime(2019, 11, 1)
end = datetime(2019, 11, 10)
result = OriginBreakdown().search(
filter_activity="loading_state",
breakdown_geography="country",
breakdown_unit="b",
filter_time_min=start,
filter_time_max=end,
breakdown_size=100
)
assert len(result["data"]) == 100
def test_search_returns_any_activity(self):
date = datetime(2019, 11, 10)
result = OriginBreakdown().search(
filter_activity="any_activity",
breakdown_geography="country",
breakdown_unit="b",
filter_time_min=date,
filter_time_max=date,
)
assert len(result["data"]) == 5
def test_search_returns_excluded_params(self):
date = datetime(2019, 11, 10)
rotterdam = "68faf65af1345067f11dc6723b8da32f00e304a6f33c000118fccd81947deb4e"
result = OriginBreakdown().search(
filter_activity="any_activity",
breakdown_geography="country",
breakdown_unit="b",
filter_time_min=date,
filter_time_max=date,
exclude_origins=rotterdam
)
assert len(result["data"]) == 5
def test_to_df(self):
date = datetime(2019, 11, 10)
df = (
OriginBreakdown()
.search(
filter_activity="any_activity",
breakdown_geography="country",
breakdown_unit="b",
filter_time_min=date,
filter_time_max=date
)
.to_df()
)
assert len(df) == 5
assert list(df.columns) == ["key", "label", "value", "count"]
def test_to_df_without_label(self):
date = datetime(2019, 11, 10)
df = (
OriginBreakdown()
.search(
filter_activity="any_activity",
breakdown_geography="country",
breakdown_unit="b",
filter_time_min=date,
filter_time_max=date,
)
.to_df(columns=["key", "value", "count"])
)
assert len(df) == 5
assert list(df.columns) == ["key", "value", "count"]
def test_to_list(self):
date = datetime(2019, 11, 10)
time_series_list = (
OriginBreakdown()
.search(
filter_activity="any_activity",
breakdown_geography="country",
breakdown_unit="b",
filter_time_min=date,
filter_time_max=date,
)
.to_list()
)
assert len(time_series_list) == 5
def test_with_params(self):
start = datetime(2019, 11, 10)
end = datetime(2019, 11, 15)
df = (
OriginBreakdown()
.search(
filter_activity="loading_end",
breakdown_geography="terminal",
breakdown_unit="t",
breakdown_size=5,
filter_time_min=start,
filter_time_max=end,
)
.to_df()
)
assert len(df) == 5
assert list(df.columns) == ["key", "label", "value", "count"]