def test_agent_events(self): source_agent = Agent.new('Source Agent') listening_agent = Agent.new('Listening Agent', source_agents=[source_agent]) listening_agent_2 = Agent.new('Listening Agent 2', source_agents=None) source_agent.add_event({'event_field': 'event_value'}) source_agent._put_events_queue() self.assertIn(listening_agent, SourceAgent.get_listening_agents(source_agent)) events = listening_agent.receive_events() self.assertEqual(len(events), 1) events = listening_agent_2.receive_events() self.assertEqual(len(events), 0)
def test_create_agent(self): name = 'My Agent' agent = Agent.new(name=name) self.assertEqual(agent.type, 'muninn.agents.Agent') agent2 = TestAgent.new(name=name) self.assertEqual(agent2.type, 'muninn.tests.test_agents.TestAgent') agents = AgentStore.all(name=name, type=agent.type) self.assertEqual(len(agents), 1) agents = AgentStore.all(name=name) self.assertEqual(len(agents), 2)
def test_parse_agents_class_name(self): agents = ['Foo', 'Bar', Agent] self.assertEqual(['Foo', 'Bar', 'muninn.agents.Agent'], Agent._parse_agents_class_name(agents))