testERP5Discussion.py 8.07 KB
Newer Older
1
# -*- coding: utf-8 -*-
2 3
##############################################################################
#
4
# Copyright (c) 2010 Nexedi SA and Contributors.
5 6
# All Rights Reserved.
#          Romain Courteaud <romain@nexedi.com>
7
#          Fabien MORIN <fabien@nexedi.com>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################

import unittest
from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
Ivan Tyagov's avatar
Ivan Tyagov committed
35 36
from Products.ERP5Type.tests.backportUnittest import expectedFailure

37 38 39 40 41 42 43 44 45 46 47 48 49 50

class TestERP5Discussion(ERP5TypeTestCase):
  """Test for erp5_discussion business template.
  """

  manager_username = 'manager'
  manager_password = 'pwd'

  def getTitle(self):
    return "Test ERP5 Discussion"

  def getBusinessTemplateList(self):
    """
    """
51 52 53 54 55 56 57 58
    return ('erp5_core',
            'erp5_base',
            'erp5_xhtml_style',
            'erp5_ingestion',
            'erp5_web',
            'erp5_dms',
            'erp5_knowledge_pad',
            'erp5_rss_style',
Ivan Tyagov's avatar
Ivan Tyagov committed
59
            'erp5_jquery',
60 61 62 63 64 65 66 67 68 69 70 71 72 73
            'erp5_discussion', )

  def login(self):
    uf = self.getPortal().acl_users
    uf._doAddUser(self.manager_username, self.manager_password, ['Manager'], [])
    user = uf.getUserById(self.manager_username).__of__(uf)
    newSecurityManager(None, user)

  def afterSetUp(self):
    self.login()
    self.portal_id = self.portal.getId()
    self.auth = '%s:%s' % (self.manager_username, self.manager_password)

  def beforeTearDown(self):
74
    self.abort()
75 76 77 78 79
    for module in (self.portal.discussion_thread_module,):
      module.manage_delObjects(list(module.objectIds()))
    self.tic()

  def stepCreateThread(self):
Fabien Morin's avatar
Fabien Morin committed
80

81 82
    module =  self.portal.getDefaultModule("Discussion Thread")
    return module.newContent(portal_type="Discussion Thread")
Fabien Morin's avatar
Fabien Morin committed
83

84 85 86 87 88
  def stepCreatePost(self,thread):
    return thread.newContent(portal_type="Discussion Post")

  def test_01_createDiscussionThread(self):
    """Create a new discussion thread"""
Fabien Morin's avatar
Fabien Morin committed
89

90
    self.stepCreateThread();
91
    self.tic()
Fabien Morin's avatar
Fabien Morin committed
92

93
  def test_02_createDiscussionPost(self):
94
    """Create a disucssion post inside a discussion thread"""
95

96 97 98 99 100 101 102 103
    thread = self.stepCreateThread()
    post = self.stepCreatePost(thread)
    # post is not indexed yet 
    self.assertSameSet([], thread.DiscussionThread_getDiscussionPostList())

    # not indexed but its relative url is passed through REQUEST
    self.app.REQUEST.set('post_relative_url', post.getRelativeUrl())
    self.assertSameSet([post], thread.DiscussionThread_getDiscussionPostList())
104
    self.tic()
105 106 107
   
    # indexed already
    self.assertSameSet([post], thread.DiscussionThread_getDiscussionPostList())
108

109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
  def test_03_createDiscussionThread(self):
    """
      Create a disucssion thread
    """
    portal = self.portal

    # create web sections & set predicates
    group1 = portal.portal_categories.group.newContent(portal_type='Category',
                                                       title = 'Group 1')
    web_site = portal.web_site_module.newContent(portal_type='Web Site')
    web_section1 = web_site.newContent(portal_type='Web Section')
    web_section1.setMultimembershipCriterionBaseCategoryList(['group'])
    web_section1.setMembershipCriterionCategoryList([group1.getRelativeUrl()])
    self.tic()

    web_section1.WebSection_createNewDiscussionThread('test1-new', 'test1 body')
    discussion_thread = [x for x in self.portal.discussion_thread_module.objectValues() \
                          if x.getReference()=='test1-new'][0]
    # not indexed yet
    self.assertSameSet([], web_section1.WebSection_getDiscussionThreadList())

    # not indexed but its relative url is passed through REQUEST
    self.app.REQUEST.set('thread_relative_url', discussion_thread.getRelativeUrl())
    self.assertSameSet([discussion_thread], web_section1.WebSection_getDiscussionThreadList())

    self.tic()
    # indexed already
    self.assertSameSet([discussion_thread], web_section1.WebSection_getDiscussionThreadList())

138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
  def test_MultipleForum(self):
    """
      Test multiple forums may exists within same ERP5 Web Site.
    """
    portal = self.portal

    # create web sections & set predicates
    group1 = portal.portal_categories.group.newContent(portal_type='Category',
                                                       title = 'Group 1')
    group2 = portal.portal_categories.group.newContent(portal_type='Category',
                                                       title = 'Group 2')                                                       
    web_site = portal.web_site_module.newContent(portal_type='Web Site')
    web_section1 = web_site.newContent(portal_type='Web Section')
    web_section2 = web_site.newContent(portal_type='Web Section')
    web_section1.setMultimembershipCriterionBaseCategoryList(['group'])
    web_section1.setMembershipCriterionCategoryList([group1.getRelativeUrl()])
    web_section2.setMultimembershipCriterionBaseCategoryList(['group'])
    web_section2.setMembershipCriterionCategoryList([group2.getRelativeUrl()])    
156
    self.tic()
157 158 159 160
    
    # add threads on Web Section context
    web_section1.WebSection_createNewDiscussionThread('test1', 'test1 body')
    web_section2.WebSection_createNewDiscussionThread('test2', 'test2 body')    
161
    self.tic()
162 163 164 165 166 167 168
    discussion_thread_object1 = portal.portal_catalog.getResultValue(portal_type = 'Discussion Thread',
                                                                    title = 'test1')
    discussion_thread_object2 = portal.portal_catalog.getResultValue(portal_type = 'Discussion Thread',
                                                                    title = 'test2')
    self.assertEqual(group1, discussion_thread_object1.getGroupValue())
    self.assertEqual(group2, discussion_thread_object2.getGroupValue())
    
169 170 171 172 173
    # check getDocumentValue.. on Web Section context (by default forum is public 
    # so threads should be part of document list)
    self.assertSameSet([discussion_thread_object1], [x.getObject() for x  in web_section1.getDocumentValueList()])
    self.assertSameSet([discussion_thread_object2], [x.getObject() for x  in web_section2.getDocumentValueList()])

174 175 176 177 178 179 180
    # test RSS generation by testing indirectly its "get" method
    # (new post should be first in list)
    current_post_list = list(discussion_thread_object1.objectValues())
    new_post = discussion_thread_object1.newContent()
    self.tic()
    self.assertSameSet([new_post] + current_post_list, web_section1.WebSection_getLatestDiscussionPostList())

181 182 183 184 185
    # test archiving threads so the do not belong any more to web section document list
    discussion_thread_object1.archive()
    discussion_thread_object2.archive()
    self.tic()

186 187
    self.assertSameSet([], web_section1.getDocumentValueList())
    self.assertSameSet([], web_section2.getDocumentValueList())
188

189

190 191 192 193
  def test_02_ReferenceGenerationFromString(self):
    s = "a test by ivan !@#$%^&*()[]\\é"
    self.assertEqual('a-test-by-ivan', self.portal.Base_generateReferenceFromString(s))

194 195 196 197
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestERP5Discussion))
  return suite