[Tests] Use common.rpath() in all tests
This commit is contained in:
parent
c8a3fd72d4
commit
d505ebe926
|
@ -1,5 +1,4 @@
|
||||||
import base64
|
import base64
|
||||||
import os
|
|
||||||
from hashlib import sha1 as sha
|
from hashlib import sha1 as sha
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -24,8 +23,6 @@ from .basetest import BaseTestCase
|
||||||
|
|
||||||
common.disable_new_release_check()
|
common.disable_new_release_check()
|
||||||
|
|
||||||
rpath = common.rpath
|
|
||||||
|
|
||||||
|
|
||||||
class CookieResource(Resource):
|
class CookieResource(Resource):
|
||||||
|
|
||||||
|
@ -35,7 +32,7 @@ class CookieResource(Resource):
|
||||||
return
|
return
|
||||||
|
|
||||||
request.setHeader("Content-Type", "application/x-bittorrent")
|
request.setHeader("Content-Type", "application/x-bittorrent")
|
||||||
with open(rpath("ubuntu-9.04-desktop-i386.iso.torrent")) as _file:
|
with open(common.rpath("ubuntu-9.04-desktop-i386.iso.torrent")) as _file:
|
||||||
data = _file.read()
|
data = _file.read()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -43,7 +40,7 @@ class CookieResource(Resource):
|
||||||
class PartialDownload(Resource):
|
class PartialDownload(Resource):
|
||||||
|
|
||||||
def render(self, request):
|
def render(self, request):
|
||||||
with open(rpath("ubuntu-9.04-desktop-i386.iso.torrent")) as _file:
|
with open(common.rpath("ubuntu-9.04-desktop-i386.iso.torrent")) as _file:
|
||||||
data = _file.read()
|
data = _file.read()
|
||||||
request.setHeader("Content-Type", len(data))
|
request.setHeader("Content-Type", len(data))
|
||||||
request.setHeader("Content-Type", "application/x-bittorrent")
|
request.setHeader("Content-Type", "application/x-bittorrent")
|
||||||
|
@ -111,7 +108,7 @@ class CoreTestCase(BaseTestCase):
|
||||||
filenames = ["test.torrent", "test_torrent.file.torrent"]
|
filenames = ["test.torrent", "test_torrent.file.torrent"]
|
||||||
files_to_add = []
|
files_to_add = []
|
||||||
for f in filenames:
|
for f in filenames:
|
||||||
filename = os.path.join(os.path.dirname(__file__), f)
|
filename = common.rpath(f)
|
||||||
with open(filename) as _file:
|
with open(filename) as _file:
|
||||||
filedump = base64.encodestring(_file.read())
|
filedump = base64.encodestring(_file.read())
|
||||||
files_to_add.append((filename, filedump, options))
|
files_to_add.append((filename, filedump, options))
|
||||||
|
@ -124,7 +121,7 @@ class CoreTestCase(BaseTestCase):
|
||||||
filenames = ["test.torrent", "test.torrent"]
|
filenames = ["test.torrent", "test.torrent"]
|
||||||
files_to_add = []
|
files_to_add = []
|
||||||
for f in filenames:
|
for f in filenames:
|
||||||
filename = os.path.join(os.path.dirname(__file__), f)
|
filename = common.rpath(f)
|
||||||
with open(filename) as _file:
|
with open(filename) as _file:
|
||||||
filedump = base64.encodestring(_file.read())
|
filedump = base64.encodestring(_file.read())
|
||||||
files_to_add.append((filename, filedump, options))
|
files_to_add.append((filename, filedump, options))
|
||||||
|
@ -135,7 +132,7 @@ class CoreTestCase(BaseTestCase):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_add_torrent_file(self):
|
def test_add_torrent_file(self):
|
||||||
options = {}
|
options = {}
|
||||||
filename = os.path.join(os.path.dirname(__file__), "test.torrent")
|
filename = common.rpath("test.torrent")
|
||||||
with open(filename) as _file:
|
with open(filename) as _file:
|
||||||
filedump = base64.encodestring(_file.read())
|
filedump = base64.encodestring(_file.read())
|
||||||
torrent_id = yield self.core.add_torrent_file(filename, filedump, options)
|
torrent_id = yield self.core.add_torrent_file(filename, filedump, options)
|
||||||
|
@ -148,7 +145,7 @@ class CoreTestCase(BaseTestCase):
|
||||||
|
|
||||||
def test_add_torrent_file_invalid_filedump(self):
|
def test_add_torrent_file_invalid_filedump(self):
|
||||||
options = {}
|
options = {}
|
||||||
filename = os.path.join(os.path.dirname(__file__), "test.torrent")
|
filename = common.rpath("test.torrent")
|
||||||
self.assertRaises(AddTorrentError, self.core.add_torrent_file, filename, False, options)
|
self.assertRaises(AddTorrentError, self.core.add_torrent_file, filename, False, options)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
@ -203,7 +200,7 @@ class CoreTestCase(BaseTestCase):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_remove_torrent(self):
|
def test_remove_torrent(self):
|
||||||
options = {}
|
options = {}
|
||||||
filename = os.path.join(os.path.dirname(__file__), "test.torrent")
|
filename = common.rpath("test.torrent")
|
||||||
with open(filename) as _file:
|
with open(filename) as _file:
|
||||||
filedump = base64.encodestring(_file.read())
|
filedump = base64.encodestring(_file.read())
|
||||||
torrent_id = yield self.core.add_torrent_file(filename, filedump, options)
|
torrent_id = yield self.core.add_torrent_file(filename, filedump, options)
|
||||||
|
@ -217,12 +214,12 @@ class CoreTestCase(BaseTestCase):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_remove_torrents(self):
|
def test_remove_torrents(self):
|
||||||
options = {}
|
options = {}
|
||||||
filename = os.path.join(os.path.dirname(__file__), "test.torrent")
|
filename = common.rpath("test.torrent")
|
||||||
with open(filename) as _file:
|
with open(filename) as _file:
|
||||||
filedump = base64.encodestring(_file.read())
|
filedump = base64.encodestring(_file.read())
|
||||||
torrent_id = yield self.core.add_torrent_file(filename, filedump, options)
|
torrent_id = yield self.core.add_torrent_file(filename, filedump, options)
|
||||||
|
|
||||||
filename2 = os.path.join(os.path.dirname(__file__), "unicode_filenames.torrent")
|
filename2 = common.rpath("unicode_filenames.torrent")
|
||||||
with open(filename2) as _file:
|
with open(filename2) as _file:
|
||||||
filedump = base64.encodestring(_file.read())
|
filedump = base64.encodestring(_file.read())
|
||||||
torrent_id2 = yield self.core.add_torrent_file(filename2, filedump, options)
|
torrent_id2 = yield self.core.add_torrent_file(filename2, filedump, options)
|
||||||
|
@ -240,7 +237,7 @@ class CoreTestCase(BaseTestCase):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_remove_torrents_invalid(self):
|
def test_remove_torrents_invalid(self):
|
||||||
options = {}
|
options = {}
|
||||||
filename = os.path.join(os.path.dirname(__file__), "test.torrent")
|
filename = common.rpath("test.torrent")
|
||||||
with open(filename) as _file:
|
with open(filename) as _file:
|
||||||
filedump = base64.encodestring(_file.read())
|
filedump = base64.encodestring(_file.read())
|
||||||
torrent_id = yield self.core.add_torrent_file(filename, filedump, options)
|
torrent_id = yield self.core.add_torrent_file(filename, filedump, options)
|
||||||
|
|
|
@ -14,8 +14,6 @@ from deluge.httpdownloader import download_file
|
||||||
from deluge.log import setup_logger
|
from deluge.log import setup_logger
|
||||||
from deluge.ui.web.common import compress
|
from deluge.ui.web.common import compress
|
||||||
|
|
||||||
from . import common
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from twisted.web.resource import Resource
|
from twisted.web.resource import Resource
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -23,7 +21,6 @@ except ImportError:
|
||||||
from twisted.web.error import Resource
|
from twisted.web.error import Resource
|
||||||
|
|
||||||
|
|
||||||
rpath = common.rpath
|
|
||||||
temp_dir = tempfile.mkdtemp()
|
temp_dir = tempfile.mkdtemp()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ class TorrentTestCase(BaseTestCase):
|
||||||
self.assertEquals(torrent.state, state)
|
self.assertEquals(torrent.state, state)
|
||||||
|
|
||||||
def get_torrent_atp(self, filename):
|
def get_torrent_atp(self, filename):
|
||||||
filename = os.path.join(os.path.dirname(__file__), filename)
|
filename = common.rpath(filename)
|
||||||
with open(filename, 'rb') as _file:
|
with open(filename, 'rb') as _file:
|
||||||
info = lt.torrent_info(lt.bdecode(_file.read()))
|
info = lt.torrent_info(lt.bdecode(_file.read()))
|
||||||
atp = {"ti": info}
|
atp = {"ti": info}
|
||||||
|
@ -117,7 +117,7 @@ class TorrentTestCase(BaseTestCase):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_torrent_error_data_missing(self):
|
def test_torrent_error_data_missing(self):
|
||||||
options = {"seed_mode": True}
|
options = {"seed_mode": True}
|
||||||
filename = os.path.join(os.path.dirname(__file__), "test_torrent.file.torrent")
|
filename = common.rpath("test_torrent.file.torrent")
|
||||||
with open(filename) as _file:
|
with open(filename) as _file:
|
||||||
filedump = base64.encodestring(_file.read())
|
filedump = base64.encodestring(_file.read())
|
||||||
torrent_id = yield self.core.add_torrent_file(filename, filedump, options)
|
torrent_id = yield self.core.add_torrent_file(filename, filedump, options)
|
||||||
|
@ -133,7 +133,7 @@ class TorrentTestCase(BaseTestCase):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_torrent_error_resume_original_state(self):
|
def test_torrent_error_resume_original_state(self):
|
||||||
options = {"seed_mode": True, "add_paused": True}
|
options = {"seed_mode": True, "add_paused": True}
|
||||||
filename = os.path.join(os.path.dirname(__file__), "test_torrent.file.torrent")
|
filename = common.rpath("test_torrent.file.torrent")
|
||||||
with open(filename) as _file:
|
with open(filename) as _file:
|
||||||
filedump = base64.encodestring(_file.read())
|
filedump = base64.encodestring(_file.read())
|
||||||
torrent_id = yield self.core.add_torrent_file(filename, filedump, options)
|
torrent_id = yield self.core.add_torrent_file(filename, filedump, options)
|
||||||
|
@ -178,7 +178,7 @@ class TorrentTestCase(BaseTestCase):
|
||||||
is_finished=True,
|
is_finished=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
filename = os.path.join(os.path.dirname(__file__), "test_torrent.file.torrent")
|
filename = common.rpath("test_torrent.file.torrent")
|
||||||
with open(filename) as _file:
|
with open(filename) as _file:
|
||||||
filedump = _file.read()
|
filedump = _file.read()
|
||||||
torrent_id = yield self.core.torrentmanager.add(state=torrent_state, filedump=filedump,
|
torrent_id = yield self.core.torrentmanager.add(state=torrent_state, filedump=filedump,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import base64
|
import base64
|
||||||
import os
|
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -30,7 +29,7 @@ class TorrentmanagerTestCase(BaseTestCase):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_remove_torrent(self):
|
def test_remove_torrent(self):
|
||||||
filename = os.path.join(os.path.dirname(__file__), "test.torrent")
|
filename = common.rpath("test.torrent")
|
||||||
with open(filename) as _file:
|
with open(filename) as _file:
|
||||||
filedump = base64.encodestring(_file.read())
|
filedump = base64.encodestring(_file.read())
|
||||||
torrent_id = yield self.core.add_torrent_file(filename, filedump, {})
|
torrent_id = yield self.core.add_torrent_file(filename, filedump, {})
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os.path
|
|
||||||
|
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
|
|
||||||
from deluge.ui.common import TorrentInfo
|
from deluge.ui.common import TorrentInfo
|
||||||
|
|
||||||
|
from . import common
|
||||||
|
|
||||||
|
|
||||||
class UICommonTestCase(unittest.TestCase):
|
class UICommonTestCase(unittest.TestCase):
|
||||||
def setUp(self): # NOQA
|
def setUp(self): # NOQA
|
||||||
|
@ -14,12 +15,12 @@ class UICommonTestCase(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_utf8_encoded_paths(self):
|
def test_utf8_encoded_paths(self):
|
||||||
filename = os.path.join(os.path.dirname(__file__), "test.torrent")
|
filename = common.rpath("test.torrent")
|
||||||
ti = TorrentInfo(filename)
|
ti = TorrentInfo(filename)
|
||||||
self.assertTrue("azcvsupdater_2.6.2.jar" in ti.files_tree)
|
self.assertTrue("azcvsupdater_2.6.2.jar" in ti.files_tree)
|
||||||
|
|
||||||
def test_utf8_encoded_paths2(self):
|
def test_utf8_encoded_paths2(self):
|
||||||
filename = os.path.join(os.path.dirname(__file__), "unicode_filenames.torrent")
|
filename = common.rpath("unicode_filenames.torrent")
|
||||||
ti = TorrentInfo(filename)
|
ti = TorrentInfo(filename)
|
||||||
|
|
||||||
files = ti.files_tree["unicode_filenames"]
|
files = ti.files_tree["unicode_filenames"]
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
# See LICENSE for more details.
|
# See LICENSE for more details.
|
||||||
#
|
#
|
||||||
|
|
||||||
import os
|
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
|
||||||
from twisted.internet import defer, reactor
|
from twisted.internet import defer, reactor
|
||||||
|
@ -156,7 +155,7 @@ class WebAPITestCase(BaseTestCase, DaemonBase):
|
||||||
self.assertFalse(self.deluge_web.web_api.remove_host(conn[0]))
|
self.assertFalse(self.deluge_web.web_api.remove_host(conn[0]))
|
||||||
|
|
||||||
def test_get_torrent_info(self):
|
def test_get_torrent_info(self):
|
||||||
filename = os.path.join(os.path.dirname(__file__), "test.torrent")
|
filename = common.rpath("test.torrent")
|
||||||
ret = self.deluge_web.web_api.get_torrent_info(filename)
|
ret = self.deluge_web.web_api.get_torrent_info(filename)
|
||||||
self.assertEquals(ret["name"], "azcvsupdater_2.6.2.jar")
|
self.assertEquals(ret["name"], "azcvsupdater_2.6.2.jar")
|
||||||
self.assertEquals(ret["info_hash"], "ab570cdd5a17ea1b61e970bb72047de141bce173")
|
self.assertEquals(ret["info_hash"], "ab570cdd5a17ea1b61e970bb72047de141bce173")
|
||||||
|
@ -171,7 +170,7 @@ class WebAPITestCase(BaseTestCase, DaemonBase):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_get_torrent_files(self):
|
def test_get_torrent_files(self):
|
||||||
yield self.deluge_web.web_api.connect(self.host_id)
|
yield self.deluge_web.web_api.connect(self.host_id)
|
||||||
filename = os.path.join(os.path.dirname(__file__), "test.torrent")
|
filename = common.rpath("test.torrent")
|
||||||
torrents = [{"path": filename, "options": {"download_location": "/home/deluge/"}}]
|
torrents = [{"path": filename, "options": {"download_location": "/home/deluge/"}}]
|
||||||
yield self.deluge_web.web_api.add_torrents(torrents)
|
yield self.deluge_web.web_api.add_torrents(torrents)
|
||||||
ret = yield self.deluge_web.web_api.get_torrent_files("ab570cdd5a17ea1b61e970bb72047de141bce173")
|
ret = yield self.deluge_web.web_api.get_torrent_files("ab570cdd5a17ea1b61e970bb72047de141bce173")
|
||||||
|
|
Loading…
Reference in New Issue