def test_create_example_files(): """ title: Example test manipulating on filesystem. description: Perform various operations on filesystem. pass_criteria: - System does not crash. - All operations complete successfully. - Data consistency is being preserved. """ with TestRun.step("Create file with content"): file1 = File.create_file("example_file") file1.write("Test file\ncontent line\ncontent") with TestRun.step("Read file content"): content_before_change = file1.read() TestRun.LOGGER.info(f"File content: {content_before_change}") with TestRun.step("Replace single line in file"): fs_utils.replace_in_lines(file1, 'content line', 'replaced line') with TestRun.step("Read file content and check if it changed"): content_after_change = file1.read() if content_before_change == content_after_change: TestRun.fail("Content didn't changed as expected") with TestRun.step("Make copy of the file and check if md5 sum matches"): file2 = file1.copy('/tmp', force=True) if file1.md5sum() != file2.md5sum(): TestRun.fail("md5 sum doesn't match!") with TestRun.step("Change permissions of second file"): file2.chmod_numerical(123) with TestRun.step("Remove second file"): fs_utils.remove(file2.full_path, True) with TestRun.step("List contents of home directory"): dir1 = Directory("~") dir_content = dir1.ls() with TestRun.step("Change permissions of file"): file1.chmod(fs_utils.Permissions['r'] | fs_utils.Permissions['w'], fs_utils.PermissionsUsers(7)) with TestRun.step("Log home directory content"): for item in dir_content: TestRun.LOGGER.info(f"Item {str(item)} - {type(item).__name__}") with TestRun.step("Remove file"): fs_utils.remove(file1.full_path, True)
def test_create_example_files(prepare_and_cleanup): prepare() TestProperties.LOGGER.info("Test run") file1 = File.create_file("example_file") file1.write("Test file\ncontent line\ncontent") content_before_change = file1.read() TestProperties.LOGGER.info(f"File content: {content_before_change}") fs_utils.replace_in_lines(file1, 'content line', 'replaced line') content_after_change = file1.read() assert content_before_change != content_after_change file2 = file1.copy('/tmp', force=True) assert file1.md5sum() == file2.md5sum() file2.chmod_numerical(123) fs_utils.remove(file2.full_path, True) dir1 = Directory("~") dir_content = dir1.ls() file1.chmod(fs_utils.Permissions['r'] | fs_utils.Permissions['w'], fs_utils.PermissionsUsers(7)) for item in dir_content: TestProperties.LOGGER.info(f"Item {str(item)} - {type(item).__name__}") fs_utils.remove(file1.full_path, True)