Exemplo n.º 1
0
 def test_process_var_failure_invalid_value(self):
     ''' process_var should fail if parameter is not a string '''
     values = [0, 3.2, {'set'}, ['a', 'list'], {'a': 'dict'}, uuid.uuid4()]
     sc = schedules.CronSchedule()
     for value in values:
         with self.assertRaises(TypeError) as cm:
             sc._process_var(value, max_value=100, min_value=10)
         self.assertEqual(str(cm.exception), 'value not a string')
Exemplo n.º 2
0
 def test_creation_CronSchedule_failure_invalid_dom(self):
     ''' creating a CronSchedule object should fail if dom is invalid '''
     doms = [0, 32, 9000, {'set'}, ['a', 'list'], {'a': 'dict'}]
     for dom in doms:
         with self.assertRaises(exceptions.BadParametersException) as cm:
             sc = schedules.CronSchedule(dom=dom)
         self.assertEqual(str(cm.exception),
                          'Invalid dom value: ' + str(dom))
Exemplo n.º 3
0
 def test_creation_CronSchedule_failure_invalid_month(self):
     ''' creating a CronSchedule object should fail if month is invalid '''
     months = [0, 13, 9000, {'set'}, ['a', 'list'], {'a': 'dict'}]
     for month in months:
         with self.assertRaises(exceptions.BadParametersException) as cm:
             sc = schedules.CronSchedule(month=month)
         self.assertEqual(str(cm.exception),
                          'Invalid month value: ' + str(month))
Exemplo n.º 4
0
 def test_creation_CronSchedule_failure_invalid_hour(self):
     ''' creating a CronSchedule object should fail if hour is invalid '''
     hours = [-1, 24, 9000, {'set'}, ['a', 'list'], {'a': 'dict'}]
     for hour in hours:
         with self.assertRaises(exceptions.BadParametersException) as cm:
             sc = schedules.CronSchedule(hour=hour)
         self.assertEqual(str(cm.exception),
                          'Invalid hour value: ' + str(hour))
Exemplo n.º 5
0
 def test_creation_CronSchedule_failure_invalid_minute(self):
     ''' creating a CronSchedule object should fail if minute is invalid '''
     minutes = [-1, 60, 9000, {'set'}, ['a', 'list'], {'a': 'dict'}]
     for minute in minutes:
         with self.assertRaises(exceptions.BadParametersException) as cm:
             sc = schedules.CronSchedule(minute=minute)
         self.assertEqual(str(cm.exception),
                          'Invalid minute value: ' + str(minute))
Exemplo n.º 6
0
 def test_creation_CronSchedule_success_with_defaults(self):
     ''' creating a CronSchedule object should succeed. exec_on_load should be False by default '''
     sc = schedules.CronSchedule()
     self.assertEqual(sc.exec_on_load, False)
     self.assertEqual(sc.activation_metrics, [])
     self.assertEqual(sc.minute, '*')
     self.assertEqual(sc.hour, '*')
     self.assertEqual(sc.month, '*')
     self.assertEqual(sc.dow, '*')
     self.assertEqual(sc.dom, '*')
Exemplo n.º 7
0
 def test_CronSchedule_meets_true(self):
     ''' CronSchedule meets should return true if timestruct meets schedule '''
     sc = schedules.CronSchedule()
     t = time.localtime()
     sc._schedule = {
         'minute': [t.tm_min],
         'hour': [t.tm_hour],
         'month': [t.tm_mon],
         'dow': [t.tm_wday],
         'dom': [t.tm_mday]
     }
     self.assertTrue(sc.meets(t))
Exemplo n.º 8
0
 def test_CronSchedule_meets_false(self):
     ''' CronSchedule meets should return false if timestruct does not meet schedule '''
     sc = schedules.CronSchedule()
     sc._schedule = {
         'minute': [],
         'hour': [],
         'month': [],
         'dow': [],
         'dom': []
     }
     t = time.localtime()
     self.assertFalse(sc.meets(t))
Exemplo n.º 9
0
    async def test_bind_transfermethod_success_with_CronSchedule(self):
        ''' calling bind should succeed with a tm with CronSchedule '''
        try:

            async def enable_tm(mid):
                return True

            enable_tm_bck = tmIndex.enable_tm
            tmIndex.enable_tm = enable_tm

            def func(param):
                pass

            tm = transfer_methods.transfermethod(
                f=func,
                f_params={'param': 'param'},
                schedule=schedules.CronSchedule())
            self.assertTrue(isinstance(tm.mid, uuid.UUID))
            self.assertEqual(tm._f, func)
            self.assertNotEqual(tm.schedule, None)
            self.assertTrue(isinstance(tm.schedule, schedules.CronSchedule))
            self.assertEqual(tm.f_params, {'param': 'param'})
            await tm.bind()
            self.assertEqual(tm._func_params.keys(), {'param': 'param'}.keys())
            self.assertNotEqual(tm.schedule, None)
            self.assertTrue(isinstance(tm.schedule, schedules.CronSchedule))
            self.assertEqual(tm.schedule.activation_metrics, [])
            self.assertEqual(tm.schedule.exec_on_load, False)
            self.assertIsNotNone(getattr(tm, 'f', None))
            self.assertTrue(asyncio.iscoroutinefunction(tm.f))
            tm_info = tmIndex.get_tm_info(tm.mid)
            self.assertEqual(tm_info['enabled'], False)
            self.assertEqual(tm_info['tm'], tm)
        except:
            raise
        finally:
            tmIndex.enable_tm = enable_tm_bck
Exemplo n.º 10
0
    def test_transfermethod_success_registering_decorated_transfermethod_CronSchedule(
            self):
        '''transfermethod object should be able to register a decorated transfer_method with CronSchedule '''
        def func(param):
            pass

        tm = transfer_methods.transfermethod(f_params={'param': 'param'},
                                             schedule=schedules.CronSchedule())
        self.assertTrue(isinstance(tm.mid, uuid.UUID))
        self.assertNotEqual(tm.schedule, None)
        self.assertTrue(isinstance(tm.schedule, schedules.CronSchedule))
        self.assertEqual(tm.f_params, {'param': 'param'})
        f = tm(func)
        self.assertEqual(f, func)
        self.assertEqual(tm._func_params.keys(), {'param': 'param'}.keys())
        self.assertNotEqual(tm.schedule, None)
        self.assertTrue(isinstance(tm.schedule, schedules.CronSchedule))
        self.assertEqual(tm.schedule.activation_metrics, [])
        self.assertEqual(tm.schedule.exec_on_load, False)
        self.assertIsNotNone(getattr(tm, 'f', None))
        self.assertTrue(asyncio.iscoroutinefunction(tm.f))
        tm_info = tmIndex.get_tm_info(tm.mid)
        self.assertEqual(tm_info['enabled'], False)
        self.assertEqual(tm_info['tm'], tm)
Exemplo n.º 11
0
 def test_transfer_method_CronSchedule_success(self):
     ''' creation of a transfermethod object should succeed if schedule is CronSchedule'''
     schedule = schedules.CronSchedule()
     tm = transfer_methods.transfermethod(schedule=schedule)
     self.assertEqual(tm.schedule, schedule)
Exemplo n.º 12
0
 def test_process_var_success_combining(self):
     ''' process_var should succeed if parameter is a combination of all above'''
     sc = schedules.CronSchedule()
     processed = sc._process_var('1,2,4-6,*/3,*/7', 20, 1)
     self.assertEqual(sorted(processed),
                      [1, 2, 3, 4, 5, 6, 7, 9, 12, 14, 15, 18])
Exemplo n.º 13
0
 def test_process_var_success_asterisk_slash(self):
     ''' process_var should succeed if parameter is */n type '''
     sc = schedules.CronSchedule()
     processed = sc._process_var('*/2', 10, 1)
     self.assertEqual(sorted(processed), [2, 4, 6, 8, 10])
Exemplo n.º 14
0
 def test_process_var_success_comma_separated_items(self):
     ''' process_var should succeed if parameter is a comma separated string with different items '''
     sc = schedules.CronSchedule()
     processed = sc._process_var('1,2,3,4,5', 10, 1)
     self.assertEqual(sorted(processed), [1, 2, 3, 4, 5])
Exemplo n.º 15
0
 def test_process_var_success_asterisk_char(self):
     ''' process_var should succeed if parameter is asterisk, returning a list of comma-separated integers between max_value and min_value '''
     sc = schedules.CronSchedule()
     processed = sc._process_var('*', 10, 1)
     self.assertEqual(sorted(processed), list(range(1, 11)))