Merging upstream version 0.14.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
082ce481df
commit
2265bd9c67
211 changed files with 12174 additions and 6401 deletions
|
@ -2,6 +2,7 @@
|
|||
# Use of this source code is governed by the Apache License 2.0
|
||||
# that can be found in the LICENSE file.
|
||||
"""ANTA Inventory models unit tests."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
@ -30,7 +31,7 @@ from tests.data.json_data import (
|
|||
from tests.lib.utils import generate_test_ids_dict
|
||||
|
||||
|
||||
class Test_InventoryUnitModels:
|
||||
class TestInventoryUnitModels:
|
||||
"""Test components of AntaInventoryInput model."""
|
||||
|
||||
@pytest.mark.parametrize("test_definition", INVENTORY_MODEL_HOST_VALID, ids=generate_test_ids_dict)
|
||||
|
@ -51,9 +52,8 @@ class Test_InventoryUnitModels:
|
|||
host_inventory = AntaInventoryHost(host=test_definition["input"])
|
||||
except ValidationError as exc:
|
||||
logging.warning("Error: %s", str(exc))
|
||||
assert False
|
||||
else:
|
||||
assert test_definition["input"] == str(host_inventory.host)
|
||||
raise AssertionError from exc
|
||||
assert test_definition["input"] == str(host_inventory.host)
|
||||
|
||||
@pytest.mark.parametrize("test_definition", INVENTORY_MODEL_HOST_INVALID, ids=generate_test_ids_dict)
|
||||
def test_anta_inventory_host_invalid(self, test_definition: dict[str, Any]) -> None:
|
||||
|
@ -110,9 +110,8 @@ class Test_InventoryUnitModels:
|
|||
network_inventory = AntaInventoryNetwork(network=test_definition["input"])
|
||||
except ValidationError as exc:
|
||||
logging.warning("Error: %s", str(exc))
|
||||
assert False
|
||||
else:
|
||||
assert test_definition["input"] == str(network_inventory.network)
|
||||
raise AssertionError from exc
|
||||
assert test_definition["input"] == str(network_inventory.network)
|
||||
|
||||
@pytest.mark.parametrize("test_definition", INVENTORY_MODEL_NETWORK_INVALID, ids=generate_test_ids_dict)
|
||||
def test_anta_inventory_network_invalid(self, test_definition: dict[str, Any]) -> None:
|
||||
|
@ -133,11 +132,11 @@ class Test_InventoryUnitModels:
|
|||
except ValidationError as exc:
|
||||
logging.warning("Error: %s", str(exc))
|
||||
else:
|
||||
assert False
|
||||
raise AssertionError
|
||||
|
||||
@pytest.mark.parametrize("test_definition", INVENTORY_MODEL_NETWORK_CACHE, ids=generate_test_ids_dict)
|
||||
def test_anta_inventory_network_cache(self, test_definition: dict[str, Any]) -> None:
|
||||
"""Test network disable_cache
|
||||
"""Test network disable_cache.
|
||||
|
||||
Test structure:
|
||||
---------------
|
||||
|
@ -176,10 +175,9 @@ class Test_InventoryUnitModels:
|
|||
)
|
||||
except ValidationError as exc:
|
||||
logging.warning("Error: %s", str(exc))
|
||||
assert False
|
||||
else:
|
||||
assert test_definition["input"]["start"] == str(range_inventory.start)
|
||||
assert test_definition["input"]["end"] == str(range_inventory.end)
|
||||
raise AssertionError from exc
|
||||
assert test_definition["input"]["start"] == str(range_inventory.start)
|
||||
assert test_definition["input"]["end"] == str(range_inventory.end)
|
||||
|
||||
@pytest.mark.parametrize("test_definition", INVENTORY_MODEL_RANGE_INVALID, ids=generate_test_ids_dict)
|
||||
def test_anta_inventory_range_invalid(self, test_definition: dict[str, Any]) -> None:
|
||||
|
@ -203,11 +201,11 @@ class Test_InventoryUnitModels:
|
|||
except ValidationError as exc:
|
||||
logging.warning("Error: %s", str(exc))
|
||||
else:
|
||||
assert False
|
||||
raise AssertionError
|
||||
|
||||
@pytest.mark.parametrize("test_definition", INVENTORY_MODEL_RANGE_CACHE, ids=generate_test_ids_dict)
|
||||
def test_anta_inventory_range_cache(self, test_definition: dict[str, Any]) -> None:
|
||||
"""Test range disable_cache
|
||||
"""Test range disable_cache.
|
||||
|
||||
Test structure:
|
||||
---------------
|
||||
|
@ -221,22 +219,23 @@ class Test_InventoryUnitModels:
|
|||
"""
|
||||
if "disable_cache" in test_definition["input"]:
|
||||
range_inventory = AntaInventoryRange(
|
||||
start=test_definition["input"]["start"], end=test_definition["input"]["end"], disable_cache=test_definition["input"]["disable_cache"]
|
||||
start=test_definition["input"]["start"],
|
||||
end=test_definition["input"]["end"],
|
||||
disable_cache=test_definition["input"]["disable_cache"],
|
||||
)
|
||||
else:
|
||||
range_inventory = AntaInventoryRange(start=test_definition["input"]["start"], end=test_definition["input"]["end"])
|
||||
assert test_definition["expected_result"] == range_inventory.disable_cache
|
||||
|
||||
|
||||
class Test_AntaInventoryInputModel:
|
||||
class TestAntaInventoryInputModel:
|
||||
"""Unit test of AntaInventoryInput model."""
|
||||
|
||||
def test_inventory_input_structure(self) -> None:
|
||||
"""Test inventory keys are those expected."""
|
||||
|
||||
inventory = AntaInventoryInput()
|
||||
logging.info("Inventory keys are: %s", str(inventory.model_dump().keys()))
|
||||
assert all(elem in inventory.model_dump().keys() for elem in ["hosts", "networks", "ranges"])
|
||||
assert all(elem in inventory.model_dump() for elem in ["hosts", "networks", "ranges"])
|
||||
|
||||
@pytest.mark.parametrize("inventory_def", INVENTORY_MODEL_VALID, ids=generate_test_ids_dict)
|
||||
def test_anta_inventory_intput_valid(self, inventory_def: dict[str, Any]) -> None:
|
||||
|
@ -265,10 +264,9 @@ class Test_AntaInventoryInputModel:
|
|||
inventory = AntaInventoryInput(**inventory_def["input"])
|
||||
except ValidationError as exc:
|
||||
logging.warning("Error: %s", str(exc))
|
||||
assert False
|
||||
else:
|
||||
logging.info("Checking if all root keys are correctly lodaded")
|
||||
assert all(elem in inventory.model_dump().keys() for elem in inventory_def["input"].keys())
|
||||
raise AssertionError from exc
|
||||
logging.info("Checking if all root keys are correctly lodaded")
|
||||
assert all(elem in inventory.model_dump() for elem in inventory_def["input"])
|
||||
|
||||
@pytest.mark.parametrize("inventory_def", INVENTORY_MODEL_INVALID, ids=generate_test_ids_dict)
|
||||
def test_anta_inventory_intput_invalid(self, inventory_def: dict[str, Any]) -> None:
|
||||
|
@ -294,19 +292,19 @@ class Test_AntaInventoryInputModel:
|
|||
|
||||
"""
|
||||
try:
|
||||
if "hosts" in inventory_def["input"].keys():
|
||||
if "hosts" in inventory_def["input"]:
|
||||
logging.info(
|
||||
"Loading %s into AntaInventoryInput hosts section",
|
||||
str(inventory_def["input"]["hosts"]),
|
||||
)
|
||||
AntaInventoryInput(hosts=inventory_def["input"]["hosts"])
|
||||
if "networks" in inventory_def["input"].keys():
|
||||
if "networks" in inventory_def["input"]:
|
||||
logging.info(
|
||||
"Loading %s into AntaInventoryInput networks section",
|
||||
str(inventory_def["input"]["networks"]),
|
||||
)
|
||||
AntaInventoryInput(networks=inventory_def["input"]["networks"])
|
||||
if "ranges" in inventory_def["input"].keys():
|
||||
if "ranges" in inventory_def["input"]:
|
||||
logging.info(
|
||||
"Loading %s into AntaInventoryInput ranges section",
|
||||
str(inventory_def["input"]["ranges"]),
|
||||
|
@ -315,10 +313,10 @@ class Test_AntaInventoryInputModel:
|
|||
except ValidationError as exc:
|
||||
logging.warning("Error: %s", str(exc))
|
||||
else:
|
||||
assert False
|
||||
raise AssertionError
|
||||
|
||||
|
||||
class Test_InventoryDeviceModel:
|
||||
class TestInventoryDeviceModel:
|
||||
"""Unit test of InventoryDevice model."""
|
||||
|
||||
@pytest.mark.parametrize("test_definition", INVENTORY_DEVICE_MODEL_VALID, ids=generate_test_ids_dict)
|
||||
|
@ -349,12 +347,12 @@ class Test_InventoryDeviceModel:
|
|||
if test_definition["expected_result"] == "invalid":
|
||||
pytest.skip("Not concerned by the test")
|
||||
|
||||
for entity in test_definition["input"]:
|
||||
try:
|
||||
try:
|
||||
for entity in test_definition["input"]:
|
||||
AsyncEOSDevice(**entity)
|
||||
except TypeError as exc:
|
||||
logging.warning("Error: %s", str(exc))
|
||||
assert False
|
||||
except TypeError as exc:
|
||||
logging.warning("Error: %s", str(exc))
|
||||
raise AssertionError from exc
|
||||
|
||||
@pytest.mark.parametrize("test_definition", INVENTORY_DEVICE_MODEL_INVALID, ids=generate_test_ids_dict)
|
||||
def test_inventory_device_invalid(self, test_definition: dict[str, Any]) -> None:
|
||||
|
@ -384,10 +382,10 @@ class Test_InventoryDeviceModel:
|
|||
if test_definition["expected_result"] == "valid":
|
||||
pytest.skip("Not concerned by the test")
|
||||
|
||||
for entity in test_definition["input"]:
|
||||
try:
|
||||
try:
|
||||
for entity in test_definition["input"]:
|
||||
AsyncEOSDevice(**entity)
|
||||
except TypeError as exc:
|
||||
logging.info("Error: %s", str(exc))
|
||||
else:
|
||||
assert False
|
||||
except TypeError as exc:
|
||||
logging.info("Error: %s", str(exc))
|
||||
else:
|
||||
raise AssertionError
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue