From fee4a3dd114f15709017f2bc2e1cd38a15ca0566 Mon Sep 17 00:00:00 2001 From: Tim DiLauro Date: Mon, 16 Sep 2024 11:28:18 -0400 Subject: [PATCH] Make library configuration selection predictable for patron auth integration self-tests. (#2058) --- .../api/admin/controller/patron_auth_services.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/palace/manager/api/admin/controller/patron_auth_services.py b/src/palace/manager/api/admin/controller/patron_auth_services.py index 9ae1fd9c87..b5d655470d 100644 --- a/src/palace/manager/api/admin/controller/patron_auth_services.py +++ b/src/palace/manager/api/admin/controller/patron_auth_services.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any +from typing import Any, cast import flask from flask import Response @@ -189,6 +189,11 @@ def run_self_tests(self, integration: IntegrationConfiguration) -> dict[str, Any def get_library_configuration( integration: IntegrationConfiguration, ) -> IntegrationLibraryConfiguration | None: - if not integration.library_configurations: + """Find the first library (lowest id) associated with this service.""" + if not (library_configurations := integration.library_configurations): return None - return integration.library_configurations[0] + # We sort by library id to ensure that the result is predictable. + # We cast the library id to `int`, since mypy doesn't understand the relationship. + return sorted( + library_configurations, key=lambda config: cast(int, config.library_id) + )[0]