Пример #1
0
    def test_ask_question_post_with_authorization(self):
        client = TestClient()
        client.add_license_keys_store()
        self._client_context = client.create_client_context("testid")

        self._client_context.brain._openchatbots._openchatbots['CHATBOT1'] = OpenChatBot("openchat1",
                                                                                         "http://localhost:5959/api/rest/v2.0/ask",
                                                                                         ["POST"],
                                                                                         "Basic",
                                                                                         "1234567890")

        mock_data = {"response": {
                            "text": "Hi there from chatbot1",
                        },
                        "status": {"code": 200, "text": "success"}
                     }
        mock_response = json.dumps(mock_data)

        service_config = BrainServiceConfiguration("openchatbot")
        service_config._method = 'POST'

        service = OpenChatRESTService(service_config, api=MockRestAPI(200, mock_response))

        response = service.ask_question(self._client_context, "chatbot1 Hello")
        self.assertIsNotNone(response)
        self.assertEqual("Hi there from chatbot1", response)
Пример #2
0
    def test_parse_response(self):
        client = TestClient()
        client_context = client.create_client_context("testid")

        config = BrainServiceConfiguration("rest")
        config._classname = "programy.testclass"
        config._method = "GET"
        config._host = "localhost"
        config._port = 8080
        config._url = "/api/v1.0/ask"

        service = ProgramyRESTService(config, api=None)
        self.assertEqual("Hello", service._parse_response('[{"response": {"answer": "Hello"}}]'))
Пример #3
0
    def test_format_get_url(self):
        client = TestClient()
        client_context = client.create_client_context("testid")

        config = BrainServiceConfiguration("rest")
        config._classname = "programy.testclass"
        config._method = "GET"
        config._host = "localhost"
        config._port = 8080
        config._url = "/api/v1.0/ask"

        service = ProgramyRESTService(config, api=None)
        self.assertEqual("/api/v1.0/ask?question=Hello&userid=testid", service._format_get_url("/api/v1.0/ask", client_context, "Hello"))
Пример #4
0
    def test_parse_response(self):
        client = TestClient()
        client_context = client.create_client_context("testid")

        config = BrainServiceConfiguration("rest")
        config._classname = "programy.testclass"
        config._method = "GET"
        config._host = "localhost"
        config._port = 8080
        config._url = "/api/v1.0/ask"

        service = ProgramyRESTService(config, api=None)
        self.assertEquals("Hello", service._parse_response('[{"response": {"answer": "Hello"}}]'))
Пример #5
0
    def test_format_get_url(self):
        client = TestClient()
        client_context = client.create_client_context("testid")

        config = BrainServiceConfiguration("rest")
        config._classname = "programy.testclass"
        config._method = "GET"
        config._host = "localhost"
        config._port = 8080
        config._url = "/api/v1.0/ask"

        service = ProgramyRESTService(config, api=None)
        self.assertEquals("/api/v1.0/ask?question=Hello&userid=testid", service._format_get_url("/api/v1.0/ask", client_context, "Hello"))
Пример #6
0
    def test_format_payload(self):
        client = TestClient()
        client_context = client.create_client_context("testid")

        config = BrainServiceConfiguration("rest")
        config._classname = "programy.testclass"
        config._method = "GET"
        config._host = "localhost"
        config._port = 8080
        config._url = "/api/v1.0/ask"

        service = ProgramyRESTService(config, api=None)
        self.assertEquals({
            'question': 'Hello',
            'userid': 'testid'
        }, service._format_payload(client_context, "Hello"))