diff --git a/tests/test_print.py b/tests/test_print.py
index 7c3a005..feeb59a 100755
--- a/tests/test_print.py
+++ b/tests/test_print.py
@@ -93,8 +93,12 @@ class TestPrint(unittest.TestCase):
read = MagicMock(return_value='
'.encode('utf8'))
info = MagicMock()
response_obj = MockResponse()
+ class MockOpener():
+ open = MagicMock(return_value=response_obj)
+ add_handler = MagicMock()
+ opener_obj = MockOpener()
with patch('urllib.request.Request', return_value=request_obj) as request:
- with patch('urllib.request.urlopen', return_value=response_obj) as urlopen:
+ with patch('urllib.request.OpenerDirector', return_value=opener_obj) as opener:
printer.descriptions([0], [{'id': '1', 'magnet': 'dn=name'}], 'example.com')
printer.print.assert_has_calls([call('Description for "name":', color='zebra_1'),call('stuff [link](href)', color='zebra_0')])
@@ -108,8 +112,12 @@ class TestPrint(unittest.TestCase):
read = MagicMock(return_value='1. | filename |
'.encode('utf8'))
info = MagicMock()
response_obj = MockResponse()
+ class MockOpener():
+ open = MagicMock(return_value=response_obj)
+ add_handler = MagicMock()
+ opener_obj = MockOpener()
with patch('urllib.request.Request', return_value=request_obj) as request:
- with patch('urllib.request.urlopen', return_value=response_obj) as urlopen:
+ with patch('urllib.request.OpenerDirector', return_value=opener_obj) as opener:
printer.file_lists([0], [{'id': '1', 'magnet': 'dn=name'}], 'example.com')
printer.print.assert_has_calls([call('Files in "name":', color='zebra_1'),call(' 1. filename', color='zebra_0')])
diff --git a/tests/test_torrent.py b/tests/test_torrent.py
index a7236c5..9939e16 100755
--- a/tests/test_torrent.py
+++ b/tests/test_torrent.py
@@ -124,14 +124,18 @@ class TestTorrent(unittest.TestCase):
add_header = mock.MagicMock()
request_obj = MockRequest()
class MockResponse():
- read = mock.MagicMock(return_value='No hits. Try adding an asterisk in you search phrase.'.encode('utf8'))
+ read = mock.MagicMock(return_value=b'No hits. Try adding an asterisk in you search phrase.')
info = mock.MagicMock()
response_obj = MockResponse()
+ class MockOpener():
+ open = mock.MagicMock(return_value=response_obj)
+ add_handler = mock.MagicMock()
+ opener_obj = MockOpener()
with patch('urllib.request.Request', return_value=request_obj) as request:
- with patch('urllib.request.urlopen', return_value=response_obj) as urlopen:
+ with patch('urllib.request.OpenerDirector', return_value=opener_obj) as opener:
res = pirate.torrent.remote(MagicMock(Printer), 1, 100, 10, 'browse', [], 'http://example.com')
request.assert_called_once_with('http://example.com/browse/100/0/10', headers=pirate.data.default_headers)
- urlopen.assert_called_once_with(request_obj, timeout=pirate.data.default_timeout)
+ opener_obj.open.assert_called_once_with(request_obj, timeout=pirate.data.default_timeout)
self.assertEqual(res, [])
if __name__ == '__main__':