1
0
Fork 0

Add Flexpool tests for API failures

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2021-02-17 16:21:08 +01:00
parent 0a2bef6192
commit 7f5bd0a1cf
No known key found for this signature in database
GPG key ID: FF42D23B580C89F7
2 changed files with 68 additions and 21 deletions

View file

@ -34,6 +34,20 @@ class TestFlexpoolHandler:
else:
notifier.notify_balance.assert_not_called()
def test_balance_with_api_failure(self, mocker):
"""An API failure should not send a balance notification"""
notifier = mocker.Mock()
notifier.notify_balance = mocker.Mock()
handler = FlexpoolHandler(notifier=notifier)
request_get = mocker.patch('requests.get')
request_get.return_value.status_code = 503
mocker.patch('companion.pools.flexpool.FlexpoolHandler._watch_miner_payments')
mocker.patch('companion.pools.flexpool.Miner.get_payements')
last_balance, last_transaction = handler.watch_miner(address='0000000000000000000000000000000000000001',
last_balance=1)
assert last_balance is None
notifier.notify_balance.assert_not_called()
@staticmethod
def _create_transactions(names):
if names:
@ -66,6 +80,19 @@ class TestFlexpoolHandler:
else:
notifier.notify_payment.assert_not_called()
def test_payment_with_api_failure(self, mocker):
"""An API failure should not send a payment notification"""
notifier = mocker.Mock()
notifier.notify_payment = mocker.Mock()
handler = FlexpoolHandler(notifier=notifier)
request_get = mocker.patch('requests.get')
request_get.return_value.status_code = 503
mocker.patch('companion.pools.flexpool.FlexpoolHandler._watch_miner_balance')
last_balance, last_transaction = handler.watch_miner(address='0000000000000000000000000000000000000001',
last_transaction=1)
assert last_transaction is None
notifier.notify_payment.assert_not_called()
@staticmethod
def _create_blocks(numbers):
if numbers:
@ -102,3 +129,14 @@ class TestFlexpoolHandler:
notifier.notify_block.assert_called_once()
else:
notifier.notify_block.assert_not_called()
def test_block_with_api_failure(self, mocker):
"""An API failure should not send a block notification"""
notifier = mocker.Mock()
notifier.notify_block = mocker.Mock()
handler = FlexpoolHandler(notifier=notifier)
request_get = mocker.patch('requests.get')
request_get.return_value.status_code = 503
block = handler.watch_blocks(last_block=1)
assert block is None
notifier.notify_block.assert_not_called()