def test_update_cache(self, timer: MagicMock): timer.return_value = timer_instance = MagicMock() service = LocastService(self.config, MagicMock()) service._get_stations = MagicMock() service._get_stations.return_value = stations = MagicMock() service._update_cache() self.assertEqual(service._stations, stations) timer.assert_called_with(3600, service._update_cache) timer_instance.start.assert_called()
def test_internal_get_stations_facility_lookup(self): stations = [{ "callSign": "CBS", "name": "WLTV1" }, { "callSign": "WLTV2", "name": "NPR" }] service = LocastService(self.config, MagicMock()) service.dma = "123" service.city = "Chicago" service.timezone = "America/Chicago" service._get_locast_stations = get_locast_stations = MagicMock() get_locast_stations.return_value = stations service._detect_callsign = MagicMock() service._detect_callsign.side_effect = [("WLTV", 1), None, ("WLTV", 2)] service._fcc_facilities = MagicMock() service._fcc_facilities.by_dma_and_call_sign.side_effect = [{ "channel": "2", "analog": False }, { "channel": "1", "analog": True }] result = service._get_stations() expected = [{ "callSign": "CBS", "name": "WLTV1", "channel": "2.1", "city": "Chicago", "timezone": "America/Chicago" }, { 'callSign': 'WLTV2', 'name': 'NPR', 'city': 'Chicago', 'channel': '1', "timezone": "America/Chicago" }] get_locast_stations.assert_called() service._fcc_facilities.by_dma_and_call_sign.assert_called_with( "123", "WLTV") self.assertEqual(result, expected)
def test_internal_get_stations_simple_case(self): stations = [{"callSign": "2.1 CBS"}] service = LocastService(self.config, MagicMock()) service.city = "Chicago" service.timezone = "America/Chicago" service._get_locast_stations = get_locast_stations = MagicMock() get_locast_stations.return_value = stations result = service._get_stations() expected = [{ "callSign": "2.1 CBS", "channel": "2.1", "city": "Chicago", "timezone": "America/Chicago" }] get_locast_stations.assert_called() self.assertEqual(result, expected)
def test_internal_get_stations_no_call_sign(self): stations = [{ "callSign": "CBS", "name": "WLTV1" }, { "callSign": "WLTV2", "name": "NPR" }] service = LocastService(self.config, MagicMock()) service.dma = "123" service.city = "Chicago" service.timezone = "America/Chicago" service._get_locast_stations = get_locast_stations = MagicMock() get_locast_stations.return_value = stations service._detect_callsign = MagicMock() service._detect_callsign.return_value = None result = service._get_stations() expected = [{ "callSign": "CBS", "name": "WLTV1", "channel": "1000", "city": "Chicago", "timezone": "America/Chicago" }, { 'callSign': 'WLTV2', 'name': 'NPR', 'city': 'Chicago', 'channel': '1001', 'timezone': 'America/Chicago' }] get_locast_stations.assert_called() self.assertEqual(result, expected)