Skip to content

Commit

Permalink
Add test for range-searching
Browse files Browse the repository at this point in the history
Adds a specific test for range-searching on recid/inspire_id entries in the OpenSearch API
  • Loading branch information
ItIsJordan committed Aug 13, 2024
1 parent 07e4c28 commit e99062b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/search_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,38 @@ def test_search(app, load_default_data, identifiers):
assert results == {'error': 'An unexpected error occurred: index_not_found_exception'}


def test_search_range_ids(app, load_default_data, identifiers):
"""
Tests range-based searching where ID-like entries are used
First checks whole range, then single entry
e.g. inspire_id and recid NOT cmenergies etc.
"""

# Test the parsed entries in config.CFG_SEARCH_RANGE_TERMS
test_queries = [
"inspire_id",
"recid"
]

for test in test_queries:
# Create the range query formatting the keyword per query
range_query = f"{test}:[%s TO %s]"

# Just do a huge range, to see if everything appears
results = os_api.search(range_query % ("0", "100000000"))
# Result count should equal maximum number of entries
assert len(results['results']) == len(identifiers)

# Do a range search for a single result, for each result of the 'all' search above.
for result in results['results']:
# We get the inspire/recid from the current result
identifier_id = result[test]
# Do a search, formatting the query to find a single result
specific_result = os_api.search(range_query % (identifier_id, identifier_id))
# Check ID of single result
assert specific_result['results'][0][test] == identifier_id


def test_merge_results():
pub_result = {
"hits": {
Expand Down

0 comments on commit e99062b

Please sign in to comment.