-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing tests for some endpoints before route refactoring (#52)
* add tests for status endpoint * add missing tests for deploy endpoints * add test for draw endpoint * Refactor status endpoint * Test refactoring using utilty methods as fixtures for calling API endpoints
- Loading branch information
1 parent
2058cac
commit 86a5be7
Showing
7 changed files
with
148 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
|
||
@pytest.fixture | ||
def deploy_pipeline(): | ||
def _deploy_pipeline(client: TestClient, pipeline_name: str, pipeline_source_code: str): | ||
deploy_response = client.post("/deploy", json={"name": pipeline_name, "source_code": pipeline_source_code}) | ||
return deploy_response | ||
return _deploy_pipeline | ||
|
||
|
||
@pytest.fixture | ||
def undeploy_pipeline(): | ||
def _undeploy_pipeline(client: TestClient, pipeline_name: str): | ||
undeploy_response = client.post(f"/undeploy/{pipeline_name}") | ||
return undeploy_response | ||
return _undeploy_pipeline | ||
|
||
|
||
@pytest.fixture | ||
def draw_pipeline(): | ||
def _draw_pipeline(client: TestClient, pipeline_name: str): | ||
draw_response = client.get(f"/draw/{pipeline_name}") | ||
return draw_response | ||
return _draw_pipeline | ||
|
||
|
||
@pytest.fixture | ||
def status_pipeline(): | ||
def _status_pipeline(client: TestClient, pipeline_name: str): | ||
status_response = client.get(f"/status/{pipeline_name}") | ||
return status_response | ||
return _status_pipeline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from fastapi.testclient import TestClient | ||
from hayhooks.server import app | ||
from pathlib import Path | ||
|
||
client = TestClient(app) | ||
|
||
|
||
def test_draw_pipeline(deploy_pipeline, draw_pipeline): | ||
pipeline_file = Path(__file__).parent / "test_files" / "working_pipelines/test_pipeline_01.yml" | ||
pipeline_data = {"name": pipeline_file.stem, "source_code": pipeline_file.read_text()} | ||
|
||
deploy_pipeline(client, pipeline_data["name"], pipeline_data["source_code"]) | ||
|
||
draw_response = draw_pipeline(client, pipeline_data["name"]) | ||
assert draw_response.status_code == 200 | ||
|
||
assert draw_response.headers["Content-Type"] == "image/png" | ||
assert len(draw_response.content) > 0 | ||
|
||
|
||
def test_draw_non_existent_pipeline(draw_pipeline): | ||
draw_response = draw_pipeline(client, "non_existent_pipeline") | ||
assert draw_response.status_code == 404 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
from hayhooks.server import app | ||
from hayhooks.server.pipelines import registry | ||
from pathlib import Path | ||
|
||
client = TestClient(app) | ||
|
||
@pytest.fixture(autouse=True) | ||
def clear_registry(): | ||
registry.clear() | ||
|
||
|
||
def test_status_all_pipelines(status_pipeline): | ||
status_response = status_pipeline(client, "") | ||
assert status_response.status_code == 200 | ||
assert "pipelines" in status_response.json() | ||
|
||
|
||
def test_status_single_pipeline(deploy_pipeline, status_pipeline): | ||
pipeline_file = Path(__file__).parent / "test_files" / "working_pipelines/test_pipeline_01.yml" | ||
pipeline_data = {"name": pipeline_file.stem, "source_code": pipeline_file.read_text()} | ||
|
||
deploy_response = deploy_pipeline(client, pipeline_data["name"], pipeline_data["source_code"]) | ||
assert deploy_response.status_code == 200 | ||
|
||
status_response = status_pipeline(client, pipeline_data["name"]) | ||
assert status_response.status_code == 200 | ||
assert status_response.json()["pipeline"] == pipeline_data["name"] | ||
|
||
|
||
def test_status_non_existent_pipeline(status_pipeline): | ||
status_response = status_pipeline(client, "non_existent_pipeline") | ||
assert status_response.status_code == 404 | ||
assert status_response.json()["detail"] == f"Pipeline 'non_existent_pipeline' not found" | ||
|
||
|
||
def test_status_no_pipelines(status_pipeline): | ||
status_response = status_pipeline(client, "") | ||
assert status_response.status_code == 200 | ||
assert "pipelines" in status_response.json() | ||
assert len(status_response.json()["pipelines"]) == 0 |