Skip to content

Commit

Permalink
Fix validation of searches
Browse files Browse the repository at this point in the history
  • Loading branch information
moradology committed May 2, 2022
1 parent cfd6140 commit 025b8c0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
18 changes: 4 additions & 14 deletions stac_pydantic/api/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def validate_spatial(
v: Intersection,
values: Dict[str, Any],
) -> Intersection:
if v and values["bbox"]:
if v and values["bbox"] is not None:
raise ValueError("intersects and bbox parameters are mutually exclusive")
return v

Expand All @@ -77,10 +77,10 @@ def validate_bbox(cls, v: BBox) -> BBox:
if v:
# Validate order
if len(v) == 4:
xmin, ymin, xmax, ymax = cast(Tuple[int, int, int, int], (*v, 4))
xmin, ymin, xmax, ymax = cast(Tuple[int, int, int, int], v)
else:
xmin, ymin, min_elev, xmax, ymax, max_elev = cast(
Tuple[int, int, int, int, int, int], (*v, 6)
Tuple[int, int, int, int, int, int], v
)
if max_elev < min_elev:
raise ValueError(
Expand Down Expand Up @@ -135,17 +135,7 @@ def spatial_filter(self) -> Optional[_GeometryBase]:
Check for both because the ``bbox`` and ``intersects`` parameters are mutually exclusive.
"""
if self.bbox:
return Polygon(
coordinates=[
[
[self.bbox[0], self.bbox[3]],
[self.bbox[2], self.bbox[3]],
[self.bbox[2], self.bbox[1]],
[self.bbox[0], self.bbox[1]],
[self.bbox[0], self.bbox[3]],
]
]
)
return Polygon.from_bounds(*self.bbox)
if self.intersects:
return self.intersects
else:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_link_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_collection_links():
links = CollectionLinks(
collection_id="collection", base_url="http://stac.com"
).create_links()
for link in links:
for link in links.link_iterator():
assert isinstance(link, Link)
assert link.rel in CollectionLinks._link_members

Expand All @@ -18,7 +18,7 @@ def test_item_links():
links = ItemLinks(
collection_id="collection", item_id="item", base_url="http://stac.com"
).create_links()
for link in links:
for link in links.link_iterator():
assert isinstance(link, Link)
assert link.rel in ItemLinks._link_members

Expand Down
4 changes: 2 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def test_resolve_link():
def test_resolve_links():
links = Links.parse_obj([Link(href="/hello/world", type="image/jpeg", rel="test")])
links.resolve(base_url="http://base_url.com")
for link in links:
for link in links.link_iterator():
assert link.href == "http://base_url.com/hello/world"


Expand All @@ -539,7 +539,7 @@ def test_resolve_pagination_link():
)
links = Links.parse_obj([normal_link, page_link])
links.resolve(base_url="http://base_url.com")
for link in links:
for link in links.link_iterator():
if isinstance(link, PaginationLink):
assert link.href == "http://base_url.com/next/page"

Expand Down

0 comments on commit 025b8c0

Please sign in to comment.