Skip to content

Commit b3cba4c

Browse files
dshemetovkrivardmelange396
committed
CovidcastRow: address code review #1044
Co-authored-by: Katie Mazaitis <[email protected]> Co-authored-by: melange396 <[email protected]>
1 parent 4178862 commit b3cba4c

File tree

13 files changed

+374
-372
lines changed

13 files changed

+374
-372
lines changed

integrations/acquisition/covidcast/test_db.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from delphi_utils import Nans
22

33
from delphi.epidata.acquisition.covidcast.database import DBLoadStateException
4-
from delphi.epidata.acquisition.covidcast.covidcast_row import CovidcastRow
5-
from delphi.epidata.acquisition.covidcast.test_utils import CovidcastBase
4+
from delphi.epidata.acquisition.covidcast.test_utils import CovidcastBase, CovidcastTestRow
65

76

87
# all the Nans we use here are just one value, so this is a shortcut to it:
@@ -11,7 +10,7 @@
1110
class TestTest(CovidcastBase):
1211

1312
def _find_matches_for_row(self, row):
14-
# finds (if existing) row from both history and latest views that matches long-key of provided CovidcastRow
13+
# finds (if existing) row from both history and latest views that matches long-key of provided CovidcastTestRow
1514
cols = "source signal time_type time_value geo_type geo_value issue".split()
1615
results = {}
1716
cur = self._db._cursor
@@ -31,8 +30,8 @@ def _find_matches_for_row(self, row):
3130

3231
def test_insert_or_update_with_nonempty_load_table(self):
3332
# make rows
34-
a_row = CovidcastRow.make_default_row(time_value=20200202)
35-
another_row = CovidcastRow.make_default_row(time_value=20200203, issue=20200203)
33+
a_row = CovidcastTestRow.make_default_row(time_value=2020_02_02)
34+
another_row = CovidcastTestRow.make_default_row(time_value=2020_02_03, issue=2020_02_03)
3635
# insert one
3736
self._db.insert_or_update_bulk([a_row])
3837
# put something into the load table
@@ -61,7 +60,7 @@ def test_id_sync(self):
6160
latest_view = 'epimetric_latest_v'
6261

6362
# add a data point
64-
base_row = CovidcastRow.make_default_row()
63+
base_row = CovidcastTestRow.make_default_row()
6564
self._insert_rows([base_row])
6665
# ensure the primary keys match in the latest and history tables
6766
matches = self._find_matches_for_row(base_row)
@@ -71,7 +70,7 @@ def test_id_sync(self):
7170
old_pk_id = matches[latest_view][pk_column]
7271

7372
# add a reissue for said data point
74-
next_row = CovidcastRow.make_default_row()
73+
next_row = CovidcastTestRow.make_default_row()
7574
next_row.issue += 1
7675
self._insert_rows([next_row])
7776
# ensure the new keys also match

integrations/acquisition/covidcast/test_delete_batch.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# first party
99
import delphi.operations.secrets as secrets
1010
from delphi.epidata.acquisition.covidcast.database import Database
11-
from delphi.epidata.acquisition.covidcast.covidcast_row import CovidcastRow, covidcast_rows_from_args
11+
from delphi.epidata.acquisition.covidcast.test_utils import covidcast_rows_from_args
1212

1313
# py3tester coverage target (equivalent to `import *`)
1414
__test_target__ = 'delphi.epidata.acquisition.covidcast.database'
@@ -57,6 +57,7 @@ def _test_delete_batch(self, cc_deletions):
5757
time_value = [0] * 5 + [1] * 5 + [0],
5858
geo_value = ["d_nonlatest"] * 2 + ["d_latest"] * 3 + ["d_nonlatest"] * 2 + ["d_latest"] * 3 + ["d_justone"],
5959
issue = [1, 2] + [1, 2, 3] + [1, 2] + [1, 2, 3] + [1],
60+
sanitize_fields = True
6061
)
6162

6263
self._db.insert_or_update_bulk(rows)

integrations/client/test_delphi_epidata.py

+22-21
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
# third party
1313
import delphi.operations.secrets as secrets
1414
from delphi.epidata.acquisition.covidcast.covidcast_meta_cache_updater import main as update_covidcast_meta_cache
15-
from delphi.epidata.acquisition.covidcast.covidcast_row import CovidcastRow
16-
from delphi.epidata.acquisition.covidcast.test_utils import CovidcastBase
15+
from delphi.epidata.acquisition.covidcast.test_utils import CovidcastBase, CovidcastTestRow
1716
from delphi.epidata.client.delphi_epidata import Epidata
1817
from delphi_utils import Nans
1918

@@ -52,13 +51,11 @@ def test_covidcast(self):
5251

5352
# insert placeholder data: three issues of one signal, one issue of another
5453
rows = [
55-
CovidcastRow.make_default_row(issue=2020_02_02 + i, value=i, lag=i)
54+
CovidcastTestRow.make_default_row(issue=2020_02_02 + i, value=i, lag=i)
5655
for i in range(3)
5756
]
5857
row_latest_issue = rows[-1]
59-
rows.append(
60-
CovidcastRow.make_default_row(signal="sig2")
61-
)
58+
rows.append(CovidcastTestRow.make_default_row(signal="sig2"))
6259
self._insert_rows(rows)
6360

6461
with self.subTest(name='request two signals'):
@@ -68,8 +65,8 @@ def test_covidcast(self):
6865
)
6966

7067
expected = [
71-
row_latest_issue.as_dict(ignore_fields=CovidcastRow._api_row_compatibility_ignore_fields),
72-
rows[-1].as_dict(ignore_fields=CovidcastRow._api_row_compatibility_ignore_fields)
68+
row_latest_issue.as_api_compatibility_row_dict(),
69+
rows[-1].as_api_compatibility_row_dict()
7370
]
7471

7572
self.assertEqual(response['epidata'], expected)
@@ -88,10 +85,10 @@ def test_covidcast(self):
8885

8986
expected = [{
9087
rows[0].signal: [
91-
row_latest_issue.as_dict(ignore_fields=CovidcastRow._api_row_compatibility_ignore_fields + ['signal']),
88+
row_latest_issue.as_api_compatibility_row_dict(ignore_fields=['signal']),
9289
],
9390
rows[-1].signal: [
94-
rows[-1].as_dict(ignore_fields=CovidcastRow._api_row_compatibility_ignore_fields + ['signal']),
91+
rows[-1].as_api_compatibility_row_dict(ignore_fields=['signal']),
9592
],
9693
}]
9794

@@ -108,7 +105,7 @@ def test_covidcast(self):
108105
**self.params_from_row(rows[0])
109106
)
110107

111-
expected = [row_latest_issue.as_dict(ignore_fields=CovidcastRow._api_row_compatibility_ignore_fields)]
108+
expected = [row_latest_issue.as_api_compatibility_row_dict()]
112109

113110
# check result
114111
self.assertEqual(response_1, {
@@ -123,7 +120,7 @@ def test_covidcast(self):
123120
**self.params_from_row(rows[0], as_of=rows[1].issue)
124121
)
125122

126-
expected = [rows[1].as_dict(ignore_fields=CovidcastRow._api_row_compatibility_ignore_fields)]
123+
expected = [rows[1].as_api_compatibility_row_dict()]
127124

128125
# check result
129126
self.maxDiff=None
@@ -140,8 +137,8 @@ def test_covidcast(self):
140137
)
141138

142139
expected = [
143-
rows[0].as_dict(ignore_fields=CovidcastRow._api_row_compatibility_ignore_fields),
144-
rows[1].as_dict(ignore_fields=CovidcastRow._api_row_compatibility_ignore_fields)
140+
rows[0].as_api_compatibility_row_dict(),
141+
rows[1].as_api_compatibility_row_dict()
145142
]
146143

147144
# check result
@@ -157,7 +154,7 @@ def test_covidcast(self):
157154
**self.params_from_row(rows[0], lag=2)
158155
)
159156

160-
expected = [row_latest_issue.as_dict(ignore_fields=CovidcastRow._api_row_compatibility_ignore_fields)]
157+
expected = [row_latest_issue.as_api_compatibility_row_dict()]
161158

162159
# check result
163160
self.assertDictEqual(response_3, {
@@ -222,16 +219,16 @@ def test_geo_value(self):
222219
# insert placeholder data: three counties, three MSAs
223220
N = 3
224221
rows = [
225-
CovidcastRow.make_default_row(geo_type="county", geo_value=str(i)*5, value=i)
222+
CovidcastTestRow.make_default_row(geo_type="county", geo_value=str(i)*5, value=i)
226223
for i in range(N)
227224
] + [
228-
CovidcastRow.make_default_row(geo_type="msa", geo_value=str(i)*5, value=i*10)
225+
CovidcastTestRow.make_default_row(geo_type="msa", geo_value=str(i)*5, value=i*10)
229226
for i in range(N)
230227
]
231228
self._insert_rows(rows)
232229

233230
counties = [
234-
rows[i].as_dict(ignore_fields=CovidcastRow._api_row_compatibility_ignore_fields) for i in range(N)
231+
rows[i].as_api_compatibility_row_dict() for i in range(N)
235232
]
236233

237234
def fetch(geo):
@@ -277,7 +274,11 @@ def test_covidcast_meta(self):
277274
# 2nd issue: 1 11 21
278275
# 3rd issue: 2 12 22
279276
rows = [
280-
CovidcastRow.make_default_row(time_value=DEFAULT_TIME_VALUE + t, issue=DEFAULT_ISSUE + i, value=t*10 + i)
277+
CovidcastTestRow.make_default_row(
278+
time_value=DEFAULT_TIME_VALUE + t,
279+
issue=DEFAULT_ISSUE + i,
280+
value=t*10 + i
281+
)
281282
for i in range(3) for t in range(3)
282283
]
283284
self._insert_rows(rows)
@@ -324,10 +325,10 @@ def test_async_epidata(self):
324325
# insert placeholder data: three counties, three MSAs
325326
N = 3
326327
rows = [
327-
CovidcastRow.make_default_row(geo_type="county", geo_value=str(i)*5, value=i)
328+
CovidcastTestRow.make_default_row(geo_type="county", geo_value=str(i)*5, value=i)
328329
for i in range(N)
329330
] + [
330-
CovidcastRow.make_default_row(geo_type="msa", geo_value=str(i)*5, value=i*10)
331+
CovidcastTestRow.make_default_row(geo_type="msa", geo_value=str(i)*5, value=i*10)
331332
for i in range(N)
332333
]
333334
self._insert_rows(rows)

0 commit comments

Comments
 (0)