Exemplo n.º 1
0
    def test_ask_question_no_response(self):

        with self.assertRaises(Exception) as raised:
            request_api = MockRequestsAPI(response=None)
            pannous_api = PannousAPI(request_api=request_api)
            response = pannous_api.ask_question("http://testurl", "Hello",
                                                "testid")
        self.assertEqual(raised.exception.args[0],
                         "No response from pannous service")
Exemplo n.º 2
0
    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")
Exemplo n.º 3
0
    def test_ask_question_missing_output(self):

        with self.assertRaises(Exception) as raised:
            request_api = MockRequestsAPI()
            pannous_api = PannousAPI(request_api=request_api)
            request_api._response = json.loads("""
            {
                "result": [
                    { "items": { "say": {"response": "Hello"} } }
                ]
            }
            """)
            response = pannous_api.ask_question("http://testurl", "Hello",
                                                "testid")
        self.assertEqual(raised.exception.args[0],
                         "'output' section missing from pannous json_data")
Exemplo n.º 4
0
    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")