factored out some tests

This commit is contained in:
Daniil Fajnberg 2021-11-28 16:52:16 +01:00
parent 4a68d45bc4
commit 3c7afcd879

View File

@ -122,29 +122,32 @@ class FunctionsTestCase(IsolatedAsyncioTestCase):
mock_soup_from_url.assert_called_once_with(test_url + '/quarter', mock_session)
mock_extract_all_data.assert_called_once_with(mock_soup)
@patch.object(functions, '_get_financial_statement')
async def test_get_balance_sheet(self, mock__get_financial_statement):
async def _helper_test_get_any_statement(self, statement: str, mock__get_financial_statement):
symbol, quarterly, mock_session = 'foo', False, MagicMock()
mock__get_financial_statement.return_value = expected_output = 'bar'
output = await functions.get_balance_sheet(symbol, quarterly, mock_session)
if statement == BS:
function = functions.get_balance_sheet
elif statement == IS:
function = functions.get_income_statement
elif statement == CF:
function = functions.get_cash_flow_statement
else:
raise ValueError
output = await function(symbol, quarterly, mock_session)
self.assertEqual(expected_output, output)
mock__get_financial_statement.assert_called_once_with(BS, symbol, quarterly, mock_session)
mock__get_financial_statement.assert_called_once_with(statement, symbol, quarterly, mock_session)
@patch.object(functions, '_get_financial_statement')
async def test_get_balance_sheet(self, mock__get_financial_statement):
await self._helper_test_get_any_statement(BS, mock__get_financial_statement)
@patch.object(functions, '_get_financial_statement')
async def test_get_income_statement(self, mock__get_financial_statement):
symbol, quarterly, mock_session = 'foo', False, MagicMock()
mock__get_financial_statement.return_value = expected_output = 'bar'
output = await functions.get_income_statement(symbol, quarterly, mock_session)
self.assertEqual(expected_output, output)
mock__get_financial_statement.assert_called_once_with(IS, symbol, quarterly, mock_session)
await self._helper_test_get_any_statement(IS, mock__get_financial_statement)
@patch.object(functions, '_get_financial_statement')
async def test_get_cash_flow_statement(self, mock__get_financial_statement):
symbol, quarterly, mock_session = 'foo', False, MagicMock()
mock__get_financial_statement.return_value = expected_output = 'bar'
output = await functions.get_cash_flow_statement(symbol, quarterly, mock_session)
self.assertEqual(expected_output, output)
mock__get_financial_statement.assert_called_once_with(CF, symbol, quarterly, mock_session)
await self._helper_test_get_any_statement(CF, mock__get_financial_statement)
@patch.object(functions, 'get_cash_flow_statement')
@patch.object(functions, 'get_income_statement')