From c3ff333934f0f8854f4ff691e445b44cfb21142a Mon Sep 17 00:00:00 2001 From: BoulderBadgeDad Date: Wed, 10 Jun 2026 15:55:41 -0700 Subject: [PATCH] tests: make the spotify source-adapter test order-independent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit assert against a monkeypatched get_spotify_client sentinel instead of web_server.spotify_client (which isn't a stable singleton across the suite) — same fix already used for the per-profile builder tests. --- tests/test_credentials_endpoints.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/test_credentials_endpoints.py b/tests/test_credentials_endpoints.py index 592b3973..a4dba6b9 100644 --- a/tests/test_credentials_endpoints.py +++ b/tests/test_credentials_endpoints.py @@ -322,17 +322,22 @@ def test_real_session_still_wins_over_background(client, nonadmin_profile): # client_getter; these prove that composition resolves per the current profile # context and stays on the global client for admin (the existing pipelines). -def test_spotify_source_adapter_resolves_per_profile(): +def test_spotify_source_adapter_resolves_per_profile(monkeypatch): from core.playlists.sources.spotify import SpotifyPlaylistSource + from core.metadata import registry + # The real global Spotify client isn't a stable singleton across the suite, + # so pin it to a sentinel for an order-independent identity check. + sentinel = object() + monkeypatch.setattr(registry, 'get_spotify_client', lambda *a, **k: sentinel) + registry.register_profile_spotify_credentials_provider(lambda pid: None) src = SpotifyPlaylistSource(web_server.get_spotify_client_for_profile) - # admin / no override -> the global client (admin pipelines unchanged) - assert src._client() is web_server.spotify_client - # a background owner override flows through the resolver, re-resolved per - # call (unconnected profile -> safe global fallback, never a frozen client) + # admin / no override -> the global resolver (the sentinel) + assert src._client() is sentinel + # unconnected background owner override -> safe global fallback, re-resolved per call from core.profile_context import set_background_profile, reset_background_profile tok = set_background_profile(424242) try: - assert src._client() is web_server.spotify_client + assert src._client() is sentinel finally: reset_background_profile(tok)