Esempio n. 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()),
        GateWayDesc("StreetInsider", col.FOREIGN, street_insider.StreetInsider()),
    )

    def _update_cond(self, event: events.UpdateDivCommand) -> bool:
        """Если данные отсутствуют, то их надо загрузить, а так же обновить раз в неделю."""
        if (timestamp := self._timestamp) is None:
            return True

        return datetime.utcnow() - timestamp > timedelta(days=7)
Esempio n. 2
0
async def test_gateway_error(mocker):
    """Осуществляется вызов необходимых функций."""
    mocker.patch.object(finrange, "_get_page_html")
    mocker.patch.object(finrange.parser,
                        "get_df_from_html",
                        side_effect=description.ParserError)

    gw = finrange.FinRangeGateway()
    df = await gw.__call__("GAZP")

    assert df is None
Esempio n. 3
0
async def test_gateway(mocker):
    """Осуществляется вызов необходимых функций."""
    fake_get_page_html = mocker.patch.object(finrange, "_get_page_html")
    fake_get_df_from_html = mocker.patch.object(finrange.parser,
                                                "get_df_from_html")
    fake_reformat_df = mocker.patch.object(finrange.description,
                                           "reformat_df_with_cur")

    gw = finrange.FinRangeGateway()
    df = await gw.__call__("AKRN")

    fake_get_page_html.assert_called_once_with(finrange._prepare_url("AKRN"))
    fake_get_df_from_html.assert_called_once_with(
        fake_get_page_html.return_value,
        finrange.TABLE_NUM,
        finrange._get_col_desc("AKRN"),
    )
    fake_reformat_df.assert_called_once_with(
        fake_get_df_from_html.return_value, "AKRN")

    assert df is fake_reformat_df.return_value