77
88
99@pytest .mark .asyncio
10- async def test_collections_sort_id_asc (app_client , txn_client , load_test_data ):
10+ async def test_collections_sort_id_asc (app_client , txn_client , ctx ):
1111 """Verify GET /collections honors ascending sort on id."""
1212 # Create multiple collections with different ids
13- base_collection = load_test_data ( "test_collection.json" )
13+ base_collection = ctx . collection
1414
1515 # Create collections with ids in a specific order to test sorting
1616 # Use unique prefixes to avoid conflicts between tests
@@ -23,6 +23,8 @@ async def test_collections_sort_id_asc(app_client, txn_client, load_test_data):
2323 test_collection ["title" ] = f"Test Collection { i } "
2424 await create_collection (txn_client , test_collection )
2525
26+ await refresh_indices (txn_client )
27+
2628 # Test ascending sort by id
2729 resp = await app_client .get (
2830 "/collections" ,
@@ -44,10 +46,10 @@ async def test_collections_sort_id_asc(app_client, txn_client, load_test_data):
4446
4547
4648@pytest .mark .asyncio
47- async def test_collections_sort_id_desc (app_client , txn_client , load_test_data ):
49+ async def test_collections_sort_id_desc (app_client , txn_client , ctx ):
4850 """Verify GET /collections honors descending sort on id."""
4951 # Create multiple collections with different ids
50- base_collection = load_test_data ( "test_collection.json" )
52+ base_collection = ctx . collection
5153
5254 # Create collections with ids in a specific order to test sorting
5355 # Use unique prefixes to avoid conflicts between tests
@@ -60,6 +62,8 @@ async def test_collections_sort_id_desc(app_client, txn_client, load_test_data):
6062 test_collection ["title" ] = f"Test Collection { i } "
6163 await create_collection (txn_client , test_collection )
6264
65+ await refresh_indices (txn_client )
66+
6367 # Test descending sort by id
6468 resp = await app_client .get (
6569 "/collections" ,
@@ -81,10 +85,10 @@ async def test_collections_sort_id_desc(app_client, txn_client, load_test_data):
8185
8286
8387@pytest .mark .asyncio
84- async def test_collections_fields (app_client , txn_client , load_test_data ):
88+ async def test_collections_fields (app_client , txn_client , ctx ):
8589 """Verify GET /collections honors the fields parameter."""
8690 # Create multiple collections with different ids
87- base_collection = load_test_data ( "test_collection.json" )
91+ base_collection = ctx . collection
8892
8993 # Create collections with ids in a specific order to test fields
9094 # Use unique prefixes to avoid conflicts between tests
@@ -98,6 +102,8 @@ async def test_collections_fields(app_client, txn_client, load_test_data):
98102 test_collection ["description" ] = f"Description for collection { i } "
99103 await create_collection (txn_client , test_collection )
100104
105+ await refresh_indices (txn_client )
106+
101107 # Test include fields parameter
102108 resp = await app_client .get (
103109 "/collections" ,
@@ -156,10 +162,10 @@ async def test_collections_fields(app_client, txn_client, load_test_data):
156162
157163
158164@pytest .mark .asyncio
159- async def test_collections_free_text_search_get (app_client , txn_client , load_test_data ):
165+ async def test_collections_free_text_search_get (app_client , txn_client , ctx ):
160166 """Verify GET /collections honors the q parameter for free text search."""
161167 # Create multiple collections with different content
162- base_collection = load_test_data ( "test_collection.json" )
168+ base_collection = ctx . collection
163169
164170 # Use unique prefixes to avoid conflicts between tests
165171 test_prefix = f"q-get-{ uuid .uuid4 ().hex [:8 ]} "
@@ -193,6 +199,8 @@ async def test_collections_free_text_search_get(app_client, txn_client, load_tes
193199 test_collection ["summaries" ] = coll ["summaries" ]
194200 await create_collection (txn_client , test_collection )
195201
202+ await refresh_indices (txn_client )
203+
196204 # Test free text search for "sentinel"
197205 resp = await app_client .get (
198206 "/collections" ,
@@ -229,10 +237,10 @@ async def test_collections_free_text_search_get(app_client, txn_client, load_tes
229237
230238
231239@pytest .mark .asyncio
232- async def test_collections_filter_search (app_client , txn_client , load_test_data ):
240+ async def test_collections_filter_search (app_client , txn_client , ctx ):
233241 """Verify GET /collections honors the filter parameter for structured search."""
234242 # Create multiple collections with different content
235- base_collection = load_test_data ( "test_collection.json" )
243+ base_collection = ctx . collection
236244
237245 # Use unique prefixes to avoid conflicts between tests
238246 test_prefix = f"filter-{ uuid .uuid4 ().hex [:8 ]} "
@@ -313,3 +321,123 @@ async def test_collections_filter_search(app_client, txn_client, load_test_data)
313321 assert (
314322 len (found_collections ) >= 1
315323 ), f"Expected at least 1 collection with ID { test_collection_id } using LIKE filter"
324+
325+
326+ @pytest .mark .asyncio
327+ async def test_collections_query_extension (app_client , txn_client , ctx ):
328+ """Verify GET /collections honors the query extension."""
329+ # Create multiple collections with different content
330+ base_collection = ctx .collection
331+ # Use unique prefixes to avoid conflicts between tests
332+ test_prefix = f"query-ext-{ uuid .uuid4 ().hex [:8 ]} "
333+
334+ # Create collections with different content to test query extension
335+ test_collections = [
336+ {
337+ "id" : f"{ test_prefix } -sentinel" ,
338+ "title" : "Sentinel-2 Collection" ,
339+ "description" : "Collection of Sentinel-2 data" ,
340+ "summaries" : {"platform" : ["sentinel-2a" , "sentinel-2b" ]},
341+ },
342+ {
343+ "id" : f"{ test_prefix } -landsat" ,
344+ "title" : "Landsat Collection" ,
345+ "description" : "Collection of Landsat data" ,
346+ "summaries" : {"platform" : ["landsat-8" , "landsat-9" ]},
347+ },
348+ {
349+ "id" : f"{ test_prefix } -modis" ,
350+ "title" : "MODIS Collection" ,
351+ "description" : "Collection of MODIS data" ,
352+ "summaries" : {"platform" : ["terra" , "aqua" ]},
353+ },
354+ ]
355+
356+ for i , coll in enumerate (test_collections ):
357+ test_collection = base_collection .copy ()
358+ test_collection ["id" ] = coll ["id" ]
359+ test_collection ["title" ] = coll ["title" ]
360+ test_collection ["description" ] = coll ["description" ]
361+ test_collection ["summaries" ] = coll ["summaries" ]
362+ await create_collection (txn_client , test_collection )
363+
364+ await refresh_indices (txn_client )
365+
366+ # Test query extension for exact ID match
367+ import json
368+
369+ # Use the exact ID that was created
370+ sentinel_id = f"{ test_prefix } -sentinel"
371+ print (f"Searching for ID: { sentinel_id } " )
372+
373+ query = {"id" : {"eq" : sentinel_id }}
374+
375+ resp = await app_client .get (
376+ "/collections" ,
377+ params = [("query" , json .dumps (query ))],
378+ )
379+ assert resp .status_code == 200
380+ resp_json = resp .json ()
381+
382+ # Filter collections to only include the ones we created for this test
383+ found_collections = [
384+ c for c in resp_json ["collections" ] if c ["id" ].startswith (test_prefix )
385+ ]
386+
387+ # Should only find the sentinel collection
388+ assert len (found_collections ) == 1
389+ assert found_collections [0 ]["id" ] == f"{ test_prefix } -sentinel"
390+
391+ # Test query extension with equal operator on ID
392+ query = {"id" : {"eq" : f"{ test_prefix } -sentinel" }}
393+
394+ resp = await app_client .get (
395+ "/collections" ,
396+ params = [("query" , json .dumps (query ))],
397+ )
398+ assert resp .status_code == 200
399+ resp_json = resp .json ()
400+
401+ # Filter collections to only include the ones we created for this test
402+ found_collections = [
403+ c for c in resp_json ["collections" ] if c ["id" ].startswith (test_prefix )
404+ ]
405+ found_ids = [c ["id" ] for c in found_collections ]
406+
407+ # Should find landsat and modis collections but not sentinel
408+ assert len (found_collections ) == 1
409+ assert f"{ test_prefix } -sentinel" in found_ids
410+ assert f"{ test_prefix } -landsat" not in found_ids
411+ assert f"{ test_prefix } -modis" not in found_ids
412+
413+ # Test query extension with not-equal operator on ID
414+ query = {"id" : {"neq" : f"{ test_prefix } -sentinel" }}
415+
416+ print (f"\n Testing neq query: { query } " )
417+ print (f"JSON query: { json .dumps (query )} " )
418+
419+ resp = await app_client .get (
420+ "/collections" ,
421+ params = [("query" , json .dumps (query ))],
422+ )
423+ print (f"Response status: { resp .status_code } " )
424+ assert resp .status_code == 200
425+ resp_json = resp .json ()
426+ print (f"Response JSON keys: { resp_json .keys ()} " )
427+ print (f"Number of collections in response: { len (resp_json .get ('collections' , []))} " )
428+
429+ # Print all collection IDs in the response
430+ all_ids = [c ["id" ] for c in resp_json .get ("collections" , [])]
431+ print (f"All collection IDs in response: { all_ids } " )
432+
433+ # Filter collections to only include the ones we created for this test
434+ found_collections = [
435+ c for c in resp_json ["collections" ] if c ["id" ].startswith (test_prefix )
436+ ]
437+ found_ids = [c ["id" ] for c in found_collections ]
438+
439+ # Should find landsat and modis collections but not sentinel
440+ assert len (found_collections ) == 2
441+ assert f"{ test_prefix } -sentinel" not in found_ids
442+ assert f"{ test_prefix } -landsat" in found_ids
443+ assert f"{ test_prefix } -modis" in found_ids
0 commit comments