From: Steven Hardy Date: Tue, 22 Jan 2013 13:15:20 +0000 (+0000) Subject: heat tests : test_watch add create_watch_data test X-Git-Tag: 2014.1~977 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=fa80030eb720e45757e123f386bffd4f1cede8a6;p=openstack-build%2Fheat-build.git heat tests : test_watch add create_watch_data test Add test for create_watch_data, note there are some limitations on what we can test here due to weird sqlite behavior with the relationships defined in the sqlalchemy model Change-Id: I2616b6dcf163914619321e9ff08e37f3f365d7db Signed-off-by: Steven Hardy --- diff --git a/heat/tests/test_watch.py b/heat/tests/test_watch.py index e62109b4..aaa7d0de 100644 --- a/heat/tests/test_watch.py +++ b/heat/tests/test_watch.py @@ -538,3 +538,35 @@ class WatchRuleTest(unittest.TestCase): actions = watcher.evaluate() self.assertEqual(watcher.state, 'NODATA') self.assertEqual(actions, ['DummyAction']) + + def test_create_watch_data(self): + rule = {u'EvaluationPeriods': u'1', + u'AlarmDescription': u'test alarm', + u'Period': u'300', + u'ComparisonOperator': u'GreaterThanThreshold', + u'Statistic': u'SampleCount', + u'Threshold': u'2', + u'MetricName': u'CreateDataMetric'} + wr = watchrule.WatchRule(context=self.ctx, + watch_name='create_data_test', + stack_id=self.stack_id, rule=rule) + + wr.store() + + data = {u'CreateDataMetric': {"Unit": "Counter", + "Value": "1", + "Dimensions": []}} + wr.create_watch_data(data) + + dbwr = db_api.watch_rule_get_by_name(self.ctx, 'create_data_test') + self.assertEqual(dbwr.watch_data[0].data, data) + + # Note, would be good to write another datapoint and check it + # but sqlite seems to not interpret the backreference correctly + # so dbwr.watch_data is always a list containing only the latest + # datapoint. In non-test use on mysql this is not the case, we + # correctly get a list of all datapoints where watch_rule_id == + # watch_rule.id, so leave it as a single-datapoint test for now. + + # Cleanup + db_api.watch_rule_delete(self.ctx, 'create_data_test')