From 7e1548516762cf599bf2c720c7d3a46113e3c8b9 Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Tue, 22 Jan 2013 13:37:43 +0000 Subject: [PATCH] heat tests : test_watch add tests for set_watch_state Add some tests providing coverage for the set_watch_state function Change-Id: Ia9f418035440c0941e25dd2e1ec85f8c0322d807 Signed-off-by: Steven Hardy --- heat/tests/test_watch.py | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/heat/tests/test_watch.py b/heat/tests/test_watch.py index aaa7d0de..12b96159 100644 --- a/heat/tests/test_watch.py +++ b/heat/tests/test_watch.py @@ -570,3 +570,57 @@ class WatchRuleTest(unittest.TestCase): # Cleanup db_api.watch_rule_delete(self.ctx, 'create_data_test') + + def test_set_watch_state(self): + rule = {'EvaluationPeriods': '1', + 'MetricName': 'test_metric', + 'AlarmActions': ['DummyAction'], + 'Period': '300', + 'Statistic': 'Maximum', + 'ComparisonOperator': 'GreaterThanOrEqualToThreshold', + 'Threshold': '30'} + + now = timeutils.utcnow() + self._action_set_stubs(now) + + # Set data so rule evaluates to ALARM state + last = now - datetime.timedelta(seconds=200) + watcher = watchrule.WatchRule(context=self.ctx, + watch_name="testwatch", + rule=rule, + watch_data=[], + stack_id=self.stack_id, + last_evaluated=last) + + actions = watcher.set_watch_state(watchrule.WatchRule.NODATA) + self.assertEqual(actions, []) + + actions = watcher.set_watch_state(watchrule.WatchRule.NORMAL) + self.assertEqual(actions, []) + + actions = watcher.set_watch_state(watchrule.WatchRule.ALARM) + self.assertEqual(actions, ['DummyAction']) + + def test_set_watch_state_invalid(self): + rule = {'EvaluationPeriods': '1', + 'MetricName': 'test_metric', + 'AlarmActions': ['DummyAction'], + 'Period': '300', + 'Statistic': 'Maximum', + 'ComparisonOperator': 'GreaterThanOrEqualToThreshold', + 'Threshold': '30'} + + now = timeutils.utcnow() + self._action_set_stubs(now) + + last = now - datetime.timedelta(seconds=200) + watcher = watchrule.WatchRule(context=self.ctx, + watch_name="testwatch", + rule=rule, + watch_data=[], + stack_id=self.stack_id, + last_evaluated=last) + + self.assertRaises(ValueError, watcher.set_watch_state, None) + + self.assertRaises(ValueError, watcher.set_watch_state, "BADSTATE") -- 2.45.2