rename_cmd converted

This commit is contained in:
bigtedde 2023-07-09 11:57:57 -04:00
parent c68e0b9936
commit 227f43958f
1 changed files with 24 additions and 31 deletions

View File

@ -1,37 +1,30 @@
import unittest
import pytest
from ...constants import * # NOQA
from ...manifest import Manifest
from ...repository import Repository
from . import ArchiverTestCaseBase, RemoteArchiverTestCaseBase, ArchiverTestCaseBinaryBase, RK_ENCRYPTION, BORG_EXES
from . import cmd, create_regular_file, RK_ENCRYPTION
class ArchiverTestCase(ArchiverTestCaseBase):
def test_rename(self):
self.create_regular_file("file1", size=1024 * 80)
self.create_regular_file("dir2/file2", size=1024 * 80)
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(f"--repo={self.repository_location}", "create", "test", "input")
self.cmd(f"--repo={self.repository_location}", "create", "test.2", "input")
self.cmd(f"--repo={self.repository_location}", "extract", "test", "--dry-run")
self.cmd(f"--repo={self.repository_location}", "extract", "test.2", "--dry-run")
self.cmd(f"--repo={self.repository_location}", "rename", "test", "test.3")
self.cmd(f"--repo={self.repository_location}", "extract", "test.2", "--dry-run")
self.cmd(f"--repo={self.repository_location}", "rename", "test.2", "test.4")
self.cmd(f"--repo={self.repository_location}", "extract", "test.3", "--dry-run")
self.cmd(f"--repo={self.repository_location}", "extract", "test.4", "--dry-run")
# Make sure both archives have been renamed
with Repository(self.repository_path) as repository:
manifest = Manifest.load(repository, Manifest.NO_OPERATION_CHECK)
self.assert_equal(len(manifest.archives), 2)
self.assert_in("test.3", manifest.archives)
self.assert_in("test.4", manifest.archives)
class RemoteArchiverTestCase(RemoteArchiverTestCaseBase, ArchiverTestCase):
"""run the same tests, but with a remote repository"""
@unittest.skipUnless("binary" in BORG_EXES, "no borg.exe available")
class ArchiverTestCaseBinary(ArchiverTestCaseBinaryBase, ArchiverTestCase):
"""runs the same tests, but via the borg binary"""
@pytest.mark.parametrize("archivers", ["archiver", "remote_archiver", "binary_archiver"])
def test_rename(archivers, request):
archiver = request.getfixturevalue(archivers)
repo_location, repo_path, input_path = archiver.repository_location, archiver.repository_path, archiver.input_path
create_regular_file(input_path, "file1", size=1024 * 80)
create_regular_file(input_path, "dir2/file2", size=1024 * 80)
cmd(archiver, f"--repo={repo_location}", "rcreate", RK_ENCRYPTION)
cmd(archiver, f"--repo={repo_location}", "create", "test", "input")
cmd(archiver, f"--repo={repo_location}", "create", "test.2", "input")
cmd(archiver, f"--repo={repo_location}", "extract", "test", "--dry-run")
cmd(archiver, f"--repo={repo_location}", "extract", "test.2", "--dry-run")
cmd(archiver, f"--repo={repo_location}", "rename", "test", "test.3")
cmd(archiver, f"--repo={repo_location}", "extract", "test.2", "--dry-run")
cmd(archiver, f"--repo={repo_location}", "rename", "test.2", "test.4")
cmd(archiver, f"--repo={repo_location}", "extract", "test.3", "--dry-run")
cmd(archiver, f"--repo={repo_location}", "extract", "test.4", "--dry-run")
# Make sure both archives have been renamed
with Repository(repo_path) as repository:
manifest = Manifest.load(repository, Manifest.NO_OPERATION_CHECK)
assert len(manifest.archives) == 2
assert "test.3" in manifest.archives
assert "test.4" in manifest.archives