Skip to content

Commit

Permalink
test: improve code coverage for search API error formatting #319
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Feb 25, 2022
1 parent 935f22d commit 1e42981
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion test/search_api/test_error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
SearchAPIError,
)
from datagateway_api.src.search_api.helpers import search_api_error_handling
from datagateway_api.src.search_api.models import Document


class TestErrorHandling:
Expand All @@ -24,14 +25,19 @@ class TestErrorHandling:
pytest.param(ValueError, BadRequestError, 400, id="Value error"),
pytest.param(AttributeError, BadRequestError, 400, id="Attribute error"),
pytest.param(ImportError, ImportError, 500, id="Import error"),
pytest.param(Document, SearchAPIError, 500, id="Validation error"),
],
)
def test_valid_error_raised(
self, raised_exception, expected_exception, status_code,
):
@search_api_error_handling
def raise_exception():
raise raised_exception()
if isinstance(raised_exception(), Exception):
raise raised_exception()
else:
# To raise Pydantic ValidationError from object creation
raised_exception()

try:
raise_exception()
Expand Down

0 comments on commit 1e42981

Please sign in to comment.