Compare commits
No commits in common. "1f8104b1a086273fd25bc1694dcc42a594b0965e" and "a6b3c57021e9529104ee9e9ca365bf3b7749ff61" have entirely different histories.
1f8104b1a0
...
a6b3c57021
@ -135,16 +135,6 @@ async def get_cash_flow_statement(*ticker_symbols: str, quarterly: bool = False,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@in_async_session
|
|
||||||
async def _get_single_company_financials(ticker_symbol: str, quarterly: bool = False,
|
|
||||||
session: ClientSession = None) -> Dict[str, ResultDict]:
|
|
||||||
return {
|
|
||||||
constants.BS: await _get_financial_statement(constants.BS, ticker_symbol, quarterly, session),
|
|
||||||
constants.IS: await _get_financial_statement(constants.IS, ticker_symbol, quarterly, session),
|
|
||||||
constants.CF: await _get_financial_statement(constants.CF, ticker_symbol, quarterly, session)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@in_async_session
|
@in_async_session
|
||||||
async def get_company_financials(*ticker_symbols: str, quarterly: bool = False,
|
async def get_company_financials(*ticker_symbols: str, quarterly: bool = False,
|
||||||
session: ClientSession = None) -> Union[Dict[str, ResultDict],
|
session: ClientSession = None) -> Union[Dict[str, ResultDict],
|
||||||
@ -153,5 +143,15 @@ async def get_company_financials(*ticker_symbols: str, quarterly: bool = False,
|
|||||||
Returns all fundamentals (balance sheet, income statement and cash flow statement) of the specified company.
|
Returns all fundamentals (balance sheet, income statement and cash flow statement) of the specified company.
|
||||||
"""
|
"""
|
||||||
if len(ticker_symbols) == 1:
|
if len(ticker_symbols) == 1:
|
||||||
return await _get_single_company_financials(ticker_symbols[0], quarterly, session)
|
return {
|
||||||
return {symbol: await _get_single_company_financials(symbol, quarterly, session) for symbol in ticker_symbols}
|
constants.BS: await get_balance_sheet(ticker_symbols[0], quarterly=quarterly, session=session),
|
||||||
|
constants.IS: await get_income_statement(ticker_symbols[0], quarterly=quarterly, session=session),
|
||||||
|
constants.CF: await get_cash_flow_statement(ticker_symbols[0], quarterly=quarterly, session=session)
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
sym: {
|
||||||
|
constants.BS: await get_balance_sheet(sym, quarterly=quarterly, session=session),
|
||||||
|
constants.IS: await get_income_statement(sym, quarterly=quarterly, session=session),
|
||||||
|
constants.CF: await get_cash_flow_statement(sym, quarterly=quarterly, session=session)
|
||||||
|
} for sym in ticker_symbols
|
||||||
|
}
|
||||||
|
@ -159,36 +159,45 @@ class FunctionsTestCase(IsolatedAsyncioTestCase):
|
|||||||
async def test_get_cash_flow_statement(self, mock__get_financial_statement):
|
async def test_get_cash_flow_statement(self, mock__get_financial_statement):
|
||||||
await self._helper_test_get_any_statement(CF, mock__get_financial_statement)
|
await self._helper_test_get_any_statement(CF, mock__get_financial_statement)
|
||||||
|
|
||||||
@patch.object(functions, '_get_financial_statement')
|
@patch.object(functions, 'get_cash_flow_statement')
|
||||||
async def test__get_single_company_financials(self, mock__get_financial_statement):
|
@patch.object(functions, 'get_income_statement')
|
||||||
symbol, quarterly, mock_session = 'foo', False, MagicMock()
|
@patch.object(functions, 'get_balance_sheet')
|
||||||
mock__get_financial_statement.return_value = bar = 'bar'
|
async def test_get_company_financials(self, mock_get_bs, mock_get_is, mock_get_cf):
|
||||||
expected_output = {BS: bar, IS: bar, CF: bar}
|
mock_end_dates = ('bar', 'baz')
|
||||||
output = await functions._get_single_company_financials(symbol, quarterly, mock_session)
|
mock_get_bs.return_value = {END_DATE: mock_end_dates, 'a': (1, 2)}
|
||||||
self.assertDictEqual(expected_output, output)
|
mock_get_is.return_value = {END_DATE: mock_end_dates, 'b': (2, 3)}
|
||||||
mock__get_financial_statement.assert_has_calls([
|
mock_get_cf.return_value = {END_DATE: mock_end_dates, 'c': (3, 4)}
|
||||||
call(BS, symbol, quarterly, mock_session),
|
expected_output = {
|
||||||
call(IS, symbol, quarterly, mock_session),
|
BS: {END_DATE: mock_end_dates, 'a': (1, 2)},
|
||||||
call(CF, symbol, quarterly, mock_session)
|
IS: {END_DATE: mock_end_dates, 'b': (2, 3)},
|
||||||
])
|
CF: {END_DATE: mock_end_dates, 'c': (3, 4)}
|
||||||
|
}
|
||||||
@patch.object(functions, '_get_single_company_financials')
|
|
||||||
async def test_get_company_financials(self, mock__get_single_company_financials):
|
|
||||||
mock__get_single_company_financials.return_value = expected_output = 'baz'
|
|
||||||
symbol, quarterly, mock_session = 'foo', False, MagicMock()
|
symbol, quarterly, mock_session = 'foo', False, MagicMock()
|
||||||
output = await functions.get_company_financials(symbol, quarterly=quarterly, session=mock_session)
|
output = await functions.get_company_financials(symbol, quarterly=quarterly, session=mock_session)
|
||||||
self.assertEqual(expected_output, output)
|
self.assertDictEqual(expected_output, output)
|
||||||
mock__get_single_company_financials.assert_called_once_with(symbol, quarterly, mock_session)
|
mock_get_bs.assert_called_once_with(symbol, quarterly=quarterly, session=mock_session)
|
||||||
mock__get_single_company_financials.reset_mock()
|
mock_get_is.assert_called_once_with(symbol, quarterly=quarterly, session=mock_session)
|
||||||
|
mock_get_cf.assert_called_once_with(symbol, quarterly=quarterly, session=mock_session)
|
||||||
|
mock_get_bs.reset_mock()
|
||||||
|
mock_get_is.reset_mock()
|
||||||
|
mock_get_cf.reset_mock()
|
||||||
|
|
||||||
test_symbol1, test_symbol2 = 'x', 'y'
|
test_symbol1, test_symbol2 = 'x', 'y'
|
||||||
expected_output = {test_symbol1: expected_output, test_symbol2: expected_output}
|
expected_output = {test_symbol1: expected_output, test_symbol2: expected_output}
|
||||||
output = await functions.get_company_financials(test_symbol1, test_symbol2,
|
output = await functions.get_company_financials(test_symbol1, test_symbol2,
|
||||||
quarterly=quarterly, session=mock_session)
|
quarterly=quarterly, session=mock_session)
|
||||||
self.assertDictEqual(expected_output, output)
|
self.assertDictEqual(expected_output, output)
|
||||||
mock__get_single_company_financials.assert_has_calls([
|
mock_get_bs.assert_has_calls([
|
||||||
call(test_symbol1, quarterly, mock_session),
|
call(test_symbol1, quarterly=quarterly, session=mock_session),
|
||||||
call(test_symbol2, quarterly, mock_session)
|
call(test_symbol2, quarterly=quarterly, session=mock_session)
|
||||||
|
])
|
||||||
|
mock_get_is.assert_has_calls([
|
||||||
|
call(test_symbol1, quarterly=quarterly, session=mock_session),
|
||||||
|
call(test_symbol2, quarterly=quarterly, session=mock_session)
|
||||||
|
])
|
||||||
|
mock_get_cf.assert_has_calls([
|
||||||
|
call(test_symbol1, quarterly=quarterly, session=mock_session),
|
||||||
|
call(test_symbol2, quarterly=quarterly, session=mock_session)
|
||||||
])
|
])
|
||||||
|
|
||||||
@patch.object(functions, 'ClientSession')
|
@patch.object(functions, 'ClientSession')
|
||||||
|
Loading…
Reference in New Issue
Block a user