def test_extract_fail(to_path, ZipFile, backup, move, exists, rmtree): path = '/var/spool/downloads/content/202ab62b551f6d7fc002f65652525544.zip' target = '/srv/zipballs' extract_path = '/srv/zipballs/202ab62b551f6d7fc002f65652525544' content_path = '/srv/zipballs/202/ab6/2b5/51f/6d7/fc0/02f/656/525/255/44' to_path.return_value = content_path ZipFile.return_value.extractall.side_effect = OSError() exists.return_value = True with pytest.raises(OSError): mod.extract(path, target) ZipFile.assert_called_once_with(path) ZipFile.return_value.extractall.assert_called_once_with(target) exists.assert_called_once_with(extract_path) rmtree.assert_called_once_with(extract_path) assert not backup.called assert not move.called
def test_extract_success(to_path, ZipFile, backup, move, exists, rmtree): path = '/var/spool/downloads/content/202ab62b551f6d7fc002f65652525544.zip' target = '/srv/zipballs' extract_path = '/srv/zipballs/202ab62b551f6d7fc002f65652525544' content_path = '/srv/zipballs/202/ab6/2b5/51f/6d7/fc0/02f/656/525/255/44' to_path.return_value = content_path backup.return_value = '/path/to/cont.backup' exists.return_value = True assert mod.extract(path, target) == content_path ZipFile.assert_called_once_with(path) ZipFile.return_value.extractall.assert_called_once_with(target) backup.assert_called_once_with(content_path) move.assert_called_once_with(extract_path, content_path) exists.assert_called_once_with(backup.return_value) rmtree.assert_called_once_with(backup.return_value)