Example #1
0
 def setUp(self):
     """ Create a Cron Parameter object
     """
     logging.basicConfig(format='%(levelname)s:%(message)s',
                         level=logging.DEBUG)
     self._obj = CronParameter(log=logging)
     self._triggered = False
Example #2
0
class ScenarioCronParameterTest(unittest.TestCase):
    """ Test CronParameter
    """
    def setUp(self):
        """ Create a Cron Parameter object
        """
        logging.basicConfig(format='%(levelname)s:%(message)s',
                            level=logging.DEBUG)
        self._obj = CronParameter(log=logging)
        self._triggered = False

    def tearDown(self):
        """ Destroy cron object
        """
        del self._obj
        self._triggered = False

    def triggered(self, payload=None):
        """ Called when the trigger is called """
        self._trigger = True

    def test_fill_with_data(self):
        """ Test fill method
        """
        parameters = {"cron": "*/5 * * * *"}
        self._obj.fill(params=parameters)
        self.assertTrue(
            self._obj.expr.__str__() == CronExpression(
                parameters["cron"]).__str__(),
            "Cron Expression not correctly setup")

    def test_fill_with_empty_data(self):
        """ TEst fill method with no cron expression
        """
        # Test without cron expression
        parameters = {}
        self._obj.fill(params=parameters)
        self.assertTrue(self._obj.expr is None,
                        "CronParameter expr should be empty")

    def test_evaluate_should_run(self):
        """ Setup a cron object which should run every minute
        """
        parameters = {"cron": "* * * * *"}
        self._obj.fill(params=parameters)
        self.assertTrue(self._obj.evaluate())

    def test_evaluate_should_not_run(self):
        """ Setup a cron object which should run in 10 minutes
        from now and ensure it does not evaluate to True
        """

        now = datetime.datetime.now()
        minute = (now.minute + 10) % 60
        parameters = {"cron": "%s * * * *" % minute}
        self._obj.fill(params=parameters)
        self.assertFalse(self._obj.evaluate())
Example #3
0
class ScenarioCronParameterTest(unittest.TestCase):
    """ Test CronParameter
    """

    def setUp(self):
        """ Create a Cron Parameter object
        """
        logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
        self._obj = CronParameter(log=logging)
        self._triggered = False

    def tearDown(self):
        """ Destroy cron object
        """
        del self._obj
        self._triggered = False

    def triggered(self, payload=None):
        """ Called when the trigger is called """
        self._trigger = True

    def test_fill_with_data(self):
        """ Test fill method
        """
        parameters = {"cron": "*/5 * * * *"}
        self._obj.fill(params=parameters)
        self.assertTrue(self._obj.expr.__str__() == CronExpression(parameters["cron"]).__str__(),
                        "Cron Expression not correctly setup")

    def test_fill_with_empty_data(self):
        """ TEst fill method with no cron expression
        """
        # Test without cron expression
        parameters = {}
        self._obj.fill(params=parameters)
        self.assertTrue(self._obj.expr is None, "CronParameter expr should be empty")

    def test_evaluate_should_run(self):
        """ Setup a cron object which should run every minute
        """
        parameters = {"cron": "* * * * *"}
        self._obj.fill(params=parameters)
        self.assertTrue(self._obj.evaluate())

    def test_evaluate_should_not_run(self):
        """ Setup a cron object which should run in 10 minutes
        from now and ensure it does not evaluate to True
        """

        now = datetime.datetime.now()
        minute = (now.minute + 10) % 60
        parameters = {"cron": "%s * * * *" % minute}
        self._obj.fill(params=parameters)
        self.assertFalse(self._obj.evaluate())
Example #4
0
 def setUp(self):
     """ Create a Cron Parameter object
     """
     logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
     self._obj = CronParameter(log=logging)
     self._triggered = False