Commit 142405c5 authored by Nicolas Delaby's avatar Nicolas Delaby

Create Mixin class to factorize code


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34882 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a0c46b11
...@@ -101,20 +101,8 @@ def makeFileUpload(name, as_name=None): ...@@ -101,20 +101,8 @@ def makeFileUpload(name, as_name=None):
path = makeFilePath(name) path = makeFilePath(name)
return FileUpload(path, as_name) return FileUpload(path, as_name)
class TestDocumentMixin(ERP5TypeTestCase):
class TestDocument(ERP5TypeTestCase, ZopeTestCase.Functional):
"""
Test basic document - related operations
"""
def getTitle(self):
return "DMS"
## setup
def setUpOnce(self): def setUpOnce(self):
self.setDefaultSitePreference()
self.setSystemPreference()
# set a dummy localizer (because normally it is cookie based) # set a dummy localizer (because normally it is cookie based)
self.portal.Localizer = DummyLocalizer() self.portal.Localizer = DummyLocalizer()
# make sure every body can traverse document module # make sure every body can traverse document module
...@@ -124,13 +112,19 @@ class TestDocument(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -124,13 +112,19 @@ class TestDocument(ERP5TypeTestCase, ZopeTestCase.Functional):
transaction.commit() transaction.commit()
self.tic() self.tic()
def afterSetUp(self):
self.setDefaultSitePreference()
self.setSystemPreference()
transaction.commit()
self.tic()
def setDefaultSitePreference(self): def setDefaultSitePreference(self):
default_pref = self.portal.portal_preferences.default_site_preference default_pref = self.portal.portal_preferences.default_site_preference
default_pref.setPreferredOoodocServerAddress(conversion_server_host[0]) default_pref.setPreferredOoodocServerAddress(conversion_server_host[0])
default_pref.setPreferredOoodocServerPortNumber(conversion_server_host[1]) default_pref.setPreferredOoodocServerPortNumber(conversion_server_host[1])
default_pref.setPreferredDocumentFileNameRegularExpression(FILE_NAME_REGULAR_EXPRESSION) default_pref.setPreferredDocumentFileNameRegularExpression(FILE_NAME_REGULAR_EXPRESSION)
default_pref.setPreferredDocumentReferenceRegularExpression(REFERENCE_REGULAR_EXPRESSION) default_pref.setPreferredDocumentReferenceRegularExpression(REFERENCE_REGULAR_EXPRESSION)
if default_pref.getPreferenceState() != 'global': if self.portal.portal_workflow.isTransitionPossible(default_pref, 'enable'):
default_pref.enable() default_pref.enable()
return default_pref return default_pref
...@@ -143,7 +137,7 @@ class TestDocument(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -143,7 +137,7 @@ class TestDocument(ERP5TypeTestCase, ZopeTestCase.Functional):
portal_type=portal_type) portal_type=portal_type)
else: else:
preference = preference_list[0] preference = preference_list[0]
if preference.getPreferenceState() != 'global': if self.portal.portal_workflow.isTransitionPossible(preference, 'enable'):
preference.enable() preference.enable()
return preference return preference
...@@ -182,6 +176,17 @@ class TestDocument(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -182,6 +176,17 @@ class TestDocument(ERP5TypeTestCase, ZopeTestCase.Functional):
transaction.commit() transaction.commit()
self.tic() self.tic()
class TestDocument(TestDocumentMixin):
"""
Test basic document - related operations
"""
def getTitle(self):
return "DMS"
## setup
## helper methods ## helper methods
def createTestDocument(self, file_name=None, portal_type='Text', reference='TEST', version='002', language='en'): def createTestDocument(self, file_name=None, portal_type='Text', reference='TEST', version='002', language='en'):
...@@ -1636,63 +1641,19 @@ style=3D'color:black'>05D65812<o:p></o:p></span></p> ...@@ -1636,63 +1641,19 @@ style=3D'color:black'>05D65812<o:p></o:p></span></p>
result_list.append(i) result_list.append(i)
self.assertEquals(result_list, []) self.assertEquals(result_list, [])
class TestDocumentWithSecurity(ERP5TypeTestCase): class TestDocumentWithSecurity(TestDocumentMixin):
username = 'yusei' username = 'yusei'
def getTitle(self): def getTitle(self):
return "DMS with security" return "DMS with security"
def afterSetUp(self):
self.setDefaultSitePreference()
self.setSystemPreference()
# set a dummy localizer (because normally it is cookie based)
self.portal.Localizer = DummyLocalizer()
# make sure every body can traverse document module
self.portal.document_module.manage_permission('View', ['Anonymous'], 1)
self.portal.document_module.manage_permission(
'Access contents information', ['Anonymous'], 1)
transaction.commit()
self.tic()
self.login()
def setDefaultSitePreference(self):
default_pref = self.portal.portal_preferences.default_site_preference
default_pref.setPreferredOoodocServerAddress(conversion_server_host[0])
default_pref.setPreferredOoodocServerPortNumber(conversion_server_host[1])
default_pref.setPreferredDocumentFileNameRegularExpression(FILE_NAME_REGULAR_EXPRESSION)
default_pref.setPreferredDocumentReferenceRegularExpression(REFERENCE_REGULAR_EXPRESSION)
if default_pref.getPreferenceState() != 'global':
default_pref.enable()
return default_pref
def setSystemPreference(self):
portal_type = 'System Preference'
preference_list = self.portal.portal_preferences.contentValues(
portal_type=portal_type)
if not preference_list:
preference = self.portal.portal_preferences.newContent(
portal_type=portal_type)
else:
preference = preference_list[0]
if preference.getPreferenceState() != 'global':
preference.enable()
return preference
def login(self): def login(self):
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
uf._doAddUser(self.username, '', ['Auditor', 'Author'], []) uf._doAddUser(self.username, '', ['Auditor', 'Author'], [])
user = uf.getUserById(self.username).__of__(uf) user = uf.getUserById(self.username).__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
def getDocumentModule(self):
return getattr(self.getPortal(),'document_module')
def getBusinessTemplateList(self):
return ('erp5_base',
'erp5_ingestion', 'erp5_ingestion_mysql_innodb_catalog',
'erp5_web', 'erp5_dms')
def test_ShowPreviewAfterSubmitted(self, quiet=QUIET, run=RUN_ALL_TEST): def test_ShowPreviewAfterSubmitted(self, quiet=QUIET, run=RUN_ALL_TEST):
""" """
Make sure that uploader can preview document after submitted. Make sure that uploader can preview document after submitted.
......
...@@ -33,7 +33,7 @@ import time ...@@ -33,7 +33,7 @@ import time
import transaction import transaction
from Testing import ZopeTestCase from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from testDms import TestDocumentMixin
from Products.ERP5Type.tests.utils import FileUpload from Products.ERP5Type.tests.utils import FileUpload
from Products.ERP5Type.tests.utils import DummyLocalizer from Products.ERP5Type.tests.utils import DummyLocalizer
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
...@@ -59,7 +59,7 @@ def makeFileUpload(name, as_name=None): ...@@ -59,7 +59,7 @@ def makeFileUpload(name, as_name=None):
return FileUpload(path, as_name) return FileUpload(path, as_name)
class TestDocumentConversionCache(ERP5TypeTestCase, ZopeTestCase.Functional): class TestDocumentConversionCache(TestDocumentMixin):
""" """
Test basic document - related operations Test basic document - related operations
""" """
...@@ -76,39 +76,7 @@ class TestDocumentConversionCache(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -76,39 +76,7 @@ class TestDocumentConversionCache(ERP5TypeTestCase, ZopeTestCase.Functional):
) )
def getTitle(self): def getTitle(self):
return "DMS" return "OOo Conversion Cache"
## setup
def afterSetUp(self):
self.setSystemPreference()
# set a dummy localizer (because normally it is cookie based)
self.portal.Localizer = DummyLocalizer()
# make sure every body can traverse document module
self.portal.document_module.manage_permission('View', ['Anonymous'], 1)
self.portal.document_module.manage_permission(
'Access contents information', ['Anonymous'], 1)
def setSystemPreference(self):
default_pref = self.portal.portal_preferences.default_site_preference
default_pref.setPreferredOoodocServerAddress(conversion_server_host[0])
default_pref.setPreferredOoodocServerPortNumber(conversion_server_host[1])
default_pref.setPreferredDocumentFileNameRegularExpression(FILE_NAME_REGULAR_EXPRESSION)
default_pref.setPreferredDocumentReferenceRegularExpression(REFERENCE_REGULAR_EXPRESSION)
default_pref.setPreferredConversionCacheFactory('document_cache_factory')
if default_pref.getPreferenceState() != 'global':
default_pref.enable()
def getDocumentModule(self):
return getattr(self.getPortal(),'document_module')
def getBusinessTemplateList(self):
return ('erp5_base',
'erp5_ingestion', 'erp5_ingestion_mysql_innodb_catalog',
'erp5_web', 'erp5_dms')
def getNeededCategoryList(self):
return ()
def beforeTearDown(self): def beforeTearDown(self):
""" """
...@@ -117,18 +85,6 @@ class TestDocumentConversionCache(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -117,18 +85,6 @@ class TestDocumentConversionCache(ERP5TypeTestCase, ZopeTestCase.Functional):
""" """
self.clearDocumentModule() self.clearDocumentModule()
def clearDocumentModule(self):
"""
Remove everything after each run
"""
transaction.abort()
self.tic()
doc_module = self.getDocumentModule()
ids = [i for i in doc_module.objectIds()]
doc_module.manage_delObjects(ids)
transaction.commit()
self.tic()
def clearCache(self): def clearCache(self):
self.portal.portal_caches.clearAllCache() self.portal.portal_caches.clearAllCache()
......
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