Пример #1
0
 def test_agent_sources(self):
     source_agent1 = TestAgent.new('Source Agent 1')
     source_agent2 = TestAgent.new('Source Agent 2')
     mute_agent = MuteAgent.new('Mute Agent')
     agent = TestAgent.new('Test Agent',
                           source_agents=[source_agent1, source_agent2, mute_agent])
     self.assertEqual(SourceAgent.get_source_agents(agent),
                      [source_agent1, source_agent2])
Пример #2
0
 def test_agent_sources(self):
     source_agent1 = TestAgent.new('Source Agent 1')
     source_agent2 = TestAgent.new('Source Agent 2')
     mute_agent = MuteAgent.new('Mute Agent')
     agent = TestAgent.new(
         'Test Agent',
         source_agents=[source_agent1, source_agent2, mute_agent])
     self.assertEqual(SourceAgent.get_source_agents(agent),
                      [source_agent1, source_agent2])
Пример #3
0
    def test_agent_due(self):
        in_two_hours = datetime.datetime.now() + datetime.timedelta(hours=2)

        agent1 = TestAgent.new('Agent 1', cron_entry='*/10 * * * *')
        agent2 = TestAgent.new('Agent 2', cron_entry='%s %s * * *' % (in_two_hours.minute, in_two_hours.hour))
        d1 = datetime.datetime.now() + datetime.timedelta(seconds=601)
        d2 = datetime.datetime.now() + datetime.timedelta(hours=3)
        d3 = datetime.datetime.now() - datetime.timedelta(seconds=10)
        a1 = AgentStore.due(d1)
        a2 = AgentStore.due(d2)
        a3 = AgentStore.due(d3)
        self.assertEqual(len(a1), 1)
        self.assertEqual(len(a2), 2)
        self.assertEqual(len(a3), 0)
Пример #4
0
    def test_agent_due(self):
        in_two_hours = datetime.datetime.now() + datetime.timedelta(hours=2)

        agent1 = TestAgent.new('Agent 1', cron_entry='*/10 * * * *')
        agent2 = TestAgent.new('Agent 2',
                               cron_entry='%s %s * * *' %
                               (in_two_hours.minute, in_two_hours.hour))
        d1 = datetime.datetime.now() + datetime.timedelta(seconds=601)
        d2 = datetime.datetime.now() + datetime.timedelta(hours=3)
        d3 = datetime.datetime.now() - datetime.timedelta(seconds=10)
        a1 = AgentStore.due(d1)
        a2 = AgentStore.due(d2)
        a3 = AgentStore.due(d3)
        self.assertEqual(len(a1), 1)
        self.assertEqual(len(a2), 2)
        self.assertEqual(len(a3), 0)
Пример #5
0
 def test_agent_run(self):
     source_agent1 = TestAgent.new('Source Agent 1')
     source_agent2 = TestAgent.new('Source Agent 2')
     agent = TestAgent.new('Test Agent',
                           source_agents=[source_agent1, source_agent2])
     listening_agent = TestAgent.new('Listening Agent',
                                     source_agents=[agent])
     source_agent1.add_event(1)
     source_agent2.add_event(2)
     source_agent1._put_events_queue()
     source_agent2._put_events_queue()
     self.assertFalse(agent.last_run)
     agent.run()
     generated_events = Event.from_agent(agent)
     print generated_events
     self.assertEqual(generated_events[0].data, {'event_data': [1, 2]})
     self.assertTrue(agent.last_run)
Пример #6
0
 def test_agent_run(self):
     source_agent1 = TestAgent.new('Source Agent 1')
     source_agent2 = TestAgent.new('Source Agent 2')
     agent = TestAgent.new('Test Agent',
                           source_agents=[source_agent1, source_agent2])
     listening_agent = TestAgent.new('Listening Agent',
                                     source_agents=[agent])
     source_agent1.add_event(1)
     source_agent2.add_event(2)
     source_agent1._put_events_queue()
     source_agent2._put_events_queue()
     self.assertFalse(agent.last_run)
     agent.run()
     generated_events = Event.from_agent(agent)
     print generated_events
     self.assertEqual(generated_events[0].data,
                      {'event_data': [1, 2]})
     self.assertTrue(agent.last_run)
Пример #7
0
 def test_agent_run_taskqueue(self):
     source_agent1 = TestAgent.new('Source Agent 1')
     source_agent1.run_taskqueue()
     queue = taskqueue.Queue(name='agents')
     stats = queue.fetch_statistics()
     self.assertEqual(stats.tasks, 1)
Пример #8
0
 def test_agent_properties(self):
     agent = TestAgent.new('Agent', config={'foo': 'bar'})
     self.assertEqual(agent.config, {'foo': 'bar'})
     self.assertTrue(agent.can_receive_events)
     self.assertTrue(agent.can_generate_events)
Пример #9
0
 def test_agent_run_taskqueue(self):
     source_agent1 = TestAgent.new('Source Agent 1')
     source_agent1.run_taskqueue()
     queue = taskqueue.Queue(name='agents')
     stats = queue.fetch_statistics()
     self.assertEqual(stats.tasks, 1)
Пример #10
0
 def test_agent_properties(self):
     agent = TestAgent.new('Agent', config={'foo': 'bar'})
     self.assertEqual(agent.config, {'foo': 'bar'})
     self.assertTrue(agent.can_receive_events)
     self.assertTrue(agent.can_generate_events)