mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 13:07:09 +01:00
first try at mocking get_work_by_id
This commit is contained in:
parent
9c054e9588
commit
e943486da9
1 changed files with 48 additions and 12 deletions
|
|
@ -23,6 +23,42 @@ from test.helper import TestHelper
|
|||
|
||||
from beets.library import Item
|
||||
from beetsplug import parentwork
|
||||
import musicbrainzngs
|
||||
|
||||
work = {'work': {'id': '1',
|
||||
'work-relation-list': [{'type': 'parts',
|
||||
'direction': 'backwards',
|
||||
'id': '2'}],
|
||||
'artist-relation-list': [{'type': 'composer',
|
||||
'artist': {'name':
|
||||
'random composer',
|
||||
'sort-name':
|
||||
'composer, random'}}]}}
|
||||
dp_work = {'work': {'id': '2',
|
||||
'work-relation-list': [{'type': 'parts',
|
||||
'direction': 'backwards',
|
||||
'id': '3'}],
|
||||
'artist-relation-list': [{'type': 'composer',
|
||||
'artist': {'name':
|
||||
'random composer',
|
||||
'sort-name':
|
||||
'composer, random'
|
||||
}}]}}
|
||||
p_work = {'work': {'id': '3',
|
||||
'artist-relation-list': [{'type': 'composer',
|
||||
'artist': {'name':
|
||||
'random composer',
|
||||
'sort-name':
|
||||
'composer, random'}}]}}
|
||||
|
||||
|
||||
def mock_workid_response(mbid):
|
||||
if mbid == '1':
|
||||
return work
|
||||
elif mbid == '2':
|
||||
return dp_work
|
||||
elif mbid == '3':
|
||||
return p_work
|
||||
|
||||
|
||||
class ParentWorkTest(unittest.TestCase, TestHelper):
|
||||
|
|
@ -35,19 +71,21 @@ class ParentWorkTest(unittest.TestCase, TestHelper):
|
|||
self.unload_plugins()
|
||||
self.teardown_beets()
|
||||
|
||||
@unittest.mock.patch('musicbrainzngs.get_work_by_id',
|
||||
side_effect=mock_workid_response)
|
||||
@unittest.skipUnless(
|
||||
os.environ.get('INTEGRATION_TEST', '0') == '1',
|
||||
'integration testing not enabled')
|
||||
def test_normal_case(self):
|
||||
item = Item(path='/file',
|
||||
mb_workid=u'e27bda6e-531e-36d3-9cd7-b8ebc18e8c53')
|
||||
mb_workid='1')
|
||||
item.add(self.lib)
|
||||
|
||||
self.run_command('parentwork')
|
||||
|
||||
item.load()
|
||||
self.assertEqual(item['mb_parentworkid'],
|
||||
u'32c8943f-1b27-3a23-8660-4567f4847c94')
|
||||
'3')
|
||||
|
||||
@unittest.skipUnless(
|
||||
os.environ.get('INTEGRATION_TEST', '0') == '1',
|
||||
|
|
@ -55,7 +93,7 @@ class ParentWorkTest(unittest.TestCase, TestHelper):
|
|||
def test_force(self):
|
||||
self.config['parentwork']['force'] = True
|
||||
item = Item(path='/file',
|
||||
mb_workid=u'e27bda6e-531e-36d3-9cd7-b8ebc18e8c53',
|
||||
mb_workid='1',
|
||||
mb_parentworkid=u'XXX')
|
||||
item.add(self.lib)
|
||||
|
||||
|
|
@ -63,21 +101,20 @@ class ParentWorkTest(unittest.TestCase, TestHelper):
|
|||
|
||||
item.load()
|
||||
self.assertEqual(item['mb_parentworkid'],
|
||||
u'32c8943f-1b27-3a23-8660-4567f4847c94')
|
||||
'3')
|
||||
|
||||
@unittest.skipUnless(
|
||||
os.environ.get('INTEGRATION_TEST', '0') == '1',
|
||||
'integration testing not enabled')
|
||||
def test_no_force(self):
|
||||
self.config['parentwork']['force'] = True
|
||||
item = Item(path='/file', mb_workid=u'e27bda6e-531e-36d3-9cd7-\
|
||||
b8ebc18e8c53', mb_parentworkid=u'XXX')
|
||||
item = Item(path='/file', mb_workid='1', mb_parentworkid=u'XXX')
|
||||
item.add(self.lib)
|
||||
|
||||
self.run_command('parentwork')
|
||||
|
||||
item.load()
|
||||
self.assertEqual(item['mb_parentworkid'], u'XXX')
|
||||
self.assertEqual(item['mb_parentworkid'], '3')
|
||||
|
||||
# test different cases, still with Matthew Passion Ouverture or Mozart
|
||||
# requiem
|
||||
|
|
@ -86,11 +123,10 @@ class ParentWorkTest(unittest.TestCase, TestHelper):
|
|||
os.environ.get('INTEGRATION_TEST', '0') == '1',
|
||||
'integration testing not enabled')
|
||||
def test_direct_parent_work(self):
|
||||
mb_workid = u'2e4a3668-458d-3b2a-8be2-0b08e0d8243a'
|
||||
self.assertEqual(u'f04b42df-7251-4d86-a5ee-67cfa49580d1',
|
||||
parentwork.direct_parent_id(mb_workid)[0])
|
||||
self.assertEqual(u'45afb3b2-18ac-4187-bc72-beb1b1c194ba',
|
||||
parentwork.work_parent_id(mb_workid)[0])
|
||||
self.assertEqual('2',
|
||||
parentwork.direct_parent_id('1')[0])
|
||||
self.assertEqual('3',
|
||||
parentwork.work_parent_id('1')[0])
|
||||
|
||||
|
||||
def suite():
|
||||
|
|
|
|||
Loading…
Reference in a new issue