]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
heat tests : functional test utils add response_xml_item
authorSteven Hardy <shardy@redhat.com>
Wed, 12 Sep 2012 11:07:51 +0000 (12:07 +0100)
committerSteven Hardy <shardy@redhat.com>
Thu, 13 Sep 2012 16:43:04 +0000 (17:43 +0100)
Add response_xml_item method to Stack, which allows stack
API XML responses to be more easily parsed base on xpath
prefix and keyname

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

index b296ff109efda21332023976b144d4f6acb8ff75..ac44423b30a09888c61e3f6d32e19ecb4f117e48 100644 (file)
@@ -437,6 +437,19 @@ class Stack(object):
         value = output.findtext('OutputValue')
         return value
 
+    def response_xml_item(self, response, prefix, key):
+        '''
+        Extract response item via xpath prefix and key name
+        we expect the prefix to map to a single Element item
+        '''
+        root = etree.fromstring(response)
+        output_list = root.xpath(prefix)
+        assert output_list
+        assert len(output_list) == 1
+        output = output_list.pop()
+        value = output.findtext(key)
+        return value
+
 
 class StackBoto(Stack):
     '''