diff --git a/tests/bento_service_examples/example_bento_service.py b/tests/bento_service_examples/example_bento_service.py index bf210fb8164..05ec49c4a24 100644 --- a/tests/bento_service_examples/example_bento_service.py +++ b/tests/bento_service_examples/example_bento_service.py @@ -1,10 +1,5 @@ import bentoml -from bentoml.adapters import ( - DataframeInput, - ImageInput, - JsonInput, - MultiImageInput, -) +from bentoml.adapters import DataframeInput, ImageInput, JsonInput, MultiImageInput from bentoml.handlers import DataframeHandler # deprecated from bentoml.service.artifacts.pickle import PickleArtifact @@ -49,3 +44,9 @@ def predict_multi_images(self, original, compared): @bentoml.api(input=JsonInput(), batch=True) def predict_json(self, input_data): return self.artifacts.model.predict_json(input_data) + + @bentoml.api( + route="v1!@$%^&*()_-+=[]\\|;:,./predict", input=JsonInput(), batch=True, + ) + def customize_route(self, input_data): + return input_data diff --git a/tests/integration/api_server/example_service.py b/tests/integration/api_server/example_service.py index 644a225bc6f..da34f9b6e5d 100644 --- a/tests/integration/api_server/example_service.py +++ b/tests/integration/api_server/example_service.py @@ -81,7 +81,7 @@ def predict_json(self, input_datas): return self.artifacts.model.predict_json(input_datas) @bentoml.api( - route="/$~!@%^&*()_-+=[]\\|;:,./predict_json", input=JsonInput(), batch=True, + route="$~!@%^&*()_-+=[]\\|;:,./predict_json", input=JsonInput(), batch=True, ) def customezed_route(self, input_datas): return input_datas diff --git a/tests/integration/api_server/test_meta.py b/tests/integration/api_server/test_meta.py index 6d9b6590c1b..85962f96b6e 100644 --- a/tests/integration/api_server/test_meta.py +++ b/tests/integration/api_server/test_meta.py @@ -13,6 +13,17 @@ async def test_api_server_meta(host): @pytest.mark.asyncio async def test_customized_route(host): + def path_in_docs(response_body): + d = json.loads(response_body.decode()) + return "/v1!@$%^&*()_-+=[]\\|;:,./predict" in d['paths'] + + await pytest.assert_request( + "GET", + f"http://{host}/docs.json", + headers=(("Content-Type", "application/json"),), + assert_data=path_in_docs, + ) + await pytest.assert_request( "POST", f"http://{host}/$~!@%^&*()_-+=[]\\|;:,./predict_json", diff --git a/tests/server/test_model_api_server.py b/tests/server/test_model_api_server.py index 7b4be2ffecf..ae3e05a7155 100644 --- a/tests/server/test_model_api_server.py +++ b/tests/server/test_model_api_server.py @@ -29,6 +29,12 @@ def test_api_function_route(bento_service, img_file): response = test_client.get("/docs.json") assert 200 == response.status_code + docs = json.loads(response.data.decode()) + assert "/v1!@$%^&*()_-+=[]\\|;:,./predict" in docs["paths"] + + response = test_client.post("/v1!@$%^&*()_-+=[]\\|;:,./predict", data='{"a": 1}',) + assert 200 == response.status_code + assert '{"a": 1}' == str(response.data) assert "predict_dataframe" in index_list data = [{"col1": 10}, {"col1": 20}]