diff --git a/model_server/api.py b/api.py similarity index 86% rename from model_server/api.py rename to api.py index 47471e3216d9f7cdd8553c827b8d881533ecb225..512083625be5b0d4a1a56539efe5b20108a90d34 100644 --- a/model_server/api.py +++ b/api.py @@ -2,8 +2,8 @@ from pathlib import Path from fastapi import FastAPI, HTTPException -from session import Session -from workflow import infer_image_to_image +from model_server.session import Session +from model_server.workflow import infer_image_to_image app = FastAPI() session = Session() @@ -14,7 +14,7 @@ def startup(): @app.get('/') def read_root(): - return {'test': 'success'} + return {'success': True} @app.get('/models') def list_active_models(): @@ -27,9 +27,6 @@ def load_model(model_id: str, project_file: Path) -> Path: # does API autoencode status_code=409, detail=f'Model with id {model_id} has already been loaded' ) - # model = new_ilastik_shell - # session.models[model_id] = model - pass @app.post('/i2i/infer/{model_id}') # image file in, image file out def infer_img(model_id: str, imgf: str, channel: int = None) -> dict: diff --git a/tests/test_api.py b/tests/test_api.py new file mode 100644 index 0000000000000000000000000000000000000000..2bdd245195e29fd20b8eb923c035fd5776595239 --- /dev/null +++ b/tests/test_api.py @@ -0,0 +1,27 @@ +from multiprocessing import Process +import requests +import unittest +import uvicorn + +class TestApiFromAutomatedClient(unittest.TestCase): + def setUp(self) -> None: + import uvicorn + host = '127.0.0.1' + port = 5000 + + self.server_process = Process( + target=uvicorn.run, + args=('api:app', ), + kwargs={'host': host, 'port': port, 'log_level': 'info'}, + daemon=True + ) + self.uri = f'http://{host}:{port}/' + self.server_process.start() + + def tearDown(self) -> None: + self.server_process.terminate() + + def test_trivial_api_response(self): + resp = requests.get(self.uri, ) + self.assertEqual(resp.status_code, 200) +