desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Testing whether the API returns response code 404 if no channel has been created'
| @deferred(timeout=10)
def test_my_channel_overview_endpoint_no_my_channel(self):
| expected_json = {'error': NO_CHANNEL_CREATED_RESPONSE_MSG}
return self.do_request('mychannel', expected_json=expected_json, expected_code=404)
|
'Testing whether the API returns the right JSON data if a channel overview is requested'
| @deferred(timeout=10)
def test_my_channel_overview_endpoint_with_channel(self):
| channel_json = {u'mychannel': {u'name': u'testname', u'description': u'testdescription', u'identifier': unicode('fakedispersyid'.encode('hex'))}}
self.create_my_channel(channel_json[u'mychannel'][u'name'], channel_json[u'mychannel'][u'description'])
return self.do_request('mychannel', expected_code=200, exp... |
'Testing whether an error 404 is returned when trying to edit your non-existing channel'
| @deferred(timeout=10)
def test_edit_my_channel_no_channel(self):
| return self.do_request('mychannel', expected_code=404, request_type='POST')
|
'Testing whether an error 404 is returned when trying to edit your channel without community'
| @deferred(timeout=10)
def test_edit_my_channel_no_cmty(self):
| mock_dispersy = MockObject()
mock_dispersy.get_community = (lambda _: None)
self.session.get_dispersy_instance = (lambda : mock_dispersy)
self.create_my_channel('test', 'test')
return self.do_request('mychannel', expected_code=404, request_type='POST')
|
'Testing whether a channel is correctly modified'
| @blocking_call_on_reactor_thread
@inlineCallbacks
def test_edit_channel(self):
| self.create_my_channel('test', 'test')
mock_channel_community = MockObject()
mock_channel_community.called_modify = False
def verify_channel_modified(_):
self.assertTrue(mock_channel_community.called_modify)
def modify_channel_called(modifications):
self.assertEqual(modifications['na... |
'Testing whether the API returns error 404 if a non-existent channel is queried for torrents'
| @deferred(timeout=10)
def test_get_torrents_in_channel_invalid_cid(self):
| self.should_check_equality = False
return self.do_request('channels/discovered/abcd/torrents', expected_code=404)
|
'Testing whether the API returns inserted torrents when fetching discovered channels, with and without filter'
| @deferred(timeout=15)
@inlineCallbacks
def test_get_torrents_in_channel(self):
| def verify_torrents_filter(torrents):
torrents_json = json.loads(torrents)
self.assertEqual(len(torrents_json['torrents']), 1)
self.assertEqual(torrents_json['torrents'][0]['infohash'], ('a' * 40))
def verify_torrents_no_filter(torrents):
torrents_json = json.loads(torrents)
... |
'Testing whether adding a torrent to your channels works'
| @deferred(timeout=10)
def test_add_torrent_to_channel(self):
| my_channel_id = self.create_fake_channel('channel', '')
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)
self.assertEqual(TorrentDef.load(torrent_path), torrent_def)
se... |
'Testing whether adding a torrent with a description to a channel works'
| @deferred(timeout=10)
def test_add_torrent_to_channel_with_description(self):
| my_channel_id = self.create_fake_channel('channel', '')
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)
self.assertEqual(TorrentDef.load(torrent_path), torrent_def)
se... |
'Testing whether adding a torrent to a non-existing channel returns error 404'
| @deferred(timeout=10)
def test_add_torrent_to_channel_404(self):
| return self.do_request(('channels/discovered/%s/torrents' % 'fakedispersyid'.encode('hex')), expected_code=404, request_type='PUT')
|
'Testing whether error 400 is returned when the torrent parameter is missing when adding a torrent to a channel'
| @deferred(timeout=10)
def test_add_torrent_to_channel_missing_parameter(self):
| self.create_fake_channel('channel', '')
expected_json = {'error': 'torrent parameter missing'}
return self.do_request(('channels/discovered/%s/torrents' % 'fakedispersyid'.encode('hex')), 400, expected_json, 'PUT')
|
'Testing whether the API returns a formatted 500 error if ValueError is raised'
| @deferred(timeout=10)
def test_add_torrent_to_channel_500(self):
| self.create_fake_channel('channel', '')
torrent_path = TORRENT_UBUNTU_FILE
def fake_error(channel_id, torrent_def, extra_info=None, forward=True):
raise ValueError('Test error')
self.session.add_torrent_def_to_channel = fake_error
def verify_error_message(body):
error_response = j... |
'Testing whether a torrent can be added to a channel using the API'
| @deferred(timeout=10)
def test_add_torrent_from_url_to_channel_with_description(self):
| my_channel_id = self.create_fake_channel('channel', '')
files_path = os.path.join(self.session_base_dir, 'http_torrent_files')
os.mkdir(files_path)
shutil.copyfile(TORRENT_UBUNTU_FILE, os.path.join(files_path, 'ubuntu.torrent'))
file_server_port = get_random_port()
self.setUpFileServer(file_serv... |
'Testing whether adding a torrent with a magnet link to a channel without description works'
| @deferred(timeout=10)
def test_add_torrent_from_magnet_to_channel(self):
| my_channel_id = self.create_fake_channel('channel', '')
def fake_get_metainfo(_, callback, timeout=10, timeout_callback=None, notify=True):
meta_info = TorrentDef.load(TORRENT_UBUNTU_FILE).get_metainfo()
callback(meta_info)
self.session.lm.ltmgr.get_metainfo = fake_get_metainfo
def verif... |
'Testing whether adding a torrent to a non-existing channel returns error code 404'
| @deferred(timeout=10)
def test_add_torrent_to_channel_404(self):
| self.should_check_equality = False
return self.do_request('channels/discovered/abcd/torrents/fake_url', expected_code=404, expected_json=None, request_type='PUT')
|
'Testing whether the API returns a formatted 500 error if ValueError is raised'
| @deferred(timeout=10)
def test_add_torrent_to_channel_500(self):
| self.create_fake_channel('channel', '')
def fake_get_metainfo(_, callback, timeout=10, timeout_callback=None, notify=True):
raise ValueError(u'Test error')
self.session.lm.ltmgr.get_metainfo = fake_get_metainfo
def verify_error_message(body):
error_response = json.loads(body)
... |
'Testing whether the API returns an error 500 if a torrent is removed from an unknown channel'
| @deferred(timeout=10)
def test_remove_tor_unknown_channel(self):
| return self.do_request('channels/discovered/abcd/torrents/abcd', expected_code=404, request_type='DELETE')
|
'Testing whether the API returns an error 500 if an unknown torrent is removed from a channel'
| @deferred(timeout=10)
def test_remove_tor_unknown_infohash(self):
| self.create_fake_channel('channel', '')
url = ('channels/discovered/%s/torrents/abcd' % 'fakedispersyid'.encode('hex'))
return self.do_request(url, expected_code=404, request_type='DELETE')
|
'Testing whether the API returns an error 500 if torrent is removed from a channel without community'
| @deferred(timeout=10)
def test_remove_tor_unknown_cmty(self):
| channel_id = self.create_fake_channel('channel', '')
torrent_list = [[channel_id, 1, 1, ('a' * 40).decode('hex'), 1460000000, 'ubuntu-torrent.iso', [['file1.txt', 42]], []]]
self.insert_torrents_into_channel(torrent_list)
def mocked_get_community(_):
raise CommunityNotFoundException('abcd')
... |
'Testing whether the API can remove a torrent from a channel'
| @deferred(timeout=10)
def test_remove_torrent(self):
| mock_channel_community = MockObject()
mock_channel_community.called_remove = False
def verify_torrent_removed(_):
self.assertTrue(mock_channel_community.called_remove)
channel_id = self.create_fake_channel('channel', '')
torrent_list = [[channel_id, 1, 1, ('a' * 40).decode('hex'), 1460000000... |
'Testing whether the API returns error 404 if an unknown channel is queried for playlists'
| @deferred(timeout=10)
def test_get_playlists_endpoint_without_channel(self):
| self.should_check_equality = True
expected_json = {'error': UNKNOWN_CHANNEL_RESPONSE_MSG}
return self.do_request('channels/discovered/aabb/playlists', expected_code=404, expected_json=expected_json)
|
'Testing whether the API returns the right JSON data if no playlists have been added to your channel'
| @deferred(timeout=10)
def test_playlists_endpoint_no_playlists(self):
| channel_cid = 'fakedispersyid'.encode('hex')
self.create_my_channel('my channel', 'this is a short description')
return self.do_request(('channels/discovered/%s/playlists' % channel_cid), expected_code=200, expected_json={'playlists': []})
|
'Testing whether the API returns the right JSON data if playlists are fetched'
| @deferred(timeout=10)
def test_playlists_endpoint(self):
| my_channel_id = self.create_my_channel('my channel', 'this is a short description')
channel_cid = 'fakedispersyid'.encode('hex')
self.create_playlist(my_channel_id, 1234, 42, 'test playlist', 'test description')
torrent_list = [[my_channel_id, 1, 1, ('a' * 40).decode('hex'), 1460000... |
'Testing whether the API returns error 404 if the channel does not exist when creating a playlist'
| @deferred(timeout=10)
def test_create_playlist_no_channel(self):
| self.create_my_channel('my channel', 'this is a short description')
post_params = {'name': 'test1', 'description': 'test2'}
return self.do_request('channels/discovered/abcd/playlists', expected_code=404, post_data=post_params, request_type='PUT')
|
'Testing whether the API returns error 400 if the name is missing when creating a new playlist'
| @deferred(timeout=10)
def test_create_playlist_no_name(self):
| self.create_my_channel('my channel', 'this is a short description')
expected_json = {'error': 'name parameter missing'}
return self.do_request(('channels/discovered/%s/playlists' % 'fakedispersyid'.encode('hex')), expected_code=400, expected_json=expected_json, request_type='PUT')
|
'Testing whether the API returns error 400 if the description is missing when creating a new playlist'
| @deferred(timeout=10)
def test_create_playlist_no_description(self):
| self.create_my_channel('my channel', 'this is a short description')
expected_json = {'error': 'description parameter missing'}
post_params = {'name': 'test'}
return self.do_request(('channels/discovered/%s/playlists' % 'fakedispersyid'.encode('hex')), expected_code=400, expected_jso... |
'Testing whether the API returns error 404 if the the channel community is missing when creating a new playlist'
| @deferred(timeout=10)
def test_create_playlist_no_cmty(self):
| self.create_my_channel('my channel', 'this is a short description')
expected_json = {'error': 'description parameter missing'}
post_params = {'name': 'test1', 'description': 'test2'}
def mocked_get_community(_):
raise CommunityNotFoundException('abcd')
mock_dispersy = Mo... |
'Testing whether the API can create a new playlist in a given channel'
| @deferred(timeout=10)
def test_create_playlist(self):
| mock_channel_community = MockObject()
mock_channel_community.called_create = False
self.create_fake_channel('channel', '')
def verify_playlist_created(_):
self.assertTrue(mock_channel_community.called_create)
def create_playlist_called(name, description, _):
self.assertEqual(name, 't... |
'Testing whether an error 404 is returned when a playlist is removed from a non-existent channel'
| @deferred(timeout=10)
def test_delete_playlist_no_channel(self):
| return self.do_request('channels/discovered/abcd/playlists/1', expected_code=404, request_type='DELETE')
|
'Testing whether an error 404 is returned when a non-existent playlist is removed from a channel'
| @deferred(timeout=10)
def test_delete_playlist_no_playlist(self):
| channel_cid = 'fakedispersyid'.encode('hex')
self.create_my_channel('my channel', 'this is a short description')
return self.do_request(('channels/discovered/%s/playlists/1' % channel_cid), expected_code=404, request_type='DELETE')
|
'Testing whether an error 404 is returned when a playlist is removed from a channel without community'
| @deferred(timeout=10)
def test_delete_playlist_no_community(self):
| def mocked_get_community(_):
raise CommunityNotFoundException('abcd')
mock_dispersy = MockObject()
mock_dispersy.get_community = mocked_get_community
self.session.get_dispersy_instance = (lambda : mock_dispersy)
channel_cid = 'fakedispersyid'.encode('hex')
my_channel_id = self.create_my_... |
'Testing whether a playlist is correctly removed'
| @deferred(timeout=10)
def test_delete_playlist(self):
| mock_channel_community = MockObject()
mock_channel_community.called_remove = False
mock_channel_community.called_remove_torrents = False
my_channel_id = self.create_fake_channel('channel', '')
def verify_playlist_removed(_):
self.assertTrue(mock_channel_community.called_remove_torrents)
... |
'Testing whether an error 400 is returned when a playlist is edit without a name parameter passed'
| @deferred(timeout=10)
def test_edit_playlist_no_name(self):
| post_params = {'description': 'test'}
expected_json = {'error': 'name parameter missing'}
return self.do_request('channels/discovered/abcd/playlists/1', expected_code=400, post_data=post_params, request_type='POST', expected_json=expected_json)
|
'Testing whether an error 400 is returned when a playlist is edit without a description parameter passed'
| @deferred(timeout=10)
def test_edit_playlist_no_description(self):
| post_params = {'name': 'test'}
expected_json = {'error': 'description parameter missing'}
return self.do_request('channels/discovered/abcd/playlists/1', expected_code=400, post_data=post_params, request_type='POST', expected_json=expected_json)
|
'Testing whether an error 404 is returned when a playlist is edit from a non-existent channel'
| @deferred(timeout=10)
def test_edit_playlist_no_channel(self):
| post_params = {'name': 'test', 'description': 'test'}
return self.do_request('channels/discovered/abcd/playlists/1', expected_code=404, post_data=post_params, request_type='POST')
|
'Testing whether an error 404 is returned when a non-existent playlist is edited'
| @deferred(timeout=10)
def test_edit_playlist_no_playlist(self):
| post_params = {'name': 'test', 'description': 'test'}
channel_cid = 'fakedispersyid'.encode('hex')
self.create_my_channel('my channel', 'this is a short description')
return self.do_request(('channels/discovered/%s/playlists/1' % channel_cid), expected_code=404, request_type='POST', post_... |
'Testing whether an error 404 is returned when a playlist is edited from a channel without community'
| @deferred(timeout=10)
def test_edit_playlist_no_community(self):
| def mocked_get_community(_):
raise CommunityNotFoundException('abcd')
mock_dispersy = MockObject()
mock_dispersy.get_community = mocked_get_community
self.session.get_dispersy_instance = (lambda : mock_dispersy)
post_params = {'name': 'test', 'description': 'test'}
channel_cid = 'fakedis... |
'Testing whether a playlist is correctly modified'
| @deferred(timeout=10)
def test_edit_playlist(self):
| mock_channel_community = MockObject()
mock_channel_community.called_modify = False
my_channel_id = self.create_fake_channel('channel', '')
def verify_playlist_modified(_):
self.assertTrue(mock_channel_community.called_modify)
def modify_playlist_called(playlist_id, modifications):
se... |
'Testing whether an error 404 is returned when a torrent is added to a playlist with a non-existent channel'
| @deferred(timeout=10)
def test_add_torrent_no_channel(self):
| return self.do_request('channels/discovered/abcd/playlists/1/abcd', expected_code=404, request_type='PUT')
|
'Testing whether an error 404 is returned when a torrent is added to a non-existing playlist'
| @deferred(timeout=10)
def test_add_torrent_no_playlist(self):
| mock_channel_community = MockObject()
mock_channel_community.called_add = False
self.create_fake_channel('channel', '')
mock_dispersy = MockObject()
mock_dispersy.get_community = (lambda _: mock_channel_community)
self.session.get_dispersy_instance = (lambda : mock_dispersy)
channel_cid = 'f... |
'Testing whether an error 404 is returned when a torrent is added to a playlist without channel community'
| @deferred(timeout=10)
def test_add_torrent_no_community(self):
| def mocked_get_community(_):
raise CommunityNotFoundException('abcd')
mock_dispersy = MockObject()
mock_dispersy.get_community = mocked_get_community
self.session.get_dispersy_instance = (lambda : mock_dispersy)
channel_cid = 'fakedispersyid'.encode('hex')
my_channel_id = self.create_my_... |
'Testing whether a torrent can successfully be added to a playlist'
| @deferred(timeout=15)
@inlineCallbacks
def test_add_torrent_playlist(self):
| mock_channel_community = MockObject()
mock_channel_community.called_add = False
my_channel_id = self.create_fake_channel('channel', '')
def verify_torrent_added(_):
self.assertTrue(mock_channel_community.called_add)
def modify_add_called(playlist_id, torrents):
self.assertEqual(playl... |
'Testing whether an error 404 is returned when a torrent from a playlist is removed from a non-existent channel'
| @deferred(timeout=10)
def test_delete_torrent_no_channel(self):
| return self.do_request('channels/discovered/abcd/playlists/1/abcd', expected_code=404, request_type='DELETE')
|
'Testing whether an error 404 is returned when a torrent from a playlist is removed from a non-existent playlist'
| @deferred(timeout=10)
def test_delete_torrent_no_playlist(self):
| channel_cid = 'fakedispersyid'.encode('hex')
self.create_my_channel('my channel', 'this is a short description')
return self.do_request(('channels/discovered/%s/playlists/1/abcd' % channel_cid), expected_code=404, request_type='DELETE')
|
'Testing whether an error 404 is returned when a torrent from a playlist without channel community'
| @deferred(timeout=10)
def test_remove_torrent_no_community(self):
| def mocked_get_community(_):
raise CommunityNotFoundException('abcd')
mock_dispersy = MockObject()
mock_dispersy.get_community = mocked_get_community
self.session.get_dispersy_instance = (lambda : mock_dispersy)
channel_cid = 'fakedispersyid'.encode('hex')
my_channel_id = self.create_my_... |
'Testing whether a torrent can be successfully removed from a playlist'
| @deferred(timeout=15)
@inlineCallbacks
def test_remove_torrent_playlist(self):
| mock_channel_community = MockObject()
mock_channel_community.called_remove = False
my_channel_id = self.create_fake_channel('channel', '')
def verify_torrent_removed(_):
self.assertTrue(mock_channel_community.called_remove)
def modify_remove_called(playlist_id, torrents):
self.assert... |
'Testing whether the API returns error 404 if an unknown channel is queried'
| @deferred(timeout=10)
def test_get_channel_info_non_existent(self):
| self.should_check_equality = True
expected_json = {'error': UNKNOWN_CHANNEL_RESPONSE_MSG}
return self.do_request('channels/discovered/aabb', expected_code=404, expected_json=expected_json)
|
'Testing whether the API returns the right JSON data if a channel overview is requested'
| @deferred(timeout=10)
def test_get_channel_info(self):
| channel_json = {u'overview': {u'name': u'testname', u'description': u'testdescription', u'identifier': unicode('fake'.encode('hex'))}}
self.insert_channel_in_db('fake', 3, channel_json[u'overview'][u'name'], channel_json[u'overview'][u'description'])
return self.do_request(('channels/discovered/%s' % 'fake'... |
'Testing whether the API returns a correct dictionary with torrent info.'
| @blocking_call_on_reactor_thread
@inlineCallbacks
def test_get_torrentinfo(self):
| files_path = os.path.join(self.session_base_dir, 'http_torrent_files')
os.mkdir(files_path)
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)
def verify_valid_dict(data):
... |
'Test whether the right operations happen when we receive an invalid metainfo object'
| @deferred(timeout=10)
def test_on_got_invalid_metainfo(self):
| def get_metainfo(infohash, callback, **_):
callback('abcd')
self.session.lm.ltmgr = MockObject()
self.session.lm.ltmgr.get_metainfo = get_metainfo
self.session.lm.ltmgr.shutdown = (lambda : None)
path = ('magnet:?xt=urn:btih:%s&dn=%s' % (hexlify(UBUNTU_1504_INFOHASH), quote_plus('test tor... |
'Testing whether the API returns an error 400 if no search query is passed with the request'
| @deferred(timeout=10)
def test_search_no_parameter(self):
| expected_json = {'error': 'query parameter missing'}
return self.do_request('search', expected_code=400, expected_json=expected_json)
|
'Testing whether the API finds no channels/torrents when searching if they are not in the database'
| @deferred(timeout=10)
def test_search_no_matches(self):
| self.insert_channels_in_db(5)
self.insert_torrents_in_db(6)
self.expected_num_results_list = [0, 0]
expected_json = {'queried': True}
return self.do_request('search?q=tribler', expected_code=200, expected_json=expected_json).addCallback(self.verify_search_results)
|
'Testing whether the API finds channels/torrents when searching if there is some inserted data in the database'
| @deferred(timeout=10)
def test_search(self):
| self.insert_channels_in_db(5)
self.insert_torrents_in_db(6)
self.expected_num_results_list = [5, 6, 0, 0]
self.session.config.get_torrent_search_enabled = (lambda : True)
self.session.config.get_channel_search_enabled = (lambda : True)
self.session.lm.search_manager = FakeSearchManager(self.sess... |
'Testing whether the API returns an error 400 if no query is passed when getting search completion terms'
| @deferred(timeout=10)
def test_completions_no_query(self):
| expected_json = {'error': 'query parameter missing'}
return self.do_request('search/completions', expected_code=400, expected_json=expected_json)
|
'Testing whether the API returns the right terms when getting search completion terms'
| @deferred(timeout=10)
def test_completions(self):
| torrent_db_handler = self.session.open_dbhandler(NTFY_TORRENTS)
torrent_db_handler.getAutoCompleteTerms = (lambda keyword, max_terms: [('%s %d' % (keyword, ind)) for ind in xrange(max_terms)])
expected_json = {'completions': [('tribler %d' % ind) for ind in xrange(5)]}
return self.do_request('sear... |
'Verify that the expected sections are present.'
| def verify_settings(self, settings):
| check_section = ['libtorrent', 'mainline_dht', 'torrent_store', 'general', 'upgrader', 'torrent_checking', 'allchannel_community', 'tunnel_community', 'http_api', 'torrent_collecting', 'dispersy', 'trustchain', 'watch_folder', 'search_community', 'metadata']
settings_json = json.loads(settings)
self.assertT... |
'Testing whether the API returns a correct settings dictionary when the settings are requested'
| @deferred(timeout=10)
def test_get_settings(self):
| self.should_check_equality = False
return self.do_request('settings', expected_code=200).addCallback(self.verify_settings)
|
'Testing whether an error is returned if we are passing an invalid dictionary that is too deep'
| @deferred(timeout=10)
def test_set_settings_invalid_dict(self):
| def verify_response(response):
json_dict = json.loads(response)
self.assertTrue(('error' in json_dict))
self.should_check_equality = False
post_data = json.dumps({'a': {'b': {'c': 'd'}}})
return self.do_request('settings', expected_code=500, request_type='POST', post_data=post_data, raw_... |
'Testing whether an error is returned when we try to set a non-existing key'
| @deferred(timeout=10)
@inlineCallbacks
def test_set_settings_no_key(self):
| def verify_response(response):
json_dict = json.loads(response)
self.assertTrue(('error' in json_dict))
self.should_check_equality = False
post_data = json.dumps({'general': {'b': 'c'}})
(yield self.do_request('settings', expected_code=500, request_type='POST', post_data=post_data, raw_d... |
'Testing whether settings in the API can be successfully set'
| @deferred(timeout=10)
def test_set_settings(self):
| old_filter_setting = self.session.config.get_family_filter_enabled()
def verify_response(_):
self.assertNotEqual(self.session.config.get_family_filter_enabled(), old_filter_setting)
self.should_check_equality = False
post_data = json.dumps({'general': {'family_filter': (not old_filter_setting)},... |
'Testing whether the API returns error 404 if no tunnel community is loaded'
| @deferred(timeout=10)
def test_get_circuit_no_community(self):
| self.dispersy.get_communities = (lambda : [])
return self.do_request('debug/circuits', expected_code=404)
|
'Testing whether the API returns the correct circuits'
| @deferred(timeout=10)
def test_get_circuits(self):
| mock_hop = MockObject()
mock_hop.host = 'somewhere'
mock_hop.port = 4242
mock_circuit = MockObject()
mock_circuit.state = 'TESTSTATE'
mock_circuit.goal_hops = 42
mock_circuit.bytes_up = 200
mock_circuit.bytes_down = 400
mock_circuit.creation_time = 1234
mock_circuit.hops = [mock_... |
'Test whether the right amount of torrents are returned when searching for torrents in db'
| @blocking_call_on_reactor_thread
def test_search_names_no_sort(self):
| columns = ['T.torrent_id', 'infohash', 'status', 'num_seeders']
self.tdb.channelcast_db = ChannelCastDBHandler(self.session)
self.assertEqual(len(self.tdb.searchNames(['content'], keys=columns, doSort=False)), 4848)
self.assertEqual(len(self.tdb.searchNames(['content', '1'], keys=columns, doSort=False))... |
'Test whether the right amount of sorted torrents are returned when searching for torrents in db'
| @blocking_call_on_reactor_thread
def test_search_names_sort(self):
| columns = ['T.torrent_id', 'infohash', 'status', 'num_seeders']
self.tdb.channelcast_db = ChannelCastDBHandler(self.session)
results = self.tdb.searchNames(['content'], keys=columns)
self.assertEqual(len(results), 4848)
self.assertEqual(results[0][3], 493785)
|
'Test the search procedure in the local database when searching for torrents'
| @blocking_call_on_reactor_thread
def test_search_local_torrents(self):
| results = self.tdb.search_in_local_torrents_db('content', ['infohash'])
self.assertEqual(len(results), 4848)
self.assertNotEqual(results[0][(-1)], 0.0)
results = self.tdb.search_in_local_torrents_db('fdsafasfds', ['infohash'])
self.assertEqual(len(results), 0)
|
'This test tests whether deleting using a single element as value works.'
| @blocking_call_on_reactor_thread
def test_delete_single_element(self):
| self.test_insert()
self.sqlite_test.insert('person', lastname='x', firstname='z')
one = self.sqlite_test.fetchone(u'SELECT * FROM person')
self.assertEqual(one, ('a', 'b'))
self.sqlite_test.delete('person', lastname='a')
one = self.sqlite_test.fetchone(u'SELECT * FROM person')
... |
'This test tests whether deleting using a tuple as value works.'
| @blocking_call_on_reactor_thread
def test_delete_tuple(self):
| self.test_insert()
self.sqlite_test.insert('person', lastname='x', firstname='z')
one = self.sqlite_test.fetchone(u'SELECT * FROM person')
self.assertEqual(one, ('a', 'b'))
self.sqlite_test.delete('person', lastname=('LIKE', 'a'))
one = self.sqlite_test.fetchone(u'SELECT * FROM ... |
'Test the cleanup of a DHT session'
| @deferred(timeout=10)
def test_cleanup(self):
| return self.dht_session.cleanup()
|
'Test the metainfo lookup of the DHT session'
| @deferred(timeout=10)
def test_connect_to_tracker(self):
| def get_metainfo(infohash, callback, **_):
callback({'seeders': 1, 'leechers': 2})
def verify_metainfo(metainfo):
self.assertTrue(('DHT' in metainfo))
self.assertEqual(metainfo['DHT'][0]['leechers'], 2)
self.assertEqual(metainfo['DHT'][0]['seeders'], 1)
self.session.lm.ltmgr ... |
'Test the metainfo timeout of the DHT session'
| @deferred(timeout=10)
def test_metainfo_timeout(self):
| test_deferred = Deferred()
def get_metainfo_timeout(*args, **kwargs):
timeout_cb = kwargs.get('timeout_callback')
timeout_cb(('a' * 20))
def on_timeout(failure):
test_deferred.callback(None)
self.session.lm.ltmgr = MockObject()
self.session.lm.ltmgr.get_metainfo = get_metainf... |
'Test various methods in the DHT session class'
| def test_methods(self):
| self.assertTrue(self.dht_session.can_add_request())
self.dht_session.add_infohash(('b' * 20))
self.assertEqual(self.dht_session.infohash, ('b' * 20))
self.assertEqual(self.dht_session.max_retries, DHT_TRACKER_MAX_RETRIES)
self.assertEqual(self.dht_session.retry_interval, DHT_TRACKER_RECHECK_INTERVAL... |
'Test the initialization of the torrent checker'
| @blocking_call_on_reactor_thread
def test_initialize(self):
| self.torrent_checker.initialize()
self.assertIsNotNone(self.torrent_checker._torrent_db)
self.assertTrue(self.torrent_checker.is_pending_task_active('torrent_checker_tracker_selection'))
|
'Test the rescheduling of the tracker select task'
| @blocking_call_on_reactor_thread
def test_reschedule_tracker_select(self):
| self.torrent_checker._reschedule_tracker_select()
self.assertTrue(self.torrent_checker.is_pending_task_active('torrent_checker_tracker_selection'))
|
'Test whether adding a request to fetch health of a trackerless torrent fails'
| @blocking_call_on_reactor_thread
def test_add_gui_request_no_trackers(self):
| test_deferred = Deferred()
self.torrent_checker._torrent_db.addExternalTorrentNoDef(('a' * 20), 'ubuntu.iso', [['a.test', 1234]], [], 5)
self.torrent_checker._torrent_db._db.execute_write('DELETE FROM TorrentTrackerMapping')
self.torrent_checker.add_gui_request(('a' * 20)).addErrback((lambda _: te... |
'Test whether cached results of a torrent are returned when fetching the health of a torrent'
| @blocking_call_on_reactor_thread
def test_add_gui_request_cached(self):
| self.torrent_checker._torrent_db.addExternalTorrentNoDef(('a' * 20), 'ubuntu.iso', [['a.test', 1234]], [], 5)
self.torrent_checker._torrent_db.updateTorrentCheckResult(1, ('a' * 20), 5, 10, time.time(), time.time(), 'good', 0)
def verify_response(result):
self.assertTrue(('db' in result))
se... |
'Test whether a Failure is raised when we try to fetch info about a torrent unknown to the database'
| @blocking_call_on_reactor_thread
def test_add_gui_request_no_tor(self):
| test_deferred = Deferred()
self.torrent_checker.add_gui_request(('a' * 20)).addErrback((lambda _: test_deferred.callback(None)))
return test_deferred
|
'Test whether we capture the error when a tracker check fails'
| @deferred(timeout=30)
def test_tracker_test_error_resolve(self):
| self.torrent_checker._torrent_db.addExternalTorrentNoDef(('a' * 20), 'ubuntu.iso', [['a.test', 1234]], ['udp://non123exiszzting456tracker89fle.abc:80/announce'], 5)
return self.torrent_checker._task_select_tracker()
|
'Test whether we do nothing when tracker URL is invalid'
| @blocking_call_on_reactor_thread
def test_tracker_test_invalid_tracker(self):
| tracker_url = u'udp://non123exiszzting456tracker89fle.abc:80'
bad_tracker_url = u'xyz://non123exiszzting456tracker89fle.abc:80'
self.torrent_checker._torrent_db.addExternalTorrentNoDef(('a' * 20), 'ubuntu.iso', [['a.test', 1234]], [tracker_url], 5)
self.session.lm.tracker_manager._tracker_dict[bad_track... |
'Test the check of a tracker without associated torrents'
| @deferred(timeout=10)
def test_tracker_no_infohashes(self):
| self.session.lm.tracker_manager.add_tracker('http://trackertest.com:80/announce')
return self.torrent_checker._task_select_tracker()
|
'Add a single file to a TorrentDef'
| def test_add_content_file_and_copy(self):
| t = TorrentDef()
fn = os.path.join(TESTS_DATA_DIR, self.VIDEO_FILE_NAME)
t.add_content(fn)
t.set_tracker(TRACKER)
t.finalize()
s = os.path.getsize(fn)
metainfo = t.get_metainfo()
self.general_check(metainfo)
self.assertEqual(metainfo['info']['name'], self.VIDEO_FILE_NAME)
self.as... |
'Add a single dir to a TorrentDef'
| def test_add_content_dir(self):
| t = TorrentDef()
dn = os.path.join(TESTS_DATA_DIR, 'contentdir')
t.add_content(dn, 'dirintorrent')
t.set_tracker(TRACKER)
t.finalize()
exps = 0
for f in os.listdir(dn):
if f.startswith('.'):
continue
p = os.path.join(dn, f)
s = os.path.getsize(p)
e... |
'Add a single dir and single file to a TorrentDef'
| def test_add_content_dir_and_file(self):
| t = TorrentDef()
dn = os.path.join(TESTS_DATA_DIR, 'contentdir')
t.add_content(dn, 'dirintorrent')
fn = os.path.join(TESTS_DATA_DIR, self.VIDEO_FILE_NAME)
t.add_content(fn, os.path.join('dirintorrent', self.VIDEO_FILE_NAME))
t.set_tracker(TRACKER)
t.finalize()
exps = os.path.getsize(fn)
... |
'Add a single file with announce-list to a TorrentDef'
| def test_add_content_announce_list(self):
| t = TorrentDef()
fn = os.path.join(TESTS_DATA_DIR, self.VIDEO_FILE_NAME)
t.add_content(fn)
t.set_tracker(TRACKER)
exphier = [[TRACKER], ['http://tracker1.tribler.org:6969/announce', 'http://tracker2.tribler.org:7070/ann'], ['http://www.cs.vu.nl', 'http://www.st.ewi.tudelft.nl', 'http://www.vuze.com'... |
'Add a single file with BitTornado httpseeds to a TorrentDef'
| def test_add_content_httpseeds(self):
| t = TorrentDef()
fn = os.path.join(TESTS_DATA_DIR, self.VIDEO_FILE_NAME)
t.add_content(fn)
t.set_tracker(TRACKER)
expseeds = ['http://www.cs.vu.nl/index.html', 'http://www.st.ewi.tudelft.nl/index.html']
t.set_httpseeds(expseeds)
t.finalize()
metainfo = t.get_metainfo()
self.general_c... |
'Add a single file with piece length to a TorrentDef'
| def test_add_content_piece_length(self):
| t = TorrentDef()
fn = os.path.join(TESTS_DATA_DIR, self.VIDEO_FILE_NAME)
t.add_content(fn)
t.set_piece_length((2 ** 16))
t.set_tracker(TRACKER)
t.finalize()
metainfo = t.get_metainfo()
self.general_check(metainfo)
self.assertEqual(metainfo['info']['piece length'], (2 ** 16))
|
'Add a single file to a TorrentDef and save the latter'
| def test_add_content_file_save(self):
| t = TorrentDef()
fn = os.path.join(TESTS_DATA_DIR, self.VIDEO_FILE_NAME)
t.add_content(fn)
t.set_tracker(TRACKER)
t.finalize()
tfn = os.path.join(os.getcwd(), 'gen.torrent')
t.save(tfn)
f = open(tfn, 'rb')
bdata = f.read()
f.close()
os.remove(tfn)
data = bdecode(bdata)
... |
'Testing whether a ValueError is raised when a non-finalized tdef is added as download.'
| @raises(ValueError)
def test_add_tdef_not_finalized(self):
| self.lm.add(TorrentDef(), None)
|
'Testing whether a DuplicateDownloadException is raised when a download is added twice'
| @raises(DuplicateDownloadException)
def test_add_duplicate_download(self):
| self.lm.downloads = {'abcd': None}
tdef = TorrentDef()
tdef.metainfo_valid = True
tdef.infohash = 'abcd'
self.lm.add(tdef, DefaultDownloadStartupConfig.getInstance())
|
'Testing whether a pstate is successfully loaded'
| def test_load_download_pstate(self):
| config_file_path = os.path.abspath(os.path.join(self.DATA_DIR, u'config_files', u'config1.conf'))
config = self.lm.load_download_pstate(config_file_path)
self.assertIsInstance(config, CallbackConfigParser)
self.assertEqual(config.get('general', 'version'), 11)
|
'Testing whether a download is stopped on error in the download states callback in LaunchManyCore'
| @deferred(timeout=10)
def test_dlstates_cb_error(self):
| error_stop_deferred = Deferred()
def mocked_stop():
error_stop_deferred.callback(None)
error_tdef = TorrentDef()
error_tdef.get_infohash = (lambda : 'aaaa')
fake_error_download = MockObject()
fake_error_download.get_def = (lambda : error_tdef)
fake_error_download.get_def().get_name_a... |
'Testing whether a download is readded when safe seeding in the download states callback in LaunchManyCore'
| @deferred(timeout=10)
def test_dlstates_cb_seeding(self):
| self.lm.session.config = MockObject()
self.lm.session.config.get_max_upload_rate = (lambda : 100)
self.lm.session.config.get_max_download_rate = (lambda : 100)
self.lm.session.config.get_default_number_hops = (lambda : 0)
readd_deferred = Deferred()
def mocked_start_download(tdef, dscfg):
... |
'Test whether we are resuming downloads after loading checkpoint'
| def test_load_checkpoint(self):
| def mocked_resume_download(filename, setupDelay=3):
self.assertTrue(filename.endswith('abcd.state'))
self.assertEqual(setupDelay, 0)
mocked_resume_download.called = True
mocked_resume_download.called = False
self.lm.session.get_downloads_pstate_dir = (lambda : self.session_base_dir)
... |
'Testing whether all Dispersy communities can be succesfully loaded'
| def test_load_communities(self):
| self.assertTrue(self.get_community(DiscoveryCommunity))
self.assertTrue(self.session.lm.initComplete)
self.assertTrue(self.get_community(SearchCommunity))
self.assertTrue(self.get_community(AllChannelCommunity))
self.assertTrue(self.get_community(HiddenTunnelCommunity))
self.assertTrue(self.get_... |
'Testing whether we do nothing if we are not running a session'
| @blocking_call_on_reactor_thread
def test_download_file_not_running(self):
| def mocked_add_new_session(_):
raise RuntimeError('_add_new_session not be called')
self.handler._add_new_session = mocked_add_new_session
self.handler.download_file('test', '127.0.0.1', 1234)
|
'Testing whether we fail if we exceed our maximum amount of retries'
| def test_check_session_timeout(self):
| mock_session = MockObject()
mock_session.retries = 2
mock_session.timeout = 1
mock_session.last_contact_time = 2
self.handler._max_retries = 1
self.assertTrue(self.handler._check_session_timeout(mock_session))
|
'Testing whether scheduling a TFTP callback works correctly'
| def test_schedule_callback_processing(self):
| self.assertFalse(self.handler.is_pending_task_active('tftp_process_callback'))
self.handler._callback_scheduled = True
self.handler._schedule_callback_processing()
self.assertFalse(self.handler.is_pending_task_active('tftp_process_callback'))
|
'Testing whether a tftp session is correctly cleaned up'
| def test_cleanup_session(self):
| self.handler._session_id_dict['c'] = 1
self.handler._session_dict = {'abc': 'test'}
self.handler._cleanup_session('abc')
self.assertFalse(('c' in self.handler._session_id_dict))
|
'Testing whether we do nothing when data comes in and the handler is not running'
| def test_data_came_in(self):
| def mocked_process_packet(_dummy1, _dummy2):
raise RuntimeError('_process_packet may not be called')
self.handler._process_packet = mocked_process_packet
self.handler._is_running = False
self.handler.data_came_in(None, None)
|
'When the metadata_store from LaunchManyCore is not available, return
from the function rather than trying to load the metadata.
:return:'
| def test_handle_new_request_no_metadata(self):
| fake_packet = {'opcode': OPCODE_RRQ, 'file_name': (METADATA_PREFIX + 'abc'), 'options': {'blksize': 1, 'timeout': 1}, 'session_id': 1}
self.handler._load_metadata = (lambda _: self.fail('This line should not be called'))
def test_function():
test_function.is_called = True
retu... |
'When the torrent_store from LaunchManyCore is not available, return
from the function rather than trying to load the metadata.
:return:'
| def test_handle_new_request_no_torrent_store(self):
| self.handler.session = MockObject()
fake_packet = {'opcode': OPCODE_RRQ, 'file_name': 'abc', 'options': {'blksize': 1, 'timeout': 1}, 'session_id': 1}
self.handler._load_metadata = (lambda _: self.fail('This line should not be called'))
def test_function():
test_function.is_called... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.