From 97a0bda3b09b609c55bdcc541f7ec6bcb0ce2999 Mon Sep 17 00:00:00 2001 From: Christophe Haen Date: Fri, 17 Jan 2025 16:21:43 +0100 Subject: [PATCH] Monkeypatch cli.auth.sleep --- diracx-cli/src/diracx/cli/auth.py | 3 ++- diracx-testing/src/diracx/testing/utils.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/diracx-cli/src/diracx/cli/auth.py b/diracx-cli/src/diracx/cli/auth.py index e7f2b9aa..d91fdaf2 100644 --- a/diracx-cli/src/diracx/cli/auth.py +++ b/diracx-cli/src/diracx/cli/auth.py @@ -5,6 +5,7 @@ import asyncio import json import os +from asyncio import sleep from datetime import datetime, timedelta, timezone from typing import Annotated, Optional @@ -92,7 +93,7 @@ async def login( if response.error == "authorization_pending": # TODO: Setting more than 5 seconds results in an error # Related to keep-alive disconnects from uvicon (--timeout-keep-alive) - await asyncio.sleep(2) + await sleep(2) continue raise RuntimeError(f"Device flow failed with {response}") break diff --git a/diracx-testing/src/diracx/testing/utils.py b/diracx-testing/src/diracx/testing/utils.py index 20c5a089..45f8ae6b 100644 --- a/diracx-testing/src/diracx/testing/utils.py +++ b/diracx-testing/src/diracx/testing/utils.py @@ -635,7 +635,7 @@ async def fake_sleep(*args, **kwargs): assert poll_attempts <= 100 # Reduce the sleep duration to zero to speed up the test - await unpatched_sleep(0.1) + await unpatched_sleep(0.0) # We monkeypatch asyncio.sleep to provide a hook to run the actions that # would normally be done by a user. This includes capturing the login URL @@ -650,7 +650,7 @@ async def fake_sleep(*args, **kwargs): # Run the login command with monkeypatch.context() as m: - m.setattr("asyncio.sleep", fake_sleep) + m.setattr("diracx.cli.auth.sleep", fake_sleep) await cli.auth.login(vo="diracAdmin", group=None, property=None) captured = capfd.readouterr() assert "Login successful!" in captured.out