-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6f6ab8
commit 97bf1a4
Showing
2 changed files
with
36 additions
and
77 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,36 @@ | ||
import pytest | ||
from sqlalchemy.exc import IntegrityError | ||
|
||
from datagateway_api.common.exceptions import ( | ||
BadRequestError, | ||
FilterError, | ||
MissingRecordError, | ||
) | ||
from datagateway_api.common.helpers import queries_records | ||
|
||
|
||
class TestQueriesRecords: | ||
@pytest.mark.parametrize( | ||
"raised_exception, expected_exception, status_code", | ||
[ | ||
pytest.param(BadRequestError, BadRequestError, 400, id="bad request error"), | ||
pytest.param(IntegrityError, BadRequestError, 400, id="integrity error"), | ||
pytest.param(FilterError, FilterError, 400, id="invalid filter"), | ||
pytest.param( | ||
MissingRecordError, MissingRecordError, 404, id="missing record", | ||
), | ||
pytest.param(TypeError, BadRequestError, 400, id="type error"), | ||
pytest.param(ValueError, BadRequestError, 400, id="value error"), | ||
], | ||
) | ||
def test_valid_error_raised( | ||
self, raised_exception, expected_exception, status_code, | ||
): | ||
@queries_records | ||
def raise_exception(): | ||
raise raised_exception() | ||
|
||
with pytest.raises(expected_exception) as ctx: | ||
raise_exception() | ||
|
||
assert ctx.exception.status_code == status_code |