97 lines
2.8 KiB
Python
97 lines
2.8 KiB
Python
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)
|