From 9f09bfdbd420b847262540e8c2bafc5b36813988 Mon Sep 17 00:00:00 2001 From: ape364 Date: Thu, 30 May 2024 01:54:09 +0500 Subject: [PATCH] fix test_txs_generator --- tests/extra/generators/test_blocks_parser.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/extra/generators/test_blocks_parser.py b/tests/extra/generators/test_blocks_parser.py index 0b691f1..6e2e1cd 100644 --- a/tests/extra/generators/test_blocks_parser.py +++ b/tests/extra/generators/test_blocks_parser.py @@ -1,5 +1,5 @@ import logging -from unittest.mock import AsyncMock +from unittest.mock import AsyncMock, Mock import pytest @@ -113,9 +113,19 @@ async def test_fetch_blocks_range_no_txs(blocks_parser, api_method): assert transfers == [] -async def test_txs_generator_success(blocks_parser, api_method): - api_method.return_value = [{'blockNumber': 200, 'transfers': [{'value': 100}]}] +async def test_txs_generator(blocks_parser, api_method): + api_method.side_effect = [ + EtherscanClientApiError('Test exception', 'result'), + [{'blockNumber': 200, 'transfers': [{'value': 100}]}], + ] + blocks_parser._blocks_range.limit.reduce = Mock() + blocks_parser._blocks_range.limit.restore = Mock() + transfers = [] async for transfer in blocks_parser.txs_generator(): transfers.append(transfer) + + blocks_parser._blocks_range.limit.reduce.assert_called_once() + blocks_parser._blocks_range.limit.restore.assert_called_once() + assert transfers == [{'blockNumber': 200, 'transfers': [{'value': 100}]}]