Example #1
0
    def test_construction_with_create_query_url(self):
        handler = OpenChatBotDomainHandler()
        self.assertIsNotNone(handler)

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

        self.assertEquals("https://website1.org/.well-known/openchatbot-configuration", handler._create_query_url("website1", True, ext="org"))
        self.assertEquals("http://website1.org/.well-known/openchatbot-configuration", handler._create_query_url("website1", False, ext="org"))
Example #2
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"))
Example #3
0
    def load_from_configuration(self,
                                configuration: BrainOpenChatBotsConfiguration):

        names = configuration.openchatbots()
        for name in names:
            openchatbot_config = configuration.openchatbot(name)
            self._openchatbots[name.upper()] = OpenChatBot(
                openchatbot_config.section_name, openchatbot_config.url,
                openchatbot_config.method, openchatbot_config.authorization,
                openchatbot_config.api_key)

        self._domain_handler = OpenChatBotDomainHandler(configuration)

        return True
Example #4
0
class OpenChatBotCollection(object):
    def __init__(self):
        self._openchatbots = {}
        self._domain_handler = None

    def load_from_configuration(self,
                                configuration: BrainOpenChatBotsConfiguration):

        names = configuration.openchatbots()
        for name in names:
            openchatbot_config = configuration.openchatbot(name)
            self._openchatbots[name.upper()] = OpenChatBot(
                openchatbot_config.section_name, openchatbot_config.url,
                openchatbot_config.method, openchatbot_config.authorization,
                openchatbot_config.api_key)

        self._domain_handler = OpenChatBotDomainHandler(configuration)

        return True

    def exists(self, name):
        return bool(name.upper() in self._openchatbots)

    def openchatbot(self, name):
        if self.exists(name):
            return self._openchatbots[name.upper()]

        return self._domain_handler.get_endpoint(name)
Example #5
0
    def test_construction_with_no_scan_alternatives(self):

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

        handler = OpenChatBotDomainHandler(scan_alternatives=False, http_requests=mock_requests)
        self.assertIsNotNone(handler)

        domaincb = handler.get_endpoint("website1", https=False)
        self.assertIsNotNone(domaincb)

        self.assertEquals("https://website1.com:80/api/mybot/v1.0/ask", domaincb.url)
Example #6
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)
Example #7
0
 def test_construction_with_get_protocol(self):
     self.assertEquals("https", OpenChatBotDomainHandler._get_protocol(https=True))
     self.assertEquals("http", OpenChatBotDomainHandler._get_protocol(https=False))