def test_get_snmp_table(monkeypatch, snmp_info, expected_values): def get_all_snmp_tables(info): backend = SNMPTestBackend(SNMPConfig, logger) if not isinstance(info, list): return snmp_table.get_snmp_table(SectionName("unit_test"), info, backend=backend) return [ snmp_table.get_snmp_table(SectionName("unit_test"), i, backend=backend) for i in info ] assert get_all_snmp_tables(snmp_info) == expected_values # only conduct further tests for legacy spec if (isinstance(snmp_info, SNMPTree) or isinstance(snmp_info, list) and all(isinstance(t, SNMPTree) for t in snmp_info)): return # when converting it to the new SNMPTree object, ... snmp_info_as_tree_list, layout_recovery = _create_snmp_trees(snmp_info) # ... using those to get the snmp data, ... reformatted_values = get_all_snmp_tables(snmp_info_as_tree_list) # ... and then applying the layout recovery function recovered = layout_recovery(reformatted_values) # ... we should get the expected data assert recovered == expected_values
def test_get_snmp_table(monkeypatch, snmp_info, expected_values): monkeypatch.setattr(snmp, "SNMPBackendFactory", _SNMPTestFactory) def get_all_snmp_tables(info): if not isinstance(info, list): return snmp.get_snmp_table(SNMPConfig, "unit-test", info) return [snmp.get_snmp_table(SNMPConfig, "unit-test", i) for i in info] assert get_all_snmp_tables(snmp_info) == expected_values # only conduct further tests for legacy spec if (isinstance(snmp_info, SNMPTree) or isinstance(snmp_info, list) and all(isinstance(t, SNMPTree) for t in snmp_info)): return # when converting it to the new SNMPTree object, ... snmp_info_as_tree_list, layout_recovery = _create_snmp_trees(snmp_info) # ... using those to get the snmp data, ... reformatted_values = get_all_snmp_tables(snmp_info_as_tree_list) # ... and then applying the layout recovery function recovered = layout_recovery(reformatted_values) # ... we should get the expected data assert recovered == expected_values
def test_snmp_tree_tranlation(snmp_info): for info_spec in snmp_info.values(): new_trees, recover_function = _create_snmp_trees(info_spec) assert callable(recover_function) # is tested separately assert isinstance(new_trees, list) assert all(isinstance(tree, SNMPTree) for tree in new_trees)