testERP5Core.py 8.58 KB
Newer Older
1 2 3 4 5 6 7 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 35 36 37 38 39
##############################################################################
#
# Copyright (c) 2004, 2005, 2006 Nexedi SARL and Contributors. 
# All Rights Reserved.
#          Romain Courteaud <romain@nexedi.com>
#
# 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 os
import sys

if __name__ == '__main__':
    execfile(os.path.join(sys.path[0], 'framework.py'))

# Needed in order to have a log file inside the current folder
os.environ['EVENT_LOG_FILE'] = os.path.join(os.getcwd(), 'zLOG.log')
os.environ['EVENT_LOG_SEVERITY'] = '-300'

40
from AccessControl.SecurityManagement import newSecurityManager
41
from Testing import ZopeTestCase
42 43 44
from Products.PageTemplates.GlobalTranslationService import \
                                      setGlobalTranslationService

45 46
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
HTTP_OK = 200
HTTP_UNAUTHORIZED = 401
HTTP_REDIRECT = 302

class DummyTranslationService:
  """A dummy translation service where you can access translated msgids and
  mappings in _translated.
  """
  _translated = {}
  def translate(self, domain, msgid, mapping=None, *args, **kw):
    self._translated.setdefault(domain, []).append((msgid, mapping))
    return msgid

class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional):
  """Test for erp5_core business template.
  """
63 64
  run_all_test = 1
  quiet = 1
65 66
  manager_username = 'rc'
  manager_password = ''
67 68 69 70 71 72

  def getTitle(self):
    return "ERP5Core"

  def login(self, quiet=0, run=run_all_test):
    uf = self.getPortal().acl_users
73 74
    uf._doAddUser(self.manager_username, self.manager_password, ['Manager'], [])
    user = uf.getUserById(self.manager_username).__of__(uf)
75 76
    newSecurityManager(None, user)

77
  def afterSetUp(self):
78 79
    self.login()
    self.portal = self.getPortal()
80 81
    self.portal_id = self.portal.getId()
    self.auth = '%s:%s' % (self.manager_username, self.manager_password)
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

  def test_01_ERP5Site_createModule(self, quiet=quiet, run=run_all_test):
    """
      Test that a module is created when ERP5Site_createModule is given the
      strict minimum number of arguments.
      A created module is composed of :
       - the module itself, directly in the portal object
       - a skin folder, directly in the skins tool
       - a portal type for the module
       - a portal type for the objects which can be contained in the module

      TODO: check more behaviours of the creation script, like skin priority, ...
    """
    if not run: return

    module_portal_type='UnitTest Module'
    portal_skins_folder='erp5_unittest'
    object_portal_type='UnitTest'
    object_title='UnitTest'
    module_id='unittest_module'
    module_title='UnitTests'
    
104 105 106 107 108 109 110
    self.failIf(self.portal._getOb(module_id, None) is not None)
    self.assertEqual(self.portal.portal_skins._getOb(portal_skins_folder, None),
                     None)
    self.assertEqual(self.portal.portal_types.getTypeInfo(module_portal_type),
                     None)
    self.assertEqual(self.portal.portal_types.getTypeInfo(object_portal_type),
                     None)
111 112 113 114 115 116
    self.portal.ERP5Site_createModule(module_portal_type=module_portal_type,
                                      portal_skins_folder=portal_skins_folder,
                                      object_portal_type=object_portal_type,
                                      object_title=object_title,
                                      module_id=module_id,
                                      module_title=module_title)
117 118 119 120 121 122 123 124 125 126 127
    self.failUnless(self.portal._getOb(module_id, None) is not None)
    self.assertNotEqual(
        self.portal.portal_skins._getOb(portal_skins_folder, None), None)
    self.assertEquals(module_title,
                      self.portal._getOb(module_id).getTitle())
    self.assertNotEqual(self.portal.portal_types.getTypeInfo(module_portal_type),
                        None)
    self.assertNotEqual(self.portal.portal_types.getTypeInfo(object_portal_type),
                        None)
    #self.assertEqual(self.portal.portal_types[object_portal_type].title,
    #                  object_title)
128
  
Kristian Rother's avatar
Kristian Rother committed
129
  def test_02_FavouritesMenu(self, quiet=quiet, run=run_all_test):
130 131 132 133
    """
      Test that Manage members is not an entry in the My Favourites menu.
    """
    if not run: return
134 135
    portal_actions = getattr(self.getPortal(), 'portal_actions', None)
    global_action_list = portal_actions.listFilteredActionsFor()['global']
136 137
    action_name_list = []
    for action in global_action_list:
138 139
      if(action['visible']):
        action_name_list.append(action['title'])
140 141 142 143 144 145

    self.assertTrue('Create Module' in action_name_list)

    for action_name in action_name_list:
      self.assertNotEqual(action_name, "Manage Members")
      self.assertNotEqual(action_name, "Manage members")
146

147 148 149 150 151 152 153 154 155 156 157 158 159 160
  def test_frontpage(self):
    """Test we can view the front page.
    """
    response = self.publish('%s/view' % self.portal_id, self.auth)
    self.assertEquals(HTTP_OK, response.getStatus())
    
  def test_login_form(self):
    """Test anonymous user are redirected to login_form
    """
    response = self.publish('%s/view' % self.portal_id)
    self.assertEquals(HTTP_REDIRECT, response.getStatus())
    self.assertEquals('%s/login_form' % self.portal.absolute_url(),
                      response.getHeader('Location'))

161 162 163 164 165 166 167 168 169 170 171
  def test_view_tools(self):
    """Test we can view tools."""
    for tool in ('portal_categories',
                 'portal_templates',
                 'portal_orders',
                 'portal_deliveries',
                 'portal_rules',
                 'portal_alarms',):
      response = self.publish('%s/%s/view' % (self.portal_id, tool), self.auth)
      self.assertEquals(HTTP_OK, response.getStatus(),
                        "%s: %s" % (tool, response.getStatus()))
172 173 174 175 176
 
  def test_allowed_content_types_translated(self):
    """Tests allowed content types from the action menu are translated"""
    translation_service = DummyTranslationService()
    setGlobalTranslationService(translation_service)
177 178 179
    # assumes that we can add Business Template in template tool
    response = self.publish('%s/portal_templates/view' %
                                self.portal_id, self.auth)
180
    self.assertEquals(HTTP_OK, response.getStatus())
181 182 183 184 185
    self.failUnless(('Business Template', {})
                    in translation_service._translated['ui'])
    self.failUnless(
      ('Add ${portal_type}', {'portal_type': 'Business Template'}) in
      translation_service._translated['ui'])
186 187 188 189 190

  def test_jump_action_translated(self):
    """Tests jump actions are translated"""
    translation_service = DummyTranslationService()
    setGlobalTranslationService(translation_service)
191 192
    # adds a new jump action to Template Tool portal type
    self.getTypesTool().getTypeInfo('Template Tool').addAction(
193 194 195 196 197 198 199
                      id='dummy_jump_action',
                      name='Dummy Jump Action',
                      action='',
                      condition='',
                      permission='View',
                      category='object_jump',
                      visible=1)
200 201
    response = self.publish('%s/portal_templates/view' %
                            self.portal_id, self.auth)
202 203 204 205
    self.assertEquals(HTTP_OK, response.getStatus())
    self.failUnless(('Dummy Jump Action', {}) in
                      translation_service._translated['ui'])

206 207 208
  def test_error_log(self):
    self.failUnless('error_log' in self.portal.objectIds())
    
209 210 211 212 213 214 215 216 217
if __name__ == '__main__':
    framework()
else:
    import unittest
    def test_suite():
        suite = unittest.TestSuite()
        suite.addTest(unittest.makeSuite(TestERP5Core))
        return suite