Пример #1
0
    def test_rest_with_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
            openchatbots:
                chatbot1:
                    url: https://99.88.77.66/api/rest/v2.0/ask
                    method: GET
                    authorization: Basic
                    api_key: '11111111'
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")
        self.assertIsNotNone(brain_config)
        openchatbots_config = yaml.get_section("openchatbots", brain_config)
        self.assertIsNotNone(openchatbots_config)

        openchatbot_config = BrainOpenChatBotConfiguration("chatbot1")
        openchatbot_config.load_config_section(yaml, openchatbots_config, ".")

        self.assertEqual("GET", openchatbot_config.method)
        self.assertEqual("https://99.88.77.66/api/rest/v2.0/ask",
                         openchatbot_config.url)
        self.assertEqual("Basic", openchatbot_config.authorization)
        self.assertEqual("11111111", openchatbot_config.api_key)
Пример #2
0
    def load_config_section(self,
                            configuration_file,
                            configuration,
                            bot_root,
                            subs: Substitutions = None):
        openchatbots = configuration_file.get_section(self.section_name,
                                                      configuration)
        if openchatbots is not None:
            openchatbot_keys = configuration_file.get_keys(openchatbots)

            for name in openchatbot_keys:
                if name == 'protocols':
                    self._protocols = configuration_file.get_option(
                        openchatbots,
                        "protocols",
                        missing_value=['http'],
                        subs=subs)
                elif name == 'domains':
                    self._domains = configuration_file.get_option(
                        openchatbots, "domains", missing_value=[], subs=subs)

                else:
                    openchatbot = BrainOpenChatBotConfiguration(name)
                    openchatbot.load_config_section(configuration_file,
                                                    openchatbots,
                                                    bot_root,
                                                    subs=subs)
                    self._openchatbots[name] = openchatbot

        else:
            YLogger.warning(
                self,
                "Config section [openchatbots] missing from Brain, no openchatbots loaded"
            )
Пример #3
0
    def test_to_yaml_with_defaults(self):
        openchatbot_config = BrainOpenChatBotConfiguration("chatbot1")

        data = {}
        openchatbot_config.to_yaml(data, defaults=True)

        self.assertEquals(
            {
                'url': None,
                'method': None,
                'authorization': None,
                'api_key': None
            }, data)
Пример #4
0
    def test_load_from_configuration(self):

        config = BrainOpenChatBotsConfiguration()
        chatbot1_config = BrainOpenChatBotConfiguration('chatbot1')
        chatbot1_config._url = "http://localhost:5959/api/rest/v2.0/ask"
        chatbot1_config._method = ["GET"]
        config._openchatbots["chatbot1"] = chatbot1_config

        collection = OpenChatBotCollection()
        collection.load_from_configuration(config)

        self.assertTrue(collection.exists("chatbot1"))
        chatbot = collection.openchatbot("chatbot1")
        self.assertIsNotNone(chatbot)
        self.assertEqual(chatbot.name, "chatbot1")
        self.assertEqual(chatbot.url, "http://localhost:5959/api/rest/v2.0/ask")
        self.assertEqual(chatbot.methods, ["GET"])
Пример #5
0
    def test_to_yaml_without_defaults(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
            openchatbots:
                chatbot1:
                    url: https://99.88.77.66/api/rest/v2.0/ask
                    method: GET
                    authorization: Basic
                    api_key: '11111111'
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")
        self.assertIsNotNone(brain_config)
        openchatbots_config = yaml.get_section("openchatbots", brain_config)
        self.assertIsNotNone(openchatbots_config)

        openchatbot_config = BrainOpenChatBotConfiguration("chatbot1")
        openchatbot_config.load_config_section(yaml, openchatbots_config, ".")

        data = {}
        openchatbot_config.to_yaml(data, defaults=False)

        self.assertEquals(
            {
                'api_key': '11111111',
                'authorization': 'Basic',
                'method': 'GET',
                'url': 'https://99.88.77.66/api/rest/v2.0/ask'
            }, data)
Пример #6
0
    def test_rest_without_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
            openchatbots:
                chatbot1:
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")
        self.assertIsNotNone(brain_config)
        openchatbots_config = yaml.get_section("openchatbots", brain_config)
        self.assertIsNotNone(openchatbots_config)

        openchatbot_config = BrainOpenChatBotConfiguration("chatbot1")
        openchatbot_config.load_config_section(yaml, openchatbots_config, ".")

        self.assertIsNone(openchatbot_config.url)
        self.assertIsNone(openchatbot_config.method)
        self.assertIsNone(openchatbot_config.authorization)
        self.assertIsNone(openchatbot_config.api_key)
Пример #7
0
    def test_defaults(self):
        openchatbot_config = BrainOpenChatBotConfiguration("chatbot1")
        data = {}
        openchatbot_config.to_yaml(data, True)

        BrainOpenChatBotConfigurationTests.assert_defaults(self, data)