Example #1
0
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_loader_web_error(mocker):
    """Регрессионный тест при ошибке загрузки данных из интернета."""
    mocker.patch.object(parser, "get_df_from_url", side_effect=description.ParserError())

    loader = close_reestry.CloseGateway()
    df = await loader("TATN")

    assert df is None
async def test_loader(mocker):
    """Добавление столбца с валютами."""
    mocker.patch.object(parser, "get_df_from_url", return_value=DF)

    loader = close_reestry.CloseGateway()
    pd.testing.assert_frame_equal(await loader("TATNP"), DF_REZ)