@@ -46,7 +46,7 @@ def tearDown(self):
46
46
def test_covidcast (self ):
47
47
"""Test that the covidcast endpoint returns expected data."""
48
48
self .maxDiff = None
49
-
49
+
50
50
# insert dummy data
51
51
self .cur .execute ('''
52
52
insert into covidcast values
@@ -123,7 +123,7 @@ def test_covidcast(self):
123
123
}],
124
124
'message' : 'success' ,
125
125
})
126
-
126
+
127
127
# fetch data, without specifying issue or lag
128
128
response_1 = Epidata .covidcast (
129
129
'src' , 'sig' , 'day' , 'county' , 20200414 , '01234' )
@@ -221,6 +221,92 @@ def test_covidcast(self):
221
221
'message' : 'success' ,
222
222
})
223
223
224
+ def test_geo_value (self ):
225
+ """test different variants of geo types: single, *, multi."""
226
+
227
+ # insert dummy data
228
+ self .cur .execute ('''
229
+ insert into covidcast values
230
+ (0, 'src', 'sig', 'day', 'county', 20200414, '11111',
231
+ 123, 10, 11, 12, 456, 13, 20200414, 0, 1, False),
232
+ (0, 'src', 'sig', 'day', 'county', 20200414, '22222',
233
+ 123, 20, 21, 22, 456, 23, 20200414, 0, 1, False),
234
+ (0, 'src', 'sig', 'day', 'county', 20200414, '33333',
235
+ 123, 30, 31, 32, 456, 33, 20200414, 0, 1, False),
236
+ (0, 'src', 'sig', 'day', 'msa', 20200414, '11111',
237
+ 123, 40, 41, 42, 456, 43, 20200414, 0, 1, False),
238
+ (0, 'src', 'sig', 'day', 'msa', 20200414, '22222',
239
+ 123, 50, 51, 52, 456, 53, 20200414, 0, 1, False),
240
+ (0, 'src', 'sig', 'day', 'msa', 20200414, '33333',
241
+ 123, 60, 61, 62, 456, 634, 20200414, 0, 1, False)
242
+ ''' )
243
+ self .cnx .commit ()
244
+
245
+ def fetch (geo_value ):
246
+ # make the request
247
+ response = Epidata .covidcast (
248
+ 'src' , 'sig' , 'day' , 'county' , 20200414 , geo_value )
249
+ return response
250
+
251
+ counties = [{
252
+ 'time_value' : 20200414 ,
253
+ 'geo_value' : '11111' ,
254
+ 'value' : 10 ,
255
+ 'stderr' : 11 ,
256
+ 'sample_size' : 12 ,
257
+ 'direction' : 13 ,
258
+ 'issue' : 20200414 ,
259
+ 'lag' : 0 ,
260
+ 'signal' : 'sig' ,
261
+ }, {
262
+ 'time_value' : 20200414 ,
263
+ 'geo_value' : '22222' ,
264
+ 'value' : 20 ,
265
+ 'stderr' : 21 ,
266
+ 'sample_size' : 22 ,
267
+ 'direction' : 23 ,
268
+ 'issue' : 20200414 ,
269
+ 'lag' : 0 ,
270
+ 'signal' : 'sig' ,
271
+ }, {
272
+ 'time_value' : 20200414 ,
273
+ 'geo_value' : '33333' ,
274
+ 'value' : 30 ,
275
+ 'stderr' : 31 ,
276
+ 'sample_size' : 32 ,
277
+ 'direction' : 33 ,
278
+ 'issue' : 20200414 ,
279
+ 'lag' : 0 ,
280
+ 'signal' : 'sig' ,
281
+ }]
282
+
283
+ # test fetch all
284
+ r = fetch ('*' )
285
+ self .assertEqual (r ['message' ], 'success' )
286
+ self .assertEqual (r ['epidata' ], counties )
287
+ # test fetch a specific region
288
+ r = fetch ('11111' )
289
+ self .assertEqual (r ['message' ], 'success' )
290
+ self .assertEqual (r ['epidata' ], [counties [0 ]])
291
+ # test fetch a specific yet not existing region
292
+ r = fetch ('55555' )
293
+ self .assertEqual (r ['message' ], 'no results' )
294
+ # test fetch a multiple regions
295
+ r = fetch (['11111' , '22222' ])
296
+ self .assertEqual (r ['message' ], 'success' )
297
+ self .assertEqual (r ['epidata' ], [counties [0 ], counties [1 ]])
298
+ # test fetch a multiple regions in another variant
299
+ r = fetch (['11111' , '33333' ])
300
+ self .assertEqual (r ['message' ], 'success' )
301
+ self .assertEqual (r ['epidata' ], [counties [0 ], counties [2 ]])
302
+ # test fetch a multiple regions but one is not existing
303
+ r = fetch (['11111' , '55555' ])
304
+ self .assertEqual (r ['message' ], 'success' )
305
+ self .assertEqual (r ['epidata' ], [counties [0 ]])
306
+ # test fetch a multiple regions but specify no region
307
+ r = fetch ([])
308
+ self .assertEqual (r ['message' ], 'no results' )
309
+
224
310
def test_covidcast_meta (self ):
225
311
"""Test that the covidcast_meta endpoint returns expected data."""
226
312
0 commit comments