Skip to content

Commit bf54210

Browse files
committed
Server: update test_utils to use CovidcastRow
1 parent 79259c2 commit bf54210

File tree

1 file changed

+10
-34
lines changed

1 file changed

+10
-34
lines changed
Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
from typing import Sequence
12
import unittest
23

34
from delphi_utils import Nans
4-
from delphi.epidata.acquisition.covidcast.database import Database, CovidcastRow
5+
from delphi.epidata.acquisition.covidcast.covidcast_row import CovidcastRow
6+
from delphi.epidata.acquisition.covidcast.database import Database
57
import delphi.operations.secrets as secrets
68

79
# all the Nans we use here are just one value, so this is a shortcut to it:
@@ -31,36 +33,20 @@ def tearDown(self):
3133
# close and destroy conenction to the database
3234
self._db.disconnect(False)
3335
del self._db
36+
self.localTearDown()
3437

35-
DEFAULT_TIME_VALUE=2000_01_01
36-
DEFAULT_ISSUE=2000_01_01
37-
def _make_placeholder_row(self, **kwargs):
38-
settings = {
39-
'source': 'src',
40-
'signal': 'sig',
41-
'geo_type': 'state',
42-
'geo_value': 'pa',
43-
'time_type': 'day',
44-
'time_value': self.DEFAULT_TIME_VALUE,
45-
'value': 0.0,
46-
'stderr': 1.0,
47-
'sample_size': 2.0,
48-
'missing_value': nmv,
49-
'missing_stderr': nmv,
50-
'missing_sample_size': nmv,
51-
'issue': self.DEFAULT_ISSUE,
52-
'lag': 0
53-
}
54-
settings.update(kwargs)
55-
return (CovidcastRow(**settings), settings)
38+
def localTearDown(self):
39+
# stub; override in subclasses to perform custom teardown.
40+
# runs after database changes have been committed
41+
pass
5642

57-
def _insert_rows(self, rows):
43+
def _insert_rows(self, rows: Sequence[CovidcastRow]):
5844
# inserts rows into the database using the full acquisition process, including 'dbjobs' load into history & latest tables
5945
n = self._db.insert_or_update_bulk(rows)
6046
print(f"{n} rows added to load table & dispatched to v4 schema")
6147
self._db._connection.commit() # NOTE: this isnt expressly needed for our test cases, but would be if using external access (like through client lib) to ensure changes are visible outside of this db session
6248

63-
def params_from_row(self, row, **kwargs):
49+
def params_from_row(self, row: CovidcastRow, **kwargs):
6450
ret = {
6551
'data_source': row.source,
6652
'signals': row.signal,
@@ -71,13 +57,3 @@ def params_from_row(self, row, **kwargs):
7157
}
7258
ret.update(kwargs)
7359
return ret
74-
75-
DEFAULT_MINUS=['time_type', 'geo_type', 'source']
76-
def expected_from_row(self, row, minus=DEFAULT_MINUS):
77-
expected = dict(vars(row))
78-
# remove columns commonly excluded from output
79-
# nb may need to add source or *_type back in for multiplexed queries
80-
for key in ['id', 'direction_updated_timestamp'] + minus:
81-
del expected[key]
82-
return expected
83-

0 commit comments

Comments
 (0)