Skip to content

Commit

Permalink
Refactor status endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mpangrazzi committed Jan 10, 2025
1 parent a50c4e3 commit bda1eaf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
16 changes: 9 additions & 7 deletions src/hayhooks/server/handlers/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
18 changes: 14 additions & 4 deletions tests/test_it_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
5 changes: 2 additions & 3 deletions tests/test_it_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

client = TestClient(app)


@pytest.fixture(autouse=True)
def clear_registry():
registry.clear()
Expand All @@ -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"

Expand Down

0 comments on commit bda1eaf

Please sign in to comment.