From bda1eaf9326f09ab48a62116a07353f5684793f9 Mon Sep 17 00:00:00 2001 From: Michele Pangrazzi Date: Fri, 10 Jan 2025 11:32:30 +0100 Subject: [PATCH] Refactor status endpoint --- src/hayhooks/server/handlers/status.py | 16 +++++++++------- tests/test_it_deploy.py | 18 ++++++++++++++---- tests/test_it_status.py | 5 ++--- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/hayhooks/server/handlers/status.py b/src/hayhooks/server/handlers/status.py index 0f53e1a..c59f6d7 100644 --- a/src/hayhooks/server/handlers/status.py +++ b/src/hayhooks/server/handlers/status.py @@ -3,12 +3,14 @@ from hayhooks.server.pipelines import registry -@app.get("/status") -async def status(pipeline_name: str | None = None): - if pipeline_name: - if pipeline_name not in registry.get_names(): - raise HTTPException(status_code=404, detail=f"Pipeline '{pipeline_name}' not found") - return {"status": "Up!", "pipeline": pipeline_name} - +@app.get("/status", tags=["status"]) +async def status_all(): pipelines = registry.get_names() return {"status": "Up!", "pipelines": pipelines} + + +@app.get("/status/{pipeline_name}", tags=["status"]) +async def status(pipeline_name: str): + if pipeline_name not in registry.get_names(): + raise HTTPException(status_code=404, detail=f"Pipeline '{pipeline_name}' not found") + return {"status": "Up!", "pipeline": pipeline_name} diff --git a/tests/test_it_deploy.py b/tests/test_it_deploy.py index d3a6d06..b71856d 100644 --- a/tests/test_it_deploy.py +++ b/tests/test_it_deploy.py @@ -35,8 +35,8 @@ def test_deploy_pipeline_def(pipeline_data: dict): deploy_response = deploy_pipeline(pipeline_data) assert deploy_response.status_code == 200 - status_response = client.get("/status") - assert pipeline_data["name"] in status_response.json()["pipelines"] + status_response = client.get(f"/status/{pipeline_data['name']}") + assert pipeline_data["name"] in status_response.json()["pipeline"] docs_response = client.get("/docs") assert docs_response.status_code == 200 @@ -52,5 +52,15 @@ def test_undeploy_pipeline_def(): undeploy_response = undeploy_pipeline(pipeline_data) assert undeploy_response.status_code == 200 - status_response = client.get("/status") - assert pipeline_data["name"] not in status_response.json()["pipelines"] + status_response = client.get(f"/status/{pipeline_data['name']}") + assert status_response.status_code == 404 + + +def test_undeploy_non_existent_pipeline(): + undeploy_response = client.post("/undeploy/non_existent_pipeline") + assert undeploy_response.status_code == 404 + + +def test_undeploy_no_pipelines(): + undeploy_response = client.post("/undeploy") + assert undeploy_response.status_code == 404 diff --git a/tests/test_it_status.py b/tests/test_it_status.py index 4bebea6..4ed32ae 100644 --- a/tests/test_it_status.py +++ b/tests/test_it_status.py @@ -7,7 +7,6 @@ client = TestClient(app) - @pytest.fixture(autouse=True) def clear_registry(): registry.clear() @@ -25,13 +24,13 @@ def test_status_single_pipeline(): deploy_pipeline(pipeline_data) - status_response = client.get(f"/status", params={"pipeline_name": pipeline_data["name"]}) + status_response = client.get(f"/status/{pipeline_data['name']}") assert status_response.status_code == 200 assert status_response.json()["pipeline"] == pipeline_data["name"] def test_status_non_existent_pipeline(): - status_response = client.get("/status", params={"pipeline_name": "non_existent_pipeline"}) + status_response = client.get("/status/non_existent_pipeline") assert status_response.status_code == 404 assert status_response.json()["detail"] == f"Pipeline 'non_existent_pipeline' not found"