fix atom link in XML Version API
This patch fixes tag names where the tag name has ':' for links templates. Some examples are '{http://www.w3.org/2005/Atom}link' should be ['{http://www.w3.org/2005/Atom}link'] and 'test1:test2' should be ['test1', 'test2'] Closes-Bug: #1311243 Change-Id: I6e7c068e41eb6b069c24ef9d6c46b726ea722074
This commit is contained in:
parent
07f64deb5a
commit
a5a33a6833
@ -14,6 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
|
import re
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
@ -29,6 +30,8 @@ XMLNS_VOLUME_V1 = 'http://docs.openstack.org/volume/api/v1'
|
|||||||
XMLNS_VOLUME_V2 = ('http://docs.openstack.org/api/openstack-volume/2.0/'
|
XMLNS_VOLUME_V2 = ('http://docs.openstack.org/api/openstack-volume/2.0/'
|
||||||
'content')
|
'content')
|
||||||
|
|
||||||
|
_split_pattern = re.compile(r'([^:{]*{[^}]*}[^:]*|[^:]+)')
|
||||||
|
|
||||||
|
|
||||||
def validate_schema(xml, schema_name):
|
def validate_schema(xml, schema_name):
|
||||||
if isinstance(xml, str):
|
if isinstance(xml, str):
|
||||||
@ -356,6 +359,10 @@ class TemplateElement(object):
|
|||||||
pass
|
pass
|
||||||
return tmpattrib
|
return tmpattrib
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _splitTagName(name):
|
||||||
|
return _split_pattern.findall(name)
|
||||||
|
|
||||||
def _render(self, parent, datum, patches, nsmap):
|
def _render(self, parent, datum, patches, nsmap):
|
||||||
"""Internal rendering.
|
"""Internal rendering.
|
||||||
|
|
||||||
@ -382,7 +389,7 @@ class TemplateElement(object):
|
|||||||
else:
|
else:
|
||||||
tmpattrib = {}
|
tmpattrib = {}
|
||||||
|
|
||||||
tagnameList = tagname.split(':')
|
tagnameList = self._splitTagName(tagname)
|
||||||
insertIndex = 0
|
insertIndex = 0
|
||||||
|
|
||||||
#If parent is not none and has same tagname
|
#If parent is not none and has same tagname
|
||||||
|
@ -472,6 +472,18 @@ class TemplateTest(test.TestCase):
|
|||||||
self.assertEqual(len(siblings), 1)
|
self.assertEqual(len(siblings), 1)
|
||||||
self.assertEqual(siblings[0], elem)
|
self.assertEqual(siblings[0], elem)
|
||||||
|
|
||||||
|
def test__splitTagName(self):
|
||||||
|
test_cases = [
|
||||||
|
('a', ['a']),
|
||||||
|
('a:b', ['a', 'b']),
|
||||||
|
('{http://test.com}a:b', ['{http://test.com}a', 'b']),
|
||||||
|
('a:b{http://test.com}:c', ['a', 'b{http://test.com}', 'c']),
|
||||||
|
]
|
||||||
|
|
||||||
|
for test_case, expected in test_cases:
|
||||||
|
result = xmlutil.TemplateElement._splitTagName(test_case)
|
||||||
|
self.assertEqual(expected, result)
|
||||||
|
|
||||||
def test__nsmap(self):
|
def test__nsmap(self):
|
||||||
# Set up a basic template
|
# Set up a basic template
|
||||||
elem = xmlutil.TemplateElement('test')
|
elem = xmlutil.TemplateElement('test')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user