def test_remove_torrents(self): options = {} filename = common.get_test_data_file('test.torrent') with open(filename, 'rb') as _file: filedump = b64encode(_file.read()) torrent_id = yield self.core.add_torrent_file_async( filename, filedump, options) filename2 = common.get_test_data_file('unicode_filenames.torrent') with open(filename2, 'rb') as _file: filedump = b64encode(_file.read()) torrent_id2 = yield self.core.add_torrent_file_async( filename2, filedump, options) d = self.core.remove_torrents([torrent_id, torrent_id2], True) def test_ret(val): self.assertTrue(val == []) d.addCallback(test_ret) def test_session_state(val): self.assertEqual(len(self.core.get_session_state()), 0) d.addCallback(test_session_state) yield d
def __init__(self): Resource.__init__(self) self.putChild('cookie', CookieResource()) self.putChild('partial', PartialDownload()) self.putChild('redirect', RedirectResource()) self.putChild('ubuntu-9.04-desktop-i386.iso.torrent', File(common.get_test_data_file('ubuntu-9.04-desktop-i386.iso.torrent')))
def render(self, request): with open( common.get_test_data_file( 'ubuntu-9.04-desktop-i386.iso.torrent'), 'rb') as _file: data = _file.read() request.setHeader(b'Content-Length', str(len(data))) request.setHeader(b'Content-Type', b'application/x-bittorrent') return data
def render(self, request): with open(common.get_test_data_file('ubuntu-9.04-desktop-i386.iso.torrent'), 'rb') as _file: data = _file.read() request.setHeader(b'Content-Type', len(data)) request.setHeader(b'Content-Type', b'application/x-bittorrent') if request.requestHeaders.hasHeader('accept-encoding'): return compress(data, request) return data
def test_remove_torrent(self): options = {} filename = common.get_test_data_file('test.torrent') with open(filename, 'rb') as _file: filedump = base64.encodestring(_file.read()) torrent_id = yield self.core.add_torrent_file(filename, filedump, options) removed = self.core.remove_torrent(torrent_id, True) self.assertTrue(removed) self.assertEqual(len(self.core.get_session_state()), 0)
def render(self, request): if request.getCookie('password') != 'deluge': request.setResponseCode(FORBIDDEN) return request.setHeader(b'Content-Type', b'application/x-bittorrent') with open(common.get_test_data_file('ubuntu-9.04-desktop-i386.iso.torrent'), 'rb') as _file: data = _file.read() return data
def __init__(self): Resource.__init__(self) self.putChild('cookie', CookieResource()) self.putChild('partial', PartialDownload()) self.putChild('redirect', RedirectResource()) self.putChild( 'ubuntu-9.04-desktop-i386.iso.torrent', File( common.get_test_data_file( 'ubuntu-9.04-desktop-i386.iso.torrent')))
def test_remove_torrents_invalid(self): options = {} filename = common.get_test_data_file('test.torrent') with open(filename, 'rb') as _file: filedump = base64.encodestring(_file.read()) torrent_id = yield self.core.add_torrent_file(filename, filedump, options) val = yield self.core.remove_torrents(['invalidid1', 'invalidid2', torrent_id], False) self.assertEqual(len(val), 2) self.assertEqual(val[0], ('invalidid1', 'torrent_id invalidid1 not in session.')) self.assertEqual(val[1], ('invalidid2', 'torrent_id invalidid2 not in session.'))
def test_remove_torrent(self): options = {} filename = common.get_test_data_file('test.torrent') with open(filename, 'rb') as _file: filedump = b64encode(_file.read()) torrent_id = yield self.core.add_torrent_file_async( filename, filedump, options) removed = self.core.remove_torrent(torrent_id, True) self.assertTrue(removed) self.assertEqual(len(self.core.get_session_state()), 0)
def render(self, request): with open( common.get_test_data_file( 'ubuntu-9.04-desktop-i386.iso.torrent'), 'rb') as _file: data = _file.read() request.setHeader(b'Content-Type', len(data)) request.setHeader(b'Content-Type', b'application/x-bittorrent') if request.requestHeaders.hasHeader('accept-encoding'): return compress(data, request) return data
def test_add_torrent_files(self): options = {} filenames = ['test.torrent', 'test_torrent.file.torrent'] files_to_add = [] for f in filenames: filename = common.get_test_data_file(f) with open(filename, 'rb') as _file: filedump = base64.encodestring(_file.read()) files_to_add.append((filename, filedump, options)) errors = yield self.core.add_torrent_files(files_to_add) self.assertEqual(len(errors), 0)
def test_add_torrent_files(self): options = {} filenames = ['test.torrent', 'test_torrent.file.torrent'] files_to_add = [] for f in filenames: filename = common.get_test_data_file(f) with open(filename, 'rb') as _file: filedump = b64encode(_file.read()) files_to_add.append((filename, filedump, options)) errors = yield self.core.add_torrent_files(files_to_add) self.assertEqual(len(errors), 0)
def add_torrent(self, filename, paused=False): if not paused: # Patch libtorrent flags starting torrents paused self.patch(deluge.core.torrentmanager, 'LT_DEFAULT_ADD_TORRENT_FLAGS', 592) options = {'add_paused': paused, 'auto_managed': False} filepath = common.get_test_data_file(filename) with open(filepath, 'rb') as _file: filedump = b64encode(_file.read()) torrent_id = self.core.add_torrent_file(filename, filedump, options) return torrent_id
def render(self, request): if request.getCookie(b'password') != b'deluge': request.setResponseCode(FORBIDDEN) return request.setHeader(b'Content-Type', b'application/x-bittorrent') with open( common.get_test_data_file( 'ubuntu-9.04-desktop-i386.iso.torrent'), 'rb') as _file: data = _file.read() return data
def test_add_torrent_file(self): options = {} filename = common.get_test_data_file('test.torrent') with open(filename, 'rb') as _file: filedump = base64.encodestring(_file.read()) torrent_id = yield self.core.add_torrent_file(filename, filedump, options) # Get the info hash from the test.torrent from deluge.bencode import bdecode, bencode with open(filename, 'rb') as _file: info_hash = sha(bencode(bdecode(_file.read())[b'info'])).hexdigest() self.assertEquals(torrent_id, info_hash)
def test_remove_torrents(self): options = {} filename = common.get_test_data_file('test.torrent') with open(filename, 'rb') as _file: filedump = base64.encodestring(_file.read()) torrent_id = yield self.core.add_torrent_file(filename, filedump, options) filename2 = common.get_test_data_file('unicode_filenames.torrent') with open(filename2, 'rb') as _file: filedump = base64.encodestring(_file.read()) torrent_id2 = yield self.core.add_torrent_file(filename2, filedump, options) d = self.core.remove_torrents([torrent_id, torrent_id2], True) def test_ret(val): self.assertTrue(val == []) d.addCallback(test_ret) def test_session_state(val): self.assertEqual(len(self.core.get_session_state()), 0) d.addCallback(test_session_state) yield d
def test_add_torrent_files_error_duplicate(self): options = {} filenames = ['test.torrent', 'test.torrent'] files_to_add = [] for f in filenames: filename = common.get_test_data_file(f) with open(filename, 'rb') as _file: filedump = base64.encodestring(_file.read()) files_to_add.append((filename, filedump, options)) errors = yield self.core.add_torrent_files(files_to_add) self.assertEqual(len(errors), 1) self.assertTrue(str(errors[0]).startswith('Torrent already in session'))
def test_add_torrent_files_error_duplicate(self): options = {} filenames = ['test.torrent', 'test.torrent'] files_to_add = [] for f in filenames: filename = common.get_test_data_file(f) with open(filename, 'rb') as _file: filedump = b64encode(_file.read()) files_to_add.append((filename, filedump, options)) errors = yield self.core.add_torrent_files(files_to_add) self.assertEqual(len(errors), 1) self.assertTrue( str(errors[0]).startswith('Torrent already in session'))
def test_add_torrent_file(self): options = {} filename = common.get_test_data_file('test.torrent') with open(filename, 'rb') as _file: filedump = base64.encodestring(_file.read()) torrent_id = yield self.core.add_torrent_file(filename, filedump, options) # Get the info hash from the test.torrent from deluge.bencode import bdecode, bencode with open(filename, 'rb') as _file: info_hash = sha(bencode(bdecode( _file.read())[b'info'])).hexdigest() self.assertEquals(torrent_id, info_hash)
def test_remove_torrents_invalid(self): options = {} filename = common.get_test_data_file('test.torrent') with open(filename, 'rb') as _file: filedump = b64encode(_file.read()) torrent_id = yield self.core.add_torrent_file_async( filename, filedump, options) val = yield self.core.remove_torrents( ['invalidid1', 'invalidid2', torrent_id], False) self.assertEqual(len(val), 2) self.assertEqual( val[0], ('invalidid1', 'torrent_id invalidid1 not in session.')) self.assertEqual( val[1], ('invalidid2', 'torrent_id invalidid2 not in session.'))
def test_add_torrent_file_invalid_filedump(self): options = {} filename = common.get_test_data_file('test.torrent') self.assertRaises(AddTorrentError, self.core.add_torrent_file, filename, False, options)