Skip to content

Commit

Permalink
Merge pull request #62 from kjsanger/bug/http-error-on-bad-input
Browse files Browse the repository at this point in the history
Fix pipelines endpoint to return HTTP 422 on bad input rather than 409
  • Loading branch information
mgcam authored Jun 14, 2024
2 parents ec1a047 + 1c4b998 commit 1a8a925
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/npg_porch/models/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2021, 2022 Genome Research Ltd.
# Copyright (C) 2021, 2022, 2024 Genome Research Ltd.
#
# Author: Kieron Taylor [email protected]
# Author: Marina Gourtovaia [email protected]
Expand All @@ -18,9 +18,11 @@
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.

from pydantic import BaseModel, Field
from pydantic import BaseModel, ConfigDict, Field

class Pipeline(BaseModel):
model_config = ConfigDict(extra='forbid')

name: str = Field(
default = None,
title='Pipeline Name',
Expand Down
12 changes: 12 additions & 0 deletions tests/pipeline_route_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from starlette import status

from npg_porch.models import Pipeline
Expand Down Expand Up @@ -100,6 +102,16 @@ def test_get_known_pipeline(async_minimum, fastapi_testclient):


def test_create_pipeline(async_minimum, fastapi_testclient):
invalid_pipeline = {
"name": "ptest one",
"url": "http://test.com", # URL, not URI
"version": "1"
}
response = fastapi_testclient.post(
"/pipelines", json=json.dumps(invalid_pipeline), follow_redirects=True,
headers=headers4power_user
)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY

# Create a pipeline
desired_pipeline = Pipeline(
Expand Down

0 comments on commit 1a8a925

Please sign in to comment.