Skip to content

Commit

Permalink
#150: Rewrite queries_records tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Dec 4, 2020
1 parent d6f6ab8 commit 97bf1a4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 77 deletions.
77 changes: 0 additions & 77 deletions test/db/test_helpers.py

This file was deleted.

36 changes: 36 additions & 0 deletions test/test_queries_records.py
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

0 comments on commit 97bf1a4

Please sign in to comment.