Debian Codegraph @

tests/units/input_models/test_system.py

raw symbols SCIP
1 # Copyright (c) 2023-2026 Arista Networks, Inc.
2 # Use of this source code is governed by the Apache License 2.0
3 # that can be found in the LICENSE file.
4 """Tests for anta.input_models.system.py."""
5
6 from __future__ import annotations
7
8 from typing import TYPE_CHECKING
9
10 import pytest
11 from pydantic import ValidationError
12
13 from anta.tests.system import VerifyNTPAssociations
14
15 if TYPE_CHECKING:
16 from anta.input_models.system import NTPPool, NTPServer
17
18
19 class TestVerifyNTPAssociationsInput:
20 """Test anta.tests.system.VerifyNTPAssociations.Input."""
21
22 @pytest.mark.parametrize(
23 ("ntp_servers", "ntp_pool"),
24 [
25 pytest.param([{"server_address": "1.1.1.1", "preferred": True, "stratum": 1}], None, id="valid-ntp-server"),
26 pytest.param(None, {"server_addresses": ["1.1.1.1"], "preferred_stratum_range": [1, 3]}, id="valid-ntp-pool"),
27 ],
28 )
29 def test_valid(self, ntp_servers: list[NTPServer], ntp_pool: NTPPool) -> None:
30 """Test VerifyNTPAssociations.Input valid inputs."""
31 VerifyNTPAssociations.Input(ntp_servers=ntp_servers, ntp_pool=ntp_pool)
32
33 @pytest.mark.parametrize(
34 ("ntp_servers", "ntp_pool"),
35 [
36 pytest.param(
37 [{"server_address": "1.1.1.1", "preferred": True, "stratum": 1}],
38 {"server_addresses": ["1.1.1.1"], "preferred_stratum_range": [1, 3]},
39 id="invalid-both-server-pool",
40 ),
41 pytest.param(None, {"server_addresses": ["1.1.1.1"], "preferred_stratum_range": [1, 3, 6]}, id="invalid-ntp-pool-stratum"),
42 pytest.param(None, None, id="invalid-both-none"),
43 ],
44 )
45 def test_invalid(self, ntp_servers: list[NTPServer], ntp_pool: NTPPool) -> None:
46 """Test VerifyNTPAssociations.Input invalid inputs."""
47 with pytest.raises(ValidationError):
48 VerifyNTPAssociations.Input(ntp_servers=ntp_servers, ntp_pool=ntp_pool)