@@ -21,25 +21,41 @@ def test_make_date_filter(self):
21
21
assert not date_filter (FILENAME_REGEX .match ("20200620_a_b.csv" ))
22
22
assert not date_filter (FILENAME_REGEX .match ("202006_a_b.csv" ))
23
23
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 )
27
39
@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 ):
29
41
"""Test that the geo signal combos are correctly pulled from the covidcast metadata."""
30
42
# 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
31
44
mock_metadata .return_value = pd .DataFrame ({"data_source" : ["chng" , "chng" , "chng" ,
32
45
"covid-act-now" ,
33
46
"covid-act-now" ,
34
- "covid-act-now" ],
47
+ "covid-act-now" ,
48
+ "chng" ],
35
49
"signal" : ["smoothed_outpatient_cli" ,
36
50
"smoothed_outpatient_covid" ,
37
51
"smoothed_outpatient_covid" ,
38
52
"pcr_specimen_positivity_rate" ,
39
53
"pcr_specimen_positivity_rate" ,
40
- "pcr_specimen_total_tests" ],
54
+ "pcr_specimen_total_tests" ,
55
+ "inactive" ],
41
56
"geo_type" : ["state" , "state" , "county" ,
42
- "hrr" , "msa" , "msa" ]
57
+ "hrr" , "msa" , "msa" ,
58
+ "state" ]
43
59
})
44
60
45
61
assert set (get_geo_signal_combos ("chng" )) == set (
0 commit comments