@@ -21,25 +21,44 @@ def test_make_date_filter(self):
2121 assert not date_filter (FILENAME_REGEX .match ("20200620_a_b.csv" ))
2222 assert not date_filter (FILENAME_REGEX .match ("202006_a_b.csv" ))
2323
24- # pylint: disable=fixme
25- # TODO: mock out the advanced meta endpoint /covidcast/meta as well
26- # https://github.com/cmu-delphi/covidcast-indicators/issues/1456
24+ # Solution from https://stackoverflow.com/questions/15753390/
25+ #how-can-i-mock-requests-and-the-response
26+ def mocked_requests_get (* args , ** kwargs ):
27+ class MockResponse :
28+ def __init__ (self , json_data , status_code ):
29+ self .json_data = json_data
30+ self .status_code = status_code
31+
32+ def json (self ):
33+ return self .json_data
34+ if len (kwargs ) == 0 :
35+ return MockResponse ([{'source' : 'chng' , 'db_source' : 'chng' },
36+ {'source' : 'covid-act-now' , 'db_source' : 'covid-act-now' }], 200 )
37+ elif kwargs ["params" ] == {'signal' : 'chng:inactive' }:
38+ return MockResponse ([{"signals" : [{"active" : False }]}], 200 )
39+ else :
40+ return MockResponse ([{"signals" : [{"active" : True }]}], 200 )
41+ @mock .patch ('requests.get' , side_effect = mocked_requests_get )
2742 @mock .patch ("covidcast.metadata" )
28- def test_get_geo_signal_combos (self , mock_metadata ):
43+ def test_get_geo_signal_combos (self , mock_metadata , mock_get ):
2944 """Test that the geo signal combos are correctly pulled from the covidcast metadata."""
3045 # Need to use actual data_source and signal names since we reference the API
46+ # We let the chng signal "inactive" be an inactive signal
3147 mock_metadata .return_value = pd .DataFrame ({"data_source" : ["chng" , "chng" , "chng" ,
3248 "covid-act-now" ,
3349 "covid-act-now" ,
34- "covid-act-now" ],
50+ "covid-act-now" ,
51+ "chng" ],
3552 "signal" : ["smoothed_outpatient_cli" ,
3653 "smoothed_outpatient_covid" ,
3754 "smoothed_outpatient_covid" ,
3855 "pcr_specimen_positivity_rate" ,
3956 "pcr_specimen_positivity_rate" ,
40- "pcr_specimen_total_tests" ],
57+ "pcr_specimen_total_tests" ,
58+ "inactive" ],
4159 "geo_type" : ["state" , "state" , "county" ,
42- "hrr" , "msa" , "msa" ]
60+ "hrr" , "msa" , "msa" ,
61+ "state" ]
4362 })
4463
4564 assert set (get_geo_signal_combos ("chng" )) == set (
0 commit comments