| 1 |
"""Tests for the 'parentwork' plugin.""" |
| 2 |
|
| 3 |
import pytest |
| 4 |
|
| 5 |
from beets.library import Item |
| 6 |
from beets.test.helper import PluginTestCase |
| 7 |
|
| 8 |
|
| 9 |
@pytest.mark.integration_test |
| 10 |
class ParentWorkIntegrationTest(PluginTestCase): |
| 11 |
plugin = "parentwork" |
| 12 |
|
| 13 |
# test how it works with real musicbrainz data |
| 14 |
def test_normal_case_real(self): |
| 15 |
item = Item( |
| 16 |
path="/file", |
| 17 |
mb_workid="e27bda6e-531e-36d3-9cd7-b8ebc18e8c53", |
| 18 |
parentwork_workid_current="e27bda6e-531e-36d3-9cd7-b8ebc18e8c53", |
| 19 |
) |
| 20 |
item.add(self.lib) |
| 21 |
|
| 22 |
self.run_command("parentwork") |
| 23 |
|
| 24 |
item.load() |
| 25 |
assert item["mb_parentworkid"] == "32c8943f-1b27-3a23-8660-4567f4847c94" |
| 26 |
|
| 27 |
def test_force_real(self): |
| 28 |
self.config["parentwork"]["force"] = True |
| 29 |
item = Item( |
| 30 |
path="/file", |
| 31 |
mb_workid="e27bda6e-531e-36d3-9cd7-b8ebc18e8c53", |
| 32 |
mb_parentworkid="XXX", |
| 33 |
parentwork_workid_current="e27bda6e-531e-36d3-9cd7-b8ebc18e8c53", |
| 34 |
parentwork="whatever", |
| 35 |
) |
| 36 |
item.add(self.lib) |
| 37 |
|
| 38 |
self.run_command("parentwork") |
| 39 |
|
| 40 |
item.load() |
| 41 |
assert item["mb_parentworkid"] == "32c8943f-1b27-3a23-8660-4567f4847c94" |
| 42 |
|
| 43 |
def test_no_force_real(self): |
| 44 |
self.config["parentwork"]["force"] = False |
| 45 |
item = Item( |
| 46 |
path="/file", |
| 47 |
mb_workid="e27bda6e-531e-36d3-9cd7-b8ebc18e8c53", |
| 48 |
mb_parentworkid="XXX", |
| 49 |
parentwork_workid_current="e27bda6e-531e-36d3-9cd7-b8ebc18e8c53", |
| 50 |
parentwork="whatever", |
| 51 |
) |
| 52 |
item.add(self.lib) |
| 53 |
|
| 54 |
self.run_command("parentwork") |
| 55 |
|
| 56 |
item.load() |
| 57 |
assert item["mb_parentworkid"] == "XXX" |
| 58 |
|
| 59 |
|
| 60 |
class ParentWorkTest(PluginTestCase): |
| 61 |
plugin = "parentwork" |
| 62 |
|
| 63 |
@pytest.fixture(autouse=True) |
| 64 |
def patch_works(self, requests_mock): |
| 65 |
requests_mock.get( |
| 66 |
"/ws/2/work/1?inc=work-rels%2Bartist-rels", |
| 67 |
json={ |
| 68 |
"id": "1", |
| 69 |
"title": "work", |
| 70 |
"work-relations": [ |
| 71 |
{ |
| 72 |
"type": "parts", |
| 73 |
"direction": "backward", |
| 74 |
"work": {"id": "2"}, |
| 75 |
} |
| 76 |
], |
| 77 |
}, |
| 78 |
) |
| 79 |
requests_mock.get( |
| 80 |
"/ws/2/work/2?inc=work-rels%2Bartist-rels", |
| 81 |
json={ |
| 82 |
"id": "2", |
| 83 |
"title": "directparentwork", |
| 84 |
"work-relations": [ |
| 85 |
{ |
| 86 |
"type": "parts", |
| 87 |
"direction": "backward", |
| 88 |
"work": {"id": "3"}, |
| 89 |
} |
| 90 |
], |
| 91 |
}, |
| 92 |
) |
| 93 |
requests_mock.get( |
| 94 |
"/ws/2/work/3?inc=work-rels%2Bartist-rels", |
| 95 |
json={ |
| 96 |
"id": "3", |
| 97 |
"title": "parentwork", |
| 98 |
"artist-relations": [ |
| 99 |
{ |
| 100 |
"type": "composer", |
| 101 |
"artist": { |
| 102 |
"name": "random composer", |
| 103 |
"sort-name": "composer, random", |
| 104 |
}, |
| 105 |
} |
| 106 |
], |
| 107 |
}, |
| 108 |
) |
| 109 |
|
| 110 |
def test_normal_case(self): |
| 111 |
item = Item(path="/file", mb_workid="1", parentwork_workid_current="1") |
| 112 |
item.add(self.lib) |
| 113 |
|
| 114 |
self.run_command("parentwork") |
| 115 |
|
| 116 |
item.load() |
| 117 |
assert item["mb_parentworkid"] == "3" |
| 118 |
|
| 119 |
def test_force(self): |
| 120 |
self.config["parentwork"]["force"] = True |
| 121 |
item = Item( |
| 122 |
path="/file", |
| 123 |
mb_workid="1", |
| 124 |
mb_parentworkid="XXX", |
| 125 |
parentwork_workid_current="1", |
| 126 |
parentwork="parentwork", |
| 127 |
) |
| 128 |
item.add(self.lib) |
| 129 |
|
| 130 |
self.run_command("parentwork") |
| 131 |
|
| 132 |
item.load() |
| 133 |
assert item["mb_parentworkid"] == "3" |
| 134 |
|
| 135 |
def test_no_force(self): |
| 136 |
self.config["parentwork"]["force"] = False |
| 137 |
item = Item( |
| 138 |
path="/file", |
| 139 |
mb_workid="1", |
| 140 |
mb_parentworkid="XXX", |
| 141 |
parentwork_workid_current="1", |
| 142 |
parentwork="parentwork", |
| 143 |
) |
| 144 |
item.add(self.lib) |
| 145 |
|
| 146 |
self.run_command("parentwork") |
| 147 |
|
| 148 |
item.load() |
| 149 |
assert item["mb_parentworkid"] == "XXX" |