@@ -21,25 +21,41 @@ 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 kwargs ["params" ] == {'signal' :'chng:inactive' }:
35+ return MockResponse ([{"signals" : [{"active" : False }]}], 200 )
36+ else :
37+ return MockResponse ([{"signals" : [{"active" : True }]}], 200 )
38+ @mock .patch ('requests.get' , side_effect = mocked_requests_get )
2739 @mock .patch ("covidcast.metadata" )
28- def test_get_geo_signal_combos (self , mock_metadata ):
40+ def test_get_geo_signal_combos (self , mock_metadata , mock_get ):
2941 """Test that the geo signal combos are correctly pulled from the covidcast metadata."""
3042 # Need to use actual data_source and signal names since we reference the API
43+ # We let the chng signal "inactive" be an inactive signal
3144 mock_metadata .return_value = pd .DataFrame ({"data_source" : ["chng" , "chng" , "chng" ,
3245 "covid-act-now" ,
3346 "covid-act-now" ,
34- "covid-act-now" ],
47+ "covid-act-now" ,
48+ "chng" ],
3549 "signal" : ["smoothed_outpatient_cli" ,
3650 "smoothed_outpatient_covid" ,
3751 "smoothed_outpatient_covid" ,
3852 "pcr_specimen_positivity_rate" ,
3953 "pcr_specimen_positivity_rate" ,
40- "pcr_specimen_total_tests" ],
54+ "pcr_specimen_total_tests" ,
55+ "inactive" ],
4156 "geo_type" : ["state" , "state" , "county" ,
42- "hrr" , "msa" , "msa" ]
57+ "hrr" , "msa" , "msa" ,
58+ "state" ]
4359 })
4460
4561 assert set (get_geo_signal_combos ("chng" )) == set (
0 commit comments