Files
napalm-netgear/tests/unit/test_firmware_offer.py
T
Christian Manivong 4ccb2b5879
CI / test (3.10) (push) Successful in 25s
CI / test (3.11) (push) Successful in 23s
CI / test (3.12) (push) Successful in 26s
CI / test (3.10) (pull_request) Successful in 24s
CI / test (3.11) (pull_request) Successful in 23s
CI / test (3.12) (pull_request) Successful in 25s
feat: report the firmware Netgear offers, not a warning (0.4.0)
The Plus driver looked the newest firmware up in Netgear's download
catalogue and named firmware_update_available itself. It now reports
get_firmware_offer() (napalm-device-types 4.16 FirmwareOfferMixin): what
runs, the newest offered, whether that is newer by Netgear's versioning,
and the download link; netOrk names the warning (netOrk #1111). The Smart
driver's empty get_device_warnings goes too. Requires
napalm-device-types 4.16.0.
2026-10-17 13:04:36 +02:00

60 lines
2.0 KiB
Python

"""The newest firmware Netgear offers, as a fact (netOrk #1111).
The Plus driver looked the newest firmware up in Netgear's download catalogue
and named ``firmware_update_available`` itself. It reports the offer now --
what runs, what is offered, whether that is newer by Netgear's versioning --
and the application decides on the warning.
"""
from __future__ import annotations
from types import SimpleNamespace
import pytest
from napalm_netgear import netgear_plus
from napalm_netgear.netgear_plus import NetgearPlusDriver
from napalm_netgear.netgear_smart import NetgearSmartDriver
def _driver(monkeypatch, *, model="GS308E", running="1.00.10", latest="1.00.12"):
d = NetgearPlusDriver("sw", "admin", "pw")
d._connector = SimpleNamespace(switch_model=SimpleNamespace(MODEL_NAME=model))
monkeypatch.setattr(d, "_get_switch_infos", lambda: {"switch_firmware": running})
monkeypatch.setattr(netgear_plus, "_fw_get_latest", lambda m: latest)
return d
def test_a_newer_offer(monkeypatch):
assert _driver(monkeypatch).get_firmware_offer() == {
"current_version": "1.00.10",
"latest_version": "1.00.12",
"newer": True,
"download_url": f"{netgear_plus._FW_CDN_BASE}/GS308E/GS308E_1.00.12.zip",
}
def test_running_the_newest(monkeypatch):
offer = _driver(monkeypatch, running="1.00.12").get_firmware_offer()
assert offer["newer"] is False
@pytest.mark.parametrize(
"kwargs",
[{"latest": None}, {"running": ""}, {"running": "beta"}],
ids=["catalogue-unknown", "no-version", "unparsable"],
)
def test_cannot_tell(monkeypatch, kwargs):
assert _driver(monkeypatch, **kwargs).get_firmware_offer() is None
def test_not_connected_cannot_tell(monkeypatch):
d = _driver(monkeypatch)
d._connector = None
assert d.get_firmware_offer() is None
@pytest.mark.parametrize("cls", [NetgearPlusDriver, NetgearSmartDriver])
def test_no_warnings_of_their_own(cls):
assert "get_device_warnings" not in vars(cls)