예제 #1
0
    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
예제 #2
0
 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')))
예제 #3
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-Length', str(len(data)))
     request.setHeader(b'Content-Type', b'application/x-bittorrent')
     return data
예제 #4
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
예제 #5
0
 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)
예제 #6
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
예제 #7
0
 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')))
예제 #8
0
 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.'))
예제 #9
0
 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)
예제 #10
0
파일: test_core.py 프로젝트: newfyle/deluge
 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
예제 #11
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 = 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)
예제 #12
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)
예제 #13
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
예제 #14
0
    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
예제 #15
0
    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)
예제 #16
0
    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
예제 #17
0
 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'))
예제 #18
0
 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'))
예제 #19
0
    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)
예제 #20
0
 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.'))
예제 #21
0
 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)
예제 #22
0
 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)