Back to index

plone3  3.1.7
atctftestcase.py
Go to the documentation of this file.
00001 #  ATContentTypes http://plone.org/products/atcontenttypes/
00002 #  Archetypes reimplementation of the CMF core types
00003 #  Copyright (c) 2003-2006 AT Content Types development team
00004 #
00005 #  This program is free software; you can redistribute it and/or modify
00006 #  it under the terms of the GNU General Public License as published by
00007 #  the Free Software Foundation; either version 2 of the License, or
00008 #  (at your option) any later version.
00009 #
00010 #  This program is distributed in the hope that it will be useful,
00011 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #  GNU General Public License for more details.
00014 #
00015 #  You should have received a copy of the GNU General Public License
00016 #  along with this program; if not, write to the Free Software
00017 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 """
00020 
00021 """
00022 __author__  = 'Christian Heimes <tiran@cheimes.de>'
00023 __docformat__ = 'restructuredtext'
00024 
00025 from Testing import ZopeTestCase
00026 from Products.ATContentTypes.tests import atcttestcase
00027 
00028 import transaction
00029 from Products.PloneTestCase.setup import default_user
00030 from Products.PloneTestCase.setup import default_password
00031 from Products.PloneTestCase.setup import portal_owner
00032 from Products.ATContentTypes.config import HAS_LINGUA_PLONE
00033 from Products.ATContentTypes.tests.utils import FakeRequestSession
00034 from Products.ATContentTypes.tests.utils import DummySessionDataManager
00035 from Products.CMFCore.utils import getToolByName
00036 from Products.PluggableAuthService.interfaces.plugins import IChallengePlugin
00037 
00038 
00039 class IntegrationTestCase(atcttestcase.ATCTFunctionalSiteTestCase):
00040 
00041     views = ()
00042 
00043     def afterSetUp(self):
00044         # basic data
00045         self.folder_url = self.folder.absolute_url()
00046         self.folder_path = '/%s' % self.folder.absolute_url(1)
00047         self.basic_auth = '%s:%s' % (default_user, default_password)
00048         self.owner_auth = '%s:%s' % (portal_owner, default_password)
00049 
00050         # error log
00051         from Products.SiteErrorLog.SiteErrorLog import temp_logs
00052         temp_logs = {} # clean up log
00053         self.error_log = self.portal.error_log
00054         self.error_log._ignored_exceptions = ()
00055 
00056         # We want 401 responses, not redirects to a login page
00057         plugins = self.portal.acl_users.plugins
00058         for id in plugins.listPluginIds(IChallengePlugin):
00059             plugins.deactivatePlugin(IChallengePlugin, id)
00060 
00061         # disable portal_factory as it's a nuisance here
00062         self.portal.portal_factory.manage_setPortalFactoryTypes(listOfTypeIds=[])
00063 
00064         # object
00065         self.setupTestObject()
00066 
00067     def setupTestObject(self):
00068         self.obj_id = 'test_object'
00069         self.obj = None
00070         self.obj_url = self.obj.absolute_url()
00071         self.obj_path = '/%s' % self.obj.absolute_url(1)
00072 
00073     def assertStatusEqual(self, a, b, msg=''):
00074         """Helper method that uses the error log to output useful debug infos
00075         """
00076         if a != b:
00077             entries = self.error_log.getLogEntries()
00078             if entries:
00079                 msg = entries[0]['tb_text']
00080             else:
00081                 if not msg:
00082                     msg = 'no error log msg available'
00083         self.failUnlessEqual(a, b, msg)
00084 
00085 
00086 class ATCTIntegrationTestCase(IntegrationTestCase):
00087     """Integration tests for view and edit templates
00088     """
00089 
00090     portal_type = None
00091 
00092     def setupTestObject(self):
00093         # create test object
00094         self.obj_id = 'test_object'
00095         self.title = u'test \xf6bject'
00096         self.folder.invokeFactory(self.portal_type, self.obj_id, title=self.title)
00097         self.obj = getattr(self.folder.aq_explicit, self.obj_id)
00098         self.obj_url = self.obj.absolute_url()
00099         self.obj_path = '/%s' % self.obj.absolute_url(1)
00100 
00101     def test_createObject(self):
00102         # create an object using the createObject script
00103         response = self.publish(self.folder_path +
00104                                 '/createObject?type_name=%s' % self.portal_type,
00105                                 self.basic_auth)
00106 
00107         self.assertStatusEqual(response.getStatus(), 302) # Redirect to edit
00108 
00109         body = response.getBody()
00110 
00111         self.failUnless(body.startswith(self.folder_url), body)
00112         # The url may end with /edit or /atct_edit depending on method aliases
00113         self.failUnless(body.endswith('edit'), body)
00114 
00115         # Perform the redirect
00116         edit_form_path = body[len(self.app.REQUEST.SERVER_URL):]
00117         response = self.publish(edit_form_path, self.basic_auth)
00118         self.assertStatusEqual(response.getStatus(), 200) # OK
00119         temp_id = body.split('/')[-2]
00120 
00121         new_obj = getattr(self.folder.portal_factory, temp_id)
00122         self.failUnlessEqual(self.obj.checkCreationFlag(), True) # object is not yet edited
00123 
00124 
00125     def check_newly_created(self):
00126         """Objects created programmatically should not have the creation flag set"""
00127         self.failUnlessEqual(self.obj.checkCreationFlag(), False) # object is fully created
00128 
00129     def test_edit_view(self):
00130         # edit should work
00131         response = self.publish('%s/atct_edit' % self.obj_path, self.basic_auth)
00132         self.assertStatusEqual(response.getStatus(), 200) # OK
00133 
00134     def test_metadata_edit_view(self):
00135         # metadata edit should work
00136         response = self.publish('%s/base_metadata' % self.obj_path, self.basic_auth)
00137         self.assertStatusEqual(response.getStatus(), 200) # OK
00138 
00139     def test_base_view(self):
00140         # base view should work
00141         response = self.publish('%s/base_view' % self.obj_path, self.basic_auth)
00142         self.assertStatusEqual(response.getStatus(), 200) # OK
00143 
00144     def test_dynamic_view(self):
00145         # dynamic view magic should work
00146         response = self.publish('%s/view' % self.obj_path, self.basic_auth)
00147         self.assertStatusEqual(response.getStatus(), 200) # OK
00148 
00149     def test_local_sharing_view(self):
00150         # sharing tab should work
00151         response = self.publish('%s/sharing' % self.obj_path, self.basic_auth)
00152         self.assertStatusEqual(response.getStatus(), 200) # OK
00153 
00154     def test_workflow_view(self):
00155         # workflow tab should work
00156         response = self.publish('%s/content_status_history' % self.obj_path, self.basic_auth)
00157         self.assertStatusEqual(response.getStatus(), 200) # OK
00158 
00159     # LinguaPlone specific tests
00160     if HAS_LINGUA_PLONE:
00161 
00162         def test_linguaplone_views(self):
00163             response = self.publish('%s/translate_item' % self.obj_path, self.basic_auth)
00164             self.assertStatusEqual(response.getStatus(), 200) # OK
00165             response = self.publish('%s/manage_translations_form' % self.obj_path, self.basic_auth)
00166             self.assertStatusEqual(response.getStatus(), 200) # OK
00167 
00168         def test_linguaplone_create_translation(self):
00169             # create translation creates a new object
00170             response = self.publish('%s/createTranslation?language=de&set_language=de'
00171                                      % self.obj_path, self.basic_auth)
00172             self.assertStatusEqual(response.getStatus(), 302) # Redirect
00173 
00174             body = response.getBody()
00175             self.failUnless(body.startswith(self.folder_url))
00176             self.failUnless(body.endswith('/translate_item'))
00177 
00178             # Perform the redirect
00179             form_path = body[len(self.app.REQUEST.SERVER_URL):]
00180             response = self.publish(form_path, self.basic_auth)
00181             self.assertStatusEqual(response.getStatus(), 200) # OK
00182 
00183             translated_id = "%s-de" % self.obj_id
00184             self.failUnless(translated_id in self.folder.objectIds(),
00185                             self.folder.objectIds())
00186 
00187     def test_additional_view(self):
00188         # additional views:
00189         for view in self.views:
00190             response = self.publish('%s/%s' % (self.obj_path, view), self.basic_auth)
00191             self.assertStatusEqual(response.getStatus(), 200,
00192                 "%s: %s" % (view, response.getStatus())) # OK
00193 
00194     def test_discussion(self):
00195         # enable discussion for the type
00196         ttool = getToolByName(self.portal, 'portal_types')
00197         ttool[self.portal_type].allow_discussion = True
00198 
00199         response = self.publish('%s/discussion_reply_form'
00200                                  % self.obj_path, self.basic_auth)
00201         self.assertStatusEqual(response.getStatus(), 200) # ok
00202 
00203         response = self.publish('%s/discussion_reply?subject=test&body_text=testbody'
00204                                  % self.obj_path, self.basic_auth)
00205         self.assertStatusEqual(response.getStatus(), 302) # Redirect
00206 
00207         body = response.getBody()
00208         self.failUnless(body.startswith(self.folder_url))
00209 
00210         self.failUnless(hasattr(self.obj.aq_explicit, 'talkback'))
00211 
00212         form_path = body[len(self.app.REQUEST.SERVER_URL):]
00213         discussionId = form_path.split('#')[1]
00214 
00215         reply = self.obj.talkback.getReply(discussionId)
00216         self.assertEquals(reply.title, 'test')
00217         self.assertEquals(reply.text, 'testbody')
00218 
00219     def test_dynamicViewContext(self):
00220         # register and add a testing template (it's a script)
00221         self.setRoles(['Manager', 'Member'])
00222 
00223         ttool = self.portal.portal_types
00224         fti = getattr(ttool, self.portal_type)
00225         view_methods = fti.getAvailableViewMethods(self.obj) + ('unittestGetTitleOf',)
00226         fti.manage_changeProperties(view_methods=view_methods)
00227 
00228         self.obj.setLayout('unittestGetTitleOf')
00229         self.folder.setTitle('the folder')
00230         self.obj.setTitle('the obj')
00231 
00232         self.setRoles(['Member'])
00233 
00234         response = self.publish('%s/view' % self.obj_path, self.basic_auth)
00235         self.assertStatusEqual(response.getStatus(), 200) # OK
00236 
00237         output = response.getBody().split(',')
00238         self.failUnlessEqual(len(output), 4, output)
00239 
00240         self.failUnlessEqual(output, ['the obj', 'the folder', 'the obj', 'the folder'])
00241