|
| 1 | +import importlib |
| 2 | +import logging |
1 | 3 | import os
|
2 |
| -import pytest |
3 | 4 |
|
4 |
| -from catalystwan.core.session import create_manager_session |
| 5 | +import pytest |
5 | 6 | from catalystwan.core.request_adapter import RequestAdapter
|
| 7 | +from catalystwan.core.session import create_manager_session |
| 8 | + |
| 9 | +logger = logging.getLogger(__name__) |
| 10 | + |
6 | 11 |
|
7 | 12 | @pytest.fixture(scope="package")
|
8 | 13 | def catalystwan_requests():
|
9 | 14 | host = os.environ["SDWAN_HOST"]
|
10 | 15 | port = int(os.environ["SDWAN_PORT"])
|
11 | 16 | username = os.environ["SDWAN_USERNAME"]
|
12 | 17 | password = os.environ["SDWAN_PASSWORD"]
|
13 |
| - print(f"Connecting to {host}:{port}...") |
| 18 | + logger.info(f"Connecting to {host}:{port}...") |
14 | 19 | with create_manager_session(host, username, password, port) as session:
|
15 | 20 | session.request_timeout = 60
|
16 | 21 | yield RequestAdapter(session=session)
|
| 22 | + |
| 23 | + |
| 24 | +@pytest.fixture(scope="package") |
| 25 | +def catalystwan_client_factory(catalystwan_requests): |
| 26 | + def wrapper(version: str): |
| 27 | + ver = version.replace(".", "_") |
| 28 | + name = f"catalystwan.versions.v{ver}.api_client" |
| 29 | + logger.info(f"Create {name}.ApiClient") |
| 30 | + module = importlib.import_module(name) |
| 31 | + ApiClient = getattr(module, "ApiClient") |
| 32 | + return ApiClient(catalystwan_requests) |
| 33 | + |
| 34 | + return wrapper |
| 35 | + |
| 36 | + |
| 37 | +@pytest.fixture(scope="package") |
| 38 | +def catalystwan_client(catalystwan_client_factory): |
| 39 | + version = os.environ["SDWAN_VERSION"] |
| 40 | + return catalystwan_client_factory(version) |
0 commit comments