24
24
def fake_epidata_endpoint (func ):
25
25
"""This can be used as a decorator to enable a bogus Epidata endpoint to return 404 responses."""
26
26
def wrapper (* args ):
27
- Epidata .BASE_URL = 'http://delphi_web_epidata/epidata/fake_api.php '
27
+ Epidata .BASE_URL = 'http://delphi_web_epidata/fake_epidata '
28
28
func (* args )
29
- Epidata .BASE_URL = 'http://delphi_web_epidata/epidata/api.php '
29
+ Epidata .BASE_URL = 'http://delphi_web_epidata/epidata'
30
30
return wrapper
31
31
32
32
class DelphiEpidataPythonClientTests (CovidcastBase ):
@@ -39,7 +39,7 @@ def localSetUp(self):
39
39
self ._db ._cursor .execute ('update covidcast_meta_cache set timestamp = 0, epidata = "[]"' )
40
40
41
41
# use the local instance of the Epidata API
42
- Epidata .BASE_URL = 'http://delphi_web_epidata/epidata/api.php '
42
+ Epidata .BASE_URL = 'http://delphi_web_epidata/epidata'
43
43
Epidata .auth = ('epidata' , 'key' )
44
44
45
45
# use the local instance of the epidata database
@@ -65,8 +65,8 @@ def test_covidcast(self):
65
65
)
66
66
67
67
expected = [
68
- row_latest_issue .as_api_compatibility_row_dict (),
69
- rows [- 1 ].as_api_compatibility_row_dict ()
68
+ row_latest_issue .as_api_row_dict (),
69
+ rows [- 1 ].as_api_row_dict ()
70
70
]
71
71
72
72
self .assertEqual (response ['epidata' ], expected )
@@ -85,10 +85,10 @@ def test_covidcast(self):
85
85
86
86
expected = [{
87
87
rows [0 ].signal : [
88
- row_latest_issue .as_api_compatibility_row_dict (ignore_fields = ['signal' ]),
88
+ row_latest_issue .as_api_row_dict (ignore_fields = ['signal' ]),
89
89
],
90
90
rows [- 1 ].signal : [
91
- rows [- 1 ].as_api_compatibility_row_dict (ignore_fields = ['signal' ]),
91
+ rows [- 1 ].as_api_row_dict (ignore_fields = ['signal' ]),
92
92
],
93
93
}]
94
94
@@ -105,7 +105,7 @@ def test_covidcast(self):
105
105
** self .params_from_row (rows [0 ])
106
106
)
107
107
108
- expected = [row_latest_issue .as_api_compatibility_row_dict ()]
108
+ expected = [row_latest_issue .as_api_row_dict ()]
109
109
110
110
# check result
111
111
self .assertEqual (response_1 , {
@@ -120,7 +120,7 @@ def test_covidcast(self):
120
120
** self .params_from_row (rows [0 ], as_of = rows [1 ].issue )
121
121
)
122
122
123
- expected = [rows [1 ].as_api_compatibility_row_dict ()]
123
+ expected = [rows [1 ].as_api_row_dict ()]
124
124
125
125
# check result
126
126
self .maxDiff = None
@@ -145,8 +145,8 @@ def test_covidcast(self):
145
145
)
146
146
147
147
expected = [
148
- rows [0 ].as_api_compatibility_row_dict (),
149
- rows [1 ].as_api_compatibility_row_dict ()
148
+ rows [0 ].as_api_row_dict (),
149
+ rows [1 ].as_api_row_dict ()
150
150
]
151
151
152
152
# check result
@@ -162,7 +162,7 @@ def test_covidcast(self):
162
162
** self .params_from_row (rows [0 ], lag = 2 )
163
163
)
164
164
165
- expected = [row_latest_issue .as_api_compatibility_row_dict ()]
165
+ expected = [row_latest_issue .as_api_row_dict ()]
166
166
167
167
# check result
168
168
self .assertDictEqual (response_3 , {
@@ -178,7 +178,7 @@ def test_covidcast(self):
178
178
)
179
179
180
180
# check result
181
- self .assertEqual (response_1 , {'message' : 'no results' , 'result' : - 2 })
181
+ self .assertEqual (response_1 , {'epidata' : [], ' message' : 'no results' , 'result' : - 2 })
182
182
183
183
@patch ('requests.post' )
184
184
@patch ('requests.get' )
@@ -204,7 +204,7 @@ def test_retry_request(self, get):
204
204
mock_response = MagicMock ()
205
205
mock_response .status_code = 200
206
206
get .side_effect = [JSONDecodeError ('Expecting value' , "" , 0 ), mock_response ]
207
- response = Epidata ._request (None )
207
+ response = Epidata ._request ("" )
208
208
self .assertEqual (get .call_count , 2 )
209
209
self .assertEqual (response , mock_response .json ())
210
210
@@ -215,7 +215,7 @@ def test_retry_request(self, get):
215
215
get .side_effect = [JSONDecodeError ('Expecting value' , "" , 0 ),
216
216
JSONDecodeError ('Expecting value' , "" , 0 ),
217
217
mock_response ]
218
- response = Epidata ._request (None )
218
+ response = Epidata ._request ("" )
219
219
self .assertEqual (get .call_count , 2 ) # 2 from previous test + 2 from this one
220
220
self .assertEqual (response ,
221
221
{'result' : 0 , 'message' : 'error: Expecting value: line 1 column 1 (char 0)' }
@@ -236,7 +236,7 @@ def test_geo_value(self):
236
236
self ._insert_rows (rows )
237
237
238
238
counties = [
239
- rows [i ].as_api_compatibility_row_dict () for i in range (N )
239
+ rows [i ].as_api_row_dict () for i in range (N )
240
240
]
241
241
242
242
def fetch (geo ):
@@ -347,13 +347,15 @@ def test_async_epidata(self):
347
347
self .params_from_row (rows [0 ], source = 'covidcast' ),
348
348
self .params_from_row (rows [1 ], source = 'covidcast' )
349
349
]* 12 , batch_size = 10 )
350
- responses = [i [0 ] for i in test_output ]
351
- # check response is same as standard covidcast call, using 24 calls to test batch sizing
350
+ responses = [i [0 ]["epidata" ] for i in test_output ]
351
+ # check response is same as standard covidcast call (minus fields omitted by the api.php endpoint),
352
+ # using 24 calls to test batch sizing
353
+ ignore_fields = CovidcastTestRow ._api_row_compatibility_ignore_fields
352
354
self .assertEqual (
353
355
responses ,
354
356
[
355
- Epidata .covidcast (** self .params_from_row (rows [0 ])),
356
- Epidata .covidcast (** self .params_from_row (rows [1 ])),
357
+ [{ k : row [ k ] for k in row . keys () - ignore_fields } for row in Epidata .covidcast (** self .params_from_row (rows [0 ]))[ "epidata" ]] ,
358
+ [{ k : row [ k ] for k in row . keys () - ignore_fields } for row in Epidata .covidcast (** self .params_from_row (rows [1 ]))[ "epidata" ]] ,
357
359
]* 12
358
360
)
359
361
0 commit comments