-
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.
Merge branch 'master' into bugfix/fix-distinct-filter-#141
- Loading branch information
Showing
16 changed files
with
281 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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,34 @@ | ||
import pytest | ||
|
||
from datagateway_api.common.exceptions import BadRequestError | ||
from datagateway_api.common.icat.helpers import get_icat_entity_name_as_camel_case | ||
|
||
|
||
class TestICATHelpers: | ||
"""Testing the helper functions which aren't covered in the endpoint tests""" | ||
|
||
@pytest.mark.parametrize( | ||
"input_entity_name, expected_entity_name", | ||
[ | ||
pytest.param("User", "user", id="singular single word entity name"), | ||
pytest.param( | ||
"PublicStep", "publicStep", id="singular two word entity name", | ||
), | ||
pytest.param( | ||
"PermissibleStringValue", | ||
"permissibleStringValue", | ||
id="singular multi-word entity name", | ||
), | ||
], | ||
) | ||
def test_valid_get_icat_entity_name_as_camel_case( | ||
self, icat_client, input_entity_name, expected_entity_name, | ||
): | ||
camel_case_entity_name = get_icat_entity_name_as_camel_case( | ||
icat_client, input_entity_name, | ||
) | ||
assert camel_case_entity_name == expected_entity_name | ||
|
||
def test_invalid_get_icat_entity_name_as_camel_case(self, icat_client): | ||
with pytest.raises(BadRequestError): | ||
get_icat_entity_name_as_camel_case(icat_client, "UnknownEntityName") |
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
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
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,81 @@ | ||
import pytest | ||
|
||
from datagateway_api.common.exceptions import ( | ||
ApiError, | ||
AuthenticationError, | ||
BadRequestError, | ||
DatabaseError, | ||
FilterError, | ||
MissingCredentialsError, | ||
MissingRecordError, | ||
MultipleIncludeError, | ||
PythonICATError, | ||
) | ||
|
||
|
||
class TestExceptions: | ||
@pytest.mark.parametrize( | ||
"exception_class, expected_message", | ||
[ | ||
pytest.param( | ||
AuthenticationError, "Authentication error", id="AuthenticationError", | ||
), | ||
pytest.param(BadRequestError, "Bad request", id="BadRequestError"), | ||
pytest.param(DatabaseError, "Database error", id="DatabaseError"), | ||
pytest.param(FilterError, "Invalid filter requested", id="FilterError"), | ||
pytest.param( | ||
MissingCredentialsError, | ||
"No credentials provided in auth header", | ||
id="MissingCredentialsError", | ||
), | ||
pytest.param( | ||
MissingRecordError, "No such record in table", id="MissingRecordError", | ||
), | ||
pytest.param( | ||
MultipleIncludeError, | ||
"Bad request, only one include filter may be given per request", | ||
id="MultipleIncludeError", | ||
), | ||
pytest.param(PythonICATError, "Python ICAT error", id="PythonICATError"), | ||
], | ||
) | ||
def test_valid_exception_message(self, exception_class, expected_message): | ||
assert exception_class().args[0] == expected_message | ||
|
||
@pytest.mark.parametrize( | ||
"exception_class, expected_status_code", | ||
[ | ||
pytest.param(ApiError, 500, id="ApiError"), | ||
pytest.param(AuthenticationError, 403, id="AuthenticationError"), | ||
pytest.param(BadRequestError, 400, id="BadRequestError"), | ||
pytest.param(DatabaseError, 500, id="DatabaseError"), | ||
pytest.param(FilterError, 400, id="FilterError"), | ||
pytest.param(MissingCredentialsError, 401, id="MissingCredentialsError"), | ||
pytest.param(MissingRecordError, 404, id="MissingRecordError"), | ||
pytest.param(MultipleIncludeError, 400, id="MultipleIncludeError"), | ||
pytest.param(PythonICATError, 500, id="PythonICATError"), | ||
], | ||
) | ||
def test_valid_exception_status_code(self, exception_class, expected_status_code): | ||
assert exception_class().status_code == expected_status_code | ||
|
||
@pytest.mark.parametrize( | ||
"exception_class", | ||
[ | ||
pytest.param(ApiError, id="ApiError"), | ||
pytest.param(AuthenticationError, id="AuthenticationError"), | ||
pytest.param(BadRequestError, id="BadRequestError"), | ||
pytest.param(DatabaseError, id="DatabaseError"), | ||
pytest.param(FilterError, id="FilterError"), | ||
pytest.param(MissingCredentialsError, id="MissingCredentialsError"), | ||
pytest.param(MissingRecordError, id="MissingRecordError"), | ||
pytest.param(MultipleIncludeError, id="MultipleIncludeError"), | ||
pytest.param(PythonICATError, id="PythonICATError"), | ||
], | ||
) | ||
def test_valid_raise_exception(self, exception_class): | ||
def raise_exception(): | ||
raise exception_class() | ||
|
||
with pytest.raises(exception_class): | ||
raise_exception() |
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,28 @@ | ||
import pytest | ||
|
||
from datagateway_api.common.database.models import FACILITY, INVESTIGATION, JOB | ||
from datagateway_api.common.exceptions import ApiError | ||
from datagateway_api.common.helpers import get_entity_object_from_name | ||
|
||
|
||
class TestGetEntityObject: | ||
@pytest.mark.parametrize( | ||
"entity_name, expected_object_type", | ||
[ | ||
pytest.param( | ||
"investigation", type(INVESTIGATION), id="singular entity name", | ||
), | ||
pytest.param("jobs", type(JOB), id="plural entity name, 's' added"), | ||
pytest.param( | ||
"facilities", type(FACILITY), id="plural entity name, 'y' to 'ies'", | ||
), | ||
], | ||
) | ||
def test_valid_get_entity_object_from_name(self, entity_name, expected_object_type): | ||
database_entity = get_entity_object_from_name(entity_name) | ||
|
||
assert type(database_entity) == expected_object_type | ||
|
||
def test_invalid_get_entity_object_from_name(self): | ||
with pytest.raises(ApiError): | ||
get_entity_object_from_name("Application1234s") |
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,18 @@ | ||
from datagateway_api.common.filters import QueryFilter | ||
|
||
|
||
class TestQueryFilter: | ||
def test_abstract_class(self): | ||
"""Test the `QueryFilter` class has all required abstract methods""" | ||
|
||
QueryFilter.__abstractmethods__ = set() | ||
|
||
class DummyQueryFilter(QueryFilter): | ||
pass | ||
|
||
qf = DummyQueryFilter() | ||
|
||
apply_filter = "apply_filter" | ||
|
||
assert qf.precedence is None | ||
assert qf.apply_filter(apply_filter) is None |