Skip to content

Commit 4e64d16

Browse files
authored
Merge pull request #1091 from cmu-delphi/Issue67
Use epidata client in covidcast integration tests + fix csv format bug + fix fields param bug
2 parents 4b26579 + f241cd3 commit 4e64d16

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

integrations/server/test_covidcast.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# first party
1212
from delphi_utils import Nans
1313
from delphi.epidata.acquisition.covidcast.test_utils import CovidcastBase, CovidcastTestRow
14+
from delphi.epidata.client.delphi_epidata import Epidata
1415

1516
# use the local instance of the Epidata API
1617
BASE_URL = 'http://delphi_web_epidata/epidata/api.php'
@@ -22,11 +23,10 @@ def localSetUp(self):
2223
"""Perform per-test setup."""
2324
self._db._cursor.execute('update covidcast_meta_cache set timestamp = 0, epidata = "[]"')
2425

25-
def request_based_on_row(self, row: CovidcastTestRow, extract_response: Callable = lambda x: x.json(), **kwargs):
26+
def request_based_on_row(self, row: CovidcastTestRow, **kwargs):
2627
params = self.params_from_row(row, endpoint='covidcast', **kwargs)
27-
response = requests.get(BASE_URL, params=params)
28-
response.raise_for_status()
29-
response = extract_response(response)
28+
Epidata.BASE_URL = BASE_URL
29+
response = Epidata.covidcast(**params)
3030

3131
return response
3232

@@ -155,7 +155,6 @@ def test_csv_format(self):
155155
# NB 'format' is a Python reserved word
156156
response = self.request_based_on_row(
157157
row,
158-
extract_response=lambda resp: resp.text,
159158
**{'format':'csv'}
160159
)
161160

@@ -194,7 +193,7 @@ def test_fields(self):
194193
row = self._insert_placeholder_set_one()
195194

196195
# limit fields
197-
response = self.request_based_on_row(row, fields='time_value,geo_value')
196+
response = self.request_based_on_row(row, **{"fields":"time_value,geo_value"})
198197

199198
expected = row.as_api_compatibility_row_dict()
200199
expected_all = {

src/client/delphi_epidata.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ def _request(params):
7272
long and returns a 414.
7373
"""
7474
try:
75-
return Epidata._request_with_retry(params).json()
75+
result = Epidata._request_with_retry(params)
76+
if params is not None and "format" in params and params["format"]=="csv":
77+
return result.text
78+
else:
79+
return result.json()
7680
except Exception as e:
7781
return {'result': 0, 'message': 'error: ' + str(e)}
7882

@@ -606,6 +610,9 @@ def covidcast(
606610
if 'format' in kwargs:
607611
params['format'] = kwargs['format']
608612

613+
if 'fields' in kwargs:
614+
params['fields'] = kwargs['fields']
615+
609616
# Make the API call
610617
return Epidata._request(params)
611618

0 commit comments

Comments
 (0)