[IMP] add tests for locate_node
bzr revid: xmo@openerp.com-20130422091014-qbd4jun4n9u4402x
This commit is contained in:
parent
aa9406e28b
commit
c9a6e74bf4
|
@ -192,9 +192,8 @@ class view(osv.osv):
|
|||
for node in arch.getiterator(spec.tag):
|
||||
if isinstance(node, SKIPPED_ELEMENT_TYPES):
|
||||
continue
|
||||
if all(node.get(attr) == spec.get(attr) \
|
||||
for attr in spec.attrib
|
||||
if attr not in ('position','version')):
|
||||
if all(node.get(attr) == spec.get(attr) for attr in spec.attrib
|
||||
if attr not in ('position','version')):
|
||||
# Version spec should match parent's root element's version
|
||||
if spec.get('version') and spec.get('version') != arch.get('version'):
|
||||
return None
|
||||
|
|
|
@ -22,6 +22,7 @@ import test_osv
|
|||
import test_translate
|
||||
import test_uninstall
|
||||
import test_view_validation
|
||||
import test_views
|
||||
# This need a change in `oe run-tests` to only run fast_suite + checks by default.
|
||||
# import test_xmlrpc
|
||||
|
||||
|
@ -42,6 +43,7 @@ checks = [
|
|||
test_misc,
|
||||
test_osv,
|
||||
test_translate,
|
||||
test_views,
|
||||
]
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
from lxml import etree as ET
|
||||
from lxml.builder import E
|
||||
|
||||
from . import common
|
||||
|
||||
Field = E.field
|
||||
|
||||
class TestNodeLocator(common.BaseCase):
|
||||
"""
|
||||
The node locator returns None when it can not find a node, and the first
|
||||
match when it finds something (no jquery-style node sets)
|
||||
"""
|
||||
def setUp(self):
|
||||
super(TestNodeLocator, self).setUp()
|
||||
self.Views = self.registry('ir.ui.view')
|
||||
|
||||
def test_no_match_xpath(self):
|
||||
"""
|
||||
xpath simply uses the provided @expr pattern to find a node
|
||||
"""
|
||||
node = self.Views.locate_node(
|
||||
E.root(E.foo(), E.bar(), E.baz()),
|
||||
E.xpath(expr="//qux"))
|
||||
self.assertIsNone(node)
|
||||
|
||||
def test_match_xpath(self):
|
||||
bar = E.bar()
|
||||
node = self.Views.locate_node(
|
||||
E.root(E.foo(), bar, E.baz()),
|
||||
E.xpath(expr="//bar"))
|
||||
self.assertIs(node, bar)
|
||||
|
||||
|
||||
def test_no_match_field(self):
|
||||
"""
|
||||
A field spec will match by @name against all fields of the view
|
||||
"""
|
||||
node = self.Views.locate_node(
|
||||
E.root(E.foo(), E.bar(), E.baz()),
|
||||
Field(name="qux"))
|
||||
self.assertIsNone(node)
|
||||
|
||||
node = self.Views.locate_node(
|
||||
E.root(Field(name="foo"), Field(name="bar"), Field(name="baz")),
|
||||
Field(name="qux"))
|
||||
self.assertIsNone(node)
|
||||
|
||||
def test_match_field(self):
|
||||
bar = Field(name="bar")
|
||||
node = self.Views.locate_node(
|
||||
E.root(Field(name="foo"), bar, Field(name="baz")),
|
||||
Field(name="bar"))
|
||||
self.assertIs(node, bar)
|
||||
|
||||
|
||||
def test_no_match_other(self):
|
||||
"""
|
||||
Non-xpath non-fields are matched by node name first
|
||||
"""
|
||||
node = self.Views.locate_node(
|
||||
E.root(E.foo(), E.bar(), E.baz()),
|
||||
E.qux())
|
||||
self.assertIsNone(node)
|
||||
|
||||
def test_match_other(self):
|
||||
bar = E.bar()
|
||||
node = self.Views.locate_node(
|
||||
E.root(E.foo(), bar, E.baz()),
|
||||
E.bar())
|
||||
self.assertIs(bar, node)
|
||||
|
||||
def test_attribute_mismatch(self):
|
||||
"""
|
||||
Non-xpath non-field are filtered by matching attributes on spec and
|
||||
matched nodes
|
||||
"""
|
||||
node = self.Views.locate_node(
|
||||
E.root(E.foo(attr='1'), E.bar(attr='2'), E.baz(attr='3')),
|
||||
E.bar(attr='5'))
|
||||
self.assertIsNone(node)
|
||||
|
||||
def test_attribute_filter(self):
|
||||
match = E.bar(attr='2')
|
||||
node = self.Views.locate_node(
|
||||
E.root(E.bar(attr='1'), match, E.root(E.bar(attr='3'))),
|
||||
E.bar(attr='2'))
|
||||
self.assertIs(node, match)
|
||||
|
||||
def test_version_mismatch(self):
|
||||
"""
|
||||
A @version on the spec will be matched against the view's version
|
||||
"""
|
||||
node = self.Views.locate_node(
|
||||
E.root(E.foo(attr='1'), version='4'),
|
||||
E.foo(attr='1', version='3'))
|
||||
self.assertIsNone(node)
|
Loading…
Reference in New Issue