mirror of
https://github.com/beetbox/beets.git
synced 2026-07-16 16:39:32 -04:00
test: add importer test for fetchart plugin
Test whether fetchart is run during the import phase and, specifically, whether the `fetch_for_asis` setting is honored. Mock boundary is between `FetchArtPlugin` and `ArtSource`, an already-existing internal API boundary.
This commit is contained in:
@@ -1439,6 +1439,10 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
||||
except UnknownPairError as e:
|
||||
raise UserError(e)
|
||||
|
||||
@cached_property
|
||||
def fetch_for_asis(self) -> bool:
|
||||
return self.config["fetch_for_asis"].get(bool)
|
||||
|
||||
@staticmethod
|
||||
def _is_source_file_removal_enabled() -> bool:
|
||||
return config["import"]["delete"].get(bool) or config["import"][
|
||||
@@ -1467,7 +1471,7 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
||||
if task.choice_flag == importer.Action.ASIS:
|
||||
# For as-is imports, don't search Web sources for art,
|
||||
# unless fetch_for_asis is set
|
||||
local = not self.config["fetch_for_asis"]
|
||||
local = not self.fetch_for_asis
|
||||
elif task.choice_flag in (
|
||||
importer.Action.APPLY,
|
||||
importer.Action.RETAG,
|
||||
|
||||
@@ -1,11 +1,66 @@
|
||||
import ctypes
|
||||
import os
|
||||
import sys
|
||||
from typing import Any, ClassVar
|
||||
from unittest import mock
|
||||
|
||||
from beets import util
|
||||
from beets.test.helper import IOMixin, PluginTestHelper
|
||||
from beetsplug.fetchart import FetchArtPlugin, FileSystem
|
||||
from beets import importer, util
|
||||
from beets.test.helper import (
|
||||
AutotagImportHelper,
|
||||
IOMixin,
|
||||
PluginMixin,
|
||||
PluginTestHelper,
|
||||
)
|
||||
from beetsplug.fetchart import CoverArtArchive, FetchArtPlugin, FileSystem
|
||||
|
||||
|
||||
class TestFetchartImport(PluginMixin, AutotagImportHelper):
|
||||
plugin = "fetchart"
|
||||
preload_plugin = False
|
||||
plugin_defaults: ClassVar[Any] = {"sources": ["filesystem", "coverart"]}
|
||||
|
||||
def setup_beets(self):
|
||||
super().setup_beets()
|
||||
|
||||
self.prepare_album_for_import(1)
|
||||
self.setup_importer()
|
||||
|
||||
self.local_art_patcher = mock.patch.object(
|
||||
FileSystem, "get", autospec=True, return_value=iter(())
|
||||
)
|
||||
self.local_art_mock = self.local_art_patcher.start()
|
||||
self.remote_art_patcher = mock.patch.object(
|
||||
CoverArtArchive, "get", autospec=True, return_value=iter(())
|
||||
)
|
||||
self.remote_art_mock = self.remote_art_patcher.start()
|
||||
|
||||
def teardown_beets(self):
|
||||
super().teardown_beets()
|
||||
self.local_art_patcher.stop()
|
||||
self.remote_art_patcher.stop()
|
||||
|
||||
def test_asis_skips_network_sources(self):
|
||||
self.importer.add_choice(importer.Action.ASIS)
|
||||
with self.configure_plugin(self.plugin_defaults):
|
||||
self.importer.run()
|
||||
self.local_art_mock.assert_called()
|
||||
self.remote_art_mock.assert_not_called()
|
||||
|
||||
def test_apply_uses_network_sources(self):
|
||||
self.importer.add_choice(importer.Action.APPLY)
|
||||
with self.configure_plugin(self.plugin_defaults):
|
||||
self.importer.run()
|
||||
self.local_art_mock.assert_called()
|
||||
self.remote_art_mock.assert_called()
|
||||
|
||||
def test_fetch_for_asis_uses_network_sources(self):
|
||||
self.importer.add_choice(importer.Action.ASIS)
|
||||
with self.configure_plugin(
|
||||
self.plugin_defaults | {"fetch_for_asis": True}
|
||||
):
|
||||
self.importer.run()
|
||||
self.local_art_mock.assert_called()
|
||||
self.remote_art_mock.assert_called()
|
||||
|
||||
|
||||
class TestFetchartCli(IOMixin, PluginTestHelper):
|
||||
|
||||
Reference in New Issue
Block a user