Permalink
Browse files

Page objects: add assertion methods for portal messages.

  • Loading branch information...
1 parent 486ab59 commit 8e4db4aef1f7316759faf3f8bc6718fd25c96ef4 @jone jone committed Apr 2, 2013
Showing with 42 additions and 0 deletions.
  1. +22 −0 ftw/testing/pages.py
  2. +20 −0 ftw/testing/tests/test_pages_plone.py
View
22 ftw/testing/pages.py
@@ -189,6 +189,28 @@ def assert_portal_message(self, kind, message, assertion_info=''):
assertion_msg += '. Additional info %s' % str(assertion_info)
assert message in messages[kind], assertion_msg
+ def assert_no_portal_messages(self):
+ """Asserts that there are no portal messages.
+ """
+ locals()['__traceback_info__'] = browser().url
+ messages = self.portal_text_messages()
+
+ # kss empty portal message workaround
+ if messages['info'] == ['']:
+ messages['info'] = []
+
+ assert messages == {'info': [], 'warning': [], 'error': []}, \
+ 'Expected no portal messages but got: %s' % str(messages)
+
+ def assert_no_error_messages(self):
+ """Asserts that there are no error portal messages.
+ """
+ locals()['__traceback_info__'] = browser().url
+ messages = self.portal_text_messages()
+
+ assert messages['error'] == [], \
+ 'Expected no error portal messages but got: %s' % str(messages)
+
def open_add_form(self, type_name):
"""Opens the add form for adding an object of type `type_name` by
opening the add menu and clicking on the link.
View
20 ftw/testing/tests/test_pages_plone.py
@@ -203,3 +203,23 @@ def test_DEXTERITY_create_object_JAVASCRIPT(self):
self.assertEquals('%s/bar/view' % Plone().portal_url, browser().url)
self.assertEquals('Bar', Plone().get_first_heading(),
'Title of newly created page is wrong.')
+
+ def test_no_portal_messages(self):
+ Plone().visit_portal()
+ Plone().assert_no_portal_messages()
+
+ Plone().visit_portal('test_rendering')
+ with self.assertRaises(AssertionError) as cm:
+ Plone().assert_no_portal_messages()
+
+ self.assertEquals(
+ str(cm.exception),
+ "Expected no portal messages but got:"
+ " {'info': ['', 'The portalMessage class, can also contain"
+ " links - used to give the user temporary status messages.'],"
+ " 'warning': [],"
+ " 'error': []}")
+
+ def test_assert_no_error_messages(self):
+ Plone().visit_portal('test_rendering')
+ Plone().assert_no_error_messages()

0 comments on commit 8e4db4a

Please sign in to comment.