Skip to content

Commit

Permalink
feat: support skip/limit string parameters on search-api and added te…
Browse files Browse the repository at this point in the history
…sting
  • Loading branch information
antolinos committed May 24, 2022
1 parent a87b2e6 commit 8c3dde1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions datagateway_api/src/search_api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ def __repr__(self):

class SearchAPISkipFilter(PythonICATSkipFilter):
def __init__(self, skip_value):
super().__init__(skip_value, filter_use="search_api")
super().__init__(int(skip_value), filter_use="search_api")

def apply_filter(self, query):
return super().apply_filter(query.icat_query.query)


class SearchAPILimitFilter(PythonICATLimitFilter):
def __init__(self, limit_value):
super().__init__(limit_value)
super().__init__(int(limit_value))

def apply_filter(self, query):
return super().apply_filter(query.icat_query.query)
Expand Down
2 changes: 1 addition & 1 deletion datagateway_api/src/search_api/query_filter_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def get_query_filter(request_filter, entity_name=None, related_entity_name=None)
)
elif filter_name == "limit":
log.info("limit JSON object found")
query_filters.append(SearchAPILimitFilter(int(filter_input)))
query_filters.append(SearchAPILimitFilter(filter_input))
elif filter_name == "skip":
log.info("skip JSON object found")
query_filters.append(SearchAPISkipFilter(filter_input))
Expand Down
11 changes: 7 additions & 4 deletions test/search_api/filters/test_search_api_limit_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ class TestSearchAPILimitFilter:
pytest.param(10, id="typical"),
pytest.param(0, id="low boundary"),
pytest.param(9999, id="high boundary"),
pytest.param("10", id="string parameter typical"),
pytest.param("0", id="string parameter low boundary"),
pytest.param("9999", id="string parameter high boundary"),
],
)
def test_valid_limit_value(self, limit_value, search_api_query_document):
test_filter = SearchAPILimitFilter(limit_value)
test_filter.apply_filter(search_api_query_document)

assert search_api_query_document.icat_query.query.limit == (0, limit_value)
assert search_api_query_document.icat_query.query.limit == (0, int(limit_value))

@pytest.mark.parametrize(
"limit_value",
[pytest.param(-50, id="extreme invalid"), pytest.param(-1, id="boundary")],
[pytest.param(-50, id="extreme invalid"), pytest.param(-1, id="boundary"), pytest.param("Nan", id="Nan string")],
)
def test_invalid_limit_value(self, limit_value):
with pytest.raises(FilterError):
SearchAPILimitFilter(limit_value)
with pytest.raises((FilterError, Exception)):
SearchAPILimitFilter(limit_value)
8 changes: 4 additions & 4 deletions test/search_api/filters/test_search_api_skip_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

class TestSearchAPISkipFilter:
@pytest.mark.parametrize(
"skip_value", [pytest.param(10, id="typical"), pytest.param(0, id="boundary")],
"skip_value", [pytest.param(10, id="typical"), pytest.param(0, id="boundary"),pytest.param("10", id="string format typical"), pytest.param("0", id="string format boundary")],
)
def test_valid_skip_value(self, search_api_query_document, skip_value):
test_filter = SearchAPISkipFilter(skip_value)
test_filter.apply_filter(search_api_query_document)

assert search_api_query_document.icat_query.query.limit == (
skip_value,
int(skip_value),
get_icat_properties(
Config.config.search_api.icat_url,
Config.config.search_api.icat_check_cert,
Expand All @@ -24,8 +24,8 @@ def test_valid_skip_value(self, search_api_query_document, skip_value):

@pytest.mark.parametrize(
"skip_value",
[pytest.param(-375, id="extreme invalid"), pytest.param(-1, id="boundary")],
[pytest.param(-375, id="extreme invalid"), pytest.param(-1, id="boundary"), pytest.param("Nan", id="Nan string")],
)
def test_invalid_skip_value(self, skip_value):
with pytest.raises(FilterError):
with pytest.raises((FilterError, Exception)):
SearchAPISkipFilter(skip_value)

0 comments on commit 8c3dde1

Please sign in to comment.