forked from LBRYCommunity/lbry-sdk
update tests
This commit is contained in:
parent
65ae1b3f08
commit
59f5381b0a
9 changed files with 157 additions and 250 deletions
|
@ -1,8 +1,9 @@
|
|||
from lbrynet.extras.daemon import analytics
|
||||
|
||||
from twisted.trial import unittest
|
||||
import unittest
|
||||
|
||||
|
||||
@unittest.SkipTest
|
||||
class TrackTest(unittest.TestCase):
|
||||
def test_empty_summarize_is_none(self):
|
||||
track = analytics.Manager(None, 'x', 'y', 'z')
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
import asyncio
|
||||
from unittest import TestCase
|
||||
import unittest
|
||||
from torba.testcase import AdvanceTimeTestCase
|
||||
|
||||
from tests import mocks
|
||||
from lbrynet.conf import Config
|
||||
from lbrynet.extras.daemon.ComponentManager import ComponentManager
|
||||
from lbrynet.extras.daemon.Components import DATABASE_COMPONENT, DHT_COMPONENT
|
||||
from lbrynet.extras.daemon.Components import HASH_ANNOUNCER_COMPONENT, REFLECTOR_COMPONENT, UPNP_COMPONENT
|
||||
from lbrynet.extras.daemon.Components import HASH_ANNOUNCER_COMPONENT, UPNP_COMPONENT
|
||||
from lbrynet.extras.daemon.Components import PEER_PROTOCOL_SERVER_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT
|
||||
from lbrynet.extras.daemon.Components import RATE_LIMITER_COMPONENT, HEADERS_COMPONENT, PAYMENT_RATE_COMPONENT
|
||||
from lbrynet.extras.daemon.Components import HEADERS_COMPONENT
|
||||
from lbrynet.extras.daemon import Components
|
||||
|
||||
|
||||
class TestComponentManager(TestCase):
|
||||
@unittest.SkipTest
|
||||
class TestComponentManager(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.default_components_sort = [
|
||||
[
|
||||
|
@ -60,7 +60,8 @@ class TestComponentManager(TestCase):
|
|||
self.component_manager.get_component("random_component")
|
||||
|
||||
|
||||
class TestComponentManagerOverrides(TestCase):
|
||||
@unittest.SkipTest
|
||||
class TestComponentManagerOverrides(unittest.TestCase):
|
||||
def test_init_with_overrides(self):
|
||||
class FakeWallet:
|
||||
component_name = "wallet"
|
||||
|
@ -88,8 +89,8 @@ class TestComponentManagerOverrides(TestCase):
|
|||
ComponentManager(Config(), randomComponent=FakeRandomComponent)
|
||||
|
||||
|
||||
@unittest.SkipTest
|
||||
class TestComponentManagerProperStart(AdvanceTimeTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.component_manager = ComponentManager(
|
||||
Config(),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from lbrynet import utils
|
||||
|
||||
from twisted.trial import unittest
|
||||
import unittest
|
||||
|
||||
|
||||
class CompareVersionTest(unittest.TestCase):
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
import asyncio
|
||||
import logging
|
||||
from copy import deepcopy
|
||||
from twisted.internet import defer
|
||||
from twisted.trial import unittest
|
||||
from lbrynet.conf import Config
|
||||
from lbrynet.extras.compat import f2d
|
||||
from lbrynet.extras.daemon.storage import SQLiteStorage, open_file_for_writing
|
||||
from lbrynet.blob.EncryptedFileDownloader import ManagedEncryptedFileDownloader
|
||||
from torba.testcase import AsyncioTestCase
|
||||
from lbrynet.blob.blob_info import BlobInfo
|
||||
from lbrynet.blob.blob_manager import BlobFileManager
|
||||
from lbrynet.stream.descriptor import StreamDescriptor
|
||||
from lbrynet.extras.daemon.storage import SQLiteStorage
|
||||
from tests.test_utils import random_lbry_hash
|
||||
|
||||
log = logging.getLogger()
|
||||
|
@ -66,103 +65,62 @@ fake_claim_info = {
|
|||
}
|
||||
|
||||
|
||||
class FakeAnnouncer:
|
||||
def __init__(self):
|
||||
self._queue_size = 0
|
||||
class StorageTest(AsyncioTestCase):
|
||||
async def asyncSetUp(self):
|
||||
self.storage = SQLiteStorage(':memory:')
|
||||
self.blob_dir = tempfile.mkdtemp()
|
||||
self.addCleanup(shutil.rmtree, self.blob_dir)
|
||||
self.blob_manager = BlobFileManager(asyncio.get_event_loop(), self.blob_dir, self.storage)
|
||||
await self.storage.open()
|
||||
|
||||
def hash_queue_size(self):
|
||||
return self._queue_size
|
||||
async def asyncTearDown(self):
|
||||
await self.storage.close()
|
||||
|
||||
async def store_fake_blob(self, blob_hash, length=100):
|
||||
await self.storage.add_known_blob(blob_hash, length)
|
||||
await self.storage.add_completed_blob(blob_hash)
|
||||
|
||||
class MocSession:
|
||||
def __init__(self, storage):
|
||||
self.storage = storage
|
||||
async def store_fake_stream(self, stream_hash, blobs=None, file_name="fake_file", key="DEADBEEF"):
|
||||
blobs = blobs or [BlobInfo(1, 100, "DEADBEEF", random_lbry_hash())]
|
||||
descriptor = StreamDescriptor(
|
||||
asyncio.get_event_loop(), self.blob_dir, file_name, key, file_name, blobs, stream_hash
|
||||
)
|
||||
sd_blob = await descriptor.make_sd_blob()
|
||||
await self.storage.store_stream(sd_blob, descriptor)
|
||||
return descriptor
|
||||
|
||||
|
||||
class StorageTest(unittest.TestCase):
|
||||
maxDiff = 5000
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def setUp(self):
|
||||
self.db_dir = tempfile.mkdtemp()
|
||||
self.storage = SQLiteStorage(Config(data_dir=self.db_dir), ':memory:')
|
||||
yield f2d(self.storage.open())
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def tearDown(self):
|
||||
yield f2d(self.storage.close())
|
||||
shutil.rmtree(self.db_dir)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def store_fake_blob(self, blob_hash, blob_length=100, next_announce=0, should_announce=0):
|
||||
yield f2d(self.storage.add_completed_blob(blob_hash, blob_length, next_announce,
|
||||
should_announce, "finished"))
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def store_fake_stream_blob(self, stream_hash, blob_hash, blob_num, length=100, iv="DEADBEEF"):
|
||||
blob_info = {
|
||||
'blob_hash': blob_hash, 'blob_num': blob_num, 'iv': iv
|
||||
}
|
||||
if length:
|
||||
blob_info['length'] = length
|
||||
yield f2d(self.storage.add_blobs_to_stream(stream_hash, [blob_info]))
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def store_fake_stream(self, stream_hash, sd_hash, file_name="fake_file", key="DEADBEEF",
|
||||
blobs=[]):
|
||||
yield f2d(self.storage.store_stream(stream_hash, sd_hash, file_name, key,
|
||||
file_name, blobs))
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def make_and_store_fake_stream(self, blob_count=2, stream_hash=None, sd_hash=None):
|
||||
async def make_and_store_fake_stream(self, blob_count=2, stream_hash=None):
|
||||
stream_hash = stream_hash or random_lbry_hash()
|
||||
sd_hash = sd_hash or random_lbry_hash()
|
||||
blobs = {
|
||||
i + 1: random_lbry_hash() for i in range(blob_count)
|
||||
}
|
||||
|
||||
yield self.store_fake_blob(sd_hash)
|
||||
|
||||
for blob in blobs.values():
|
||||
yield self.store_fake_blob(blob)
|
||||
|
||||
yield self.store_fake_stream(stream_hash, sd_hash)
|
||||
|
||||
for pos, blob in sorted(blobs.items(), key=lambda x: x[0]):
|
||||
yield self.store_fake_stream_blob(stream_hash, blob, pos)
|
||||
blobs = [
|
||||
BlobInfo(i + 1, 100, "DEADBEEF", random_lbry_hash())
|
||||
for i in range(blob_count)
|
||||
]
|
||||
await self.store_fake_stream(stream_hash, blobs)
|
||||
|
||||
|
||||
class TestSetup(StorageTest):
|
||||
@defer.inlineCallbacks
|
||||
def test_setup(self):
|
||||
files = yield f2d(self.storage.get_all_lbry_files())
|
||||
class TestSQLiteStorage(StorageTest):
|
||||
async def test_setup(self):
|
||||
files = await self.storage.get_all_lbry_files()
|
||||
self.assertEqual(len(files), 0)
|
||||
blobs = yield f2d(self.storage.get_all_blob_hashes())
|
||||
blobs = await self.storage.get_all_blob_hashes()
|
||||
self.assertEqual(len(blobs), 0)
|
||||
|
||||
|
||||
class BlobStorageTests(StorageTest):
|
||||
@defer.inlineCallbacks
|
||||
def test_store_blob(self):
|
||||
async def test_store_blob(self):
|
||||
blob_hash = random_lbry_hash()
|
||||
yield self.store_fake_blob(blob_hash)
|
||||
blob_hashes = yield f2d(self.storage.get_all_blob_hashes())
|
||||
await self.store_fake_blob(blob_hash)
|
||||
blob_hashes = await self.storage.get_all_blob_hashes()
|
||||
self.assertEqual(blob_hashes, [blob_hash])
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_delete_blob(self):
|
||||
async def test_delete_blob(self):
|
||||
blob_hash = random_lbry_hash()
|
||||
yield self.store_fake_blob(blob_hash)
|
||||
blob_hashes = yield f2d(self.storage.get_all_blob_hashes())
|
||||
await self.store_fake_blob(blob_hash)
|
||||
blob_hashes = await self.storage.get_all_blob_hashes()
|
||||
self.assertEqual(blob_hashes, [blob_hash])
|
||||
yield f2d(self.storage.delete_blobs_from_db(blob_hashes))
|
||||
blob_hashes = yield f2d(self.storage.get_all_blob_hashes())
|
||||
await self.storage.delete_blobs_from_db(blob_hashes)
|
||||
blob_hashes = await self.storage.get_all_blob_hashes()
|
||||
self.assertEqual(blob_hashes, [])
|
||||
|
||||
|
||||
class SupportsStorageTests(StorageTest):
|
||||
@defer.inlineCallbacks
|
||||
def test_supports_storage(self):
|
||||
async def test_supports_storage(self):
|
||||
claim_ids = [random_lbry_hash() for _ in range(10)]
|
||||
random_supports = [{
|
||||
"txid": random_lbry_hash(),
|
||||
|
@ -172,83 +130,38 @@ class SupportsStorageTests(StorageTest):
|
|||
} for i in range(20)]
|
||||
expected_supports = {}
|
||||
for idx, claim_id in enumerate(claim_ids):
|
||||
yield f2d(self.storage.save_supports(claim_id, random_supports[idx*2:idx*2+2]))
|
||||
await self.storage.save_supports(claim_id, random_supports[idx*2:idx*2+2])
|
||||
for random_support in random_supports[idx*2:idx*2+2]:
|
||||
random_support['claim_id'] = claim_id
|
||||
expected_supports.setdefault(claim_id, []).append(random_support)
|
||||
supports = yield f2d(self.storage.get_supports(claim_ids[0]))
|
||||
|
||||
supports = await self.storage.get_supports(claim_ids[0])
|
||||
self.assertEqual(supports, expected_supports[claim_ids[0]])
|
||||
all_supports = yield f2d(self.storage.get_supports(*claim_ids))
|
||||
all_supports = await self.storage.get_supports(*claim_ids)
|
||||
for support in all_supports:
|
||||
self.assertIn(support, expected_supports[support['claim_id']])
|
||||
|
||||
|
||||
class StreamStorageTests(StorageTest):
|
||||
@defer.inlineCallbacks
|
||||
def test_store_stream(self, stream_hash=None):
|
||||
stream_hash = stream_hash or random_lbry_hash()
|
||||
sd_hash = random_lbry_hash()
|
||||
blob1 = random_lbry_hash()
|
||||
blob2 = random_lbry_hash()
|
||||
|
||||
yield self.store_fake_blob(sd_hash)
|
||||
yield self.store_fake_blob(blob1)
|
||||
yield self.store_fake_blob(blob2)
|
||||
|
||||
yield self.store_fake_stream(stream_hash, sd_hash)
|
||||
yield self.store_fake_stream_blob(stream_hash, blob1, 1)
|
||||
yield self.store_fake_stream_blob(stream_hash, blob2, 2)
|
||||
|
||||
stream_blobs = yield f2d(self.storage.get_blobs_for_stream(stream_hash))
|
||||
stream_blob_hashes = [b.blob_hash for b in stream_blobs]
|
||||
self.assertListEqual(stream_blob_hashes, [blob1, blob2])
|
||||
|
||||
blob_hashes = yield f2d(self.storage.get_all_blob_hashes())
|
||||
self.assertSetEqual(set(blob_hashes), {sd_hash, blob1, blob2})
|
||||
|
||||
stream_blobs = yield f2d(self.storage.get_blobs_for_stream(stream_hash))
|
||||
stream_blob_hashes = [b.blob_hash for b in stream_blobs]
|
||||
self.assertListEqual(stream_blob_hashes, [blob1, blob2])
|
||||
|
||||
yield f2d(self.storage.set_should_announce(sd_hash, 1, 1))
|
||||
yield f2d(self.storage.set_should_announce(blob1, 1, 1))
|
||||
|
||||
should_announce_count = yield f2d(self.storage.count_should_announce_blobs())
|
||||
self.assertEqual(should_announce_count, 2)
|
||||
should_announce_hashes = yield f2d(self.storage.get_blobs_to_announce())
|
||||
self.assertSetEqual(set(should_announce_hashes), {sd_hash, blob1})
|
||||
|
||||
stream_hashes = yield f2d(self.storage.get_all_streams())
|
||||
self.assertListEqual(stream_hashes, [stream_hash])
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_delete_stream(self):
|
||||
async def test_store_and_delete_stream(self):
|
||||
stream_hash = random_lbry_hash()
|
||||
yield self.test_store_stream(stream_hash)
|
||||
yield f2d(self.storage.delete_stream(stream_hash))
|
||||
stream_hashes = yield f2d(self.storage.get_all_streams())
|
||||
descriptor = await self.store_fake_stream(stream_hash)
|
||||
files = await self.storage.get_all_lbry_files()
|
||||
self.assertListEqual(files, [])
|
||||
stream_hashes = await self.storage.get_all_stream_hashes()
|
||||
self.assertListEqual(stream_hashes, [stream_hash])
|
||||
await self.storage.delete_stream(descriptor)
|
||||
files = await self.storage.get_all_lbry_files()
|
||||
self.assertListEqual(files, [])
|
||||
stream_hashes = await self.storage.get_all_stream_hashes()
|
||||
self.assertListEqual(stream_hashes, [])
|
||||
|
||||
stream_blobs = yield f2d(self.storage.get_blobs_for_stream(stream_hash))
|
||||
self.assertListEqual(stream_blobs, [])
|
||||
blob_hashes = yield f2d(self.storage.get_all_blob_hashes())
|
||||
self.assertListEqual(blob_hashes, [])
|
||||
|
||||
|
||||
@unittest.SkipTest
|
||||
class FileStorageTests(StorageTest):
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_setup_output(self):
|
||||
file_name = 'encrypted_file_saver_test.tmp'
|
||||
self.assertFalse(os.path.isfile(file_name))
|
||||
written_to = yield f2d(open_file_for_writing(self.db_dir, file_name))
|
||||
self.assertEqual(written_to, file_name)
|
||||
self.assertTrue(os.path.isfile(os.path.join(self.db_dir, file_name)))
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_store_file(self):
|
||||
async def test_store_file(self):
|
||||
download_directory = self.db_dir
|
||||
out = yield f2d(self.storage.get_all_lbry_files())
|
||||
out = await self.storage.get_all_lbry_files()
|
||||
self.assertEqual(len(out), 0)
|
||||
|
||||
stream_hash = random_lbry_hash()
|
||||
|
@ -256,40 +169,29 @@ class FileStorageTests(StorageTest):
|
|||
blob1 = random_lbry_hash()
|
||||
blob2 = random_lbry_hash()
|
||||
|
||||
yield self.store_fake_blob(sd_hash)
|
||||
yield self.store_fake_blob(blob1)
|
||||
yield self.store_fake_blob(blob2)
|
||||
await self.store_fake_blob(sd_hash)
|
||||
await self.store_fake_blob(blob1)
|
||||
await self.store_fake_blob(blob2)
|
||||
|
||||
yield self.store_fake_stream(stream_hash, sd_hash)
|
||||
yield self.store_fake_stream_blob(stream_hash, blob1, 1)
|
||||
yield self.store_fake_stream_blob(stream_hash, blob2, 2)
|
||||
await self.store_fake_stream(stream_hash, sd_hash)
|
||||
await self.store_fake_stream_blob(stream_hash, blob1, 1)
|
||||
await self.store_fake_stream_blob(stream_hash, blob2, 2)
|
||||
|
||||
blob_data_rate = 0
|
||||
file_name = "test file"
|
||||
out = yield f2d(self.storage.save_published_file(
|
||||
await self.storage.save_published_file(
|
||||
stream_hash, file_name, download_directory, blob_data_rate
|
||||
))
|
||||
rowid = yield f2d(self.storage.get_rowid_for_stream_hash(stream_hash))
|
||||
self.assertEqual(out, rowid)
|
||||
)
|
||||
|
||||
files = yield f2d(self.storage.get_all_lbry_files())
|
||||
files = await self.storage.get_all_lbry_files()
|
||||
self.assertEqual(1, len(files))
|
||||
|
||||
status = yield f2d(self.storage.get_lbry_file_status(rowid))
|
||||
self.assertEqual(status, ManagedEncryptedFileDownloader.STATUS_STOPPED)
|
||||
|
||||
running = ManagedEncryptedFileDownloader.STATUS_RUNNING
|
||||
yield f2d(self.storage.change_file_status(rowid, running))
|
||||
status = yield f2d(self.storage.get_lbry_file_status(rowid))
|
||||
self.assertEqual(status, ManagedEncryptedFileDownloader.STATUS_RUNNING)
|
||||
|
||||
|
||||
@unittest.SkipTest
|
||||
class ContentClaimStorageTests(StorageTest):
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_store_content_claim(self):
|
||||
async def test_store_content_claim(self):
|
||||
download_directory = self.db_dir
|
||||
out = yield f2d(self.storage.get_all_lbry_files())
|
||||
out = await self.storage.get_all_lbry_files()
|
||||
self.assertEqual(len(out), 0)
|
||||
|
||||
stream_hash = random_lbry_hash()
|
||||
|
@ -299,35 +201,35 @@ class ContentClaimStorageTests(StorageTest):
|
|||
# use the generated sd hash in the fake claim
|
||||
fake_outpoint = "%s:%i" % (fake_claim_info['txid'], fake_claim_info['nout'])
|
||||
|
||||
yield self.make_and_store_fake_stream(blob_count=2, stream_hash=stream_hash, sd_hash=sd_hash)
|
||||
await self.make_and_store_fake_stream(blob_count=2, stream_hash=stream_hash, sd_hash=sd_hash)
|
||||
blob_data_rate = 0
|
||||
file_name = "test file"
|
||||
yield f2d(self.storage.save_published_file(
|
||||
await self.storage.save_published_file(
|
||||
stream_hash, file_name, download_directory, blob_data_rate
|
||||
))
|
||||
yield f2d(self.storage.save_claims([fake_claim_info]))
|
||||
yield f2d(self.storage.save_content_claim(stream_hash, fake_outpoint))
|
||||
stored_content_claim = yield f2d(self.storage.get_content_claim(stream_hash))
|
||||
)
|
||||
await self.storage.save_claims([fake_claim_info])
|
||||
await self.storage.save_content_claim(stream_hash, fake_outpoint)
|
||||
stored_content_claim = await self.storage.get_content_claim(stream_hash)
|
||||
self.assertDictEqual(stored_content_claim, fake_claim_info)
|
||||
|
||||
stream_hashes = yield f2d(self.storage.get_old_stream_hashes_for_claim_id(fake_claim_info['claim_id'],
|
||||
stream_hash))
|
||||
stream_hashes = await self.storage.get_old_stream_hashes_for_claim_id(fake_claim_info['claim_id'],
|
||||
stream_hash)
|
||||
self.assertListEqual(stream_hashes, [])
|
||||
|
||||
# test that we can't associate a claim update with a new stream to the file
|
||||
second_stream_hash, second_sd_hash = random_lbry_hash(), random_lbry_hash()
|
||||
yield self.make_and_store_fake_stream(blob_count=2, stream_hash=second_stream_hash, sd_hash=second_sd_hash)
|
||||
await self.make_and_store_fake_stream(blob_count=2, stream_hash=second_stream_hash, sd_hash=second_sd_hash)
|
||||
with self.assertRaisesRegex(Exception, "stream mismatch"):
|
||||
yield f2d(self.storage.save_content_claim(second_stream_hash, fake_outpoint))
|
||||
await self.storage.save_content_claim(second_stream_hash, fake_outpoint)
|
||||
|
||||
# test that we can associate a new claim update containing the same stream to the file
|
||||
update_info = deepcopy(fake_claim_info)
|
||||
update_info['txid'] = "beef0000" * 12
|
||||
update_info['nout'] = 0
|
||||
second_outpoint = "%s:%i" % (update_info['txid'], update_info['nout'])
|
||||
yield f2d(self.storage.save_claims([update_info]))
|
||||
yield f2d(self.storage.save_content_claim(stream_hash, second_outpoint))
|
||||
update_info_result = yield f2d(self.storage.get_content_claim(stream_hash))
|
||||
await self.storage.save_claims([update_info])
|
||||
await self.storage.save_content_claim(stream_hash, second_outpoint)
|
||||
update_info_result = await self.storage.get_content_claim(stream_hash)
|
||||
self.assertDictEqual(update_info_result, update_info)
|
||||
|
||||
# test that we can't associate an update with a mismatching claim id
|
||||
|
@ -339,8 +241,8 @@ class ContentClaimStorageTests(StorageTest):
|
|||
with self.assertRaisesRegex(Exception, "mismatching claim ids when updating stream "
|
||||
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeef "
|
||||
"vs beef0002beef0002beef0002beef0002beef0002"):
|
||||
yield f2d(self.storage.save_claims([invalid_update_info]))
|
||||
yield f2d(self.storage.save_content_claim(stream_hash, invalid_update_outpoint))
|
||||
current_claim_info = yield f2d(self.storage.get_content_claim(stream_hash))
|
||||
await self.storage.save_claims([invalid_update_info])
|
||||
await self.storage.save_content_claim(stream_hash, invalid_update_outpoint)
|
||||
current_claim_info = await self.storage.get_content_claim(stream_hash)
|
||||
# this should still be the previous update
|
||||
self.assertDictEqual(current_claim_info, update_info)
|
||||
|
|
|
@ -1,30 +1,24 @@
|
|||
from unittest import mock
|
||||
import unittest
|
||||
import mock
|
||||
import json
|
||||
|
||||
from twisted.internet import defer
|
||||
from twisted.trial import unittest
|
||||
|
||||
from lbrynet.extras.compat import f2d
|
||||
from lbrynet.conf import Config
|
||||
from lbrynet.schema.decode import smart_decode
|
||||
from lbrynet.extras.daemon.storage import SQLiteStorage
|
||||
from lbrynet.extras.daemon.ComponentManager import ComponentManager
|
||||
from lbrynet.extras.daemon.Components import DATABASE_COMPONENT, DHT_COMPONENT, WALLET_COMPONENT
|
||||
from lbrynet.extras.daemon.Components import HASH_ANNOUNCER_COMPONENT, REFLECTOR_COMPONENT
|
||||
from lbrynet.extras.daemon.Components import HASH_ANNOUNCER_COMPONENT
|
||||
from lbrynet.extras.daemon.Components import UPNP_COMPONENT, BLOB_COMPONENT
|
||||
from lbrynet.extras.daemon.Components import PEER_PROTOCOL_SERVER_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT
|
||||
from lbrynet.extras.daemon.Components import RATE_LIMITER_COMPONENT, HEADERS_COMPONENT, FILE_MANAGER_COMPONENT
|
||||
from lbrynet.extras.daemon.Components import HEADERS_COMPONENT, STREAM_MANAGER_COMPONENT
|
||||
from lbrynet.extras.daemon.Daemon import Daemon as LBRYDaemon
|
||||
from lbrynet.blob.EncryptedFileDownloader import ManagedEncryptedFileDownloader
|
||||
from lbrynet.blob.EncryptedFileStatusReport import EncryptedFileStatusReport
|
||||
from lbrynet.extras.wallet import LbryWalletManager
|
||||
from torba.client.wallet import Wallet
|
||||
|
||||
from lbrynet.conf import Config
|
||||
from lbrynet.p2p.PaymentRateManager import OnlyFreePaymentsManager
|
||||
from tests import test_utils
|
||||
from tests.mocks import FakeNetwork, FakeFileManager
|
||||
from tests.mocks import ExchangeRateManager as DummyExchangeRateManager
|
||||
from tests.mocks import BTCLBCFeed, USDBTCFeed
|
||||
# from tests.mocks import mock_conf_settings, FakeNetwork, FakeFileManager
|
||||
# from tests.mocks import ExchangeRateManager as DummyExchangeRateManager
|
||||
# from tests.mocks import BTCLBCFeed, USDBTCFeed
|
||||
from tests.test_utils import is_android
|
||||
|
||||
|
||||
|
@ -51,7 +45,7 @@ def get_test_daemon(conf: Config, with_fee=False):
|
|||
daemon.storage = mock.Mock(spec=SQLiteStorage)
|
||||
market_feeds = [BTCLBCFeed(), USDBTCFeed()]
|
||||
daemon.exchange_rate_manager = DummyExchangeRateManager(market_feeds, rates)
|
||||
daemon.file_manager = component_manager.get_component(FILE_MANAGER_COMPONENT)
|
||||
daemon.stream_manager = component_manager.get_component(FILE_MANAGER_COMPONENT)
|
||||
|
||||
metadata = {
|
||||
"author": "fake author",
|
||||
|
@ -78,12 +72,11 @@ def get_test_daemon(conf: Config, with_fee=False):
|
|||
return daemon
|
||||
|
||||
|
||||
@unittest.SkipTest
|
||||
class TestCostEst(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
test_utils.reset_time(self)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_fee_and_generous_data(self):
|
||||
size = 10000000
|
||||
correct_result = 4.5
|
||||
|
@ -91,7 +84,6 @@ class TestCostEst(unittest.TestCase):
|
|||
result = yield f2d(daemon.get_est_cost("test", size))
|
||||
self.assertEqual(result, correct_result)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_fee_and_ungenerous_data(self):
|
||||
conf = Config(is_generous_host=False)
|
||||
size = 10000000
|
||||
|
@ -101,7 +93,6 @@ class TestCostEst(unittest.TestCase):
|
|||
result = yield f2d(daemon.get_est_cost("test", size))
|
||||
self.assertEqual(result, round(correct_result, 1))
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_generous_data_and_no_fee(self):
|
||||
size = 10000000
|
||||
correct_result = 0.0
|
||||
|
@ -109,7 +100,6 @@ class TestCostEst(unittest.TestCase):
|
|||
result = yield f2d(daemon.get_est_cost("test", size))
|
||||
self.assertEqual(result, correct_result)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_ungenerous_data_and_no_fee(self):
|
||||
conf = Config(is_generous_host=False)
|
||||
size = 10000000
|
||||
|
@ -119,8 +109,8 @@ class TestCostEst(unittest.TestCase):
|
|||
self.assertEqual(result, round(correct_result, 1))
|
||||
|
||||
|
||||
@unittest.SkipTest
|
||||
class TestJsonRpc(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
def noop():
|
||||
return None
|
||||
|
@ -129,7 +119,6 @@ class TestJsonRpc(unittest.TestCase):
|
|||
self.test_daemon = get_test_daemon(Config())
|
||||
self.test_daemon.wallet_manager.get_best_blockhash = noop
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_status(self):
|
||||
status = yield f2d(self.test_daemon.jsonrpc_status())
|
||||
self.assertDictContainsSubset({'is_running': False}, status)
|
||||
|
@ -142,8 +131,8 @@ class TestJsonRpc(unittest.TestCase):
|
|||
test_help.skip = "Test cannot pass on Android because PYTHONOPTIMIZE removes the docstrings."
|
||||
|
||||
|
||||
@unittest.SkipTest
|
||||
class TestFileListSorting(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
test_utils.reset_time(self)
|
||||
self.test_daemon = get_test_daemon(Config())
|
||||
|
@ -162,43 +151,36 @@ class TestFileListSorting(unittest.TestCase):
|
|||
]
|
||||
return f2d(self.test_daemon.component_manager.setup())
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_sort_by_points_paid_no_direction_specified(self):
|
||||
sort_options = ['points_paid']
|
||||
file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options))
|
||||
self.assertEqual(self.test_points_paid, [f['points_paid'] for f in file_list])
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_sort_by_points_paid_ascending(self):
|
||||
sort_options = ['points_paid,asc']
|
||||
file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options))
|
||||
self.assertEqual(self.test_points_paid, [f['points_paid'] for f in file_list])
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_sort_by_points_paid_descending(self):
|
||||
sort_options = ['points_paid, desc']
|
||||
file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options))
|
||||
self.assertEqual(list(reversed(self.test_points_paid)), [f['points_paid'] for f in file_list])
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_sort_by_file_name_no_direction_specified(self):
|
||||
sort_options = ['file_name']
|
||||
file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options))
|
||||
self.assertEqual(self.test_file_names, [f['file_name'] for f in file_list])
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_sort_by_file_name_ascending(self):
|
||||
sort_options = ['file_name,\nasc']
|
||||
file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options))
|
||||
self.assertEqual(self.test_file_names, [f['file_name'] for f in file_list])
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_sort_by_file_name_descending(self):
|
||||
sort_options = ['\tfile_name,\n\tdesc']
|
||||
file_list = yield f2d(self.test_daemon.jsonrpc_file_list(sort=sort_options))
|
||||
self.assertEqual(list(reversed(self.test_file_names)), [f['file_name'] for f in file_list])
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_sort_by_multiple_criteria(self):
|
||||
expected = [
|
||||
'file_name=different.json, points_paid=9.1',
|
||||
|
@ -232,7 +214,6 @@ class TestFileListSorting(unittest.TestCase):
|
|||
file_list = yield f2d(self.test_daemon.jsonrpc_file_list())
|
||||
self.assertNotEqual(expected, [format_result(r) for r in file_list])
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_sort_by_nested_field(self):
|
||||
extract_authors = lambda file_list: [f['metadata']['author'] for f in file_list]
|
||||
|
||||
|
@ -249,7 +230,6 @@ class TestFileListSorting(unittest.TestCase):
|
|||
file_list = yield f2d(self.test_daemon.jsonrpc_file_list())
|
||||
self.assertNotEqual(self.test_authors, extract_authors(file_list))
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_invalid_sort_produces_meaningful_errors(self):
|
||||
sort_options = ['meta.author']
|
||||
expected_message = "Failed to get 'meta.author', key 'meta' was not found."
|
||||
|
|
|
@ -1,10 +1,38 @@
|
|||
import unittest
|
||||
from lbrynet.schema.fee import Fee
|
||||
from lbrynet.extras.daemon import exchange_rate_manager
|
||||
from lbrynet.p2p.Error import InvalidExchangeRateResponse
|
||||
from lbrynet.error import InvalidExchangeRateResponse
|
||||
from tests import test_utils
|
||||
from tests.mocks import ExchangeRateManager as DummyExchangeRateManager
|
||||
from tests.mocks import BTCLBCFeed, USDBTCFeed
|
||||
|
||||
|
||||
class BTCLBCFeed(exchange_rate_manager.MarketFeed):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
"BTCLBC",
|
||||
"market name",
|
||||
"derp.com",
|
||||
None,
|
||||
0.0
|
||||
)
|
||||
|
||||
|
||||
class USDBTCFeed(exchange_rate_manager.MarketFeed):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
"USDBTC",
|
||||
"market name",
|
||||
"derp.com",
|
||||
None,
|
||||
0.0
|
||||
)
|
||||
|
||||
|
||||
class DummyExchangeRateManager(exchange_rate_manager.ExchangeRateManager):
|
||||
def __init__(self, market_feeds, rates):
|
||||
self.market_feeds = market_feeds
|
||||
for feed in self.market_feeds:
|
||||
feed.rate = exchange_rate_manager.ExchangeRate(
|
||||
feed.market, rates[feed.market]['spot'], rates[feed.market]['ts'])
|
||||
|
||||
|
||||
class FeeFormatTest(unittest.TestCase):
|
||||
|
@ -91,11 +119,11 @@ class LBRYioFeedTest(unittest.TestCase):
|
|||
|
||||
response = '{}'
|
||||
with self.assertRaises(InvalidExchangeRateResponse):
|
||||
out = feed._handle_response(response)
|
||||
feed._handle_response(response)
|
||||
|
||||
response = '{"success":true,"result":[]}'
|
||||
with self.assertRaises(InvalidExchangeRateResponse):
|
||||
out = feed._handle_response(response)
|
||||
feed._handle_response(response)
|
||||
|
||||
|
||||
class TestExchangeRateFeeds(unittest.TestCase):
|
||||
|
@ -129,11 +157,11 @@ class TestExchangeRateFeeds(unittest.TestCase):
|
|||
|
||||
response = '{}'
|
||||
with self.assertRaises(InvalidExchangeRateResponse):
|
||||
out = feed._handle_response(response)
|
||||
feed._handle_response(response)
|
||||
|
||||
response = '{"success":true,"ticker":{}}'
|
||||
with self.assertRaises(InvalidExchangeRateResponse):
|
||||
out = feed._handle_response(response)
|
||||
feed._handle_response(response)
|
||||
|
||||
def test_handle_cryptonator_btc_response(self):
|
||||
feed = exchange_rate_manager.CryptonatorBTCFeed()
|
||||
|
@ -147,11 +175,11 @@ class TestExchangeRateFeeds(unittest.TestCase):
|
|||
|
||||
response = '{}'
|
||||
with self.assertRaises(InvalidExchangeRateResponse):
|
||||
out = feed._handle_response(response)
|
||||
feed._handle_response(response)
|
||||
|
||||
response = '{"success":true,"ticker":{}}'
|
||||
with self.assertRaises(InvalidExchangeRateResponse):
|
||||
out = feed._handle_response(response)
|
||||
feed._handle_response(response)
|
||||
|
||||
def test_handle_bittrex_response(self):
|
||||
feed = exchange_rate_manager.BittrexFeed()
|
||||
|
@ -167,8 +195,8 @@ class TestExchangeRateFeeds(unittest.TestCase):
|
|||
|
||||
response = '{}'
|
||||
with self.assertRaises(InvalidExchangeRateResponse):
|
||||
out = feed._handle_response(response)
|
||||
feed._handle_response(response)
|
||||
|
||||
response = '{"success":true,"result":[]}'
|
||||
with self.assertRaises(InvalidExchangeRateResponse):
|
||||
out = feed._handle_response(response)
|
||||
feed._handle_response(response)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from twisted.trial import unittest
|
||||
import unittest
|
||||
|
||||
from lbrynet.extras.daemon.Daemon import sort_claim_results
|
||||
|
||||
|
@ -35,9 +35,5 @@ class ClaimsComparatorTest(unittest.TestCase):
|
|||
self.run_test(results, 'nout', [1, 2, 3])
|
||||
|
||||
def run_test(self, results, field, expected):
|
||||
actual = sort_claim_results(results)
|
||||
self.assertEqual(expected, [r[field] for r in actual])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
sort_claim_results(results)
|
||||
self.assertListEqual(expected, [r[field] for r in results])
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import docopt
|
||||
from twisted.trial import unittest
|
||||
import unittest
|
||||
from lbrynet.extras.daemon.Daemon import Daemon
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ import contextlib
|
|||
from io import StringIO
|
||||
import unittest
|
||||
|
||||
from docopt import DocoptExit
|
||||
from lbrynet.extras.cli import normalize_value, main
|
||||
from lbrynet.extras.system_info import get_platform
|
||||
|
||||
|
|
Loading…
Reference in a new issue