Beispiel #1
0
    def test_get_rest_api(self):
        expected_rest_api = RestAPI(password_protected=True, active=True,
                                    login="******", password="******", port=5000,
                                    allowed_cors_origin=False)

        sl = SettingLoader(file_path=self.settings_file_to_test)
        self.assertEqual(expected_rest_api, sl._get_rest_api(self.settings_dict))
Beispiel #2
0
    def test_get_settings(self):
        settings_object = Settings()
        settings_object.default_tts_name = "pico2wave"
        settings_object.default_stt_name = "google"
        settings_object.default_trigger_name = "snowboy"
        tts1 = Tts(name="pico2wave",
                   parameters={
                       'cache': True,
                       'language': 'fr-FR'
                   })
        tts2 = Tts(name="voxygen",
                   parameters={
                       'voice': 'Agnes',
                       'cache': True
                   })
        settings_object.ttss = [tts1, tts2]
        stt = Stt(name="google", parameters={'language': 'fr-FR'})
        settings_object.stts = [stt]
        settings_object.random_wake_up_answers = ['Oui monsieur?']
        settings_object.random_wake_up_sounds = [
            'sounds/ding.wav', 'sounds/dong.wav'
        ]
        settings_object.play_on_ready_notification = "never"
        settings_object.on_ready_answers = ['Kalliope is ready']
        settings_object.on_ready_sounds = [
            'sounds/ding.wav', 'sounds/dong.wav'
        ]
        trigger1 = Trigger(
            name="snowboy",
            parameters={
                'pmdl_file':
                'trigger/snowboy/resources/kalliope-FR-6samples.pmdl'
            })
        settings_object.triggers = [trigger1]
        settings_object.rest_api = RestAPI(password_protected=True,
                                           active=True,
                                           login="******",
                                           password="******",
                                           port=5000,
                                           allowed_cors_origin=False)
        settings_object.cache_path = '/tmp/kalliope_tts_cache'
        settings_object.default_synapse = 'Default-synapse'
        resources = Resources(
            neuron_folder="/tmp/kalliope/tests/kalliope_resources_dir/neurons",
            stt_folder="/tmp/kalliope/tests/kalliope_resources_dir/stt",
            tts_folder="/tmp/kalliope/tests/kalliope_resources_dir/tts",
            trigger_folder="/tmp/kalliope/tests/kalliope_resources_dir/trigger"
        )
        settings_object.resources = resources
        settings_object.variables = {
            "author": "Lamonf",
            "test_number": 60,
            "test": "kalliope"
        }
        settings_object.machine = platform.machine()

        sl = SettingLoader(file_path=self.settings_file_to_test)

        self.assertEqual(settings_object, sl.settings)
Beispiel #3
0
    def test_RestAPI(self):

        rest_api1 = RestAPI(password_protected=True,
                            login="******",
                            password="******",
                            active=True,
                            port=5000,
                            allowed_cors_origin="*")

        rest_api2 = RestAPI(password_protected=False,
                            active=False,
                            port=5000,
                            allowed_cors_origin=None)

        rest_api3 = RestAPI(password_protected=True,
                            login="******",
                            password="******",
                            active=True,
                            port=5000,
                            allowed_cors_origin="*")

        expected_result_serialize = {
            'password_protected': True,
            'port': 5000,
            'active': True,
            'allowed_cors_origin': '*',
            'password': '******',
            'login': '******'
        }

        self.assertDictEqual(expected_result_serialize, rest_api1.serialize())

        self.assertTrue(rest_api1.__eq__(rest_api3))
        self.assertFalse(rest_api1.__eq__(rest_api2))
    def test_get_rest_api(self):
        expected_rest_api = RestAPI(password_protected=True,
                                    active=True,
                                    login="******",
                                    password="******",
                                    port=5000)

        sl = SettingLoader.Instance(file_path=self.settings_file_to_test)
        self.assertEqual(expected_rest_api,
                         sl._get_rest_api(self.settings_dict))
        del sl
Beispiel #5
0
    def test_get_settings(self):
        settings_object = Settings()
        settings_object.default_tts_name = "pico2wave"
        settings_object.default_stt_name = "google"
        settings_object.default_trigger_name = "snowboy"
        settings_object.default_player_name = "mplayer"
        tts1 = Tts(name="pico2wave",
                   parameters={
                       'cache': True,
                       'language': 'fr-FR'
                   })
        tts2 = Tts(name="voxygen",
                   parameters={
                       'voice': 'Agnes',
                       'cache': True
                   })
        settings_object.ttss = [tts1, tts2]
        stt = Stt(name="google", parameters={'language': 'fr-FR'})
        settings_object.stts = [stt]
        trigger1 = Trigger(
            name="snowboy",
            parameters={
                'pmdl_file':
                'trigger/snowboy/resources/kalliope-FR-6samples.pmdl'
            })
        settings_object.triggers = [trigger1]
        player1 = Player(name="mplayer", parameters={})
        player2 = Player(name="pyalsaaudio", parameters={"device": "default"})
        settings_object.players = [player1, player2]
        settings_object.rest_api = RestAPI(password_protected=True,
                                           active=True,
                                           login="******",
                                           password="******",
                                           port=5000,
                                           allowed_cors_origin=False)
        settings_object.cache_path = '/tmp/kalliope_tts_cache'
        resources = Resources(
            neuron_folder="/tmp/kalliope/tests/kalliope_resources_dir/neurons",
            stt_folder="/tmp/kalliope/tests/kalliope_resources_dir/stt",
            tts_folder="/tmp/kalliope/tests/kalliope_resources_dir/tts",
            trigger_folder="/tmp/kalliope/tests/kalliope_resources_dir/trigger"
        )
        settings_object.resources = resources
        settings_object.variables = {
            "author": "Lamonf",
            "test_number": 60,
            "test": "kalliope"
        }
        settings_object.start_options = {"muted": True}
        settings_object.machine = platform.machine()
        settings_object.recognition_options = RecognitionOptions()
        settings_object.hooks = {
            'on_waiting_for_trigger': 'test',
            'on_stop_listening': None,
            'on_start_listening': None,
            'on_order_found': None,
            'on_start': ['on-start-synapse', 'bring-led-on'],
            'on_unmute': [],
            'on_triggered': ['on-triggered-synapse'],
            'on_mute': [],
            'on_order_not_found': ['order-not-found-synapse'],
            'on_start_speaking': None,
            'on_stop_speaking': None,
        }

        sl = SettingLoader(file_path=self.settings_file_to_test)

        self.assertEqual(settings_object, sl.settings)
Beispiel #6
0
    def _get_rest_api(settings):
        """
        Return the settings of the RestApi

        :param settings: The YAML settings file
        :type settings: dict
        :return: the RestApi object
        :rtype: RestApi

        :Example:

            rest_api = cls._get_rest_api(settings)

        .. seealso:: RestApi
        .. raises:: SettingNotFound, NullSettingException, SettingInvalidException
        .. warnings:: Class Method and Private
        """

        try:
            rest_api = settings["rest_api"]
        except KeyError as e:
            raise SettingNotFound("%s setting not found" % e)

        if rest_api is not None:
            try:
                password_protected = rest_api["password_protected"]
                if password_protected is None:
                    raise NullSettingException(
                        "password_protected setting cannot be null")
                login = rest_api["login"]
                password = rest_api["password"]
                if password_protected:
                    if login is None:
                        raise NullSettingException(
                            "login setting cannot be null if password_protected is True"
                        )
                    if password is None:
                        raise NullSettingException(
                            "password setting cannot be null if password_protected is True"
                        )
                active = rest_api["active"]
                if active is None:
                    raise NullSettingException("active setting cannot be null")
                port = rest_api["port"]
                if port is None:
                    raise NullSettingException("port setting cannot be null")
                # check that the port in an integer
                try:
                    port = int(port)
                except ValueError:
                    raise SettingInvalidException("port must be an integer")
                # check the port is a valid port number
                if not 1024 <= port <= 65535:
                    raise SettingInvalidException(
                        "port must be in range 1024-65535")

                # check the CORS request settings
                allowed_cors_origin = False
                if "allowed_cors_origin" in rest_api:
                    allowed_cors_origin = rest_api["allowed_cors_origin"]

            except KeyError as e:
                raise SettingNotFound("%s settings not found" % e)

            # config ok, we can return the rest api object
            rest_api_obj = RestAPI(password_protected=password_protected,
                                   login=login,
                                   password=password,
                                   active=active,
                                   port=port,
                                   allowed_cors_origin=allowed_cors_origin)
            return rest_api_obj
        else:
            raise NullSettingException("rest_api settings cannot be null")
Beispiel #7
0
                    raise SettingInvalidException(
                        "port must be in range 1024-65535")

                # check the CORS request settings
                allowed_cors_origin = False
                if "allowed_cors_origin" in rest_api:
                    allowed_cors_origin = rest_api["allowed_cors_origin"]

            except KeyError, e:
                # print e
                raise SettingNotFound("%s settings not found" % e)

            # config ok, we can return the rest api object
            rest_api_obj = RestAPI(password_protected=password_protected,
                                   login=login,
                                   password=password,
                                   active=active,
                                   port=port,
                                   allowed_cors_origin=allowed_cors_origin)
            return rest_api_obj
        else:
            raise NullSettingException("rest_api settings cannot be null")

    @staticmethod
    def _get_cache_path(settings):
        """
        Return the path where to store the cache

        :param settings: The YAML settings file
        :type settings: dict
        :return: the path to store the cache
        :rtype: String
Beispiel #8
0
    def test_Settings(self):
        with mock.patch('platform.machine', return_value='pumpkins'):
            rest_api1 = RestAPI(password_protected=True,
                                login="******",
                                password="******",
                                active=True,
                                port=5000,
                                allowed_cors_origin="*")

            recognition_options = RecognitionOptions()

            setting1 = Settings(default_tts_name="pico2wav",
                                default_stt_name="google",
                                default_trigger_name="swoyboy",
                                default_player_name="mplayer",
                                ttss=["ttts"],
                                stts=["stts"],
                                random_wake_up_answers=["yes"],
                                random_wake_up_sounds=None,
                                play_on_ready_notification=False,
                                on_ready_answers=None,
                                on_ready_sounds=None,
                                triggers=["snowboy"],
                                players=["mplayer"],
                                rest_api=rest_api1,
                                cache_path="/tmp/kalliope",
                                default_synapse="default_synapse",
                                resources=None,
                                variables={"key1": "val1"},
                                recognition_options=recognition_options)
            setting1.kalliope_version = "0.4.5"

            setting2 = Settings(default_tts_name="accapela",
                                default_stt_name="bing",
                                default_trigger_name="swoyboy",
                                default_player_name="mplayer",
                                ttss=["ttts"],
                                stts=["stts"],
                                random_wake_up_answers=["no"],
                                random_wake_up_sounds=None,
                                play_on_ready_notification=False,
                                on_ready_answers=None,
                                on_ready_sounds=None,
                                triggers=["snowboy"],
                                rest_api=rest_api1,
                                cache_path="/tmp/kalliope_tmp",
                                default_synapse="my_default_synapse",
                                resources=None,
                                variables={"key1": "val1"},
                                recognition_options=recognition_options)
            setting2.kalliope_version = "0.4.5"

            setting3 = Settings(default_tts_name="pico2wav",
                                default_stt_name="google",
                                default_trigger_name="swoyboy",
                                default_player_name="mplayer",
                                ttss=["ttts"],
                                stts=["stts"],
                                random_wake_up_answers=["yes"],
                                random_wake_up_sounds=None,
                                play_on_ready_notification=False,
                                on_ready_answers=None,
                                on_ready_sounds=None,
                                triggers=["snowboy"],
                                players=["mplayer"],
                                rest_api=rest_api1,
                                cache_path="/tmp/kalliope",
                                default_synapse="default_synapse",
                                resources=None,
                                variables={"key1": "val1"},
                                recognition_options=recognition_options)
            setting3.kalliope_version = "0.4.5"

            expected_result_serialize = {
                'default_synapse': 'default_synapse',
                'default_tts_name': 'pico2wav',
                'rest_api': {
                    'password_protected': True,
                    'port': 5000,
                    'active': True,
                    'allowed_cors_origin': '*',
                    'password': '******',
                    'login': '******'
                },
                'play_on_ready_notification': False,
                'default_stt_name': 'google',
                'kalliope_version': '0.4.5',
                'random_wake_up_sounds': None,
                'on_ready_answers': None,
                'default_trigger_name': 'swoyboy',
                'default_player_name': 'mplayer',
                'cache_path': '/tmp/kalliope',
                'stts': ['stts'],
                'machine': 'pumpkins',
                'random_wake_up_answers': ['yes'],
                'on_ready_sounds': None,
                'ttss': ['ttts'],
                'variables': {
                    'key1': 'val1'
                },
                'resources': None,
                'triggers': ['snowboy'],
                'rpi_settings': None,
                'players': ['mplayer'],
                'recognition_options': {
                    'energy_threshold': 4000,
                    'adjust_for_ambient_noise_second': 0
                }
            }

            self.assertDictEqual(expected_result_serialize,
                                 setting1.serialize())

            self.assertTrue(setting1.__eq__(setting3))
            self.assertFalse(setting1.__eq__(setting2))
                    port = int(port)
                except ValueError:
                    raise SettingInvalidException("port must be an integer")
                # check the port is a valid port number
                if not 1024 <= port <= 65535:
                    raise SettingInvalidException(
                        "port must be in range 1024-65535")

            except KeyError, e:
                # print e
                raise SettingNotFound("%s settings not found" % e)

            # config ok, we can return the rest api object
            rest_api_obj = RestAPI(password_protected=password_protected,
                                   login=login,
                                   password=password,
                                   active=active,
                                   port=port)
            return rest_api_obj
        else:
            raise NullSettingException("rest_api settings cannot be null")

    @staticmethod
    def _get_cache_path(settings):
        """
        Return the path where to store the cache

        :param settings: The YAML settings file
        :type settings: dict
        :return: the path to store the cache
        :rtype: String