]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
heat tests : add test for new manager show_watch_metric method
authorSteven Hardy <shardy@redhat.com>
Tue, 28 Aug 2012 08:33:01 +0000 (09:33 +0100)
committerSteven Hardy <shardy@redhat.com>
Tue, 28 Aug 2012 08:33:01 +0000 (09:33 +0100)
Add unit tests for new manager show_watch_metric action

Change-Id: Ie1b7c0a0e1eb5c7e5fad74674b1a9669bf7c9a1c
Signed-off-by: Steven Hardy <shardy@redhat.com>
heat/tests/test_stacks.py

index d48e8a1d8647ab20e0c12a6c6fd93b27ef9ef528..42e647217b4df1220875b7ddfdc266f770e7034e 100644 (file)
@@ -400,6 +400,33 @@ class stackManagerTest(unittest.TestCase):
         for key in engine_api.WATCH_KEYS:
             self.assertTrue(key in result[0])
 
+    def test_show_watch_metric(self):
+        # Get one of the  watch rules created in test_show_watch
+        # And add a metric datapoint
+        watch = db_api.watch_rule_get(self.ctx, "HttpFailureAlarm")
+        self.assertNotEqual(watch, None)
+        values = {'watch_rule_id': watch.id,
+                  'data': {
+                        u'Namespace': u'system/linux',
+                        u'ServiceFailure': {
+                            u'Units': u'Counter', u'Value': 1}}}
+        watch = db_api.watch_data_create(self.ctx, values)
+
+        # Check there is one result returned
+        result = self.man.show_watch_metric(self.ctx, namespace=None,
+                                            metric_name=None)
+        self.assertEqual(1, len(result))
+
+        # Create another metric datapoint and check we get two
+        watch = db_api.watch_data_create(self.ctx, values)
+        result = self.man.show_watch_metric(self.ctx, namespace=None,
+                                            metric_name=None)
+        self.assertEqual(2, len(result))
+
+        # Check the response has all keys defined in the engine API
+        for key in engine_api.WATCH_DATA_KEYS:
+            self.assertTrue(key in result[0])
+
 
 # allows testing of the test directly
 if __name__ == '__main__':