refactoring

This commit is contained in:
Maximilian Fajnberg 2021-12-03 11:56:09 +01:00
parent 68f3e428ab
commit 1f8104b1a0
2 changed files with 7 additions and 14 deletions

View File

@ -138,7 +138,11 @@ async def get_cash_flow_statement(*ticker_symbols: str, quarterly: bool = False,
@in_async_session @in_async_session
async def _get_single_company_financials(ticker_symbol: str, quarterly: bool = False, async def _get_single_company_financials(ticker_symbol: str, quarterly: bool = False,
session: ClientSession = None) -> Dict[str, ResultDict]: session: ClientSession = None) -> Dict[str, ResultDict]:
pass 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
@ -149,15 +153,5 @@ 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 { return await _get_single_company_financials(ticker_symbols[0], quarterly, session)
constants.BS: await get_balance_sheet(ticker_symbols[0], quarterly=quarterly, session=session), return {symbol: await _get_single_company_financials(symbol, quarterly, session) for symbol in ticker_symbols}
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
}

View File

@ -181,7 +181,6 @@ class FunctionsTestCase(IsolatedAsyncioTestCase):
mock__get_single_company_financials.assert_called_once_with(symbol, quarterly, mock_session) mock__get_single_company_financials.assert_called_once_with(symbol, quarterly, mock_session)
mock__get_single_company_financials.reset_mock() mock__get_single_company_financials.reset_mock()
# keep
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,