Commit 1d9b8139 authored by Jérome Perrin's avatar Jérome Perrin

test: use xpath when checking for HTML

parent 544cb918
...@@ -27,12 +27,13 @@ ...@@ -27,12 +27,13 @@
# #
############################################################################## ##############################################################################
import lxml.html
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Type.tests.Sequence import SequenceList from Products.ERP5Type.tests.Sequence import SequenceList
class TestGUISecurity(ERP5TypeTestCase): class TestGUISecurity(ERP5TypeTestCase):
""" """
""" """
...@@ -82,9 +83,10 @@ class TestGUISecurity(ERP5TypeTestCase): ...@@ -82,9 +83,10 @@ class TestGUISecurity(ERP5TypeTestCase):
Try to view the Foo_view form, make sure our category name is displayed Try to view the Foo_view form, make sure our category name is displayed
""" """
self.loginAs() self.loginAs()
self.assertIn( self.assertTrue(
self.category_field_markup, lxml.html.fromstring(
self.portal.foo_module.foo.Foo_view()) self.portal.foo_module.foo.Foo_view()
).xpath(self.category_field_xpath))
self.login() self.login()
def stepAccessFooDoesNotDisplayCategoryName(self, sequence = None, sequence_list = None, **kw): def stepAccessFooDoesNotDisplayCategoryName(self, sequence = None, sequence_list = None, **kw):
...@@ -92,9 +94,10 @@ class TestGUISecurity(ERP5TypeTestCase): ...@@ -92,9 +94,10 @@ class TestGUISecurity(ERP5TypeTestCase):
Try to view the Foo_view form, make sure our category name is not displayed Try to view the Foo_view form, make sure our category name is not displayed
""" """
self.loginAs() self.loginAs()
self.assertNotIn( self.assertFalse(
self.category_field_markup, lxml.html.fromstring(
self.portal.foo_module.foo.Foo_view()) self.portal.foo_module.foo.Foo_view()
).xpath(self.category_field_xpath))
self.login() self.login()
def stepChangeCategorySecurity(self, sequence = None, sequence_list = None, **kw): def stepChangeCategorySecurity(self, sequence = None, sequence_list = None, **kw):
...@@ -127,7 +130,7 @@ class TestGUISecurity(ERP5TypeTestCase): ...@@ -127,7 +130,7 @@ class TestGUISecurity(ERP5TypeTestCase):
An attempt to view the document form would raise Unauthorized. An attempt to view the document form would raise Unauthorized.
""" """
# this really depends on the generated markup # this really depends on the generated markup
self.category_field_markup = '<input name="field_my_foo_category_title" value="a" type="text"' self.category_field_xpath = '//input[@name="field_my_foo_category_title" and @type="text" and @value="a"]'
sequence_list = SequenceList() sequence_list = SequenceList()
sequence_string = '\ sequence_string = '\
...@@ -156,11 +159,18 @@ class TestGUISecurity(ERP5TypeTestCase): ...@@ -156,11 +159,18 @@ class TestGUISecurity(ERP5TypeTestCase):
self.stepCreateObjects() self.stepCreateObjects()
self.stepCreateTestFoo() self.stepCreateTestFoo()
protected_property_markup = '<input name="field_my_protected_property" value="Protected Property" type="text"' protected_property_xpath = '//input[@name="field_my_protected_property" and @type="text" and @value="Protected Property"]'
self.assertIn(protected_property_markup, self.portal.foo_module.foo.Foo_viewSecurity())
self.assertTrue(
lxml.html.fromstring(
self.portal.foo_module.foo.Foo_viewSecurity()
).xpath(protected_property_xpath))
self.loginAs() # user without permission to access protected property self.loginAs() # user without permission to access protected property
self.assertNotIn(protected_property_markup, self.portal.foo_module.foo.Foo_viewSecurity()) self.assertFalse(
lxml.html.fromstring(
self.portal.foo_module.foo.Foo_viewSecurity()
).xpath(protected_property_xpath))
def test_translated_state_title_lookup(self): def test_translated_state_title_lookup(self):
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment