fix tests

This commit is contained in:
Jack Robison 2019-05-08 14:47:04 -04:00
parent 761a2b235c
commit a2a1ef34ab
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 35 additions and 19 deletions

View file

@ -172,27 +172,43 @@ class CommandTestCase(IntegrationTestCase):
return json.loads(jsonrpc_dumps_pretty(value, ledger=self.ledger))['result'] return json.loads(jsonrpc_dumps_pretty(value, ledger=self.ledger))['result']
async def stream_create(self, name='hovercraft', bid='1.0', data=b'hi!', confirm=True, **kwargs): async def stream_create(self, name='hovercraft', bid='1.0', data=b'hi!', confirm=True, **kwargs):
with tempfile.NamedTemporaryFile() as file: file = tempfile.NamedTemporaryFile()
file.write(data)
file.flush() def cleanup():
claim = await self.out( try:
self.daemon.jsonrpc_stream_create(name, bid, file_path=file.name, **kwargs) file.close()
) except FileNotFoundError:
self.assertEqual(claim['outputs'][0]['name'], name) pass
if confirm:
await self.on_transaction_dict(claim) self.addCleanup(cleanup)
await self.generate(1) file.write(data)
await self.on_transaction_dict(claim) file.flush()
return claim claim = await self.out(
self.daemon.jsonrpc_stream_create(name, bid, file_path=file.name, **kwargs)
)
self.assertEqual(claim['outputs'][0]['name'], name)
if confirm:
await self.on_transaction_dict(claim)
await self.generate(1)
await self.on_transaction_dict(claim)
return claim
async def stream_update(self, claim_id, data=None, confirm=True, **kwargs): async def stream_update(self, claim_id, data=None, confirm=True, **kwargs):
if data: if data:
with tempfile.NamedTemporaryFile() as file: file = tempfile.NamedTemporaryFile()
file.write(data) file.write(data)
file.flush() file.flush()
claim = await self.out(
self.daemon.jsonrpc_stream_update(claim_id, file_path=file.name, **kwargs) def cleanup():
) try:
file.close()
except FileNotFoundError:
pass
self.addCleanup(cleanup)
claim = await self.out(
self.daemon.jsonrpc_stream_update(claim_id, file_path=file.name, **kwargs)
)
else: else:
claim = await self.out(self.daemon.jsonrpc_stream_update(claim_id, **kwargs)) claim = await self.out(self.daemon.jsonrpc_stream_update(claim_id, **kwargs))
self.assertIsNotNone(claim['outputs'][0]['name']) self.assertIsNotNone(claim['outputs'][0]['name'])

View file

@ -97,7 +97,7 @@ class RangeRequests(CommandTestCase):
async def test_range_requests_no_padding_size_from_claim(self): async def test_range_requests_no_padding_size_from_claim(self):
size = ((MAX_BLOB_SIZE - 1) * 4) - 14 size = ((MAX_BLOB_SIZE - 1) * 4) - 14
await self.test_range_requests_0_padded_bytes(size, padding=b'', file_size=size, await self.test_range_requests_0_padded_bytes(size, padding=b'', file_size=size,
expected_range=f"bytes 0-{size}/{size+1}") expected_range=f"bytes 0-{size-1}/{size}")
async def test_range_requests_15_padded_bytes(self): async def test_range_requests_15_padded_bytes(self):
await self.test_range_requests_0_padded_bytes( await self.test_range_requests_0_padded_bytes(