예제 #1
0
    def test_ask_default_method(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"

        service = GenericRESTService(config=config)
        self.assertIsNotNone(service)
        self.assertEquals(service.method, "GET")
예제 #2
0
    def test_init_default_api(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"
        config._method = "GET"

        service = GenericRESTService(config=config)
        self.assertIsNotNone(service)
        self.assertIsInstance(service.api, RestAPI)
예제 #3
0
    def test_init_default_api(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"
        config._method = "GET"

        service = GenericRESTService(config=config)
        self.assertIsNotNone(service)
        self.assertIsInstance(service.api, RestAPI)
예제 #4
0
    def test_init_with_no_request_api(self):
        config = BrainServiceConfiguration("pannous")
        config._url = "http://test.pandora.url"

        service = DuckDuckGoService(config=config)

        self.assertIsNotNone(service)
        self.assertIsInstance(service._api, DuckDuckGoAPI)
예제 #5
0
    def test_init_with_no_request_api(self):
        config = BrainServiceConfiguration("pannous")
        config._url = "http://test.pandora.url"

        service = DuckDuckGoService(config=config)

        self.assertIsNotNone(service)
        self.assertIsInstance(service._api, DuckDuckGoAPI)
예제 #6
0
    def test_ask_question_delete(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"
        config._method = "DELETE"

        service = GenericRESTService(config=config, api=MockRestAPI())
        self.assertIsNotNone(service)

        self.assertEquals("", service.ask_question(self._client_context, "what is a cat"))
예제 #7
0
    def test_ask_question_error(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"
        config._method = "GET"

        service = GenericRESTService(config=config, api=MockRestAPI(500, "Bad thing happened!"))
        self.assertIsNotNone(service)

        self.assertEquals("", service.ask_question(self._client_context, "what is a cat"))
예제 #8
0
    def test_ask_question_general_exception(self):
        config = BrainServiceConfiguration("pannous")
        config._url = "http://test.pandora.url"

        service = DuckDuckGoService(config=config, api=MockDuckDuckGoAPI(response=None, throw_exception=True))
        self.assertIsNotNone(service)

        response = service.ask_question(self._client_context, "what is a cat")
        self.assertEqual("", response)
예제 #9
0
    def test_ask_question_general_exception(self):
        config = BrainServiceConfiguration("pannous")
        config._url = "http://test.pandora.url"

        service = DuckDuckGoService(config=config, api=MockDuckDuckGoAPI(response=None, throw_exception=True))
        self.assertIsNotNone(service)

        response = service.ask_question(self._client_context, "what is a cat")
        self.assertEquals("", response)
예제 #10
0
    def test_ask_question_delete(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"
        config._method = "DELETE"

        service = GenericRESTService(config=config, api=MockRestAPI())
        self.assertIsNotNone(service)

        self.assertEquals("", service.ask_question(self.bot, "testid", "what is a cat"))
예제 #11
0
    def test_ask_question_error(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"
        config._method = "GET"

        service = GenericRESTService(config=config, api=MockRestAPI(500, "Bad thing happened!"))
        self.assertIsNotNone(service)

        self.assertEquals("", service.ask_question(self.bot, "testid", "what is a cat"))
예제 #12
0
    def test_ask_question_post(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"
        config._method = "POST"

        service = GenericRESTService(config=config, api=MockRestAPI(200, "Post REST response"))
        self.assertIsNotNone(service)

        response = service.ask_question(self._client_context, "what is a cat")
        self.assertEquals("Post REST response", response)
예제 #13
0
    def test_ask_question_post(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"
        config._method = "POST"

        service = GenericRESTService(config=config, api=MockRestAPI(200, "Post REST response"))
        self.assertIsNotNone(service)

        response = service.ask_question(self.bot, "testid", "what is a cat")
        self.assertEquals("Post REST response", response)
예제 #14
0
    def test_ask_question_with_exception(self):

        config = BrainServiceConfiguration("pandora")
        config._url = "http://test.pandora.url"

        service = PandoraService(config=config, api=MockPandoraAPI(response="Some wierd error", throw_exception=True))
        self.assertIsNotNone(service)

        response = service.ask_question(self._client_context, "what is a cat")
        self.assertEquals("", response)
예제 #15
0
    def test_ask_question_summary(self):
        config = BrainServiceConfiguration("pannous")
        config._url = "http://api.duckduckgo.com"

        service = DuckDuckGoService(config=config)
        self.assertIsNotNone(service)

        response = service.ask_question(self.bot, "testid", "cat")
        self.assertIsNotNone(response)
        self.assertEqual("Cat A small, typically furry, carnivorous mammal", response)
예제 #16
0
    def test_ask_question_with_exception(self):

        config = BrainServiceConfiguration("pannous")
        config._url = "http://test.pandora.url"

        service = PannousService(config=config, api=MockPannousAPI(response="Some wierd error", throw_exception=True))
        self.assertIsNotNone(service)

        response = service.ask_question(self._client_context, "what is a cat")
        self.assertEquals("", response)
예제 #17
0
    def test_ask_question(self):

        config = BrainServiceConfiguration("pandora")
        config._url = "http://test.pandora.url"

        service = PandoraService(config=config, api=MockPandoraAPI(response="Test pandora response"))
        self.assertIsNotNone(service)

        response = service.ask_question(self._client_context, "what is a cat")
        self.assertEquals("Test pandora response", response)
예제 #18
0
    def test_ask_question(self):

        config = BrainServiceConfiguration("pannous")
        config._url = "http://test.pandora.url"

        service = PannousService(config=config, api=MockPannousAPI(response="Test pannous response"))
        self.assertIsNotNone(service)

        response = service.ask_question(self._client_context, "what is a cat")
        self.assertEquals("Test pannous response", response)
예제 #19
0
    def test_ask_question_get(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"
        config._method = "GET"

        service = GenericRESTService(config=config, api=MockRestAPI(200, "Test REST response"))
        self.assertIsNotNone(service)

        response = service.ask_question(self._client_context, "what is a cat")
        self.assertEqual("Test REST response", response)
예제 #20
0
    def test_ask_question_summary(self):
        config = BrainServiceConfiguration("pannous")
        config._url = "http://api.duckduckgo.com"

        service = DuckDuckGoService(config=config)
        self.assertIsNotNone(service)

        response = service.ask_question(self.bot, "testid", "cat")
        self.assertIsNotNone(response)
        self.assertEqual("Cat A small, typically furry, carnivorous mammal",
                         response)
예제 #21
0
    def test_ask_question(self):

        config = BrainServiceConfiguration("pandora")
        config._url = "http://test.pandora.url"

        service = PandoraService(
            config=config,
            api=MockPandoraAPI(response="Test pandora response"))
        self.assertIsNotNone(service)

        response = service.ask_question(self.bot, "testid", "what is a cat")
        self.assertEquals("Test pandora response", response)
예제 #22
0
    def test_ask_question_no_license_key(self):

        self.bot = TestBot()
        self.bot.license_keys = LicenseKeys()

        config = BrainServiceConfiguration("pannous")
        config._url = "http://test.pandora.url"

        service = PannousService(config=config, api=MockPannousAPI(response="Test pannous response"))
        self.assertIsNotNone(service)

        response = service.ask_question(self.bot, "testid", "what is a cat")
        self.assertEquals("", response)
    def test_ask_question_none_setting(self):

        config = BrainServiceConfiguration("__PUBLISHEDBOT__")
        config._host = "test_publishdbot"

        response_data = '{"response": "Hello"}'
        request_api = MockPublishedBotAPI(response=response_data)
        service = PublishedBotService(config=config, api=request_api)
        self.assertIsNotNone(service)

        question = "Hello"
        response = service.ask_question(self._client_context, question)
        self.assertEqual('', response)
        self.assertEqual('', service._status_code)
예제 #24
0
    def test_ask_question_no_botid(self):

        self._client_context.client.license_keys._keys.clear()

        config = BrainServiceConfiguration("pandora")
        config._url = "http://test.pandora.url"

        service = PandoraService(
            config=config,
            api=MockPandoraAPI(response="Test pandora response"))
        self.assertIsNotNone(service)

        response = service.ask_question(self._client_context, "what is a cat")
        self.assertEqual("", response)
    def test_ask_question_default_host(self):

        config = BrainServiceConfiguration("__PUBLISHEDBOT__")

        self._client_context.bot.brain.configuration._bot_name = "RequestBot"
        self._client_context.bot.brain.configuration._manager_name = "Bot_API_key"

        response_data = '{"response": "Hello"}'
        request_api = MockPublishedBotAPI(response=response_data)
        service = PublishedBotService(config=config, api=request_api)
        self.assertIsNotNone(service)

        service.botId = "PublishedBot"
        service.botHost = None
        service.locale = None
        service.time = None
        service.userId = None
        service.topic = None
        service.deleteVariable = None
        service.metadata = None
        service.config = None

        question = "Hello"
        response = service.ask_question(self._client_context, question)
        self.assertEqual('{"response": "Hello"}', response)
    def test_ask_question_no_parameter(self):

        config = BrainServiceConfiguration("__PUBLISHEDBOT__")
        config._host = "test_publishdbot"

        self._client_context.bot.brain.configuration._bot_name = "RequestBot"
        self._client_context.bot.brain.configuration._manager_name = "Bot_API_key"

        response_data = '{"response": "Hello"}'
        request_api = MockPublishedBotAPI(response=response_data)
        service = PublishedBotService(config=config, api=request_api)
        self.assertIsNotNone(service)

        question = "Hello"
        response = service.ask_question(self._client_context, question)
        self.assertEqual('', response)
    def test_ask_question_no_parameter(self):

        config = BrainServiceConfiguration("__PUBLISHEDBOT__")
        config._host = "test_publishdbot"

        response_data = '{"response": "Hello"}'
        request_api = MockPublishedBotAPI(response=response_data)
        service = PublishedBotService(config=config, api=request_api)
        self.assertIsNotNone(service)

        bot_info = PublicBotInfo("https://cotobadesign.co.jp/bots/PublishedBot/ask", 'api_key')

        service.botInfo = bot_info
        service.userId = "user00"

        question = "Hello"
        response = service.ask_question(self._client_context, question)
        self.assertEqual('{"response": "Hello"}', response)
        self.assertEqual('200', service._status_code)
예제 #28
0
    def test_ask_question_no_url(self):

        config = BrainServiceConfiguration("pannous")

        with self.assertRaises(Exception) as raised:
            service = PannousService(config=config, api=MockPannousAPI(response="Test pannous response"))
            self.assertIsNotNone(service)

            response = service.ask_question(self._client_context, "what is a cat")
            self.assertEquals("", response)

        self.assertEqual(raised.exception.args[0], "Undefined url parameter")
 def setUp(self):
     client = TestClient()
     self._client_context = client.create_client_context("testid")
     self._config = BrainServiceConfiguration("__PUBLISHEDBOT__")
예제 #30
0
    def test_ask_no_host(self):
        config = BrainServiceConfiguration("rest")

        with self.assertRaises(Exception):
            service = GenericRESTService(config=config)
예제 #31
0
    def test_init_with_no_url(self):
        config = BrainServiceConfiguration("pannous")
        config._url = None

        with self.assertRaises(Exception):
            service = DuckDuckGoService(config=config)
예제 #32
0
    def test_init_with_no_url(self):
        config = BrainServiceConfiguration("pannous")
        config._url = None

        with self.assertRaises(Exception):
            service = DuckDuckGoService(config=config)