9
9
# first party
10
10
from delphi .epidata .client .delphi_epidata import Epidata
11
11
from delphi .epidata .acquisition .covidcast .covidcast_meta_cache_updater import main as update_covidcast_meta_cache
12
+ import delphi .operations .secrets as secrets
12
13
13
14
# py3tester coverage target
14
15
__test_target__ = 'delphi.epidata.client.delphi_epidata'
@@ -38,69 +39,41 @@ def setUp(self):
38
39
# use the local instance of the Epidata API
39
40
Epidata .BASE_URL = 'http://delphi_web_epidata/epidata/api.php'
40
41
42
+ # use the local instance of the epidata database
43
+ secrets .db .host = 'delphi_database_epidata'
44
+ secrets .db .epi = ('user' , 'pass' )
45
+
41
46
def tearDown (self ):
42
47
"""Perform per-test teardown."""
43
48
self .cur .close ()
44
49
self .cnx .close ()
45
50
46
51
def test_covidcast (self ):
47
52
"""Test that the covidcast endpoint returns expected data."""
48
- self .maxDiff = None
49
53
50
54
# insert dummy data
51
55
self .cur .execute ('''
52
56
insert into covidcast values
53
57
(0, 'src', 'sig', 'day', 'county', 20200414, '01234',
54
58
123, 1.5, 2.5, 3.5, 456, 4, 20200414, 0, 0, False),
55
59
(0, 'src', 'sig2', 'day', 'county', 20200414, '01234',
56
- 123, 1.5, 2.5, 3.5, 456, 4, 20200414, 0, 0 , False),
60
+ 123, 1.5, 2.5, 3.5, 456, 4, 20200414, 0, 1 , False),
57
61
(0, 'src', 'sig', 'day', 'county', 20200414, '01234',
58
62
456, 5.5, 1.2, 10.5, 789, 0, 20200415, 1, 0, False),
59
63
(0, 'src', 'sig', 'day', 'county', 20200414, '01234',
60
64
345, 6.5, 2.2, 11.5, 678, 0, 20200416, 2, 1, False)
61
65
''' )
62
66
self .cnx .commit ()
63
67
64
- # fetch data
65
- response = Epidata .covidcast (
66
- 'src' , ['sig' ,'sig2' ], 'day' , 'county' , 20200414 , '01234' )
67
-
68
- # check result
69
- self .assertEqual (response , {
70
- 'result' : 1 ,
71
- 'epidata' : [{
72
- 'time_value' : 20200414 ,
73
- 'geo_value' : '01234' ,
74
- 'value' : 6.5 ,
75
- 'stderr' : 2.2 ,
76
- 'sample_size' : 11.5 ,
77
- 'direction' : 0 ,
78
- 'issue' : 20200416 ,
79
- 'lag' : 2 ,
80
- 'signal' : 'sig' ,
81
- },{
82
- 'time_value' : 20200414 ,
83
- 'geo_value' : '01234' ,
84
- 'value' : 1.5 ,
85
- 'stderr' : 2.5 ,
86
- 'sample_size' : 3.5 ,
87
- 'direction' : 4 ,
88
- 'issue' : 20200414 ,
89
- 'lag' : 0 ,
90
- 'signal' : 'sig2' ,
91
- }],
92
- 'message' : 'success' ,
93
- })
94
-
95
- # fetch data
96
- response = Epidata .covidcast (
97
- 'src' , ['sig' ,'sig2' ], 'day' , 'county' , 20200414 , '01234' , format = 'tree' )
68
+ with self .subTest (name = 'request two signals' ):
69
+ # fetch data
70
+ response = Epidata .covidcast (
71
+ 'src' , ['sig' , 'sig2' ], 'day' , 'county' , 20200414 , '01234' )
98
72
99
- # check result
100
- self .assertEqual (response , {
101
- 'result' : 1 ,
102
- 'epidata' : [{
103
- 'sig' : [{
73
+ # check result
74
+ self .assertEqual (response , {
75
+ 'result' : 1 ,
76
+ 'epidata' : [{
104
77
'time_value' : 20200414 ,
105
78
'geo_value' : '01234' ,
106
79
'value' : 6.5 ,
@@ -109,8 +82,8 @@ def test_covidcast(self):
109
82
'direction' : 0 ,
110
83
'issue' : 20200416 ,
111
84
'lag' : 2 ,
112
- }] ,
113
- 'sig2' : [ {
85
+ 'signal' : 'sig' ,
86
+ }, {
114
87
'time_value' : 20200414 ,
115
88
'geo_value' : '01234' ,
116
89
'value' : 1.5 ,
@@ -119,63 +92,100 @@ def test_covidcast(self):
119
92
'direction' : 4 ,
120
93
'issue' : 20200414 ,
121
94
'lag' : 0 ,
95
+ 'signal' : 'sig2' ,
122
96
}],
123
- }],
124
- 'message' : 'success' ,
125
- })
97
+ 'message' : 'success' ,
98
+ })
126
99
127
- # fetch data, without specifying issue or lag
128
- response_1 = Epidata .covidcast (
129
- 'src' , 'sig' , 'day' , 'county' , 20200414 , '01234' )
100
+ with self .subTest (name = 'request two signals with tree format' ):
101
+ # fetch data
102
+ response = Epidata .covidcast (
103
+ 'src' , ['sig' , 'sig2' ], 'day' , 'county' , 20200414 , '01234' ,
104
+ format = 'tree' )
130
105
131
- # check result
132
- self .assertEqual (response_1 , {
133
- 'result' : 1 ,
134
- 'epidata' : [{
135
- 'time_value' : 20200414 ,
136
- 'geo_value' : '01234' ,
137
- 'value' : 6.5 ,
138
- 'stderr' : 2.2 ,
139
- 'sample_size' : 11.5 ,
140
- 'direction' : 0 ,
141
- 'issue' : 20200416 ,
142
- 'lag' : 2 ,
143
- 'signal' : 'sig' ,
144
- }],
145
- 'message' : 'success' ,
146
- })
106
+ # check result
107
+ self .assertEqual (response , {
108
+ 'result' : 1 ,
109
+ 'epidata' : [{
110
+ 'sig' : [{
111
+ 'time_value' : 20200414 ,
112
+ 'geo_value' : '01234' ,
113
+ 'value' : 6.5 ,
114
+ 'stderr' : 2.2 ,
115
+ 'sample_size' : 11.5 ,
116
+ 'direction' : 0 ,
117
+ 'issue' : 20200416 ,
118
+ 'lag' : 2 ,
119
+ }],
120
+ 'sig2' : [{
121
+ 'time_value' : 20200414 ,
122
+ 'geo_value' : '01234' ,
123
+ 'value' : 1.5 ,
124
+ 'stderr' : 2.5 ,
125
+ 'sample_size' : 3.5 ,
126
+ 'direction' : 4 ,
127
+ 'issue' : 20200414 ,
128
+ 'lag' : 0 ,
129
+ }],
130
+ }],
131
+ 'message' : 'success' ,
132
+ })
147
133
148
- # fetch data, specifying as_of
149
- response_1a = Epidata . covidcast (
150
- 'src' , 'sig' , 'day' , 'county' , 20200414 , '01234' ,
151
- as_of = 20200415 )
134
+ with self . subTest ( name = 'request most recent' ):
135
+ # fetch data, without specifying issue or lag
136
+ response_1 = Epidata . covidcast (
137
+ 'src' , 'sig' , 'day' , 'county' , 20200414 , '01234' )
152
138
153
- # check result
154
- self .assertEqual (response_1a , {
155
- 'result' : 1 ,
156
- 'epidata' : [{
157
- 'time_value' : 20200414 ,
158
- 'geo_value' : '01234' ,
159
- 'value' : 5 .5 ,
160
- 'stderr' : 1 .2 ,
161
- 'sample_size' : 10 .5 ,
162
- 'direction' : 0 ,
163
- 'issue' : 20200415 ,
164
- 'lag' : 1 ,
165
- 'signal' : 'sig' ,
166
- }],
167
- 'message' : 'success' ,
168
- })
139
+ # check result
140
+ self .assertEqual (response_1 , {
141
+ 'result' : 1 ,
142
+ 'epidata' : [{
143
+ 'time_value' : 20200414 ,
144
+ 'geo_value' : '01234' ,
145
+ 'value' : 6 .5 ,
146
+ 'stderr' : 2 .2 ,
147
+ 'sample_size' : 11 .5 ,
148
+ 'direction' : 0 ,
149
+ 'issue' : 20200416 ,
150
+ 'lag' : 2 ,
151
+ 'signal' : 'sig' ,
152
+ }],
153
+ 'message' : 'success' ,
154
+ })
169
155
170
- # fetch data, specifying issue range, not lag
171
- response_2 = Epidata .covidcast (
172
- 'src' , 'sig' , 'day' , 'county' , 20200414 , '01234' ,
173
- issues = Epidata .range (20200414 , 20200415 ))
156
+ with self .subTest (name = 'request as-of a date' ):
157
+ # fetch data, specifying as_of
158
+ response_1a = Epidata .covidcast (
159
+ 'src' , 'sig' , 'day' , 'county' , 20200414 , '01234' ,
160
+ as_of = 20200415 )
174
161
175
- # check result
176
- self .assertDictEqual ( response_2 , {
162
+ # check result
163
+ self .assertEqual ( response_1a , {
177
164
'result' : 1 ,
178
165
'epidata' : [{
166
+ 'time_value' : 20200414 ,
167
+ 'geo_value' : '01234' ,
168
+ 'value' : 5.5 ,
169
+ 'stderr' : 1.2 ,
170
+ 'sample_size' : 10.5 ,
171
+ 'direction' : 0 ,
172
+ 'issue' : 20200415 ,
173
+ 'lag' : 1 ,
174
+ 'signal' : 'sig' ,
175
+ }],
176
+ 'message' : 'success' ,
177
+ })
178
+
179
+ with self .subTest (name = 'request a range of issues' ):
180
+ # fetch data, specifying issue range, not lag
181
+ response_2 = Epidata .covidcast (
182
+ 'src' , 'sig' , 'day' , 'county' , 20200414 , '01234' ,
183
+ issues = Epidata .range (20200414 , 20200415 ))
184
+
185
+ # check result
186
+ self .assertDictEqual (response_2 , {
187
+ 'result' : 1 ,
188
+ 'epidata' : [{
179
189
'time_value' : 20200414 ,
180
190
'geo_value' : '01234' ,
181
191
'value' : 1.5 ,
@@ -185,7 +195,7 @@ def test_covidcast(self):
185
195
'issue' : 20200414 ,
186
196
'lag' : 0 ,
187
197
'signal' : 'sig' ,
188
- }, {
198
+ }, {
189
199
'time_value' : 20200414 ,
190
200
'geo_value' : '01234' ,
191
201
'value' : 5.5 ,
@@ -195,19 +205,20 @@ def test_covidcast(self):
195
205
'issue' : 20200415 ,
196
206
'lag' : 1 ,
197
207
'signal' : 'sig' ,
198
- }],
199
- 'message' : 'success' ,
200
- })
201
-
202
- # fetch data, specifying lag, not issue range
203
- response_3 = Epidata .covidcast (
204
- 'src' , 'sig' , 'day' , 'county' , 20200414 , '01234' ,
205
- lag = 2 )
206
-
207
- # check result
208
- self .assertDictEqual (response_3 , {
209
- 'result' : 1 ,
210
- 'epidata' : [{
208
+ }],
209
+ 'message' : 'success' ,
210
+ })
211
+
212
+ with self .subTest (name = 'request at a given lag' ):
213
+ # fetch data, specifying lag, not issue range
214
+ response_3 = Epidata .covidcast (
215
+ 'src' , 'sig' , 'day' , 'county' , 20200414 , '01234' ,
216
+ lag = 2 )
217
+
218
+ # check result
219
+ self .assertDictEqual (response_3 , {
220
+ 'result' : 1 ,
221
+ 'epidata' : [{
211
222
'time_value' : 20200414 ,
212
223
'geo_value' : '01234' ,
213
224
'value' : 6.5 ,
@@ -217,9 +228,9 @@ def test_covidcast(self):
217
228
'issue' : 20200416 ,
218
229
'lag' : 2 ,
219
230
'signal' : 'sig' ,
220
- }],
221
- 'message' : 'success' ,
222
- })
231
+ }],
232
+ 'message' : 'success' ,
233
+ })
223
234
224
235
def test_geo_value (self ):
225
236
"""test different variants of geo types: single, *, multi."""
0 commit comments