| 1 |
import shutil |
| 2 |
|
| 3 |
from beets import library |
| 4 |
from beets.test.helper import BeetsTestCase, IOMixin |
| 5 |
|
| 6 |
|
| 7 |
class MoveTest(IOMixin, BeetsTestCase): |
| 8 |
def setUp(self): |
| 9 |
super().setUp() |
| 10 |
|
| 11 |
self.initial_item_path = self.lib_path / "srcfile" |
| 12 |
shutil.copy(self.resource_path, self.initial_item_path) |
| 13 |
|
| 14 |
# Add a file to the library but don't copy it in yet. |
| 15 |
self.i = library.Item.from_path(self.initial_item_path) |
| 16 |
self.lib.add(self.i) |
| 17 |
self.album = self.lib.add_album([self.i]) |
| 18 |
|
| 19 |
# Alternate destination directory. |
| 20 |
self.otherdir = self.temp_path / "testotherdir" |
| 21 |
self.otherdir.mkdir() |
| 22 |
self.item_moved_to = self.otherdir / "Compilations" |
| 23 |
|
| 24 |
def test_move_item(self): |
| 25 |
self.run_command("move") |
| 26 |
self.i.load() |
| 27 |
assert b"libdir" in self.i.path |
| 28 |
assert self.i.filepath.exists() |
| 29 |
assert not self.initial_item_path.exists() |
| 30 |
|
| 31 |
def test_copy_item(self): |
| 32 |
self.run_command("move", "-c") |
| 33 |
self.i.load() |
| 34 |
assert b"libdir" in self.i.path |
| 35 |
assert self.i.filepath.exists() |
| 36 |
assert self.initial_item_path.exists() |
| 37 |
|
| 38 |
def test_move_album(self): |
| 39 |
self.run_command("move", "-a") |
| 40 |
self.i.load() |
| 41 |
assert b"libdir" in self.i.path |
| 42 |
assert self.i.filepath.exists() |
| 43 |
assert not self.initial_item_path.exists() |
| 44 |
|
| 45 |
def test_copy_album(self): |
| 46 |
self.run_command("move", "-a", "-c") |
| 47 |
self.i.load() |
| 48 |
assert b"libdir" in self.i.path |
| 49 |
assert self.i.filepath.exists() |
| 50 |
assert self.initial_item_path.exists() |
| 51 |
|
| 52 |
def test_move_item_custom_dir(self): |
| 53 |
self.run_command("move", "--dest", str(self.otherdir)) |
| 54 |
self.i.load() |
| 55 |
assert b"testotherdir" in self.i.path |
| 56 |
assert self.i.filepath.exists() |
| 57 |
assert not self.initial_item_path.exists() |
| 58 |
|
| 59 |
def test_move_album_custom_dir(self): |
| 60 |
self.run_command("move", "-a", "--dest", str(self.otherdir)) |
| 61 |
self.i.load() |
| 62 |
assert b"testotherdir" in self.i.path |
| 63 |
assert self.i.filepath.exists() |
| 64 |
assert not self.initial_item_path.exists() |
| 65 |
|
| 66 |
def test_move_album_custom_dir_timid(self): |
| 67 |
self.io.addinput("s") # select |
| 68 |
self.io.addinput("y") # yes |
| 69 |
self.run_command("move", "-a", "--dest", str(self.otherdir), "-t") |
| 70 |
self.i.load() |
| 71 |
assert b"testotherdir" in self.i.path |
| 72 |
assert self.i.filepath.exists() |
| 73 |
assert not self.initial_item_path.exists() |
| 74 |
|
| 75 |
def test_pretend_move_item(self): |
| 76 |
self.run_command("move", "--dest", str(self.otherdir), "-p") |
| 77 |
self.i.load() |
| 78 |
assert self.i.filepath == self.initial_item_path |
| 79 |
|
| 80 |
def test_pretend_move_album(self): |
| 81 |
self.run_command("move", "-a", "-p") |
| 82 |
self.i.load() |
| 83 |
assert self.i.filepath == self.initial_item_path |
| 84 |
|
| 85 |
def test_export_item_custom_dir(self): |
| 86 |
self.run_command("move", "--dest", str(self.otherdir), "-e") |
| 87 |
self.i.load() |
| 88 |
assert self.i.filepath == self.initial_item_path |
| 89 |
assert self.item_moved_to.exists() |
| 90 |
|
| 91 |
def test_export_album_custom_dir(self): |
| 92 |
self.run_command("move", "--dest", str(self.otherdir), "-a", "-e") |
| 93 |
self.i.load() |
| 94 |
assert self.i.filepath == self.initial_item_path |
| 95 |
assert self.item_moved_to.exists() |
| 96 |
|
| 97 |
def test_pretend_export_item(self): |
| 98 |
self.run_command("move", "--dest", str(self.otherdir), "-e", "-p") |
| 99 |
self.i.load() |
| 100 |
assert self.i.filepath == self.initial_item_path |
| 101 |
assert not self.item_moved_to.exists() |
| 102 |
|
| 103 |
def test_move_missing_singleton_continues(self): |
| 104 |
self.i.load() |
| 105 |
old_path = self.i.filepath |
| 106 |
old_path.unlink() |
| 107 |
self.run_command("move") |
| 108 |
self.i.load() |
| 109 |
assert self.i.filepath == old_path |
| 110 |
|
| 111 |
def test_move_album_with_missing_track(self): |
| 112 |
self.i.load() |
| 113 |
old_i_path = self.i.filepath |
| 114 |
old_i_path.unlink() |
| 115 |
|
| 116 |
i2_path = self.lib_path / "srcfile2" |
| 117 |
shutil.copy(self.resource_path, i2_path) |
| 118 |
i2 = library.Item.from_path(i2_path) |
| 119 |
self.lib.add(i2) |
| 120 |
i2.album_id = self.album.id |
| 121 |
i2.store() |
| 122 |
|
| 123 |
self.run_command("move", "-a") |
| 124 |
self.i.load() |
| 125 |
i2.load() |
| 126 |
assert self.i.filepath == old_i_path |
| 127 |
assert i2.filepath.is_relative_to(self.lib_path) |
| 128 |
assert i2.filepath.exists() |
| 129 |
|
| 130 |
def test_move_item_skips_missing_file(self): |
| 131 |
self.i.load() |
| 132 |
old_path = self.i.filepath |
| 133 |
old_path.unlink() |
| 134 |
self.i.move() |
| 135 |
assert self.i.filepath == old_path |