def test_find_torrent_without_credentials(self, transmission_client): rpc_client = transmission_client.return_value plugin = TransmissionClientPlugin() torrent_hash = 'SomeRandomHashMockString' self.assertFalse(plugin.find_torrent(torrent_hash)) rpc_client.get_torrent.assert_not_called()
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_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_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'])