"""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)