2009-08-12 00:09:22 +00:00
|
|
|
from twisted.trial import unittest
|
|
|
|
from twisted.python.failure import Failure
|
|
|
|
|
|
|
|
import os
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
from deluge import maketorrent
|
|
|
|
|
|
|
|
|
|
|
|
def check_torrent(filename):
|
|
|
|
# Test loading with libtorrent to make sure it's valid
|
2010-03-21 02:12:10 +00:00
|
|
|
from deluge._libtorrent import lt
|
2009-08-12 00:09:22 +00:00
|
|
|
lt.torrent_info(filename)
|
2010-03-21 02:12:10 +00:00
|
|
|
|
2009-08-12 00:09:22 +00:00
|
|
|
# Test loading with our internal TorrentInfo class
|
|
|
|
from deluge.ui.common import TorrentInfo
|
2010-03-21 02:12:10 +00:00
|
|
|
ti = TorrentInfo(filename)
|
|
|
|
|
2009-08-12 00:09:22 +00:00
|
|
|
class MakeTorrentTestCase(unittest.TestCase):
|
|
|
|
def test_save_multifile(self):
|
|
|
|
# Create a temporary folder for torrent creation
|
|
|
|
tmp_path = tempfile.mkdtemp()
|
|
|
|
open(os.path.join(tmp_path, "file_A"), "wb").write("a" * (312 * 1024))
|
|
|
|
open(os.path.join(tmp_path, "file_B"), "wb").write("b" * (2354 * 1024))
|
|
|
|
open(os.path.join(tmp_path, "file_C"), "wb").write("c" * (11 * 1024))
|
2010-03-21 02:12:10 +00:00
|
|
|
|
2009-08-12 00:09:22 +00:00
|
|
|
t = maketorrent.TorrentMetadata()
|
|
|
|
t.data_path = tmp_path
|
|
|
|
tmp_file = tempfile.mkstemp(".torrent")[1]
|
|
|
|
t.save(tmp_file)
|
2010-03-21 02:12:10 +00:00
|
|
|
|
2009-08-12 00:09:22 +00:00
|
|
|
check_torrent(tmp_file)
|
2010-03-21 02:12:10 +00:00
|
|
|
|
2009-08-12 00:09:22 +00:00
|
|
|
os.remove(os.path.join(tmp_path, "file_A"))
|
|
|
|
os.remove(os.path.join(tmp_path, "file_B"))
|
|
|
|
os.remove(os.path.join(tmp_path, "file_C"))
|
|
|
|
os.rmdir(tmp_path)
|
|
|
|
os.remove(tmp_file)
|
|
|
|
|
|
|
|
def test_save_singlefile(self):
|
|
|
|
tmp_data = tempfile.mkstemp("testdata")[1]
|
|
|
|
open(tmp_data, "wb").write("a"*(2314*1024))
|
|
|
|
t = maketorrent.TorrentMetadata()
|
|
|
|
t.data_path = tmp_data
|
|
|
|
tmp_file = tempfile.mkstemp(".torrent")[1]
|
|
|
|
t.save(tmp_file)
|
2010-03-21 02:12:10 +00:00
|
|
|
|
2009-08-12 00:09:22 +00:00
|
|
|
check_torrent(tmp_file)
|
|
|
|
|
|
|
|
os.remove(tmp_data)
|
|
|
|
os.remove(tmp_file)
|
|
|
|
|
|
|
|
def test_save_multifile_padded(self):
|
|
|
|
# Create a temporary folder for torrent creation
|
|
|
|
tmp_path = tempfile.mkdtemp()
|
|
|
|
open(os.path.join(tmp_path, "file_A"), "wb").write("a" * (312 * 1024))
|
|
|
|
open(os.path.join(tmp_path, "file_B"), "wb").write("b" * (2354 * 1024))
|
|
|
|
open(os.path.join(tmp_path, "file_C"), "wb").write("c" * (11 * 1024))
|
2010-03-21 02:12:10 +00:00
|
|
|
|
2009-08-12 00:09:22 +00:00
|
|
|
t = maketorrent.TorrentMetadata()
|
|
|
|
t.data_path = tmp_path
|
|
|
|
t.pad_files = True
|
|
|
|
tmp_file = tempfile.mkstemp(".torrent")[1]
|
|
|
|
t.save(tmp_file)
|
2010-03-21 02:12:10 +00:00
|
|
|
|
2009-08-12 00:09:22 +00:00
|
|
|
check_torrent(tmp_file)
|
2010-03-21 02:12:10 +00:00
|
|
|
|
2009-08-12 00:09:22 +00:00
|
|
|
os.remove(os.path.join(tmp_path, "file_A"))
|
|
|
|
os.remove(os.path.join(tmp_path, "file_B"))
|
|
|
|
os.remove(os.path.join(tmp_path, "file_C"))
|
|
|
|
os.rmdir(tmp_path)
|
2010-03-21 02:12:10 +00:00
|
|
|
os.remove(tmp_file)
|