def test_settings(self): plugin = DelugeClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} self.assertIsNone(plugin.get_settings()) plugin.set_settings(settings) readed_settings = plugin.get_settings() self.assertEqual({'host': 'localhost', 'port': None, 'username': '******'}, readed_settings)
def test_settings(self): plugin = DelugeClientPlugin() settings = {"host": "localhost", "username": "******", "password": "******"} self.assertIsNone(plugin.get_settings()) plugin.set_settings(settings) readed_settings = plugin.get_settings() self.assertEqual({"host": "localhost", "port": None, "username": "******"}, readed_settings)
def test_find_torrent_false(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = True plugin = DelugeClientPlugin() settings = {"host": "localhost", "username": "******", "password": "******"} plugin.set_settings(settings) torrent_hash = "SomeRandomHashMockString" self.assertFalse(plugin.find_torrent(torrent_hash)) rpc_client.call.assert_called_once_with("core.get_torrent_status", torrent_hash.lower(), ["time_added", "name"])
def test_get_download_dir_exception(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = True rpc_client.call.side_effect = Exception plugin = DelugeClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) assert plugin.get_download_dir() is None rpc_client.call.assert_called_once_with('core.get_config_value', 'download_location')
def test_remove_torrent_call_exception(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = True rpc_client.call.side_effect = Exception plugin = DelugeClientPlugin() settings = {"host": "localhost", "username": "******", "password": "******"} plugin.set_settings(settings) torrent_hash = "SomeRandomHashMockString" self.assertFalse(plugin.remove_torrent(torrent_hash)) rpc_client.call.assert_called_once_with("core.remove_torrent", torrent_hash.lower(), False)
def test_add_torrent_call_exception(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = True rpc_client.call.side_effect = Exception plugin = DelugeClientPlugin() settings = {"host": "localhost", "username": "******", "password": "******"} plugin.set_settings(settings) torrent = b"!torrent.content" self.assertFalse(plugin.add_torrent(torrent, None)) rpc_client.call.assert_called_once_with("core.add_torrent_file", None, base64.b64encode(torrent), None)
def test_remove_torrent_call_exception(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = True rpc_client.call.side_effect = Exception plugin = DelugeClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) torrent_hash = 'SomeRandomHashMockString' self.assertFalse(plugin.remove_torrent(torrent_hash)) rpc_client.call.assert_called_once_with('core.remove_torrent', torrent_hash.lower(), False)
def test_find_torrent_connect_exception(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = True rpc_client.connect.side_effect = Exception plugin = DelugeClientPlugin() settings = {"host": "localhost", "username": "******", "password": "******"} plugin.set_settings(settings) torrent_hash = "SomeRandomHashMockString" self.assertFalse(plugin.find_torrent(torrent_hash)) rpc_client.call.assert_not_called()
def test_find_torrent_false(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = True plugin = DelugeClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) torrent_hash = 'SomeRandomHashMockString' self.assertFalse(plugin.find_torrent(torrent_hash)) rpc_client.call.assert_called_once_with('core.get_torrent_status', torrent_hash.lower(), ['time_added', 'name'])
def test_find_torrent_connect_exception(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = True rpc_client.connect.side_effect = Exception plugin = DelugeClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) torrent_hash = 'SomeRandomHashMockString' self.assertFalse(plugin.find_torrent(torrent_hash)) rpc_client.call.assert_not_called()
def test_add_torrent_call_exception(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = True rpc_client.call.side_effect = Exception plugin = DelugeClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) torrent = b'!torrent.content' self.assertFalse(plugin.add_torrent(torrent, None)) rpc_client.call.assert_called_once_with('core.add_torrent_file', None, base64.b64encode(torrent), None)
def test_add_torrent_call_exception(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = True rpc_client.call.side_effect = Exception plugin = DelugeClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) torrent = b'!torrent.content' self.assertFalse(plugin.add_torrent(torrent)) rpc_client.call.assert_called_once_with('core.add_torrent_file', None, base64.encodestring(torrent), None)
def test_check_connection_successfull(self, value, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = value plugin = DelugeClientPlugin() settings = {"host": "localhost", "username": "******", "password": "******"} plugin.set_settings(settings) self.assertEqual(value, plugin.check_connection()) deluge_client.assert_called_with("localhost", DelugeClientPlugin.DEFAULT_PORT, "monitorrent", "monitorrent") connect_mock = rpc_client.connect connect_mock.assert_called_once_with()
def test_check_connection_successfull(self, value, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = value plugin = DelugeClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) self.assertEqual(value, plugin.check_connection()) deluge_client.assert_called_with('localhost', DelugeClientPlugin.DEFAULT_PORT, 'monitorrent', 'monitorrent') connect_mock = rpc_client.connect connect_mock.assert_called_once_with()
def test_check_connection_connect_exception(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connect.side_effect = Exception plugin = DelugeClientPlugin() settings = {"host": "localhost", "username": "******", "password": "******"} plugin.set_settings(settings) self.assertFalse(plugin.check_connection()) deluge_client.assert_called_with("localhost", DelugeClientPlugin.DEFAULT_PORT, "monitorrent", "monitorrent") connect_mock = rpc_client.connect connect_mock.assert_called_once_with()
def test_check_connection_connect_exception(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connect.side_effect = Exception plugin = DelugeClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) self.assertFalse(plugin.check_connection()) deluge_client.assert_called_with('localhost', DelugeClientPlugin.DEFAULT_PORT, 'monitorrent', 'monitorrent') connect_mock = rpc_client.connect connect_mock.assert_called_once_with()
def test_add_torrent(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = True plugin = DelugeClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) rpc_client.call.return_value = True torrent = b'!torrent.content' self.assertTrue(plugin.add_torrent(torrent)) rpc_client.call.assert_called_once_with('core.add_torrent_file', None, base64.encodebytes(torrent), None)
def test_get_download_dir_success(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = True rpc_client.call.return_value = b'/mnt/media/torrents/complete' plugin = DelugeClientPlugin() assert plugin.get_download_dir() is None settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) assert plugin.get_download_dir() == u'/mnt/media/torrents/complete' rpc_client.call.assert_called_once_with('core.get_config_value', 'download_location')
def test_add_torrent_with_settings(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = True plugin = DelugeClientPlugin() settings = {"host": "localhost", "username": "******", "password": "******"} plugin.set_settings(settings) rpc_client.call.return_value = True torrent = b"!torrent.content" self.assertTrue(plugin.add_torrent(torrent, TopicSettings("/path/to/download"))) options = {"download_location": "/path/to/download"} rpc_client.call.assert_called_once_with("core.add_torrent_file", None, base64.b64encode(torrent), options)
def test_find_torrent(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = True plugin = DelugeClientPlugin() settings = {"host": "localhost", "username": "******", "password": "******"} plugin.set_settings(settings) date_added = datetime(2015, 10, 9, 12, 3, 55, tzinfo=pytz.reference.LocalTimezone()) rpc_client.call.return_value = {"name": "Torrent 1", "time_added": time.mktime(date_added.timetuple())} torrent_hash = "SomeRandomHashMockString" torrent = plugin.find_torrent(torrent_hash) self.assertEqual({"name": "Torrent 1", "date_added": date_added.astimezone(pytz.utc)}, torrent) rpc_client.call.assert_called_once_with("core.get_torrent_status", torrent_hash.lower(), ["time_added", "name"])
def test_find_torrent(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = True plugin = DelugeClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) date_added = datetime(2015, 10, 9, 12, 3, 55, tzinfo=pytz.reference.LocalTimezone()) rpc_client.call.return_value = {'name': 'Torrent 1', 'time_added': time.mktime(date_added.timetuple())} torrent_hash = 'SomeRandomHashMockString' torrent = plugin.find_torrent(torrent_hash) self.assertEqual({'name': 'Torrent 1', 'date_added': date_added.astimezone(pytz.utc)}, torrent) rpc_client.call.assert_called_once_with('core.get_torrent_status', torrent_hash.lower(), ['time_added', 'name'])
def test_add_torrent_with_settings(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = True plugin = DelugeClientPlugin() settings = {'host': 'localhost', 'username': '******', 'password': '******'} plugin.set_settings(settings) rpc_client.call.return_value = True torrent = b'!torrent.content' self.assertTrue(plugin.add_torrent(torrent, TopicSettings('/path/to/download'))) options = { 'download_location': '/path/to/download' } rpc_client.call.assert_called_once_with('core.add_torrent_file', None, base64.b64encode(torrent), options)
def test_add_torrent(self, deluge_client): rpc_client = deluge_client.return_value rpc_client.connected = True plugin = DelugeClientPlugin() settings = { 'host': 'localhost', 'username': '******', 'password': '******' } plugin.set_settings(settings) rpc_client.call.return_value = True torrent = b'!torrent.content' self.assertTrue(plugin.add_torrent(torrent)) rpc_client.call.assert_called_once_with('core.add_torrent_file', None, base64.encodebytes(torrent), None)