fix: resolve per-torrent qb save paths
This commit is contained in:
+47
-7
@@ -1,5 +1,7 @@
|
||||
import tempfile
|
||||
import unittest
|
||||
from dataclasses import replace
|
||||
from pathlib import PurePosixPath
|
||||
from pathlib import Path
|
||||
|
||||
from archive_clients.eviction import (
|
||||
@@ -86,7 +88,7 @@ class EvictionTests(unittest.TestCase):
|
||||
job_id="job-1",
|
||||
resource=evicted,
|
||||
selected_indices=[0, 1],
|
||||
qb_root=self.root,
|
||||
content_root=self.root,
|
||||
store=self.store,
|
||||
)
|
||||
remove_qb_entry(
|
||||
@@ -97,9 +99,9 @@ class EvictionTests(unittest.TestCase):
|
||||
)
|
||||
result = safe_unlink(
|
||||
job_id="job-1",
|
||||
qb_root=self.root,
|
||||
qbittorrent=qb,
|
||||
store=self.store,
|
||||
resource_root=lambda _: self.root,
|
||||
)
|
||||
self.assertTrue((self.root / "tree/shared.bin").exists())
|
||||
self.assertFalse((self.root / "tree/owned.bin").exists())
|
||||
@@ -121,7 +123,7 @@ class EvictionTests(unittest.TestCase):
|
||||
job_id="job-1",
|
||||
resource=evicted,
|
||||
selected_indices=[0],
|
||||
qb_root=self.root,
|
||||
content_root=self.root,
|
||||
store=self.store,
|
||||
)
|
||||
path.unlink()
|
||||
@@ -134,9 +136,9 @@ class EvictionTests(unittest.TestCase):
|
||||
)
|
||||
result = safe_unlink(
|
||||
job_id="job-1",
|
||||
qb_root=self.root,
|
||||
qbittorrent=qb,
|
||||
store=self.store,
|
||||
resource_root=lambda _: self.root,
|
||||
)
|
||||
self.assertTrue(path.exists())
|
||||
self.assertEqual(
|
||||
@@ -152,7 +154,7 @@ class EvictionTests(unittest.TestCase):
|
||||
job_id="job-1",
|
||||
resource=evicted,
|
||||
selected_indices=[0],
|
||||
qb_root=self.root,
|
||||
content_root=self.root,
|
||||
store=self.store,
|
||||
)
|
||||
remove_qb_entry(
|
||||
@@ -163,19 +165,57 @@ class EvictionTests(unittest.TestCase):
|
||||
)
|
||||
first = safe_unlink(
|
||||
job_id="job-1",
|
||||
qb_root=self.root,
|
||||
qbittorrent=qb,
|
||||
store=self.store,
|
||||
resource_root=lambda _: self.root,
|
||||
)
|
||||
second = safe_unlink(
|
||||
job_id="job-1",
|
||||
qb_root=self.root,
|
||||
qbittorrent=qb,
|
||||
store=self.store,
|
||||
resource_root=lambda _: self.root,
|
||||
)
|
||||
self.assertEqual(first, second)
|
||||
self.assertEqual(qb.deleted, ["a" * 40])
|
||||
|
||||
def test_nested_save_path_uses_its_own_root_and_not_a_same_named_peer(self):
|
||||
nested = self.root / "Downloading"
|
||||
nested.mkdir()
|
||||
evicted = replace(
|
||||
normalized("a" * 40, ["resource/file.bin"]),
|
||||
save_path=PurePosixPath("/downloads/Downloading"),
|
||||
)
|
||||
peer = replace(
|
||||
normalized("b" * 40, ["resource/file.bin"]),
|
||||
save_path=PurePosixPath("/downloads"),
|
||||
)
|
||||
nested_file = nested / "resource/file.bin"
|
||||
nested_file.parent.mkdir()
|
||||
nested_file.write_bytes(b"x" * evicted.files[0].logical_bytes)
|
||||
root_file = self.root / "resource/file.bin"
|
||||
root_file.parent.mkdir()
|
||||
root_file.write_bytes(b"x" * peer.files[0].logical_bytes)
|
||||
qb = FakeQB(evicted, [peer])
|
||||
|
||||
verify_and_snapshot(
|
||||
job_id="job-1", resource=evicted, selected_indices=[0],
|
||||
content_root=nested, store=self.store,
|
||||
)
|
||||
remove_qb_entry(
|
||||
job_id="job-1", torrent_hash="a" * 40,
|
||||
qbittorrent=qb, store=self.store,
|
||||
)
|
||||
safe_unlink(
|
||||
job_id="job-1", qbittorrent=qb, store=self.store,
|
||||
resource_root=lambda item: (
|
||||
nested
|
||||
if item.save_path == PurePosixPath("/downloads/Downloading")
|
||||
else self.root
|
||||
),
|
||||
)
|
||||
self.assertFalse(nested_file.exists())
|
||||
self.assertTrue(root_file.exists())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user