def initManagers(self): from core.commons.CommonsManager import CommonsManager from core.base.ConfigManager import ConfigManager from core.base.ModuleManager import ModuleManager from core.device.DeviceManager import DeviceManager from core.dialog.DialogSessionManager import DialogSessionManager from core.dialog.MultiIntentManager import MultiIntentManager from core.dialog.ProtectedIntentManager import ProtectedIntentManager from core.server.MqttManager import MqttManager from core.snips.SamkillaManager import SamkillaManager from core.snips.SnipsConsoleManager import SnipsConsoleManager from core.snips.SnipsServicesManager import SnipsServicesManager from core.user.UserManager import UserManager from core.util.DatabaseManager import DatabaseManager from core.util.InternetManager import InternetManager from core.util.TelemetryManager import TelemetryManager from core.util.ThreadManager import ThreadManager from core.util.TimeManager import TimeManager from core.voice.ASRManager import ASRManager from core.voice.LanguageManager import LanguageManager from core.voice.TalkManager import TalkManager from core.voice.TTSManager import TTSManager from core.voice.WakewordManager import WakewordManager from core.interface.WebInterfaceManager import WebInterfaceManager from core.snips.SnipsWatchManager import SnipsWatchManager self.commonsManager = CommonsManager() self.commons = self.commonsManager self.configManager = ConfigManager() self.databaseManager = DatabaseManager() self.languageManager = LanguageManager() self.snipsServicesManager = SnipsServicesManager() self.asrManager = ASRManager() self.ttsManager = TTSManager() self.threadManager = ThreadManager() self.protectedIntentManager = ProtectedIntentManager() self.mqttManager = MqttManager() self.timeManager = TimeManager() self.userManager = UserManager() self.dialogSessionManager = DialogSessionManager() self.multiIntentManager = MultiIntentManager() self.telemetryManager = TelemetryManager() self.moduleManager = ModuleManager() self.deviceManager = DeviceManager() self.internetManager = InternetManager() self.snipsConsoleManager = SnipsConsoleManager() self.samkillaManager = SamkillaManager() self.wakewordManager = WakewordManager() self.talkManager = TalkManager() self.webInterfaceManager = WebInterfaceManager() self.snipsWatchManager = SnipsWatchManager() self._managers = { name[0].upper() + name[1:]: manager for name, manager in self.__dict__.items() if name.endswith('Manager') }
def test_checkOnlineState(self, mock_commons, mock_requests, mock_broadcast): common_mock = MagicMock() common_mock.getFunctionCaller.return_value = 'InternetManager' mock_commons.return_value = common_mock internetManager = InternetManager() # request returns status code 204 mock_requestsResult = MagicMock() mock_statusCode = mock.PropertyMock(return_value=204) type(mock_requestsResult).status_code = mock_statusCode mock_requests.get.return_value = mock_requestsResult internetManager.checkOnlineState() mock_requests.get.assert_called_once_with( 'http://clients3.google.com/generate_204') mock_broadcast.assert_called_once_with(method='internetConnected', exceptions=['InternetManager'], propagateToSkills=True) self.assertEqual(internetManager.online, True) mock_broadcast.reset_mock() mock_requests.reset_mock() # when calling check online state a second time it does not broadcast again internetManager.checkOnlineState() mock_requests.get.assert_called_once_with( 'http://clients3.google.com/generate_204') mock_broadcast.assert_not_called() self.assertEqual(internetManager.online, True) mock_broadcast.reset_mock() mock_requests.reset_mock() # request returns status code 400 mock_requestsResult = MagicMock() mock_statusCode = mock.PropertyMock(return_value=400) type(mock_requestsResult).status_code = mock_statusCode mock_requests.get.return_value = mock_requestsResult # when wrong status code is returned (and currently online) internetManager.checkOnlineState() mock_requests.get.assert_called_once_with( 'http://clients3.google.com/generate_204') mock_broadcast.assert_called_once_with(method='internetLost', exceptions=['InternetManager'], propagateToSkills=True) self.assertEqual(internetManager.online, False) mock_broadcast.reset_mock() mock_requests.reset_mock() # when calling check online state a second time it does not broadcast again internetManager.checkOnlineState() mock_requests.get.assert_called_once_with( 'http://clients3.google.com/generate_204') mock_broadcast.assert_not_called() self.assertEqual(internetManager.online, False) mock_broadcast.reset_mock() mock_requests.reset_mock() # set state to online again mock_requestsResult = MagicMock() mock_statusCode = mock.PropertyMock(return_value=204) type(mock_requestsResult).status_code = mock_statusCode mock_requests.get.return_value = mock_requestsResult internetManager.checkOnlineState() mock_broadcast.reset_mock() mock_requests.reset_mock() # request raises exception is the same as non 204 status code mock_requests.get.side_effect = RequestException internetManager.checkOnlineState() mock_requests.get.assert_called_once_with( 'http://clients3.google.com/generate_204') mock_broadcast.assert_called_once_with(method='internetLost', exceptions=['InternetManager'], propagateToSkills=True) self.assertEqual(internetManager.online, False)
def initManagers(self): from core.commons.CommonsManager import CommonsManager from core.base.ConfigManager import ConfigManager from core.base.SkillManager import SkillManager from core.device.DeviceManager import DeviceManager from core.device.LocationManager import LocationManager from core.dialog.MultiIntentManager import MultiIntentManager from core.server.MqttManager import MqttManager from core.user.UserManager import UserManager from core.util.DatabaseManager import DatabaseManager from core.util.InternetManager import InternetManager from core.util.TelemetryManager import TelemetryManager from core.util.ThreadManager import ThreadManager from core.util.TimeManager import TimeManager from core.asr.ASRManager import ASRManager from core.voice.LanguageManager import LanguageManager from core.voice.TalkManager import TalkManager from core.voice.TTSManager import TTSManager from core.voice.WakewordRecorder import WakewordRecorder from core.interface.WebInterfaceManager import WebInterfaceManager from core.interface.NodeRedManager import NodeRedManager from core.base.SkillStoreManager import SkillStoreManager from core.dialog.DialogTemplateManager import DialogTemplateManager from core.base.AssistantManager import AssistantManager from core.nlu.NluManager import NluManager from core.util.AliceWatchManager import AliceWatchManager from core.server.AudioServer import AudioManager from core.dialog.DialogManager import DialogManager from core.voice.WakewordManager import WakewordManager self.commonsManager = CommonsManager() self.commons = self.commonsManager self.configManager = ConfigManager() self.databaseManager = DatabaseManager() self.skillManager = SkillManager() self.deviceManager = DeviceManager() self.audioManager = AudioManager() self.languageManager = LanguageManager() self.asrManager = ASRManager() self.ttsManager = TTSManager() self.threadManager = ThreadManager() self.mqttManager = MqttManager() self.timeManager = TimeManager() self.userManager = UserManager() self.multiIntentManager = MultiIntentManager() self.telemetryManager = TelemetryManager() self.locationManager = LocationManager() self.internetManager = InternetManager() self.wakewordRecorder = WakewordRecorder() self.talkManager = TalkManager() self.webInterfaceManager = WebInterfaceManager() self.nodeRedManager = NodeRedManager() self.skillStoreManager = SkillStoreManager() self.dialogTemplateManager = DialogTemplateManager() self.assistantManager = AssistantManager() self.nluManager = NluManager() self.aliceWatchManager = AliceWatchManager() self.dialogManager = DialogManager() self.wakewordManager = WakewordManager() self._managers = { name[0].upper() + name[1:]: manager for name, manager in self.__dict__.items() if name.endswith('Manager') }
def test_checkOnlineState(self, mock_superManager, mock_commons, mock_requests, mock_broadcast): address = 'https://api.projectalice.io/generate_204' common_mock = MagicMock() common_mock.getFunctionCaller.return_value = 'InternetManager' mock_commons.return_value = common_mock # mock SuperManager mock_instance = MagicMock() mock_superManager.getInstance.return_value = mock_instance mock_instance.configManager.getAliceConfigByName.return_value = False internetManager = InternetManager() # request returns status code 204 mock_requestsResult = MagicMock() mock_statusCode = mock.PropertyMock(return_value=204) type(mock_requestsResult).status_code = mock_statusCode mock_requests.get.return_value = mock_requestsResult # Not called if stay completely offline mock_instance.configManager.getAliceConfigByName.return_value = True internetManager.checkOnlineState() mock_requests.get.asset_not_called() mock_instance.configManager.getAliceConfigByName.return_value = False internetManager.checkOnlineState() mock_requests.get.assert_called_once_with(address) mock_broadcast.assert_called_once_with(method='internetConnected', exceptions=['InternetManager'], propagateToSkills=True) self.assertEqual(internetManager.online, True) mock_broadcast.reset_mock() mock_requests.reset_mock() # when calling check online state a second time it does not broadcast again internetManager.checkOnlineState() mock_requests.get.assert_called_once_with(address) mock_broadcast.assert_not_called() self.assertEqual(internetManager.online, True) mock_broadcast.reset_mock() mock_requests.reset_mock() # request returns status code 400 mock_requestsResult = MagicMock() mock_statusCode = mock.PropertyMock(return_value=400) type(mock_requestsResult).status_code = mock_statusCode mock_requests.get.return_value = mock_requestsResult # when wrong status code is returned (and currently online) internetManager.checkOnlineState() mock_requests.get.assert_called_once_with(address) mock_broadcast.assert_called_once_with(method='internetLost', exceptions=['InternetManager'], propagateToSkills=True) self.assertEqual(internetManager.online, False) mock_broadcast.reset_mock() mock_requests.reset_mock() # when calling check online state a second time it does not broadcast again internetManager.checkOnlineState() mock_requests.get.assert_called_once_with(address) mock_broadcast.assert_not_called() self.assertEqual(internetManager.online, False) mock_broadcast.reset_mock() mock_requests.reset_mock() # set state to online again mock_requestsResult = MagicMock() mock_statusCode = mock.PropertyMock(return_value=204) type(mock_requestsResult).status_code = mock_statusCode mock_requests.get.return_value = mock_requestsResult internetManager.checkOnlineState() mock_broadcast.reset_mock() mock_requests.reset_mock() # request raises exception is the same as non 204 status code mock_requests.get.side_effect = RequestException internetManager.checkOnlineState() mock_requests.get.assert_called_once_with(address) mock_broadcast.assert_called_once_with(method='internetLost', exceptions=['InternetManager'], propagateToSkills=True) self.assertEqual(internetManager.online, False)