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")
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)
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)
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)
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)
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"))
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)
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"))
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)
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)
def test_ask_question_no_license_key(self): self._client_context.client.license_keys._keys.clear() 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("", response)
def test_ask_question_no_url(self): config = BrainServiceConfiguration("pandora") with self.assertRaises(Exception) as raised: 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("", response) self.assertEqual(raised.exception.args[0], "Undefined url parameter")
def test_init_with_no_url(self): config = BrainServiceConfiguration("pannous") config._url = None with self.assertRaises(Exception): service = DuckDuckGoService(config=config)
def test_ask_no_host(self): config = BrainServiceConfiguration("rest") with self.assertRaises(Exception): service = GenericRESTService(config=config)