Merge branch 'tests_to_lbrynet'
This commit is contained in:
commit
33a95abeac
54 changed files with 358 additions and 250 deletions
|
@ -28,7 +28,7 @@ test_script:
|
|||
- pylint lbrynet
|
||||
# disable tests for now so that appveyor can build the app
|
||||
- set PYTHONPATH=.
|
||||
- trial tests
|
||||
- trial lbrynet.tests
|
||||
# TODO: integration tests do not work
|
||||
#- python -m unittest discover tests/integration
|
||||
#- rvm use 2.3.1 && gem install danger --version '~> 4.0' && danger
|
||||
|
|
|
@ -39,7 +39,7 @@ script:
|
|||
- pip install cython
|
||||
- pip install mock pylint unqlite
|
||||
- pylint lbrynet
|
||||
- PYTHONPATH=. trial tests
|
||||
- python -m unittest discover tests/integration
|
||||
- PYTHONPATH=. trial lbrynet.tests
|
||||
- python -m unittest discover lbrynet/tests/integration
|
||||
- rvm install ruby-2.3.1
|
||||
- rvm use 2.3.1 && gem install danger --version '~> 4.0' && danger
|
||||
|
|
|
@ -28,6 +28,7 @@ at anytime.
|
|||
### Changed
|
||||
* Announcing by head blob is turned on by default
|
||||
* Updated reflector server dns
|
||||
* Moved tests into the lbrynet package.
|
||||
|
||||
### Added
|
||||
* Added WAL pragma to sqlite3
|
||||
|
|
|
@ -32,8 +32,8 @@ from lbrynet.core.RateLimiter import DummyRateLimiter, RateLimiter
|
|||
from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
|
||||
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
|
||||
|
||||
from tests import mocks
|
||||
from tests.util import mk_db_and_blob_dir, rm_db_and_blob_dir
|
||||
from lbrynet.tests import mocks
|
||||
from lbrynet.tests.util import mk_db_and_blob_dir, rm_db_and_blob_dir
|
||||
|
||||
FakeNode = mocks.Node
|
||||
FakeWallet = mocks.Wallet
|
|
@ -1,7 +1,3 @@
|
|||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
from twisted.internet import defer, threads, error
|
||||
from twisted.trial import unittest
|
||||
|
||||
|
@ -19,8 +15,8 @@ from lbrynet.lbry_file.client import EncryptedFileOptions
|
|||
from lbrynet.file_manager import EncryptedFileCreator
|
||||
from lbrynet.file_manager import EncryptedFileManager
|
||||
|
||||
from tests import mocks
|
||||
from tests.util import mk_db_and_blob_dir, rm_db_and_blob_dir
|
||||
from lbrynet.tests import mocks
|
||||
from lbrynet.tests.util import mk_db_and_blob_dir, rm_db_and_blob_dir
|
||||
|
||||
class TestReflector(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
@ -73,7 +69,8 @@ class TestReflector(unittest.TestCase):
|
|||
dht_node_class=Node
|
||||
)
|
||||
|
||||
self.stream_info_manager = EncryptedFileMetadataManager.DBEncryptedFileMetadataManager(self.db_dir)
|
||||
self.stream_info_manager = EncryptedFileMetadataManager.DBEncryptedFileMetadataManager(
|
||||
self.db_dir)
|
||||
|
||||
self.lbry_file_manager = EncryptedFileManager.EncryptedFileManager(
|
||||
self.session, self.stream_info_manager, sd_identifier)
|
||||
|
@ -81,7 +78,8 @@ class TestReflector(unittest.TestCase):
|
|||
self.server_db_dir, self.server_blob_dir = mk_db_and_blob_dir()
|
||||
self.server_blob_manager = BlobManager.DiskBlobManager(
|
||||
hash_announcer, self.server_blob_dir, self.server_db_dir)
|
||||
self.server_stream_info_manager = EncryptedFileMetadataManager.DBEncryptedFileMetadataManager(self.server_db_dir)
|
||||
self.server_stream_info_manager = \
|
||||
EncryptedFileMetadataManager.DBEncryptedFileMetadataManager(self.server_db_dir)
|
||||
|
||||
|
||||
d = self.session.setup()
|
||||
|
@ -124,7 +122,8 @@ class TestReflector(unittest.TestCase):
|
|||
return d
|
||||
|
||||
def start_server():
|
||||
server_factory = reflector.ServerFactory(peer_manager, self.server_blob_manager, self.server_stream_info_manager)
|
||||
server_factory = reflector.ServerFactory(
|
||||
peer_manager, self.server_blob_manager, self.server_stream_info_manager)
|
||||
from twisted.internet import reactor
|
||||
port = 8943
|
||||
while self.reflector_port is None:
|
||||
|
@ -181,7 +180,8 @@ class TestReflector(unittest.TestCase):
|
|||
blob_hashes = [b[0] for b in blobs if b[0] is not None]
|
||||
expected_blob_hashes = [b[0] for b in self.expected_blobs[:-1] if b[0] is not None]
|
||||
self.assertEqual(expected_blob_hashes, blob_hashes)
|
||||
sd_hashes = yield self.server_stream_info_manager.get_sd_blob_hashes_for_stream(self.stream_hash)
|
||||
sd_hashes = yield self.server_stream_info_manager.get_sd_blob_hashes_for_stream(
|
||||
self.stream_hash)
|
||||
self.assertEqual(1, len(sd_hashes))
|
||||
expected_sd_hash = self.expected_blobs[-1][0]
|
||||
self.assertEqual(self.sd_hash, sd_hashes[0])
|
||||
|
@ -309,7 +309,8 @@ class TestReflector(unittest.TestCase):
|
|||
blob_hashes = [b[0] for b in blobs if b[0] is not None]
|
||||
expected_blob_hashes = [b[0] for b in self.expected_blobs[:-1] if b[0] is not None]
|
||||
self.assertEqual(expected_blob_hashes, blob_hashes)
|
||||
sd_hashes = yield self.server_stream_info_manager.get_sd_blob_hashes_for_stream(self.stream_hash)
|
||||
sd_hashes = yield self.server_stream_info_manager.get_sd_blob_hashes_for_stream(
|
||||
self.stream_hash)
|
||||
self.assertEqual(1, len(sd_hashes))
|
||||
expected_sd_hash = self.expected_blobs[-1][0]
|
||||
self.assertEqual(self.sd_hash, sd_hashes[0])
|
|
@ -17,9 +17,9 @@ from lbrynet.file_manager.EncryptedFileCreator import create_lbry_file
|
|||
from lbrynet.lbry_file.client.EncryptedFileOptions import add_lbry_file_to_sd_identifier
|
||||
from lbrynet.lbry_file.StreamDescriptor import get_sd_info
|
||||
from lbrynet.core.PeerManager import PeerManager
|
||||
from lbrynet.core.RateLimiter import DummyRateLimiter, RateLimiter
|
||||
from lbrynet.core.RateLimiter import DummyRateLimiter
|
||||
|
||||
from tests import mocks
|
||||
from lbrynet.tests import mocks
|
||||
|
||||
|
||||
FakeNode = mocks.Node
|
|
@ -1,7 +1,6 @@
|
|||
import io
|
||||
|
||||
from Crypto.PublicKey import RSA
|
||||
from decimal import Decimal
|
||||
from twisted.internet import defer
|
||||
|
||||
from lbrynet.core import PTCWallet
|
||||
|
@ -220,16 +219,37 @@ class BlobAvailabilityTracker(BlobAvailability.BlobAvailabilityTracker):
|
|||
|
||||
def __init__(self, blob_manager=None, peer_finder=None, dht_node=None):
|
||||
self.availability = {
|
||||
'91dc64cf1ff42e20d627b033ad5e4c3a4a96856ed8a6e3fb4cd5fa1cfba4bf72eefd325f579db92f45f4355550ace8e7': ['1.2.3.4'],
|
||||
'b2e48bb4c88cf46b76adf0d47a72389fae0cd1f19ed27dc509138c99509a25423a4cef788d571dca7988e1dca69e6fa0': ['1.2.3.4', '1.2.3.4'],
|
||||
'6af95cd062b4a179576997ef1054c9d2120f8592eea045e9667bea411d520262cd5a47b137eabb7a7871f5f8a79c92dd': ['1.2.3.4', '1.2.3.4', '1.2.3.4'],
|
||||
'6d8017aba362e5c5d0046625a039513419810a0397d728318c328a5cc5d96efb589fbca0728e54fe5adbf87e9545ee07': ['1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4'],
|
||||
'5a450b416275da4bdff604ee7b58eaedc7913c5005b7184fc3bc5ef0b1add00613587f54217c91097fc039ed9eace9dd': ['1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4'],
|
||||
'd7c82e6cac093b3f16107d2ae2b2c75424f1fcad2c7fbdbe66e4a13c0b6bd27b67b3a29c403b82279ab0f7c1c48d6787': ['1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4'],
|
||||
'9dbda74a472a2e5861a5d18197aeba0f5de67c67e401124c243d2f0f41edf01d7a26aeb0b5fc9bf47f6361e0f0968e2c': ['1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4'],
|
||||
'8c70d5e2f5c3a6085006198e5192d157a125d92e7378794472007a61947992768926513fc10924785bdb1761df3c37e6': ['1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4'],
|
||||
'f99d24cd50d4bfd77c2598bfbeeb8415bf0feef21200bdf0b8fbbde7751a77b7a2c68e09c25465a2f40fba8eecb0b4e0': ['1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4'],
|
||||
'c84aa1fd8f5009f7c4e71e444e40d95610abc1480834f835eefb267287aeb10025880a3ce22580db8c6d92efb5bc0c9c': ['1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4'],
|
||||
'91dc64cf1ff42e20d627b033ad5e4c3a4a96856ed8a6e3fb'
|
||||
'4cd5fa1cfba4bf72eefd325f579db92f45f4355550ace8e7': ['1.2.3.4'],
|
||||
'b2e48bb4c88cf46b76adf0d47a72389fae0cd1f19ed27dc5'
|
||||
'09138c99509a25423a4cef788d571dca7988e1dca69e6fa0': ['1.2.3.4', '1.2.3.4'],
|
||||
'6af95cd062b4a179576997ef1054c9d2120f8592eea045e9'
|
||||
'667bea411d520262cd5a47b137eabb7a7871f5f8a79c92dd':
|
||||
['1.2.3.4', '1.2.3.4', '1.2.3.4'],
|
||||
'6d8017aba362e5c5d0046625a039513419810a0397d72831'
|
||||
'8c328a5cc5d96efb589fbca0728e54fe5adbf87e9545ee07':
|
||||
['1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4'],
|
||||
'5a450b416275da4bdff604ee7b58eaedc7913c5005b7184f'
|
||||
'c3bc5ef0b1add00613587f54217c91097fc039ed9eace9dd':
|
||||
['1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4'],
|
||||
'd7c82e6cac093b3f16107d2ae2b2c75424f1fcad2c7fbdbe'
|
||||
'66e4a13c0b6bd27b67b3a29c403b82279ab0f7c1c48d6787':
|
||||
['1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4'],
|
||||
'9dbda74a472a2e5861a5d18197aeba0f5de67c67e401124c'
|
||||
'243d2f0f41edf01d7a26aeb0b5fc9bf47f6361e0f0968e2c':
|
||||
['1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4'],
|
||||
'8c70d5e2f5c3a6085006198e5192d157a125d92e73787944'
|
||||
'72007a61947992768926513fc10924785bdb1761df3c37e6':
|
||||
['1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4',
|
||||
'1.2.3.4'],
|
||||
'f99d24cd50d4bfd77c2598bfbeeb8415bf0feef21200bdf0'
|
||||
'b8fbbde7751a77b7a2c68e09c25465a2f40fba8eecb0b4e0':
|
||||
['1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4',
|
||||
'1.2.3.4', '1.2.3.4'],
|
||||
'c84aa1fd8f5009f7c4e71e444e40d95610abc1480834f835'
|
||||
'eefb267287aeb10025880a3ce22580db8c6d92efb5bc0c9c':
|
||||
['1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4',
|
||||
'1.2.3.4', '1.2.3.4', '1.2.3.4'],
|
||||
}
|
||||
self._blob_manager = None
|
||||
self._peer_finder = PeerFinder(11223, 11224, 2)
|
||||
|
@ -252,19 +272,22 @@ create_stream_sd_file = {
|
|||
{
|
||||
'length': 2097152,
|
||||
'blob_num': 0,
|
||||
'blob_hash': 'dc4708f76a5e7af0f1cae0ee96b824e2ed9250c9346c093b441f0a20d3607c17948b6fcfb4bc62020fe5286693d08586',
|
||||
'blob_hash': 'dc4708f76a5e7af0f1cae0ee96b824e2ed9250c9346c093b'
|
||||
'441f0a20d3607c17948b6fcfb4bc62020fe5286693d08586',
|
||||
'iv': '30303030303030303030303030303031'
|
||||
},
|
||||
{
|
||||
'length': 2097152,
|
||||
'blob_num': 1,
|
||||
'blob_hash': 'f4067522c1b49432a2a679512e3917144317caa1abba0c041e0cd2cf9f635d4cf127ce1824fa04189b63916174951f70',
|
||||
'blob_hash': 'f4067522c1b49432a2a679512e3917144317caa1abba0c04'
|
||||
'1e0cd2cf9f635d4cf127ce1824fa04189b63916174951f70',
|
||||
'iv': '30303030303030303030303030303032'
|
||||
},
|
||||
{
|
||||
'length': 1015056,
|
||||
'blob_num': 2,
|
||||
'blob_hash': '305486c434260484fcb2968ce0e963b72f81ba56c11b08b1af0789b55b44d78422600f9a38e3cf4f2e9569897e5646a9',
|
||||
'blob_hash': '305486c434260484fcb2968ce0e963b72f81ba56c11b08b1'
|
||||
'af0789b55b44d78422600f9a38e3cf4f2e9569897e5646a9',
|
||||
'iv': '30303030303030303030303030303033'
|
||||
},
|
||||
{'length': 0, 'blob_num': 3, 'iv': '30303030303030303030303030303034'}
|
||||
|
@ -272,7 +295,8 @@ create_stream_sd_file = {
|
|||
'stream_type': 'lbryfile',
|
||||
'key': '30313233343536373031323334353637',
|
||||
'suggested_file_name': '746573745f66696c65',
|
||||
'stream_hash': '6d27fbe10c86d81aacfb897c7a426d0a2214f5a299455a6d315c0f998c4b3545c2dc60906122d94653c23b1898229e3f'
|
||||
'stream_hash': '6d27fbe10c86d81aacfb897c7a426d0a2214f5a299455a6d'
|
||||
'315c0f998c4b3545c2dc60906122d94653c23b1898229e3f'
|
||||
}
|
||||
|
||||
|
|
@ -1,20 +1,15 @@
|
|||
import sys
|
||||
import time
|
||||
import logging
|
||||
|
||||
from lbrynet.core import log_support
|
||||
from lbrynet.core.client.ClientRequest import ClientRequest
|
||||
from lbrynet.core.server.ServerProtocol import ServerProtocol
|
||||
from lbrynet.core.client.ClientProtocol import ClientProtocol
|
||||
from lbrynet.core.RateLimiter import RateLimiter
|
||||
from lbrynet.core.Peer import Peer
|
||||
from lbrynet.core.PeerManager import PeerManager
|
||||
from lbrynet.core.Error import ConnectionClosedBeforeResponseError, NoResponseError
|
||||
from lbrynet.core.Error import NoResponseError
|
||||
|
||||
from twisted.trial import unittest
|
||||
from twisted.internet import defer, reactor, task
|
||||
from twisted.internet.task import deferLater
|
||||
from twisted.internet.protocol import Protocol, ServerFactory
|
||||
from twisted.internet.protocol import ServerFactory
|
||||
from lbrynet import conf
|
||||
from lbrynet.core import utils
|
||||
from lbrynet.interfaces import IQueryHandlerFactory, IQueryHandler, IRequestCreator
|
||||
|
@ -153,7 +148,8 @@ class TestIntegrationConnectionManager(unittest.TestCase):
|
|||
self.server_port = reactor.listenTCP(PEER_PORT, self.server, interface=LOCAL_HOST)
|
||||
yield self.connection_manager.manage(schedule_next_call=False)
|
||||
self.assertEqual(1, self.connection_manager.num_peer_connections())
|
||||
connection_made = yield self.connection_manager._peer_connections[self.TEST_PEER].factory.connection_was_made_deferred
|
||||
connection_made = yield self.connection_manager._peer_connections[self.TEST_PEER].\
|
||||
factory.connection_was_made_deferred
|
||||
self.assertEqual(0, self.connection_manager.num_peer_connections())
|
||||
self.assertTrue(connection_made)
|
||||
self.assertEqual(1, self.TEST_PEER.success_count)
|
||||
|
@ -166,7 +162,8 @@ class TestIntegrationConnectionManager(unittest.TestCase):
|
|||
self.server_port = reactor.listenTCP(PEER_PORT, self.server, interface=LOCAL_HOST)
|
||||
yield self.connection_manager.manage(schedule_next_call=False)
|
||||
self.assertEqual(1, self.connection_manager.num_peer_connections())
|
||||
connection_made = yield self.connection_manager._peer_connections[self.TEST_PEER].factory.connection_was_made_deferred
|
||||
connection_made = yield self.connection_manager._peer_connections[self.TEST_PEER].\
|
||||
factory.connection_was_made_deferred
|
||||
self.assertEqual(0, self.connection_manager.num_peer_connections())
|
||||
self.assertTrue(connection_made)
|
||||
self.assertEqual(0, self.TEST_PEER.success_count)
|
||||
|
@ -179,7 +176,8 @@ class TestIntegrationConnectionManager(unittest.TestCase):
|
|||
self._init_connection_manager()
|
||||
yield self.connection_manager.manage(schedule_next_call=False)
|
||||
self.assertEqual(1, self.connection_manager.num_peer_connections())
|
||||
connection_made = yield self.connection_manager._peer_connections[self.TEST_PEER].factory.connection_was_made_deferred
|
||||
connection_made = yield self.connection_manager._peer_connections[self.TEST_PEER].\
|
||||
factory.connection_was_made_deferred
|
||||
self.assertEqual(0, self.connection_manager.num_peer_connections())
|
||||
self.assertFalse(connection_made)
|
||||
self.assertEqual(0, self.connection_manager.num_peer_connections())
|
||||
|
@ -199,12 +197,14 @@ class TestIntegrationConnectionManager(unittest.TestCase):
|
|||
self.assertEqual(2, self.connection_manager.num_peer_connections())
|
||||
self.assertIn(self.TEST_PEER, self.connection_manager._peer_connections)
|
||||
self.assertIn(test_peer2, self.connection_manager._peer_connections)
|
||||
connection_made = yield self.connection_manager._peer_connections[self.TEST_PEER].factory.connection_was_made_deferred
|
||||
connection_made = yield self.connection_manager._peer_connections[self.TEST_PEER].\
|
||||
factory.connection_was_made_deferred
|
||||
self.assertFalse(connection_made)
|
||||
self.assertEqual(1, self.connection_manager.num_peer_connections())
|
||||
self.assertEqual(0, self.TEST_PEER.success_count)
|
||||
self.assertEqual(1, self.TEST_PEER.down_count)
|
||||
connection_made = yield self.connection_manager._peer_connections[test_peer2].factory.connection_was_made_deferred
|
||||
connection_made = yield self.connection_manager._peer_connections[test_peer2].\
|
||||
factory.connection_was_made_deferred
|
||||
self.assertFalse(connection_made)
|
||||
self.assertEqual(0, self.connection_manager.num_peer_connections())
|
||||
self.assertEqual(0, test_peer2.success_count)
|
||||
|
@ -227,19 +227,21 @@ class TestIntegrationConnectionManager(unittest.TestCase):
|
|||
@defer.inlineCallbacks
|
||||
def test_closed_connection_when_server_is_slow(self):
|
||||
self._init_connection_manager()
|
||||
self.server = MocServerProtocolFactory(self.clock, has_moc_query_handler=True,is_delayed=True)
|
||||
self.server = MocServerProtocolFactory(
|
||||
self.clock, has_moc_query_handler=True, is_delayed=True)
|
||||
self.server_port = reactor.listenTCP(PEER_PORT, self.server, interface=LOCAL_HOST)
|
||||
|
||||
yield self.connection_manager.manage(schedule_next_call=False)
|
||||
self.assertEqual(1, self.connection_manager.num_peer_connections())
|
||||
connection_made = yield self.connection_manager._peer_connections[self.TEST_PEER].factory.connection_was_made_deferred
|
||||
connection_made = yield self.connection_manager._peer_connections[self.TEST_PEER].\
|
||||
factory.connection_was_made_deferred
|
||||
self.assertEqual(0, self.connection_manager.num_peer_connections())
|
||||
self.assertEqual(True, connection_made)
|
||||
self.assertEqual(0, self.TEST_PEER.success_count)
|
||||
self.assertEqual(1, self.TEST_PEER.down_count)
|
||||
|
||||
|
||||
""" test header first seeks """
|
||||
# test header first seeks
|
||||
@defer.inlineCallbacks
|
||||
def test_no_peer_for_head_blob(self):
|
||||
# test that if we can't find blobs for the head blob,
|
||||
|
@ -253,7 +255,8 @@ class TestIntegrationConnectionManager(unittest.TestCase):
|
|||
|
||||
yield self.connection_manager.manage(schedule_next_call=False)
|
||||
self.assertEqual(1, self.connection_manager.num_peer_connections())
|
||||
connection_made = yield self.connection_manager._peer_connections[self.TEST_PEER].factory.connection_was_made_deferred
|
||||
connection_made = yield self.connection_manager._peer_connections[self.TEST_PEER].\
|
||||
factory.connection_was_made_deferred
|
||||
self.assertEqual(0, self.connection_manager.num_peer_connections())
|
||||
self.assertTrue(connection_made)
|
||||
self.assertEqual(1, self.TEST_PEER.success_count)
|
|
@ -8,7 +8,8 @@ from twisted.trial import unittest
|
|||
from lbrynet.core import Peer
|
||||
from lbrynet.core.server import BlobRequestHandler
|
||||
from lbrynet.core.PaymentRateManager import NegotiatedPaymentRateManager, BasePaymentRateManager
|
||||
from tests.mocks import BlobAvailabilityTracker as DummyBlobAvailabilityTracker, mock_conf_settings
|
||||
from lbrynet.tests.mocks\
|
||||
import BlobAvailabilityTracker as DummyBlobAvailabilityTracker, mock_conf_settings
|
||||
|
||||
|
||||
class TestBlobRequestHandlerQueries(unittest.TestCase):
|
|
@ -1,10 +1,8 @@
|
|||
from twisted.trial import unittest
|
||||
from twisted.internet import defer, task
|
||||
|
||||
from lbrynet.core.server.DHTHashAnnouncer import DHTHashAnnouncer,DHTHashSupplier
|
||||
from lbrynet.core.utils import random_string
|
||||
from lbrynet.core import log_support, utils
|
||||
from tests.util import random_lbry_hash
|
||||
from lbrynet.core import utils
|
||||
from lbrynet.tests.util import random_lbry_hash
|
||||
|
||||
class MocDHTNode(object):
|
||||
def __init__(self):
|
||||
|
@ -35,7 +33,7 @@ class DHTHashAnnouncerTest(unittest.TestCase):
|
|||
self.clock = task.Clock()
|
||||
self.dht_node = MocDHTNode()
|
||||
utils.call_later = self.clock.callLater
|
||||
from lbrynet.core.server.DHTHashAnnouncer import DHTHashAnnouncer,DHTHashSupplier
|
||||
from lbrynet.core.server.DHTHashAnnouncer import DHTHashAnnouncer
|
||||
self.announcer = DHTHashAnnouncer(self.dht_node, peer_port=3333)
|
||||
self.supplier = MocSupplier(self.blobs_to_announce)
|
||||
self.announcer.add_supplier(self.supplier)
|
|
@ -1,11 +1,10 @@
|
|||
import tempfile
|
||||
import shutil
|
||||
import mock
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
|
||||
from tests.util import random_lbry_hash
|
||||
from lbrynet.tests.util import random_lbry_hash
|
||||
from lbrynet.core.BlobManager import DiskBlobManager
|
||||
from lbrynet.core.HashAnnouncer import DummyHashAnnouncer
|
||||
from lbrynet.core.Peer import Peer
|
||||
|
@ -113,4 +112,3 @@ class BlobManagerTest(unittest.TestCase):
|
|||
self.assertEqual(len(blobs), 10)
|
||||
self.assertTrue(blob_hashes[-1] in blobs)
|
||||
self.assertTrue(os.path.isfile(os.path.join(self.blob_dir, blob_hashes[-1])))
|
||||
|
|
@ -2,11 +2,9 @@ from lbrynet.blob import BlobFile
|
|||
from lbrynet.core.Error import DownloadCanceledError, InvalidDataError
|
||||
|
||||
|
||||
from tests.util import mk_db_and_blob_dir, rm_db_and_blob_dir, random_lbry_hash
|
||||
from lbrynet.tests.util import mk_db_and_blob_dir, rm_db_and_blob_dir, random_lbry_hash
|
||||
from twisted.trial import unittest
|
||||
from twisted.internet import defer
|
||||
import os
|
||||
import time
|
||||
|
||||
|
||||
class BlobFileTest(unittest.TestCase):
|
||||
|
@ -14,7 +12,8 @@ class BlobFileTest(unittest.TestCase):
|
|||
self.db_dir, self.blob_dir = mk_db_and_blob_dir()
|
||||
self.fake_content_len = 64
|
||||
self.fake_content = bytearray('0'*self.fake_content_len)
|
||||
self.fake_content_hash = '53871b26a08e90cb62142f2a39f0b80de41792322b0ca5602b6eb7b5cf067c49498a7492bb9364bbf90f40c1c5412105'
|
||||
self.fake_content_hash = '53871b26a08e90cb62142f2a39f0b80de41792322b0ca560' \
|
||||
'2b6eb7b5cf067c49498a7492bb9364bbf90f40c1c5412105'
|
||||
|
||||
def tearDown(self):
|
||||
rm_db_and_blob_dir(self.db_dir, self.blob_dir)
|
|
@ -5,31 +5,44 @@ import mock
|
|||
from lbrynet.core.PaymentRateManager import NegotiatedPaymentRateManager, BasePaymentRateManager
|
||||
from lbrynet.core.Strategy import BasicAvailabilityWeightedStrategy
|
||||
from lbrynet.core.Offer import Offer
|
||||
from tests.mocks import BlobAvailabilityTracker as DummyBlobAvailabilityTracker, mock_conf_settings
|
||||
from lbrynet.tests.mocks\
|
||||
import BlobAvailabilityTracker as DummyBlobAvailabilityTracker, mock_conf_settings
|
||||
|
||||
MAX_NEGOTIATION_TURNS = 10
|
||||
random.seed(12345)
|
||||
|
||||
|
||||
def get_random_sample(list_to_sample):
|
||||
result = list_to_sample[random.randint(1, len(list_to_sample)):random.randint(1, len(list_to_sample))]
|
||||
result = list_to_sample[
|
||||
random.randint(1, len(list_to_sample)):random.randint(1, len(list_to_sample))]
|
||||
if not result:
|
||||
return get_random_sample(list_to_sample)
|
||||
return result
|
||||
|
||||
|
||||
def calculate_negotation_turns(client_base, host_base, host_is_generous=True, client_is_generous=True):
|
||||
def calculate_negotation_turns(client_base, host_base, host_is_generous=True,
|
||||
client_is_generous=True):
|
||||
blobs = [
|
||||
'b2e48bb4c88cf46b76adf0d47a72389fae0cd1f19ed27dc509138c99509a25423a4cef788d571dca7988e1dca69e6fa0',
|
||||
'd7c82e6cac093b3f16107d2ae2b2c75424f1fcad2c7fbdbe66e4a13c0b6bd27b67b3a29c403b82279ab0f7c1c48d6787',
|
||||
'5a450b416275da4bdff604ee7b58eaedc7913c5005b7184fc3bc5ef0b1add00613587f54217c91097fc039ed9eace9dd',
|
||||
'f99d24cd50d4bfd77c2598bfbeeb8415bf0feef21200bdf0b8fbbde7751a77b7a2c68e09c25465a2f40fba8eecb0b4e0',
|
||||
'9dbda74a472a2e5861a5d18197aeba0f5de67c67e401124c243d2f0f41edf01d7a26aeb0b5fc9bf47f6361e0f0968e2c',
|
||||
'91dc64cf1ff42e20d627b033ad5e4c3a4a96856ed8a6e3fb4cd5fa1cfba4bf72eefd325f579db92f45f4355550ace8e7',
|
||||
'6d8017aba362e5c5d0046625a039513419810a0397d728318c328a5cc5d96efb589fbca0728e54fe5adbf87e9545ee07',
|
||||
'6af95cd062b4a179576997ef1054c9d2120f8592eea045e9667bea411d520262cd5a47b137eabb7a7871f5f8a79c92dd',
|
||||
'8c70d5e2f5c3a6085006198e5192d157a125d92e7378794472007a61947992768926513fc10924785bdb1761df3c37e6',
|
||||
'c84aa1fd8f5009f7c4e71e444e40d95610abc1480834f835eefb267287aeb10025880a3ce22580db8c6d92efb5bc0c9c'
|
||||
'b2e48bb4c88cf46b76adf0d47a72389fae0cd1f19ed27dc5'
|
||||
'09138c99509a25423a4cef788d571dca7988e1dca69e6fa0',
|
||||
'd7c82e6cac093b3f16107d2ae2b2c75424f1fcad2c7fbdbe'
|
||||
'66e4a13c0b6bd27b67b3a29c403b82279ab0f7c1c48d6787',
|
||||
'5a450b416275da4bdff604ee7b58eaedc7913c5005b7184f'
|
||||
'c3bc5ef0b1add00613587f54217c91097fc039ed9eace9dd',
|
||||
'f99d24cd50d4bfd77c2598bfbeeb8415bf0feef21200bdf0'
|
||||
'b8fbbde7751a77b7a2c68e09c25465a2f40fba8eecb0b4e0',
|
||||
'9dbda74a472a2e5861a5d18197aeba0f5de67c67e401124c'
|
||||
'243d2f0f41edf01d7a26aeb0b5fc9bf47f6361e0f0968e2c',
|
||||
'91dc64cf1ff42e20d627b033ad5e4c3a4a96856ed8a6e3fb'
|
||||
'4cd5fa1cfba4bf72eefd325f579db92f45f4355550ace8e7',
|
||||
'6d8017aba362e5c5d0046625a039513419810a0397d72831'
|
||||
'8c328a5cc5d96efb589fbca0728e54fe5adbf87e9545ee07',
|
||||
'6af95cd062b4a179576997ef1054c9d2120f8592eea045e9'
|
||||
'667bea411d520262cd5a47b137eabb7a7871f5f8a79c92dd',
|
||||
'8c70d5e2f5c3a6085006198e5192d157a125d92e73787944'
|
||||
'72007a61947992768926513fc10924785bdb1761df3c37e6',
|
||||
'c84aa1fd8f5009f7c4e71e444e40d95610abc1480834f835'
|
||||
'eefb267287aeb10025880a3ce22580db8c6d92efb5bc0c9c'
|
||||
]
|
||||
|
||||
host = mock.Mock()
|
|
@ -20,7 +20,10 @@ test_metadata = {
|
|||
test_claim_dict = {
|
||||
'version':'_0_0_1',
|
||||
'claimType':'streamType',
|
||||
'stream':{'metadata':test_metadata, 'version':'_0_0_1','source':{'source':'8655f713819344980a9a0d67b198344e2c462c90f813e86f0c63789ab0868031f25c54d0bb31af6658e997e2041806eb','sourceType':'lbry_sd_hash','contentType':'video/mp4','version':'_0_0_1'},
|
||||
'stream':{'metadata':test_metadata, 'version':'_0_0_1', 'source':
|
||||
{'source': '8655f713819344980a9a0d67b198344e2c462c90f813e86f'
|
||||
'0c63789ab0868031f25c54d0bb31af6658e997e2041806eb',
|
||||
'sourceType': 'lbry_sd_hash', 'contentType': 'video/mp4', 'version': '_0_0_1'},
|
||||
}}
|
||||
|
||||
|
||||
|
@ -188,6 +191,7 @@ class WalletTest(unittest.TestCase):
|
|||
d = wallet.update_balance()
|
||||
d.addCallback(lambda _: self.assertEqual(5, wallet.get_balance()))
|
||||
d.addCallback(lambda _: wallet.reserve_points('testid', 2))
|
||||
d.addCallback(lambda _: wallet.support_claim('test', "f43dc06256a69988bdbea09a58c80493ba15dcfa", 4))
|
||||
d.addCallback(lambda _: wallet.support_claim(
|
||||
'test', "f43dc06256a69988bdbea09a58c80493ba15dcfa", 4))
|
||||
self.assertFailure(d, InsufficientFundsError)
|
||||
return d
|
|
@ -3,15 +3,12 @@ from twisted.internet import defer
|
|||
from lbrynet.cryptstream import CryptBlob
|
||||
from lbrynet import conf
|
||||
|
||||
from tests.mocks import mock_conf_settings
|
||||
from lbrynet.tests.mocks import mock_conf_settings
|
||||
|
||||
from Crypto import Random
|
||||
from Crypto.Cipher import AES
|
||||
import tempfile
|
||||
import random
|
||||
import string
|
||||
import StringIO
|
||||
import time
|
||||
|
||||
class MocBlob(object):
|
||||
def __init__(self):
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
import unittest
|
||||
import time
|
||||
import datetime
|
||||
import random
|
||||
|
||||
import lbrynet.dht.datastore
|
||||
import lbrynet.dht.constants
|
||||
|
@ -44,23 +42,32 @@ class DictDataStoreTest(unittest.TestCase):
|
|||
self.ds.addPeerToBlob(key, value, now, now, 'node1')
|
||||
except Exception:
|
||||
import traceback
|
||||
self.fail('Failed writing the following data: key: "%s", data: "%s"\n The error was: %s:' % (key, value, traceback.format_exc(5)))
|
||||
self.fail('Failed writing the following data: key: "%s" '
|
||||
'data: "%s"\n The error was: %s:' %
|
||||
(key, value, traceback.format_exc(5)))
|
||||
|
||||
# Verify writing (test query ability)
|
||||
for key, value in self.cases:
|
||||
try:
|
||||
self.failUnless(self.ds.hasPeersForBlob(key), 'Key "%s" not found in DataStore! DataStore key dump: %s' % (key, self.ds.keys()))
|
||||
self.failUnless(self.ds.hasPeersForBlob(key),
|
||||
'Key "%s" not found in DataStore! DataStore key dump: %s' %
|
||||
(key, self.ds.keys()))
|
||||
except Exception:
|
||||
import traceback
|
||||
self.fail('Failed verifying that the following key exists: "%s"\n The error was: %s:' % (key, traceback.format_exc(5)))
|
||||
self.fail(
|
||||
'Failed verifying that the following key exists: "%s"\n The error was: %s:' %
|
||||
(key, traceback.format_exc(5)))
|
||||
|
||||
# Read back the data
|
||||
for key, value in self.cases:
|
||||
self.failUnless(value in self.ds.getPeersForBlob(key), 'DataStore returned invalid data! Expected "%s", got "%s"' % (value, self.ds.getPeersForBlob(key)))
|
||||
self.failUnless(value in self.ds.getPeersForBlob(key),
|
||||
'DataStore returned invalid data! Expected "%s", got "%s"' %
|
||||
(value, self.ds.getPeersForBlob(key)))
|
||||
|
||||
def testNonExistentKeys(self):
|
||||
for key, value in self.cases:
|
||||
self.failIf(key in self.ds.keys(), 'DataStore reports it has non-existent key: "%s"' % key)
|
||||
self.failIf(key in self.ds.keys(), 'DataStore reports it has non-existent key: "%s"' %
|
||||
key)
|
||||
|
||||
def testExpires(self):
|
||||
now = int(time.time())
|
||||
|
@ -78,10 +85,24 @@ class DictDataStoreTest(unittest.TestCase):
|
|||
self.ds.addPeerToBlob(h2, 'val3', now - td2, now - td2, '3')
|
||||
self.ds.addPeerToBlob(h2, 'val4', now, now, '4')
|
||||
self.ds.removeExpiredPeers()
|
||||
self.failUnless('val1' in self.ds.getPeersForBlob(h1), 'DataStore deleted an unexpired value! Value %s, publish time %s, current time %s' % ('val1', str(now - td), str(now)))
|
||||
self.failIf('val2' in self.ds.getPeersForBlob(h1), 'DataStore failed to delete an expired value! Value %s, publish time %s, current time %s' % ('val2', str(now - td2), str(now)))
|
||||
self.failIf('val3' in self.ds.getPeersForBlob(h2), 'DataStore failed to delete an expired value! Value %s, publish time %s, current time %s' % ('val3', str(now - td2), str(now)))
|
||||
self.failUnless('val4' in self.ds.getPeersForBlob(h2), 'DataStore deleted an unexpired value! Value %s, publish time %s, current time %s' % ('val4', str(now), str(now)))
|
||||
self.failUnless(
|
||||
'val1' in self.ds.getPeersForBlob(h1),
|
||||
'DataStore deleted an unexpired value! Value %s, publish time %s, current time %s' %
|
||||
('val1', str(now - td), str(now)))
|
||||
self.failIf(
|
||||
'val2' in self.ds.getPeersForBlob(h1),
|
||||
'DataStore failed to delete an expired value! '
|
||||
'Value %s, publish time %s, current time %s' %
|
||||
('val2', str(now - td2), str(now)))
|
||||
self.failIf(
|
||||
'val3' in self.ds.getPeersForBlob(h2),
|
||||
'DataStore failed to delete an expired value! '
|
||||
'Value %s, publish time %s, current time %s' %
|
||||
('val3', str(now - td2), str(now)))
|
||||
self.failUnless(
|
||||
'val4' in self.ds.getPeersForBlob(h2),
|
||||
'DataStore deleted an unexpired value! Value %s, publish time %s, current time %s' %
|
||||
('val4', str(now), str(now)))
|
||||
|
||||
# # First write with fake values
|
||||
# for key, value in self.cases:
|
|
@ -18,8 +18,10 @@ class BencodeTest(unittest.TestCase):
|
|||
(['spam', 42], 'l4:spami42ee'),
|
||||
({'foo':42, 'bar':'spam'}, 'd3:bar4:spam3:fooi42ee'),
|
||||
# ...and now the "real life" tests
|
||||
([['abc', '127.0.0.1', 1919], ['def', '127.0.0.1', 1921]], 'll3:abc9:127.0.0.1i1919eel3:def9:127.0.0.1i1921eee'))
|
||||
# The following test cases are "bad"; i.e. sending rubbish into the decoder to test what exceptions get thrown
|
||||
([['abc', '127.0.0.1', 1919], ['def', '127.0.0.1', 1921]],
|
||||
'll3:abc9:127.0.0.1i1919eel3:def9:127.0.0.1i1921eee'))
|
||||
# The following test cases are "bad"; i.e. sending rubbish into the decoder to test
|
||||
# what exceptions get thrown
|
||||
self.badDecoderCases = ('abcdefghijklmnopqrstuvwxyz',
|
||||
'')
|
||||
|
||||
|
@ -27,15 +29,22 @@ class BencodeTest(unittest.TestCase):
|
|||
""" Tests the bencode encoder """
|
||||
for value, encodedValue in self.cases:
|
||||
result = self.encoding.encode(value)
|
||||
self.failUnlessEqual(result, encodedValue, 'Value "%s" not correctly encoded! Expected "%s", got "%s"' % (value, encodedValue, result))
|
||||
self.failUnlessEqual(
|
||||
result, encodedValue,
|
||||
'Value "%s" not correctly encoded! Expected "%s", got "%s"' %
|
||||
(value, encodedValue, result))
|
||||
|
||||
def testDecoder(self):
|
||||
""" Tests the bencode decoder """
|
||||
for value, encodedValue in self.cases:
|
||||
result = self.encoding.decode(encodedValue)
|
||||
self.failUnlessEqual(result, value, 'Value "%s" not correctly decoded! Expected "%s", got "%s"' % (encodedValue, value, result))
|
||||
self.failUnlessEqual(
|
||||
result, value,
|
||||
'Value "%s" not correctly decoded! Expected "%s", got "%s"' %
|
||||
(encodedValue, value, result))
|
||||
for encodedValue in self.badDecoderCases:
|
||||
self.failUnlessRaises(lbrynet.dht.encoding.DecodeError, self.encoding.decode, encodedValue)
|
||||
self.failUnlessRaises(
|
||||
lbrynet.dht.encoding.DecodeError, self.encoding.decode, encodedValue)
|
||||
|
||||
def suite():
|
||||
suite = unittest.TestSuite()
|
|
@ -22,7 +22,10 @@ class KBucketTest(unittest.TestCase):
|
|||
for i in range(constants.k):
|
||||
tmpContact = contact.Contact('tempContactID%d' % i, str(i), i, i)
|
||||
self.kbucket.addContact(tmpContact)
|
||||
self.failUnlessEqual(self.kbucket._contacts[i], tmpContact, "Contact in position %d not the same as the newly-added contact" % i)
|
||||
self.failUnlessEqual(
|
||||
self.kbucket._contacts[i],
|
||||
tmpContact,
|
||||
"Contact in position %d not the same as the newly-added contact" % i)
|
||||
|
||||
# Test if contact is not added to full list
|
||||
i += 1
|
||||
|
@ -32,12 +35,16 @@ class KBucketTest(unittest.TestCase):
|
|||
# Test if an existing contact is updated correctly if added again
|
||||
existingContact = self.kbucket._contacts[0]
|
||||
self.kbucket.addContact(existingContact)
|
||||
self.failUnlessEqual(self.kbucket._contacts.index(existingContact), len(self.kbucket._contacts)-1, 'Contact not correctly updated; it should be at the end of the list of contacts')
|
||||
self.failUnlessEqual(
|
||||
self.kbucket._contacts.index(existingContact),
|
||||
len(self.kbucket._contacts)-1,
|
||||
'Contact not correctly updated; it should be at the end of the list of contacts')
|
||||
|
||||
def testGetContacts(self):
|
||||
# try and get 2 contacts from empty list
|
||||
result = self.kbucket.getContacts(2)
|
||||
self.failIf(len(result) != 0, "Returned list should be empty; returned list length: %d" % (len(result)))
|
||||
self.failIf(len(result) != 0, "Returned list should be empty; returned list length: %d" %
|
||||
(len(result)))
|
||||
|
||||
|
||||
# Add k-2 contacts
|
||||
|
@ -54,27 +61,31 @@ class KBucketTest(unittest.TestCase):
|
|||
# try to get too many contacts
|
||||
# requested count greater than bucket size; should return at most k contacts
|
||||
contacts = self.kbucket.getContacts(constants.k+3)
|
||||
self.failUnless(len(contacts) <= constants.k, 'Returned list should not have more than k entries!')
|
||||
self.failUnless(len(contacts) <= constants.k,
|
||||
'Returned list should not have more than k entries!')
|
||||
|
||||
# verify returned contacts in list
|
||||
for i in range(constants.k-2):
|
||||
self.failIf(self.kbucket._contacts[i].id != i, "Contact in position %s not same as added contact" % (str(i)))
|
||||
self.failIf(self.kbucket._contacts[i].id != i,
|
||||
"Contact in position %s not same as added contact" % (str(i)))
|
||||
|
||||
# try to get too many contacts
|
||||
# requested count one greater than number of contacts
|
||||
if constants.k >= 2:
|
||||
result = self.kbucket.getContacts(constants.k-1)
|
||||
self.failIf(len(result) != constants.k-2, "Too many contacts in returned list %s - should be %s" % (len(result), constants.k-2))
|
||||
self.failIf(len(result) != constants.k-2,
|
||||
"Too many contacts in returned list %s - should be %s" %
|
||||
(len(result), constants.k-2))
|
||||
else:
|
||||
result = self.kbucket.getContacts(constants.k-1)
|
||||
# if the count is <= 0, it should return all of it's contats
|
||||
self.failIf(len(result) != constants.k, "Too many contacts in returned list %s - should be %s" % (len(result), constants.k-2))
|
||||
|
||||
# try to get contacts
|
||||
# requested count less than contact number
|
||||
if constants.k >= 3:
|
||||
self.failIf(len(result) != constants.k,
|
||||
"Too many contacts in returned list %s - should be %s" %
|
||||
(len(result), constants.k-2))
|
||||
result = self.kbucket.getContacts(constants.k-3)
|
||||
self.failIf(len(result) != constants.k-3, "Too many contacts in returned list %s - should be %s" % (len(result), constants.k-3))
|
||||
self.failIf(len(result) != constants.k-3,
|
||||
"Too many contacts in returned list %s - should be %s" %
|
||||
(len(result), constants.k-3))
|
||||
|
||||
def testRemoveContact(self):
|
||||
# try remove contact from empty list
|
|
@ -6,13 +6,14 @@
|
|||
|
||||
import unittest
|
||||
|
||||
from lbrynet.dht.msgtypes import Message, RequestMessage, ResponseMessage, ErrorMessage
|
||||
from lbrynet.dht.msgtypes import RequestMessage, ResponseMessage, ErrorMessage
|
||||
from lbrynet.dht.msgformat import MessageTranslator, DefaultFormat
|
||||
|
||||
class DefaultFormatTranslatorTest(unittest.TestCase):
|
||||
""" Test case for the default message translator """
|
||||
def setUp(self):
|
||||
self.cases = ((RequestMessage('node1', 'rpcMethod', {'arg1': 'a string', 'arg2': 123}, 'rpc1'),
|
||||
self.cases = ((RequestMessage('node1', 'rpcMethod',
|
||||
{'arg1': 'a string', 'arg2': 123}, 'rpc1'),
|
||||
{DefaultFormat.headerType: DefaultFormat.typeRequest,
|
||||
DefaultFormat.headerNodeID: 'node1',
|
||||
DefaultFormat.headerMsgID: 'rpc1',
|
||||
|
@ -25,37 +26,61 @@ class DefaultFormatTranslatorTest(unittest.TestCase):
|
|||
DefaultFormat.headerMsgID: 'rpc2',
|
||||
DefaultFormat.headerPayload: 'response'}),
|
||||
|
||||
(ErrorMessage('rpc3', 'node3', "<type 'exceptions.ValueError'>", 'this is a test exception'),
|
||||
(ErrorMessage('rpc3', 'node3',
|
||||
"<type 'exceptions.ValueError'>", 'this is a test exception'),
|
||||
{DefaultFormat.headerType: DefaultFormat.typeError,
|
||||
DefaultFormat.headerNodeID: 'node3',
|
||||
DefaultFormat.headerMsgID: 'rpc3',
|
||||
DefaultFormat.headerPayload: "<type 'exceptions.ValueError'>",
|
||||
DefaultFormat.headerArgs: 'this is a test exception'}),
|
||||
|
||||
(ResponseMessage('rpc4', 'node4', [('H\x89\xb0\xf4\xc9\xe6\xc5`H>\xd5\xc2\xc5\xe8Od\xf1\xca\xfa\x82', '127.0.0.1', 1919), ('\xae\x9ey\x93\xdd\xeb\xf1^\xff\xc5\x0f\xf8\xac!\x0e\x03\x9fY@{', '127.0.0.1', 1921)]),
|
||||
(ResponseMessage(
|
||||
'rpc4', 'node4',
|
||||
[('H\x89\xb0\xf4\xc9\xe6\xc5`H>\xd5\xc2\xc5\xe8Od\xf1\xca\xfa\x82',
|
||||
'127.0.0.1', 1919),
|
||||
('\xae\x9ey\x93\xdd\xeb\xf1^\xff\xc5\x0f\xf8\xac!\x0e\x03\x9fY@{',
|
||||
'127.0.0.1', 1921)]),
|
||||
{DefaultFormat.headerType: DefaultFormat.typeResponse,
|
||||
DefaultFormat.headerNodeID: 'node4',
|
||||
DefaultFormat.headerMsgID: 'rpc4',
|
||||
DefaultFormat.headerPayload: [('H\x89\xb0\xf4\xc9\xe6\xc5`H>\xd5\xc2\xc5\xe8Od\xf1\xca\xfa\x82', '127.0.0.1', 1919), ('\xae\x9ey\x93\xdd\xeb\xf1^\xff\xc5\x0f\xf8\xac!\x0e\x03\x9fY@{', '127.0.0.1', 1921)]})
|
||||
DefaultFormat.headerPayload:
|
||||
[('H\x89\xb0\xf4\xc9\xe6\xc5`H>\xd5\xc2\xc5\xe8Od\xf1\xca\xfa\x82',
|
||||
'127.0.0.1', 1919),
|
||||
('\xae\x9ey\x93\xdd\xeb\xf1^\xff\xc5\x0f\xf8\xac!\x0e\x03\x9fY@{',
|
||||
'127.0.0.1', 1921)]})
|
||||
)
|
||||
self.translator = DefaultFormat()
|
||||
self.failUnless(isinstance(self.translator, MessageTranslator), 'Translator class must inherit from entangled.kademlia.msgformat.MessageTranslator!')
|
||||
self.failUnless(
|
||||
isinstance(self.translator, MessageTranslator),
|
||||
'Translator class must inherit from entangled.kademlia.msgformat.MessageTranslator!')
|
||||
|
||||
def testToPrimitive(self):
|
||||
""" Tests translation from a Message object to a primitive """
|
||||
for msg, msgPrimitive in self.cases:
|
||||
translatedObj = self.translator.toPrimitive(msg)
|
||||
self.failUnlessEqual(len(translatedObj), len(msgPrimitive), "Translated object does not match example object's size")
|
||||
self.failUnlessEqual(len(translatedObj), len(msgPrimitive),
|
||||
"Translated object does not match example object's size")
|
||||
for key in msgPrimitive:
|
||||
self.failUnlessEqual(translatedObj[key], msgPrimitive[key], 'Message object type %s not translated correctly into primitive on key "%s"; expected "%s", got "%s"' % (msg.__class__.__name__, key, msgPrimitive[key], translatedObj[key]))
|
||||
self.failUnlessEqual(
|
||||
translatedObj[key], msgPrimitive[key],
|
||||
'Message object type %s not translated correctly into primitive on '
|
||||
'key "%s"; expected "%s", got "%s"' %
|
||||
(msg.__class__.__name__, key, msgPrimitive[key], translatedObj[key]))
|
||||
|
||||
def testFromPrimitive(self):
|
||||
""" Tests translation from a primitive to a Message object """
|
||||
for msg, msgPrimitive in self.cases:
|
||||
translatedObj = self.translator.fromPrimitive(msgPrimitive)
|
||||
self.failUnlessEqual(type(translatedObj), type(msg), 'Message type incorrectly translated; expected "%s", got "%s"' % (type(msg), type(translatedObj)))
|
||||
self.failUnlessEqual(
|
||||
type(translatedObj), type(msg),
|
||||
'Message type incorrectly translated; expected "%s", got "%s"' %
|
||||
(type(msg), type(translatedObj)))
|
||||
for key in msg.__dict__:
|
||||
self.failUnlessEqual(msg.__dict__[key], translatedObj.__dict__[key], 'Message instance variable "%s" not translated correctly; expected "%s", got "%s"' % (key, msg.__dict__[key], translatedObj.__dict__[key]))
|
||||
self.failUnlessEqual(
|
||||
msg.__dict__[key], translatedObj.__dict__[key],
|
||||
'Message instance variable "%s" not translated correctly; '
|
||||
'expected "%s", got "%s"' %
|
||||
(key, msg.__dict__[key], translatedObj.__dict__[key]))
|
||||
|
||||
|
||||
def suite():
|
|
@ -22,7 +22,8 @@ class TestEncryptedFileSaver(unittest.TestCase):
|
|||
wallet = None
|
||||
download_directory = '.'
|
||||
upload_allowed = False
|
||||
saver = EncryptedFileSaver(stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
|
||||
saver = EncryptedFileSaver(
|
||||
stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
|
||||
payment_rate_manager, wallet, download_directory, file_name)
|
||||
|
||||
yield saver._setup_output()
|
|
@ -3,10 +3,9 @@ import shutil
|
|||
from twisted.trial import unittest
|
||||
from twisted.internet import defer
|
||||
from lbrynet.lbry_file.EncryptedFileMetadataManager import DBEncryptedFileMetadataManager
|
||||
from lbrynet.core import utils
|
||||
from lbrynet.cryptstream.CryptBlob import CryptBlobInfo
|
||||
from lbrynet.core.Error import NoSuchStreamHash
|
||||
from tests.util import random_lbry_hash
|
||||
from lbrynet.tests.util import random_lbry_hash
|
||||
|
||||
class DBEncryptedFileMetadataManagerTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
@ -76,6 +75,3 @@ class DBEncryptedFileMetadataManagerTest(unittest.TestCase):
|
|||
yield self.manager.delete_stream(stream_hash)
|
||||
out = yield self.manager.check_if_stream_exists(stream_hash)
|
||||
self.assertFalse(out)
|
||||
|
||||
|
||||
|
|
@ -1,7 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
from Crypto.Cipher import AES
|
||||
import mock
|
||||
from twisted.trial import unittest
|
||||
|
@ -12,8 +9,8 @@ from lbrynet.core import Session
|
|||
from lbrynet.core.server import DHTHashAnnouncer
|
||||
from lbrynet.file_manager import EncryptedFileCreator
|
||||
from lbrynet.file_manager import EncryptedFileManager
|
||||
from tests import mocks
|
||||
from tests.util import mk_db_and_blob_dir, rm_db_and_blob_dir
|
||||
from lbrynet.tests import mocks
|
||||
from lbrynet.tests.util import mk_db_and_blob_dir, rm_db_and_blob_dir
|
||||
|
||||
MB = 2**20
|
||||
|
||||
|
@ -37,7 +34,8 @@ class CreateEncryptedFileTest(unittest.TestCase):
|
|||
def create_file(self, filename):
|
||||
session = mock.Mock(spec=Session.Session)(None, None)
|
||||
hash_announcer = DHTHashAnnouncer.DHTHashAnnouncer(None, None)
|
||||
self.blob_manager = BlobManager.DiskBlobManager(hash_announcer, self.tmp_blob_dir, self.tmp_db_dir)
|
||||
self.blob_manager = BlobManager.DiskBlobManager(
|
||||
hash_announcer, self.tmp_blob_dir, self.tmp_db_dir)
|
||||
session.blob_manager = self.blob_manager
|
||||
yield session.blob_manager.setup()
|
||||
session.db_dir = self.tmp_db_dir
|
|
@ -3,7 +3,7 @@ from twisted.trial import unittest
|
|||
from lbrynet import conf
|
||||
from lbrynet.file_manager.EncryptedFileDownloader import ManagedEncryptedFileDownloader
|
||||
from lbrynet.file_manager.EncryptedFileManager import EncryptedFileManager
|
||||
from tests.util import random_lbry_hash
|
||||
from lbrynet.tests.util import random_lbry_hash
|
||||
|
||||
class TestEncryptedFileManager(unittest.TestCase):
|
||||
|
||||
|
@ -22,7 +22,8 @@ class TestEncryptedFileManager(unittest.TestCase):
|
|||
stream_info_manager = None
|
||||
sd_identifier = None
|
||||
download_directory = '.'
|
||||
manager = EncryptedFileManager(session, stream_info_manager, sd_identifier, download_directory)
|
||||
manager = EncryptedFileManager(
|
||||
session, stream_info_manager, sd_identifier, download_directory)
|
||||
yield manager._open_db()
|
||||
out = yield manager._get_all_lbry_files()
|
||||
self.assertEqual(len(out), 0)
|
|
@ -1,7 +1,7 @@
|
|||
import mock
|
||||
from twisted.trial import unittest
|
||||
|
||||
from tests.mocks import mock_conf_settings
|
||||
from lbrynet.tests.mocks import mock_conf_settings
|
||||
from lbrynet.daemon.auth import server
|
||||
|
||||
|
|
@ -8,13 +8,12 @@ from lbryschema.decode import smart_decode
|
|||
from lbrynet import conf
|
||||
from lbrynet.core import Session, PaymentRateManager, Wallet
|
||||
from lbrynet.daemon.Daemon import Daemon as LBRYDaemon
|
||||
from lbrynet.daemon import ExchangeRateManager
|
||||
|
||||
from tests import util
|
||||
from tests.mocks import mock_conf_settings, FakeNetwork
|
||||
from tests.mocks import BlobAvailabilityTracker as DummyBlobAvailabilityTracker
|
||||
from tests.mocks import ExchangeRateManager as DummyExchangeRateManager
|
||||
from tests.mocks import BTCLBCFeed, USDBTCFeed
|
||||
from lbrynet.tests import util
|
||||
from lbrynet.tests.mocks import mock_conf_settings, FakeNetwork
|
||||
from lbrynet.tests.mocks import BlobAvailabilityTracker as DummyBlobAvailabilityTracker
|
||||
from lbrynet.tests.mocks import ExchangeRateManager as DummyExchangeRateManager
|
||||
from lbrynet.tests.mocks import BTCLBCFeed, USDBTCFeed
|
||||
|
||||
def get_test_daemon(data_rate=None, generous=True, with_fee=False):
|
||||
if data_rate is None:
|
||||
|
@ -43,7 +42,8 @@ def get_test_daemon(data_rate=None, generous=True, with_fee=False):
|
|||
"license_url": "fake license url",
|
||||
"nsfw": False,
|
||||
"sources": {
|
||||
"lbry_sd_hash": "d2b8b6e907dde95245fe6d144d16c2fdd60c4e0c6463ec98b85642d06d8e9414e8fcfdcb7cb13532ec5454fb8fe7f280"
|
||||
"lbry_sd_hash": 'd2b8b6e907dde95245fe6d144d16c2fdd60c4e0c6463ec98'
|
||||
'b85642d06d8e9414e8fcfdcb7cb13532ec5454fb8fe7f280'
|
||||
},
|
||||
"thumbnail": "fake thumbnail",
|
||||
"title": "fake title",
|
||||
|
@ -54,7 +54,8 @@ def get_test_daemon(data_rate=None, generous=True, with_fee=False):
|
|||
{"fee": {"USD": {"address": "bQ6BGboPV2SpTMEP7wLNiAcnsZiH8ye6eA", "amount": 0.75}}})
|
||||
daemon._resolve_name = lambda _: defer.succeed(metadata)
|
||||
migrated = smart_decode(json.dumps(metadata))
|
||||
daemon.session.wallet.resolve = lambda *_: defer.succeed({"test": {'claim': {'value': migrated.claim_dict}}})
|
||||
daemon.session.wallet.resolve = lambda *_: defer.succeed(
|
||||
{"test": {'claim': {'value': migrated.claim_dict}}})
|
||||
return daemon
|
||||
|
||||
|
|
@ -7,7 +7,8 @@ class DaemonCLITests(unittest.TestCase):
|
|||
self.assertEqual('0.3.8', DaemonCLI.guess_type('0.3.8'))
|
||||
self.assertEqual(0.3, DaemonCLI.guess_type('0.3'))
|
||||
self.assertEqual(3, DaemonCLI.guess_type('3'))
|
||||
self.assertEqual('VdNmakxFORPSyfCprAD/eDDPk5TY9QYtSA==', DaemonCLI.guess_type('VdNmakxFORPSyfCprAD/eDDPk5TY9QYtSA=='))
|
||||
self.assertEqual('VdNmakxFORPSyfCprAD/eDDPk5TY9QYtSA==',
|
||||
DaemonCLI.guess_type('VdNmakxFORPSyfCprAD/eDDPk5TY9QYtSA=='))
|
||||
self.assertEqual(0.3, DaemonCLI.guess_type('0.3'))
|
||||
self.assertEqual(True, DaemonCLI.guess_type('TRUE'))
|
||||
self.assertEqual(True, DaemonCLI.guess_type('true'))
|
|
@ -3,7 +3,6 @@ import mock
|
|||
from twisted.trial import unittest
|
||||
from twisted.internet import defer, task
|
||||
|
||||
|
||||
from lbrynet.core import Session, PaymentRateManager, Wallet
|
||||
from lbrynet.core.Error import DownloadDataTimeout, DownloadSDTimeout
|
||||
from lbrynet.daemon import Downloader
|
||||
|
@ -13,8 +12,8 @@ from lbrynet.file_manager.EncryptedFileStatusReport import EncryptedFileStatusRe
|
|||
from lbrynet.file_manager.EncryptedFileDownloader import ManagedEncryptedFileDownloader
|
||||
from lbrynet.daemon.ExchangeRateManager import ExchangeRateManager
|
||||
|
||||
from tests.mocks import ExchangeRateManager as DummyExchangeRateManager
|
||||
from tests.mocks import mock_conf_settings
|
||||
from lbrynet.tests.mocks import ExchangeRateManager as DummyExchangeRateManager
|
||||
from lbrynet.tests.mocks import mock_conf_settings
|
||||
|
||||
|
||||
class MocDownloader(object):
|
||||
|
@ -29,7 +28,8 @@ class MocDownloader(object):
|
|||
|
||||
@defer.inlineCallbacks
|
||||
def status(self):
|
||||
out = yield EncryptedFileStatusReport(self.name, self.num_completed, self.num_known, self.running_status)
|
||||
out = yield EncryptedFileStatusReport(
|
||||
self.name, self.num_completed, self.num_known, self.running_status)
|
||||
defer.returnValue(out)
|
||||
|
||||
def start(self):
|
||||
|
@ -40,7 +40,8 @@ class MocDownloader(object):
|
|||
self.finish_deferred.callback(True)
|
||||
|
||||
def moc_initialize(self, stream_info):
|
||||
self.sd_hash ="d5169241150022f996fa7cd6a9a1c421937276a3275eb912790bd07ba7aec1fac5fd45431d226b8fb402691e79aeb24b"
|
||||
self.sd_hash = "d5169241150022f996fa7cd6a9a1c421937276a3275eb912" \
|
||||
"790bd07ba7aec1fac5fd45431d226b8fb402691e79aeb24b"
|
||||
return None
|
||||
|
||||
def moc_download_sd_blob(self):
|
|
@ -3,9 +3,9 @@ from lbrynet.daemon import ExchangeRateManager
|
|||
from lbrynet.core.Error import InvalidExchangeRateResponse
|
||||
from twisted.trial import unittest
|
||||
from twisted.internet import defer
|
||||
from tests import util
|
||||
from tests.mocks import ExchangeRateManager as DummyExchangeRateManager
|
||||
from tests.mocks import BTCLBCFeed, USDBTCFeed
|
||||
from lbrynet.tests import util
|
||||
from lbrynet.tests.mocks import ExchangeRateManager as DummyExchangeRateManager
|
||||
from lbrynet.tests.mocks import BTCLBCFeed, USDBTCFeed
|
||||
|
||||
|
||||
class FeeFormatTest(unittest.TestCase):
|
||||
|
@ -84,7 +84,9 @@ class LBRYioFeedTest(unittest.TestCase):
|
|||
def test_handle_response(self):
|
||||
feed = ExchangeRateManager.LBRYioFeed()
|
||||
|
||||
response ='{\"data\": {\"fresh\": 0, \"lbc_usd\": 0.05863062523378918, \"lbc_btc\": 5.065289549855739e-05, \"btc_usd\": 1157.498}, \"success\": true, \"error\": null}'
|
||||
response = '{\"data\": {\"fresh\": 0, \"lbc_usd\": 0.05863062523378918, ' \
|
||||
'\"lbc_btc\": 5.065289549855739e-05, \"btc_usd\": 1157.498}, ' \
|
||||
'\"success\": true, \"error\": null}'
|
||||
out = yield feed._handle_response(response)
|
||||
expected = 1.0 / 5.065289549855739e-05
|
||||
self.assertEqual(expected, out)
|
||||
|
@ -103,7 +105,9 @@ class LBRYioBTCFeedTest(unittest.TestCase):
|
|||
def test_handle_response(self):
|
||||
feed = ExchangeRateManager.LBRYioBTCFeed()
|
||||
|
||||
response ='{\"data\": {\"fresh\": 0, \"lbc_usd\": 0.05863062523378918, \"lbc_btc\": 5.065289549855739e-05, \"btc_usd\": 1157.498}, \"success\": true, \"error\": null}'
|
||||
response = '{\"data\": {\"fresh\": 0, \"lbc_usd\": 0.05863062523378918, ' \
|
||||
'\"lbc_btc\": 5.065289549855739e-05, \"btc_usd\": 1157.498}, ' \
|
||||
'\"success\": true, \"error\": null}'
|
||||
out = yield feed._handle_response(response)
|
||||
expected = 1.0 / 1157.498
|
||||
self.assertEqual(expected, out)
|
2
setup.py
2
setup.py
|
@ -62,7 +62,7 @@ setup(
|
|||
long_description=long_description,
|
||||
keywords="lbry protocol media",
|
||||
license='MIT',
|
||||
packages=find_packages(base_dir, exclude=['tests']),
|
||||
packages=find_packages(base_dir),
|
||||
install_requires=requires,
|
||||
entry_points={'console_scripts': console_scripts},
|
||||
package_data={
|
||||
|
|
Loading…
Reference in a new issue