]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
heat tests : test_watch add create_watch_data test
authorSteven Hardy <shardy@redhat.com>
Tue, 22 Jan 2013 13:15:20 +0000 (13:15 +0000)
committerSteven Hardy <shardy@redhat.com>
Tue, 22 Jan 2013 13:15:20 +0000 (13:15 +0000)
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 <shardy@redhat.com>
heat/tests/test_watch.py

index e62109b4003825b4403db1b3a3d79f619e37671f..aaa7d0def733ada42f10b9f34159e824ae2ade9e 100644 (file)
@@ -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')