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

Ensure limit 0 searches return 400 #296

Merged
merged 2 commits into from
Nov 24, 2021
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

### Fixed

* The minimum `limit` value for searches is now 1 ([#296](https://github.com/stac-utils/stac-fastapi/pull/296))
* Links stored with Collections and Items (e.g. license links) are now returned with those STAC objects ([#282](https://github.com/stac-utils/stac-fastapi/pull/282))

## [2.2.0]
Expand Down
2 changes: 1 addition & 1 deletion stac_fastapi/pgstac/stac_fastapi/pgstac/types/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class PgstacSearch(Search):
token: Optional[str] = None
datetime: Optional[str] = None
sortby: Any
limit: Optional[conint(ge=0, le=10000)] = 10
limit: Optional[conint(gt=0, le=10000)] = 10

@root_validator(pre=True)
def validate_query_fields(cls, values: Dict) -> Dict:
Expand Down
7 changes: 7 additions & 0 deletions stac_fastapi/pgstac/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ async def test_app_query_extension_limit_1(
assert len(resp_json["features"]) == 1


@pytest.mark.asyncio
async def test_app_query_extension_limit_eq0(app_client):
params = {"limit": 0}
resp = await app_client.post("/search", json=params)
assert resp.status_code == 400


@pytest.mark.asyncio
async def test_app_query_extension_limit_lt0(
load_test_data, app_client, load_test_collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class SQLAlchemySTACSearch(Search):
# Override query extension with supported operators
query: Optional[Dict[Queryables, Dict[Operator, Any]]]
token: Optional[str] = None
limit: Optional[conint(ge=0, le=10000)] = 10
limit: Optional[conint(gt=0, le=10000)] = 10

@root_validator(pre=True)
def validate_query_fields(cls, values: Dict) -> Dict:
Expand Down
6 changes: 6 additions & 0 deletions stac_fastapi/sqlalchemy/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def test_app_query_extension_gte(load_test_data, app_client, postgres_transactio
assert len(resp_json["features"]) == 1


def test_app_query_extension_limit_eq0(app_client):
params = {"limit": 0}
resp = app_client.post("/search", json=params)
assert resp.status_code == 400


def test_app_query_extension_limit_lt0(
load_test_data, app_client, postgres_transactions
):
Expand Down