Change core.remove_torrent to only accept one torrent_id, not a list

Added test for core.remove_torrent
This commit is contained in:
Andrew Resch 2009-07-23 04:14:08 +00:00
parent 0ca5a10d5e
commit 1b7be24bdf
4 changed files with 28 additions and 6 deletions

View File

@ -308,10 +308,18 @@ class Core(component.Component):
return self.torrentmanager.add(magnet=uri, options=options)
@export
def remove_torrent(self, torrent_ids, remove_data):
log.debug("Removing torrent %s from the core.", torrent_ids)
for torrent_id in torrent_ids:
self.torrentmanager.remove(torrent_id, remove_data)
def remove_torrent(self, torrent_id, remove_data):
"""
Removes a torrent from the session.
:param torrent_id: the torrent_id of the torrent to remove
:type torrent_id: string
:param remove_data: if True, remove the data associated with this torrent
:type remove_data: boolean
"""
log.debug("Removing torrent %s from the core.", torrent_id)
self.torrentmanager.remove(torrent_id, remove_data)
@export
def get_stats(self):

View File

@ -60,7 +60,8 @@ class Command(BaseCommand):
for arg in args:
torrent_ids.extend(self.console.match_torrent(arg))
return client.core.remove_torrent(torrent_ids, options['remove_data'])
for torrent_id in torrent_ids:
client.core.remove_torrent(torrent_id, options['remove_data'])
def complete(self, line):
# We use the ConsoleUI torrent tab complete method

View File

@ -82,7 +82,8 @@ class RemoveTorrentDialog(object):
button_data.set_label(pluralize_torrents(button_data.get_label()))
def __remove_torrents(self, remove_data):
client.core.remove_torrent(self.__torrent_ids, remove_data)
for torrent_id in self.__torrent_ids:
client.core.remove_torrent(torrent_id, remove_data)
# Unselect all to avoid issues with the selection changed event
component.get("TorrentView").treeview.get_selection().unselect_all()

View File

@ -68,3 +68,15 @@ class CoreTestCase(unittest.TestCase):
torrent_id = self.core.add_torrent_magnet(uri, options)
self.assertEquals(torrent_id, info_hash)
def test_remove_torrent(self):
options = {}
filename = "../test.torrent"
import base64
torrent_id = self.core.add_torrent_file(filename, base64.encodestring(open(filename).read()), options)
self.core.remove_torrent(torrent_id, True)
self.assertEquals(len(self.core.get_session_state()), 0)