Skip to content

Commit

Permalink
Monkeypatch cli.auth.sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
chaen committed Jan 17, 2025
1 parent 0b85ed3 commit d139252
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion diracx-cli/src/diracx/cli/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions diracx-testing/src/diracx/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,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
Expand All @@ -640,7 +640,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
Expand Down

0 comments on commit d139252

Please sign in to comment.