Clean up the test

This commit is contained in:
Miroslav Kovar 2019-10-05 16:06:29 +02:00 committed by Lex Berezhny
parent 342184e532
commit 5fe536a058
2 changed files with 17 additions and 30 deletions

View file

@ -179,8 +179,8 @@ class BaseClaim:
def locations(self) -> LocationList: def locations(self) -> LocationList:
return LocationList(self.claim.message.locations) return LocationList(self.claim.message.locations)
def __delitem__(self, key): def clear_field_by_name(self, field_name: str):
self.message.ClearField(key) self.message.ClearField(field_name)
class Stream(BaseClaim): class Stream(BaseClaim):
@ -242,7 +242,7 @@ class Stream(BaseClaim):
self.source.size = kwargs.pop('file_size') self.source.size = kwargs.pop('file_size')
if source_stream_type in ('image', 'video', 'audio') and stream_type != source_stream_type: if source_stream_type in ('image', 'video', 'audio') and stream_type != source_stream_type:
del self[source_stream_type] self.clear_field_by_name(source_stream_type)
if stream_type in ('image', 'video', 'audio'): if stream_type in ('image', 'video', 'audio'):
media = getattr(self, stream_type) media = getattr(self, stream_type)

View file

@ -29,7 +29,7 @@ class ClaimTestCase(CommandTestCase):
open(self.video_file_name, 'wb') as video_file: open(self.video_file_name, 'wb') as video_file:
video_file.write(response.read()) video_file.write(response.read())
async def image_stream_create(self, name='blank-image', bid='1.0', confirm=True): async def _image_stream_operation(self, func, *args, **kwargs):
with tempfile.NamedTemporaryFile(suffix='.png') as file: with tempfile.NamedTemporaryFile(suffix='.png') as file:
file.write(unhexlify( file.write(unhexlify(
b'89504e470d0a1a0a0000000d49484452000000050000000708020000004fc' b'89504e470d0a1a0a0000000d49484452000000050000000708020000004fc'
@ -38,33 +38,23 @@ class ClaimTestCase(CommandTestCase):
b'9454e44ae426082' b'9454e44ae426082'
)) ))
file.flush() file.flush()
tx = await self.out( return await self.out(func(*args, file_path=file.name, **kwargs))
self.daemon.jsonrpc_stream_create(
name, bid, file_path=file.name async def _confirm_tx(self, tx):
)
)
if confirm:
await self.on_transaction_dict(tx) await self.on_transaction_dict(tx)
await self.generate(1) await self.generate(1)
await self.on_transaction_dict(tx) await self.on_transaction_dict(tx)
async def image_stream_create(self, name='blank-image', bid='1.0', confirm=True):
tx = await self._image_stream_operation(self.daemon.jsonrpc_stream_create, name, bid)
if confirm:
await self._confirm_tx(tx)
return tx return tx
async def update_stream_to_image_type(self, claim_id, confirm=True): async def update_stream_to_image_type(self, claim_id, confirm=True):
with tempfile.NamedTemporaryFile(suffix='.png') as file: tx = await self._image_stream_operation(self.daemon.jsonrpc_stream_update, claim_id)
file.write(unhexlify(
b'89504e470d0a1a0a0000000d49484452000000050000000708020000004fc'
b'510b9000000097048597300000b1300000b1301009a9c1800000015494441'
b'5408d763fcffff3f031260624005d4e603004c45030b5286e9ea000000004'
b'9454e44ae426082'
))
file.flush()
tx = await self.out(self.daemon.jsonrpc_stream_update(
claim_id, file_path=file.name
))
if confirm: if confirm:
await self.on_transaction_dict(tx) await self._confirm_tx(tx)
await self.generate(1)
await self.on_transaction_dict(tx)
return tx return tx
async def video_stream_create(self, name='chrome', bid='1.0', confirm=True): async def video_stream_create(self, name='chrome', bid='1.0', confirm=True):
@ -74,12 +64,9 @@ class ClaimTestCase(CommandTestCase):
) )
) )
if confirm: if confirm:
await self.on_transaction_dict(tx) await self._confirm_tx(tx)
await self.generate(1)
await self.on_transaction_dict(tx)
return tx return tx
class ClaimSearchCommand(ClaimTestCase): class ClaimSearchCommand(ClaimTestCase):
async def create_channel(self): async def create_channel(self):