Skip to content

Commit

Permalink
test: fix text operator tests for query params #259
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Dec 3, 2021
1 parent 2106e99 commit 9e404ed
Showing 1 changed file with 148 additions and 76 deletions.
224 changes: 148 additions & 76 deletions test/search_api/test_search_api_query_filter_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,6 @@ class TestSearchAPIQueryFilterFactory:
["and"],
id="Property value with operator",
),
pytest.param(
{"filter": {"where": {"text": "Dataset 1"}}},
"datasets",
1,
["title"],
["eq"],
["Dataset 1"],
["or"],
# TODO
id="Text operator on dataset",
),
pytest.param(
{"filter": {"where": {"text": "Instrument 1"}}},
"instrument",
1,
["name", "facility"],
["eq", "eq"],
["Instrument 1", "Instrument 1"],
["or", "or"],
# TODO
id="Text operator on instrument",
),
pytest.param(
{"where": {"summary": {"like": "My Test Summary"}}},
"documents",
Expand Down Expand Up @@ -100,6 +78,53 @@ def test_valid_where_filter(
assert test_filter.value == value
assert test_filter.boolean_operator == boolean_operator

@pytest.mark.parametrize(
"test_request_filter, test_entity_name, expected_length, expected_lhs"
", expected_rhs, expected_joining_operator",
[
pytest.param(
{"filter": {"where": {"text": "Dataset 1"}}},
"datasets",
1,
[],
[SearchAPIWhereFilter("title", "Dataset 1", "eq")],
"or",
id="Text operator on dataset",
),
pytest.param(
{"filter": {"where": {"text": "Instrument 1"}}},
"instrument",
1,
[SearchAPIWhereFilter("name", "Instrument 1", "eq")],
[SearchAPIWhereFilter("facility", "Instrument 1", "eq")],
"or",
id="Text operator on instrument",
),
],
)
def test_valid_where_filter_text_operator(
self,
test_request_filter,
test_entity_name,
expected_length,
expected_lhs,
expected_rhs,
expected_joining_operator,
):
filters = SearchAPIQueryFilterFactory.get_query_filter(
test_request_filter, test_entity_name,
)

# TODO - Will expected length always be 1?
assert len(filters) == expected_length
assert isinstance(filters[0], NestedWhereFilters)
print(type(filters[0]))
print(f"LHS: {repr(filters[0].lhs)}, Type: {type(filters[0].lhs)}")
print(f"RHS: {repr(filters[0].rhs)}, Type: {type(filters[0].rhs)}")
assert repr(filters[0].lhs) == repr(expected_lhs)
assert repr(filters[0].rhs) == repr(expected_rhs)
assert filters[0].joining_operator == expected_joining_operator

@pytest.mark.parametrize(
"test_request_filter, test_entity_name, expected_length, expected_fields,"
"expected_operations, expected_values, expected_boolean_operators"
Expand Down Expand Up @@ -235,24 +260,32 @@ def test_valid_where_filter(
["eq"],
["Dataset 1"],
["or"],
# TODO
"lhs",
"rhs",
"joining operator",
[],
[
NestedWhereFilters(
[], SearchAPIWhereFilter("title", "Dataset 1", "eq"), "or",
),
],
"and",
id="Single condition, text operator on dataset",
),
pytest.param(
{"filter": {"where": {"and": [{"text": "Instrument 1"}]}}},
"instrument",
2,
1,
["name", "facility"],
["eq", "eq"],
["Instrument 1", "Instrument 1"],
["or", "or"],
# TODO
"lhs",
"rhs",
"joining operator",
[],
[
NestedWhereFilters(
[SearchAPIWhereFilter("name", "Instrument 1", "eq")],
[SearchAPIWhereFilter("facility", "Instrument 1", "eq")],
"or",
),
],
"and",
id="Single condition, text operator on instrument",
),
pytest.param(
Expand All @@ -262,15 +295,18 @@ def test_valid_where_filter(
},
},
"datasets",
2,
1,
["title", "pid"],
["eq", "eq"],
["Dataset 1", "Test pid"],
["or", "and"],
# TODO
"lhs",
"rhs",
"joining operator",
[
NestedWhereFilters(
[], [SearchAPIWhereFilter("title", "Dataset 1", "eq")], "or",
),
],
[SearchAPIWhereFilter("pid", "Test pid", "eq")],
"and",
id="Multiple conditions (two), text operator on dataset and "
"property value with no operator",
),
Expand All @@ -283,15 +319,20 @@ def test_valid_where_filter(
},
},
"instrument",
3,
1,
["name", "facility", "pid"],
["eq", "eq", "eq"],
["Instrument 1", "Instrument 1", "Test pid"],
["or", "or", "and"],
# TODO
"lhs",
"rhs",
"joining operator",
[
NestedWhereFilters(
[SearchAPIWhereFilter("name", "Instrument 1", "eq")],
[SearchAPIWhereFilter("facility", "Instrument 1", "eq")],
"or",
),
],
[SearchAPIWhereFilter("pid", "Test pid", "eq")],
"and",
id="Multiple conditions (two), text operator on instrument and "
"property value with no operator",
),
Expand All @@ -307,15 +348,18 @@ def test_valid_where_filter(
},
},
"datasets",
2,
1,
["title", "pid"],
["eq", "eq"],
["Dataset 1", "Test pid"],
["or", "and"],
# TODO
"lhs",
"rhs",
"joining operator",
[
NestedWhereFilters(
[], [SearchAPIWhereFilter("title", "Dataset 1", "eq")], "or",
),
],
[SearchAPIWhereFilter("pid", "Test pid", "eq")],
"and",
id="Multiple conditions (two), text operator on dataset and "
"property value with operator",
),
Expand All @@ -331,15 +375,20 @@ def test_valid_where_filter(
},
},
"instrument",
3,
1,
["name", "facility", "pid"],
["eq", "eq", "eq"],
["Instrument 1", "Instrument 1", "Test pid"],
["or", "or", "and"],
# TODO
"lhs",
"rhs",
"joining operator",
[
NestedWhereFilters(
[SearchAPIWhereFilter("name", "Instrument 1", "eq")],
[SearchAPIWhereFilter("facility", "Instrument 1", "eq")],
"or",
),
],
[SearchAPIWhereFilter("pid", "Test pid", "eq")],
"and",
id="Multiple conditions (two), text operator on instrument and "
"property value with operator",
),
Expand Down Expand Up @@ -408,7 +457,6 @@ def test_valid_where_filter_with_and_boolean_operator(
["eq", "eq"],
["My Test Summary", "Test title"],
["or", "or"],
# TODO
[SearchAPIWhereFilter("summary", "My Test Summary", "eq")],
[SearchAPIWhereFilter("title", "Test title", "eq")],
"or",
Expand Down Expand Up @@ -509,10 +557,13 @@ def test_valid_where_filter_with_and_boolean_operator(
["eq"],
["Dataset 1"],
["or"],
# TODO
"lhs",
"rhs",
"joining operator",
[],
[
NestedWhereFilters(
[], SearchAPIWhereFilter("title", "Dataset 1", "eq"), "or",
),
],
"or",
id="Single condition, text operator on dataset",
),
pytest.param(
Expand All @@ -523,10 +574,15 @@ def test_valid_where_filter_with_and_boolean_operator(
["eq", "eq"],
["Instrument 1", "Instrument 1"],
["or", "or"],
# TODO
"lhs",
"rhs",
"joining operator",
[],
[
NestedWhereFilters(
[SearchAPIWhereFilter("name", "Instrument 1", "eq")],
[SearchAPIWhereFilter("facility", "Instrument 1", "eq")],
"or",
),
],
"or",
id="Single condition, text operator on instrument",
),
pytest.param(
Expand All @@ -541,10 +597,13 @@ def test_valid_where_filter_with_and_boolean_operator(
["eq", "eq"],
["Dataset 1", "Test pid"],
["or", "or"],
# TODO
"lhs",
"rhs",
"joining operator",
[
NestedWhereFilters(
[], [SearchAPIWhereFilter("title", "Dataset 1", "eq")], "or",
),
],
[SearchAPIWhereFilter("pid", "Test pid", "eq")],
"or",
id="Multiple conditions (two), text operator on dataset and "
"property value with no operator",
),
Expand All @@ -562,10 +621,15 @@ def test_valid_where_filter_with_and_boolean_operator(
["eq", "eq", "eq"],
["Instrument 1", "Instrument 1", "Test pid"],
["or", "or", "or"],
# TODO
"lhs",
"rhs",
"joining operator",
[
NestedWhereFilters(
[SearchAPIWhereFilter("name", "Instrument 1", "eq")],
[SearchAPIWhereFilter("facility", "Instrument 1", "eq")],
"or",
),
],
[SearchAPIWhereFilter("pid", "Test pid", "eq")],
"or",
id="Multiple conditions (two), text operator on instrument and "
"property value with no operator",
),
Expand All @@ -583,10 +647,13 @@ def test_valid_where_filter_with_and_boolean_operator(
["eq", "eq"],
["Dataset 1", "Test pid"],
["or", "or"],
# TODO
"lhs",
"rhs",
"joining operator",
[
NestedWhereFilters(
[], [SearchAPIWhereFilter("title", "Dataset 1", "eq")], "or",
),
],
[SearchAPIWhereFilter("pid", "Test pid", "eq")],
"or",
id="Multiple conditions (two), text operator on dataset and "
"property value with operator",
),
Expand All @@ -607,10 +674,15 @@ def test_valid_where_filter_with_and_boolean_operator(
["eq", "eq", "eq"],
["Instrument 1", "Instrument 1", "Test pid"],
["or", "or", "or"],
# TODO
"lhs",
"rhs",
"joining operator",
[
NestedWhereFilters(
[SearchAPIWhereFilter("name", "Instrument 1", "eq")],
[SearchAPIWhereFilter("facility", "Instrument 1", "eq")],
"or",
),
],
[SearchAPIWhereFilter("pid", "Test pid", "eq")],
"or",
id="Multiple conditions (two), text operator on instrument and "
"property value with operator",
),
Expand Down

0 comments on commit 9e404ed

Please sign in to comment.