def message_callback(self): return Mock(name="message_callback")
def test_contribute_to_stream(self, *, table): table.contribute_to_stream(Mock(name='stream', autospec=Stream))
def test_new_changelog_topic__window_expires(self, *, table): table.window = Mock(name='window', autospec=Window) table.window.expires = 3600.3 assert table._new_changelog_topic(retention=None).retention == 3600.3
def test_should_expire_keys(self, *, table): table.window = None assert not table._should_expire_keys() table.window = Mock(name='window', autospec=Window) table.window.expires = 3600 assert table._should_expire_keys()
def test__join(self, *, table): with pytest.raises(NotImplementedError): table._join(Mock(name='join_strategy', autospec=joins.Join))
async def test_on_start(self, *, app): app.finalize = Mock(name="app.finalize") await app.on_start() app.finalize.assert_called_once_with()
def test_reset_state(self, *, table): data = table._data = Mock(name='_data', autospec=Store) table.reset_state() data.reset_state.assert_called_once_with()
def consumer(self): return Mock( name="consumer", autospec=Consumer, _drain_messages=AsyncMock(), )
def callback(self): return Mock(name="callback")
def transport(self, *, app): return Mock( name="transport", spec=Transport, app=app, )
def test_send_soon(self, *, manager): with pytest.raises(NotImplementedError): manager.send_soon(Mock(name="FutureMessage"))
def consumer(self): return Mock( name="consumer", spec=Consumer, )
def partitions_assigned_callback(self): return Mock(name="partitions_assigned_callback")
def partitions_revoked_callback(self): return Mock(name="partitions_revoked_callback")
def test_ack__disabled(self, *, consumer, message, app): message.acked = False app.topics = Mock(name="app.topics", autospec=Conductor) app.topics.acks_enabled_for.return_value = False consumer.ack(message)
def on_P_revoked(self): return Mock(name="on_partitions_revoked")
async def test_on_first_start(self, *, app): app.agents = Mock(name="agents") app._create_directories = Mock(name="app._create_directories") await app.on_first_start() app._create_directories.assert_called_once_with()
def on_P_assigned(self): return Mock(name="on_partitions_assigned")
async def test_wait_for_table_recovery_completed(self, *, app): app.tables = Mock() app.tables.recovery.started = True app.tables.wait_until_recovery_completed = AsyncMock() await app._wait_for_table_recovery_completed() app.tables.wait_until_recovery_completed.assert_called_once_with()
def message(self): return Mock(name="message", autospec=Message)
def test_del_old_keys__empty(self, *, table): table.window = Mock(name='window') table._del_old_keys()
async def test_on_restart(self, *, consumer): consumer._reset_state = Mock() consumer.on_init = Mock() await consumer.on_restart() consumer._reset_state.assert_called_once_with() consumer.on_init.assert_called_once_with()
def test_outer_join(self, *, table): table._join = Mock(name='join') ret = table.outer_join(User.id, User.name) table._join.assert_called_once_with( joins.OuterJoin(stream=table, fields=(User.id, User.name)), ) assert ret is table._join()
def test__get_active_partitions__when_set(self, *, consumer): consumer._active_partitions = {TP1, TP2} consumer.assignment = Mock(return_value={TP1}) assert consumer._get_active_partitions() == {TP1, TP2}
def test_combine(self, *, table): with pytest.raises(NotImplementedError): table.combine(Mock(name='joinable', autospec=Stream))
async def test_on_stop__drainer_done(self, *, fetcher): fetcher._drainer = Mock(done=Mock(return_value=True)) await fetcher.on_stop()
async def test_remove_from_stream(self, *, table): await table.remove_from_stream(Mock(name='stream', autospec=Stream))
def test_is_changelog_tp(self, *, app, consumer): app.tables = Mock(name="tables", autospec=TableManager) app.tables.changelog_topics = {"foo", "bar"} assert consumer._is_changelog_tp(TP("foo", 31)) assert consumer._is_changelog_tp(TP("bar", 0)) assert not consumer._is_changelog_tp(TP("baz", 3))
def test__maybe_set_key_ttl(self, *, table): table._should_expire_keys = Mock(return_value=False) table._maybe_set_key_ttl(('k', (100, 110)), 0) table._should_expire_keys = Mock(return_value=True) table._maybe_set_key_ttl(('k', (100, 110)), 0)
def test__create_site(self, *, web, app): web._new_transport = Mock() ret = web._create_site() web._new_transport.assert_called_once_with( app.conf.web_transport.scheme) assert ret is web._new_transport()