Skip to content

Commit fca828f

Browse files
CMLDEV-727 JWT authentication (#182)
CMLDEV-777 Refactored the configuration handling Reduced complexity of _get_configuration Moved config methods to ClientConfig Resolved some pyats inconsistencies Type annotations in tests
1 parent 546ccf0 commit fca828f

File tree

10 files changed

+365
-326
lines changed

10 files changed

+365
-326
lines changed

tests/conftest.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,51 @@
1818
# limitations under the License.
1919
#
2020

21+
import sys
22+
from collections.abc import Iterator
2123
from functools import partial
2224
from pathlib import Path
23-
from unittest.mock import patch
25+
from unittest.mock import MagicMock, patch
2426

2527
import httpx
2628
import pytest
29+
from respx import MockRouter
2730

2831
from virl2_client.models import authentication
2932
from virl2_client.virl2_client import ClientLibrary
3033

34+
# Patch sys.stdin.isatty to simulate an interactive terminal
35+
sys.stdin.isatty = lambda: True
36+
3137
CURRENT_VERSION = ClientLibrary.VERSION.version_str
3238
FAKE_HOST = "https://0.0.0.0"
3339
FAKE_HOST_API = f"{FAKE_HOST}/api/v0/"
3440

3541

36-
def client_library_patched_system_info(version):
42+
def client_library_patched_system_info(version: str) -> Iterator[MagicMock]:
3743
with patch.object(
3844
ClientLibrary, "system_info", return_value={"version": version, "ready": True}
3945
) as cl:
4046
yield cl
4147

4248

4349
@pytest.fixture
44-
def client_library_server_current():
50+
def client_library_server_current() -> Iterator[MagicMock]:
4551
yield from client_library_patched_system_info(version=CURRENT_VERSION)
4652

4753

4854
@pytest.fixture
49-
def client_library_server_2_0_0():
55+
def client_library_server_2_0_0() -> Iterator[MagicMock]:
5056
yield from client_library_patched_system_info(version="2.0.0")
5157

5258

5359
@pytest.fixture
54-
def client_library_server_2_19_0():
60+
def client_library_server_2_19_0() -> Iterator[MagicMock]:
5561
yield from client_library_patched_system_info(version="2.19.0")
5662

5763

5864
@pytest.fixture
59-
def mocked_session():
65+
def mocked_session() -> Iterator[MagicMock]:
6066
with patch.object(authentication, "CustomClient", autospec=True) as session:
6167
yield session
6268

@@ -86,7 +92,7 @@ def resp_body_from_file(test_data_dir: Path, request: httpx.Request) -> httpx.Re
8692

8793

8894
@pytest.fixture
89-
def respx_mock_with_labs(respx_mock, test_data_dir: Path):
95+
def respx_mock_with_labs(respx_mock: MockRouter, test_data_dir: Path):
9096
"""
9197
A test fixture that provides basic lab data with respx_mock so that unit tests can
9298
call ``client.all_labs`` or ``client.join_existing_lab``. The sample data includes
@@ -96,7 +102,15 @@ def respx_mock_with_labs(respx_mock, test_data_dir: Path):
96102
json={"version": CURRENT_VERSION, "ready": True, "oui": "52:54:00:00:00:00"},
97103
)
98104
respx_mock.post(FAKE_HOST_API + "authenticate").respond(json="BOGUS_TOKEN")
99-
respx_mock.get(FAKE_HOST_API + "authok")
105+
respx_mock.get(FAKE_HOST_API + "authentication").respond(
106+
json={
107+
"username": "username",
108+
"id": "6c7dd461-1cbe-428f-bdd5-545a0d766ed7",
109+
"token": "BOGUS_TOKEN",
110+
"admin": True,
111+
"error": None,
112+
}
113+
)
100114
respx_mock.get(
101115
FAKE_HOST_API + "labs/444a78d1-575c-4746-8469-696e580f17b6/resource_pools"
102116
).respond(json=[])
@@ -164,6 +178,7 @@ def respx_mock_with_labs(respx_mock, test_data_dir: Path):
164178

165179

166180
@pytest.fixture
167-
def client_library(respx_mock_with_labs):
181+
def client_library(respx_mock_with_labs: MockRouter) -> Iterator[ClientLibrary]:
182+
_ = respx_mock_with_labs
168183
client = ClientLibrary(url=FAKE_HOST, username="test", password="pa$$")
169184
yield client

0 commit comments

Comments
 (0)