testing get

This commit is contained in:
Lex Berezhny 2019-02-11 23:54:24 -05:00
parent e6b6a3f55e
commit 5e509c9fd6
3 changed files with 80 additions and 9 deletions

View file

@ -629,7 +629,7 @@ class ExchangeRateManagerComponent(Component):
component_name = EXCHANGE_RATE_MANAGER_COMPONENT component_name = EXCHANGE_RATE_MANAGER_COMPONENT
def __init__(self, component_manager): def __init__(self, component_manager):
Component.__init__(self, component_manager) super().__init__(component_manager)
self.exchange_rate_manager = ExchangeRateManager() self.exchange_rate_manager = ExchangeRateManager()
@property @property

View file

@ -0,0 +1,23 @@
import logging
from integration.testcase import CommandTestCase
class FileCommands(CommandTestCase):
VERBOSITY = logging.INFO
async def test_file_management(self):
await self.make_claim('foo', '0.01')
await self.make_claim('foo2', '0.01')
file1, file2 = self.daemon.jsonrpc_file_list()
self.assertEqual(file1['claim_name'], 'foo')
self.assertEqual(file2['claim_name'], 'foo2')
await self.daemon.jsonrpc_file_delete(claim_name='foo')
self.assertEqual(len(self.daemon.jsonrpc_file_list()), 1)
await self.daemon.jsonrpc_file_delete(claim_name='foo2')
self.assertEqual(len(self.daemon.jsonrpc_file_list()), 0)
await self.daemon.jsonrpc_get('lbry://foo')
self.assertEqual(len(self.daemon.jsonrpc_file_list()), 1)

View file

@ -1,11 +1,10 @@
import json import json
import shutil
import tempfile import tempfile
import logging import logging
from binascii import unhexlify from binascii import unhexlify
import lbrynet.extras.wallet import lbrynet.extras.wallet
from lbrynet.extras.wallet.transaction import Transaction
from lbrynet.error import InsufficientFundsError
from lbrynet.schema.claim import ClaimDict from lbrynet.schema.claim import ClaimDict
from torba.testcase import IntegrationTestCase from torba.testcase import IntegrationTestCase
@ -16,12 +15,48 @@ lbrynet.schema.BLOCKCHAIN_NAME = 'lbrycrd_regtest'
from lbrynet.conf import Config from lbrynet.conf import Config
from lbrynet.extras.daemon.Daemon import Daemon, jsonrpc_dumps_pretty from lbrynet.extras.daemon.Daemon import Daemon, jsonrpc_dumps_pretty
from lbrynet.extras.wallet import LbryWalletManager from lbrynet.extras.wallet import LbryWalletManager
from lbrynet.extras.daemon.Components import WalletComponent from lbrynet.extras.daemon.Components import Component, WalletComponent
from lbrynet.extras.daemon.Components import ( from lbrynet.extras.daemon.Components import (
DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT, DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT,
UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT
) )
from lbrynet.extras.daemon.ComponentManager import ComponentManager from lbrynet.extras.daemon.ComponentManager import ComponentManager
from lbrynet.extras.daemon.storage import SQLiteStorage
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.stream.reflector.server import ReflectorServer
class ExchangeRateManager:
def start(self):
pass
def stop(self):
pass
def convert_currency(self, from_currency, to_currency, amount):
return amount
def fee_dict(self):
return {}
class ExchangeRateManagerComponent(Component):
component_name = EXCHANGE_RATE_MANAGER_COMPONENT
def __init__(self, component_manager):
super().__init__(component_manager)
self.exchange_rate_manager = ExchangeRateManager()
@property
def component(self) -> ExchangeRateManager:
return self.exchange_rate_manager
async def start(self):
self.exchange_rate_manager.start()
async def stop(self):
self.exchange_rate_manager.stop()
class CommandTestCase(IntegrationTestCase): class CommandTestCase(IntegrationTestCase):
@ -36,6 +71,7 @@ class CommandTestCase(IntegrationTestCase):
logging.getLogger('lbrynet.blob_exchange').setLevel(self.VERBOSITY) logging.getLogger('lbrynet.blob_exchange').setLevel(self.VERBOSITY)
logging.getLogger('lbrynet.daemon').setLevel(self.VERBOSITY) logging.getLogger('lbrynet.daemon').setLevel(self.VERBOSITY)
logging.getLogger('lbrynet.stream').setLevel(self.VERBOSITY)
conf = Config() conf = Config()
conf.data_dir = self.wallet_node.data_path conf.data_dir = self.wallet_node.data_path
@ -43,10 +79,10 @@ class CommandTestCase(IntegrationTestCase):
conf.download_dir = self.wallet_node.data_path conf.download_dir = self.wallet_node.data_path
conf.share_usage_data = False conf.share_usage_data = False
conf.use_upnp = False conf.use_upnp = False
conf.reflect_streams = False conf.reflect_streams = True
conf.blockchain_name = 'lbrycrd_regtest' conf.blockchain_name = 'lbrycrd_regtest'
conf.lbryum_servers = [('localhost', 50001)] conf.lbryum_servers = [('127.0.0.1', 50001)]
conf.reflector_servers = [] conf.reflector_servers = [('127.0.0.1', 5566)]
conf.known_dht_nodes = [] conf.known_dht_nodes = []
await self.account.ensure_address_gap() await self.account.ensure_address_gap()
@ -63,14 +99,26 @@ class CommandTestCase(IntegrationTestCase):
conf.components_to_skip = [ conf.components_to_skip = [
DHT_COMPONENT, UPNP_COMPONENT, HASH_ANNOUNCER_COMPONENT, DHT_COMPONENT, UPNP_COMPONENT, HASH_ANNOUNCER_COMPONENT,
PEER_PROTOCOL_SERVER_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT PEER_PROTOCOL_SERVER_COMPONENT
] ]
self.daemon = Daemon(conf, ComponentManager( self.daemon = Daemon(conf, ComponentManager(
conf, skip_components=conf.components_to_skip, wallet=wallet_maker conf, skip_components=conf.components_to_skip, wallet=wallet_maker,
exchange_rate_manager=ExchangeRateManagerComponent
)) ))
await self.daemon.initialize() await self.daemon.initialize()
self.manager.old_db = self.daemon.storage self.manager.old_db = self.daemon.storage
server_tmp_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, server_tmp_dir)
self.server_storage = SQLiteStorage(Config(), ':memory:')
await self.server_storage.open()
self.server_blob_manager = BlobFileManager(self.loop, server_tmp_dir, self.server_storage)
self.reflector = ReflectorServer(self.server_blob_manager)
self.reflector.start_server(5566, '127.0.0.1')
await self.reflector.started_listening.wait()
self.addCleanup(self.reflector.stop_server)
async def asyncTearDown(self): async def asyncTearDown(self):
await super().asyncTearDown() await super().asyncTearDown()
self.wallet_component._running = False self.wallet_component._running = False