Skip to content

Commit

Permalink
added unit tests for input validators
Browse files Browse the repository at this point in the history
  • Loading branch information
vitthalmagadum committed Jan 20, 2025
1 parent 59b92e1 commit b751f9c
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/units/input_models/routing/test_generic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) 2023-2025 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
"""Tests for anta.input_models.routing.generic.py."""

# pylint: disable=C0302
from __future__ import annotations

from typing import TYPE_CHECKING

import pytest
from pydantic import ValidationError

from anta.tests.routing.generic import VerifyIPv4RouteType

if TYPE_CHECKING:
from anta.input_models.routing.generic import IPv4Routes


class TestVerifyIPv4RouteTypeInput:
"""Test anta.tests.routing.bgp.VerifyIPv4RouteType.Input."""

@pytest.mark.parametrize(
("routes_entries"),
[
pytest.param([{"prefix": "192.168.0.0/24", "vrf": "default", "route_type": "eBGP"}], id="valid"),
],
)
def test_valid(self, routes_entries: list[IPv4Routes]) -> None:
"""Test VerifyIPv4RouteType.Input valid inputs."""
VerifyIPv4RouteType.Input(routes_entries=routes_entries)

@pytest.mark.parametrize(
("routes_entries"),
[
pytest.param([{"prefix": "192.168.0.0/24", "vrf": "default"}], id="invalid"),
],
)
def test_invalid(self, routes_entries: list[IPv4Routes]) -> None:
"""Test VerifyIPv4RouteType.Input invalid inputs."""
with pytest.raises(ValidationError):
VerifyIPv4RouteType.Input(routes_entries=routes_entries)
52 changes: 52 additions & 0 deletions tests/units/input_models/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
from typing import TYPE_CHECKING

import pytest
from pydantic import ValidationError

from anta.input_models.interfaces import InterfaceState
from anta.tests.interfaces import VerifyInterfacesStatus, VerifyLACPInterfacesStatus

if TYPE_CHECKING:
from anta.custom_types import Interface, PortChannelInterface
Expand All @@ -31,3 +33,53 @@ class TestInterfaceState:
def test_valid__str__(self, name: Interface, portchannel: PortChannelInterface | None, expected: str) -> None:
"""Test InterfaceState __str__."""
assert str(InterfaceState(name=name, portchannel=portchannel)) == expected


class TestVerifyInterfacesStatusInput:
"""Test anta.tests.interfaces.VerifyInterfacesStatus.Input."""

@pytest.mark.parametrize(
("interfaces"),
[
pytest.param([{"name": "Ethernet1", "status": "up"}], id="valid"),
],
)
def test_valid(self, interfaces: list[InterfaceState]) -> None:
"""Test VerifyInterfacesStatus.Input valid inputs."""
VerifyInterfacesStatus.Input(interfaces=interfaces)

@pytest.mark.parametrize(
("interfaces"),
[
pytest.param([{"name": "Ethernet1"}], id="invalid"),
],
)
def test_invalid(self, interfaces: list[InterfaceState]) -> None:
"""Test VerifyInterfacesStatus.Input invalid inputs."""
with pytest.raises(ValidationError):
VerifyInterfacesStatus.Input(interfaces=interfaces)


class TestVerifyLACPInterfacesStatusInput:
"""Test anta.tests.interfaces.VerifyLACPInterfacesStatus.Input."""

@pytest.mark.parametrize(
("interfaces"),
[
pytest.param([{"name": "Ethernet1", "portchannel": "Port-Channel100"}], id="valid"),
],
)
def test_valid(self, interfaces: list[InterfaceState]) -> None:
"""Test VerifyLACPInterfacesStatus.Input valid inputs."""
VerifyLACPInterfacesStatus.Input(interfaces=interfaces)

@pytest.mark.parametrize(
("interfaces"),
[
pytest.param([{"name": "Ethernet1"}], id="invalid"),
],
)
def test_invalid(self, interfaces: list[InterfaceState]) -> None:
"""Test VerifyLACPInterfacesStatus.Input invalid inputs."""
with pytest.raises(ValidationError):
VerifyLACPInterfacesStatus.Input(interfaces=interfaces)

0 comments on commit b751f9c

Please sign in to comment.