Files
galaxy/test/unit/webapps/test_query_params_lists.py
T
Nicola Soranzo 7f89e0eab9 Code cleanups from pyupgrade
Found by running:

```
make pyupgrade
ruff check --fix .
ruff check --preview --unsafe-fixes --select=F401 --fix .
make format
make update-client-api-schema
```

The bulk of the changes are replacements of typing deprecated aliases
such as `Dict` and `List` with the standard library classes. These
aliases became redundant in Python 3.9 when the corresponding
pre-existing classes were enhanced to support `[]`, see
https://docs.python.org/3/library/typing.html#deprecated-aliases

Also:
- Update the `pyupgrade` Makefile target to use `--py38-plus` for the
  packages needed by Pulsar, including the new galaxy-tool-util-models
  package.
2025-07-31 11:17:22 +01:00

55 lines
1.3 KiB
Python

from fastapi.applications import FastAPI
from fastapi.param_functions import (
Depends,
Query,
)
from fastapi.testclient import TestClient
from galaxy.webapps.galaxy.api.common import query_parameter_as_list
app = FastAPI()
client = TestClient(app)
@app.get("/test/get_value_as_list")
async def get_value_as_list(
values: list[str] = Depends(query_parameter_as_list(Query(alias="value"))),
):
return values
def test_single_value():
query_params = "value=val"
result = _get_result_for_params(query_params)
assert len(result) == 1
assert result[0] == "val"
def test_list_as_comma_separated_values():
query_params = "value=val1,val2,val3"
result = _get_result_for_params(query_params)
assert len(result) == 3
assert result[0] == "val1"
assert result[1] == "val2"
assert result[2] == "val3"
def test_list_as_multiple_query_entries():
query_params = "value=val1&value=val2&value=val3"
result = _get_result_for_params(query_params)
assert len(result) == 3
assert result[0] == "val1"
assert result[1] == "val2"
assert result[2] == "val3"
def _get_result_for_params(query_params: str):
response = client.get(f"/test/get_value_as_list?{query_params}")
assert response.status_code == 200
result = response.json()
return result