Skip to content

Commit

Permalink
test: refactor more query params tests #259
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Dec 3, 2021
1 parent d6c62ea commit 605315c
Showing 1 changed file with 63 additions and 45 deletions.
108 changes: 63 additions & 45 deletions test/search_api/test_search_api_query_filter_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1790,10 +1790,11 @@ def test_valid_include_filter_with_include_filter_in_scope(
)

assert len(filters) == expected_length

for test_filter, included_entities in zip(filters, expected_included_entities):
for test_filter in filters:
if isinstance(test_filter, SearchAPIIncludeFilter):
assert test_filter.included_filters == included_entities
for expected_include in expected_included_entities:
assert test_filter.included_filters == expected_include
expected_included_entities.remove(expected_include)

@pytest.mark.parametrize(
"test_request_filter, expected_limit_value",
Expand Down Expand Up @@ -1828,7 +1829,7 @@ def test_valid_skip_filter(
@pytest.mark.parametrize(
"test_request_filter, test_entity_name, expected_length"
", expected_included_entities, expected_where_filter_data"
", expected_limit_values, expected_skip_values",
", expected_nested_wheres, expected_limit_values, expected_skip_values",
[
pytest.param(
{
Expand All @@ -1841,10 +1842,11 @@ def test_valid_skip_filter(
},
"datasets",
4,
[[], ["instrument"], [], []],
[["title", "eq", "My Title", "and"], [], [], []],
[None, None, 50, None],
[None, None, None, 20],
[["instrument"]],
[SearchAPIWhereFilter("title", "My Title", "eq")],
[],
[50],
[20],
id="Simple case",
),
pytest.param(
Expand Down Expand Up @@ -1883,23 +1885,43 @@ def test_valid_skip_filter(
},
},
"datasets",
11,
[[], [], [], [], [], [], ["instrument"], [], [], [], []],
5,
[["instrument"]],
[SearchAPIWhereFilter("instrument.name", "Instrument 1", "eq")],
[
["summary", "eq", "My Test Summary", "and"],
["title", "like", "Test title", "and"],
["pid", "eq", "Test pid", "and"],
["type", "eq", "Test type", "and"],
["doi", "eq", "Test doi", "or"],
["license", "like", "Test license", "or"],
[],
["instrument.name", "eq", "Instrument 1", "and"],
[],
[],
[],
NestedWhereFilters(
[
NestedWhereFilters(
[
SearchAPIWhereFilter(
"summary", "My Test Summary", "eq"
)
],
[SearchAPIWhereFilter("title", "Test title", "like")],
"and",
),
NestedWhereFilters(
[SearchAPIWhereFilter("pid", "Test pid", "eq")],
[SearchAPIWhereFilter("type", "Test type", "eq")],
"and",
),
],
[
NestedWhereFilters(
[SearchAPIWhereFilter("doi", "Test doi", "eq")],
[
SearchAPIWhereFilter(
"license", "Test license", "like"
)
],
"or",
),
],
"and",
)
],
[None, None, None, None, None, None, None, None, 2, 50, None],
[None, None, None, None, None, None, None, None, None, None, 20],
[50],
[20],
id="Complex case",
),
],
Expand All @@ -1911,40 +1933,36 @@ def test_valid_filter_input_with_all_filters(
expected_length,
expected_included_entities,
expected_where_filter_data,
expected_nested_wheres,
expected_limit_values,
expected_skip_values,
):
# TODO - remove limit from scope
filters = SearchAPIQueryFilterFactory.get_query_filter(
test_request_filter, test_entity_name,
)

assert len(filters) == expected_length

for (
test_filter,
included_entities,
where_filter_data,
limit_value,
skip_value,
) in zip(
filters,
expected_included_entities,
expected_where_filter_data,
expected_limit_values,
expected_skip_values,
):
for test_filter in filters:
if isinstance(test_filter, SearchAPIIncludeFilter):
assert test_filter.included_filters == included_entities
for expected_include in expected_included_entities:
assert test_filter.included_filters == expected_include
expected_included_entities.remove(expected_include)
if isinstance(test_filter, NestedWhereFilters):
for expected_nested in expected_nested_wheres:
assert repr(test_filter) == repr(expected_nested)
expected_nested_wheres.remove(expected_nested)
if isinstance(test_filter, SearchAPIWhereFilter):
assert test_filter.field == where_filter_data[0]
assert test_filter.operation == where_filter_data[1]
assert test_filter.value == where_filter_data[2]
assert test_filter.boolean_operator == where_filter_data[3]
for expected_where in expected_where_filter_data:
assert repr(test_filter) == repr(expected_where)
expected_where_filter_data.remove(expected_where)
if isinstance(test_filter, SearchAPILimitFilter):
assert test_filter.limit_value == limit_value
for expected_limit in expected_limit_values:
assert test_filter.limit_value == expected_limit
expected_limit_values.remove(expected_limit)
if isinstance(test_filter, SearchAPISkipFilter):
assert test_filter.skip_value == skip_value
for expected_skip in expected_skip_values:
assert test_filter.skip_value == expected_skip
expected_skip_values.remove(expected_skip)

@pytest.mark.parametrize(
"test_request_filter",
Expand Down

0 comments on commit 605315c

Please sign in to comment.