From b174d62538802a2e5d87d55c1757bfc0c07b56be Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:30:41 +0000 Subject: [PATCH] Update pytest-httpx requirement from ~=0.33.0 to ~=0.34.0 in the dependencies group (#537) * Update pytest-httpx requirement in the dependencies group Updates the requirements on [pytest-httpx](https://github.com/Colin-b/pytest_httpx) to permit the latest version. Updates `pytest-httpx` to 0.34.0 - [Release notes](https://github.com/Colin-b/pytest_httpx/releases) - [Changelog](https://github.com/Colin-b/pytest_httpx/blob/develop/CHANGELOG.md) - [Commits](https://github.com/Colin-b/pytest_httpx/compare/v0.33.0...v0.34.0) --- updated-dependencies: - dependency-name: pytest-httpx dependency-type: direct:production dependency-group: dependencies ... Signed-off-by: dependabot[bot] * Don't use sets of AnyUrl AnyUrl from pydantic is no longer hashable. --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Casper Welzel Andersen --- optimade_gateway/models/gateways.py | 10 +++++++++- optimade_gateway/models/search.py | 4 ++-- optimade_gateway/mongo/collection.py | 6 +++--- optimade_gateway/queries/params.py | 6 +++--- optimade_gateway/routers/search.py | 25 +++++++++++++++---------- pyproject.toml | 2 +- tests/conftest.py | 2 +- 7 files changed, 34 insertions(+), 21 deletions(-) diff --git a/optimade_gateway/models/gateways.py b/optimade_gateway/models/gateways.py index 1e2f2e4f..ecdcf0b3 100644 --- a/optimade_gateway/models/gateways.py +++ b/optimade_gateway/models/gateways.py @@ -46,7 +46,15 @@ def unique_base_urls(cls, value: list[LinksResource]) -> list[LinksResource]: ) db_base_urls = [_.attributes.base_url for _ in value] - unique_base_urls = set(db_base_urls) + + unique_base_urls = [] + for base_url in db_base_urls: + if base_url is None: + continue + if base_url in unique_base_urls: + continue + unique_base_urls.append(base_url) + if len(db_base_urls) == len(unique_base_urls): return value diff --git a/optimade_gateway/models/search.py b/optimade_gateway/models/search.py index 4e21e3c3..2829fdfd 100644 --- a/optimade_gateway/models/search.py +++ b/optimade_gateway/models/search.py @@ -40,7 +40,7 @@ class Search(BaseModel): ] = set() optimade_urls: Annotated[ - set[AnyUrl], + list[AnyUrl], Field( description=( "A list of OPTIMADE base URLs. If a versioned base URL is supplied it " @@ -52,7 +52,7 @@ class Search(BaseModel): "the server logic." ), ), - ] = set() + ] = [] endpoint: Annotated[ str, diff --git a/optimade_gateway/mongo/collection.py b/optimade_gateway/mongo/collection.py index ecf658d9..053ecc12 100644 --- a/optimade_gateway/mongo/collection.py +++ b/optimade_gateway/mongo/collection.py @@ -244,7 +244,7 @@ async def afind( else: single_entry = isinstance(params, SingleEntryQueryParams) - response_fields = criteria.pop("fields", self.all_fields) + response_fields: set[str] = criteria.pop("fields", self.all_fields) results, data_returned, more_data_available = await self._arun_db_query( criteria=criteria, @@ -264,8 +264,8 @@ async def afind( include_fields = ( response_fields - self.resource_mapper.TOP_LEVEL_NON_ATTRIBUTES_FIELDS ) - bad_optimade_fields = set() - bad_provider_fields = set() + bad_optimade_fields: set[str] = set() + bad_provider_fields: set[str] = set() for field in include_fields: if field not in self.resource_mapper.ALL_ATTRIBUTES: if field.startswith("_"): diff --git a/optimade_gateway/queries/params.py b/optimade_gateway/queries/params.py index f85b3c32..46a77211 100644 --- a/optimade_gateway/queries/params.py +++ b/optimade_gateway/queries/params.py @@ -21,7 +21,7 @@ class in `optimade`, which defines the standard entry listing endpoint query the gateway. To be known they need to be registered with the gateway (currently not possible). - optimade_urls (set[AnyUrl]): A list of OPTIMADE base URLs. If a versioned base + optimade_urls (list[AnyUrl]): A list of OPTIMADE base URLs. If a versioned base URL is supplied it will be used as is, as long as it represents a supported version. If an un-versioned base URL, standard version negotiation will be conducted to get the versioned base URL, which will be used as long as it @@ -61,7 +61,7 @@ def __init__( ), ] = set(), optimade_urls: Annotated[ - set[AnyUrl], + list[AnyUrl], Query( description=( "A unique list of OPTIMADE base URLs. If a versioned base URL is " @@ -71,7 +71,7 @@ def __init__( "which will be used as long as it represents a supported version." ), ), - ] = set(), + ] = [], endpoint: Annotated[ str, Query( diff --git a/optimade_gateway/routers/search.py b/optimade_gateway/routers/search.py index b75e5f9b..190bef46 100644 --- a/optimade_gateway/routers/search.py +++ b/optimade_gateway/routers/search.py @@ -84,20 +84,22 @@ async def post_search(request: Request, search: Search) -> QueriesResponseSingle # NOTE: It may be that the final list of base URLs (`base_urls`) contains the same # provider(s), but with differring base URLS, if, for example, a versioned base URL # is supplied. - base_urls: set[AnyUrl] = set() + base_urls: list[AnyUrl] = [] if search.database_ids: databases = await databases_collection.get_multiple( filter={"id": {"$in": await clean_python_types(search.database_ids)}} ) - base_urls |= { - get_resource_attribute(database, "attributes.base_url") - for database in databases - if get_resource_attribute(database, "attributes.base_url") is not None - } + base_urls.extend( + [ + get_resource_attribute(database, "attributes.base_url") + for database in databases + if get_resource_attribute(database, "attributes.base_url") is not None + ] + ) if search.optimade_urls: - base_urls |= {_ for _ in search.optimade_urls if _ is not None} + base_urls.extend([_ for _ in search.optimade_urls if _ is not None]) if not base_urls: msg = "No (valid) OPTIMADE URLs with:" @@ -128,10 +130,13 @@ async def post_search(request: Request, search: Search) -> QueriesResponseSingle elif len(databases) < len(base_urls): # There are unregistered databases, i.e., databases not in the local collection - current_base_urls: set[AnyUrl] = { + current_base_urls: list[AnyUrl] = [ get_resource_attribute(database, "attributes.base_url") for database in databases - } + ] + diff_base_urls = [ + base_url for base_url in base_urls if base_url not in current_base_urls + ] databases.extend( [ LinksResource( @@ -150,7 +155,7 @@ async def post_search(request: Request, search: Search) -> QueriesResponseSingle homepage=None, ), ) - for url in base_urls - current_base_urls + for url in diff_base_urls ] ) else: diff --git a/pyproject.toml b/pyproject.toml index a799a81b..23b8186c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,7 @@ dev = [ "pytest~=8.2", "pytest-asyncio~=0.24.0", "pytest-cov~=6.0", - "pytest-httpx~=0.33.0", + "pytest-httpx~=0.34.0", ] [project.urls] diff --git a/tests/conftest.py b/tests/conftest.py index 8c53eb6f..e1f7f8a2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -262,7 +262,7 @@ async def random_gateway() -> dict: """Get a random gateway currently in the MongoDB""" from optimade_gateway.mongo.database import MONGO_DB - gateway_ids = set() + gateway_ids: set[str] = set() async for gateway in MONGO_DB["gateways"].find( filter={}, projection={"id": True, "_id": False} ):