Skip to content

Commit

Permalink
don't add standalone recordings
Browse files Browse the repository at this point in the history
  • Loading branch information
dvirtz committed Mar 10, 2024
1 parent 4219d8f commit a4539cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion plugins/add_to_collection/post_save_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def post_save_processor(file: File) -> None:
log.error(f"cannot find collection with id {collection_id}")
return
release_id = file.metadata["musicbrainz_albumid"]
if release_id not in collection.releases:
if release_id and release_id not in collection.releases:
log.debug("Adding release %r to %r", release_id, collection.name)
collection.add_releases(set([release_id]), callback=lambda: None)

Expand Down
23 changes: 20 additions & 3 deletions test/test_add_to_collection.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
from itertools import chain
from test.plugin_test_case import PluginTestCase
from typing import Union
from unittest.mock import ANY, patch

from picard.collection import Collection, user_collections
from picard.file import File
from picard.file import _file_post_save_processors as post_save_processors
from picard.ui.options import _pages as option_pages
from test.plugin_test_case import PluginTestCase


class TestAddToCollection(PluginTestCase):
Expand All @@ -25,10 +26,11 @@ def install_plugin(self) -> None:
"Add to Collection", "add_to_collection"
)

def create_file(self, file_name: str, album_id: str) -> File:
def create_file(self, file_name: str, album_id: Union[str, None] = None) -> File:
file_path = os.path.join(self.tmp_directory, file_name)
file = File(file_path)
file.metadata["musicbrainz_albumid"] = album_id
if album_id:
file.metadata["musicbrainz_albumid"] = album_id
self.tagger.files[file_path] = file
return file

Expand Down Expand Up @@ -119,3 +121,18 @@ def test_no_user_collection(self) -> None:
with patch("picard.collection.Collection.add_releases") as add_releases:
file.save()
add_releases.assert_not_called()

def test_no_release(self) -> None:
self.install_plugin()

self.set_config_values(
setting={
**self.SAVE_FILE_SETTINGS,
"add_to_collection_id": "test_collection_id",
}
)

file = self.create_file(file_name="test.mp3")
with patch("picard.collection.Collection.add_releases") as add_releases:
file.save()
add_releases.assert_not_called()

0 comments on commit a4539cf

Please sign in to comment.