diff --git a/conda-store-server/conda_store_server/_internal/server/views/pagination.py b/conda-store-server/conda_store_server/_internal/server/views/pagination.py index 0f138a0c2..19b62e8bf 100644 --- a/conda-store-server/conda_store_server/_internal/server/views/pagination.py +++ b/conda-store-server/conda_store_server/_internal/server/views/pagination.py @@ -2,7 +2,7 @@ import base64 import operator -from typing import Any +from typing import Any, Optional import pydantic from fastapi import HTTPException @@ -159,7 +159,7 @@ def paginate( class CursorPaginatedArgs(pydantic.BaseModel): limit: int - order: str + order: Optional[str] = None sort_by: list[str] @pydantic.field_validator("sort_by") diff --git a/conda-store-server/tests/_internal/server/views/test_api.py b/conda-store-server/tests/_internal/server/views/test_api.py index d902a1dec..f6557dad8 100644 --- a/conda-store-server/tests/_internal/server/views/test_api.py +++ b/conda-store-server/tests/_internal/server/views/test_api.py @@ -1158,3 +1158,22 @@ def test_api_list_environments_by_namespace_name( ) assert [env.name for env in sorted_envs] == env_names assert [env.namespace.name for env in sorted_envs] == namespace_names + + +def test_api_list_environments_no_qparam( + conda_store_server, + testclient, + seed_conda_store_big, + authenticate, +): + """Test the REST API lists the paginated envs when sorting by namespace.""" + response = testclient.get("api/v1/environment/") + response.raise_for_status() + + model = schema.APIListEnvironment.model_validate(response.json()) + assert model.status == schema.APIStatus.OK + + env_ids = [env.id for env in model.data] + + # Check that the environments are sorted by ID + assert sorted(env_ids) == env_ids