def test_write_and_read_host_attributes( tmp_path: Path, attributes: dict[str, Union[str, list[str]]] ) -> None: folder_path = str(tmp_path) # Used to write the data write_data_folder = hosts_and_folders.Folder( "testfolder", folder_path=folder_path, parent_folder=None ) # Used to read the previously written data read_data_folder = hosts_and_folders.Folder( "testfolder", folder_path=folder_path, parent_folder=None ) # Write data # Note: The create_hosts function modifies the attributes dict, adding a meta_data key inplace write_data_folder.create_hosts([("testhost", attributes, [])]) write_folder_hosts = write_data_folder.hosts() assert len(write_folder_hosts) == 1 # Read data back read_folder_hosts = read_data_folder.hosts() assert len(read_folder_hosts) == 1 for _, host in read_folder_hosts.items(): assert host.attributes() == attributes
def test_create_nested_folders(request_context: None) -> None: with in_chdir("/"): root = hosts_and_folders.Folder.root_folder() folder1 = hosts_and_folders.Folder("folder1", parent_folder=root) folder1.persist_instance() folder2 = hosts_and_folders.Folder("folder2", parent_folder=folder1) folder2.persist_instance() shutil.rmtree(os.path.dirname(folder1.wato_info_path()))
def f(name, title, root_dir="/", parent_folder=None, may_see=True): folder = hosts_and_folders.Folder( name, folder_path=None, parent_folder=parent_folder, title=title, root_dir=root_dir ) # Attribute only used for testing folder._may_see = may_see # type: ignore[attr-defined] return folder
def f(name, title, root_dir='/', parent_folder=None, may_see=True): folder = hosts_and_folders.Folder(name, folder_path=None, parent_folder=parent_folder, title=title, root_dir=root_dir) folder._may_see = may_see return folder
def test_eq_operation(request_context: None) -> None: with in_chdir("/"): root = hosts_and_folders.Folder.root_folder() folder1 = hosts_and_folders.Folder("folder1", parent_folder=root) folder1.persist_instance() folder1_new = hosts_and_folders.Folder("folder1") folder1_new.load_instance() assert folder1 == folder1_new assert id(folder1) != id(folder1_new) assert folder1 in [folder1_new] folder2 = hosts_and_folders.Folder("folder2", parent_folder=folder1) folder2.persist_instance() assert folder1 not in [folder2]