def test_ask_question_missing_say(self): with self.assertRaises(Exception) as raised: request_api = MockRequestsAPI() pannous_api = PannousAPI(request_api=request_api) request_api._response = json.loads(""" { "output": [ { "actions": { "said": {"response": "Hello"} } } ] } """) pannous_api.ask_question("http://testurl", "Hello", "testid") self.assertEqual( raised.exception.args[0], "'say' section missing from output[0]['actions'] in pannous json_data" )
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": [] } """) response = 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 } """) response = pannous_api.ask_question("http://testurl", "Hello", "testid") self.assertEqual( raised.exception.args[0], "'output' section has no elements in pannous json_data")