Files
beets/test/plugins/test_ipfs.py
T

100 lines
3.3 KiB
Python

import os
from pathlib import Path
from unittest.mock import Mock, patch
from beets import library, util
from beets.test import _common
from beets.test.helper import PluginTestCase, PluginTestHelper
from beetsplug.ipfs import IPFSPlugin
@patch("beets.util.command_output", Mock())
class IPFSPluginTest(PluginTestCase):
plugin = "ipfs"
def test_stored_hashes(self):
test_album = self.mk_test_album()
ipfs = IPFSPlugin()
added_albums = ipfs.ipfs_added_albums(self.lib, self.lib.path)
with added_albums.music_dir_context():
added_album = added_albums.get_album(1)
assert added_album.ipfs == test_album.ipfs
found = False
want_item = test_album.items()[2]
for check_item in added_album.items():
if check_item.get("ipfs", with_album=False):
ipfs_item = want_item.filepath.name
want_path = (
Path("/ipfs").resolve() / test_album.ipfs / ipfs_item
)
assert check_item.filepath == want_path
assert (
check_item.get("ipfs", with_album=False)
== want_item.ipfs
)
assert check_item.title == want_item.title
found = True
assert found
def test_get_remote_lib_accepts_library_path(self):
self.lib.path = self.temp_path / "library.db"
remote_dir = self.temp_path / "remotes"
remote_dir.mkdir()
remote_lib = library.Library(remote_dir / "joined.db")
remote_lib._close()
ipfs = IPFSPlugin()
with ipfs.remote_lib(self.lib) as added_lib:
assert added_lib.path == remote_dir / "joined.db"
def mk_test_album(self):
items = [_common.item() for _ in range(3)]
items[0].title = "foo bar"
items[0].artist = "1one"
items[0].album = "baz"
items[0].year = 2001
items[0].comp = True
items[1].title = "baz qux"
items[1].artist = "2two"
items[1].album = "baz"
items[1].year = 2002
items[1].comp = True
items[2].title = "beets 4 eva"
items[2].artist = "3three"
items[2].album = "foo"
items[2].year = 2003
items[2].comp = False
items[2].ipfs = "QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSk"
for item in items:
self.lib.add(item)
album = self.lib.add_album(items)
album.ipfs = "QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSf"
album.store(inherit=False)
return album
class TestIPFSPlay(PluginTestHelper):
plugin = "ipfs"
db_on_disk = True
def test_ipfs_play(self, monkeypatch):
"""Test that ipfs successfully calls PlayPlugin's play method."""
# do not attempt to actually play the music
monkeypatch.setattr("beetsplug.play.play", lambda *_: None)
# we need some music to play
self.add_album_fixture()
# create remote lib in the expected place,
# see IPFSPlugin._remote_libs_path
remote_dir = Path(os.fsdecode(self.lib.path)).parent / "remotes"
remote_dir.mkdir()
util.copy(self.lib.path, remote_dir / "joined.db")
# check that we can play without any errors
IPFSPlugin().ipfs_play(self.lib, None, [])