57 lines
1.4 KiB
Python
57 lines
1.4 KiB
Python
"""Test validation engine"""
|
|
import pytest
|
|
from app.validation import ConfigValidator
|
|
|
|
|
|
def test_validate_valid_config():
|
|
"""Test validation of valid config"""
|
|
config = {
|
|
"vlans": [{"id": 10, "name": "USERS"}],
|
|
"interfaces": [
|
|
{
|
|
"name": "GigabitEthernet0/1",
|
|
"type": "access",
|
|
"vlan": 10,
|
|
"enabled": True,
|
|
}
|
|
],
|
|
}
|
|
|
|
validator = ConfigValidator()
|
|
errors, warnings = validator.validate(config)
|
|
|
|
assert errors == []
|
|
assert warnings == []
|
|
|
|
|
|
def test_validate_undefined_vlan_reference():
|
|
"""Test error when interface references undefined VLAN"""
|
|
config = {
|
|
"vlans": [{"id": 10, "name": "USERS"}],
|
|
"interfaces": [
|
|
{
|
|
"name": "GigabitEthernet0/1",
|
|
"type": "access",
|
|
"vlan": 99, # Doesn't exist
|
|
"enabled": True,
|
|
}
|
|
],
|
|
}
|
|
|
|
validator = ConfigValidator()
|
|
errors, warnings = validator.validate(config)
|
|
|
|
assert any("undefined VLAN 99" in e["message"] for e in errors)
|
|
|
|
|
|
def test_validate_vlan_out_of_range():
|
|
"""Test error for invalid VLAN ID"""
|
|
config = {
|
|
"vlans": [{"id": 5000, "name": "INVALID"}],
|
|
}
|
|
|
|
validator = ConfigValidator()
|
|
errors, warnings = validator.validate(config)
|
|
|
|
assert any("5000" in e["message"] for e in errors)
|