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)
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_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_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)
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)
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)