From 92240acb5cc600eec60624ece9ed4b9ec43b386f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 23 May 2024 07:06:46 +0200 Subject: Adding upstream version 0.15.0. Signed-off-by: Daniel Baumann --- tests/units/cli/get/test__init__.py | 2 +- tests/units/cli/get/test_commands.py | 2 +- tests/units/cli/get/test_utils.py | 30 +++++++++++++++++++++++++++--- 3 files changed, 29 insertions(+), 5 deletions(-) (limited to 'tests/units/cli/get') diff --git a/tests/units/cli/get/test__init__.py b/tests/units/cli/get/test__init__.py index a6a0c3c..1ef65c2 100644 --- a/tests/units/cli/get/test__init__.py +++ b/tests/units/cli/get/test__init__.py @@ -7,7 +7,7 @@ from __future__ import annotations from typing import TYPE_CHECKING -from anta.cli import anta +from anta.cli._main import anta from anta.cli.utils import ExitCode if TYPE_CHECKING: diff --git a/tests/units/cli/get/test_commands.py b/tests/units/cli/get/test_commands.py index 9edc7c3..e0b17a0 100644 --- a/tests/units/cli/get/test_commands.py +++ b/tests/units/cli/get/test_commands.py @@ -13,7 +13,7 @@ from unittest.mock import ANY, patch import pytest from cvprac.cvp_client_errors import CvpApiError -from anta.cli import anta +from anta.cli._main import anta from anta.cli.utils import ExitCode if TYPE_CHECKING: diff --git a/tests/units/cli/get/test_utils.py b/tests/units/cli/get/test_utils.py index 0dce335..7ce85dc 100644 --- a/tests/units/cli/get/test_utils.py +++ b/tests/units/cli/get/test_utils.py @@ -81,14 +81,15 @@ def test_create_inventory_from_cvp(tmp_path: Path, inventory: list[dict[str, Any @pytest.mark.parametrize( - ("inventory_filename", "ansible_group", "expected_raise", "expected_inv_length"), + ("inventory_filename", "ansible_group", "expected_raise", "expected_log", "expected_inv_length"), [ - pytest.param("ansible_inventory.yml", None, nullcontext(), 7, id="no group"), - pytest.param("ansible_inventory.yml", "ATD_LEAFS", nullcontext(), 4, id="group found"), + pytest.param("ansible_inventory.yml", None, nullcontext(), None, 7, id="no group"), + pytest.param("ansible_inventory.yml", "ATD_LEAFS", nullcontext(), None, 4, id="group found"), pytest.param( "ansible_inventory.yml", "DUMMY", pytest.raises(ValueError, match="Group DUMMY not found in Ansible inventory"), + None, 0, id="group not found", ), @@ -96,6 +97,7 @@ def test_create_inventory_from_cvp(tmp_path: Path, inventory: list[dict[str, Any "empty_ansible_inventory.yml", None, pytest.raises(ValueError, match="Ansible inventory .* is empty"), + None, 0, id="empty inventory", ), @@ -103,19 +105,39 @@ def test_create_inventory_from_cvp(tmp_path: Path, inventory: list[dict[str, Any "wrong_ansible_inventory.yml", None, pytest.raises(ValueError, match="Could not parse"), + None, 0, id="os error inventory", ), + pytest.param( + "ansible_inventory_with_vault.yml", + None, + pytest.raises(ValueError, match="Could not parse"), + "`anta get from-ansible` does not support inline vaulted variables", + 0, + id="Vault variable in inventory", + ), + pytest.param( + "ansible_inventory_unknown_yaml_tag.yml", + None, + pytest.raises(ValueError, match="Could not parse"), + None, + 0, + id="Unknown YAML tag in inventory", + ), ], ) def test_create_inventory_from_ansible( + caplog: pytest.LogCaptureFixture, tmp_path: Path, inventory_filename: Path, ansible_group: str | None, expected_raise: AbstractContextManager[Exception], + expected_log: str | None, expected_inv_length: int, ) -> None: """Test anta.get.utils.create_inventory_from_ansible.""" + # pylint: disable=R0913 target_file = tmp_path / "inventory.yml" inventory_file_path = DATA_DIR / inventory_filename @@ -130,3 +152,5 @@ def test_create_inventory_from_ansible( assert len(inv) == expected_inv_length if not isinstance(expected_raise, nullcontext): assert not target_file.exists() + if expected_log: + assert expected_log in caplog.text -- cgit v1.2.3