testCatalogSecurity.py 5.57 KB
Newer Older
Sebastien Robin's avatar
Sebastien Robin committed
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
##############################################################################
#
# Copyright (c) 2004 Nexedi SARL and Contributors. All Rights Reserved.
#          Sebastien Robin <seb@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.
#
##############################################################################


Jérome Perrin's avatar
Jérome Perrin committed
30
import unittest
Sebastien Robin's avatar
Sebastien Robin committed
31 32
from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
Jérome Perrin's avatar
Jérome Perrin committed
33
from AccessControl.SecurityManagement import newSecurityManager
Sebastien Robin's avatar
Sebastien Robin committed
34 35 36 37 38 39 40 41 42
from zLOG import LOG

class Test(ERP5TypeTestCase):
  """
  This is the list of test

  """

  def getTitle(self):
43
    return "CatalogSecurity"
Sebastien Robin's avatar
Sebastien Robin committed
44

Sebastien Robin's avatar
Sebastien Robin committed
45 46 47
  def getBusinessTemplateList(self):
    return ('erp5_base',)

Sebastien Robin's avatar
Sebastien Robin committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
  # Different variables used for this test
  run_all_test = 1
  source_company_id = 'Nexedi'
  destination_company_id = 'Coramy'
  component_id = 'brick'
  sales_order_id = '1'
  quantity = 10
  base_price = 0.7832

  #def populate(self, quiet=1, run=1):
  def afterSetUp(self, quiet=1, run=1):
    self.login()
    portal = self.getPortal()
    catalog_tool = self.getCatalogTool()
    # XXX This does not works
    #catalog_tool.reindexObject(portal)

    # First reindex
    #LOG('afterSetup',0,'portal.portal_categories.immediateReindexObject')
    #portal.portal_categories.immediateReindexObject()
    #LOG('afterSetup',0,'portal.portal_simulation.immediateReindexObject')
    #portal.portal_simulation.immediateReindexObject()

  def login(self, username='seb',quiet=0, run=run_all_test):
    uf = self.getPortal().acl_users
    if getattr(uf,'seb',None) is None:
      uf._doAddUser('seb', '', ['Manager'], [])
      uf._addGroup('GroupA')
      uf._addGroup('GroupB')
      uf._doAddUser('UserA', '', ['Member'], [],groups=['GroupA'])
      uf._doAddUser('UserB', '', ['Member'], [],groups=['GroupB'])
    user = uf.getUserById(username).__of__(uf)
    newSecurityManager(None, user)

82
  def getSQLPathList(self):
Sebastien Robin's avatar
Sebastien Robin committed
83 84 85
    """
    Give the full list of path in the catalog
    """
86
    sql_connection = self.getSQLConnection()
Sebastien Robin's avatar
Sebastien Robin committed
87 88 89 90 91
    sql = 'select path from catalog'
    result = sql_connection.manage_test(sql)
    path_list = map(lambda x: x['path'],result)
    return path_list

92 93
  def checkRelativeUrlInSQLPathList(self,url_list):
    path_list = self.getSQLPathList()
Sebastien Robin's avatar
Sebastien Robin committed
94 95 96 97
    portal_id = self.getPortalId()
    for url in url_list:
      path = '/' + portal_id + '/' + url
      self.failUnless(path in path_list)
98
      LOG('checkRelativeUrlInSQLPathList found path:',0,path)
Sebastien Robin's avatar
Sebastien Robin committed
99

100 101
  def checkRelativeUrlNotInSQLPathList(self,url_list):
    path_list = self.getSQLPathList()
Sebastien Robin's avatar
Sebastien Robin committed
102 103 104 105
    portal_id = self.getPortalId()
    for url in url_list:
      path = '/' + portal_id + '/' + url
      self.failUnless(path not in  path_list)
106
      LOG('checkRelativeUrlInSQLPathList not found path:',0,path)
Sebastien Robin's avatar
Sebastien Robin committed
107 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 138 139 140 141 142 143 144 145 146


  def test_01_StandardSearchFolder(self, quiet=0, run=run_all_test):
    # Test if portal_synchronizations was created
    if not run: return
    if not quiet:
      ZopeTestCase._print('\nTest Standard Search Folder ')
      LOG('Testing... ',0,'testStandardSearchFolder')
    organisation_module = self.getOrganisationModule()
    organisation_module.manage_addLocalGroupRoles('GroupA',['Author'])
    organisation_module.manage_addLocalGroupRoles('GroupB',['Author'])
    self.login('UserA')
    organisation_module.newContent(id='A',immediate_reindex=1)
    organisation_list = organisation_module.searchFolder()
    self.assertEquals(len(organisation_list),1)
    self.login('UserB')
    organisation_list = organisation_module.searchFolder()
    self.assertEquals(len(organisation_list),1)

  def test_02_SearchFolderWithNegativeGroup(self, quiet=0, run=run_all_test):
    # Test if portal_synchronizations was created
    if not run: return
    if not quiet:
      ZopeTestCase._print('\nTest Search Folder With Negative Group')
      LOG('Testing... ',0,'testSeachFolderWithNegativeGroup')
    organisation_module = self.getOrganisationModule()
    organisation_module.manage_addLocalGroupRoles('GroupA',['Author'])
    organisation_module.manage_addLocalGroupRoles('GroupB',['Author'])
    self.login('UserA')
    organisation = organisation_module.newContent(id='A',immediate_reindex=1)
    organisation_list = organisation_module.searchFolder()
    self.assertEquals(len(organisation_list),1)
    self.login()
    organisation.manage_addLocalGroupRoles('GroupB',['-Author'])
    organisation.immediateReindexObject()
    self.login('UserB')
    organisation_list = organisation_module.searchFolder()
    self.assertEquals(len(organisation_list),0)


Jérome Perrin's avatar
Jérome Perrin committed
147 148 149 150
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(Test))
  return suite
Sebastien Robin's avatar
Sebastien Robin committed
151