Files
Christian Manivong 09029ca0a4 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). Mapping and
Iterable come from collections.abc, imports are sorted. What ruff cannot
fix comes in the next commit.
2026-10-23 08:39:45 +02:00

78 lines
2.3 KiB
Python

from napalm_redfish.parsers import parse_account, to_napalm_users
def test_account(rackmount):
acc = parse_account(rackmount("/redfish/v1/AccountService/Accounts/1"))
assert acc == {
"id": "1",
"username": "Administrator",
"role_id": "Administrator",
"enabled": True,
"locked": False,
"account_types": ["Redfish"],
}
def test_account_snmp_user(rackmount):
acc = parse_account(rackmount("/redfish/v1/AccountService/Accounts/2"))
assert acc["username"] == "contoso_employee457"
assert acc["account_types"] == ["Redfish", "SNMP"]
def test_empty_account_slot_is_none():
# iDRAC and Supermicro list every slot, unused ones with an empty UserName.
assert parse_account({"Id": "3", "UserName": "", "Enabled": False, "RoleId": "None"}) is None
assert parse_account({"Id": "4"}) is None
def test_account_defaults():
acc = parse_account({"Id": "2", "UserName": "ADMIN"})
assert acc["enabled"] is None
assert acc["locked"] is None
assert acc["role_id"] is None
assert acc["account_types"] == []
def test_to_napalm_users(rackmount):
accounts = [
parse_account(rackmount(f"/redfish/v1/AccountService/Accounts/{i}")) for i in (1, 2)
]
accounts.append(
{
"id": "3",
"username": "netork",
"role_id": "ReadOnly",
"enabled": True,
"locked": False,
"account_types": [],
}
)
accounts.append(
{
"id": "4",
"username": "ops",
"role_id": "Operator",
"enabled": False,
"locked": False,
"account_types": [],
}
)
accounts.append(
{
"id": "5",
"username": "custom",
"role_id": "OemSpecial",
"enabled": True,
"locked": False,
"account_types": [],
}
)
accounts.append(None)
assert to_napalm_users(accounts) == {
"Administrator": {"level": 15, "password": "", "sshkeys": []},
"contoso_employee457": {"level": 15, "password": "", "sshkeys": []},
"netork": {"level": 1, "password": "", "sshkeys": []},
"ops": {"level": 5, "password": "", "sshkeys": []},
"custom": {"level": 0, "password": "", "sshkeys": []},
}