def test_ask_question_empty_output(self): with self.assertRaises(Exception) as raised: request_api = MockRequestsAPI() pannous_api = PannousAPI(request_api=request_api) request_api._response = json.loads(""" { "output": [] } """) pannous_api.ask_question("http://testurl", "Hello", "testid") self.assertEqual( raised.exception.args[0], "'output' section has no elements in pannous json_data") with self.assertRaises(Exception) as raised: request_api = MockRequestsAPI() pannous_api = PannousAPI(request_api=request_api) request_api._response = json.loads(""" { "output": null } """) pannous_api.ask_question("http://testurl", "Hello", "testid") self.assertEqual( raised.exception.args[0], "'output' section has no elements in pannous json_data")
def test_ask_question_valid_xml(self): request_api = MockRequestsAPI() pandora_api = PandoraAPI(request_api=request_api) request_api._response = """ <response> <that>Hello</that> </response> """ response = pandora_api.ask_question("http://testurl", "Hello", "testid") self.assertEquals(response, "Hello")
def test_ask_question_valid_xml(self): request_api = MockRequestsAPI() pandora_api = PandoraAPI(request_api=request_api) request_api._response = """ <response> <that>Hello</that> </response> """ response = pandora_api.ask_question("http://testurl", "Hello", "testid") self.assertEquals(response, "Hello")
def test_ask_question_no_that(self): request_api = MockRequestsAPI() pandora_api = PandoraAPI(request_api=request_api) request_api._response = """ <response> </response> """ with self.assertRaises(Exception) as raised: response = pandora_api.ask_question("http://testurl", "Hello", "testid") self.assertEqual(raised.exception.args[0], "Invalid response from pandora service, no <that> element in xml")
def test_ask_question_valid_json(self): request_api = MockRequestsAPI() pannous_api = PannousAPI(request_api=request_api) request_api._response = json.loads(""" { "output": [ { "actions": { "say": {"text": "Hello"} } } ] } """) response = pannous_api.ask_question("http://testurl", "Hello", "testid") self.assertEquals(response, "Hello")
def test_ask_question_missing_actions(self): with self.assertRaises(Exception) as raised: request_api = MockRequestsAPI() pannous_api = PannousAPI(request_api=request_api) request_api._response = json.loads(""" { "output": [ { "items": { "say": {"response": "Hello"} } } ] } """) response = pannous_api.ask_question("http://testurl", "Hello", "testid") self.assertEqual(raised.exception.args[0], "'actions' section in output[0] in pannous json_data")
def test_ask_question_no_that(self): request_api = MockRequestsAPI() pandora_api = PandoraAPI(request_api=request_api) request_api._response = """ <response> </response> """ with self.assertRaises(Exception) as raised: response = pandora_api.ask_question("http://testurl", "Hello", "testid") self.assertEqual( raised.exception.args[0], "Invalid response from pandora service, no <that> element in xml")