Skip to content

Commit 9483093

Browse files
committed
add integration test skeletons
1 parent f137320 commit 9483093

File tree

5 files changed

+132
-310
lines changed

5 files changed

+132
-310
lines changed

integrations/acquisition/rvdss/test_scenarios.py

Lines changed: 74 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
# third party
1212
import mysql.connector
13+
import pandas as pd
14+
from pathlib import Path
15+
import pdb
1316

1417
# py3tester coverage target (equivalent to `import *`)
1518
# __test_target__ = 'delphi.epidata.acquisition.covid_hosp.facility.update'
@@ -25,74 +28,88 @@ def setUp(self):
2528
# self.test_utils = UnitTestUtils(__file__)
2629

2730
# use the local instance of the Epidata API
28-
Epidata.BASE_URL = 'https://delphi_web_epidata/epidata'
31+
Epidata.BASE_URL = 'http://delphi_web_epidata/epidata'
2932
Epidata.auth = ('epidata', 'key')
3033

3134
# use the local instance of the epidata database
3235
secrets.db.host = 'delphi_database_epidata'
3336
secrets.db.epi = ('user', 'pass')
3437

3538
# clear relevant tables
36-
u, p = secrets.db.epi
37-
cnx = mysql.connector.connect(user=u, password=p, database="epidata")
38-
cur = cnx.cursor()
39-
40-
cur.execute('truncate table rvdss_repiratory_detections')
41-
cur.execute('delete from api_user')
42-
cur.execute('insert into api_user(api_key, email) values ("key", "emai")')
4339

40+
epidata_cnx = mysql.connector.connect(
41+
user='user',
42+
password='pass',
43+
host='delphi_database_epidata',
44+
database='epidata')
45+
epidata_cur = epidata_cnx.cursor()
46+
47+
epidata_cur.execute('truncate table rvdss')
48+
epidata_cur.execute('DELETE from api_user')
49+
epidata_cur.execute('INSERT INTO api_user(api_key, email) VALUES ("key", "emai")')
50+
epidata_cnx.commit()
51+
epidata_cur.close()
52+
epidata_cnx.close()
53+
4454
def test_rvdss_repiratory_detections(self):
55+
#TEST_DIR = Path(__file__).parent.parent.parent
56+
#detection_data = pd.read_csv(str(TEST_DIR) + "/testdata/acquisition/rvdss/RVD_CurrentWeekTable_Formatted.csv")
57+
#detection_subset = detection_data[(detection_data['geo_value'].isin(['nl', 'nb'])) & (detection_data['time_value'].isin(['2024-08-31', '2024-09-07'])) ]
58+
4559
# make sure the data does not yet exist
4660
with self.subTest(name='no data yet'):
47-
response = Epidata.rvdss_repiratory_detections(
48-
'450822', Epidata.range(20200101, 20210101))
61+
response = Epidata.rvdss(geo_type='province',
62+
time_values= ['2024-08-31', '2024-09-07'],
63+
geo_value = ['nl','nb'])
4964
self.assertEqual(response['result'], -2, response)
50-
51-
# acquire sample data into local database
52-
# TODO: Define example data
53-
with self.subTest(name='first acquisition'):
54-
acquired = Update.run(network=mock_network)
55-
#self.assertTrue(acquired)
56-
57-
# make sure the data now exists
58-
with self.subTest(name='initial data checks'):
59-
expected_spotchecks = {
60-
"hospital_pk": "450822",
61-
"collection_week": 20201030,
62-
"publication_date": 20210315,
63-
"previous_day_total_ed_visits_7_day_sum": 536,
64-
"total_personnel_covid_vaccinated_doses_all_7_day_sum": 18,
65-
"total_beds_7_day_avg": 69.3,
66-
"previous_day_admission_influenza_confirmed_7_day_sum": -999999
67-
}
68-
response = Epidata.covid_hosp_facility(
69-
'450822', Epidata.range(20200101, 20210101))
70-
self.assertEqual(response['result'], 1)
71-
self.assertEqual(len(response['epidata']), 2)
72-
row = response['epidata'][0]
73-
for k,v in expected_spotchecks.items():
74-
self.assertTrue(
75-
k in row,
76-
f"no '{k}' in row:\n{NEWLINE.join(sorted(row.keys()))}"
77-
)
78-
if isinstance(v, float):
79-
self.assertAlmostEqual(row[k], v, f"row[{k}] is {row[k]} not {v}")
80-
else:
81-
self.assertEqual(row[k], v, f"row[{k}] is {row[k]} not {v}")
82-
83-
# expect 113 fields per row (114 database columns, except `id`)
84-
self.assertEqual(len(row), 113)
85-
86-
# re-acquisition of the same dataset should be a no-op
87-
with self.subTest(name='second acquisition'):
88-
acquired = Update.run(network=mock_network)
89-
self.assertFalse(acquired)
90-
91-
# make sure the data still exists
92-
with self.subTest(name='final data checks'):
93-
response = Epidata.covid_hosp_facility(
94-
'450822', Epidata.range(20200101, 20210101))
95-
self.assertEqual(response['result'], 1)
96-
self.assertEqual(len(response['epidata']), 2)
65+
66+
67+
# # acquire sample data into local database
68+
# # TODO: Define example data
69+
# with self.subTest(name='first acquisition'):
70+
# acquired = Update.run(network=mock_network)
71+
# #self.assertTrue(acquired)
72+
73+
# # make sure the data now exists
74+
# with self.subTest(name='initial data checks'):
75+
# expected_spotchecks = {
76+
# "hospital_pk": "450822",
77+
# "collection_week": 20201030,
78+
# "publication_date": 20210315,
79+
# "previous_day_total_ed_visits_7_day_sum": 536,
80+
# "total_personnel_covid_vaccinated_doses_all_7_day_sum": 18,
81+
# "total_beds_7_day_avg": 69.3,
82+
# "previous_day_admission_influenza_confirmed_7_day_sum": -999999
83+
# }
84+
# response = Epidata.covid_hosp_facility(
85+
# '450822', Epidata.range(20200101, 20210101))
86+
# self.assertEqual(response['result'], 1)
87+
# self.assertEqual(len(response['epidata']), 2)
88+
# row = response['epidata'][0]
89+
# for k,v in expected_spotchecks.items():
90+
# self.assertTrue(
91+
# k in row,
92+
# f"no '{k}' in row:\n{NEWLINE.join(sorted(row.keys()))}"
93+
# )
94+
# if isinstance(v, float):
95+
# self.assertAlmostEqual(row[k], v, f"row[{k}] is {row[k]} not {v}")
96+
# else:
97+
# self.assertEqual(row[k], v, f"row[{k}] is {row[k]} not {v}")
98+
99+
# # expect 113 fields per row (114 database columns, except `id`)
100+
# self.assertEqual(len(row), 113)
101+
102+
# # re-acquisition of the same dataset should be a no-op
103+
# with self.subTest(name='second acquisition'):
104+
# acquired = Update.run(network=mock_network)
105+
# self.assertFalse(acquired)
106+
107+
# # make sure the data still exists
108+
# with self.subTest(name='final data checks'):
109+
# response = Epidata.covid_hosp_facility(
110+
# '450822', Epidata.range(20200101, 20210101))
111+
# self.assertEqual(response['result'], 1)
112+
# self.assertEqual(len(response['epidata']), 2)
113+
pass
97114

98115

integrations/server/test_rvdss.py

Lines changed: 52 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,72 @@
11
# first party
22
from delphi.epidata.common.integration_test_base_class import DelphiTestBase
3+
import pdb
34

45

56
class rvdssTest(DelphiTestBase):
67
"""Basic integration tests for rvdss endpoint."""
78

89
def localSetUp(self):
9-
self.truncate_tables_list = ["rvdss_repiratory_detections",
10-
"rvdss_pct_positive",
11-
"rvdss_detections_counts"]
10+
self.truncate_tables_list = ["rvdss"]
1211

1312
def test_rvdss_repiratory_detections(self):
14-
"""Basic integration test for rvdss_repiratory_detections endpoint"""
13+
"""Basic integration test for rvdss endpoint"""
1514
self.cur.execute(
16-
"INSERT INTO `rvdss_repiratory_detections`(`epiweek`, `time_value`, `issue`, `geo_type`, `geo_value`, `sarscov2_tests`, `sarscov2_positive_tests`, `flu_tests`, `flu_positive_tests`, `fluah1n1pdm09_positive_tests`, `fluah3_positive_tests`, `fluauns_positive_tests`, `flua_positive_tests`, `flub_positive_tests`, `rsv_tests`, `rsv_positive_tests`, `hpiv_tests`, `hpiv1_positive_tests`, `hpiv2_positive_tests`, `hpiv3_positive_tests`, `hpiv4_positive_tests`, `hpivother_positive_tests`, `adv_tests`, `adv_positive_tests`, `hmpv_tests`, `hmpv_positive_tests`, `evrv_tests`, `evrv_positive_tests`, `hcov_tests`, `hcov_positive_tests`, `week`, `weekorder`, `year`) VALUES(%(epiweek)s, %(time_value)s, %(issue)s, %(geo_type)s, %(geo_value)s, %(sarscov2_tests)s, %(sarscov2_positive_tests)s, %(flu_tests)s, %(flu_positive_tests)s, %(fluah1n1pdm09_positive_tests)s, %(fluah3_positive_tests)s, %(fluauns_positive_tests)s, %(flua_positive_tests)s, %(flub_positive_tests)s, %(rsv_tests)s, %(rsv_positive_tests)s, %(hpiv_tests)s, %(hpiv1_positive_tests)s, %(hpiv2_positive_tests)s, %(hpiv3_positive_tests)s, %(hpiv4_positive_tests)s, %(hpivother_positive_tests)s, %(adv_tests)s, %(adv_positive_tests)s, %(hmpv_tests)s, %(hmpv_positive_tests)s, %(evrv_tests)s, %(evrv_positive_tests)s, %(hcov_tests)s, %(hcov_positive_tests)s, %(week)s, %(weekorder)s, %(year)s)",
17-
("201212", "2012-04-12", "2012-04-17", "region","on", "10", "1", "9", "1", "0", "0", "2", "3", "1", "8", "2", "7", "1", "1", "1", "1","1", "6", "5", "100", "13", "92", "9", "167", "52", "12", "34", "2012"),
15+
"INSERT INTO `rvdss`(`epiweek`, `time_value`,`time_type`, `issue`, `geo_type`, `geo_value`, `sarscov2_tests`, `sarscov2_positive_tests`, `sarscov2_pct_positive`, `flu_tests`, `flu_positive_tests`, `flu_pct_positive`, `fluah1n1pdm09_positive_tests`, `fluah3_positive_tests`, `fluauns_positive_tests`, `flua_positive_tests`, `flua_tests`, `flua_pct_positive`, `flub_positive_tests`, `flub_tests`, `flub_pct_positive`, `rsv_tests`, `rsv_positive_tests`, `rsv_pct_positive`, `hpiv_tests`, `hpiv1_positive_tests`, `hpiv2_positive_tests`, `hpiv3_positive_tests`, `hpiv4_positive_tests`, `hpivother_positive_tests`, `hpiv_positive_tests`, `hpiv_pct_positive`, `adv_tests`, `adv_positive_tests`, `adv_pct_positive`, `hmpv_tests`, `hmpv_positive_tests`, `hmpv_pct_positive`, `evrv_tests`, `evrv_positive_tests`, `evrv_pct_positive`, `hcov_tests`, `hcov_positive_tests`, `hcov_pct_positive`, `year`) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
16+
(201212,20120412,"week","2012-04-17",'province','on',10,1,10,20, 10, 50, 1, 1, 1, 5, 20, 25, 4, 20, 20, 30, 3, 10, 40, 2, 2, 2, 1, 1, 8, 20, 40, 16, 40, 10, 2, 20, 1, 0, 0, 24, 3, 12.5, 2012),
1817
)
1918
self.cnx.commit()
20-
response = self.epidata_client.rvdss_repiratory_detections(epiweeks=201212, geo_value="on")
19+
pdb.set_trace()
20+
response = self.epidata_client.rvdss(geo_type="province", time_values = 20120412,geo_value="on")
2121
self.assertEqual(
2222
response,
2323
{
2424
"epidata": [
25-
{'epiweek':201212,
26-
'time_value':"2012-04-12",
27-
'issue':"2012-04-17",
28-
'geo_type':"region",
29-
'geo_value':"on",
30-
'sarscov2_tests':10,
31-
'sarscov2_positive_tests':1,
32-
'flu_tests':9,
33-
'flu_positive_tests':1,
34-
'fluah1n1pdm09_positive_tests':0,
35-
'fluah3_positive_tests':0,
36-
'fluauns_positive_tests':2,
37-
'flua_positive_tests':3,
38-
'flub_positive_tests':1,
39-
'rsv_tests':8,
40-
'rsv_positive_tests':2,
41-
'hpiv_tests':8,
42-
'hpiv1_positive_tests':1,
43-
'hpiv2_positive_tests':1,
44-
'hpiv3_positive_tests':1,
45-
'hpiv4_positive_tests':1,
46-
'hpivother_positive_tests':1,
47-
'adv_tests':6,
48-
'adv_positive_tests':5,
49-
'hmpv_tests':100,
50-
'hmpv_positive_tests':13,
51-
'evrv_tests':92,
52-
'evrv_positive_tests':9,
53-
'hcov_tests':167,
54-
'hcov_positive_tests':52,
55-
'week':12,
56-
'weekorder':34,
57-
'year':2012
58-
}
59-
],
60-
"result": 1,
61-
"message": "success",
62-
},
63-
)
64-
65-
def test_rvdss_pct_positive(self):
66-
"""Basic integration test for rvdss_pct_positive endpoint"""
67-
self.cur.execute(
68-
"INSERT INTO rvdss_pct_positive (`epiweek`, `time_value`, `issue`, `geo_type`, `geo_value`, `evrv_pct_positive`, `evrv_tests`, `evrv_positive_tests`, `hpiv_pct_positive`, `hpiv_tests`, `hpiv_positive_tests`, `adv_pct_positive`, `adv_tests`, `adv_positive_tests`,`hcov_pct_positive`, `hcov_tests`, `hcov_positive_tests`, `flua_pct_positive`, `flub_pct_positive`, `flu_tests`, `flua_positive_tests`, `flua_tests`, `flub_tests`, `flub_positive_tests`, `flu_positive_tests`, `flu_pct_positive`, `hmpv_pct_positive`, `hmpv_tests`, `hmpv_positive_tests`, `rsv_pct_positive`, `rsv_tests`, `rsv_positive_tests`, `sarscov2_pct_positive`, `sarscov2_tests`, `sarscov2_positive_tests`, `region`, `week`, `weekorder`, `year`) VALUES (%(epiweek)s, %(time_value)s, %(issue)s, %(geo_type)s, %(geo_value)s, %(evrv_pct_positive)s, %(evrv_tests)s, %(evrv_positive_tests)s, %(hpiv_pct_positive)s, %(hpiv_tests)s, %(hpiv_positive_tests)s, %(adv_pct_positive)s, %(adv_tests)s, %(hcov_pct_positive)s, %(hcov_tests)s, %(hcov_positive_tests)s, %(flua_pct_positive)s, %(flub_pct_positive)s, %(flu_tests)s, %(flua_positive_tests)s, %(flua_tests)s, %(flub_tests)s, %(flub_positive_tests)s, %(flu_positive_tests)s, %(flu_pct_positive)s, %(hmpv_pct_positive)s, %(hmpv_tests)s, %(hmpv_positive_tests)s, %(rsv_pct_positive)s, %(rsv_tests)s, %(rsv_positive_tests)s, %(sarscov2_pct_positive)s, %(sarscov2_tests)s, %(sarscov2_positive_tests)s, %(region)s, %(week)s, %(weekorder)s, %(year)s)",
69-
("201212", "2012-04-12", "2012-04-17", "region","on","0.1","10","1","0.1","10","1","0.1","10","1","0.1","10","1","0.05","0.05","100", "10", "100","100", "10", "20", "0.1","0.1","10","1","0.1","10","1","0.1","10","1","on","12","34","2012")
70-
)
71-
self.cnx.commit()
72-
response = self.epidata_client.rvdss_pct_positive(epiweeks=201212, geo_value="on")
73-
self.assertEqual(
74-
response,
75-
{
76-
"epidata": [
77-
{'epiweek':201212,
78-
'time_value':"2012-04-12",
79-
'issue':"2012-04-17",
80-
'geo_type':"region",
81-
'geo_value':"on",
82-
'evrv_pct_positive':0.1,
83-
'evrv_tests':10,
84-
'evrv_positive_tests':1,
85-
'hpiv_pct_positive':0.1,
86-
'hpiv_tests':10,
87-
'hpiv_positive_tests':1,
88-
'adv_pct_positive':0.1,
89-
'adv_tests':10,
90-
'adv_positive_tests':1,
91-
'hcov_pct_positive':0.1,
92-
'hcov_tests':10,
93-
'hcov_positive_tests':1,
94-
'flua_pct_positive':0.05,
95-
'flub_pct_positive':0.05,
96-
'flu_tests':100,
97-
'flua_positive_tests':10,
98-
'flua_tests':100,
99-
'flub_tests':100,
100-
'flub_positive_tests':10,
101-
'flu_positive_tests':20,
102-
'flu_pct_positive':0.1,
103-
'hmpv_pct_positive':0.1,
104-
'hmpv_tests':10,
105-
'hmpv_positive_tests':1,
106-
'rsv_pct_positive':0.1,
107-
'rsv_tests':10,
108-
'rsv_positive_tests':1,
109-
'sarscov2_pct_positive':0.1,
110-
'sarscov2_tests':10,
111-
'sarscov2_positive_tests':1,
112-
'region':"on",
113-
'week':12,
114-
'weekorder':34,
115-
'year':2012
116-
}
117-
],
118-
"result": 1,
119-
"message": "success",
120-
},
121-
)
122-
123-
def test_rvdss_detections_counts(self):
124-
"""Basic integration test for rvdss_detections_counts endpoint"""
125-
self.cur.execute(
126-
"INSERT INTO rvdss_detections_counts (`epiweek`, `time_value`, `issue`, `geo_type`, `geo_value`, `hpiv_positive_tests`, `adv_positive_tests`, `hmpv_positive_tests`, `evrv_positive_tests`, `hcov_positive_tests`, `rsv_positive_tests`, `flu_positive_tests`) VALUES (%(epiweek)s, %(time_value)s, %(issue)s, %(geo_type)s, %(geo_value)s, %(hpiv_positive_tests)s, %(adv_positive_tests)s, %(hmpv_positive_tests)s, %(evrv_positive_tests)s, %(hcov_positive_tests)s, %(rsv_positive_tests)s, %(flu_positive_tests)s)",
127-
("201212", "2012-04-12", "2012-04-17", "nation","ca", "10", "9", "8", "7", "6", "5", "4"),
128-
)
129-
self.cnx.commit()
130-
response = self.epidata_client.rvdss_detections_counts(epiweeks=201212, geo_value="ca")
131-
self.assertEqual(
132-
response,
133-
{
134-
"epidata": [
135-
{'epiweek':201212,
136-
'time_value':"2012-04-12",
137-
'issue':"2012-04-17",
138-
'geo_type':"nation",
139-
'geo_value':"ca",
140-
'hpiv_positive_tests':10,
141-
'adv_positive_tests':9,
142-
'hmpv_positive_tests':8,
143-
'evrv_positive_tests':7,
144-
'hcov_positive_tests':6,
145-
'rsv_positive_tests':5,
146-
'flu_positive_tests':4
25+
{ "epiweek":201212,
26+
"time_value":20120412,
27+
"time_type":"week",
28+
"issue":"2012-04-17",
29+
"geo_type":"province",
30+
"geo_value":"on",
31+
"sarscov2_tests":10,
32+
"sarscov2_positive_tests":1,
33+
"sarscov2_pct_positive":10,
34+
"flu_tests":20,
35+
"flu_positive_tests":10,
36+
"flu_pct_positive":50,
37+
"fluah1n1pdm09_positive_tests":1,
38+
"fluah3_positive_tests":1,
39+
"fluauns_positive_tests":1,
40+
"flua_positive_tests":5,
41+
"flua_tests":20,
42+
"flua_pct_positive":25,
43+
"flub_positive_tests":4,
44+
"flub_tests":20,
45+
"flub_pct_positive":25,
46+
"rsv_tests":30,
47+
"rsv_positive_tests":3,
48+
"rsv_pct_positive":10,
49+
"hpiv_tests":40,
50+
"hpiv1_positive_tests":2,
51+
"hpiv2_positive_tests":2,
52+
"hpiv3_positive_tests":2,
53+
"hpiv4_positive_tests":1,
54+
"hpivother_positive_tests":1,
55+
"hpiv_positive_tests":8,
56+
"hpiv_pct_positive":20,
57+
"adv_tests":40,
58+
"adv_positive_tests":16,
59+
"adv_pct_positive":40,
60+
"hmpv_tests":10,
61+
"hmpv_positive_tests":2,
62+
"hmpv_pct_positive":20,
63+
"evrv_tests":1,
64+
"evrv_positive_tests":0,
65+
"evrv_pct_positive":0,
66+
"hcov_tests":24,
67+
"hcov_positive_tests":3,
68+
"hcov_pct_positive":12.5,
69+
"year":2012
14770
}
14871
],
14972
"result": 1,

src/acquisition/rvdss/database.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020
import mysql.connector
2121

2222
# first party
23-
from delphi.epidata.acquisition.rvdss import rvdss
2423
import delphi.operations.secrets as secrets
2524

26-
2725
rvdss_cols= (
2826
"epiweek",
2927
"time_value",
28+
"time_type",
3029
"issue",
3130
"geo_type",
3231
"geo_value",
@@ -68,8 +67,7 @@
6867
"hcov_tests",
6968
"hcov_positive_tests",
7069
"hcov_pct_positive",
71-
"year",
72-
"region"
70+
"year"
7371
)
7472

7573
def get_num_rows(cursor):
@@ -84,7 +82,6 @@ def update(data,logger):
8482
cnx = mysql.connector.connect(user=u, password=p, database="epidata")
8583
cur = cnx.cursor()
8684

87-
8885
data_tuples = list(data.itertuples(index=False,name=None))
8986

9087
rvdss_cols_subset = [col for col in rvdss_cols if col in data.columns]

0 commit comments

Comments
 (0)