Skip to content

Commit

Permalink
Fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dbernstein committed May 14, 2024
1 parent d2166dd commit 3a58adc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
8 changes: 3 additions & 5 deletions src/palace/manager/search/external_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,8 +1071,6 @@ class Operators(Values):
RESERVED_CHARS_MAP = dict(map(lambda ch: (ord(ch), f"\\{ch}"), RESERVED_CHARS))

_KEYWORD_ONLY = {"keyword": True}
_LONG_TYPE = {"type": "long"}
_BOOL_TYPE = {"type": "bool"}

# The fields mappings in the search DB
FIELD_MAPPING: dict[str, dict] = {
Expand Down Expand Up @@ -1101,15 +1099,15 @@ class Operators(Values):
"licensepools.availability_time": dict(path="licensepools"),
"licensepools.collection_id": dict(path="licensepools"),
"licensepools.data_source_id": dict(
path="licensepools", ops=[Operators.EQ, Operators.EQ]
path="licensepools", ops=[Operators.EQ, Operators.NEQ]
),
"licensepools.licensed": dict(path="licensepools"),
"licensepools.medium": dict(path="licensepools"),
"licensepools.open_access": dict(path="licensepools"),
"licensepools.quality": dict(path="licensepools"),
"licensepools.suppressed": dict(path="licensepools"),
"medium": _KEYWORD_ONLY,
"presentation_ready": _BOOL_TYPE,
"presentation_ready": dict(),
"publisher": _KEYWORD_ONLY,
"quality": dict(),
"series": _KEYWORD_ONLY,
Expand Down Expand Up @@ -1293,7 +1291,7 @@ def _parse_json_leaf(self, query: dict) -> dict:
def _parse_json_join(self, query: dict) -> dict:
if len(query.keys()) != 1:
raise QueryParseException(
detail="A conjuction cannot have multiple parts in the same sub-query"
detail="A conjunction cannot have multiple parts in the same sub-query"
)

join = list(query.keys())[0]
Expand Down
19 changes: 12 additions & 7 deletions tests/manager/search/test_external_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5074,8 +5074,15 @@ def test_search_query(self, external_search_fixture: ExternalSearchFixture):
assert q.search_query.to_dict() == {
"bool": {
"must": [
{"term": {"medium.keyword": "Book"}},
{"term": {"medium.keyword": "Audio"}},
{"term": {"title.keyword": "Title"}},
{
"bool": {
"should": [
{"term": {"medium.keyword": "Book"}},
{"term": {"medium.keyword": "Audio"}},
]
}
},
]
}
}
Expand All @@ -5086,7 +5093,7 @@ def test_search_query(self, external_search_fixture: ExternalSearchFixture):
"bool": {
"should": [
{"term": {"medium.keyword": "Book"}},
{"term": {"medium.keyword": "Audio"}},
{"bool": {"must_not": [{"term": {"medium.keyword": "Audio"}}]}},
]
}
}
Expand Down Expand Up @@ -5147,7 +5154,7 @@ def test_search_query_nested(self, key, value, is_keyword):
dict(kew="author", op="eq", value="name"),
"Could not make sense of the query",
),
({"and": [], "or": []}, "A conjuction cannot have multiple parts"),
({"and": [], "or": []}, "A conjunction cannot have multiple parts"),
],
)
def test_errors(self, query, error_match):
Expand Down Expand Up @@ -5287,9 +5294,7 @@ def test_special_chars(self, value, escaped, contains):
== f".*{escaped}.*"
)
else:
assert (
q.search_query.to_dict()["match"]["title.keyword"]["query"] == escaped
)
assert q.search_query.to_dict()["term"]["title.keyword"] == escaped


class TestExternalSearchJSONQueryData:
Expand Down

0 comments on commit 3a58adc

Please sign in to comment.