From 3c7afcd879d3ffab47a0e1322e60f34a781e7b46 Mon Sep 17 00:00:00 2001 From: Daniil Fajnberg Date: Sun, 28 Nov 2021 16:52:16 +0100 Subject: [PATCH] factored out some tests --- tests/test_functions.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tests/test_functions.py b/tests/test_functions.py index cad26ea..219218a 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -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')