1
0
Fork 1
mirror of https://github.com/thatmattlove/hyperglass.git synced 2026-01-17 08:48:05 +00:00
thatmattlove-hyperglass/hyperglass/models/tests/test_util.py
2025-06-14 21:44:20 -04:00

30 lines
904 B
Python

"""Test model utilities."""
# Third Party
import pytest
# Local
from ..util import check_legacy_fields
@pytest.mark.dependency()
def test_check_legacy_fields():
test1 = {"name": "Device A", "nos": "juniper"}
test1_expected = {"name": "Device A", "platform": "juniper"}
test2 = {"name": "Device B", "platform": "juniper"}
test3 = {"name": "Device C"}
test4 = {"name": "Device D", "network": "this is wrong"}
assert set(check_legacy_fields(model="Device", data=test1).keys()) == set(
test1_expected.keys()
), "legacy field not replaced"
assert set(check_legacy_fields(model="Device", data=test2).keys()) == set(test2.keys()), (
"new field not left unmodified"
)
with pytest.raises(ValueError):
check_legacy_fields(model="Device", data=test3)
with pytest.raises(ValueError):
check_legacy_fields(model="Device", data=test4)