Skip to content

Commit 0fa597e

Browse files
committed
Add pytest client plugin
1 parent 765418f commit 0fa597e

File tree

1 file changed

+27
-3
lines changed
  • packages/catalystwan-core/src/catalystwan/core

1 file changed

+27
-3
lines changed
Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,40 @@
1+
import importlib
2+
import logging
13
import os
2-
import pytest
34

4-
from catalystwan.core.session import create_manager_session
5+
import pytest
56
from catalystwan.core.request_adapter import RequestAdapter
7+
from catalystwan.core.session import create_manager_session
8+
9+
logger = logging.getLogger(__name__)
10+
611

712
@pytest.fixture(scope="package")
813
def catalystwan_requests():
914
host = os.environ["SDWAN_HOST"]
1015
port = int(os.environ["SDWAN_PORT"])
1116
username = os.environ["SDWAN_USERNAME"]
1217
password = os.environ["SDWAN_PASSWORD"]
13-
print(f"Connecting to {host}:{port}...")
18+
logger.info(f"Connecting to {host}:{port}...")
1419
with create_manager_session(host, username, password, port) as session:
1520
session.request_timeout = 60
1621
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

Comments
 (0)