From bccf6ba33ef6ad943fb5795cad046712ef98f0cc Mon Sep 17 00:00:00 2001 From: Philip Bauer Date: Thu, 7 Jun 2018 18:03:02 +0200 Subject: [PATCH] Revert "migrate all tests to use dexterity, fix most tests." This reverts commit 0093daad2a3e614f0161bd3c5ef0367aeecb7ff5. --- plone/app/contentrules/testing.py | 30 ----------- plone/app/contentrules/tests/assignment.txt | 3 -- plone/app/contentrules/tests/base.py | 30 ++++------- plone/app/contentrules/tests/multipublish.txt | 14 ++--- .../app/contentrules/tests/simplepublish.txt | 7 +-- .../contentrules/tests/test_action_copy.py | 15 ++++-- .../contentrules/tests/test_action_delete.py | 8 +-- .../contentrules/tests/test_action_logger.py | 6 ++- .../contentrules/tests/test_action_mail.py | 24 +++++---- .../contentrules/tests/test_action_move.py | 21 +++++--- .../contentrules/tests/test_action_notify.py | 4 ++ .../tests/test_action_workflow.py | 4 ++ plone/app/contentrules/tests/test_browser.py | 4 +- .../contentrules/tests/test_cascading_rule.py | 49 ++++++----------- .../tests/test_condition_group.py | 3 ++ .../tests/test_condition_portal_type.py | 3 ++ .../contentrules/tests/test_condition_role.py | 3 ++ .../tests/test_condition_tales_expression.py | 3 ++ .../tests/test_condition_wfstate.py | 3 ++ .../tests/test_condition_wftransition.py | 3 ++ .../contentrules/tests/test_configuration.py | 54 +++++++++++-------- plone/app/contentrules/tests/test_handlers.py | 12 ++--- .../tests/test_rule_assignment_mapping.py | 20 +------ .../tests/test_rule_management_views.py | 3 ++ .../app/contentrules/tests/test_traversal.py | 3 ++ 25 files changed, 152 insertions(+), 177 deletions(-) delete mode 100644 plone/app/contentrules/testing.py diff --git a/plone/app/contentrules/testing.py b/plone/app/contentrules/testing.py deleted file mode 100644 index 196ccab..0000000 --- a/plone/app/contentrules/testing.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- coding: utf-8 -*- -from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE -from plone.app.testing import FunctionalTesting -from plone.app.testing import IntegrationTesting -from plone.app.testing import PloneSandboxLayer - -import plone.app.contentrules - - -class PloneAppContentrulesLayer(PloneSandboxLayer): - - defaultBases = (PLONE_APP_CONTENTTYPES_FIXTURE,) - - def setUpZope(self, app, configurationContext): - self.loadZCML('testing.zcml', package=plone.app.contentrules.tests) - - -PLONE_APP_CONTENTRULES_FIXTURE = PloneAppContentrulesLayer() - - -PLONE_APP_CONTENTRULES_INTEGRATION_TESTING = IntegrationTesting( - bases=(PLONE_APP_CONTENTRULES_FIXTURE,), - name='PloneAppContentrulesLayer:IntegrationTesting', -) - - -PLONE_APP_CONTENTRULES_FUNCTIONAL_TESTING = FunctionalTesting( - bases=(PLONE_APP_CONTENTRULES_FIXTURE,), - name='PloneAppContentrulesLayer:FunctionalTesting', -) diff --git a/plone/app/contentrules/tests/assignment.txt b/plone/app/contentrules/tests/assignment.txt index 62e266b..9ea34af 100644 --- a/plone/app/contentrules/tests/assignment.txt +++ b/plone/app/contentrules/tests/assignment.txt @@ -2,12 +2,9 @@ Setup ----- >>> from plone.app.testing import SITE_OWNER_NAME, SITE_OWNER_PASSWORD - >>> from plone.app.testing import setRoles - >>> from plone.app.testing import TEST_USER_ID >>> from plone.testing.z2 import Browser >>> portal = layer['portal'] - >>> setRoles(portal, TEST_USER_ID, ['Manager']) >>> if 'news' not in layer['portal']: ... obj = portal.invokeFactory('Folder', 'news') >>> import transaction diff --git a/plone/app/contentrules/tests/base.py b/plone/app/contentrules/tests/base.py index 4bd5bf3..fcf6b70 100644 --- a/plone/app/contentrules/tests/base.py +++ b/plone/app/contentrules/tests/base.py @@ -1,34 +1,17 @@ # -*- coding: utf-8 -*- """Base class for integration tests, based on plone.app.testing """ -from plone.app.contentrules.testing import PLONE_APP_CONTENTRULES_INTEGRATION_TESTING # noqa: E501 -from plone.app.testing import login -from plone.app.testing import setRoles -from plone.app.testing import TEST_USER_ID -from plone.app.testing import TEST_USER_NAME -from zope.component import getMultiAdapter -import unittest +from plone.app.testing.bbb import PloneTestCase +from zope.component import getMultiAdapter -class ContentRulesTestCase(unittest.TestCase): +class ContentRulesTestCase(PloneTestCase): """Base class for integration tests for plone.app.contentrules. This may provide specific set-up and tear-down operations, or provide convenience methods. """ - layer = PLONE_APP_CONTENTRULES_INTEGRATION_TESTING - - def setUp(self): - self.portal = self.layer['portal'] - self.request = self.layer['request'] - login(self.portal, TEST_USER_NAME) - setRoles(self.portal, TEST_USER_ID, ['Manager']) - self.portal.invokeFactory('Folder', 'f1') - self.folder = self.portal['f1'] - self.folder.invokeFactory('Document', 'd1') - self.portal.invokeFactory('Folder', 'target') - def addAuthToRequest(self): portal = self.layer['portal'] request = self.layer['request'] @@ -36,3 +19,10 @@ def addAuthToRequest(self): (portal, request), name=u'authenticator') auth = authenticator.authenticator().split('value="')[1].rstrip('"/>') request.form['_authenticator'] = auth + + +class ContentRulesFunctionalTestCase(PloneTestCase): + """Base class for functional integration tests for plone.app.contentrules. + This may provide specific set-up and tear-down operations, or provide + convenience methods. + """ diff --git a/plone/app/contentrules/tests/multipublish.txt b/plone/app/contentrules/tests/multipublish.txt index d022797..7b9bbf9 100644 --- a/plone/app/contentrules/tests/multipublish.txt +++ b/plone/app/contentrules/tests/multipublish.txt @@ -6,19 +6,13 @@ Setup >>> from plone.app.testing import SITE_OWNER_NAME, SITE_OWNER_PASSWORD >>> from plone.testing.z2 import Browser - >>> from plone.app.testing import setRoles - >>> from plone.app.testing import TEST_USER_ID - - >>> portal = layer['portal'] - >>> setRoles(portal, TEST_USER_ID, ['Manager']) - >>> obj = portal.invokeFactory('Folder', 'news') - >>> import transaction - >>> transaction.commit() >>> browser = Browser(layer['app']) >>> browser.addHeader('Authorization', ... 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD)) + >>> portal = layer['portal'] + Let's visit the control panel and add a content rule. We'll add a rule with a triggering event of `Workflow state changed`: @@ -76,7 +70,7 @@ Let's go back and create two news items now: >>> browser.getControl('Add').click() >>> browser.getControl('Title').value = 'My news item' >>> browser.getControl('Save').click() - >>> 'Item created' in browser.contents + >>> 'Changes saved' in browser.contents True >>> browser.getLink('Home').click() @@ -85,7 +79,7 @@ Let's go back and create two news items now: >>> browser.getControl('Add').click() >>> browser.getControl('Title').value = 'Second news item' >>> browser.getControl('Save').click() - >>> 'Item created' in browser.contents + >>> 'Changes saved' in browser.contents True Now let's publish both simultaneously. diff --git a/plone/app/contentrules/tests/simplepublish.txt b/plone/app/contentrules/tests/simplepublish.txt index 9c74964..81e6826 100644 --- a/plone/app/contentrules/tests/simplepublish.txt +++ b/plone/app/contentrules/tests/simplepublish.txt @@ -3,13 +3,8 @@ Setup >>> from plone.app.testing import SITE_OWNER_NAME, SITE_OWNER_PASSWORD >>> from plone.testing.z2 import Browser - >>> from plone.app.testing import setRoles - >>> from plone.app.testing import TEST_USER_ID - >>> portal = layer['portal'] - >>> setRoles(portal, TEST_USER_ID, ['Manager']) - >>> # portal.portal_workflow.setDefaultChain('simple_publication_workflow') >>> if 'news' not in portal: ... obj = portal.invokeFactory('Folder', 'news') >>> import transaction @@ -75,7 +70,7 @@ Let's go back and create the news item now: >>> browser.getControl('Add').click() >>> browser.getControl('Title').value = 'My news item' >>> browser.getControl('Save').click() - >>> 'Item created' in browser.contents + >>> 'Changes saved' in browser.contents True >>> browser.getLink('State:').click() >>> ctrl = browser.getControl(name='workflow_action') # XXX fix label diff --git a/plone/app/contentrules/tests/test_action_copy.py b/plone/app/contentrules/tests/test_action_copy.py index 38e7cb7..9f1a552 100644 --- a/plone/app/contentrules/tests/test_action_copy.py +++ b/plone/app/contentrules/tests/test_action_copy.py @@ -3,7 +3,6 @@ from plone.app.contentrules.actions.copy import CopyEditFormView from plone.app.contentrules.rule import Rule from plone.app.contentrules.tests.base import ContentRulesTestCase -from plone.app.testing import setRoles from plone.app.testing import TEST_USER_ID from plone.contentrules.engine.interfaces import IRuleStorage from plone.contentrules.rule.interfaces import IExecutable @@ -23,6 +22,12 @@ def __init__(self, object): class TestCopyAction(ContentRulesTestCase): + def afterSetUp(self): + self.loginAsPortalOwner() + self.portal.invokeFactory('Folder', 'target') + self.login() + self.folder.invokeFactory('Document', 'd1') + def testRegistered(self): element = getUtility(IRuleAction, name='plone.actions.Copy') self.assertEqual('plone.actions.Copy', element.addview) @@ -79,7 +84,7 @@ def testExecuteWithError(self): self.assertFalse('d1' in self.portal.target.objectIds()) def testExecuteWithoutPermissionsOnTarget(self): - setRoles(self.portal, TEST_USER_ID, ('Member', )) + self.setRoles(('Member', )) e = CopyAction() e.target_folder = '/target' @@ -92,9 +97,9 @@ def testExecuteWithoutPermissionsOnTarget(self): self.assertTrue('d1' in self.portal.target.objectIds()) def testExecuteWithNamingConflict(self): - setRoles(self.portal, TEST_USER_ID, ('Manager', )) + self.setRoles(('Manager', )) self.portal.target.invokeFactory('Document', 'd1') - setRoles(self.portal, TEST_USER_ID, ('Member', )) + self.setRoles(('Member', )) e = CopyAction() e.target_folder = '/target' @@ -117,7 +122,7 @@ def testExecuteWithNamingConflictDoesNotStupidlyAcquireHasKey(self): self.folder.target.invokeFactory('Document', 'd1') e = CopyAction() - e.target_folder = '/f1/target' + e.target_folder = '/Members/{0}/target'.format(TEST_USER_ID) ex = getMultiAdapter( (self.folder.target, e, DummyEvent(self.folder.d1)), IExecutable) diff --git a/plone/app/contentrules/tests/test_action_delete.py b/plone/app/contentrules/tests/test_action_delete.py index 8e5f2e0..f778644 100644 --- a/plone/app/contentrules/tests/test_action_delete.py +++ b/plone/app/contentrules/tests/test_action_delete.py @@ -9,10 +9,6 @@ from zope.component import getUtility from zope.component.interfaces import IObjectEvent from zope.interface import implementer -from plone.app.testing import login -from plone.app.testing import TEST_USER_ID -from plone.app.testing import TEST_USER_NAME -from plone.app.testing import setRoles @implementer(IObjectEvent) @@ -24,6 +20,10 @@ def __init__(self, object): class TestDeleteAction(ContentRulesTestCase): + def afterSetUp(self): + self.setRoles(('Manager', )) + self.folder.invokeFactory('Document', 'd1') + def testRegistered(self): element = getUtility(IRuleAction, name='plone.actions.Delete') self.assertEqual('plone.actions.Delete', element.addview) diff --git a/plone/app/contentrules/tests/test_action_logger.py b/plone/app/contentrules/tests/test_action_logger.py index b2b5c21..6c72b95 100644 --- a/plone/app/contentrules/tests/test_action_logger.py +++ b/plone/app/contentrules/tests/test_action_logger.py @@ -29,6 +29,9 @@ def __init__(self, obj): class TestLoggerAction(ContentRulesTestCase): + def afterSetUp(self): + self.setRoles(('Manager', )) + def testRegistered(self): element = getUtility(IRuleAction, name='plone.actions.Logger') self.assertEqual('plone.actions.Logger', element.addview) @@ -75,7 +78,8 @@ def testProcessedMessage(self): e.message = 'Test log event : &c' self.assertEqual( - 'Test log event : ', + 'Test log event : ' + ''.format(TEST_USER_ID), ex.processedMessage(), ) diff --git a/plone/app/contentrules/tests/test_action_mail.py b/plone/app/contentrules/tests/test_action_mail.py index 9ed7c56..1bf04ac 100644 --- a/plone/app/contentrules/tests/test_action_mail.py +++ b/plone/app/contentrules/tests/test_action_mail.py @@ -31,9 +31,11 @@ def __init__(self, object): class TestMailAction(ContentRulesTestCase): - def setUp(self): - super(TestMailAction, self).setUp() - self.folder['d1'].setTitle(u'Wälkommen') + def afterSetUp(self): + self.setRoles(('Manager', )) + self.portal.invokeFactory('Folder', 'target') + self.folder.invokeFactory('Document', 'd1', + title='W\xc3\xa4lkommen'.decode('utf-8')) users = ( ('userone', 'User One', 'user@one.com', ('Manager', 'Member')), @@ -108,6 +110,7 @@ def testInvokeEditView(self): def testExecute(self): # this avoids sending mail as currentuser@foobar.com + self.loginAsPortalOwner() self.portal.portal_membership.getAuthenticatedMember().setProperties( email='currentuser@foobar.com') dummyMailHost = self._setup_mockmail() @@ -115,7 +118,8 @@ def testExecute(self): e.source = '$user_email' e.recipients = 'bar@foo.be, bar@foo.be, $reviewer_emails, ' \ '$manager_emails, $member_emails' - e.message = u"Päge '${title}' created in ${url} !" + e.message = "P\xc3\xa4ge '${title}' created in ${url} !".decode( + 'utf-8') ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)), IExecutable) ex() @@ -130,8 +134,9 @@ def testExecute(self): self.assertEqual('currentuser@foobar.com', mailSent.get('From')) # The output message should be a utf-8 encoded string self.assertEqual( - u"Päge 'Wälkommen' created in http://nohost/plone/f1/d1 !", - mailSent.get_payload()) + "P\xc3\xa4ge 'W\xc3\xa4lkommen' created in " + 'http://nohost/plone/Members/test_user_1_/d1 !', + mailSent.get_payload(decode=True)) # check interpolation of $reviewer_emails self.assertTrue('user@two.com' in sent_mails) @@ -176,7 +181,7 @@ def testExecuteNoSource(self): self.assertEqual('"plone@rulez" ', mailSent.get('From')) self.assertEqual('Document created !', - mailSent.get_payload()) + mailSent.get_payload(decode=True)) self._teardown_mockmail() def testExecuteMultiRecipients(self): @@ -195,14 +200,14 @@ def testExecuteMultiRecipients(self): self.assertEqual('bar@foo.be', mailSent.get('To')) self.assertEqual('foo@bar.be', mailSent.get('From')) self.assertEqual('Document created !', - mailSent.get_payload()) + mailSent.get_payload(decode=True)) mailSent = message_from_string(dummyMailHost.messages[1]) self.assertEqual('text/plain; charset="utf-8"', mailSent.get('Content-Type')) self.assertEqual('foo@bar.be', mailSent.get('To')) self.assertEqual('foo@bar.be', mailSent.get('From')) self.assertEqual('Document created !', - mailSent.get_payload()) + mailSent.get_payload(decode=True)) self._teardown_mockmail() def testExecuteExcludeActor(self): @@ -241,6 +246,7 @@ def testExecuteNoRecipients(self): ) def testExecuteBadMailHost(self): # Our goal is that mailing errors should not cause exceptions + self.loginAsPortalOwner() self.portal.portal_membership.getAuthenticatedMember().setProperties( email='currentuser@foobar.com') e = MailAction() diff --git a/plone/app/contentrules/tests/test_action_move.py b/plone/app/contentrules/tests/test_action_move.py index a06f350..136e46d 100644 --- a/plone/app/contentrules/tests/test_action_move.py +++ b/plone/app/contentrules/tests/test_action_move.py @@ -3,8 +3,7 @@ from plone.app.contentrules.actions.move import MoveEditFormView from plone.app.contentrules.rule import Rule from plone.app.contentrules.tests.base import ContentRulesTestCase -from plone.app.testing import setRoles -from plone.app.testing import TEST_USER_ID +from plone.app.testing import TEST_USER_ID as default_user from plone.contentrules.engine.interfaces import IRuleStorage from plone.contentrules.rule.interfaces import IExecutable from plone.contentrules.rule.interfaces import IRuleAction @@ -23,6 +22,12 @@ def __init__(self, object): class TestMoveAction(ContentRulesTestCase): + def afterSetUp(self): + self.loginAsPortalOwner() + self.portal.invokeFactory('Folder', 'target') + self.login() + self.folder.invokeFactory('Document', 'd1') + def testRegistered(self): element = getUtility(IRuleAction, name='plone.actions.Move') self.assertEqual('plone.actions.Move', element.addview) @@ -84,7 +89,7 @@ def testExecuteWithError(self): self.assertFalse('d1' in self.portal.target.objectIds()) def testExecuteWithoutPermissionsOnTarget(self): - setRoles(self.portal, TEST_USER_ID, ('Member', )) + self.setRoles(('Member', )) e = MoveAction() e.target_folder = '/target' @@ -97,9 +102,9 @@ def testExecuteWithoutPermissionsOnTarget(self): self.assertTrue('d1' in self.portal.target.objectIds()) def testExecuteWithNamingConflict(self): - setRoles(self.portal, TEST_USER_ID, ('Manager', )) + self.setRoles(('Manager', )) self.portal.target.invokeFactory('Document', 'd1') - setRoles(self.portal, TEST_USER_ID, ('Member', )) + self.setRoles(('Member', )) e = MoveAction() e.target_folder = '/target' @@ -113,9 +118,9 @@ def testExecuteWithNamingConflict(self): self.assertTrue('d1.1' in self.portal.target.objectIds()) def testExecuteWithSameSourceAndTargetFolder(self): - setRoles(self.portal, TEST_USER_ID, ('Manager', )) + self.setRoles(('Manager', )) self.portal.target.invokeFactory('Document', 'd1') - setRoles(self.portal, TEST_USER_ID, ('Member', )) + self.setRoles(('Member', )) e = MoveAction() e.target_folder = '/target' @@ -138,7 +143,7 @@ def testExecuteWithNamingConflictDoesNotStupidlyAcquireHasKey(self): self.folder.target.invokeFactory('Document', 'd1') e = MoveAction() - e.target_folder = '/f1/target' + e.target_folder = '/Members/{0}/target'.format(default_user) ex = getMultiAdapter( (self.folder.target, e, DummyEvent(self.folder.d1)), IExecutable) diff --git a/plone/app/contentrules/tests/test_action_notify.py b/plone/app/contentrules/tests/test_action_notify.py index 03fa951..47706ad 100644 --- a/plone/app/contentrules/tests/test_action_notify.py +++ b/plone/app/contentrules/tests/test_action_notify.py @@ -21,6 +21,10 @@ class DummyEvent(object): class TestNotifyAction(ContentRulesTestCase): + def afterSetUp(self): + self.setRoles(('Manager', )) + self.request = self.layer['request'] + def testRegistered(self): element = getUtility(IRuleAction, name='plone.actions.Notify') self.assertEqual('plone.actions.Notify', element.addview) diff --git a/plone/app/contentrules/tests/test_action_workflow.py b/plone/app/contentrules/tests/test_action_workflow.py index f102b18..d741d43 100644 --- a/plone/app/contentrules/tests/test_action_workflow.py +++ b/plone/app/contentrules/tests/test_action_workflow.py @@ -21,6 +21,10 @@ def __init__(self, object): class TestWorkflowAction(ContentRulesTestCase): + def afterSetUp(self): + self.setRoles(('Manager', )) + self.folder.invokeFactory('Document', 'd1') + def testRegistered(self): element = getUtility(IRuleAction, name='plone.actions.Workflow') self.assertEqual('plone.actions.Workflow', element.addview) diff --git a/plone/app/contentrules/tests/test_browser.py b/plone/app/contentrules/tests/test_browser.py index d9e0dda..031592a 100644 --- a/plone/app/contentrules/tests/test_browser.py +++ b/plone/app/contentrules/tests/test_browser.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from plone.app.contentrules.testing import PLONE_APP_CONTENTRULES_FUNCTIONAL_TESTING +from plone.app.testing.bbb import PTC_FUNCTIONAL_TESTING from plone.testing import layered import doctest @@ -17,5 +17,5 @@ def test_suite(): suite.addTest(layered( doctest.DocFileSuite(doc, package='plone.app.contentrules.tests', optionflags=optionflags), - layer=PLONE_APP_CONTENTRULES_FUNCTIONAL_TESTING)) + layer=PTC_FUNCTIONAL_TESTING)) return suite diff --git a/plone/app/contentrules/tests/test_cascading_rule.py b/plone/app/contentrules/tests/test_cascading_rule.py index 492115e..02e40c4 100644 --- a/plone/app/contentrules/tests/test_cascading_rule.py +++ b/plone/app/contentrules/tests/test_cascading_rule.py @@ -1,31 +1,28 @@ # -*- coding: utf-8 -*- from plone.app.contentrules.api import edit_rule_assignment -from plone.app.contentrules.testing import PLONE_APP_CONTENTRULES_FUNCTIONAL_TESTING from plone.app.contentrules.tests.base import ContentRulesTestCase -from plone.app.testing import applyProfile -from plone.app.testing import FunctionalTesting -from plone.app.testing import login -from plone.app.testing import setRoles -from plone.app.testing import TEST_USER_ID -from plone.app.testing import TEST_USER_NAME +from plone.app.contentrules.tests.test_configuration import TestContentrulesGSLayer # noqa +from plone.contentrules.engine.interfaces import IRuleStorage from zope.component import getUtility -import unittest +class TestCascadingRule(ContentRulesTestCase): -class TestCascadingRule(unittest.TestCase): + layer = TestContentrulesGSLayer - layer = PLONE_APP_CONTENTRULES_FUNCTIONAL_TESTING + def afterSetUp(self): + self.storage = getUtility(IRuleStorage) + self.loginAsPortalOwner() + if 'news' not in self.portal: + self.portal.invokeFactory('Folder', 'news') - def setUp(self): - self.portal = self.layer['portal'] - self.request = self.layer['request'] - login(self.portal, TEST_USER_NAME) - setRoles(self.portal, TEST_USER_ID, ['Manager']) - self.portal.invokeFactory('Folder', 'news') - self.portal.invokeFactory('Folder', 'events') + self.portal.news.setLocallyAllowedTypes(['News Item', 'Event']) + if 'events' not in self.portal: + self.portal.invokeFactory('Folder', 'events') - applyProfile(self.portal, 'plone.app.contentrules:testing') + portal_setup = self.portal.portal_setup + portal_setup.runAllImportStepsFromProfile( + 'profile-plone.app.contentrules:testing') edit_rule_assignment(self.portal, 'test4', bubbles=1, enabled=1) edit_rule_assignment(self.portal, 'test5', bubbles=1, enabled=1) @@ -33,23 +30,9 @@ def test_cascading_rule(self): # check that test2 rule and test4 rule are executed # test2 rule publishes the event in news folder # test4 rule moves it in events folder when it is published - - # FIXME: - # This fails at the moment since the ObjectAddedEvent - # of move-rule (test4) is triggered during container._setObject in - # _constructInstance: - # rval = container._setObject(id, obj) - # newid = isinstance(rval, six.string_types) and rval or id - # obj = container._getOb(newid) - # when the rule is executed the container changed and the object - # can no longer be found in the original container. - - # For Archetypes the workaround was to delay the execution of - # the action until IObjectInitializedEvent which we do not have :( - # See handlers.added - self.portal.news.invokeFactory('Event', 'my-event') event = self.portal.news['my-event'] + event.processForm() self.assertFalse('my-event' in self.portal.news) self.assertTrue('my-event' in self.portal.events) diff --git a/plone/app/contentrules/tests/test_condition_group.py b/plone/app/contentrules/tests/test_condition_group.py index b51a936..4d38142 100644 --- a/plone/app/contentrules/tests/test_condition_group.py +++ b/plone/app/contentrules/tests/test_condition_group.py @@ -21,6 +21,9 @@ def __init__(self, obj): class TestGroupCondition(ContentRulesTestCase): + def afterSetUp(self): + self.setRoles(('Manager', )) + def testRegistered(self): element = getUtility(IRuleCondition, name='plone.conditions.Group') self.assertEqual('plone.conditions.Group', element.addview) diff --git a/plone/app/contentrules/tests/test_condition_portal_type.py b/plone/app/contentrules/tests/test_condition_portal_type.py index 1f6842f..9126051 100644 --- a/plone/app/contentrules/tests/test_condition_portal_type.py +++ b/plone/app/contentrules/tests/test_condition_portal_type.py @@ -22,6 +22,9 @@ def __init__(self, obj): class TestPortalTypeCondition(ContentRulesTestCase): + def afterSetUp(self): + self.setRoles(('Manager', )) + def testRegistered(self): element = getUtility( IRuleCondition, name='plone.conditions.PortalType') diff --git a/plone/app/contentrules/tests/test_condition_role.py b/plone/app/contentrules/tests/test_condition_role.py index 9c30258..6ad3cdb 100644 --- a/plone/app/contentrules/tests/test_condition_role.py +++ b/plone/app/contentrules/tests/test_condition_role.py @@ -21,6 +21,9 @@ def __init__(self, obj): class TestRoleCondition(ContentRulesTestCase): + def afterSetUp(self): + self.setRoles(('Manager', )) + def testRegistered(self): element = getUtility(IRuleCondition, name='plone.conditions.Role') self.assertEqual('plone.conditions.Role', element.addview) diff --git a/plone/app/contentrules/tests/test_condition_tales_expression.py b/plone/app/contentrules/tests/test_condition_tales_expression.py index 89b68e5..e270cbb 100644 --- a/plone/app/contentrules/tests/test_condition_tales_expression.py +++ b/plone/app/contentrules/tests/test_condition_tales_expression.py @@ -21,6 +21,9 @@ def __init__(self, obj): class TestTalesExpressionCondition(ContentRulesTestCase): + def afterSetUp(self): + self.setRoles(('Manager', )) + def testRegistered(self): element = getUtility( IRuleCondition, name='plone.conditions.TalesExpression') diff --git a/plone/app/contentrules/tests/test_condition_wfstate.py b/plone/app/contentrules/tests/test_condition_wfstate.py index f05548b..34ee2af 100644 --- a/plone/app/contentrules/tests/test_condition_wfstate.py +++ b/plone/app/contentrules/tests/test_condition_wfstate.py @@ -21,6 +21,9 @@ def __init__(self, obj): class TestWorkflowStateCondition(ContentRulesTestCase): + def afterSetUp(self): + self.setRoles(('Manager', )) + def testRegistered(self): element = getUtility( IRuleCondition, name='plone.conditions.WorkflowState') diff --git a/plone/app/contentrules/tests/test_condition_wftransition.py b/plone/app/contentrules/tests/test_condition_wftransition.py index 4de5dfb..457311c 100644 --- a/plone/app/contentrules/tests/test_condition_wftransition.py +++ b/plone/app/contentrules/tests/test_condition_wftransition.py @@ -14,6 +14,9 @@ class TestWorkflowTransitionCondition(ContentRulesTestCase): + def afterSetUp(self): + self.setRoles(('Manager', )) + def testRegistered(self): element = getUtility( IRuleCondition, name='plone.conditions.WorkflowTransition') diff --git a/plone/app/contentrules/tests/test_configuration.py b/plone/app/contentrules/tests/test_configuration.py index 7eb65c6..82f94c5 100644 --- a/plone/app/contentrules/tests/test_configuration.py +++ b/plone/app/contentrules/tests/test_configuration.py @@ -1,10 +1,8 @@ # -*- coding: utf-8 -*- -from plone.app.contentrules.testing import PLONE_APP_CONTENTRULES_FUNCTIONAL_TESTING # noqa: E501 -from plone.app.testing import applyProfile -from plone.app.testing import login -from plone.app.testing import setRoles -from plone.app.testing import TEST_USER_ID -from plone.app.testing import TEST_USER_NAME + +from plone.app.contentrules.tests.base import ContentRulesTestCase +from plone.app.testing import FunctionalTesting +from plone.app.testing.bbb import PloneTestCaseFixture from plone.contentrules.engine.interfaces import IRuleAssignmentManager from plone.contentrules.engine.interfaces import IRuleStorage from Products.GenericSetup.context import TarballExportContext @@ -14,22 +12,35 @@ from zope.lifecycleevent.interfaces import IObjectModifiedEvent import time -import unittest -class TestGenericSetup(unittest.TestCase): +class TestContentrulesGSFixture(PloneTestCaseFixture): + + def setUpZope(self, app, configurationContext): + super(TestContentrulesGSFixture, + self).setUpZope(app, configurationContext) + import plone.app.contentrules.tests + self.loadZCML('testing.zcml', package=plone.app.contentrules.tests) + + +ContentrulesGSFixture = TestContentrulesGSFixture() +TestContentrulesGSLayer = FunctionalTesting(bases=(ContentrulesGSFixture, ), + name='TestContentRules:Functional') + - layer = PLONE_APP_CONTENTRULES_FUNCTIONAL_TESTING +class TestGenericSetup(ContentRulesTestCase): - def setUp(self): - self.portal = self.layer['portal'] - self.request = self.layer['request'] - login(self.portal, TEST_USER_NAME) - setRoles(self.portal, TEST_USER_ID, ['Manager']) - self.portal.invokeFactory('Folder', 'news') - self.portal.invokeFactory('Folder', 'events') + layer = TestContentrulesGSLayer + + def afterSetUp(self): self.storage = getUtility(IRuleStorage) - applyProfile(self.portal, 'plone.app.contentrules:testing') + if 'news' not in self.portal: + self.loginAsPortalOwner() + self.portal.invokeFactory('Folder', 'news') + + portal_setup = self.portal.portal_setup + portal_setup.runAllImportStepsFromProfile( + 'profile-plone.app.contentrules:testing') def testRuleInstalled(self): self.assertTrue('test1' in self.storage) @@ -46,8 +57,8 @@ def testRulesConfigured(self): self.assertEqual(2, len(rule1.conditions)) self.assertEqual('plone.conditions.PortalType', rule1.conditions[0].element) - self.assertEqual(set(['Document', 'News Item']), - set(rule1.conditions[0].check_types)) + self.assertEqual(['Document', 'News Item'], + list(rule1.conditions[0].check_types)) self.assertEqual('plone.conditions.Role', rule1.conditions[1].element) self.assertEqual(['Manager'], list(rule1.conditions[1].role_names)) @@ -87,7 +98,7 @@ def testRuleAssigned(self): def testAssignmentOrdering(self): assignable = IRuleAssignmentManager(self.portal.news) - self.assertEqual(set([u'test3', u'test2', u'test1']), set(assignable.keys())) + self.assertEqual([u'test3', u'test2', u'test1'], assignable.keys()) def testImportTwice(self): # Ensure rules, actions/conditions and assignments are not duplicated @@ -103,7 +114,6 @@ def testImportTwice(self): self.testRuleAssigned() def testExport(self): - self.maxDiff = None site = self.portal context = TarballExportContext(self.portal.portal_setup) exporter = getMultiAdapter( @@ -207,4 +217,4 @@ def testExport(self): """ body = exporter.body - self.assertEqual(expected.strip(), body.strip().decode('utf8'), body.decode('utf8')) + self.assertEqual(expected.strip(), body.strip(), body) diff --git a/plone/app/contentrules/tests/test_handlers.py b/plone/app/contentrules/tests/test_handlers.py index fce4c5f..23ea5a4 100644 --- a/plone/app/contentrules/tests/test_handlers.py +++ b/plone/app/contentrules/tests/test_handlers.py @@ -1,15 +1,16 @@ # -*- coding: utf-8 -*- from plone.app.contentrules import handlers +from plone.app.contentrules.tests import base from plone.app.contentrules.tests import dummy -from plone.app.contentrules.tests.base import ContentRulesTestCase from zope.event import notify from zope.lifecycleevent import ObjectCreatedEvent -class TestDuplicateRuleFilter(ContentRulesTestCase): +class TestDuplicateRuleFilter(base.ContentRulesTestCase): def setUp(self): super(TestDuplicateRuleFilter, self).setUp() + self.setRoles(('Manager', )) self.context = self.folder self.event = dummy.DummyEvent(self.context) self.rulefilter = handlers.DuplicateRuleFilter() @@ -41,13 +42,12 @@ def test_call_uuidaware(self): def test_delayed_events(self): # many events can be delayed - # But this was only true for Archetypes content. - # The tests no use dexterity so we skip it: - return - + self.loginAsPortalOwner() self.portal.invokeFactory('Folder', 'folder2') + event1 = dummy.DummyEvent(self.folder) event2 = dummy.DummyEvent(self.portal.folder2) + from plone.app.contentrules.handlers import _status _status.delayed_events = {} handlers.added(event1) diff --git a/plone/app/contentrules/tests/test_rule_assignment_mapping.py b/plone/app/contentrules/tests/test_rule_assignment_mapping.py index 5f563b4..c052ad6 100644 --- a/plone/app/contentrules/tests/test_rule_assignment_mapping.py +++ b/plone/app/contentrules/tests/test_rule_assignment_mapping.py @@ -3,34 +3,18 @@ from plone.app.contentrules.rule import get_assignments from plone.app.contentrules.rule import insert_assignment from plone.app.contentrules.rule import Rule -from plone.app.contentrules.testing import PLONE_APP_CONTENTRULES_FUNCTIONAL_TESTING # noqa: E501 from plone.app.contentrules.tests.base import ContentRulesTestCase -from plone.app.testing import login -from plone.app.testing import setRoles -from plone.app.testing import TEST_USER_ID -from plone.app.testing import TEST_USER_NAME from plone.contentrules.engine.assignments import RuleAssignment from plone.contentrules.engine.interfaces import IRuleAssignmentManager from plone.contentrules.engine.interfaces import IRuleStorage from zope.component import getUtility import transaction -import unittest -class TestRuleAssignmentMapping(unittest.TestCase): +class TestRuleAssignmentMapping(ContentRulesTestCase): - layer = PLONE_APP_CONTENTRULES_FUNCTIONAL_TESTING - - def setUp(self): - self.portal = self.layer['portal'] - self.request = self.layer['request'] - login(self.portal, TEST_USER_NAME) - setRoles(self.portal, TEST_USER_ID, ['Manager']) - self.portal.invokeFactory('Folder', 'f1') - self.folder = self.portal['f1'] - self.folder.invokeFactory('Document', 'd1') - self.portal.invokeFactory('Folder', 'target') + def afterSetUp(self): self.folder.invokeFactory('Folder', 'f1') self.folder.f1.invokeFactory('Folder', 'f11') self.folder.f1.invokeFactory('Folder', 'f12') diff --git a/plone/app/contentrules/tests/test_rule_management_views.py b/plone/app/contentrules/tests/test_rule_management_views.py index 1f12657..83179b9 100644 --- a/plone/app/contentrules/tests/test_rule_management_views.py +++ b/plone/app/contentrules/tests/test_rule_management_views.py @@ -20,6 +20,9 @@ class DummyModifiedRule(Rule): class TestRuleManagementViews(ContentRulesTestCase): + def afterSetUp(self): + self.setRoles(('Manager', )) + def testRuleAdding(self): adding = getMultiAdapter( (self.portal, self.portal.REQUEST), name='+rule') diff --git a/plone/app/contentrules/tests/test_traversal.py b/plone/app/contentrules/tests/test_traversal.py index 26b1c49..ac71e5c 100644 --- a/plone/app/contentrules/tests/test_traversal.py +++ b/plone/app/contentrules/tests/test_traversal.py @@ -11,6 +11,9 @@ class TestTraversal(ContentRulesTestCase): + def afterSetUp(self): + self.setRoles(('Manager', )) + def testTraverseToRule(self): r = Rule() storage = getUtility(IRuleStorage)