"""get_snmp_config reports the community the switch lists, never one it made up (#3). It started from "public" and kept it when no table row parsed, so a switch whose community table could not be read reported a running agent with the community "public". The fixture is ``show snmp-server community`` recorded from a JetStream switch: its table starts with an ``Index`` column, which was read as the community. """ from pathlib import Path from unittest.mock import MagicMock import pytest from napalm_tplink_jetstream.tplink_jetstream import TPLinkJetstreamDriver FIXTURES = Path(__file__).parent.parent / "fixtures" SHOW_SNMP_COMMUNITY = (FIXTURES / "jetstream-show-snmp-server-community.txt").read_text() #: The recording without its only row. NO_COMMUNITY = "".join(SHOW_SNMP_COMMUNITY.splitlines(keepends=True)[:2]) def _driver(output: str) -> TPLinkJetstreamDriver: driver = TPLinkJetstreamDriver("10.0.0.30", "admin", "pw") driver._send_command = MagicMock(return_value=output) return driver def test_the_listed_community_is_reported(): config = _driver(SHOW_SNMP_COMMUNITY).get_snmp_config() assert config == {"running": True, "community": "public", "port": 161, "version": "2c"} @pytest.mark.parametrize( "output", [ NO_COMMUNITY, SHOW_SNMP_COMMUNITY.splitlines(keepends=True)[0], # A table without a column headed Name: its rows name no community. SHOW_SNMP_COMMUNITY.replace("Name ", "Comm ", 1), "something the parser does not know\n", ], ) def test_without_a_listed_community_none_is_invented(output): config = _driver(output).get_snmp_config() assert config is not None assert config["community"] != "public" assert config == {"running": False, "community": "", "port": 161, "version": "2c"}