-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from plone/python3
migrate all tests to use dexterity, fix most tests
- Loading branch information
Showing
28 changed files
with
187 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- 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', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,38 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Base class for integration tests, based on plone.app.testing | ||
""" | ||
|
||
from plone.app.testing.bbb import PloneTestCase | ||
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 | ||
|
||
|
||
class ContentRulesTestCase(PloneTestCase): | ||
class ContentRulesTestCase(unittest.TestCase): | ||
"""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'] | ||
authenticator = getMultiAdapter( | ||
(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. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
from plone.app.contentrules.actions.mail import MailEditFormView | ||
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 | ||
from plone.contentrules.rule.interfaces import IRuleAction | ||
|
@@ -31,11 +33,9 @@ def __init__(self, object): | |
|
||
class TestMailAction(ContentRulesTestCase): | ||
|
||
def afterSetUp(self): | ||
self.setRoles(('Manager', )) | ||
self.portal.invokeFactory('Folder', 'target') | ||
self.folder.invokeFactory('Document', 'd1', | ||
title='W\xc3\xa4lkommen'.decode('utf-8')) | ||
def setUp(self): | ||
super(TestMailAction, self).setUp() | ||
self.folder['d1'].setTitle(u'Wälkommen') | ||
|
||
users = ( | ||
('userone', 'User One', '[email protected]', ('Manager', 'Member')), | ||
|
@@ -47,6 +47,8 @@ def afterSetUp(self): | |
self.portal.portal_membership.addMember(id, 'secret', roles, []) | ||
member = self.portal.portal_membership.getMemberById(id) | ||
member.setMemberProperties({'fullname': fname, 'email': email}) | ||
# XXX: remove the manager role that was set in the base class | ||
setRoles(self.portal, TEST_USER_ID, []) | ||
|
||
def _setup_mockmail(self): | ||
sm = getSiteManager(self.portal) | ||
|
@@ -110,16 +112,14 @@ def testInvokeEditView(self): | |
|
||
def testExecute(self): | ||
# this avoids sending mail as [email protected] | ||
self.loginAsPortalOwner() | ||
self.portal.portal_membership.getAuthenticatedMember().setProperties( | ||
email='[email protected]') | ||
dummyMailHost = self._setup_mockmail() | ||
e = MailAction() | ||
e.source = '$user_email' | ||
e.recipients = '[email protected], [email protected], $reviewer_emails, ' \ | ||
'$manager_emails, $member_emails' | ||
e.message = "P\xc3\xa4ge '${title}' created in ${url} !".decode( | ||
'utf-8') | ||
e.message = u"Päge '${title}' created in ${url} !" | ||
ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)), | ||
IExecutable) | ||
ex() | ||
|
@@ -134,9 +134,8 @@ def testExecute(self): | |
self.assertEqual('[email protected]', mailSent.get('From')) | ||
# The output message should be a utf-8 encoded string | ||
self.assertEqual( | ||
"P\xc3\xa4ge 'W\xc3\xa4lkommen' created in " | ||
'http://nohost/plone/Members/test_user_1_/d1 !', | ||
mailSent.get_payload(decode=True)) | ||
u"Päge 'Wälkommen' created in http://nohost/plone/f1/d1 !", | ||
mailSent.get_payload(decode=True).decode('utf8')) | ||
|
||
# check interpolation of $reviewer_emails | ||
self.assertTrue('[email protected]' in sent_mails) | ||
|
@@ -181,7 +180,7 @@ def testExecuteNoSource(self): | |
self.assertEqual('"plone@rulez" <[email protected]>', | ||
mailSent.get('From')) | ||
self.assertEqual('Document created !', | ||
mailSent.get_payload(decode=True)) | ||
mailSent.get_payload()) | ||
self._teardown_mockmail() | ||
|
||
def testExecuteMultiRecipients(self): | ||
|
@@ -200,14 +199,14 @@ def testExecuteMultiRecipients(self): | |
self.assertEqual('[email protected]', mailSent.get('To')) | ||
self.assertEqual('[email protected]', mailSent.get('From')) | ||
self.assertEqual('Document created !', | ||
mailSent.get_payload(decode=True)) | ||
mailSent.get_payload()) | ||
mailSent = message_from_string(dummyMailHost.messages[1]) | ||
self.assertEqual('text/plain; charset="utf-8"', | ||
mailSent.get('Content-Type')) | ||
self.assertEqual('[email protected]', mailSent.get('To')) | ||
self.assertEqual('[email protected]', mailSent.get('From')) | ||
self.assertEqual('Document created !', | ||
mailSent.get_payload(decode=True)) | ||
mailSent.get_payload()) | ||
self._teardown_mockmail() | ||
|
||
def testExecuteExcludeActor(self): | ||
|
@@ -246,7 +245,6 @@ 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='[email protected]') | ||
e = MailAction() | ||
|
Oops, something went wrong.
e1cb327
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pbauer Jenkins CI reporting about code analysis
See the full report here: https://jenkins.plone.org/job/package-plone.app.contentrules/53/violations
Follow these instructions to reproduce it locally.