Skip to content

Commit

Permalink
test: test where filter on isPublic fields #329
Browse files Browse the repository at this point in the history
  • Loading branch information
VKTB committed Feb 16, 2022
1 parent 5f65725 commit c70b9e9
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
20 changes: 18 additions & 2 deletions test/search_api/endpoints/test_count_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,29 @@ def test_valid_count_endpoint(
"datasets",
'{"isPublic": true}',
{"count": 479},
id="Dataset count with isPublic condition",
id="Dataset count with isPublic condition (True)",
),
pytest.param(
"documents",
'{"isPublic": true}',
{"count": 239},
id="Document count with isPublic condition",
id="Document count with isPublic condition (True)",
),
pytest.param(
"datasets",
'{"isPublic": false}',
{"count": 0},
id="Dataset count with isPublic condition (False)",
# Skipped due to skip filter causing issue on count endpoints
marks=pytest.mark.skip,
),
pytest.param(
"documents",
'{"isPublic": false}',
{"count": 0},
id="Document count with isPublic condition (False)",
# Skipped due to skip filter causing issue on count endpoints
marks=pytest.mark.skip,
),
],
)
Expand Down
8 changes: 7 additions & 1 deletion test/search_api/endpoints/test_search_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,13 @@ class TestSearchAPISearchEndpoint:
"samples": [],
},
],
id="Search datasets with isPublic condition",
id="Search datasets with isPublic condition (True)",
),
pytest.param(
"datasets",
'{"where": {"isPublic": false}}',
[],
id="Search datasets with isPublic condition (False)",
),
],
)
Expand Down
43 changes: 43 additions & 0 deletions test/search_api/test_search_api_query_filter_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,49 @@ def test_valid_where_filter(
assert len(filters) == 1
assert repr(filters[0]) == repr(expected_where)

@pytest.mark.parametrize(
"test_request_filter, test_entity_name, expected_filters",
[
pytest.param(
{"filter": {"where": {"isPublic": True}}},
"Dataset",
[],
id="Public data",
),
pytest.param(
{"filter": {"where": {"isPublic": {"neq": False}}}},
"Dataset",
[],
id="Public data - neq operator",
),
pytest.param(
{"filter": {"where": {"isPublic": {"eq": False}}}},
"Dataset",
[SearchAPISkipFilter(1), SearchAPILimitFilter(0)],
id="Non-public data",
),
pytest.param(
{"filter": {"where": {"isPublic": {"neq": True}}}},
"Dataset",
[SearchAPISkipFilter(1), SearchAPILimitFilter(0)],
id="Non-public data - neq operator",
),
],
)
def test_valid_where_filter_on_is_public_field(
self, test_request_filter, test_entity_name, expected_filters,
):
filters = SearchAPIQueryFilterFactory.get_query_filter(
test_request_filter, test_entity_name,
)

assert len(filters) == len(expected_filters)
for test_filter in filters:
if isinstance(test_filter, SearchAPISkipFilter):
assert test_filter.skip_value == 1
if isinstance(test_filter, SearchAPILimitFilter):
assert test_filter.limit_value == 0

@pytest.mark.parametrize(
"test_request_filter, test_entity_name, expected_lhs, expected_rhs"
", expected_joining_operator",
Expand Down

0 comments on commit c70b9e9

Please sign in to comment.