diracx-testing 0.0.1a25__py3-none-any.whl → 0.0.1a26__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- diracx/testing/utils.py +27 -18
- {diracx_testing-0.0.1a25.dist-info → diracx_testing-0.0.1a26.dist-info}/METADATA +2 -1
- {diracx_testing-0.0.1a25.dist-info → diracx_testing-0.0.1a26.dist-info}/RECORD +5 -5
- {diracx_testing-0.0.1a25.dist-info → diracx_testing-0.0.1a26.dist-info}/WHEEL +0 -0
- {diracx_testing-0.0.1a25.dist-info → diracx_testing-0.0.1a26.dist-info}/top_level.txt +0 -0
diracx/testing/utils.py
CHANGED
@@ -18,8 +18,8 @@ from typing import TYPE_CHECKING, Generator
|
|
18
18
|
from urllib.parse import parse_qs, urljoin, urlparse
|
19
19
|
from uuid import uuid4
|
20
20
|
|
21
|
+
import httpx
|
21
22
|
import pytest
|
22
|
-
import requests
|
23
23
|
|
24
24
|
if TYPE_CHECKING:
|
25
25
|
from diracx.core.settings import DevelopmentSettings
|
@@ -616,7 +616,7 @@ async def test_login(monkeypatch, capfd, cli_env):
|
|
616
616
|
|
617
617
|
poll_attempts = 0
|
618
618
|
|
619
|
-
def fake_sleep(*args, **kwargs):
|
619
|
+
async def fake_sleep(*args, **kwargs):
|
620
620
|
nonlocal poll_attempts
|
621
621
|
|
622
622
|
# Keep track of the number of times this is called
|
@@ -629,13 +629,13 @@ async def test_login(monkeypatch, capfd, cli_env):
|
|
629
629
|
match = re.search(rf"{cli_env['DIRACX_URL']}[^\n]+", captured.out)
|
630
630
|
assert match, captured
|
631
631
|
|
632
|
-
do_device_flow_with_dex(match.group(), cli_env["DIRACX_CA_PATH"])
|
632
|
+
await do_device_flow_with_dex(match.group(), cli_env["DIRACX_CA_PATH"])
|
633
633
|
|
634
634
|
# Ensure we don't poll forever
|
635
635
|
assert poll_attempts <= 100
|
636
636
|
|
637
637
|
# Reduce the sleep duration to zero to speed up the test
|
638
|
-
|
638
|
+
await unpatched_sleep(0.0)
|
639
639
|
|
640
640
|
# We monkeypatch asyncio.sleep to provide a hook to run the actions that
|
641
641
|
# would normally be done by a user. This includes capturing the login URL
|
@@ -650,7 +650,7 @@ async def test_login(monkeypatch, capfd, cli_env):
|
|
650
650
|
|
651
651
|
# Run the login command
|
652
652
|
with monkeypatch.context() as m:
|
653
|
-
m.setattr("
|
653
|
+
m.setattr("diracx.cli.auth.sleep", fake_sleep)
|
654
654
|
await cli.auth.login(vo="diracAdmin", group=None, property=None)
|
655
655
|
captured = capfd.readouterr()
|
656
656
|
assert "Login successful!" in captured.out
|
@@ -664,7 +664,7 @@ async def test_login(monkeypatch, capfd, cli_env):
|
|
664
664
|
return expected_credentials_path.read_text()
|
665
665
|
|
666
666
|
|
667
|
-
def do_device_flow_with_dex(url: str, ca_path: str) -> None:
|
667
|
+
async def do_device_flow_with_dex(url: str, ca_path: str) -> None:
|
668
668
|
"""Do the device flow with dex."""
|
669
669
|
|
670
670
|
class DexLoginFormParser(HTMLParser):
|
@@ -672,10 +672,14 @@ def do_device_flow_with_dex(url: str, ca_path: str) -> None:
|
|
672
672
|
nonlocal action_url
|
673
673
|
if "form" in str(tag):
|
674
674
|
assert action_url is None
|
675
|
-
action_url = urljoin(login_page_url, dict(attrs)["action"])
|
675
|
+
action_url = urljoin(str(login_page_url), dict(attrs)["action"])
|
676
676
|
|
677
|
+
ssl_context = ssl.create_default_context(cafile=ca_path)
|
678
|
+
client_kwargs = dict(verify=ssl_context, follow_redirects=True)
|
677
679
|
# Get the login page
|
678
|
-
|
680
|
+
async with httpx.AsyncClient(**client_kwargs) as client:
|
681
|
+
r = await client.get(url)
|
682
|
+
|
679
683
|
r.raise_for_status()
|
680
684
|
login_page_url = r.url # This is not the same as URL as we redirect to dex
|
681
685
|
login_page_body = r.text
|
@@ -686,19 +690,24 @@ def do_device_flow_with_dex(url: str, ca_path: str) -> None:
|
|
686
690
|
assert action_url is not None, login_page_body
|
687
691
|
|
688
692
|
# Do the actual login
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
693
|
+
async with httpx.AsyncClient(**client_kwargs) as client:
|
694
|
+
r = await client.post(
|
695
|
+
action_url,
|
696
|
+
data={"login": "admin@example.com", "password": "password"},
|
697
|
+
)
|
698
|
+
|
694
699
|
r.raise_for_status()
|
695
700
|
approval_url = r.url # This is not the same as URL as we redirect to dex
|
696
701
|
# Do the actual approval
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
+
|
703
|
+
async with httpx.AsyncClient(**client_kwargs) as client:
|
704
|
+
r = await client.post(
|
705
|
+
approval_url,
|
706
|
+
data={
|
707
|
+
"approval": "approve",
|
708
|
+
"req": parse_qs(urlparse(str(r.url)).query)["req"][0],
|
709
|
+
},
|
710
|
+
)
|
702
711
|
|
703
712
|
# This should have redirected to the DiracX page that shows the login is complete
|
704
713
|
assert "Please close the window" in r.text
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: diracx-testing
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.1a26
|
4
4
|
Summary: TODO
|
5
5
|
License: GPL-3.0-only
|
6
6
|
Classifier: Intended Audience :: Science/Research
|
@@ -14,5 +14,6 @@ Requires-Dist: pytest
|
|
14
14
|
Requires-Dist: pytest-asyncio
|
15
15
|
Requires-Dist: pytest-cov
|
16
16
|
Requires-Dist: pytest-xdist
|
17
|
+
Requires-Dist: httpx
|
17
18
|
Provides-Extra: testing
|
18
19
|
Requires-Dist: diracx-testing; extra == "testing"
|
@@ -4,8 +4,8 @@ diracx/testing/entrypoints.py,sha256=MbH0VLUQz96XPdHzb7XWFwYtWEitAqPrrGM1H1FzDLo
|
|
4
4
|
diracx/testing/mock_osdb.py,sha256=hHuvmQZ3212SaSGX11dQv4ki3ZWsmqJZFYwdn6kg2MA,6029
|
5
5
|
diracx/testing/osdb.py,sha256=m6mUBLnGOoQLTCIBie9P2GhmLMybrgzIrlIYfhF1_Ss,3230
|
6
6
|
diracx/testing/routers.py,sha256=UW-TnikMQgcNxF5sUZD5DWoucGiCpP6s8mYmuahDiSc,979
|
7
|
-
diracx/testing/utils.py,sha256=
|
8
|
-
diracx_testing-0.0.
|
9
|
-
diracx_testing-0.0.
|
10
|
-
diracx_testing-0.0.
|
11
|
-
diracx_testing-0.0.
|
7
|
+
diracx/testing/utils.py,sha256=uPI7UssaOkDvaG3Lq1-A-IJCYvhQ1F_HcQsI6N6O-Bw,24417
|
8
|
+
diracx_testing-0.0.1a26.dist-info/METADATA,sha256=Cye4WM98UB1L1irFN3KHkgq4Iqd74Gxi-Ej8U-kc9fw,634
|
9
|
+
diracx_testing-0.0.1a26.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
10
|
+
diracx_testing-0.0.1a26.dist-info/top_level.txt,sha256=vJx10tdRlBX3rF2Psgk5jlwVGZNcL3m_7iQWwgPXt-U,7
|
11
|
+
diracx_testing-0.0.1a26.dist-info/RECORD,,
|
File without changes
|
File without changes
|