def test_new_events(table, mocker): """Возвращает событие обновления курса.""" table._df = mocker.Mock() new_events = table._new_events( events.TradingDayEnded(date=date(2020, 2, 5))) assert new_events == [ events.USDUpdated( date=date(2020, 2, 5), usd=table._df.copy.return_value, ), ]
async def test_usd_traded(mocker): """После загрузки курса началось обновление данных о торгуемых бумагах.""" dispatcher = handlers.EventHandlersDispatcher() event = events.USDUpdated(date=date(2021, 2, 5), usd=pd.DataFrame) fake_repo = mocker.Mock() fake_loader_and_handler = mocker.patch.object( handlers, "_load_by_id_and_handle_event") assert await dispatcher.handle_event( event, fake_repo) is fake_loader_and_handler.return_value fake_loader_and_handler.assert_called_once_with( fake_repo, base.create_id(ports.SECURITIES), event, )
def test_new_events(table, mocker): """Создание событий для всех торгуемых тикеров.""" table._df = pd.DataFrame( [["YY", 10, "m2"], ["UU", 100, "m1"]], columns=[col.ISIN, col.LOT_SIZE, col.MARKET], index=["GAZP", "AKRN"], ) trading_date = date(2020, 12, 15) fake_usd = mocker.Mock() event = events.USDUpdated(trading_date, fake_usd) assert table._new_events(event) == [ events.TickerTraded("GAZP", "YY", "m2", trading_date, fake_usd.copy.return_value), events.TickerTraded("AKRN", "UU", "m1", trading_date, fake_usd.copy.return_value), ]
def _new_events( self, event: events.TradingDayEnded) -> List[domain.AbstractEvent]: """Порождает событие об обновлении курса.""" return [events.USDUpdated(event.date, self._df.copy(deep=True))]