plone.app.discussion/plone/app/discussion/testing.py

128 lines
3.9 KiB
Python
Raw Permalink Normal View History

from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE
from plone.app.discussion.interfaces import IDiscussionSettings
from plone.app.robotframework.testing import REMOTE_LIBRARY_ROBOT_TESTING
from plone.app.testing import applyProfile
from plone.app.testing import FunctionalTesting
from plone.app.testing import IntegrationTesting
from plone.app.testing import PloneSandboxLayer
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
2022-09-19 05:46:04 +02:00
from plone.app.testing import TEST_USER_PASSWORD
from plone.registry.interfaces import IRegistry
from Products.CMFCore.utils import getToolByName
from zope.component import queryUtility
try:
2013-04-18 15:51:57 +02:00
import plone.app.collection # noqa
2022-05-01 23:14:09 +02:00
COLLECTION_TYPE = "Collection"
except ImportError:
2022-05-01 23:14:09 +02:00
COLLECTION_TYPE = "Topic"
2012-01-14 07:53:03 +01:00
class PloneAppDiscussion(PloneSandboxLayer):
defaultBases = (PLONE_APP_CONTENTTYPES_FIXTURE,)
2022-05-01 23:14:09 +02:00
USER_NAME = "johndoe"
2022-09-19 05:46:04 +02:00
USER_PASSWORD = TEST_USER_PASSWORD
2022-05-01 23:14:09 +02:00
MEMBER_NAME = "janedoe"
2022-09-19 05:46:04 +02:00
MEMBER_PASSWORD = TEST_USER_PASSWORD
2022-05-01 23:14:09 +02:00
USER_WITH_FULLNAME_NAME = "jim"
USER_WITH_FULLNAME_FULLNAME = "Jim Fulton"
2022-09-19 05:46:04 +02:00
USER_WITH_FULLNAME_PASSWORD = TEST_USER_PASSWORD
2022-05-01 23:14:09 +02:00
MANAGER_USER_NAME = "manager"
2022-09-19 05:46:04 +02:00
MANAGER_USER_PASSWORD = TEST_USER_PASSWORD
2022-05-01 23:14:09 +02:00
REVIEWER_NAME = "reviewer"
2022-09-19 05:46:04 +02:00
REVIEWER_PASSWORD = TEST_USER_PASSWORD
def setUpZope(self, app, configurationContext):
# Load ZCML
import plone.app.discussion
2022-05-01 23:14:09 +02:00
self.loadZCML(
package=plone.app.discussion,
context=configurationContext,
)
def setUpPloneSite(self, portal):
# Install into Plone site using portal_setup
2022-05-01 23:14:09 +02:00
applyProfile(portal, "plone.app.discussion:default")
# Creates some users
2022-05-01 23:14:09 +02:00
acl_users = getToolByName(portal, "acl_users")
acl_users.userFolderAddUser(
self.USER_NAME,
self.USER_PASSWORD,
[],
[],
)
acl_users.userFolderAddUser(
self.MEMBER_NAME,
self.MEMBER_PASSWORD,
2022-05-01 23:14:09 +02:00
["Member"],
[],
)
acl_users.userFolderAddUser(
self.USER_WITH_FULLNAME_NAME,
self.USER_WITH_FULLNAME_PASSWORD,
2022-05-01 23:14:09 +02:00
["Member"],
[],
)
acl_users.userFolderAddUser(
self.REVIEWER_NAME,
self.REVIEWER_PASSWORD,
2022-05-01 23:14:09 +02:00
["Member"],
[],
)
2022-05-01 23:14:09 +02:00
mtool = getToolByName(portal, "portal_membership", None)
gtool = getToolByName(portal, "portal_groups", None)
gtool.addPrincipalToGroup(self.REVIEWER_NAME, "Reviewers")
mtool.addMember("jim", "Jim", ["Member"], [])
mtool.getMemberById("jim").setMemberProperties(
{"fullname": "Jim Fult\xc3\xb8rn"}
)
acl_users.userFolderAddUser(
self.MANAGER_USER_NAME,
self.MANAGER_USER_PASSWORD,
2022-05-01 23:14:09 +02:00
["Manager"],
[],
)
# Add a document
2022-05-01 23:14:09 +02:00
setRoles(portal, TEST_USER_ID, ["Manager"])
portal.invokeFactory(
2022-05-01 23:14:09 +02:00
id="doc1",
title="Document 1",
type_name="Document",
)
class PloneAppDiscussionRobot(PloneAppDiscussion):
2017-02-17 07:47:07 +01:00
defaultBases = (
PLONE_APP_CONTENTTYPES_FIXTURE,
REMOTE_LIBRARY_ROBOT_TESTING,
)
def setUpPloneSite(self, portal):
registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings)
settings.globally_enabled = True
PLONE_APP_DISCUSSION_ROBOT_FIXTURE = PloneAppDiscussionRobot()
PLONE_APP_DISCUSSION_FIXTURE = PloneAppDiscussion()
PLONE_APP_DISCUSSION_INTEGRATION_TESTING = IntegrationTesting(
2022-05-01 23:14:09 +02:00
bases=(PLONE_APP_DISCUSSION_FIXTURE,), name="PloneAppDiscussion:Integration"
)
PLONE_APP_DISCUSSION_FUNCTIONAL_TESTING = FunctionalTesting(
2022-05-01 23:14:09 +02:00
bases=(PLONE_APP_DISCUSSION_FIXTURE,), name="PloneAppDiscussion:Functional"
)
PLONE_APP_DISCUSSION_ROBOT_TESTING = FunctionalTesting(
2017-02-17 07:47:07 +01:00
bases=(PLONE_APP_DISCUSSION_ROBOT_FIXTURE,),
2022-05-01 23:14:09 +02:00
name="PloneAppDiscussion:Robot",
)