Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove warning to from_extensions method #776

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Removed

* Remove `warnings` in `CollectionSearchExtension.from_extensions()` methods when passing `unknown` extensions

## [3.0.4] - 2025-01-08

### Removed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Collection-Search extension."""

import warnings
from enum import Enum
from typing import List, Optional, Union

Expand Down Expand Up @@ -79,7 +78,7 @@ def from_extensions(
schema_href: Optional[str] = None,
) -> "CollectionSearchExtension":
"""Create CollectionSearchExtension object from extensions."""
supported_extensions = {
known_extension_conformances = {
"FreeTextExtension": ConformanceClasses.FREETEXT,
"FreeTextAdvancedExtension": ConformanceClasses.FREETEXT,
"QueryExtension": ConformanceClasses.QUERY,
Expand All @@ -92,13 +91,7 @@ def from_extensions(
ConformanceClasses.BASIS,
]
for ext in extensions:
conf = supported_extensions.get(ext.__class__.__name__, None)
if not conf:
warnings.warn(
f"Conformance class for `{ext.__class__.__name__}` extension not found.", # noqa: E501
UserWarning,
)
else:
if conf := known_extension_conformances.get(ext.__class__.__name__, None):
conformance_classes.append(conf)

get_request_model = create_request_model(
Expand Down Expand Up @@ -187,7 +180,7 @@ def from_extensions(
router: Optional[APIRouter] = None,
) -> "CollectionSearchPostExtension":
"""Create CollectionSearchPostExtension object from extensions."""
supported_extensions = {
known_extension_conformances = {
"FreeTextExtension": ConformanceClasses.FREETEXT,
"FreeTextAdvancedExtension": ConformanceClasses.FREETEXT,
"QueryExtension": ConformanceClasses.QUERY,
Expand All @@ -200,13 +193,7 @@ def from_extensions(
ConformanceClasses.BASIS,
]
for ext in extensions:
conf = supported_extensions.get(ext.__class__.__name__, None)
if not conf:
warnings.warn(
f"Conformance class for `{ext.__class__.__name__}` extension not found.", # noqa: E501
UserWarning,
)
else:
if conf := known_extension_conformances.get(ext.__class__.__name__, None):
conformance_classes.append(conf)

get_request_model = create_request_model(
Expand Down
23 changes: 12 additions & 11 deletions stac_fastapi/extensions/tests/test_collection_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,35 +476,36 @@ def test_from_extensions_methods(extensions):


def test_from_extensions_methods_invalid():
"""Should raise warnings for invalid extensions."""
"""Should also work with unknown extensions."""
extensions = [
AggregationExtension(),
]
with pytest.warns((UserWarning)):
ext = CollectionSearchExtension.from_extensions(
extensions,
)
ext = CollectionSearchExtension.from_extensions(
extensions,
)

collection_search = ext.GET()
assert collection_search.__class__.__name__ == "CollectionsGetRequest"
assert hasattr(collection_search, "bbox")
assert hasattr(collection_search, "datetime")
assert hasattr(collection_search, "limit")
assert hasattr(collection_search, "aggregations")
assert ext.conformance_classes == [
ConformanceClasses.COLLECTIONSEARCH,
ConformanceClasses.BASIS,
]

with pytest.warns((UserWarning)):
ext = CollectionSearchPostExtension.from_extensions(
extensions,
client=DummyPostClient(),
settings=ApiSettings(),
)
ext = CollectionSearchPostExtension.from_extensions(
extensions,
client=DummyPostClient(),
settings=ApiSettings(),
)
collection_search = ext.POST()
assert collection_search.__class__.__name__ == "CollectionsPostRequest"
assert hasattr(collection_search, "bbox")
assert hasattr(collection_search, "datetime")
assert hasattr(collection_search, "limit")
assert hasattr(collection_search, "aggregations")
assert ext.conformance_classes == [
ConformanceClasses.COLLECTIONSEARCH,
ConformanceClasses.BASIS,
Expand Down
Loading