本文整理汇总了Python中Tribler.Test.Core.base_test.MockObject.payload方法的典型用法代码示例。如果您正苦于以下问题:Python MockObject.payload方法的具体用法?Python MockObject.payload怎么用?Python MockObject.payload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tribler.Test.Core.base_test.MockObject
的用法示例。
在下文中一共展示了MockObject.payload方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_encode_torrent
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import payload [as 别名]
def test_encode_torrent(self):
"""
Test the encoding of a torrent file
"""
message = MockObject()
message.payload = MockObject()
message.payload.name = u'test'
message.payload.infohash = 'a' * 20
message.payload.timestamp = 1234
message.payload.files = [(u'a', 1234)]
message.payload.trackers = ['udp://tracker.openbittorrent.com:80/announce', 'http://google.com']
meta = self.channel_community.get_meta_message(u"torrent")
msg = MockObject()
msg.meta = meta
decoded_message = self.conversion._decode_torrent(msg, 0, self.conversion._encode_torrent(message)[0])[1]
self.assertEqual(len(decoded_message.files), 1)
self.assertEqual(len(decoded_message.trackers), 1)
message.payload.files = [(u'a', 1234)] * 1000
message.payload.trackers = ['udp://tracker.openbittorrent.com:80/announce'] * 100
decoded_message = self.conversion._decode_torrent(msg, 0, self.conversion._encode_torrent(message)[0])[1]
self.assertGreaterEqual(len(decoded_message.files), 133)
self.assertEqual(len(decoded_message.trackers), 10)
示例2: test_on_socks_in
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import payload [as 别名]
def test_on_socks_in(self):
"""
Test whether data is correctly dispatched to a circuit
"""
mock_socks_server = MockObject()
self.dispatcher.set_socks_servers([mock_socks_server])
mock_udp_connection = MockObject()
mock_udp_connection.socksconnection = MockObject()
mock_udp_connection.socksconnection.socksserver = mock_socks_server
mock_request = MockObject()
mock_request.destination = ("0.0.0.0", 1024)
mock_request.payload = 'a'
# No circuit is selected
self.assertFalse(self.dispatcher.on_socks5_udp_data(mock_udp_connection, mock_request))
self.selection_strategy.select = lambda *_: self.mock_circuit
# Circuit is not ready
self.assertFalse(self.dispatcher.on_socks5_udp_data(mock_udp_connection, mock_request))
self.mock_circuit.state = CIRCUIT_STATE_READY
# Circuit ready, should be able to tunnel data
self.assertTrue(self.dispatcher.on_socks5_udp_data(mock_udp_connection, mock_request))
示例3: test_on_search
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import payload [as 别名]
def test_on_search(self):
"""
Test whether we are creating a search response when we receive a search request
"""
def log_incoming_searches(sock_addr, keywords):
log_incoming_searches.called = True
log_incoming_searches.called = False
def create_search_response(id, results, candidate):
create_search_response.called = True
self.assertEqual(id, "abc")
self.assertEqual(results, [])
self.assertEqual(candidate.sock_addr, "1234")
create_search_response.called = False
def search_names(keywords, local=False, keys=None):
return []
self.search_community._torrent_db = MockObject()
self.search_community._torrent_db.searchNames = search_names
fake_message = MockObject()
fake_message.candidate = MockObject()
fake_message.candidate.sock_addr = "1234"
fake_message.payload = MockObject()
fake_message.payload.keywords = "test"
fake_message.payload.identifier = "abc"
self.search_community._create_search_response = create_search_response
self.search_community.log_incoming_searches = log_incoming_searches
self.search_community.on_search([fake_message])
self.assertTrue(log_incoming_searches.called)
self.assertTrue(create_search_response.called)