discussion.examplecontent added to src folder.
svn path=/plone.app.discussion/buildouts/; revision=27163
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import transaction
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
|
||||
PRODUCT_DEPENDENCIES = ('plone.app.discussion',)
|
||||
|
||||
EXTENSION_PROFILES = ('discussion.examplecontent:default',)
|
||||
|
||||
def install(self, reinstall=False):
|
||||
"""Install a set of products (which themselves may either use Install.py
|
||||
or GenericSetup extension profiles for their configuration) and then
|
||||
install a set of extension profiles.
|
||||
|
||||
One of the extension profiles we install is that of this product. This
|
||||
works because an Install.py installation script (such as this one) takes
|
||||
precedence over extension profiles for the same product in
|
||||
portal_quickinstaller.
|
||||
|
||||
We do this because it is not possible to install other products during
|
||||
the execution of an extension profile (i.e. we cannot do this during
|
||||
the importVarious step for this profile).
|
||||
"""
|
||||
|
||||
portal_quickinstaller = getToolByName(self, 'portal_quickinstaller')
|
||||
portal_setup = getToolByName(self, 'portal_setup')
|
||||
|
||||
for product in PRODUCT_DEPENDENCIES:
|
||||
if reinstall and portal_quickinstaller.isProductInstalled(product):
|
||||
portal_quickinstaller.reinstallProducts([product])
|
||||
transaction.savepoint()
|
||||
elif not portal_quickinstaller.isProductInstalled(product):
|
||||
portal_quickinstaller.installProduct(product)
|
||||
transaction.savepoint()
|
||||
|
||||
for extension_id in EXTENSION_PROFILES:
|
||||
portal_setup.runAllImportStepsFromProfile('profile-%s' % extension_id, purge_old=False)
|
||||
product_name = extension_id.split(':')[0]
|
||||
portal_quickinstaller.notifyInstalled(product_name)
|
||||
transaction.savepoint()
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
def initialize(context):
|
||||
"""Initializer called when used as a Zope 2 product."""
|
||||
@@ -0,0 +1,17 @@
|
||||
<configure
|
||||
xmlns="http://namespaces.zope.org/zope"
|
||||
xmlns:five="http://namespaces.zope.org/five"
|
||||
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
|
||||
i18n_domain="discussion.examplecontent">
|
||||
|
||||
<five:registerPackage package="." initialize=".initialize" />
|
||||
|
||||
<genericsetup:registerProfile
|
||||
name="default"
|
||||
title="Plone Discussion Example Content"
|
||||
directory="profiles/default"
|
||||
description="Example content to test and develop plone.app.discussion"
|
||||
provides="Products.GenericSetup.interfaces.EXTENSION"
|
||||
/>
|
||||
|
||||
</configure>
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0"?>
|
||||
<import-steps>
|
||||
<import-step id="discussion-examplecontent-various" version="20090525-01"
|
||||
handler="discussion.examplecontent.setuphandlers.importVarious"
|
||||
title="Example content to test and develop plone.app.discussion">
|
||||
plone.app.discussion example content </import-step>
|
||||
</import-steps>
|
||||
@@ -0,0 +1,138 @@
|
||||
from zope.component import createObject
|
||||
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
from Products.CMFEditions.setuphandlers import DEFAULT_POLICIES
|
||||
|
||||
from Products.CMFPlone.utils import _createObjectByType
|
||||
|
||||
from plone.app.discussion.interfaces import IConversation, IReplies
|
||||
|
||||
def addUser(portal, id, fullname, password, email, roles):
|
||||
status=""
|
||||
props = {"username": id,
|
||||
"fullname": fullname,
|
||||
"password": password,
|
||||
"email": email}
|
||||
# add a new member to the Portal
|
||||
try:
|
||||
portal.portal_registration.addMember(id, password, roles,domains="",
|
||||
properties=props)
|
||||
status+="The user "+fullname+" was successfully added.\n"
|
||||
except:
|
||||
status+="The user "+fullname+" was not added.\n"
|
||||
portal.plone_log(status)
|
||||
|
||||
def addComments(portal):
|
||||
|
||||
# Create document
|
||||
_createObjectByType('Document', portal, id='doc1', title='Document 1')
|
||||
portal.plone_log("Document 1 created")
|
||||
|
||||
doc1 = portal.get('doc1', None)
|
||||
|
||||
# Create a conversation. In this case we doesn't assign it to an
|
||||
# object, as we just want to check the Conversation object API.
|
||||
conversation = IConversation(doc1)
|
||||
|
||||
# Pretend that we have traversed to the comment by aq wrapping it.
|
||||
conversation = conversation.__of__(doc1)
|
||||
|
||||
replies = IReplies(conversation)
|
||||
|
||||
# Create a nested comment structure:
|
||||
#
|
||||
# Conversation
|
||||
# +- Comment 1
|
||||
# +- Comment 1_1
|
||||
# | +- Comment 1_1_1
|
||||
# +- Comment 1_2
|
||||
# +- Comment 2
|
||||
# +- Comment 2_1
|
||||
# +- Comment 3
|
||||
# +- Comment 4
|
||||
|
||||
# Create all comments
|
||||
comment1 = createObject('plone.Comment')
|
||||
comment1.title = 'Comment 1'
|
||||
comment1.text = 'Comment text'
|
||||
comment1.Creator = 'Jim'
|
||||
|
||||
comment1_1 = createObject('plone.Comment')
|
||||
comment1_1.title = 'Re: Comment 1'
|
||||
comment1_1.text = 'Comment text'
|
||||
comment1_1.Creator = 'Emma'
|
||||
|
||||
comment1_1_1 = createObject('plone.Comment')
|
||||
comment1_1_1.title = 'Re: Re: Comment 1'
|
||||
comment1_1_1.text = 'Comment text'
|
||||
comment1_1_1.Creator = 'Lukas'
|
||||
|
||||
comment1_2 = createObject('plone.Comment')
|
||||
comment1_2.title = 'Re: Comment 1 (2)'
|
||||
comment1_2.text = 'Comment text'
|
||||
comment1_2.Creator = 'Jim'
|
||||
|
||||
comment2 = createObject('plone.Comment')
|
||||
comment2.title = 'Comment 2'
|
||||
comment2.text = 'Comment text'
|
||||
comment2.Creator = 'Lukas'
|
||||
|
||||
comment2_1 = createObject('plone.Comment')
|
||||
comment2_1.title = 'Re: Comment 2'
|
||||
comment2_1.text = 'Comment text'
|
||||
comment2_1.Creator = 'Emma'
|
||||
|
||||
comment3 = createObject('plone.Comment')
|
||||
comment3.title = 'Comment 3'
|
||||
comment3.text = 'Comment text'
|
||||
comment3.Creator = 'Lukas'
|
||||
|
||||
comment4 = createObject('plone.Comment')
|
||||
comment4.title = 'Comment 4'
|
||||
comment4.text = 'Comment text'
|
||||
comment4.Creator = 'Emma'
|
||||
|
||||
# Create the nested comment structure
|
||||
new_id_1 = conversation.addComment(comment1)
|
||||
new_id_2 = conversation.addComment(comment2)
|
||||
new_id_3 = conversation.addComment(comment3)
|
||||
new_id_4 = conversation.addComment(comment4)
|
||||
|
||||
comment1_1.in_reply_to = new_id_1
|
||||
new_id_1_1 = conversation.addComment(comment1_1)
|
||||
|
||||
comment1_1_1.in_reply_to = new_id_1_1
|
||||
new_id_1_1_1 = conversation.addComment(comment1_1_1)
|
||||
|
||||
comment1_2.in_reply_to = new_id_1
|
||||
new_id_1_2 = conversation.addComment(comment1_2)
|
||||
|
||||
comment2_1.in_reply_to = new_id_2
|
||||
new_id_2_1 = conversation.addComment(comment2_1)
|
||||
|
||||
# Add a comment. Note: in real life, we always create comments via the factory
|
||||
# to allow different factories to be swapped in
|
||||
|
||||
portal.plone_log("")
|
||||
|
||||
def importVarious(context):
|
||||
"""Miscellanous steps import handle
|
||||
"""
|
||||
|
||||
# Ordinarily, GenericSetup handlers check for the existence of XML files.
|
||||
# Here, we are not parsing an XML file, but we use this text file as a
|
||||
# flag to check that we actually meant for this import step to be run.
|
||||
# The file is found in profiles/default.
|
||||
|
||||
if context.readDataFile('discussion.examplecontent_various.txt') is None:
|
||||
return
|
||||
|
||||
portal = context.getSite()
|
||||
|
||||
addUser(portal, id="jim", fullname="Jim Knopf", password="lummerland",
|
||||
email="jim@lummerland.com", roles = ("Member",))
|
||||
addUser(portal, id="lukas", fullname="Lukas", password="lummerland",
|
||||
email="lukas@lummerland.com", roles = ("Member",))
|
||||
addUser(portal, id="emma", fullname="Emma", password="lummerland",
|
||||
email="emma@lummerland.com", roles = ("Member",))
|
||||
addComments(portal)
|
||||
@@ -0,0 +1,53 @@
|
||||
import unittest
|
||||
|
||||
from zope.testing import doctestunit
|
||||
from zope.component import testing
|
||||
from Testing import ZopeTestCase as ztc
|
||||
|
||||
from Products.Five import zcml
|
||||
from Products.Five import fiveconfigure
|
||||
from Products.PloneTestCase import PloneTestCase as ptc
|
||||
from Products.PloneTestCase.layer import PloneSite
|
||||
ptc.setupPloneSite()
|
||||
|
||||
import discussion.examplecontent
|
||||
|
||||
class TestCase(ptc.PloneTestCase):
|
||||
class layer(PloneSite):
|
||||
@classmethod
|
||||
def setUp(cls):
|
||||
fiveconfigure.debug_mode = True
|
||||
ztc.installPackage(discussion.examplecontent)
|
||||
fiveconfigure.debug_mode = False
|
||||
|
||||
@classmethod
|
||||
def tearDown(cls):
|
||||
pass
|
||||
|
||||
|
||||
def test_suite():
|
||||
return unittest.TestSuite([
|
||||
|
||||
# Unit tests
|
||||
#doctestunit.DocFileSuite(
|
||||
# 'README.txt', package='discussion.examplecontent',
|
||||
# setUp=testing.setUp, tearDown=testing.tearDown),
|
||||
|
||||
#doctestunit.DocTestSuite(
|
||||
# module='discussion.examplecontent.mymodule',
|
||||
# setUp=testing.setUp, tearDown=testing.tearDown),
|
||||
|
||||
|
||||
# Integration tests that use PloneTestCase
|
||||
#ztc.ZopeDocFileSuite(
|
||||
# 'README.txt', package='discussion.examplecontent',
|
||||
# test_class=TestCase),
|
||||
|
||||
#ztc.FunctionalDocFileSuite(
|
||||
# 'browser.txt', package='discussion.examplecontent',
|
||||
# test_class=TestCase),
|
||||
|
||||
])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(defaultTest='test_suite')
|
||||
Reference in New Issue
Block a user