mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-08 09:28:41 +00:00
Add some tests for core
This commit is contained in:
parent
2ced8ad189
commit
76bc45a3bf
3 changed files with 79 additions and 3 deletions
|
@ -3,6 +3,25 @@ import tempfile
|
||||||
import deluge.configmanager
|
import deluge.configmanager
|
||||||
import deluge.log
|
import deluge.log
|
||||||
|
|
||||||
deluge.log.setupLogger()
|
deluge.log.setupLogger("none")
|
||||||
|
|
||||||
|
def set_tmp_config_dir():
|
||||||
config_directory = tempfile.mkdtemp()
|
config_directory = tempfile.mkdtemp()
|
||||||
deluge.configmanager.set_config_dir(config_directory)
|
deluge.configmanager.set_config_dir(config_directory)
|
||||||
|
|
||||||
|
import gettext
|
||||||
|
import locale
|
||||||
|
import pkg_resources
|
||||||
|
|
||||||
|
# Initialize gettext
|
||||||
|
try:
|
||||||
|
locale.setlocale(locale.LC_ALL, '')
|
||||||
|
if hasattr(locale, "bindtextdomain"):
|
||||||
|
locale.bindtextdomain("deluge", pkg_resources.resource_filename("deluge", "i18n"))
|
||||||
|
if hasattr(locale, "textdomain"):
|
||||||
|
locale.textdomain("deluge")
|
||||||
|
gettext.bindtextdomain("deluge", pkg_resources.resource_filename("deluge", "i18n"))
|
||||||
|
gettext.textdomain("deluge")
|
||||||
|
gettext.install("deluge", pkg_resources.resource_filename("deluge", "i18n"))
|
||||||
|
except Exception, e:
|
||||||
|
print e
|
||||||
|
|
2
deluge/tests/test.torrent
Normal file
2
deluge/tests/test.torrent
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
d8:announce40:http://tracker.aelitis.com:6969/announce13:announce-listll40:http://tracker.aelitis.com:6969/announceel41:http://tracker.aelitis.com:16969/announceee18:azureus_propertiesd17:dht_backup_enablei0ee7:comment34:provided by http://getazureus.com/13:comment.utf-834:provided by http://getazureus.com/10:created by19:Azureus/2.5.0.3_CVS13:creation datei1169429806e4:infod4:ed2k16:>pïlú]•K^Â\;;e·6:lengthi307949e4:name22:azcvsupdater_2.6.2.jar10:name.utf-822:azcvsupdater_2.6.2.jar12:piece lengthi32768e6:pieces200:ÛBÃ'Úb¸su97©uÊ<w\fÔ›©}ÀŸ:ý—qvƒ¢"ï<>7y!
låv·{÷/"Pé<50>Dž8½ãû-<2D>ª¼Mº’üFð†x+ÈÐS©<53>`¡ä‚èü÷ãåö…%ç%
|
||||||
|
íÀ¡;šêÏ<C3AA>/F>ßÚgAÄ2|Ú‚õ¦b¡¸#€wIØfø½¬W«Ãsà»wòK¾î¨rGáWè·Âióد<C398>ÜÐ#ôÁuÍE?:èœu«b(oj
^ÕÕAƒˆš¡J?¡ÖŒƒž&7:privatei0e4:sha120:2ζ¨"×ðÔ¿Ü^Kºh<>Å·¬Ýee
|
55
deluge/tests/test_core.py
Normal file
55
deluge/tests/test_core.py
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
from twisted.trial import unittest
|
||||||
|
|
||||||
|
try:
|
||||||
|
from hashlib import sha1 as sha
|
||||||
|
except ImportError:
|
||||||
|
from sha import sha
|
||||||
|
|
||||||
|
import common
|
||||||
|
|
||||||
|
from deluge.core.rpcserver import RPCServer
|
||||||
|
from deluge.core.core import Core
|
||||||
|
import deluge.component as component
|
||||||
|
|
||||||
|
class CoreTestCase(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
common.set_tmp_config_dir()
|
||||||
|
self.rpcserver = RPCServer(listen=False)
|
||||||
|
self.core = Core()
|
||||||
|
component.start()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
component.stop()
|
||||||
|
component.shutdown()
|
||||||
|
del self.rpcserver
|
||||||
|
del self.core
|
||||||
|
|
||||||
|
def test_add_torrent_file(self):
|
||||||
|
options = {}
|
||||||
|
filename = "../test.torrent"
|
||||||
|
import base64
|
||||||
|
torrent_id = self.core.add_torrent_file(filename, base64.encodestring(open(filename).read()), options)
|
||||||
|
|
||||||
|
# Get the info hash from the test.torrent
|
||||||
|
from deluge.bencode import bdecode, bencode
|
||||||
|
info_hash = sha(bencode(bdecode(open(filename).read())["info"])).hexdigest()
|
||||||
|
|
||||||
|
self.assertEquals(torrent_id, info_hash)
|
||||||
|
|
||||||
|
def test_add_torrent_url(self):
|
||||||
|
url = "http://torrent.ubuntu.com:6969/file?info_hash=%60%D5%D8%23%28%B4Tu%11%FD%EA%C9%BFM%01%12%DA%A0%CE%00"
|
||||||
|
options = {}
|
||||||
|
info_hash = "60d5d82328b4547511fdeac9bf4d0112daa0ce00"
|
||||||
|
|
||||||
|
d = self.core.add_torrent_url(url, options)
|
||||||
|
d.addCallback(self.assertEquals, info_hash)
|
||||||
|
return d
|
||||||
|
|
||||||
|
def test_add_magnet(self):
|
||||||
|
info_hash = "60d5d82328b4547511fdeac9bf4d0112daa0ce00"
|
||||||
|
import deluge.common
|
||||||
|
uri = deluge.common.create_magnet_uri(info_hash)
|
||||||
|
options = {}
|
||||||
|
|
||||||
|
torrent_id = self.core.add_torrent_magnet(uri, options)
|
||||||
|
self.assertEquals(torrent_id, info_hash)
|
Loading…
Add table
Add a link
Reference in a new issue