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