def test_can_load(blockchain_path, base_filename, optimized_file_path): binary_data = b'\x08Test' fss = PathOptimizedFileSystemStorage(base_path=blockchain_path) fss.save(base_filename, binary_data) assert os.path.isfile(optimized_file_path) with open(optimized_file_path, 'rb') as fo: assert fo.read() == binary_data assert fss.load(base_filename) == binary_data
def test_compression(blockchain_path, base_filename, optimized_file_path): binary_data = b'A' * 10000 fss = PathOptimizedFileSystemStorage(base_path=blockchain_path, compressors=('gz',)) fss.save(base_filename, binary_data, is_final=True) expected_path = optimized_file_path + '.gz' assert os.path.isfile(expected_path) with gzip.open(expected_path, 'rb') as fo: assert fo.read() == binary_data assert fss.load(base_filename) == binary_data
def test_move(blockchain_path): source = 'file1.txt' destination = 'file2.txt' storage = PathOptimizedFileSystemStorage(blockchain_path, max_depth=5) storage.save(source, b'AAA') assert os.path.isfile(str(blockchain_path / 'f/i/l/e/1/file1.txt')) storage.move(source, destination) assert os.path.isfile(str(blockchain_path / 'f/i/l/e/2/file2.txt')) assert not os.path.isfile(str(blockchain_path / 'f/i/l/e/1/file1.txt')) assert storage.load(destination) == b'AAA'
def test_can_load_from_optimized_path(blockchain_path): storage = PathOptimizedFileSystemStorage(blockchain_path) with patch('thenewboston_node.business_logic.storages.file_system.FileSystemStorage.load') as load_mock: storage.load('parent/file.txt') load_mock.assert_called_once_with('parent/f/i/l/e/file.txt')