integration test publishes actual file instead of just sources

This commit is contained in:
Lex Berezhny 2018-07-12 15:05:24 -04:00 committed by Jack Robison
parent e175e43082
commit 315661208d
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 24 additions and 14 deletions

View file

@ -100,13 +100,13 @@ class CryptStreamCreator(object):
@staticmethod @staticmethod
def random_iv_generator(): def random_iv_generator():
while 1: while 1:
yield os.urandom(AES.block_size / 8) yield os.urandom(AES.block_size // 8)
def setup(self): def setup(self):
"""Create the symmetric key if it wasn't provided""" """Create the symmetric key if it wasn't provided"""
if self.key is None: if self.key is None:
self.key = os.urandom(AES.block_size / 8) self.key = os.urandom(AES.block_size // 8)
return defer.succeed(True) return defer.succeed(True)
@ -121,7 +121,7 @@ class CryptStreamCreator(object):
yield defer.DeferredList(self.finished_deferreds) yield defer.DeferredList(self.finished_deferreds)
self.blob_count += 1 self.blob_count += 1
iv = self.iv_generator.next() iv = next(self.iv_generator)
final_blob = self._get_blob_maker(iv, self.blob_manager.get_blob_creator()) final_blob = self._get_blob_maker(iv, self.blob_manager.get_blob_creator())
stream_terminator = yield final_blob.close() stream_terminator = yield final_blob.close()
terminator_info = yield self._blob_finished(stream_terminator) terminator_info = yield self._blob_finished(stream_terminator)
@ -132,7 +132,7 @@ class CryptStreamCreator(object):
if self.current_blob is None: if self.current_blob is None:
self.next_blob_creator = self.blob_manager.get_blob_creator() self.next_blob_creator = self.blob_manager.get_blob_creator()
self.blob_count += 1 self.blob_count += 1
iv = self.iv_generator.next() iv = next(self.iv_generator)
self.current_blob = self._get_blob_maker(iv, self.next_blob_creator) self.current_blob = self._get_blob_maker(iv, self.next_blob_creator)
done, num_bytes_written = self.current_blob.write(data) done, num_bytes_written = self.current_blob.write(data)
data = data[num_bytes_written:] data = data[num_bytes_written:]

View file

@ -1,4 +1,4 @@
import types import tempfile
from twisted.internet import defer from twisted.internet import defer
from orchstr8.testcase import IntegrationTestCase, d2f from orchstr8.testcase import IntegrationTestCase, d2f
@ -25,8 +25,14 @@ class FakeAnalytics:
pass pass
class FakeBlobManager:
def get_blob_creator(self):
return None
class FakeSession: class FakeSession:
storage = None storage = None
blob_manager = FakeBlobManager()
class CommandTestCase(IntegrationTestCase): class CommandTestCase(IntegrationTestCase):
@ -53,24 +59,30 @@ class CommandTestCase(IntegrationTestCase):
await self.on_transaction_id(sendtxid) await self.on_transaction_id(sendtxid)
await self.blockchain.generate(1) await self.blockchain.generate(1)
await self.on_transaction_id(sendtxid) await self.on_transaction_id(sendtxid)
self.daemon = Daemon(FakeAnalytics()) self.daemon = Daemon(FakeAnalytics())
self.daemon.wallet = self.manager
wallet_component = WalletComponent(self.daemon.component_manager) wallet_component = WalletComponent(self.daemon.component_manager)
wallet_component.wallet = self.manager wallet_component.wallet = self.manager
wallet_component._running = True wallet_component._running = True
self.daemon.wallet = self.manager
self.daemon.component_manager.components.add(wallet_component) self.daemon.component_manager.components.add(wallet_component)
session_component = SessionComponent(self.daemon.component_manager) session_component = SessionComponent(self.daemon.component_manager)
session_component.session = FakeSession() session_component.session = FakeSession()
session_component._running = True session_component._running = True
self.daemon.session = session_component.session
self.daemon.component_manager.components.add(session_component) self.daemon.component_manager.components.add(session_component)
file_manager = FileManager(self.daemon.component_manager) file_manager = FileManager(self.daemon.component_manager)
file_manager.file_manager = EncryptedFileManager(session_component.session, True) file_manager.file_manager = EncryptedFileManager(session_component.session, True)
file_manager._running = True file_manager._running = True
self.daemon.component_manager.components.add(file_manager) self.daemon.component_manager.components.add(file_manager)
storage_component = DatabaseComponent(self.daemon.component_manager) storage_component = DatabaseComponent(self.daemon.component_manager)
await d2f(storage_component.start()) await d2f(storage_component.start())
self.daemon.component_manager.components.add(storage_component)
self.daemon.storage = storage_component.storage self.daemon.storage = storage_component.storage
self.daemon.component_manager.components.add(storage_component)
class ChannelNewCommandTests(CommandTestCase): class ChannelNewCommandTests(CommandTestCase):
@ -102,10 +114,8 @@ class PublishCommandTests(CommandTestCase):
@defer.inlineCallbacks @defer.inlineCallbacks
def test_publish(self): def test_publish(self):
result = yield self.daemon.jsonrpc_publish('foo', 1, sources={ with tempfile.NamedTemporaryFile() as file:
'version': '_0_0_1', file.write(b'hello world!')
'sourceType': 'lbry_sd_hash', file.flush()
'source': '0' * 96, result = yield self.daemon.jsonrpc_publish('foo', 1, file_path=file.name)
'contentType': ''
})
print(result) print(result)