Exemplo n.º 1
0
    def test_with_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
            openchatbots:
                protocols: http, https
                domains: org, co.uk
                chatbot1:
                    url: https://11.11.11.11/api/rest/v2.0/ask
                    method: GET
                chatbot2:
                    url: https://22.22.22.22/api/rest/v2.0/ask
                    method: GET
                chatbot3:
                    url: https://33.33.33.33/api/rest/v2.0/ask
                    method: POST
                    authorisation_type: Basic
                    authorisation_token: 1234567890
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        openchatbots_config = BrainOpenChatBotsConfiguration()
        openchatbots_config.load_config_section(yaml, brain_config, ".")

        self.assertEquals(openchatbots_config.protocols, ['http', 'https'])
        self.assertEquals(openchatbots_config.domains, ['org', 'co.uk'])

        self.assertTrue(openchatbots_config.exists("chatbot1"))
        self.assertTrue(openchatbots_config.exists("chatbot2"))
        self.assertTrue(openchatbots_config.exists("chatbot3"))
        self.assertFalse(openchatbots_config.exists("chatbot4"))
Exemplo n.º 2
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"])
Exemplo n.º 3
0
    def test_construction_with_create_query_url(self):
        config = BrainOpenChatBotsConfiguration()
        handler = OpenChatBotDomainHandler(config)
        self.assertIsNotNone(handler)

        self.assertEquals("https://website1.com/.well-known/openchatbot-configuration", handler._create_query_url("website1", "https", "com"))
        self.assertEquals("http://website1.com/.well-known/openchatbot-configuration", handler._create_query_url("website1", "http", "com"))

        self.assertEquals("https://website1.org/.well-known/openchatbot-configuration", handler._create_query_url("website1", "https", ext="org"))
        self.assertEquals("http://website1.org/.well-known/openchatbot-configuration", handler._create_query_url("website1", "http", ext="org"))
Exemplo n.º 4
0
 def to_yaml(self, data, defaults=True):
     self.config_to_yaml(data, BrainOverridesConfiguration(), defaults)
     self.config_to_yaml(data, BrainDefaultsConfiguration(), defaults)
     self.config_to_yaml(data, BrainBinariesConfiguration(), defaults)
     self.config_to_yaml(data, BrainBraintreeConfiguration(), defaults)
     self.config_to_yaml(data, BrainServicesConfiguration(), defaults)
     self.config_to_yaml(data, BrainOpenChatBotsConfiguration(), defaults)
     self.config_to_yaml(data, BrainSecuritiesConfiguration(), defaults)
     self.config_to_yaml(data, BrainDynamicsConfiguration(), defaults)
     self.config_to_yaml(data, BrainTokenizerConfiguration(), defaults)
     self.config_to_yaml(data, BrainDebugFilesConfiguration(), defaults)
Exemplo n.º 5
0
    def test_construction_with_scan_alternatives_org(self):

        mock_requests = MockHTTPRequests(response="""{
                       "openchatbot": {
                           "endpoint": "api/mybot/v1.0/ask",
                           "host": "https://website1.com",
                           "port": 80,
                           "methods": ["GET", "POST"]
                       }
                    }""",
                    valid_domain=".org")

        config = BrainOpenChatBotsConfiguration()
        config._domains = ['org']
        handler = OpenChatBotDomainHandler(config, http_requests=mock_requests)
        self.assertIsNotNone(handler)

        domaincb = handler.get_endpoint("website1")
        self.assertIsNotNone(domaincb)

        self.assertEquals("https://website1.com:80/api/mybot/v1.0/ask", domaincb.url)
Exemplo n.º 6
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        brain:
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        openchatbots_config = BrainOpenChatBotsConfiguration()
        openchatbots_config.load_config_section(yaml, brain_config, ".")

        self.assertEquals(openchatbots_config.protocols, ['http'])
        self.assertEquals(openchatbots_config.domains, [])

        self.assertFalse(openchatbots_config.exists("REST"))
        self.assertFalse(openchatbots_config.exists("Pannous"))
        self.assertFalse(openchatbots_config.exists("Pandora"))
        self.assertFalse(openchatbots_config.exists("Wikipedia"))
        self.assertFalse(openchatbots_config.exists("Other"))
Exemplo n.º 7
0
class BrainConfiguration(BaseContainerConfigurationData):
    def __init__(self, section_name="brain"):
        self._overrides = BrainOverridesConfiguration()
        self._defaults = BrainDefaultsConfiguration()
        self._binaries = BrainBinariesConfiguration()
        self._braintree = BrainBraintreeConfiguration()
        self._services = BrainServicesConfiguration()
        self._openchatbots = BrainOpenChatBotsConfiguration()
        self._security = BrainSecuritiesConfiguration()
        self._dynamics = BrainDynamicsConfiguration()
        self._tokenizer = BrainTokenizerConfiguration()
        self._debugfiles = BrainDebugFilesConfiguration()
        BaseContainerConfigurationData.__init__(self, section_name)

    @property
    def overrides(self):
        return self._overrides

    @property
    def defaults(self):
        return self._defaults

    @property
    def binaries(self):
        return self._binaries

    @property
    def braintree(self):
        return self._braintree

    @property
    def services(self):
        return self._services

    @property
    def openchatbots(self):
        return self._openchatbots

    @property
    def security(self):
        return self._security

    @property
    def dynamics(self):
        return self._dynamics

    @property
    def tokenizer(self):
        return self._tokenizer

    @property
    def debugfiles(self):
        return self._debugfiles

    def check_for_license_keys(self, license_keys):
        self._overrides.check_for_license_keys(license_keys)
        self._defaults.check_for_license_keys(license_keys)
        self._binaries.check_for_license_keys(license_keys)
        self._braintree.check_for_license_keys(license_keys)
        self._services.check_for_license_keys(license_keys)
        self._openchatbots.check_for_license_keys(license_keys)
        self._security.check_for_license_keys(license_keys)
        self._dynamics.check_for_license_keys(license_keys)
        self._tokenizer.check_for_license_keys(license_keys)
        self._debugfiles.check_for_license_keys(license_keys)
        BaseContainerConfigurationData.check_for_license_keys(
            self, license_keys)

    def load_configuration(self,
                           configuration_file,
                           brain_config,
                           bot_root,
                           subs: Substitutions = None):
        if brain_config is not None:
            self._overrides.load_config_section(configuration_file,
                                                brain_config,
                                                bot_root,
                                                subs=subs)
            self._defaults.load_config_section(configuration_file,
                                               brain_config,
                                               bot_root,
                                               subs=subs)
            self._binaries.load_config_section(configuration_file,
                                               brain_config,
                                               bot_root,
                                               subs=subs)
            self._braintree.load_config_section(configuration_file,
                                                brain_config,
                                                bot_root,
                                                subs=subs)
            self._services.load_config_section(configuration_file,
                                               brain_config,
                                               bot_root,
                                               subs=subs)
            self._openchatbots.load_config_section(configuration_file,
                                                   brain_config,
                                                   bot_root,
                                                   subs=subs)
            self._security.load_config_section(configuration_file,
                                               brain_config,
                                               bot_root,
                                               subs=subs)
            self._dynamics.load_config_section(configuration_file,
                                               brain_config,
                                               bot_root,
                                               subs=subs)
            self._tokenizer.load_config_section(configuration_file,
                                                brain_config,
                                                bot_root,
                                                subs=subs)
            self._debugfiles.load_config_section(configuration_file,
                                                 brain_config,
                                                 bot_root,
                                                 subs=subs)

    def to_yaml(self, data, defaults=True):
        self.config_to_yaml(data, BrainOverridesConfiguration(), defaults)
        self.config_to_yaml(data, BrainDefaultsConfiguration(), defaults)
        self.config_to_yaml(data, BrainBinariesConfiguration(), defaults)
        self.config_to_yaml(data, BrainBraintreeConfiguration(), defaults)
        self.config_to_yaml(data, BrainServicesConfiguration(), defaults)
        self.config_to_yaml(data, BrainOpenChatBotsConfiguration(), defaults)
        self.config_to_yaml(data, BrainSecuritiesConfiguration(), defaults)
        self.config_to_yaml(data, BrainDynamicsConfiguration(), defaults)
        self.config_to_yaml(data, BrainTokenizerConfiguration(), defaults)
        self.config_to_yaml(data, BrainDebugFilesConfiguration(), defaults)
Exemplo n.º 8
0
    def test_defaults(self):
        openchatbots_config = BrainOpenChatBotsConfiguration()
        data = {}
        openchatbots_config.to_yaml(data, True)

        BrainOpenChatBotsConfigurationTests.assert_defaults(self, data)