1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
# This file is part of beets.
# Copyright 2017, Dorian Soergel
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
"""Tests for the 'parentwork' plugin."""
from unittest.mock import patch
import pytest
from beets.library import Item
from beets.test.helper import PluginTestCase
from beetsplug import parentwork
work = {
"work": {
"id": "1",
"title": "work",
"work-relation-list": [
{"type": "parts", "direction": "backward", "work": {"id": "2"}}
],
"artist-relation-list": [
{
"type": "composer",
"artist": {
"name": "random composer",
"sort-name": "composer, random",
},
}
],
}
}
dp_work = {
"work": {
"id": "2",
"title": "directparentwork",
"work-relation-list": [
{"type": "parts", "direction": "backward", "work": {"id": "3"}}
],
"artist-relation-list": [
{
"type": "composer",
"artist": {
"name": "random composer",
"sort-name": "composer, random",
},
}
],
}
}
p_work = {
"work": {
"id": "3",
"title": "parentwork",
"artist-relation-list": [
{
"type": "composer",
"artist": {
"name": "random composer",
"sort-name": "composer, random",
},
}
],
}
}
def mock_workid_response(mbid, includes):
if mbid == "1":
return work
elif mbid == "2":
return dp_work
elif mbid == "3":
return p_work
@pytest.mark.integration_test
class ParentWorkIntegrationTest(PluginTestCase):
plugin = "parentwork"
# test how it works with real musicbrainz data
def test_normal_case_real(self):
item = Item(
path="/file",
mb_workid="e27bda6e-531e-36d3-9cd7-b8ebc18e8c53",
parentwork_workid_current="e27bda6e-531e-36d3-9cd7-b8ebc18e8c53",
)
item.add(self.lib)
self.run_command("parentwork")
item.load()
assert item["mb_parentworkid"] == "32c8943f-1b27-3a23-8660-4567f4847c94"
def test_force_real(self):
self.config["parentwork"]["force"] = True
item = Item(
path="/file",
mb_workid="e27bda6e-531e-36d3-9cd7-b8ebc18e8c53",
mb_parentworkid="XXX",
parentwork_workid_current="e27bda6e-531e-36d3-9cd7-b8ebc18e8c53",
parentwork="whatever",
)
item.add(self.lib)
self.run_command("parentwork")
item.load()
assert item["mb_parentworkid"] == "32c8943f-1b27-3a23-8660-4567f4847c94"
def test_no_force_real(self):
self.config["parentwork"]["force"] = False
item = Item(
path="/file",
mb_workid="e27bda6e-531e-36d3-9cd7-b8ebc18e8c53",
mb_parentworkid="XXX",
parentwork_workid_current="e27bda6e-531e-36d3-9cd7-b8ebc18e8c53",
parentwork="whatever",
)
item.add(self.lib)
self.run_command("parentwork")
item.load()
assert item["mb_parentworkid"] == "XXX"
# test different cases, still with Matthew Passion Ouverture or Mozart
# requiem
def test_direct_parent_work_real(self):
mb_workid = "2e4a3668-458d-3b2a-8be2-0b08e0d8243a"
assert (
"f04b42df-7251-4d86-a5ee-67cfa49580d1"
== parentwork.direct_parent_id(mb_workid)[0]
)
assert (
"45afb3b2-18ac-4187-bc72-beb1b1c194ba"
== parentwork.work_parent_id(mb_workid)[0]
)
class ParentWorkTest(PluginTestCase):
plugin = "parentwork"
def setUp(self):
"""Set up configuration"""
super().setUp()
self.patcher = patch(
"musicbrainzngs.get_work_by_id", side_effect=mock_workid_response
)
self.patcher.start()
def tearDown(self):
super().tearDown()
self.patcher.stop()
def test_normal_case(self):
item = Item(path="/file", mb_workid="1", parentwork_workid_current="1")
item.add(self.lib)
self.run_command("parentwork")
item.load()
assert item["mb_parentworkid"] == "3"
def test_force(self):
self.config["parentwork"]["force"] = True
item = Item(
path="/file",
mb_workid="1",
mb_parentworkid="XXX",
parentwork_workid_current="1",
parentwork="parentwork",
)
item.add(self.lib)
self.run_command("parentwork")
item.load()
assert item["mb_parentworkid"] == "3"
def test_no_force(self):
self.config["parentwork"]["force"] = False
item = Item(
path="/file",
mb_workid="1",
mb_parentworkid="XXX",
parentwork_workid_current="1",
parentwork="parentwork",
)
item.add(self.lib)
self.run_command("parentwork")
item.load()
assert item["mb_parentworkid"] == "XXX"
def test_direct_parent_work(self):
assert "2" == parentwork.direct_parent_id("1")[0]
assert "3" == parentwork.work_parent_id("1")[0]
|