コード例 #1
0
def test_set_on_item_published(agent):
    callback = Mock()

    class FocusBehaviour(OneShotBehaviour):
        async def run(self):
            await agent.artifacts.focus("artifact@server", callback)

    behav = FocusBehaviour()
    agent.add_behaviour(behav)
    behav.join()

    class Item:
        def __init__(self, data):
            self.data = data
            _data = collections.namedtuple("data", "data")
            self.registered_payload = _data(data=self.data)

    agent.artifacts.on_item_published(
        jid="artifact@server",
        node="artifact@server",
        item=Item("payload"),
        message=None,
    )

    assert callback.called_with("artifact@server", "payload")
    agent.stop()