desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Adding corrupt values should result in the default value.
Note that this test might fail if there is already an upgraded config stored in the default
state directory. The code being tested here however shouldn\'t be ran if that config already exists.
:return:'
| def test_read_test_corr_tribler_conf(self):
| old_config = RawConfigParser()
old_config.read(os.path.join(self.CONFIG_PATH, 'triblercorrupt70.conf'))
new_config = TriblerConfig()
result_config = add_tribler_config(new_config, old_config)
self.assertEqual(result_config.get_default_anonymity_enabled(), True)
|
'Adding corrupt values should result in the default value.
Note that this test might fail if there is already an upgraded config stored in the default
state directory. The code being tested here however shouldn\'t be ran if that config already exists.
:return:'
| def test_read_test_corr_libtribler_conf(self):
| old_config = RawConfigParser()
old_config.read(os.path.join(self.CONFIG_PATH, 'libtriblercorrupt70.conf'))
new_config = TriblerConfig(ConfigObj(configspec=CONFIG_SPEC_PATH))
result_config = add_libtribler_config(new_config, old_config)
self.assertTrue(result_config.get_permid_keypair_filename().ends... |
'We no longer support DB versions older than 17 (Tribler 6.0)'
| def test_upgrade_from_obsolete_version(self):
| self.copy_and_initialize_upgrade_database('tribler_v12.sdb')
db_migrator = DBUpgrader(self.session, self.sqlitedb, torrent_store=MockTorrentStore())
self.assertRaises(VersionNoLongerSupportedError, db_migrator.start_migrate)
|
'Test the run method of the upgrader'
| @blocking_call_on_reactor_thread
def test_run(self):
| def check_should_upgrade():
self.upgrader.failed = True
return (True, False)
self.upgrader.session.config.get_upgrader_enabled = (lambda : True)
self.upgrader.check_should_upgrade_database = check_should_upgrade
self.upgrader.run()
self.assertTrue(self.upgrader.notified)
|
'Testing whether the right results are returned when searching in the local database for channels'
| def test_search_local_channels(self):
| results = self.cdb.search_in_local_channels_db('fancy')
self.assertEqual(len(results), 2)
self.assertNotEqual(results[0][(-1)], 0.0)
results = self.cdb.search_in_local_channels_db('fdajlkerhui')
self.assertEqual(len(results), 0)
|
'Setup some classes and files that are used by the tests in this module.'
| @blocking_call_on_reactor_thread
@inlineCallbacks
def setUp(self, annotate=True, autoload_discovery=True):
| (yield super(BaseTestChannel, self).setUp(autoload_discovery=autoload_discovery))
if annotate:
self.annotate(self._testMethodName, start=True)
self.fake_session = MockObject()
self.fake_session.add_observer = (lambda a, b, c: False)
self.fake_session_config = MockObject()
self.fake_sessi... |
'This method creates a fake AllChannel community so we can check whether a request is made in the community
when doing stuff with a channel.'
| @blocking_call_on_reactor_thread
def create_fake_allchannel_community(self):
| self.session.lm.dispersy._database.open()
fake_member = DummyMember(self.session.lm.dispersy, 1, ('a' * 20))
member = self.session.lm.dispersy.get_new_member(u'curve25519')
fake_community = AllChannelCommunity(self.session.lm.dispersy, fake_member, member)
self.session.lm.dispersy._communities = {'a... |
'Test the pass through function of Session.create_channel to the ChannelManager.'
| def test_create_channel(self):
| class LmMock(object, ):
class ChannelManager(object, ):
invoked_name = None
invoked_desc = None
invoked_mode = None
def create_channel(self, name, description, mode=u'closed'):
self.invoked_name = name
self.invoked_desc = descri... |
'Test the unhandled error observer'
| def test_unhandled_error_observer(self):
| self.mock_endpoints()
expected_text = ''
def on_tribler_exception(exception_text):
self.assertEqual(exception_text, expected_text)
on_tribler_exception.called = 0
self.session.lm.api_manager.root_endpoint.events_endpoint.on_tribler_exception = on_tribler_exception
self.session.lm.api_man... |
'Testing whether some errors are ignored (like socket errors)'
| def test_error_observer_ignored_error(self):
| self.mock_endpoints()
def on_tribler_exception(_):
raise RuntimeError('This method cannot be called!')
self.session.lm.api_manager.root_endpoint.events_endpoint.on_tribler_exception = on_tribler_exception
self.session.lm.api_manager.root_endpoint.state_endpoint.on_tribler_exception =... |
'Test whether adding a torrent def to a channel works'
| @deferred(timeout=10)
def test_add_torrent_def_to_channel(self):
| test_deferred = Deferred()
torrent_def = TorrentDef.load(TORRENT_UBUNTU_FILE)
@blocking_call_on_reactor_thread
def on_channel_created(subject, change_type, object_id, channel_data):
channel_id = self.channel_db_handler.getMyChannelId()
self.session.add_torrent_def_to_channel(channel_id, ... |
'Test whether adding a torrent def twice to a channel raises an exception'
| @deferred(timeout=10)
def test_add_torrent_def_to_channel_duplicate(self):
| test_deferred = Deferred()
torrent_def = TorrentDef.load(TORRENT_UBUNTU_FILE)
@blocking_call_on_reactor_thread
def on_channel_created(subject, change_type, object_id, channel_data):
channel_id = self.channel_db_handler.getMyChannelId()
try:
self.session.add_torrent_def_to_cha... |
'When libtorrent is not enabled, an exception should be thrown when getting the libtorrent instance.'
| @raises(OperationNotEnabledByConfigurationException)
def test_get_libtorrent_process_not_enabled(self):
| self.session.config.get_libtorrent_enabled = (lambda : False)
self.session.get_libtorrent_process()
|
'Opening the database without the megacache enabled should raise an exception.'
| @raises(OperationNotEnabledByConfigurationException)
def test_open_dbhandler(self):
| self.session.config.get_megacache_enabled = (lambda : False)
self.session.open_dbhandler('x')
|
'When libtorrent is not enabled, an exception should be thrown when downloading a torrentfile.'
| def test_download_torrentfile(self):
| self.called = False
def verify_download_torrentfile_call(*args, **kwargs):
self.called = True
self.session.lm.rtorrent_handler.download_torrent = verify_download_torrentfile_call
self.session.download_torrentfile()
self.assertTrue(self.called)
|
'When libtorrent is not enabled, an exception should be thrown when downloading a torrentfile from a peer.'
| def test_download_torrentfile_from_peer(self):
| self.called = False
def verify_download_torrentfile_call(*args, **kwargs):
self.called = True
self.session.lm.rtorrent_handler.download_torrent = verify_download_torrentfile_call
self.session.download_torrentfile_from_peer('a')
self.assertTrue(self.called)
|
'When libtorrent is not enabled, an exception should be thrown when downloading a torrentfile from a peer.'
| def test_download_torrentmessage_from_peer(self):
| self.called = False
def verify_download_torrentmessage_call(*args, **kwargs):
self.called = True
self.session.lm.rtorrent_handler.download_torrentmessage = verify_download_torrentmessage_call
self.session.download_torrentmessage_from_peer('a', 'b', 'c')
self.assertTrue(self.called)
|
'Retrieving the string encoded permid should be successful.'
| def test_get_permid(self):
| self.assertIsInstance(self.session.get_permid(), str)
|
'Remove downloads method when empty.'
| def test_remove_download_by_id_empty(self):
| self.session.remove_download_by_id('nonexisting_infohash')
self.assertEqual(len(self.session.get_downloads()), 0)
|
'Remove an existing download.'
| def test_remove_download_by_id_nonempty(self):
| infohash = 'abc'
download = MockObject()
torrent_def = MockObject()
torrent_def.get_infohash = (lambda : infohash)
download.get_def = (lambda : torrent_def)
self.session.get_downloads = (lambda : [download])
self.called = False
def verify_remove_download_called(*args, **kwargs):
... |
'Test whether the get dispersy instance throws an exception if dispersy is not enabled.'
| @raises(OperationNotEnabledByConfigurationException)
def test_get_dispersy_instance(self):
| self.session.config.get_dispersy_enabled = (lambda : False)
self.session.get_dispersy_instance()
|
'Test whether the has_collected_torrent throws an exception if dispersy is not enabled.'
| @raises(OperationNotEnabledByConfigurationException)
def test_has_collected_torrent(self):
| self.session.config.get_torrent_store_enabled = (lambda : False)
self.session.has_collected_torrent(None)
|
'Test whether the get_collected_torrent throws an exception if dispersy is not enabled.'
| @raises(OperationNotEnabledByConfigurationException)
def test_get_collected_torrent(self):
| self.session.config.get_torrent_store_enabled = (lambda : False)
self.session.get_collected_torrent(None)
|
'Test whether the save_collected_torrent throws an exception if dispersy is not enabled.'
| @raises(OperationNotEnabledByConfigurationException)
def test_save_collected_torrent(self):
| self.session.config.get_torrent_store_enabled = (lambda : False)
self.session.save_collected_torrent(None, None)
|
'Test whether the delete_collected_torrent throws an exception if dispersy is not enabled.'
| @raises(OperationNotEnabledByConfigurationException)
def test_delete_collected_torrent(self):
| self.session.config.get_torrent_store_enabled = (lambda : False)
self.session.delete_collected_torrent(None)
|
'Test whether the search_remote_channels throws an exception if dispersy is not enabled.'
| @raises(OperationNotEnabledByConfigurationException)
def test_search_remote_channels(self):
| self.session.config.get_channel_search_enabled = (lambda : False)
self.session.search_remote_channels(None)
|
'Test whether the get_thumbnail_data throws an exception if dispersy is not enabled.'
| @raises(OperationNotEnabledByConfigurationException)
def test_get_thumbnail_data(self):
| self.session.lm.metadata_store = None
self.session.get_thumbnail_data(None)
|
'testing random policy'
| def test_random_policy(self):
| rdrwh = random.WichmannHill(0)
policy = RandomPolicy(self.session)
policy.key = (lambda _: rdrwh.random())
(torrents_start, torrents_stop) = policy.apply(self.torrents, 6, force=True)
ids_start = [torrent['metainfo'].get_infohash() for torrent in torrents_start]
self.assertEqual(1, len(ids_start... |
'testing seeder ratio policy'
| def test_seederratio_policy(self):
| policy = SeederRatioPolicy(self.session)
(torrents_start, torrents_stop) = policy.apply(self.torrents, 6, force=True)
ids_start = [torrent['metainfo'].get_infohash() for torrent in torrents_start]
self.assertEqual(ids_start, [10, 8, 6])
ids_stop = [torrent['metainfo'].get_infohash() for torrent in t... |
'testing policy (seederratio) and then fallback'
| @skip('The random seed is not reliable')
def test_fallback_policy(self):
| for i in xrange(1, 11):
mock_metainfo = MockMeta(i)
self.torrents[i] = {'metainfo': mock_metainfo, 'num_seeders': (- i), 'num_leechers': (- i), 'creation_date': i}
random.seed(0)
policy = SeederRatioPolicy(self.session)
(torrents_start, torrents_stop) = policy.apply(self.torrents, 6)
... |
'test policy based on creation date'
| def test_creationdate_policy(self):
| policy = CreationDatePolicy(self.session)
(torrents_start, torrents_stop) = policy.apply(self.torrents, 5, force=True)
ids_start = [torrent['metainfo'].get_infohash() for torrent in torrents_start]
self.assertEqual(ids_start, [10, 8, 6])
ids_stop = [torrent['metainfo'].get_infohash() for torrent in ... |
'Test whether boosting manager dependencies works or not.
In all test, check dependencies always off. In production, it is on by default.'
| def test_boosting_dependencies(self):
| self.bsettings.check_dependencies = True
self.bsettings.initial_swarm_interval = 9000
self.bsettings.initial_tracker_interval = 9000
self.bsettings.initial_logging_interval = 9000
self.session.open_dbhandler = (lambda _: None)
self.session.lm.ltmgr = MockLtSession()
self.session.config.get_t... |
'Test load default configuration in BoostingManager'
| def test_load_default(self):
| self.bsettings.load_config = True
self.bsettings.auto_start_source = False
self.bsettings.initial_swarm_interval = 9000
self.bsettings.initial_tracker_interval = 9000
self.bsettings.initial_logging_interval = 9000
self.session.open_dbhandler = (lambda _: None)
self.session.lm.ltmgr = MockLtS... |
'test - predict number of seeder and leecher only based on peer discovered and
their activities'
| def test_translate_peer_info(self):
| peerlist_dict = []
for peer in self.peer:
peerlist_dict.append(LibtorrentDownloadImpl.create_peerlist_data(peer))
(num_seed, num_leech) = utilities.translate_peers_into_health(peerlist_dict)
self.assertEqual(num_seed, 4, "Seeder number don't match")
self.assertEqual(num_leech, 3, "L... |
'test levenshtein between two string (in this case, file name)
source :
http://people.cs.pitt.edu/~kirk/cs1501/Pruhs/Fall2006/Assignments/editdistance/Levenshtein%20Distance.htm'
| def test_levenshtein(self):
| string1 = 'GUMBO'
string2 = 'GAMBOL'
dist = levenshtein_dist(string1, string2)
dist_swap = levenshtein_dist(string2, string1)
self.assertEqual(dist, 2, 'Wrong levenshtein distance')
self.assertEqual(dist_swap, 2, 'Wrong levenshtein distance')
string1 = 'ubuntu-15.10-desktop-i386.... |
'test updating statistics of a torrent (pick a new one)'
| def test_update_statistics(self):
| self.session.open_dbhandler = (lambda _: None)
infohash_1 = ('a' * 20)
infohash_2 = ('b' * 20)
torrents = {infohash_1: {'last_seeding_stats': {'time_seeding': 100, 'value': 5}}, infohash_2: {'last_seeding_stats': {}}}
new_seeding_stats = {'time_seeding': 110, 'value': 1}
new_seeding_stats_unexis... |
'testing escape symbols occured in xml/rss document file.'
| def test_escape_xml(self):
| re_symbols = re.compile('\\&\\#(x?[0-9a-fA-F]+);')
ampersand_str = re_symbols.sub(ent2chr, '&')
self.assertEqual(ampersand_str, '&', ('wrong ampersand conversion %s' % ampersand_str))
str_123 = re_symbols.sub(ent2chr, '123')
self.assertEqual(str_123, '123', ('wrong nu... |
'testing insert torrent on unknown source'
| def test_insert_torrent_unknown_source(self):
| torrent = {'preload': False, 'metainfo': MockMeta('1234'), 'infohash': '12345'}
self.boosting_manager.on_torrent_insert(binascii.unhexlify(('abcd' * 10)), '12345', torrent)
self.assertNotIn('12345', self.boosting_manager.torrents)
|
'testing uknkown source added to boosting source, and try to apply archive
on top of that'
| def test_unknown_source(self):
| unknown_key = '1234567890'
sources = len(self.boosting_manager.boosting_sources.keys())
self.boosting_manager.add_source(unknown_key)
self.boosting_manager.set_archive(unknown_key, False)
self.assertEqual(sources, len(self.boosting_manager.boosting_sources.keys()), 'unknown source added')
|
'test assertion error then not download the actual torrent'
| def test_failed_start_download(self):
| torrent = {'preload': False, 'metainfo': MockMeta('1234')}
self.session.lm.download_exists = (lambda _: True)
self.boosting_manager.start_download(torrent)
self.assertNotIn('download', torrent, ('%s downloading despite error' % torrent))
|
'set settings in credit mining'
| def set_boosting_settings(self):
| self.bsettings = BoostingSettings(policy=SeederRatioPolicy(self.session))
self.bsettings.credit_mining_path = os.path.join(self.session_base_dir, 'credit_mining')
self.bsettings.load_config = False
self.bsettings.check_dependencies = False
self.bsettings.min_connection_start = (-1)
self.bsetting... |
'Check if a specified number of torrent has been added to the passed source.'
| def check_torrents(self, src, target=1):
| defer_param = defer.Deferred()
def do_check():
src_obj = self.boosting_manager.get_source_object(src)
if (src_obj and (len(src_obj.torrents) >= target)):
def _get_tor_dummy(_, keys=123, include_mypref=True):
'\n ... |
'function to check if a source is ready initializing'
| def check_source(self, src):
| defer_param = defer.Deferred()
def do_check():
src_obj = self.boosting_manager.get_source_object(src)
if (src_obj and src_obj.ready):
self._check_source_lc.stop()
self._check_source_lc = None
defer_param.callback(src)
self._check_source_lc = LoopingCall(do... |
'test rss source'
| @deferred(timeout=30)
def test_rss(self):
| url = ('http://localhost:%s/test_rss_cm.xml' % self.file_server_port)
self.boosting_manager.add_source(url)
rss_obj = self.boosting_manager.get_source_object(url)
rss_obj.start()
d = self.check_source(url)
d.addCallback(self.check_torrents, target=1)
return d
|
'dummy errback when RSS source produces an error'
| def _on_error_rss(self, dummy_1, dummy_2):
| self.rss_error_deferred.callback(True)
|
'Testing an unexisting RSS feed'
| @deferred(timeout=8)
def test_rss_unexist(self):
| url = ('http://localhost:%s/nothingness' % self.file_server_port)
self.boosting_manager.add_source(url)
rss_obj = self.boosting_manager.get_source_object(url)
rss_obj._on_error_rss = self._on_error_rss
rss_obj.start()
return self.rss_error_deferred
|
'Testing an unavailable RSS feed'
| @deferred(timeout=8)
def test_rss_unavailable(self):
| url = ('http://localhost:%s/err503' % self.file_server_port)
self.boosting_manager.add_source(url)
rss_obj = self.boosting_manager.get_source_object(url)
rss_obj._on_error_rss = self._on_error_rss
rss_obj.start()
return self.rss_error_deferred
|
'test directory filled with .torrents'
| @deferred(timeout=10)
def test_dir(self):
| self.boosting_manager.add_source(TESTS_DATA_DIR)
len_source = len(self.boosting_manager.boosting_sources)
self.boosting_manager.add_source(TESTS_DATA_DIR)
self.assertEqual(len(self.boosting_manager.boosting_sources), len_source, 'identical source added')
dir_obj = self.boosting_manager.get_sou... |
'test archive mode. Use diretory because easier to fetch torrent'
| @deferred(timeout=10)
def test_dir_archive_example(self):
| self.boosting_manager.add_source(TESTS_DATA_DIR)
self.boosting_manager.set_archive(TESTS_DATA_DIR, True)
dir_obj = self.boosting_manager.get_source_object(TESTS_DATA_DIR)
self.assertTrue(dir_obj.ready, 'Not Ready')
def check_archive(_):
'\n f... |
'Dummy method to download the torrent'
| def _load(self, _):
| return defer.succeed(self.tdef)
|
'Helper function to insert 10 torrent into designated channel'
| @blocking_call_on_reactor_thread
def create_torrents_in_channel(self, dispersy_cid_hex):
| for i in xrange(0, 10):
self.insert_channel_in_db(('rand%d' % i), (42 + i), ('Test channel %d' % i), ('Test description %d' % i))
self.channel_id = self.insert_channel_in_db(dispersy_cid_hex.decode('hex'), 42, 'Simple Channel', 'Channel description')
torrent_list = [[self.channel_i... |
'testing channel source.
It includes finding and downloading actual torrent'
| @deferred(timeout=20)
def test_chn_lookup(self):
| self.create_fake_allchannel_community()
self.create_torrents_in_channel(self.dispersy_cid_hex)
self.boosting_manager.add_source(self.dispersy_cid)
chn_obj = self.boosting_manager.get_source_object(self.dispersy_cid)
def check_torrents_channel(src, defer_param=None, target=1):
'\n ... |
'testing existing channel as a source.
It also tests how boosting manager cope with unknown channel with retrying
the lookup'
| @deferred(timeout=30)
def test_chn_exist_lookup(self):
| self.create_fake_allchannel_community()
self.create_torrents_in_channel(self.dispersy_cid_hex)
community = ChannelCommunity.init_community(self.session.lm.dispersy, self.session.lm.dispersy.get_member(mid=self.dispersy_cid), self.session.lm.dispersy._communities['allchannel']._my_member, self.session)
i... |
'Test the restriction of max_torrents in a source.'
| @deferred(timeout=30)
def test_chn_max_torrents(self):
| self.create_fake_allchannel_community()
self.create_torrents_in_channel(self.dispersy_cid_hex)
pioneer_file = os.path.join(TESTS_DATA_DIR, 'Pioneer.One.S01E06.720p.x264-VODO.torrent')
pioneer_tdef = TorrentDef.load(pioneer_file)
pioneer_ihash = binascii.unhexlify('66ED7F30E3B30FA647ABAA19A36E7503AA0... |
'class returning peer info for a particular handle'
| def get_peer_info(self):
| peer = ([None] * 6)
peer[0] = MockLtPeer(MockPeerId('1'), 'ip1')
peer[0].setvalue(True, True, True)
peer[1] = MockLtPeer(MockPeerId('2'), 'ip2')
peer[1].setvalue(False, False, True)
peer[2] = MockLtPeer(MockPeerId('3'), 'ip3')
peer[2].setvalue(True, False, True)
peer[3] = MockLtPeer(Mock... |
'check whether the handle is valid or not'
| def is_valid(self):
| return True
|
'returning infohash of torrents'
| def get_infohash(self):
| return self.infohash
|
'supposed to get libtorrent session'
| def get_session(self):
| return self
|
'set settings (don\'t do anything)'
| def set_settings(self, _):
| pass
|
'obligatory shutdown function'
| def shutdown(self):
| pass
|
'mocked function to get a download'
| def get_download(self, x):
| return (x % 2)
|
'Testing the init method of DownloadState'
| def test_init(self):
| download_state = DownloadState(self.mock_download, DLSTATUS_DOWNLOADING, 'error', 0.5)
self.assertEqual(download_state.get_error(), 'error')
download_state = DownloadState(self.mock_download, DLSTATUS_SEEDING, None, 0.5)
self.assertEqual(download_state.get_status(), DLSTATUS_SEEDING)
download_state ... |
'Testing various getters and setters in DownloadState'
| def test_getters_setters_1(self):
| download_state = DownloadState(self.mock_download, DLSTATUS_DOWNLOADING, None, 0.5)
self.assertEqual(download_state.get_download(), self.mock_download)
self.assertEqual(download_state.get_progress(), 0.5)
self.assertEqual(download_state.get_status(), DLSTATUS_DOWNLOADING)
self.assertIsNone(download_... |
'Testing various getters and setters in DownloadState'
| def test_getters_setters_2(self):
| download_state = DownloadState(self.mock_download, DLSTATUS_DOWNLOADING, None, 0.5)
stats = {'up': 123, 'down': 1234, 'stats': self.mock_transferred, 'time': 42, 'vod_prebuf_frac_consec': 43, 'vod_prebuf_frac': 44, 'vod': True, 'tracker_status': {'a': 'b'}}
download_state.stats = stats
self.assertEqual(... |
'Testing whether the right completion of files is returned'
| def test_get_files_completion(self):
| self.mock_download.get_selected_files = (lambda : [['test.txt', 42]])
download_state = DownloadState(self.mock_download, DLSTATUS_DOWNLOADING, None, 0.6)
self.assertEqual(download_state.get_files_completion(), [(['test.txt', 42], 0.6)])
download_state.filepieceranges = [(5, 10, None, ['test.txt', 42])]
... |
'Testing whether the right availability of a file is returned'
| def test_get_availability(self):
| download_state = DownloadState(self.mock_download, DLSTATUS_DOWNLOADING, None, 0.6)
download_state.stats = {'spew': [{}]}
self.assertEqual(download_state.get_availability(), 0)
download_state.stats = {'spew': [{'completed': 1.0}]}
self.assertEqual(download_state.get_availability(), 1.0)
download... |
'Testing whether the right destination of a VOD download is returned'
| def test_get_vod_dest_dir(self):
| mock_download = MockObject()
mock_download.get_content_dest = (lambda : 'abc')
mock_download.get_selected_files = (lambda : ['def'])
mock_def = MockObject()
mock_def.is_multifile_torrent = (lambda : True)
mock_download.get_def = (lambda : mock_def)
self.assertEqual(self.video_server.get_vod_... |
'Testing whether the right VOD stream is returned'
| def test_get_vod_stream(self):
| self.mock_session.get_download = (lambda _: None)
self.assertEqual(self.video_server.get_vod_stream('abcd'), (None, None))
|
'unittest test setup code'
| @blocking_call_on_reactor_thread
@inlineCallbacks
def setUp(self, autoload_discovery=True):
| (yield TestAsServer.setUp(self, autoload_discovery=autoload_discovery))
self.port = self.session.config.get_video_server_port()
self.sourcefn = os.path.join(TESTS_DATA_DIR, 'video.avi')
self.sourcesize = os.path.getsize(self.sourcefn)
self.tdef = None
self.expsize = 0
(yield self.start_vod_d... |
'Testing whether the process checker returns false when there is no lock file.'
| def test_no_lock_file(self):
| process_checker = ProcessChecker(state_directory=self.state_dir)
self.assertTrue(os.path.exists(os.path.join(self.state_dir, LOCK_FILE_NAME)))
self.assertFalse(process_checker.already_running)
|
'Test whether a new lock file is created when an invalid pid is written inside the current lock file'
| def test_invalid_pid_in_lock_file(self):
| with open(os.path.join(self.state_dir, LOCK_FILE_NAME), 'wb') as lock_file:
lock_file.write('Hello world')
process_checker = ProcessChecker()
self.assertGreater(int(process_checker.get_pid_from_lock_file()), 0)
|
'Testing whether the process checker returns false when it finds its own pid in the lock file.'
| def test_own_pid_in_lock_file(self):
| self.create_lock_file_with_pid(os.getpid())
process_checker = ProcessChecker(state_directory=self.state_dir)
self.assertFalse(process_checker.already_running)
|
'Testing whether the process checker returns true when another process is running.'
| def test_other_instance_running(self):
| self.process = Process(target=process_dummy_function)
self.process.start()
self.create_lock_file_with_pid(self.process.pid)
process_checker = ProcessChecker(state_directory=self.state_dir)
self.assertTrue(process_checker.is_pid_running(self.process.pid))
self.assertTrue(process_checker.already_r... |
'Testing whether the process checker returns false when there is a dead pid in the lock file.'
| def test_dead_pid_in_lock_file(self):
| dead_pid = 134824733
self.create_lock_file_with_pid(dead_pid)
process_checker = ProcessChecker(state_directory=self.state_dir)
self.assertFalse(process_checker.is_pid_running(dead_pid))
self.assertFalse(process_checker.already_running)
|
'Setup the tests by creating the ChannelRssParser instance and initializing it.'
| def setUp(self, annotate=True):
| super(TestChannelRss, self).setUp(annotate=annotate)
self.channel_rss = ChannelRssParser(self.fake_session, self.fake_channel_community, 'a')
self.channel_rss.initialize()
|
'Setup the tests by creating the ChannelObject instance.'
| def setUp(self, annotate=True):
| super(TestChannel, self).setUp(annotate=annotate)
self.channel_object = ChannelObject(self.fake_session, self.fake_channel_community)
|
'Test the initialization of the tracker manager'
| @blocking_call_on_reactor_thread
def test_initialize(self):
| self.tracker_manager.add_tracker('http://test1.com:80/announce')
self.tracker_manager.add_tracker('http://test2.com:80/announce')
self.tracker_manager.initialize()
self.assertEqual(len(self.tracker_manager._tracker_dict.keys()), 4)
self.assertTrue(('http://test1.com/announce' in self.tracker_manager... |
'Test whether adding a tracker works correctly'
| @blocking_call_on_reactor_thread
def test_add_tracker(self):
| self.tracker_manager.add_tracker('http://test1.com')
self.assertEqual(len(self.tracker_manager._tracker_dict), 0)
self.tracker_manager.add_tracker('http://test1.com:80/announce')
self.assertEqual(len(self.tracker_manager._tracker_dict), 1)
self.tracker_manager.add_tracker('http://test1.com:80/announ... |
'Test whether the correct tracker info is returned when requesting it in the tracker manager'
| @blocking_call_on_reactor_thread
def test_get_tracker_info(self):
| self.assertFalse(self.tracker_manager.get_tracker_info('http://nonexisting.com'))
self.tracker_manager.add_tracker('http://test1.com:80/announce')
self.assertTrue(self.tracker_manager.get_tracker_info('http://test1.com:80/announce'))
|
'Test whether the tracker info is correctly updated'
| @blocking_call_on_reactor_thread
def test_update_tracker_info(self):
| self.tracker_manager.update_tracker_info('http://nonexisting.com', True)
self.assertEqual(len(self.tracker_manager._tracker_dict), 0)
self.tracker_manager.add_tracker('http://test1.com:80/announce')
self.tracker_manager.update_tracker_info('http://test1.com/announce', False)
self.assertEqual(self.tr... |
'Test whether we should check a tracker or not'
| @blocking_call_on_reactor_thread
def test_should_check_tracker(self):
| self.assertTrue(self.tracker_manager.should_check_tracker('http://nonexisting.com'))
self.tracker_manager.add_tracker('http://test1.com:80/announce')
self.tracker_manager.update_tracker_info('http://test1.com/announce', False)
self.assertFalse(self.tracker_manager.should_check_tracker('http://test1.com/... |
'Test whether the correct tracker is returned when fetching the next eligable tracker for the auto check'
| @blocking_call_on_reactor_thread
def test_get_tracker_for_check(self):
| self.assertFalse(self.tracker_manager.get_next_tracker_for_auto_check())
self.tracker_manager.initialize()
self.assertEqual('DHT', self.tracker_manager.get_next_tracker_for_auto_check()[0])
self.tracker_manager.add_tracker('http://test1.com:80/announce')
self.tracker_manager._tracker_dict['http://te... |
'Test the method to get the market community in the market API'
| def test_get_market_community(self):
| endpoint = BaseMarketEndpoint(self.session)
self.session.get_dispersy_instance().get_communities = (lambda : [])
self.assertRaises(RuntimeError, endpoint.get_market_community)
|
'Add a transaction and a payment to the market'
| def add_transaction_and_payment(self):
| proposed_trade = Trade.propose(MessageId(TraderId('0'), MessageNumber('message_number')), OrderId(TraderId('0'), OrderNumber(1)), OrderId(TraderId('1'), OrderNumber(2)), Price(63400, 'BTC'), Quantity(30, 'MC'), Timestamp(1462224447.117))
transaction = self.session.lm.market_community.transaction_manager.create_... |
'Test whether the API returns the right asks in the order book when performing a request'
| @deferred(timeout=10)
def test_get_asks(self):
| def on_response(response):
json_response = json.loads(response)
self.assertIn('asks', json_response)
self.assertEqual(len(json_response['asks']), 1)
self.assertIn('ticks', json_response['asks'][0])
self.assertEqual(len(json_response['asks'][0]['ticks']), 1)
self.session.l... |
'Test whether we can create an ask using the API'
| @deferred(timeout=10)
def test_create_ask(self):
| def on_response(_):
self.assertEqual(len(self.session.lm.market_community.order_book.asks), 1)
self.should_check_equality = False
post_data = {'price': 10, 'quantity': 10, 'price_type': 'DUM1', 'quantity_type': 'DUM2', 'timeout': 3400}
return self.do_request('market/asks', expected_code=200, req... |
'Test for an error when we don\'t add a price when creating an ask'
| @deferred(timeout=10)
def test_create_ask_no_price(self):
| self.should_check_equality = False
post_data = {'quantity': 10, 'price_type': 'DUM1', 'quantity_type': 'DUM2', 'timeout': 3400}
return self.do_request('market/asks', expected_code=400, request_type='PUT', post_data=post_data)
|
'Test for an error when we don\'t add a price type when creating an ask'
| @deferred(timeout=10)
def test_create_ask_no_price_type(self):
| self.should_check_equality = False
post_data = {'price': 10, 'quantity': 10, 'quantity_type': 'DUM2', 'timeout': 3400}
return self.do_request('market/asks', expected_code=400, request_type='PUT', post_data=post_data)
|
'Test whether the API returns the right bids in the order book when performing a request'
| @deferred(timeout=10)
def test_get_bids(self):
| def on_response(response):
json_response = json.loads(response)
self.assertIn('bids', json_response)
self.assertEqual(len(json_response['bids']), 1)
self.assertIn('ticks', json_response['bids'][0])
self.assertEqual(len(json_response['bids'][0]['ticks']), 1)
self.session.l... |
'Test whether we can create a bid using the API'
| @deferred(timeout=10)
def test_create_bid(self):
| def on_response(_):
self.assertEqual(len(self.session.lm.market_community.order_book.bids), 1)
self.should_check_equality = False
post_data = {'price': 10, 'quantity': 10, 'price_type': 'DUM1', 'quantity_type': 'DUM2'}
return self.do_request('market/bids', expected_code=200, request_type='PUT', ... |
'Test for an error when we don\'t add a price when creating a bid'
| @deferred(timeout=10)
def test_create_bid_no_price(self):
| self.should_check_equality = False
post_data = {'quantity': 10, 'price_type': 'DUM1', 'quantity_type': 'DUM2', 'timeout': 3400}
return self.do_request('market/bids', expected_code=400, request_type='PUT', post_data=post_data)
|
'Test for an error when we don\'t add a price type when creating a bid'
| @deferred(timeout=10)
def test_create_bid_no_price_type(self):
| self.should_check_equality = False
post_data = {'price': 10, 'quantity': 10, 'quantity_type': 'DUM2', 'timeout': 3400}
return self.do_request('market/bids', expected_code=400, request_type='PUT', post_data=post_data)
|
'Test whether the API returns the right transactions in the order book when performing a request'
| @deferred(timeout=10)
def test_get_transactions(self):
| def on_response(response):
json_response = json.loads(response)
self.assertIn('transactions', json_response)
self.assertEqual(len(json_response['transactions']), 1)
self.add_transaction_and_payment()
self.should_check_equality = False
return self.do_request('market/transactions',... |
'Test whether the API returns a 404 when a payment cannot be found'
| @deferred(timeout=10)
def test_get_payment_not_found(self):
| self.should_check_equality = False
return self.do_request('market/transactions/abc/3/payments', expected_code=404)
|
'Test whether the API returns the right orders when we perform a request'
| @deferred(timeout=10)
def test_get_orders(self):
| def on_response(response):
json_response = json.loads(response)
self.assertIn('orders', json_response)
self.assertEqual(len(json_response['orders']), 1)
self.session.lm.market_community.order_manager.create_ask_order(Price(3, 'DUM1'), Quantity(4, 'DUM2'), Timeout(3600))
self.should_c... |
'Test whether the API returns the right payments when we perform a request'
| @deferred(timeout=10)
def test_get_payments(self):
| def on_response(response):
json_response = json.loads(response)
self.assertIn('payments', json_response)
self.assertEqual(len(json_response['payments']), 1)
transaction = self.add_transaction_and_payment()
self.should_check_equality = False
return self.do_request(('market/transac... |
'Test whether a 404 is returned when we try to cancel an order that does not exist'
| @deferred(timeout=10)
def test_cancel_order_not_found(self):
| self.session.lm.market_community.order_manager.create_ask_order(Price(3, 'DUM1'), Quantity(4, 'DUM2'), Timeout(3600))
self.should_check_equality = False
return self.do_request('market/orders/1234/cancel', request_type='POST', expected_code=404)
|
'Test whether an error is returned when we try to cancel an order that has expired'
| @deferred(timeout=10)
def test_cancel_order_invalid(self):
| self.session.lm.market_community.order_manager.create_ask_order(Price(3, 'DUM1'), Quantity(4, 'DUM2'), Timeout(0))
self.should_check_equality = False
return self.do_request('market/orders/1/cancel', request_type='POST', expected_code=400)
|
'Test whether an error is returned when we try to cancel an order that has expired'
| @deferred(timeout=10)
def test_cancel_order(self):
| order = self.session.lm.market_community.order_manager.create_ask_order(Price(3, 'DUM1'), Quantity(4, 'DUM2'), Timeout(3600))
def on_response(response):
json_response = json.loads(response)
self.assertTrue(json_response['cancelled'])
cancelled_order = self.session.lm.market_community.ord... |
'Test whether the conversion from remote torrent dict to json works'
| def test_convert_torrent_to_json_dict(self):
| mocked_db = MockObject()
mocked_db.latest_matchinfo_torrent = None
self.session.open_dbhandler = (lambda _: mocked_db)
input = {'torrent_id': 42, 'infohash': 'a', 'name': 'test torrent', 'length': 43, 'category': 'other', 'num_seeders': 1, 'num_leechers': 2}
output = {'id': 42, 'infohash': 'a'.en... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.