def test_find_behaviour(): class EmptyOneShotBehaviour(OneShotBehaviour): async def run(self): pass agent = Agent("jid@server", "password") behaviour = EmptyOneShotBehaviour() agent.add_behaviour(behaviour) found_behaviour = agent.web.find_behaviour("OneShotBehaviour/EmptyOneShotBehaviour") assert found_behaviour == behaviour agent.stop()
async def test_kill_behaviour(test_client, loop): class EmptyCyclicBehaviour(CyclicBehaviour): async def run(self): await asyncio.sleep(0.1) agent = Agent("jid@server", "password") behaviour = EmptyCyclicBehaviour() agent.add_behaviour(behaviour) agent.web.setup_routes() client = await test_client(agent.web.app) await client.get("/behaviour/CyclicBehaviour/EmptyCyclicBehaviour/kill/") assert behaviour.is_killed() agent.stop()
async def test_kill_behaviour(test_client): class EmptyCyclicBehaviour(CyclicBehaviour): async def run(self): await asyncio.sleep(0.1) agent = Agent("jid@server", "password") behaviour = EmptyCyclicBehaviour() agent.add_behaviour(behaviour) agent.web.setup_routes() client = await test_client(agent.web.app) await client.get("/spade/behaviour/CyclicBehaviour/EmptyCyclicBehaviour/kill/") assert behaviour.is_killed() agent.stop()
async def test_get_behaviour(test_client): class EmptyOneShotBehaviour(OneShotBehaviour): async def run(self): self.kill() agent = Agent("jid@server", "password") behaviour = EmptyOneShotBehaviour() agent.add_behaviour(behaviour) agent.web.setup_routes() client = await test_client(agent.web.app) response = await client.get("/spade/behaviour/OneShotBehaviour/EmptyOneShotBehaviour/") response = await response.text() sel = Selector(text=response) assert sel.css("section.content-header > h1::text").get().strip() == "OneShotBehaviour/EmptyOneShotBehaviour" agent.stop()
async def test_get_behaviour(test_client, loop): class EmptyOneShotBehaviour(OneShotBehaviour): async def run(self): self.kill() agent = Agent("jid@server", "password") behaviour = EmptyOneShotBehaviour() agent.add_behaviour(behaviour) agent.web.setup_routes() client = await test_client(agent.web.app) response = await client.get("/behaviour/OneShotBehaviour/EmptyOneShotBehaviour/") response = await response.text() sel = Selector(text=response) assert sel.css("section.content-header > h1::text").get().strip() == "OneShotBehaviour/EmptyOneShotBehaviour" agent.stop()