Skip to content

Commit 3f1c7d2

Browse files
authored
Merge pull request #254 from dfarrow0/dfarrow_fix
fix failing integration test
2 parents 6826be8 + 6418f4d commit 3f1c7d2

File tree

1 file changed

+119
-108
lines changed

1 file changed

+119
-108
lines changed

integrations/client/test_delphi_epidata.py

Lines changed: 119 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# first party
1010
from delphi.epidata.client.delphi_epidata import Epidata
1111
from delphi.epidata.acquisition.covidcast.covidcast_meta_cache_updater import main as update_covidcast_meta_cache
12+
import delphi.operations.secrets as secrets
1213

1314
# py3tester coverage target
1415
__test_target__ = 'delphi.epidata.client.delphi_epidata'
@@ -38,69 +39,41 @@ def setUp(self):
3839
# use the local instance of the Epidata API
3940
Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/api.php'
4041

42+
# use the local instance of the epidata database
43+
secrets.db.host = 'delphi_database_epidata'
44+
secrets.db.epi = ('user', 'pass')
45+
4146
def tearDown(self):
4247
"""Perform per-test teardown."""
4348
self.cur.close()
4449
self.cnx.close()
4550

4651
def test_covidcast(self):
4752
"""Test that the covidcast endpoint returns expected data."""
48-
self.maxDiff=None
4953

5054
# insert dummy data
5155
self.cur.execute('''
5256
insert into covidcast values
5357
(0, 'src', 'sig', 'day', 'county', 20200414, '01234',
5458
123, 1.5, 2.5, 3.5, 456, 4, 20200414, 0, 0, False),
5559
(0, 'src', 'sig2', 'day', 'county', 20200414, '01234',
56-
123, 1.5, 2.5, 3.5, 456, 4, 20200414, 0, 0, False),
60+
123, 1.5, 2.5, 3.5, 456, 4, 20200414, 0, 1, False),
5761
(0, 'src', 'sig', 'day', 'county', 20200414, '01234',
5862
456, 5.5, 1.2, 10.5, 789, 0, 20200415, 1, 0, False),
5963
(0, 'src', 'sig', 'day', 'county', 20200414, '01234',
6064
345, 6.5, 2.2, 11.5, 678, 0, 20200416, 2, 1, False)
6165
''')
6266
self.cnx.commit()
6367

64-
# fetch data
65-
response = Epidata.covidcast(
66-
'src', ['sig','sig2'], 'day', 'county', 20200414, '01234')
67-
68-
# check result
69-
self.assertEqual(response, {
70-
'result': 1,
71-
'epidata': [{
72-
'time_value': 20200414,
73-
'geo_value': '01234',
74-
'value': 6.5,
75-
'stderr': 2.2,
76-
'sample_size': 11.5,
77-
'direction': 0,
78-
'issue': 20200416,
79-
'lag': 2,
80-
'signal': 'sig',
81-
},{
82-
'time_value': 20200414,
83-
'geo_value': '01234',
84-
'value': 1.5,
85-
'stderr': 2.5,
86-
'sample_size': 3.5,
87-
'direction': 4,
88-
'issue': 20200414,
89-
'lag': 0,
90-
'signal': 'sig2',
91-
}],
92-
'message': 'success',
93-
})
94-
95-
# fetch data
96-
response = Epidata.covidcast(
97-
'src', ['sig','sig2'], 'day', 'county', 20200414, '01234', format='tree')
68+
with self.subTest(name='request two signals'):
69+
# fetch data
70+
response = Epidata.covidcast(
71+
'src', ['sig', 'sig2'], 'day', 'county', 20200414, '01234')
9872

99-
# check result
100-
self.assertEqual(response, {
101-
'result': 1,
102-
'epidata': [{
103-
'sig': [{
73+
# check result
74+
self.assertEqual(response, {
75+
'result': 1,
76+
'epidata': [{
10477
'time_value': 20200414,
10578
'geo_value': '01234',
10679
'value': 6.5,
@@ -109,8 +82,8 @@ def test_covidcast(self):
10982
'direction': 0,
11083
'issue': 20200416,
11184
'lag': 2,
112-
}],
113-
'sig2': [{
85+
'signal': 'sig',
86+
}, {
11487
'time_value': 20200414,
11588
'geo_value': '01234',
11689
'value': 1.5,
@@ -119,63 +92,100 @@ def test_covidcast(self):
11992
'direction': 4,
12093
'issue': 20200414,
12194
'lag': 0,
95+
'signal': 'sig2',
12296
}],
123-
}],
124-
'message': 'success',
125-
})
97+
'message': 'success',
98+
})
12699

127-
# fetch data, without specifying issue or lag
128-
response_1 = Epidata.covidcast(
129-
'src', 'sig', 'day', 'county', 20200414, '01234')
100+
with self.subTest(name='request two signals with tree format'):
101+
# fetch data
102+
response = Epidata.covidcast(
103+
'src', ['sig', 'sig2'], 'day', 'county', 20200414, '01234',
104+
format='tree')
130105

131-
# check result
132-
self.assertEqual(response_1, {
133-
'result': 1,
134-
'epidata': [{
135-
'time_value': 20200414,
136-
'geo_value': '01234',
137-
'value': 6.5,
138-
'stderr': 2.2,
139-
'sample_size': 11.5,
140-
'direction': 0,
141-
'issue': 20200416,
142-
'lag': 2,
143-
'signal': 'sig',
144-
}],
145-
'message': 'success',
146-
})
106+
# check result
107+
self.assertEqual(response, {
108+
'result': 1,
109+
'epidata': [{
110+
'sig': [{
111+
'time_value': 20200414,
112+
'geo_value': '01234',
113+
'value': 6.5,
114+
'stderr': 2.2,
115+
'sample_size': 11.5,
116+
'direction': 0,
117+
'issue': 20200416,
118+
'lag': 2,
119+
}],
120+
'sig2': [{
121+
'time_value': 20200414,
122+
'geo_value': '01234',
123+
'value': 1.5,
124+
'stderr': 2.5,
125+
'sample_size': 3.5,
126+
'direction': 4,
127+
'issue': 20200414,
128+
'lag': 0,
129+
}],
130+
}],
131+
'message': 'success',
132+
})
147133

148-
# fetch data, specifying as_of
149-
response_1a = Epidata.covidcast(
150-
'src', 'sig', 'day', 'county', 20200414, '01234',
151-
as_of=20200415)
134+
with self.subTest(name='request most recent'):
135+
# fetch data, without specifying issue or lag
136+
response_1 = Epidata.covidcast(
137+
'src', 'sig', 'day', 'county', 20200414, '01234')
152138

153-
# check result
154-
self.assertEqual(response_1a, {
155-
'result': 1,
156-
'epidata': [{
157-
'time_value': 20200414,
158-
'geo_value': '01234',
159-
'value': 5.5,
160-
'stderr': 1.2,
161-
'sample_size': 10.5,
162-
'direction': 0,
163-
'issue': 20200415,
164-
'lag': 1,
165-
'signal': 'sig',
166-
}],
167-
'message': 'success',
168-
})
139+
# check result
140+
self.assertEqual(response_1, {
141+
'result': 1,
142+
'epidata': [{
143+
'time_value': 20200414,
144+
'geo_value': '01234',
145+
'value': 6.5,
146+
'stderr': 2.2,
147+
'sample_size': 11.5,
148+
'direction': 0,
149+
'issue': 20200416,
150+
'lag': 2,
151+
'signal': 'sig',
152+
}],
153+
'message': 'success',
154+
})
169155

170-
# fetch data, specifying issue range, not lag
171-
response_2 = Epidata.covidcast(
172-
'src', 'sig', 'day', 'county', 20200414, '01234',
173-
issues=Epidata.range(20200414, 20200415))
156+
with self.subTest(name='request as-of a date'):
157+
# fetch data, specifying as_of
158+
response_1a = Epidata.covidcast(
159+
'src', 'sig', 'day', 'county', 20200414, '01234',
160+
as_of=20200415)
174161

175-
# check result
176-
self.assertDictEqual(response_2, {
162+
# check result
163+
self.assertEqual(response_1a, {
177164
'result': 1,
178165
'epidata': [{
166+
'time_value': 20200414,
167+
'geo_value': '01234',
168+
'value': 5.5,
169+
'stderr': 1.2,
170+
'sample_size': 10.5,
171+
'direction': 0,
172+
'issue': 20200415,
173+
'lag': 1,
174+
'signal': 'sig',
175+
}],
176+
'message': 'success',
177+
})
178+
179+
with self.subTest(name='request a range of issues'):
180+
# fetch data, specifying issue range, not lag
181+
response_2 = Epidata.covidcast(
182+
'src', 'sig', 'day', 'county', 20200414, '01234',
183+
issues=Epidata.range(20200414, 20200415))
184+
185+
# check result
186+
self.assertDictEqual(response_2, {
187+
'result': 1,
188+
'epidata': [{
179189
'time_value': 20200414,
180190
'geo_value': '01234',
181191
'value': 1.5,
@@ -185,7 +195,7 @@ def test_covidcast(self):
185195
'issue': 20200414,
186196
'lag': 0,
187197
'signal': 'sig',
188-
}, {
198+
}, {
189199
'time_value': 20200414,
190200
'geo_value': '01234',
191201
'value': 5.5,
@@ -195,19 +205,20 @@ def test_covidcast(self):
195205
'issue': 20200415,
196206
'lag': 1,
197207
'signal': 'sig',
198-
}],
199-
'message': 'success',
200-
})
201-
202-
# fetch data, specifying lag, not issue range
203-
response_3 = Epidata.covidcast(
204-
'src', 'sig', 'day', 'county', 20200414, '01234',
205-
lag=2)
206-
207-
# check result
208-
self.assertDictEqual(response_3, {
209-
'result': 1,
210-
'epidata': [{
208+
}],
209+
'message': 'success',
210+
})
211+
212+
with self.subTest(name='request at a given lag'):
213+
# fetch data, specifying lag, not issue range
214+
response_3 = Epidata.covidcast(
215+
'src', 'sig', 'day', 'county', 20200414, '01234',
216+
lag=2)
217+
218+
# check result
219+
self.assertDictEqual(response_3, {
220+
'result': 1,
221+
'epidata': [{
211222
'time_value': 20200414,
212223
'geo_value': '01234',
213224
'value': 6.5,
@@ -217,9 +228,9 @@ def test_covidcast(self):
217228
'issue': 20200416,
218229
'lag': 2,
219230
'signal': 'sig',
220-
}],
221-
'message': 'success',
222-
})
231+
}],
232+
'message': 'success',
233+
})
223234

224235
def test_geo_value(self):
225236
"""test different variants of geo types: single, *, multi."""

0 commit comments

Comments
 (0)