first try at using patch
@@ -19,13 +19,15 @@ from __future__ import division, absolute_import, print_function
import os
import unittest
+from unittest.mock import patch
from test.helper import TestHelper
-from mock import Mock
-import musicbrainzngs
+#from mock import Mock
+#import musicbrainzngs
from beets.library import Item
from beetsplug import parentwork
+
work = {'work': {'id': '1',
'title': 'work',
'work-relation-list': [{'type': 'parts',
@@ -56,15 +58,6 @@ p_work = {'work': {'id': '3',
'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
-
-
class ParentWorkIntegrationTest(unittest.TestCase, TestHelper):
def setUp(self):
"""Set up configuration"""
@@ -145,11 +138,22 @@ class ParentWorkTest(unittest.TestCase, TestHelper):
"""Set up configuration"""
self.setup_beets()
self.load_plugins('parentwork')
- musicbrainzngs.get_work_by_id = Mock(side_effect=mock_workid_response)
+ self.patcher1 = patch('musicbrainzngs.get_work_by_id')
+ mock_workid_response = self.patcher1.start()
+ #musicbrainzngs.get_work_by_id = Mock(side_effect=mock_workid_response)
def tearDown(self):
self.unload_plugins()
self.teardown_beets()
+ self.patcher1.stop()
+
+ def mock_workid_response(self, mbid, includes):
+ if mbid == '1':
+ return work
+ elif mbid == '2':
+ return dp_work
+ elif mbid == '3':
+ return p_work
def test_normal_case(self):
item = Item(path='/file', mb_workid='1', parentwork_workid_current='1')
