first commit
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from librenet_scanner.models import Host
|
||||
from librenet_scanner.visual_identity import (
|
||||
DEVICE_THEME_CANDIDATES,
|
||||
OS_ICON_FILES,
|
||||
device_icon_key_for_host,
|
||||
os_icon_key_for_host,
|
||||
)
|
||||
|
||||
|
||||
class GenericEquipmentIconTests(unittest.TestCase):
|
||||
def test_server_uses_server_class_independent_from_linux(self):
|
||||
host = Host("192.0.2.10", os_name="Debian GNU/Linux 13", device_type="Serveur Linux")
|
||||
self.assertEqual(device_icon_key_for_host(host), "server")
|
||||
self.assertEqual(os_icon_key_for_host(host), "linux")
|
||||
|
||||
def test_nas_is_nas_even_if_linux_underneath(self):
|
||||
host = Host("192.0.2.20", os_name="Linux 6.x", device_type="NAS Synology")
|
||||
self.assertEqual(device_icon_key_for_host(host), "nas")
|
||||
self.assertEqual(os_icon_key_for_host(host), "linux")
|
||||
|
||||
def test_printer_is_printer(self):
|
||||
self.assertEqual(device_icon_key_for_host(Host("192.0.2.30", device_type="Imprimante")), "printer")
|
||||
|
||||
def test_access_point_is_access_point(self):
|
||||
self.assertEqual(device_icon_key_for_host(Host("192.0.2.40", device_type="Point d'accès Wi-Fi")), "access-point")
|
||||
|
||||
def test_switch_is_switch(self):
|
||||
self.assertEqual(device_icon_key_for_host(Host("192.0.2.50", device_type="Switch")), "switch")
|
||||
|
||||
def test_local_host_is_workstation(self):
|
||||
host = Host("192.0.2.60", os_name="Linux", device_type="Ce poste", is_local=True)
|
||||
self.assertEqual(device_icon_key_for_host(host), "workstation")
|
||||
|
||||
|
||||
class GenericOsIconTests(unittest.TestCase):
|
||||
def test_linux_distributions_share_tux_family(self):
|
||||
for name in ("Debian GNU/Linux 13", "Ubuntu 26.04", "OpenWrt 24.10", "Linux 6.12", "Proxmox Linux 6.x"):
|
||||
with self.subTest(name=name):
|
||||
self.assertEqual(os_icon_key_for_host(Host("192.0.2.1", os_name=name)), "linux")
|
||||
|
||||
def test_bsd_family_shares_daemon_icon(self):
|
||||
for name in ("FreeBSD 14", "OpenBSD 7.6", "NetBSD 10", "OPNsense 25"):
|
||||
with self.subTest(name=name):
|
||||
self.assertEqual(os_icon_key_for_host(Host("192.0.2.1", os_name=name)), "bsd")
|
||||
|
||||
def test_unknown_os_uses_other(self):
|
||||
self.assertEqual(os_icon_key_for_host(Host("192.0.2.1")), "other")
|
||||
|
||||
def test_only_generic_os_assets_are_declared(self):
|
||||
self.assertTrue({"linux", "bsd", "windows", "other"}.issubset(set(OS_ICON_FILES)))
|
||||
|
||||
def test_theme_device_classes_have_fallbacks(self):
|
||||
for key, names in DEVICE_THEME_CANDIDATES.items():
|
||||
with self.subTest(key=key):
|
||||
self.assertTrue(names)
|
||||
self.assertTrue(all(names))
|
||||
|
||||
def test_os_assets_exist(self):
|
||||
root = Path(__file__).resolve().parents[1] / "assets" / "icons"
|
||||
for filename in OS_ICON_FILES.values():
|
||||
with self.subTest(filename=filename):
|
||||
self.assertTrue((root / filename).is_file())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user