Skip to content

Commit

Permalink
Remove useless test and condition in validator
Browse files Browse the repository at this point in the history
The test was added in ab33375
The condition is checked before this custom validation
  • Loading branch information
juhoinkinen committed Apr 19, 2024
1 parent 5f02228 commit e1e5d5a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
8 changes: 2 additions & 6 deletions annif/openapi/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,16 @@

class CustomRequestBodyValidator(JSONRequestBodyValidator):
"""Custom request body validator that overrides the default error message for the
'maxItems' validator for the 'documents' property."""
'maxItems' validator for the 'documents' property to prevent logging request body
with the contents of all documents."""

def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

def _validate(self, body: Any) -> dict | None:
if not self._nullable and body is None:
raise BadRequestProblem(
"Request body must not be empty"
) # pragma: no cover
try:
return self._validator.validate(body)
except ValidationError as exception:
# Prevent logging request body with contents of all documents
if exception.validator == "maxItems" and list(exception.schema_path) == [
"properties",
"documents",
Expand Down
9 changes: 0 additions & 9 deletions tests/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,6 @@ def test_openapi_suggest_novocab(app_client):
assert req.status_code == 503


def test_openapi_suggest_emptybody(app_client):
data = {}
req = app_client.post(
"http://localhost:8000/v1/projects/dummy-fi/suggest", data=data
)
assert req.status_code == 400
assert req.json()["detail"] == "RequestBody is required"


def test_openapi_suggest_batch(app_client):
data = {"documents": [{"text": "A quick brown fox jumped over the lazy dog."}] * 32}
req = app_client.post(
Expand Down

0 comments on commit e1e5d5a

Please sign in to comment.