@@ -76,7 +76,7 @@ def test_acquire_dataset(self):
7676 response = Epidata .covid_hosp_facility (
7777 '450822' , Epidata .range (20200101 , 20210101 ))
7878 self .assertEqual (response ['result' ], 1 )
79- self .assertEqual (len (response ['epidata' ]), 1 )
79+ self .assertEqual (len (response ['epidata' ]), 2 )
8080 row = response ['epidata' ][0 ]
8181 for k ,v in expected_spotchecks .items ():
8282 self .assertTrue (
@@ -101,9 +101,9 @@ def test_acquire_dataset(self):
101101 response = Epidata .covid_hosp_facility (
102102 '450822' , Epidata .range (20200101 , 20210101 ))
103103 self .assertEqual (response ['result' ], 1 )
104- self .assertEqual (len (response ['epidata' ]), 1 )
104+ self .assertEqual (len (response ['epidata' ]), 2 )
105105
106- @freeze_time ("2021-03-16 " )
106+ @freeze_time ("2021-03-17 " )
107107 def test_facility_lookup (self ):
108108 """Lookup facilities using various filters."""
109109
@@ -120,7 +120,7 @@ def test_facility_lookup(self):
120120 self .assertTrue (acquired )
121121
122122 # texas ground truth, sorted by `hospital_pk`
123- # see sample data at testdata/acquisition/covid_hosp/facility/dataset_old .csv
123+ # see sample data at testdata/acquisition/covid_hosp/facility/dataset .csv
124124 texas_hospitals = [{
125125 'hospital_pk' : '450771' ,
126126 'state' : 'TX' ,
@@ -139,7 +139,7 @@ def test_facility_lookup(self):
139139 'hospital_name' : 'MEDICAL CITY LAS COLINAS' ,
140140 'address' : '6800 N MACARTHUR BLVD' ,
141141 'city' : 'IRVING' ,
142- 'zip' : '75039' ,
142+ 'zip' : '77777' , # most-recent collection week should take precedence
143143 'hospital_subtype' : 'Short Term' ,
144144 'fips_code' : '48113' ,
145145 'is_metro_micro' : 1 ,
@@ -150,7 +150,7 @@ def test_facility_lookup(self):
150150 'hospital_name' : 'RANKIN HOSPITAL MEDICAL CLINIC' ,
151151 'address' : '1611 SPUR 576' ,
152152 'city' : 'RANKIN' ,
153- 'zip' : '79778' ,
153+ 'zip' : '99999' , # most-recent collection week should take precedence
154154 'hospital_subtype' : 'Critical Access Hospitals' ,
155155 'fips_code' : '48461' ,
156156 'is_metro_micro' : 0 ,
@@ -160,16 +160,16 @@ def test_facility_lookup(self):
160160 response = Epidata .covid_hosp_facility_lookup (state = 'tx' )
161161 self .assertEqual (response ['epidata' ], texas_hospitals )
162162
163- with self .subTest (name = 'by ccn ' ):
164- response = Epidata .covid_hosp_facility_lookup (ccn = '450771 ' )
163+ with self .subTest (name = 'by zip ' ):
164+ response = Epidata .covid_hosp_facility_lookup (zip = '75093 ' )
165165 self .assertEqual (response ['epidata' ], texas_hospitals [0 :1 ])
166166
167167 with self .subTest (name = 'by city' ):
168168 response = Epidata .covid_hosp_facility_lookup (city = 'irving' )
169169 self .assertEqual (response ['epidata' ], texas_hospitals [1 :2 ])
170170
171- with self .subTest (name = 'by zip ' ):
172- response = Epidata .covid_hosp_facility_lookup (zip = '79778 ' )
171+ with self .subTest (name = 'by ccn ' ):
172+ response = Epidata .covid_hosp_facility_lookup (ccn = '451329 ' )
173173 self .assertEqual (response ['epidata' ], texas_hospitals [2 :3 ])
174174
175175 with self .subTest (name = 'by fips_code' ):
@@ -179,3 +179,20 @@ def test_facility_lookup(self):
179179 with self .subTest (name = 'no results' ):
180180 response = Epidata .covid_hosp_facility_lookup (state = 'not a state' )
181181 self .assertEqual (response ['result' ], - 2 )
182+
183+ # update facility info
184+ mock_network = MagicMock ()
185+ mock_network .fetch_metadata .return_value = \
186+ self .test_utils .load_sample_metadata ('metadata_update_facility.csv' )
187+ mock_network .fetch_dataset .return_value = \
188+ self .test_utils .load_sample_dataset ('dataset_update_facility.csv' )
189+
190+ # acquire sample data into local database
191+ with self .subTest (name = 'second acquisition' ):
192+ acquired = Update .run (network = mock_network )
193+ self .assertTrue (acquired )
194+
195+ texas_hospitals [1 ]['zip' ] = '88888'
196+ with self .subTest (name = 'by city after update' ):
197+ response = Epidata .covid_hosp_facility_lookup (city = 'irving' )
198+ self .assertEqual (response ['epidata' ], texas_hospitals [1 :2 ])
0 commit comments