Merge branch 'master' of deluge-torrent.org:deluge

This commit is contained in:
Pedro Algarvio 2011-04-21 00:47:01 +01:00
commit d258794517
4 changed files with 67 additions and 13 deletions

View File

@ -1,3 +1,5 @@
import os
import tempfile
import deluge.configmanager
@ -10,6 +12,9 @@ def set_tmp_config_dir():
deluge.configmanager.set_config_dir(config_directory)
return config_directory
def rpath(*args):
return os.path.join(os.path.dirname(__file__), *args)
import gettext
import locale
import pkg_resources

View File

@ -1,5 +1,10 @@
from twisted.trial import unittest
from twisted.internet import reactor
from twisted.python.failure import Failure
from twisted.web.http import FORBIDDEN
from twisted.web.resource import Resource
from twisted.web.server import Site
from twisted.web.static import File
try:
from hashlib import sha1 as sha
@ -8,19 +13,62 @@ except ImportError:
import os
import common
rpath = common.rpath
from deluge.core.rpcserver import RPCServer
from deluge.core.core import Core
from deluge.ui.web.common import compress
import deluge.component as component
import deluge.error
class TestCookieResource(Resource):
def render(self, request):
if request.getCookie("password") != "deluge":
request.setResponseCode(FORBIDDEN)
return
request.setHeader("Content-Type", "application/x-bittorrent")
return open(rpath("ubuntu-9.04-desktop-i386.iso.torrent")).read()
class TestPartialDownload(Resource):
def render(self, request):
data = open(rpath("ubuntu-9.04-desktop-i386.iso.torrent")).read()
request.setHeader("Content-Type", len(data))
request.setHeader("Content-Type", "application/x-bittorrent")
if request.requestHeaders.hasHeader("accept-encoding"):
return compress(data, request)
return data
class TestRedirectResource(Resource):
def render(self, request):
request.redirect("/ubuntu-9.04-desktop-i386.iso.torrent")
return ""
class TopLevelResource(Resource):
addSlash = True
def __init__(self):
Resource.__init__(self)
self.putChild("cookie", TestCookieResource())
self.putChild("partial", TestPartialDownload())
self.putChild("redirect", TestRedirectResource())
self.putChild("ubuntu-9.04-desktop-i386.iso.torrent", File(common.rpath("ubuntu-9.04-desktop-i386.iso.torrent")))
class CoreTestCase(unittest.TestCase):
def setUp(self):
common.set_tmp_config_dir()
self.rpcserver = RPCServer(listen=False)
self.core = Core()
d = component.start()
return d
return component.start().addCallback(self.startWebserver)
def startWebserver(self, result):
self.website = Site(TopLevelResource())
self.webserver = reactor.listenTCP(51242, self.website)
return result
def tearDown(self):
@ -28,6 +76,7 @@ class CoreTestCase(unittest.TestCase):
component._ComponentRegistry.components = {}
del self.rpcserver
del self.core
return self.webserver.stopListening()
return component.shutdown().addCallback(on_shutdown)
@ -44,7 +93,7 @@ class CoreTestCase(unittest.TestCase):
self.assertEquals(torrent_id, info_hash)
def test_add_torrent_url(self):
url = "http://deluge-torrent.org/ubuntu-9.04-desktop-i386.iso.torrent"
url = "http://localhost:51242/ubuntu-9.04-desktop-i386.iso.torrent"
options = {}
info_hash = "60d5d82328b4547511fdeac9bf4d0112daa0ce00"
@ -53,7 +102,7 @@ class CoreTestCase(unittest.TestCase):
return d
def test_add_torrent_url_with_cookie(self):
url = "http://deluge-torrent.org/test_torrent.php?test=cookie"
url = "http://localhost:51242/cookie"
options = {}
headers = { "Cookie" : "password=deluge" }
info_hash = "60d5d82328b4547511fdeac9bf4d0112daa0ce00"
@ -67,7 +116,7 @@ class CoreTestCase(unittest.TestCase):
return d
def test_add_torrent_url_with_redirect(self):
url = "http://deluge-torrent.org/test_torrent.php?test=redirect"
url = "http://localhost:51242/redirect"
options = {}
info_hash = "60d5d82328b4547511fdeac9bf4d0112daa0ce00"
@ -77,7 +126,7 @@ class CoreTestCase(unittest.TestCase):
return d
def test_add_torrent_url_with_partial_download(self):
url = "http://deluge-torrent.org/test_torrent.php?test=partial"
url = "http://localhost:51242/partial"
options = {}
info_hash = "60d5d82328b4547511fdeac9bf4d0112daa0ce00"

View File

@ -13,11 +13,11 @@ from deluge.ui.web.common import compress
from email.utils import formatdate
def rpath(*paths):
return os.path.join(os.path.dirname(__file__), *paths)
import common
rpath = common.rpath
class TestRedirectResource(Resource):
def render(self, request):
request.redirect("http://localhost:51242/")
@ -107,14 +107,14 @@ class DownloadFileTestCase(unittest.TestCase):
return d
def test_download_without_required_cookies(self):
url = "http://localhost:51242/cookie"
url = "http://localhost:51242/cookie"
d = download_file(url, "none")
d.addCallback(self.fail)
d.addErrback(self.assertIsInstance, Failure)
return d
def test_download_with_required_cookies(self):
url = "http://localhost:51242/cookie"
url = "http://localhost:51242/cookie"
cookie = { "cookie" : "password=deluge" }
d = download_file(url, "monster", headers=cookie)
d.addCallback(self.assertEqual, "monster")
@ -150,13 +150,13 @@ class DownloadFileTestCase(unittest.TestCase):
return d
def test_download_with_gzip_encoding(self):
url = "http://localhost:51242/gzip?msg=success"
url = "http://localhost:51242/gzip?msg=success"
d = download_file(url, "gzip_encoded")
d.addCallback(self.assertContains, "success")
return d
def test_download_with_gzip_encoding_disabled(self):
url = "http://localhost:51242/gzip?msg=fail"
url = "http://localhost:51242/gzip?msg=fail"
d = download_file(url, "gzip_encoded", allow_compression=False)
d.addCallback(self.failIfContains, "fail")
return d

Binary file not shown.