Commit b3ef6288 authored by Vincent Pelletier's avatar Vincent Pelletier

Make testPredicate methods available on testDomainTool (split in 2 classes &...

Make testPredicate methods available on testDomainTool (split in 2 classes & make testDomainTool inherit from the MixIn class).
Add a test for searchPredicateList: it must not return predicates which would be possible to filter out from SQL.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21990 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 33d28b14
...@@ -28,13 +28,13 @@ ...@@ -28,13 +28,13 @@
import unittest import unittest
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5.tests.testPredicate import TestPredicateMixIn, REGION_FRANCE_PATH, REGION_GERMANY_PATH, GROUP_STOREVER_PATH, GROUP_OTHER_PATH
from DateTime import DateTime from DateTime import DateTime
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from zLOG import LOG from zLOG import LOG
from Products.ZSQLCatalog.SQLCatalog import Query from Products.ZSQLCatalog.SQLCatalog import Query
class TestDomainTool(ERP5TypeTestCase): class TestDomainTool(TestPredicateMixIn):
# Different variables used for this test # Different variables used for this test
run_all_test = 1 run_all_test = 1
...@@ -47,12 +47,6 @@ class TestDomainTool(ERP5TypeTestCase): ...@@ -47,12 +47,6 @@ class TestDomainTool(ERP5TypeTestCase):
""" """
return "Domain Tool" return "Domain Tool"
def enableHotReindexing(self):
"""
You can override this. Return if we should create (1) or not (0) an activity tool
"""
return 0
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
""" """
Return the list of business templates. Return the list of business templates.
...@@ -66,15 +60,6 @@ class TestDomainTool(ERP5TypeTestCase): ...@@ -66,15 +60,6 @@ class TestDomainTool(ERP5TypeTestCase):
def getResourceModule(self): def getResourceModule(self):
return getattr(self.getPortal(), self.resource_module, None) return getattr(self.getPortal(), self.resource_module, None)
def afterSetUp(self):
self.login()
def login(self, quiet=0):
uf = self.getPortal().acl_users
uf._doAddUser('seb', '', ['Manager'], [])
user = uf.getUserById('seb').__of__(uf)
newSecurityManager(None, user)
def getSaleOrderModule(self): def getSaleOrderModule(self):
return getattr(self.getPortal(),'sale_order_module',None) return getattr(self.getPortal(),'sale_order_module',None)
...@@ -410,6 +395,28 @@ class TestDomainTool(ERP5TypeTestCase): ...@@ -410,6 +395,28 @@ class TestDomainTool(ERP5TypeTestCase):
'variation/%s/blue' % self.resource.getRelativeUrl()]), 'variation/%s/blue' % self.resource.getRelativeUrl()]),
sort_method=sort_method),45) sort_method=sort_method),45)
def test_06_SQLQueryDoesNotReturnTooManyPredicates(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
self.logMessage('Check that SQL query does not return unneeded predicates')
predicate_both_match = self.createPredicate(
multimembership_criterion_base_category_list=['group', 'region'],
membership_criterion_category_list=[GROUP_STOREVER_PATH, REGION_FRANCE_PATH])
predicate_one_match = self.createPredicate(
multimembership_criterion_base_category_list=['group', 'region'],
membership_criterion_category_list=[GROUP_STOREVER_PATH, REGION_GERMANY_PATH])
document = self.createDocument(group='nexedi/storever',
region='europe/western_europe/france')
get_transaction().commit()
self.tic()
portal_domains = self.getPortalObject().portal_domains
# Basic sanity checks
self.assertTrue(predicate_both_match.test(document))
self.assertFalse(predicate_one_match.test(document))
self.assertSameSet(portal_domains.searchPredicateList(document, test=1), [predicate_both_match])
# Real test
self.assertSameSet(portal_domains.searchPredicateList(document, test=0), [predicate_both_match])
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestDomainTool)) suite.addTest(unittest.makeSuite(TestDomainTool))
......
...@@ -48,7 +48,7 @@ RUN_ALL_TESTS = 1 ...@@ -48,7 +48,7 @@ RUN_ALL_TESTS = 1
QUIET = 1 QUIET = 1
PREDICATE_FOLDER_NAME = "predicate_unit_test_folder" PREDICATE_FOLDER_NAME = "predicate_unit_test_folder"
class TestPredicates(ERP5TypeTestCase): class TestPredicateMixIn(ERP5TypeTestCase):
"""Test Predicates. """ """Test Predicates. """
def getTitle(self): def getTitle(self):
...@@ -264,6 +264,8 @@ class TestPredicates(ERP5TypeTestCase): ...@@ -264,6 +264,8 @@ class TestPredicates(ERP5TypeTestCase):
predicate = sequence.get('predicate') predicate = sequence.get('predicate')
self.assertFalse(predicate.test(doc)) self.assertFalse(predicate.test(doc))
class TestPredicates(TestPredicateMixIn):
############################################################################ ############################################################################
## Test Methods ############################################################ ## Test Methods ############################################################
############################################################################ ############################################################################
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment