-
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 pull request #295 from ral-facilities/implement-limit-and-skip-…
…filters Implement Limit and Skip filters
- Loading branch information
Showing
5 changed files
with
94 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from icat.client import Client | ||
from icat.query import Query | ||
import pytest | ||
|
||
from datagateway_api.src.common.config import Config | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def icat_client(): | ||
client = Client( | ||
Config.config.search_api.icat_url, | ||
checkCert=Config.config.search_api.icat_check_cert, | ||
) | ||
client.login( | ||
Config.config.test_mechanism, Config.config.test_user_credentials.dict(), | ||
) | ||
return client | ||
|
||
|
||
@pytest.fixture() | ||
def icat_query(icat_client): | ||
return Query(icat_client, "Investigation") |
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.src.common.exceptions import FilterError | ||
from datagateway_api.src.search_api.filters import SearchAPILimitFilter | ||
|
||
|
||
class TestSearchAPILimitFilter: | ||
@pytest.mark.parametrize( | ||
"limit_value", | ||
[ | ||
pytest.param(10, id="typical"), | ||
pytest.param(0, id="low boundary"), | ||
pytest.param(9999, id="high boundary"), | ||
], | ||
) | ||
def test_valid_limit_value(self, icat_query, limit_value): | ||
test_filter = SearchAPILimitFilter(limit_value) | ||
test_filter.apply_filter(icat_query) | ||
|
||
assert icat_query.limit == (0, limit_value) | ||
|
||
@pytest.mark.parametrize( | ||
"limit_value", | ||
[pytest.param(-50, id="extreme invalid"), pytest.param(-1, id="boundary")], | ||
) | ||
def test_invalid_limit_value(self, icat_query, limit_value): | ||
with pytest.raises(FilterError): | ||
SearchAPILimitFilter(limit_value) |
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,31 @@ | ||
import pytest | ||
|
||
from datagateway_api.src.common.config import Config | ||
from datagateway_api.src.common.exceptions import FilterError | ||
from datagateway_api.src.common.helpers import get_icat_properties | ||
from datagateway_api.src.search_api.filters import SearchAPISkipFilter | ||
|
||
|
||
class TestSearchAPISkipFilter: | ||
@pytest.mark.parametrize( | ||
"skip_value", [pytest.param(10, id="typical"), pytest.param(0, id="boundary")], | ||
) | ||
def test_valid_skip_value(self, icat_query, skip_value): | ||
test_filter = SearchAPISkipFilter(skip_value) | ||
test_filter.apply_filter(icat_query) | ||
|
||
assert icat_query.limit == ( | ||
skip_value, | ||
get_icat_properties( | ||
Config.config.search_api.icat_url, | ||
Config.config.search_api.icat_check_cert, | ||
)["maxEntities"], | ||
) | ||
|
||
@pytest.mark.parametrize( | ||
"skip_value", | ||
[pytest.param(-375, id="extreme invalid"), pytest.param(-1, id="boundary")], | ||
) | ||
def test_invalid_skip_value(self, icat_query, skip_value): | ||
with pytest.raises(FilterError): | ||
SearchAPISkipFilter(skip_value) |