def test_can_finalize(blockchain_path, base_filename, optimized_file_path):
    fss = PathOptimizedFileSystemStorage(base_path=blockchain_path)
    fss.save(base_filename, b'\x08Test')
    assert os_stat(optimized_file_path).st_mode & (stat.S_IWGRP | stat.S_IWUSR | stat.S_IWOTH) != 0

    fss.finalize(base_filename)
    assert os_stat(optimized_file_path).st_mode & (stat.S_IWGRP | stat.S_IWUSR | stat.S_IWOTH) == 0
def test_can_finalize_to_optimized_path(blockchain_path):
    storage = PathOptimizedFileSystemStorage(blockchain_path)
    with patch('thenewboston_node.business_logic.storages.file_system.FileSystemStorage._finalize') as finalize_mock:
        storage.finalize('parent/file.txt')

    finalize_mock.assert_called_once_with(blockchain_path / 'parent/f/i/l/e/file.txt')