示例#1
0
文件: test_clock.py 项目: Carl4/scale
    def test_check_rule_name_error(self):
        '''Tests checking a rule with a name configuration problem.'''
        rule1 = job_test_utils.create_clock_rule(name=u'')
        self.assertRaises(ClockEventError, clock._check_rule, rule1)

        rule2 = job_test_utils.create_clock_rule(name=u'missing')
        self.assertRaises(ClockEventError, clock._check_rule, rule2)
示例#2
0
文件: test_clock.py 项目: sau29/scale
    def test_check_rule_name_error(self):
        """Tests checking a rule with a name configuration problem."""
        rule1 = job_test_utils.create_clock_rule(name='')
        self.assertRaises(ClockEventError, clock._check_rule, rule1)

        rule2 = job_test_utils.create_clock_rule(name='missing')
        self.assertRaises(ClockEventError, clock._check_rule, rule2)
示例#3
0
文件: test_clock.py 项目: sau29/scale
    def test_perform_tick(self, mock_check_rule):
        """Tests performing a single clock tick."""
        job_test_utils.create_clock_rule()
        job_test_utils.create_clock_rule()

        clock.perform_tick()

        self.assertEqual(mock_check_rule.call_count, 2)
示例#4
0
文件: test_clock.py 项目: Carl4/scale
    def test_perform_tick_skip(self, mock_check_rule):
        '''Tests performing a single clock tick with rules that should be skipped.'''
        job_test_utils.create_clock_rule(is_active=False)
        job_test_utils.create_clock_rule(rule_type=u'NOT_CLOCK')

        clock.perform_tick()

        self.assertFalse(mock_check_rule.called)
示例#5
0
文件: test_clock.py 项目: Carl4/scale
    def test_perform_tick(self, mock_check_rule):
        '''Tests performing a single clock tick.'''
        job_test_utils.create_clock_rule()
        job_test_utils.create_clock_rule()

        clock.perform_tick()

        self.assertEqual(mock_check_rule.call_count, 2)
示例#6
0
文件: test_clock.py 项目: sau29/scale
    def test_perform_tick_skip(self, mock_check_rule):
        """Tests performing a single clock tick with rules that should be skipped."""
        job_test_utils.create_clock_rule(is_active=False)
        job_test_utils.create_clock_rule(rule_type='NOT_CLOCK')

        clock.perform_tick()

        self.assertFalse(mock_check_rule.called)
示例#7
0
文件: test_clock.py 项目: sau29/scale
    def test_check_rule_schedule_error(self):
        """Tests checking a rule with a schedule configuration problem."""
        rule1 = job_test_utils.create_clock_rule(schedule='')
        self.assertRaises(ClockEventError, clock._check_rule, rule1)

        rule2 = job_test_utils.create_clock_rule(schedule='invalid')
        self.assertRaises(ClockEventError, clock._check_rule, rule2)

        rule3 = job_test_utils.create_clock_rule(schedule='1H0M0S')
        self.assertRaises(ClockEventError, clock._check_rule, rule1)
示例#8
0
文件: test_clock.py 项目: Carl4/scale
    def test_perform_tick_error(self, mock_check_rule):
        '''Tests performing a clock tick will continue even when rules fail.'''
        mock_check_rule.side_effect = ClockEventError()

        job_test_utils.create_clock_rule()
        job_test_utils.create_clock_rule()

        clock.perform_tick()

        self.assertEqual(mock_check_rule.call_count, 2)
示例#9
0
文件: test_clock.py 项目: sau29/scale
    def test_perform_tick_error(self, mock_check_rule):
        """Tests performing a clock tick will continue even when rules fail."""
        mock_check_rule.side_effect = ClockEventError()

        job_test_utils.create_clock_rule()
        job_test_utils.create_clock_rule()

        clock.perform_tick()

        self.assertEqual(mock_check_rule.call_count, 2)
示例#10
0
文件: test_clock.py 项目: Carl4/scale
    def test_check_rule_schedule_error(self):
        '''Tests checking a rule with a schedule configuration problem.'''
        rule1 = job_test_utils.create_clock_rule(schedule=u'')
        self.assertRaises(ClockEventError, clock._check_rule, rule1)

        rule2 = job_test_utils.create_clock_rule(schedule=u'invalid')
        self.assertRaises(ClockEventError, clock._check_rule, rule2)

        rule3 = job_test_utils.create_clock_rule(schedule=u'1H0M0S')
        self.assertRaises(ClockEventError, clock._check_rule, rule1)
示例#11
0
    def test_check_rule_last_event(self, mock_check_schedule,
                                   mock_trigger_event):
        '''Tests a valid rule checks the most recent matching event type.'''
        rule = job_test_utils.create_clock_rule(name='test-name',
                                                schedule='PT1H0M0S')
        job_test_utils.create_clock_event(rule=rule,
                                          occurred=datetime.datetime(
                                              2013, 1, 1, tzinfo=timezone.utc))
        job_test_utils.create_clock_event(rule=rule,
                                          occurred=datetime.datetime(
                                              2012, 1, 1, tzinfo=timezone.utc))
        last = job_test_utils.create_clock_event(rule=rule,
                                                 occurred=datetime.datetime(
                                                     2014,
                                                     1,
                                                     1,
                                                     tzinfo=timezone.utc))
        job_test_utils.create_clock_event(rule=rule,
                                          occurred=datetime.datetime(
                                              2011, 1, 1, tzinfo=timezone.utc))
        job_test_utils.create_clock_event(
            occurred=datetime.datetime(2015, 1, 1, tzinfo=timezone.utc))

        clock._check_rule(rule)

        mock_check_schedule.assert_called_with(datetime.timedelta(hours=1),
                                               last)
示例#12
0
    def test_multiple_processors(self):
        """Tests running multiple processors for the same trigger rule."""
        clock.register_processor('test-name', lambda: self.processor)

        rule = job_test_utils.create_clock_rule(name='test-name', event_type='TEST_TYPE')
        clock._trigger_event(rule)

        self.assertEqual(self.processor.process_event.call_count, 2)
示例#13
0
文件: test_clock.py 项目: sau29/scale
    def test_multiple_processors(self):
        """Tests running multiple processors for the same trigger rule."""
        clock.register_processor('test-name', lambda: self.processor)

        rule = job_test_utils.create_clock_rule(name='test-name', event_type='TEST_TYPE')
        clock._trigger_event(rule)

        self.assertEqual(self.processor.process_event.call_count, 2)
示例#14
0
文件: test_clock.py 项目: Carl4/scale
    def test_trigger_event_first(self):
        '''Tests triggering a new event the first time for a rule.'''
        rule = job_test_utils.create_clock_rule(name=u'test-name', event_type=u'TEST_TYPE')

        clock._trigger_event(rule, None)

        events = TriggerEvent.objects.filter(type=u'TEST_TYPE')
        self.assertEqual(len(events), 1)
        self.processor.process_event.assert_called_with(events[0], None)
示例#15
0
文件: test_clock.py 项目: sau29/scale
    def test_trigger_event_first(self):
        """Tests triggering a new event the first time for a rule."""
        rule = job_test_utils.create_clock_rule(name='test-name', event_type='TEST_TYPE')

        clock._trigger_event(rule, None)

        events = TriggerEvent.objects.filter(type='TEST_TYPE')
        self.assertEqual(len(events), 1)
        self.processor.process_event.assert_called_with(events[0], None)
示例#16
0
文件: test_clock.py 项目: sau29/scale
    def test_check_rule(self, mock_check_schedule, mock_trigger_event):
        """Tests a valid rule triggers a new event."""
        mock_check_schedule.return_value = True

        rule = job_test_utils.create_clock_rule(name='test-name', schedule='PT1H0M0S')

        clock._check_rule(rule)

        mock_check_schedule.assert_called_with(datetime.timedelta(hours=1), None)
        self.assertTrue(mock_trigger_event.called)
示例#17
0
文件: test_clock.py 项目: Carl4/scale
    def test_check_rule(self, mock_check_schedule, mock_trigger_event):
        '''Tests a valid rule triggers a new event.'''
        mock_check_schedule.return_value = True

        rule = job_test_utils.create_clock_rule(name=u'test-name', schedule=u'PT1H0M0S')

        clock._check_rule(rule)

        mock_check_schedule.assert_called_with(datetime.timedelta(hours=1), None)
        self.assertTrue(mock_trigger_event.called)
示例#18
0
文件: test_clock.py 项目: Carl4/scale
    def test_check_rule_skip(self, mock_check_schedule, mock_trigger_event):
        '''Tests a valid rule does not trigger a new event when the schedule threshold has not been met.'''
        mock_check_schedule.return_value = False

        rule = job_test_utils.create_clock_rule(name=u'test-name')

        clock._check_rule(rule)

        self.assertTrue(mock_check_schedule.called)
        self.assertFalse(mock_trigger_event.called)
示例#19
0
文件: test_clock.py 项目: sau29/scale
    def test_check_rule_skip(self, mock_check_schedule, mock_trigger_event):
        """Tests a valid rule does not trigger a new event when the schedule threshold has not been met."""
        mock_check_schedule.return_value = False

        rule = job_test_utils.create_clock_rule(name='test-name')

        clock._check_rule(rule)

        self.assertTrue(mock_check_schedule.called)
        self.assertFalse(mock_trigger_event.called)
示例#20
0
文件: test_clock.py 项目: Carl4/scale
    def test_trigger_event_last(self):
        '''Tests triggering a new event after the rule has processed an event previously.'''
        rule = job_test_utils.create_clock_rule(name=u'test-name', event_type=u'TEST_TYPE')
        last = job_test_utils.create_clock_event(rule=rule, occurred=datetime.datetime(2015, 1, 1, tzinfo=timezone.utc))

        clock._trigger_event(rule, last)

        events = TriggerEvent.objects.filter(type=u'TEST_TYPE').order_by(u'-occurred')
        self.assertEqual(len(events), 2)
        self.assertNotEqual(events[0], last)
        self.processor.process_event.assert_called_with(events[0], last)
示例#21
0
文件: test_clock.py 项目: sau29/scale
    def test_trigger_event_last(self):
        """Tests triggering a new event after the rule has processed an event previously."""
        rule = job_test_utils.create_clock_rule(name='test-name', event_type='TEST_TYPE')
        last = job_test_utils.create_clock_event(rule=rule, occurred=datetime.datetime(2015, 1, 1, tzinfo=utc))

        clock._trigger_event(rule, last)

        events = TriggerEvent.objects.filter(type='TEST_TYPE').order_by('-occurred')
        self.assertEqual(len(events), 2)
        self.assertNotEqual(events[0], last)
        self.processor.process_event.assert_called_with(events[0], last)
示例#22
0
文件: test_clock.py 项目: Carl4/scale
    def test_check_rule_last_event(self, mock_check_schedule, mock_trigger_event):
        '''Tests a valid rule checks the most recent matching event type.'''
        rule = job_test_utils.create_clock_rule(name=u'test-name', schedule=u'PT1H0M0S')
        job_test_utils.create_clock_event(rule=rule, occurred=datetime.datetime(2013, 1, 1, tzinfo=timezone.utc))
        job_test_utils.create_clock_event(rule=rule, occurred=datetime.datetime(2012, 1, 1, tzinfo=timezone.utc))
        last = job_test_utils.create_clock_event(rule=rule, occurred=datetime.datetime(2014, 1, 1, tzinfo=timezone.utc))
        job_test_utils.create_clock_event(rule=rule, occurred=datetime.datetime(2011, 1, 1, tzinfo=timezone.utc))
        job_test_utils.create_clock_event(occurred=datetime.datetime(2015, 1, 1, tzinfo=timezone.utc))

        clock._check_rule(rule)

        mock_check_schedule.assert_called_with(datetime.timedelta(hours=1), last)
示例#23
0
文件: test_clock.py 项目: sau29/scale
 def test_check_rule_event_type_error(self):
     """Tests checking a rule with an event type configuration problem."""
     rule = job_test_utils.create_clock_rule(event_type='')
     self.assertRaises(ClockEventError, clock._check_rule, rule)
示例#24
0
文件: test_clock.py 项目: Carl4/scale
 def test_check_rule_event_type_error(self):
     '''Tests checking a rule with an event type configuration problem.'''
     rule = job_test_utils.create_clock_rule(event_type=u'')
     self.assertRaises(ClockEventError, clock._check_rule, rule)