class DivExt(base.AbstractTable[events.UpdateDivCommand]): """Таблица со сводными данными по дивидендам из внешних источников.""" group: ClassVar[ports.GroupName] = ports.DIV_EXT _gateways: Final[tuple[GateWayDesc, ...]] = ( GateWayDesc("Dohod", col.ORDINARY, dohod.DohodGateway()), GateWayDesc("Dohod", col.PREFERRED, dohod.DohodGateway()), GateWayDesc("Conomy", col.ORDINARY, conomy.ConomyGateway()), GateWayDesc("Conomy", col.PREFERRED, conomy.ConomyGateway()), GateWayDesc("BCS", col.ORDINARY, bcs.BCSGateway()), GateWayDesc("BCS", col.PREFERRED, bcs.BCSGateway()), GateWayDesc("NASDAQ", col.FOREIGN, nasdaq.NASDAQGateway()), # GateWayDesc("FinRange", col.ORDINARY, finrange.FinRangeGateway()), # GateWayDesc("FinRange", col.FOREIGN, finrange.FinRangeGateway()), GateWayDesc("Close", col.ORDINARY, close_reestry.CloseGateway()), GateWayDesc("Close", col.PREFERRED, close_reestry.CloseGateway()), GateWayDesc("InvestMint", col.ORDINARY, invest_mint.InvestMintGateway()), GateWayDesc("InvestMint", col.PREFERRED, invest_mint.InvestMintGateway()), GateWayDesc("InvestMint", col.FOREIGN, invest_mint.InvestMintGateway()), ) def _update_cond(self, event: events.UpdateDivCommand) -> bool: """Если данные отсутствуют, то их надо загрузить, а так же обновить раз в неделю.""" if (timestamp := self._timestamp) is None: return True return datetime.utcnow() - timestamp > timedelta(days=7)
async def test_nasdaq_gateway(mocker): """Форматирование результатов с обычной загрузкой.""" mocker.patch.object(nasdaq, "_load_ticker_page") mocker.patch.object(nasdaq.parser, "get_df_from_html", return_value=DF) gateway = nasdaq.NASDAQGateway() pd.testing.assert_frame_equal(await gateway.__call__("BELU"), DF_REZ)
async def test_nasdaq_gateway_error(mocker): """Обработка сработавшей загрузки с ошибкой.""" mocker.patch.object(nasdaq, "_load_ticker_page") mocker.patch.object(nasdaq.parser, "get_df_from_html", side_effect=description.ParserError) gateway = nasdaq.NASDAQGateway() df = await gateway("BELU") assert df is None