Files
napalm-yealink/tests/test_fingerprint.py
T
Christian Manivong 4a4f9378c5 style: ruff format and the lint rules of the driver standard
Mechanical: ruff format, and ruff check --fix with the rule set every NAPALM
driver uses (E, F, I, UP, B at line length 100, Python 3.10). What ruff
cannot fix comes in the next commit.
2026-10-23 08:42:02 +02:00

62 lines
2.2 KiB
Python

"""Fingerprint tests for YealinkDriver."""
from napalm_device_types import DeviceTypeDriver, PhoneDriver, role_keys_of
from napalm_yealink import YealinkDriver
def test_yealink_is_device_type_driver():
assert issubclass(YealinkDriver, DeviceTypeDriver)
def test_type_label():
assert YealinkDriver.TYPE_LABEL == "Phone"
def test_vendor():
assert YealinkDriver.VENDOR == "Yealink"
def test_driver_name():
assert YealinkDriver.DRIVER_NAME == "yealink"
def test_snmp_oid_prefix():
assert YealinkDriver.SNMP_OBJECT_ID_PREFIX == "1.3.6.1.4.1.37403"
def test_yealink_pattern_is_decisive_but_not_mandatory():
"""A mandatory rule disqualifies the driver whenever the pattern is absent.
Some Yealink models answer / with a redirect to their API page, whose body
carries no "yealink" anywhere — making the rule mandatory would rule out a
real Yealink phone. It carries decisive weight instead, so a page that does
say "yealink" still wins by a wide margin.
"""
yealink_rules = [r for r in YealinkDriver.HTTP_FINGERPRINT if r.pattern == "yealink"]
assert yealink_rules, "the vendor pattern must be present at all"
assert all(not r.mandatory for r in yealink_rules)
assert max(r.weight for r in yealink_rules) >= 10.0
def test_fingerprint_matches_t58_title():
"""'Yealink T58 Phone' im Titel → mandatory 'yealink' trifft zu."""
combined = "yealink t58 phone nginx "
mandatory = [r for r in YealinkDriver.HTTP_FINGERPRINT if r.mandatory]
assert all(r.pattern in combined for r in mandatory)
def test_fingerprint_scores_nothing_on_a_cisco_page():
"""Without a mandatory rule, what keeps a Cisco phone out is that none of
Yealink's patterns match it at all — so the driver contributes zero score
and never wins."""
combined = "cisco ip phone cp-8841 "
assert not any(r.pattern in combined for r in YealinkDriver.HTTP_FINGERPRINT)
def test_declares_the_phone_role_not_access_point():
"""A desk phone used to inherit AccessPointDriver for want of anywhere
better, which put it in netOrk's wireless page and AP profile pickers."""
assert issubclass(YealinkDriver, PhoneDriver)
assert role_keys_of(YealinkDriver) == ["phone"]