"""The SNMP list says each device's state with the shared badge and shows its
readings as stat tiles (#5126)."""
from datetime import datetime, timedelta, timezone
from plugins.snmp.routes import _device_state
from tests._templates import render_plugin_template
from tests.test_style_tokens import hex_colours
async def test_devices_wear_a_status_badge_and_readings_are_tiles(app):
devices = [
{"name": "ups", "host": "10.0.0.9", "oids": [{"oid": "1.3.6", "label": "battery_charge_pct"},
{"oid": "1.3.7", "label": "in_octets"}],
"readings": {"battery_charge_pct": 97.0, "in_octets": 2_500_000.0}, "reach": "up",
"at": datetime.now(timezone.utc) - timedelta(seconds=30)},
{"name": "switch", "host": "10.0.0.11", "oids": [], "readings": {"x": 1.0}, "reach": "stale",
"at": datetime.now(timezone.utc) - timedelta(hours=3)},
{"name": "printer", "host": "10.0.0.10", "oids": [], "readings": {}, "reach": "pending", "at": None},
]
async with app.test_request_context("/plugins/snmp/"):
page = await render_plugin_template(app, "snmp", "snmp/index.html", devices=devices, poll_interval=60)
assert 'Reachable' in page
assert 'No data yet' in page
# Old readings are not "reachable": they say how old they are (#5210).
assert 'badge badge-warn" title="The last reading is from' in page and ">No answer" in page
assert ">3h ago" in page
assert '97' in page and '2.50M' in page
assert 'href="/plugins/snmp/device/ups"' in page
main = page[page.index("