def test_ask_question_no_parameter(self):

        response_data = 'Hello'
        request_api = MockPublishedRestAPI(response=response_data)
        service = PublishedRestService(config=self._config, api=request_api)
        self.assertIsNotNone(service)

        question = None
        response = service.ask_question(self._client_context, question)
        self.assertEqual('', response)
Ejemplo n.º 2
0
    def test_ask_question_no_charset(self):

        response_data = 'Hello'
        request_api = MockPublishedRestAPI(response=response_data)
        service = PublishedRestService(config=self._config, api=request_api)
        self.assertIsNotNone(service)

        params = RestParameters("http://test.publishdrest.url")
        params.set_method("GET")
        params.set_query('"userid": "test01", "question": "Hello"')
        params.set_header('"Content-type": "application/json"')
        params.set_body('{"json": {"data": "test"}}')
        service.params = params

        question = None
        response = service.ask_question(self._client_context, question)
        self.assertEqual('Hello', response)
Ejemplo n.º 3
0
    def test_ask_question_delete(self):

        response_data = 'Hello'
        request_api = MockPublishedRestAPI(response=response_data)
        service = PublishedRestService(config=self._config, api=request_api)
        self.assertIsNotNone(service)

        params = RestParameters("http://test.publishdrest.url")
        params.set_method("DELETE")
        params.set_query(None)
        params.set_header(None)
        params.set_body("Hello")
        service.params = params

        question = None
        response = service.ask_question(self._client_context, question)
        self.assertEqual('Hello', response)
Ejemplo n.º 4
0
    def test_ask_question_set_parameter(self):

        service = PublishedRestService(config=self._config)
        self.assertIsNotNone(service)

        params = RestParameters("http://test.publishdrest.url")
        params.set_method("GET")
        params.set_query('"userid": "test01", "question": "Hello"')
        params.set_header('"Content-type": "application/json;charset=UTF-8"')
        params.set_body("Hello")
        service.params = params

        self.assertEqual('http://test.publishdrest.url', service.params.host)
        self.assertEqual('GET', service.params.method)
        self.assertEqual({"userid": "test01", "question": "Hello"}, service.params.query)
        self.assertEqual({"Content-type": "application/json;charset=UTF-8"}, service.params.header)
        self.assertEqual('Hello', service.params.body)
Ejemplo n.º 5
0
    def test_ask_question_invlid_method(self):

        response_data = 'Hello'
        request_api = MockPublishedRestAPI(response=response_data)
        service = PublishedRestService(config=self._config, api=request_api)
        self.assertIsNotNone(service)

        params = RestParameters("http://test.publishdrest.url")
        self.assertFalse(params.set_method("INSERT"))
        params.set_query(None)
        params.set_header(None)
        params.set_body("Hello")
        service.params = params

        self.assertEqual('GET', params.method)
        question = None
        response = service.ask_question(self._client_context, question)
        self.assertEqual("Hello", response)
    def test_ask_question_no_charset(self):

        response_data = 'Hello'
        request_api = MockPublishedRestAPI(response=response_data)
        service = PublishedRestService(config=self._config, api=request_api)
        self.assertIsNotNone(service)

        service.host = "http://test.publishdrest.url"
        service.method = "GET"
        service.query = {"userid": "test01", "question": "Hello"}
        service.header = {"Content-type": "application/json"}
        service.body = '{"json": {"data": "test"}}'

        question = None
        response = service.ask_question(self._client_context, question)
        self.assertEqual('Hello', response)
    def test_ask_question_invlid_method(self):

        response_data = 'Hello'
        request_api = MockPublishedRestAPI(response=response_data)
        service = PublishedRestService(config=self._config, api=request_api)
        self.assertIsNotNone(service)

        service.host = "http://test.publishdrest.url"
        service.method = "INSERT"
        service.query = None
        service.header = None
        service.body = "Hello"

        question = None
        response = service.ask_question(self._client_context, question)
        self.assertEqual("", response)
    def test_ask_question_no_host(self):

        response_data = 'Hello'
        request_api = MockPublishedRestAPI(response=response_data)
        service = PublishedRestService(config=self._config, api=request_api)
        self.assertIsNotNone(service)

        service.method = "GET"
        service.query = '"userid": "test01", "question": "Hello"'
        service.header = '"Content-type": "application/json,charset=UTF-8"'
        service.body = None

        question = None
        response = service.ask_question(self._client_context, question)
        self.assertEqual('', response)
    def test_ask_question_set_parameter(self):

        service = PublishedRestService(config=self._config)
        self.assertIsNotNone(service)

        service._host = "http://test.publishdrest.url"
        service._method = "GET"
        service._query = '"userid": "test01", "question": "Hello"'
        service._header = '"Content-type": "application/json;charset=UTF-8"'
        service._body = "Hello"

        self.assertEqual('http://test.publishdrest.url', service.host)
        self.assertEqual('GET', service.method)
        self.assertEqual('"userid": "test01", "question": "Hello"',
                         service.query)
        self.assertEqual('"Content-type": "application/json;charset=UTF-8"',
                         service.header)
        self.assertEqual('Hello', service.body)