Skip to content

Commit

Permalink
Refactor constant to external class
Browse files Browse the repository at this point in the history
  • Loading branch information
ardhipoetra committed Jul 2, 2016
1 parent 63f49df commit 83264c5
Show file tree
Hide file tree
Showing 26 changed files with 80 additions and 74 deletions.
7 changes: 3 additions & 4 deletions Tribler/Test/API/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import threading
from Tribler.Core.Utilities.network_utils import get_random_port
from Tribler.Core.simpledefs import dlstatus_strings, DLSTATUS_DOWNLOADING
from Tribler.Test.common import UBUNTU_1504_INFOHASH
from Tribler.Test.common import UBUNTU_1504_INFOHASH, TORRENT_UBUNTU_FILE
from Tribler.Test.test_as_server import TestAsServer
from Tribler.Test.test_libtorrent_download import TORRENT_FILE


class TestDownload(TestAsServer):
Expand Down Expand Up @@ -39,7 +38,7 @@ def test_download_torrent_from_url(self):
# Setup file server to serve torrent file
files_path = os.path.join(self.session_base_dir, 'http_torrent_files')
os.mkdir(files_path)
shutil.copyfile(TORRENT_FILE, os.path.join(files_path, 'ubuntu.torrent'))
shutil.copyfile(TORRENT_UBUNTU_FILE, os.path.join(files_path, 'ubuntu.torrent'))
file_server_port = get_random_port()
self.setUpFileServer(file_server_port, files_path)

Expand All @@ -57,7 +56,7 @@ def test_download_torrent_from_magnet(self):

def test_download_torrent_from_file(self):
from urllib import pathname2url
d = self.session.start_download_from_uri('file:' + pathname2url(TORRENT_FILE))
d = self.session.start_download_from_uri('file:' + pathname2url(TORRENT_UBUNTU_FILE))
self._logger.debug("Download started: %s", d)
d.set_state_callback(self.downloader_state_callback)
assert self.downloading_event.wait(60)
Expand Down
4 changes: 2 additions & 2 deletions Tribler/Test/API/test_seeding.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from Tribler.Core.TorrentDef import TorrentDef
from Tribler.Core.simpledefs import DLSTATUS_SEEDING, dlstatus_strings
from Tribler.Test.btconn import BTConnection
from Tribler.Test.test_as_server import TESTS_DATA_DIR, TestAsServer

from Tribler.Test.test_as_server import TestAsServer
from Tribler.Test.common import TESTS_DATA_DIR

CHOKE = chr(0)
EXTEND = chr(20)
Expand Down
14 changes: 7 additions & 7 deletions Tribler/Test/Core/CreditMining/test_creditmining_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from Tribler.Main.Utility.GuiDBTuples import CollectedTorrent
from Tribler.Policies.BoostingManager import BoostingManager, BoostingSettings
from Tribler.Test.Core.CreditMining.mock_creditmining import MockLtTorrent, ResourceFailClass
from Tribler.Test.test_as_server import TestAsServer, TESTS_DATA_DIR
from Tribler.Test.test_libtorrent_download import TORRENT_FILE, TORRENT_FILE_INFOHASH
from Tribler.Test.test_as_server import TestAsServer
from Tribler.Test.common import TORRENT_UBUNTU_FILE, TORRENT_UBUNTU_FILE_INFOHASH, TESTS_DATA_DIR
from Tribler.Test.util import prepare_xml_rss
from Tribler.community.allchannel.community import AllChannelCommunity
from Tribler.community.channel.community import ChannelCommunity
Expand Down Expand Up @@ -147,7 +147,7 @@ def setUp(self, autoload_discovery=True):

files_path, self.file_server_port = prepare_xml_rss(self.session_base_dir, 'test_rss_cm.xml')

shutil.copyfile(TORRENT_FILE, os.path.join(files_path, 'ubuntu.torrent'))
shutil.copyfile(TORRENT_UBUNTU_FILE, os.path.join(files_path, 'ubuntu.torrent'))
self.setUpFileServer(self.file_server_port, self.session_base_dir)

self.rss_error_deferred = defer.Deferred()
Expand Down Expand Up @@ -277,7 +277,7 @@ class TestBoostingManagerSysChannel(TestBoostingManagerSys):

def __init__(self, *argv, **kwargs):
super(TestBoostingManagerSysChannel, self).__init__(*argv, **kwargs)
self.tdef = TorrentDef.load(TORRENT_FILE)
self.tdef = TorrentDef.load(TORRENT_UBUNTU_FILE)
self.channel_id = 0
self.expected_votecast_cid = None
self.expected_votecast_vote = None
Expand Down Expand Up @@ -338,7 +338,7 @@ def create_torrents_in_channel(self, dispersy_cid_hex):
self.channel_id = self.insert_channel_in_db(dispersy_cid_hex.decode('hex'), 42,
'Simple Channel', 'Channel description')

torrent_list = [[self.channel_id, 1, 1, TORRENT_FILE_INFOHASH, 1460000000, TORRENT_FILE,
torrent_list = [[self.channel_id, 1, 1, TORRENT_UBUNTU_FILE_INFOHASH, 1460000000, TORRENT_UBUNTU_FILE,
self.tdef.get_files_as_unicode_with_length(), self.tdef.get_trackers_as_single_tuple()]]

self.insert_torrents_into_channel(torrent_list)
Expand Down Expand Up @@ -388,10 +388,10 @@ def check_torrents_channel(src, defer_param=None, target=1):
if not src_obj or len(src_obj.torrents) < target:
success = False
reactor.callLater(1, check_torrents_channel, src, defer_param, target=target)
elif not self.boosting_manager.torrents.get(TORRENT_FILE_INFOHASH, None):
elif not self.boosting_manager.torrents.get(TORRENT_UBUNTU_FILE_INFOHASH, None):
success = False
reactor.callLater(1, check_torrents_channel, src, defer_param, target=target)
elif not self.boosting_manager.torrents[TORRENT_FILE_INFOHASH].get('download', None):
elif not self.boosting_manager.torrents[TORRENT_UBUNTU_FILE_INFOHASH].get('download', None):
success = False
reactor.callLater(1, check_torrents_channel, src, defer_param, target=target)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from Tribler.Core.TorrentDef import TorrentDef
from Tribler.Core.Utilities.configparser import CallbackConfigParser
from Tribler.Core.Utilities.twisted_thread import deferred, reactor
from Tribler.Test.test_as_server import TestAsServer, TESTS_DATA_DIR
from Tribler.Test.test_as_server import TestAsServer
from Tribler.Test.common import TESTS_DATA_DIR


class TestLibtorrentDownloadImpl(TestAsServer):
Expand Down
2 changes: 1 addition & 1 deletion Tribler/Test/Core/Modules/Channel/test_channel_rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from Tribler.Core.Modules.channel.channel_rss import ChannelRssParser, RSSFeedParser
from Tribler.Test.Core.Modules.Channel.base_test_channel import BaseTestChannel
from Tribler.Test.Core.base_test import TriblerCoreTest
from Tribler.Test.test_as_server import TESTS_DATA_DIR
from Tribler.Test.common import TESTS_DATA_DIR


class TestChannelRss(BaseTestChannel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
from Tribler.Core.Utilities.twisted_thread import deferred
from Tribler.Test.Core.Modules.RestApi.Channels.test_channels_endpoint import AbstractTestChannelsEndpoint
from Tribler.Test.Core.base_test import MockObject
from Tribler.Test.test_libtorrent_download import TORRENT_FILE
from Tribler.Test.common import TORRENT_UBUNTU_FILE
from Tribler.dispersy.exception import CommunityNotFoundException


class TestChannelTorrentsEndpoint(AbstractTestChannelsEndpoint):

@deferred(timeout=10)
Expand Down Expand Up @@ -50,7 +49,7 @@ def test_add_torrent_to_channel(self):
Testing whether adding a torrent to your channels works
"""
my_channel_id = self.create_fake_channel("channel", "")
torrent_path = TORRENT_FILE
torrent_path = TORRENT_UBUNTU_FILE

def verify_method_invocation(channel_id, torrent_def, extra_info=None, forward=True):
self.assertEqual(my_channel_id, channel_id)
Expand All @@ -76,7 +75,7 @@ def test_add_torrent_to_channel_with_description(self):
Testing whether adding a torrent with a description to a channel works
"""
my_channel_id = self.create_fake_channel("channel", "")
torrent_path = TORRENT_FILE
torrent_path = TORRENT_UBUNTU_FILE

def verify_method_invocation(channel_id, torrent_def, extra_info=None, forward=True):
self.assertEqual(my_channel_id, channel_id)
Expand Down Expand Up @@ -121,7 +120,7 @@ def test_add_torrent_to_channel_500(self):
Testing whether the API returns a formatted 500 error if ValueError is raised
"""
self.create_fake_channel("channel", "")
torrent_path = TORRENT_FILE
torrent_path = TORRENT_UBUNTU_FILE

def fake_error(channel_id, torrent_def, extra_info=None, forward=True):
raise ValueError("Test error")
Expand Down Expand Up @@ -167,7 +166,7 @@ def test_add_torrent_from_url_to_channel_with_description(self):
# Setup file server to serve torrent file
files_path = os.path.join(self.session_base_dir, 'http_torrent_files')
os.mkdir(files_path)
shutil.copyfile(TORRENT_FILE, os.path.join(files_path, 'ubuntu.torrent'))
shutil.copyfile(TORRENT_UBUNTU_FILE, os.path.join(files_path, 'ubuntu.torrent'))
file_server_port = get_random_port()
self.setUpFileServer(file_server_port, files_path)

Expand All @@ -194,7 +193,7 @@ def test_add_torrent_from_magnet_to_channel_without_description(self):
Testing whether adding a torrent with a magnet link to a channel without description works
"""
my_channel_id = self.create_fake_channel("channel", "")
torrent_path = TORRENT_FILE
torrent_path = TORRENT_UBUNTU_FILE

def fake_load_from_dht(_, callback):
meta_info = TorrentDef.load(torrent_path).get_metainfo()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from Tribler.Core.DownloadConfig import DownloadStartupConfig
from Tribler.Core.Utilities.twisted_thread import deferred
from Tribler.Test.Core.Modules.RestApi.base_api_test import AbstractApiTest
from Tribler.Test.test_as_server import TESTS_DATA_DIR
from Tribler.Test.common import TESTS_DATA_DIR


class TestDownloadsEndpoint(AbstractApiTest):
Expand Down
10 changes: 5 additions & 5 deletions Tribler/Test/Core/Modules/test_watch_folder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import shutil
from Tribler.Test.test_as_server import TestAsServer, TESTS_DATA_DIR
from Tribler.Test.test_libtorrent_download import TORRENT_FILE
from Tribler.Test.test_as_server import TestAsServer
from Tribler.Test.common import TORRENT_UBUNTU_FILE, TESTS_DATA_DIR


class TestWatchFolder(TestAsServer):
Expand All @@ -21,18 +21,18 @@ def test_watchfolder_no_files(self):
self.assertEqual(len(self.session.get_downloads()), 0)

def test_watchfolder_no_torrent_file(self):
shutil.copyfile(TORRENT_FILE, os.path.join(self.watch_dir, "test.txt"))
shutil.copyfile(TORRENT_UBUNTU_FILE, os.path.join(self.watch_dir, "test.txt"))
self.session.lm.watch_folder.check_watch_folder()
self.assertEqual(len(self.session.get_downloads()), 0)

def test_watchfolder_invalid_dir(self):
shutil.copyfile(TORRENT_FILE, os.path.join(self.watch_dir, "test.txt"))
shutil.copyfile(TORRENT_UBUNTU_FILE, os.path.join(self.watch_dir, "test.txt"))
self.session.set_watch_folder_path(os.path.join(self.watch_dir, "test.txt"))
self.session.lm.watch_folder.check_watch_folder()
self.assertEqual(len(self.session.get_downloads()), 0)

def test_watchfolder_torrent_file_one_corrupt(self):
shutil.copyfile(TORRENT_FILE, os.path.join(self.watch_dir, "test.torrent"))
shutil.copyfile(TORRENT_UBUNTU_FILE, os.path.join(self.watch_dir, "test.torrent"))
shutil.copyfile(os.path.join(TESTS_DATA_DIR, 'test_rss.xml'), os.path.join(self.watch_dir, "test2.torrent"))
self.session.lm.watch_folder.check_watch_folder()
self.assertEqual(len(self.session.get_downloads()), 1)
Expand Down
6 changes: 3 additions & 3 deletions Tribler/Test/Core/Upgrade/test_db_upgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from Tribler.Core.Utilities.utilities import fix_torrent
from Tribler.Core.leveldbstore import LevelDbStore
from Tribler.Test.Core.Upgrade.upgrade_base import AbstractUpgrader, MockTorrentStore
from Tribler.Test.test_libtorrent_download import TORRENT_FILE, TORRENT_FILE_INFOHASH
from Tribler.Test.common import TORRENT_UBUNTU_FILE, TORRENT_UBUNTU_FILE_INFOHASH


class TestDBUpgrader(AbstractUpgrader):
Expand Down Expand Up @@ -47,10 +47,10 @@ def test_reimport_torrents(self):
db_migrator.start_migrate()

# Import a torrent
self.torrent_store[TORRENT_FILE_INFOHASH] = fix_torrent(TORRENT_FILE)
self.torrent_store[TORRENT_UBUNTU_FILE_INFOHASH] = fix_torrent(TORRENT_UBUNTU_FILE)
self.torrent_store.flush()

db_migrator.reimport_torrents()

torrent_db_handler = TorrentDBHandler(self.session)
self.assertEqual(torrent_db_handler.getTorrentID(TORRENT_FILE_INFOHASH), 1)
self.assertEqual(torrent_db_handler.getTorrentID(TORRENT_UBUNTU_FILE_INFOHASH), 1)
4 changes: 2 additions & 2 deletions Tribler/Test/Core/Upgrade/test_torrent_upgrade_63_64.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from nose.tools import raises
from Tribler.Core.Upgrade.torrent_upgrade64 import TorrentMigrator64
from Tribler.Test.Core.base_test import TriblerCoreTest
from Tribler.Test.test_libtorrent_download import TORRENT_FILE
from Tribler.Test.common import TORRENT_UBUNTU_FILE


class AbstractTorrentUpgrade63to64(TriblerCoreTest):
Expand Down Expand Up @@ -35,7 +35,7 @@ def setUp(self):
self.write_data_to_file(os.path.join(self.torrent_collecting_dir, "torrent1.torrent"))
self.write_data_to_file(os.path.join(self.torrent_collecting_dir, "torrent2.torrent"))
os.mkdir(os.path.join(self.torrent_collecting_dir, "swift_reseeds"))
shutil.copyfile(TORRENT_FILE, os.path.join(self.torrent_collecting_dir, "torrent3.torrent"))
shutil.copyfile(TORRENT_UBUNTU_FILE, os.path.join(self.torrent_collecting_dir, "torrent3.torrent"))
shutil.copyfile(os.path.join(self.DB_DATA_DIR, "torrent_upgrade_64_dispersy.db"),
os.path.join(self.sqlite_path, "dispersy.db"))

Expand Down
6 changes: 3 additions & 3 deletions Tribler/Test/Core/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from Tribler.Core.TorrentDef import TorrentDef
from Tribler.Test.Core.base_test import TriblerCoreTest
from Tribler.Test.test_as_server import TestAsServer
from Tribler.Test.test_libtorrent_download import TORRENT_FILE
from Tribler.Test.common import TORRENT_UBUNTU_FILE
from Tribler.dispersy.util import blocking_call_on_reactor_thread


Expand Down Expand Up @@ -94,7 +94,7 @@ def test_add_torrent_def_to_channel(self):
"""
test_deferred = Deferred()

torrent_def = TorrentDef.load(TORRENT_FILE)
torrent_def = TorrentDef.load(TORRENT_UBUNTU_FILE)

@blocking_call_on_reactor_thread
def on_channel_created(subject, change_type, object_id, channel_data):
Expand All @@ -115,7 +115,7 @@ def test_add_torrent_def_to_channel_duplicate(self):
"""
test_deferred = Deferred()

torrent_def = TorrentDef.load(TORRENT_FILE)
torrent_def = TorrentDef.load(TORRENT_UBUNTU_FILE)

@blocking_call_on_reactor_thread
def on_channel_created(subject, change_type, object_id, channel_data):
Expand Down
2 changes: 1 addition & 1 deletion Tribler/Test/Core/test_sqlitecachedbhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from Tribler.Core.Session import Session
from Tribler.Core.SessionConfig import SessionStartupConfig
from Tribler.Test.Core.base_test import TriblerCoreTest
from Tribler.Test.test_as_server import TESTS_DATA_DIR
from Tribler.Test.common import TESTS_DATA_DIR
from Tribler.dispersy.util import blocking_call_on_reactor_thread


Expand Down
2 changes: 1 addition & 1 deletion Tribler/Test/Core/test_sqlitecachedbhandler_torrents.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from Tribler.Core.TorrentDef import TorrentDef
from Tribler.Core.leveldbstore import LevelDbStore
from Tribler.Test.Core.test_sqlitecachedbhandler import AbstractDB
from Tribler.Test.test_as_server import TESTS_DATA_DIR
from Tribler.Test.common import TESTS_DATA_DIR
from Tribler.dispersy.util import blocking_call_on_reactor_thread


Expand Down
8 changes: 4 additions & 4 deletions Tribler/Test/Core/test_torrent_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

import logging
import os
from nose.tools import raises

from libtorrent import bdecode

from nose.tools import raises

from Tribler.Core.TorrentDef import TorrentDef, TorrentDefNoMetainfo
from Tribler.Core.Utilities.utilities import isValidTorrentFile
from Tribler.Core.exceptions import TorrentDefNotFinalizedException
from Tribler.Core.simpledefs import INFOHASH_LENGTH
from Tribler.Test.test_as_server import BaseTestCase, TESTS_API_DIR, TESTS_DATA_DIR

from Tribler.Test.common import TESTS_DATA_DIR
from Tribler.Test.test_as_server import BaseTestCase

TRACKER = 'http:https://www.tribler.org/announce'

Expand Down
12 changes: 12 additions & 0 deletions Tribler/Test/common.py
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
import binascii
import os

UBUNTU_1504_INFOHASH = 'FC8A15A2FAF2734DBB1DC5F7AFDC5C9BEAEB1F59'.decode('hex')

TESTS_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
TESTS_API_DIR = os.path.abspath(os.path.join(TESTS_DIR, u"API"))
TESTS_DATA_DIR = os.path.abspath(os.path.join(TESTS_DIR, u"data"))

TORRENT_UBUNTU_FILE = os.path.join(TESTS_DATA_DIR, "ubuntu-15.04-desktop-amd64.iso.torrent")
TORRENT_UBUNTU_FILE_INFOHASH = binascii.unhexlify("fc8a15a2faf2734dbb1dc5f7afdc5c9beaeb1f59")
TORRENT_VIDEO_FILE = os.path.join(TESTS_DATA_DIR, "Night.Of.The.Living.Dead_1080p_archive.torrent")
TORRENT_VIDEO_FILE_INFOHASH = binascii.unhexlify("90ed3962785c52a774e89706fb4f811a468e6c05")
13 changes: 5 additions & 8 deletions Tribler/Test/test_as_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@

from twisted.internet import interfaces
from twisted.internet.base import BasePort
from twisted.internet.defer import Deferred, maybeDeferred, succeed
from twisted.internet.defer import maybeDeferred, succeed
from twisted.web.server import Site
from twisted.web.static import File

from Tribler.Core.DownloadConfig import DownloadStartupConfig
from Tribler.Core.TorrentDef import TorrentDef
from Tribler.Core.simpledefs import dlstatus_strings, DLSTATUS_SEEDING, UPLOAD

from Tribler.Main.Utility.utility import initialize_x11_threads
from Tribler.Test.common import TESTS_DIR
from Tribler.Test.util import process_unhandled_exceptions, process_unhandled_twisted_exceptions

initialize_x11_threads()

# set wxpython version before importing wx or anything from Tribler
Expand Down Expand Up @@ -45,7 +47,7 @@
from traceback import print_exc

import wx
from .util import process_unhandled_exceptions, UnhandledTwistedExceptionCatcher, process_unhandled_twisted_exceptions


from Tribler.Core.Utilities.twisted_thread import deferred
from Tribler.Core import defaults
Expand All @@ -54,11 +56,6 @@
from Tribler.Core.Utilities.instrumentation import WatchDog
from Tribler.dispersy.util import blocking_call_on_reactor_thread


TESTS_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
TESTS_DATA_DIR = os.path.abspath(os.path.join(TESTS_DIR, u"data"))
TESTS_API_DIR = os.path.abspath(os.path.join(TESTS_DIR, u"API"))

defaults.sessdefaults['general']['minport'] = -1
defaults.sessdefaults['general']['maxport'] = -1
defaults.sessdefaults['dispersy']['dispersy_port'] = -1
Expand Down
4 changes: 2 additions & 2 deletions Tribler/Test/test_gui_dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@


# Import WX after selecting the version
from Tribler.Test.test_as_server import TestGuiAsServer, TESTS_DATA_DIR, wx
from Tribler.Test.test_libtorrent_download import TORRENT_VIDEO_FILE
from Tribler.Test.test_as_server import TestGuiAsServer, wx
from Tribler.Test.common import TORRENT_VIDEO_FILE, TESTS_DATA_DIR

from Tribler.Main.Dialogs.ConfirmationDialog import ConfirmationDialog
from Tribler.Main.Dialogs.AddTorrent import AddTorrent
Expand Down
11 changes: 3 additions & 8 deletions Tribler/Test/test_libtorrent_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@
import shutil
import unittest
from time import time
from Tribler.Core.Utilities.network_utils import get_random_port

from Tribler.Test.common import UBUNTU_1504_INFOHASH
from Tribler.Test.test_as_server import TestGuiAsServer, TESTS_DATA_DIR
from Tribler.Core.Utilities.network_utils import get_random_port
from Tribler.Core.simpledefs import DOWNLOAD, DLSTATUS_SEEDING

TORRENT_FILE = os.path.join(TESTS_DATA_DIR, "ubuntu-15.04-desktop-amd64.iso.torrent")
TORRENT_FILE_INFOHASH = binascii.unhexlify("fc8a15a2faf2734dbb1dc5f7afdc5c9beaeb1f59")
TORRENT_VIDEO_FILE = os.path.join(TESTS_DATA_DIR, "Night.Of.The.Living.Dead_1080p_archive.torrent")
TORRENT_VIDEO_FILE_INFOHASH = binascii.unhexlify("90ed3962785c52a774e89706fb4f811a468e6c05")
from Tribler.Test.common import UBUNTU_1504_INFOHASH, TORRENT_VIDEO_FILE, TORRENT_VIDEO_FILE_INFOHASH, TESTS_DATA_DIR
from Tribler.Test.test_as_server import TestGuiAsServer


class TestLibtorrentDownload(TestGuiAsServer):
Expand Down
Loading

0 comments on commit 83264c5

Please sign in to comment.