From 0cda04cb4ed8b89e4d1dd72ca972e5d2aa1aa94a Mon Sep 17 00:00:00 2001 From: Roman Dodin Date: Sat, 24 Aug 2024 12:45:11 +0300 Subject: [PATCH] added pytest for ports --- setup.cfg | 4 ++-- test/unit/jsonrpc_client.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 test/unit/jsonrpc_client.py diff --git a/setup.cfg b/setup.cfg index cfd8fc5..e0a0d11 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,8 +21,8 @@ python_files = *_test.py tests.py addopts = - --cov=napalm - --cov-report term-missing + # --cov=napalm + # --cov-report term-missing -vs ; --pylama json_report = report.json diff --git a/test/unit/jsonrpc_client.py b/test/unit/jsonrpc_client.py new file mode 100644 index 0000000..e36d454 --- /dev/null +++ b/test/unit/jsonrpc_client.py @@ -0,0 +1,34 @@ +""" +Determines the JSON-RPC port to use based on the provided configuration. + +Args: + config (dict): A dictionary containing the configuration options. + +Returns: + int: The JSON-RPC port to use. +""" + +import pytest + +from napalm_srlinux.srlinux import NokiaSRLinuxDriver + + +@pytest.fixture +def driver(): + return NokiaSRLinuxDriver("hostname", "username", "password") + + +def test_determine_jsonrpc_port(driver): + # Test default case + assert driver._determine_jsonrpc_port({}) == 443 + + # Test when jsonrpc_port is specified + assert driver._determine_jsonrpc_port({"jsonrpc_port": 8080}) == 8080 + + # Test when insecure is set and jsonrpc_port is not specified + assert driver._determine_jsonrpc_port({"insecure": True}) == 80 + + # Test when both jsonrpc_port and insecure are set + assert ( + driver._determine_jsonrpc_port({"jsonrpc_port": 9000, "insecure": True}) == 9000 + )