[Tests] Use common.rpath() in all tests

This commit is contained in:
bendikro 2016-06-09 14:23:20 +02:00 committed by Calum Lind
parent c8a3fd72d4
commit d505ebe926
6 changed files with 21 additions and 28 deletions

View File

@ -1,5 +1,4 @@
import base64
import os
from hashlib import sha1 as sha
import pytest
@ -24,8 +23,6 @@ from .basetest import BaseTestCase
common.disable_new_release_check()
rpath = common.rpath
class CookieResource(Resource):
@ -35,7 +32,7 @@ class CookieResource(Resource):
return
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()
return data
@ -43,7 +40,7 @@ class CookieResource(Resource):
class PartialDownload(Resource):
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()
request.setHeader("Content-Type", len(data))
request.setHeader("Content-Type", "application/x-bittorrent")
@ -111,7 +108,7 @@ class CoreTestCase(BaseTestCase):
filenames = ["test.torrent", "test_torrent.file.torrent"]
files_to_add = []
for f in filenames:
filename = os.path.join(os.path.dirname(__file__), f)
filename = common.rpath(f)
with open(filename) as _file:
filedump = base64.encodestring(_file.read())
files_to_add.append((filename, filedump, options))
@ -124,7 +121,7 @@ class CoreTestCase(BaseTestCase):
filenames = ["test.torrent", "test.torrent"]
files_to_add = []
for f in filenames:
filename = os.path.join(os.path.dirname(__file__), f)
filename = common.rpath(f)
with open(filename) as _file:
filedump = base64.encodestring(_file.read())
files_to_add.append((filename, filedump, options))
@ -135,7 +132,7 @@ class CoreTestCase(BaseTestCase):
@defer.inlineCallbacks
def test_add_torrent_file(self):
options = {}
filename = os.path.join(os.path.dirname(__file__), "test.torrent")
filename = common.rpath("test.torrent")
with open(filename) as _file:
filedump = base64.encodestring(_file.read())
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):
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)
@defer.inlineCallbacks
@ -203,7 +200,7 @@ class CoreTestCase(BaseTestCase):
@defer.inlineCallbacks
def test_remove_torrent(self):
options = {}
filename = os.path.join(os.path.dirname(__file__), "test.torrent")
filename = common.rpath("test.torrent")
with open(filename) as _file:
filedump = base64.encodestring(_file.read())
torrent_id = yield self.core.add_torrent_file(filename, filedump, options)
@ -217,12 +214,12 @@ class CoreTestCase(BaseTestCase):
@defer.inlineCallbacks
def test_remove_torrents(self):
options = {}
filename = os.path.join(os.path.dirname(__file__), "test.torrent")
filename = common.rpath("test.torrent")
with open(filename) as _file:
filedump = base64.encodestring(_file.read())
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:
filedump = base64.encodestring(_file.read())
torrent_id2 = yield self.core.add_torrent_file(filename2, filedump, options)
@ -240,7 +237,7 @@ class CoreTestCase(BaseTestCase):
@defer.inlineCallbacks
def test_remove_torrents_invalid(self):
options = {}
filename = os.path.join(os.path.dirname(__file__), "test.torrent")
filename = common.rpath("test.torrent")
with open(filename) as _file:
filedump = base64.encodestring(_file.read())
torrent_id = yield self.core.add_torrent_file(filename, filedump, options)

View File

@ -14,8 +14,6 @@ from deluge.httpdownloader import download_file
from deluge.log import setup_logger
from deluge.ui.web.common import compress
from . import common
try:
from twisted.web.resource import Resource
except ImportError:
@ -23,7 +21,6 @@ except ImportError:
from twisted.web.error import Resource
rpath = common.rpath
temp_dir = tempfile.mkdtemp()

View File

@ -52,7 +52,7 @@ class TorrentTestCase(BaseTestCase):
self.assertEquals(torrent.state, state)
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:
info = lt.torrent_info(lt.bdecode(_file.read()))
atp = {"ti": info}
@ -117,7 +117,7 @@ class TorrentTestCase(BaseTestCase):
@defer.inlineCallbacks
def test_torrent_error_data_missing(self):
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:
filedump = base64.encodestring(_file.read())
torrent_id = yield self.core.add_torrent_file(filename, filedump, options)
@ -133,7 +133,7 @@ class TorrentTestCase(BaseTestCase):
@defer.inlineCallbacks
def test_torrent_error_resume_original_state(self):
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:
filedump = base64.encodestring(_file.read())
torrent_id = yield self.core.add_torrent_file(filename, filedump, options)
@ -178,7 +178,7 @@ class TorrentTestCase(BaseTestCase):
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:
filedump = _file.read()
torrent_id = yield self.core.torrentmanager.add(state=torrent_state, filedump=filedump,

View File

@ -1,5 +1,4 @@
import base64
import os
import warnings
import pytest
@ -30,7 +29,7 @@ class TorrentmanagerTestCase(BaseTestCase):
@defer.inlineCallbacks
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:
filedump = base64.encodestring(_file.read())
torrent_id = yield self.core.add_torrent_file(filename, filedump, {})

View File

@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
import os.path
from twisted.trial import unittest
from deluge.ui.common import TorrentInfo
from . import common
class UICommonTestCase(unittest.TestCase):
def setUp(self): # NOQA
@ -14,12 +15,12 @@ class UICommonTestCase(unittest.TestCase):
pass
def test_utf8_encoded_paths(self):
filename = os.path.join(os.path.dirname(__file__), "test.torrent")
filename = common.rpath("test.torrent")
ti = TorrentInfo(filename)
self.assertTrue("azcvsupdater_2.6.2.jar" in ti.files_tree)
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)
files = ti.files_tree["unicode_filenames"]

View File

@ -7,7 +7,6 @@
# See LICENSE for more details.
#
import os
from StringIO import StringIO
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]))
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)
self.assertEquals(ret["name"], "azcvsupdater_2.6.2.jar")
self.assertEquals(ret["info_hash"], "ab570cdd5a17ea1b61e970bb72047de141bce173")
@ -171,7 +170,7 @@ class WebAPITestCase(BaseTestCase, DaemonBase):
@defer.inlineCallbacks
def test_get_torrent_files(self):
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/"}}]
yield self.deluge_web.web_api.add_torrents(torrents)
ret = yield self.deluge_web.web_api.get_torrent_files("ab570cdd5a17ea1b61e970bb72047de141bce173")