def test_pendingevent_future_created(self): """ Test the cron launches PendingEvent in the future """ self.e.on_fire = "param.set_value('has_been_called', True)" self.e.save() pe = PendingEvent( event=self.e, kingdom=self.k, started=datetime.now()+timedelta(milliseconds=5) ) pe.save() # Sanity check : not started yet self.assertFalse(pe.is_started) self.assertFalse(pe.has_value('has_been_called')) # Wait until completion time.sleep(0.005) cron_minute.send(self, counter=1000) # PE has been executed self.assertTrue(pe.get_value('has_been_called')) self.assertTrue(PendingEvent.objects.get(pk=pe.id).is_started)
def test_pendingmission_cron_notimeout(self): """ Test the cron does not timeout pendingmission without timeout. """ self.m.timeout = None self.m.save() self.pm.created = datetime.now() - timedelta(minutes=15) self.pm.save() cron_minute.send(self, counter=1000) # assertNoRaises PendingMission.objects.get(pk=self.pm.id)
def test_pendingmission_cron_duration_resolution_code(self): """ Test the cron resolves pendingmission and execute the code. """ self.m.duration = 10 self.m.on_resolution = """ kingdom.set_value('pm_resolved', param.pk) """ self.m.save() self.pm.started = datetime.now() - timedelta(minutes=15) self.pm.save() cron_minute.send(self, counter=1000) self.assertEqual(self.k.get_value('pm_resolved'), self.pm.id)
def test_pendingmission_cron_timeout_cancel_code(self): """ Test the cron triggers the on_cancel code. """ self.m.timeout = 10 self.m.on_cancel = """ kingdom.set_value('pm_deleted', param.pk) """ self.m.save() self.pm.created = datetime.now() - timedelta(minutes=15) self.pm.save() cron_minute.send(self, counter=1000) self.assertEqual(self.k.get_value('pm_deleted'), self.pm.id)
def test_pendingmission_cron_timeout(self): """ Test the cron timeouts pendingmission. """ self.m.timeout = 10 self.m.save() self.pm.created = datetime.now() - timedelta(minutes=15) self.pm.save() pm2 = PendingMission(kingdom=self.k, mission=self.m) pm2.save() cron_minute.send(self, counter=1000) self.assertRaises(PendingMission.DoesNotExist, (lambda: PendingMission.objects.get(pk=self.pm.id))) # Assert no raises PendingMission.objects.get(pk=pm2.id)
def test_pendingmission_cron_duration(self): """ Test the cron resolves pendingmission and deletes them. """ self.m.duration = 10 self.m.save() self.pm.started = datetime.now() - timedelta(minutes=15) self.pm.save() pm2 = PendingMission(kingdom=self.k, mission=self.m) pm2.started = datetime.now() pm2.save() cron_minute.send(self, counter=1000) self.assertRaises(PendingMission.DoesNotExist, (lambda: PendingMission.objects.get(pk=self.pm.id))) # Assert no raises PendingMission.objects.get(pk=pm2.id)
def test_pendingevent_future_cancelled(self): """ Test the cron launches PendingEvent in the future, and gracefully handles cancellation if the event asks not to be displayed. """ self.e.condition = "status='no'" self.e.save() pe = PendingEvent( event=self.e, kingdom=self.k, started=datetime.now()+timedelta(milliseconds=5) ) pe.save() # Sanity check : not started yet self.assertFalse(pe.is_started) # Wait until completion time.sleep(0.005) cron_minute.send(self, counter=1000) # PE has been deleted (status=no) self.assertRaises(PendingEvent.DoesNotExist, (lambda: PendingEvent.objects.get(pk=pe.id)))