Skip to content

Commit

Permalink
clean up warnings, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hrodmn committed Oct 10, 2024
1 parent 1296aa7 commit faa8d8c
Show file tree
Hide file tree
Showing 7 changed files with 547 additions and 143 deletions.
7 changes: 3 additions & 4 deletions pystac_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,11 +734,10 @@ def collection_search(
if not (
self.conforms_to(ConformanceClasses.COLLECTION_SEARCH)
or self.conforms_to(ConformanceClasses.COLLECTIONS)
):
) and any([bbox, datetime, q, query, filter, sortby, fields]):
raise DoesNotConformTo(
"COLLECTION_SEARCH",
"COLLECTIONS",
"There is no fallback option available for search.",
"COLLECTION_SEARCH or COLLECTIONS",
"there is no fallback option available for search.",
)

return CollectionSearch(
Expand Down
25 changes: 13 additions & 12 deletions pystac_client/collection_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,20 +281,21 @@ def __init__(
self._collection_search_free_text_enabled = client.conforms_to(
ConformanceClasses.COLLECTION_SEARCH_FREE_TEXT
)
if not self._collection_search_extension_enabled:
warnings.warn(
str(DoesNotConformTo("COLLECTION_SEARCH"))
+ ". Filtering will be performed client-side where only bbox, "
"datetime, and q arguments are supported"
)
self._validate_client_side_args()
else:
if not self._collection_search_free_text_enabled:
if any([bbox, datetime, q, query, filter, sortby, fields]):
if not self._collection_search_extension_enabled:
warnings.warn(
str(DoesNotConformTo("COLLECTION_SEARCH#FREE_TEXT"))
+ ". Free-text search is not enabled for collection search"
"Free-text filters will be applied client-side."
str(DoesNotConformTo("COLLECTION_SEARCH"))
+ ". Filtering will be performed client-side where only bbox, "
"datetime, and q arguments are supported"
)
self._validate_client_side_args()
else:
if not self._collection_search_free_text_enabled:
warnings.warn(
str(DoesNotConformTo("COLLECTION_SEARCH#FREE_TEXT"))
+ ". Free-text search is not enabled for collection search"
"Free-text filters will be applied client-side."
)

else:
self._stac_io = stac_io or StacApiIO()
Expand Down

Large diffs are not rendered by default.

This file was deleted.

17 changes: 17 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,23 @@ def test_collections(self, script_runner: ScriptRunner) -> None:
assert result.success
assert result.stdout.startswith('[{"type": "Collection"')

@pytest.mark.vcr
def test_collection_search(self, script_runner: ScriptRunner) -> None:
args = [
"stac-client",
"collections",
STAC_URLS["EARTH-SEARCH"],
"--q",
"sentinel",
]
with pytest.warns(UserWarning, match="COLLECTION_SEARCH"):
result = script_runner.run(args, print_result=False)

assert result.success

collections = json.loads(result.stdout)
assert len(collections) == 5

@pytest.mark.vcr
def test_save(self, script_runner: ScriptRunner) -> None:
with tempfile.NamedTemporaryFile() as fp:
Expand Down
5 changes: 2 additions & 3 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,8 @@ def test_search_conformance_error(self, api: Client) -> None:

with strict():
with pytest.raises(DoesNotConformTo, match="COLLECTION_SEARCH"):
api.collection_search(limit=10, max_collections=10)
api.collection_search(limit=10, max_collections=10, q="test")

@pytest.mark.vcr
def test_search_conformance_warning(self) -> None:
api = Client.from_file(str(TEST_DATA / "planetary-computer-root.json"))

Expand All @@ -527,7 +526,7 @@ def test_search_conformance_warning(self) -> None:

with strict():
with pytest.warns(UserWarning, match="COLLECTION_SEARCH"):
api.collection_search(limit=10, max_collections=10)
api.collection_search(limit=10, max_collections=10, q="test")

@pytest.mark.vcr
def test_search(self, api: Client) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_collection_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_single_collection(

assert collection.id == COLLECTION_EXAMPLE["id"]

def test_single_item_search(
def test_single_collection_search(
self, benchmark: BenchmarkFixture, single_href: str
) -> None:
search = CollectionSearch(url=COLLECTION_SEARCH_URL, **COLLECTION_EXAMPLE)
Expand Down

0 comments on commit faa8d8c

Please sign in to comment.