@@ -309,11 +309,12 @@ def validate_search(
309
309
errors .append ("/: Link[rel=search] must exist when Item Search is implemented" )
310
310
return
311
311
312
- collections = href_for (links , "data" )
313
- if collections :
312
+ # Collections may not be implemented, so set to None
313
+ # and later get some collection ids another way
314
+ if collections := href_for (links , "data" ):
314
315
collections_url = collections .get ("href" )
315
316
else :
316
- collections_url = f" { root } /collections"
317
+ collections_url = None
317
318
318
319
search_url = search ["href" ]
319
320
r = requests .get (search_url )
@@ -739,16 +740,20 @@ def _validate_search_collections_with_ids(
739
740
def validate_search_collections (
740
741
search_url : str , collections_url : str , post : bool , errors : List [str ]
741
742
):
742
- collections_entity = requests .get (collections_url ).json ()
743
- if isinstance (collections_entity , List ):
744
- errors .append ("/collections entity is an array rather than an object" )
745
- return
746
- collections = collections_entity .get ("collections" )
747
- if not collections :
748
- errors .append ('/collections entity does not contain a "collections" attribute' )
749
- return
750
-
751
- collection_ids = [x ["id" ] for x in collections ]
743
+ if collections_url :
744
+ collections_entity = requests .get (collections_url ).json ()
745
+ if isinstance (collections_entity , List ):
746
+ errors .append ("/collections entity is an array rather than an object" )
747
+ return
748
+ collections = collections_entity .get ("collections" )
749
+ if not collections :
750
+ errors .append ('/collections entity does not contain a "collections" attribute' )
751
+ return
752
+
753
+ collection_ids = [x ["id" ] for x in collections ]
754
+ else : # if Collections is not implemented, get some from search
755
+ r = requests .get (search_url )
756
+ collection_ids = list ({i ["collection" ] for i in r .json ().get ("features" )})
752
757
753
758
_validate_search_collections_with_ids (search_url , collection_ids , post , errors )
754
759
0 commit comments