Author: andar

Revision: 5450

Log:
        Add some tests for core

Diff:
Modified: trunk/deluge/tests/common.py
===================================================================
--- trunk/deluge/tests/common.py        2009-07-05 00:09:49 UTC (rev 5449)
+++ trunk/deluge/tests/common.py        2009-07-05 01:17:38 UTC (rev 5450)
@@ -3,6 +3,25 @@
 import deluge.configmanager
 import deluge.log
 
-deluge.log.setupLogger()
-config_directory = tempfile.mkdtemp()
-deluge.configmanager.set_config_dir(config_directory)
+deluge.log.setupLogger("none")
+
+def set_tmp_config_dir():
+    config_directory = tempfile.mkdtemp()
+    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

Added: trunk/deluge/tests/test.torrent
===================================================================
--- trunk/deluge/tests/test.torrent                             (rev 0)
+++ trunk/deluge/tests/test.torrent     2009-07-05 01:17:38 UTC (rev 5450)
@@ -0,0 +1,4 @@
+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ƒ¢"ï 7 y!
+låv· {÷/"Pé  Dž8½ ãû- ª¼M º’ü Fð †x+ÈÐS© `¡ä‚èü ÷ãåö… %ç%
+íÀ ¡;šêÏ  /F>ßÚgAÄ2|Ú‚õ¦b¡¸#€wIØfø½¬W«Ãsà»wòK¾î¨rGáWè·ÂióØ¯ ÜÐ#ôÁ uÍ E?:èœ 
u«b(oj
+^ÕÕAƒˆš¡J ?¡ÖŒƒž&7:privatei0e4:sha120:2ζ¨"×ðÔ¿Ü^Kº h Å·¬Ýee
\ No newline at end of file

Added: trunk/deluge/tests/test_core.py
===================================================================
--- trunk/deluge/tests/test_core.py                             (rev 0)
+++ trunk/deluge/tests/test_core.py     2009-07-05 01:17:38 UTC (rev 5450)
@@ -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)



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to