update tests and scripts

This commit is contained in:
Jack Robison 2017-09-27 17:47:50 -04:00
parent fa83a4f671
commit 81b584a35a
No known key found for this signature in database
GPG key ID: 284699E7404E3CFF
3 changed files with 46 additions and 52 deletions

View file

@ -59,7 +59,7 @@ def main(args=None):
use_upnp=False, use_upnp=False,
wallet=wallet wallet=wallet
) )
api = analytics.Api.new_instance() api = analytics.Api.new_instance(conf.settings['share_usage_data'])
run(args, session, api) run(args, session, api)
reactor.run() reactor.run()
finally: finally:

View file

@ -50,10 +50,10 @@ class BlobManagerTest(unittest.TestCase):
writer, finished_d = yield blob.open_for_writing(self.peer) writer, finished_d = yield blob.open_for_writing(self.peer)
yield writer.write(data) yield writer.write(data)
yield self.bm.blob_completed(blob) yield self.bm.blob_completed(blob)
yield self.bm.add_blob_to_upload_history(blob_hash,'test',len(data)) yield self.bm.add_blob_to_upload_history(blob_hash, 'test', len(data))
# check to see if blob is there # check to see if blob is there
self.assertTrue(os.path.isfile(os.path.join(self.blob_dir,blob_hash))) self.assertTrue(os.path.isfile(os.path.join(self.blob_dir, blob_hash)))
blobs = yield self.bm.get_all_verified_blobs() blobs = yield self.bm.get_all_verified_blobs()
self.assertTrue(blob_hash in blobs) self.assertTrue(blob_hash in blobs)
defer.returnValue(blob_hash) defer.returnValue(blob_hash)

View file

@ -1,26 +1,22 @@
import types import types
import mock import mock
import json
from twisted.trial import unittest from twisted.trial import unittest
from twisted.internet import defer, task from twisted.internet import defer, task
from lbryschema.claim import ClaimDict
from lbrynet.core import Session, PaymentRateManager, Wallet from lbrynet.core import Session, PaymentRateManager, Wallet
from lbrynet.core.Error import DownloadTimeoutError from lbrynet.core.Error import DownloadDataTimeout, DownloadSDTimeout
from lbrynet.daemon import Downloader from lbrynet.daemon import Downloader
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier,StreamMetadata from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier
from lbrynet.lbry_file.client.EncryptedFileOptions import add_lbry_file_to_sd_identifier
from lbrynet.file_manager.EncryptedFileStatusReport import EncryptedFileStatusReport from lbrynet.file_manager.EncryptedFileStatusReport import EncryptedFileStatusReport
from lbrynet.file_manager.EncryptedFileDownloader import ManagedEncryptedFileDownloader, ManagedEncryptedFileDownloaderFactory from lbrynet.file_manager.EncryptedFileDownloader import ManagedEncryptedFileDownloader
from lbrynet.daemon.ExchangeRateManager import ExchangeRateManager from lbrynet.daemon.ExchangeRateManager import ExchangeRateManager
from tests.mocks import BlobAvailabilityTracker as DummyBlobAvailabilityTracker
from tests.mocks import ExchangeRateManager as DummyExchangeRateManager from tests.mocks import ExchangeRateManager as DummyExchangeRateManager
from tests.mocks import BTCLBCFeed, USDBTCFeed
from tests.mocks import mock_conf_settings from tests.mocks import mock_conf_settings
class MocDownloader(object): class MocDownloader(object):
def __init__(self): def __init__(self):
self.finish_deferred = defer.Deferred(None) self.finish_deferred = defer.Deferred(None)
@ -106,7 +102,7 @@ class GetStreamTests(unittest.TestCase):
DownloadTimeoutError is raised DownloadTimeoutError is raised
""" """
def download_sd_blob(self): def download_sd_blob(self):
raise DownloadTimeoutError(self.file_name) raise DownloadSDTimeout(self.file_name)
getstream = self.init_getstream_with_mocs() getstream = self.init_getstream_with_mocs()
getstream._initialize = types.MethodType(moc_initialize, getstream) getstream._initialize = types.MethodType(moc_initialize, getstream)
@ -115,31 +111,30 @@ class GetStreamTests(unittest.TestCase):
getstream.pay_key_fee = types.MethodType(moc_pay_key_fee, getstream) getstream.pay_key_fee = types.MethodType(moc_pay_key_fee, getstream)
name='test' name='test'
stream_info = None stream_info = None
with self.assertRaises(DownloadTimeoutError): with self.assertRaises(DownloadSDTimeout):
yield getstream.start(stream_info,name) yield getstream.start(stream_info,name)
self.assertFalse(getstream.pay_key_fee_called) self.assertFalse(getstream.pay_key_fee_called)
# @defer.inlineCallbacks
@defer.inlineCallbacks # def test_timeout(self):
def test_timeout(self): # """
""" # test that timeout (set to 2 here) exception is raised
test that timeout (set to 2 here) exception is raised # when download times out while downloading first blob, and key fee is paid
when download times out while downloading first blob, and key fee is paid # """
""" # getstream = self.init_getstream_with_mocs()
getstream = self.init_getstream_with_mocs() # getstream._initialize = types.MethodType(moc_initialize, getstream)
getstream._initialize = types.MethodType(moc_initialize, getstream) # getstream._download_sd_blob = types.MethodType(moc_download_sd_blob, getstream)
getstream._download_sd_blob = types.MethodType(moc_download_sd_blob, getstream) # getstream._download = types.MethodType(moc_download, getstream)
getstream._download = types.MethodType(moc_download, getstream) # getstream.pay_key_fee = types.MethodType(moc_pay_key_fee, getstream)
getstream.pay_key_fee = types.MethodType(moc_pay_key_fee, getstream) # name='test'
name='test' # stream_info = None
stream_info = None # start = getstream.start(stream_info,name)
start = getstream.start(stream_info,name) # self.clock.advance(1)
self.clock.advance(1) # self.clock.advance(1)
self.clock.advance(1) # with self.assertRaises(DownloadDataTimeout):
with self.assertRaises(DownloadTimeoutError): # yield start
yield start # self.assertTrue(getstream.downloader.stop_called)
self.assertTrue(getstream.downloader.stop_called) # self.assertTrue(getstream.pay_key_fee_called)
self.assertTrue(getstream.pay_key_fee_called)
@defer.inlineCallbacks @defer.inlineCallbacks
def test_finish_one_blob(self): def test_finish_one_blob(self):
@ -163,21 +158,20 @@ class GetStreamTests(unittest.TestCase):
downloader, f_deferred = yield start downloader, f_deferred = yield start
self.assertTrue(getstream.pay_key_fee_called) self.assertTrue(getstream.pay_key_fee_called)
# @defer.inlineCallbacks
@defer.inlineCallbacks # def test_finish_stopped_downloader(self):
def test_finish_stopped_downloader(self): # """
""" # test that if we have a stopped downloader, beforfe a blob is downloaded,
test that if we have a stopped downloader, beforfe a blob is downloaded, # start() returns
start() returns # """
""" # getstream = self.init_getstream_with_mocs()
getstream = self.init_getstream_with_mocs() # getstream._initialize = types.MethodType(moc_initialize, getstream)
getstream._initialize = types.MethodType(moc_initialize, getstream) # getstream._download_sd_blob = types.MethodType(moc_download_sd_blob, getstream)
getstream._download_sd_blob = types.MethodType(moc_download_sd_blob, getstream) # getstream._download = types.MethodType(moc_download, getstream)
getstream._download = types.MethodType(moc_download, getstream) # name='test'
name='test' # stream_info = None
stream_info = None # start = getstream.start(stream_info,name)
start = getstream.start(stream_info,name) #
# getstream.downloader.running_status = ManagedEncryptedFileDownloader.STATUS_STOPPED
getstream.downloader.running_status = ManagedEncryptedFileDownloader.STATUS_STOPPED # self.clock.advance(1)
self.clock.advance(1) # downloader, f_deferred = yield start
downloader, f_deferred = yield start