Skip to content

Commit 45af02a

Browse files
author
Jayant Kernel
committed
fix(review): address CodeRabbit feedback on PR #266
- Add Field(max_length=) constraints to FlowExistsBody.name (1024) and .external_version (128) to mirror the bounds already on the Flow model - Add smoke test for the deprecated GET shim (flow_exists_get) to prevent silent regressions on the backward-compatibility surface - Add regression test for URI-unsafe flow names (containing '/') via POST /flows/exists, guarding the core motivation for the GET->POST migration - Extract duplicated marker expression into a job-level TEST_MARKER env var in tests.yml to eliminate drift risk
1 parent a5cac49 commit 45af02a

3 files changed

Lines changed: 30 additions & 7 deletions

File tree

.github/workflows/tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ permissions:
1414
jobs:
1515
tests:
1616
name: "${{ matrix.php_api == true && 'Migration' || 'Python-only' }} ${{ matrix.mutations == true && 'with mutations' || 'read-only' }}"
17+
env:
18+
TEST_MARKER: "${{ matrix.php_api == true && 'php_api' || 'not php_api' }} and ${{ matrix.mutations == true && 'mut' || 'not mut' }}"
1719
strategy:
1820
matrix:
1921
php_api: [true, false]
@@ -36,12 +38,10 @@ jobs:
3638
3739
- name: Run internal tests
3840
run: |
39-
marker="${{ matrix.php_api == true && 'php_api' || 'not php_api' }} and ${{ matrix.mutations == true && 'mut' || 'not mut' }}"
40-
docker exec openml-python-rest-api coverage run -m pytest tests/database tests/config_test.py -n auto -v -m "$marker"
41+
docker exec openml-python-rest-api coverage run -m pytest tests/database tests/config_test.py -n auto -v -m "$TEST_MARKER"
4142
- name: Run API tests
4243
run: |
43-
marker="${{ matrix.php_api == true && 'php_api' || 'not php_api' }} and ${{ matrix.mutations == true && 'mut' || 'not mut' }}"
44-
docker exec openml-python-rest-api coverage run -a -m pytest tests/routers -n auto -v -m "$marker"
44+
docker exec openml-python-rest-api coverage run -a -m pytest tests/routers -n auto -v -m "$TEST_MARKER"
4545
- name: Produce coverage report
4646
run: docker exec openml-python-rest-api coverage xml
4747
- name: Upload results to Codecov

src/schemas/flows.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88

99
class FlowExistsBody(BaseModel):
10-
name: str
11-
external_version: str
10+
name: str = Field(max_length=1024)
11+
external_version: str = Field(max_length=128)
1212

1313

1414
class Parameter(BaseModel):

tests/routers/openml/flows_test.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55
from fastapi import HTTPException
66
from pytest_mock import MockerFixture
7-
from sqlalchemy import Connection
7+
from sqlalchemy import Connection, text
88
from starlette.testclient import TestClient
99

1010
from routers.openml.flows import flow_exists
@@ -76,6 +76,29 @@ def test_flow_exists_not_exists(py_api: TestClient) -> None:
7676
assert response.json()["detail"] == "Flow not found."
7777

7878

79+
def test_flow_exists_get_deprecated(flow: Flow, py_api: TestClient) -> None:
80+
response = py_api.get(f"/flows/exists/{flow.name}/{flow.external_version}")
81+
assert response.status_code == HTTPStatus.OK
82+
assert response.json() == {"flow_id": flow.id}
83+
84+
85+
def test_flow_exists_uri_unsafe(expdb_test: Connection, py_api: TestClient) -> None:
86+
expdb_test.execute(
87+
text(
88+
"""
89+
INSERT INTO implementation(fullname,name,version,external_version,uploadDate)
90+
VALUES ('weka/ZeroR','weka/ZeroR',2,'1.0/beta','2024-02-02 02:23:23');
91+
""",
92+
),
93+
)
94+
(flow_id,) = expdb_test.execute(text("""SELECT LAST_INSERT_ID();""")).one()
95+
response = py_api.post(
96+
"/flows/exists", json={"name": "weka/ZeroR", "external_version": "1.0/beta"}
97+
)
98+
assert response.status_code == HTTPStatus.OK
99+
assert response.json() == {"flow_id": flow_id}
100+
101+
79102
def test_get_flow_no_subflow(py_api: TestClient) -> None:
80103
response = py_api.get("/flows/1")
81104
assert response.status_code == HTTPStatus.OK

0 commit comments

Comments
 (0)