def test_find_torrent(self, transmission_client): rpc_client = transmission_client.return_value plugin = TransmissionClientPlugin() settings = { 'host': 'localhost', 'username': '******', 'password': '******' } plugin.set_settings(settings) date_added = datetime(2015, 10, 9, 12, 3, 55, tzinfo=pytz.reference.LocalTimezone()) torrent_hash = 'SomeRandomHashMockString' torrent_class = namedtuple('Torrent', ['name', 'date_added']) rpc_client.get_torrent.return_value = torrent_class( name='Torrent 1', date_added=date_added) torrent = plugin.find_torrent(torrent_hash) self.assertEqual( { 'name': 'Torrent 1', 'date_added': date_added.astimezone(pytz.utc) }, torrent) rpc_client.get_torrent.assert_called_once_with( torrent_hash.lower(), ['id', 'hashString', 'addedDate', 'name'])
def test_settings(self): plugin = TransmissionClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} self.assertIsNone(plugin.get_settings()) plugin.set_settings(settings) readed_settings = plugin.get_settings() expected = {'host': 'localhost', 'port': TransmissionClientPlugin.DEFAULT_PORT, 'username': '******'} self.assertEqual(expected, readed_settings)
def test_check_connection_successfull(self, transmission_client): plugin = TransmissionClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) self.assertNotEqual(False, plugin.check_connection()) transmission_client.assert_called_with(address='localhost', port=TransmissionClientPlugin.DEFAULT_PORT, user='******', password='******')
def test_add_torrent_with_settings(self, transmission_client): rpc_client = transmission_client.return_value plugin = TransmissionClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) torrent = b'!torrent.content' self.assertTrue(plugin.add_torrent(torrent, TopicSettings('/path/to/download/dir'))) rpc_client.add_torrent.assert_called_once_with(base64.b64encode(torrent).decode('utf-8'), download_dir='/path/to/download/dir')
def test_check_connection_connect_exception(self, transmission_client): transmission_client.side_effect = transmissionrpc.TransmissionError plugin = TransmissionClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) self.assertFalse(plugin.check_connection()) transmission_client.assert_called_with(address='localhost', port=TransmissionClientPlugin.DEFAULT_PORT, user='******', password='******')
def test_remove_torrent(self, transmission_client): rpc_client = transmission_client.return_value plugin = TransmissionClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) torrent_hash = 'SomeRandomHashMockString' self.assertTrue(plugin.remove_torrent(torrent_hash)) rpc_client.remove_torrent.assert_called_once_with(torrent_hash.lower(), delete_data=False)
def test_add_torrent(self, transmission_client): rpc_client = transmission_client.return_value plugin = TransmissionClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) torrent = b'!torrent.content' self.assertTrue(plugin.add_torrent(torrent)) rpc_client.add_torrent.assert_called_once_with(base64.encodestring(torrent))
def test_add_torrent(self, transmission_client): rpc_client = transmission_client.return_value plugin = TransmissionClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) torrent = b'!torrent.content' self.assertTrue(plugin.add_torrent(torrent)) rpc_client.add_torrent.assert_called_once_with(base64.encodebytes(torrent))
def test_add_torrent_add_torrent_exception(self, transmission_client): rpc_client = transmission_client.return_value rpc_client.add_torrent.side_effect = transmissionrpc.TransmissionError plugin = TransmissionClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) torrent = b'!torrent.content' self.assertFalse(plugin.add_torrent(torrent, None)) rpc_client.add_torrent.assert_called_once_with(base64.b64encode(torrent).decode('utf-8'))
def test_find_torrent_get_torrent_exception(self, transmission_client): rpc_client = transmission_client.return_value plugin = TransmissionClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) torrent_hash = 'SomeRandomHashMockString' rpc_client.get_torrent.side_effect = KeyError self.assertFalse(plugin.find_torrent(torrent_hash)) rpc_client.get_torrent.assert_called_once_with(torrent_hash.lower(), ['id', 'hashString', 'addedDate', 'name'])
def test_get_download_dir_exception(self, transmission_client): rpc_client = transmission_client.return_value rpc_client.get_session.side_effect = transmissionrpc.TransmissionError plugin = TransmissionClientPlugin() settings = { 'host': 'localhost', 'username': '******', 'password': '******' } plugin.set_settings(settings) assert plugin.get_download_dir() is None rpc_client.get_session.assert_called_once()
def test_add_torrent_add_torrent_exception(self, transmission_client): rpc_client = transmission_client.return_value rpc_client.add_torrent.side_effect = transmissionrpc.TransmissionError plugin = TransmissionClientPlugin() settings = { 'host': 'localhost', 'username': '******', 'password': '******' } plugin.set_settings(settings) torrent = b'!torrent.content' self.assertFalse(plugin.add_torrent(torrent, None)) rpc_client.add_torrent.assert_called_once_with( base64.b64encode(torrent).decode('utf-8'))
def test_get_download_dir_success(self, transmission_client): rpc_client = transmission_client.return_value rpc_client.get_session.return_value = transmissionrpc.Session( fields={'download_dir': '/mnt/media/downloads'}) plugin = TransmissionClientPlugin() assert plugin.get_download_dir() is None settings = { 'host': 'localhost', 'username': '******', 'password': '******' } plugin.set_settings(settings) assert plugin.get_download_dir() == u'/mnt/media/downloads' rpc_client.get_session.assert_called_once()
def test_add_torrent_with_settings(self, transmission_client): rpc_client = transmission_client.return_value plugin = TransmissionClientPlugin() settings = { 'host': 'localhost', 'username': '******', 'password': '******' } plugin.set_settings(settings) torrent = b'!torrent.content' self.assertTrue( plugin.add_torrent(torrent, TopicSettings('/path/to/download/dir'))) rpc_client.add_torrent.assert_called_once_with( base64.b64encode(torrent).decode('utf-8'), download_dir='/path/to/download/dir')
def test_remove_torrent_remove_torrent_exception(self, transmission_client): rpc_client = transmission_client.return_value rpc_client.remove_torrent.side_effect = transmissionrpc.TransmissionError plugin = TransmissionClientPlugin() settings = { 'host': 'localhost', 'username': '******', 'password': '******' } plugin.set_settings(settings) torrent_hash = 'SomeRandomHashMockString' with pytest.raises(transmissionrpc.TransmissionError) as e: plugin.remove_torrent(torrent_hash) rpc_client.remove_torrent.assert_called_once_with(torrent_hash.lower(), delete_data=False)
def test_find_torrent(self, transmission_client): rpc_client = transmission_client.return_value plugin = TransmissionClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) date_added = datetime(2015, 10, 9, 12, 3, 55, tzinfo=pytz.reference.LocalTimezone()) torrent_hash = 'SomeRandomHashMockString' torrent_class = namedtuple('Torrent', ['name', 'date_added']) rpc_client.get_torrent.return_value = torrent_class(name='Torrent 1', date_added=date_added) torrent = plugin.find_torrent(torrent_hash) self.assertEqual({'name': 'Torrent 1', 'date_added': date_added.astimezone(pytz.utc)}, torrent) rpc_client.get_torrent.assert_called_once_with(torrent_hash.lower(), ['id', 'hashString', 'addedDate', 'name'])