Commit c4bb81fa authored by Bartek Górny's avatar Bartek Górny

specs for testing core dms

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14037 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent de228781
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
""" """
A test suite for Document Management System functionality. A test suite for Document Management System functionality.
This will test: This will test:
- creating text documents - creating Text Document objects
- setting properties of a document, assigning local roles - setting properties of a document, assigning local roles
- setting relations between documents (explicit and implicity) - setting relations between documents (explicit and implicity)
- searching in basic and advanced modes - searching in basic and advanced modes
...@@ -51,15 +51,6 @@ ...@@ -51,15 +51,6 @@
from random import randint from random import randint
import os, 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'
from Testing import ZopeTestCase from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.SecurityManagement import newSecurityManager, noSecurityManager from AccessControl.SecurityManagement import newSecurityManager, noSecurityManager
...@@ -70,21 +61,68 @@ import os ...@@ -70,21 +61,68 @@ import os
from Products.ERP5Type import product_path from Products.ERP5Type import product_path
from Products.ERP5OOo.Document.OOoDocument import ConversionError from Products.ERP5OOo.Document.OOoDocument import ConversionError
import os, 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'
QUIET = 0
RUN_ALL_TEST = 0
# Define the conversion server host
conversion_server_host = ('127.0.0.1', 8008)
def printAndLog(msg):
"""
A utility function to print a message
to the standard output and to the LOG
at the same time
"""
if not QUIET:
msg = str(msg)
ZopeTestCase._print('\n ' + msg)
LOG('Testing... ', 0, msg)
class FileUploadTest(file):
__allow_access_to_unprotected_subobjects__=1
def __init__(self, path, name):
self.filename = name
file.__init__(self, path)
self.headers = {}
def makeFilePath(name):
return os.getenv('INSTANCE_HOME') + '/../Products/ERP5OOo/tests/test_document/' + name
def makeFileUpload(name):
path = makeFilePath(name)
return FileUploadTest(path, name)
class TestDocument(ERP5TypeTestCase): class TestDocument(ERP5TypeTestCase):
""" """
""" """
# Different variables used for this test # Different variables used for this test
run_all_test = 1
def getTitle(self): def getTitle(self):
return "DMS" return "DMS"
## setup ## setup
def afterSetUp(self, quiet=1, run=1): def afterSetUp(self, quiet=QUIET, run=1):
self.createCategories() self.createCategoryList()
self.createObjects() self.createObjectList()
self.setSystemPreference()
self.login() self.login()
portal = self.getPortal() portal = self.getPortal()
...@@ -97,7 +135,7 @@ class TestDocument(ERP5TypeTestCase): ...@@ -97,7 +135,7 @@ class TestDocument(ERP5TypeTestCase):
def getNeededCategoryList(self): def getNeededCategoryList(self):
return ('function/publication/reviewer','function/project/director','function/hq') return ('function/publication/reviewer','function/project/director','function/hq')
def createCategories(self): def createCategoryList(self):
"""Create the categories for our test. """ """Create the categories for our test. """
# create categories # create categories
for cat_string in self.getNeededCategoryList(): for cat_string in self.getNeededCategoryList():
...@@ -108,54 +146,72 @@ class TestDocument(ERP5TypeTestCase): ...@@ -108,54 +146,72 @@ class TestDocument(ERP5TypeTestCase):
path = path.newContent( path = path.newContent(
portal_type='Category', portal_type='Category',
id=cat, id=cat,
title=cat,
immediate_reindex=1) immediate_reindex=1)
else: else:
path = path[cat] path = path[cat]
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(
"(?P<reference>[A-Z]{3,6})-(?P<language>[a-z]{2})-(?P<version>[0-9]{3})")
default_pref.setPreferredReferenceLookupRegularExpression(
"(?P<reference>[A-Z]{3,6})(-(?P<language>[a-z]{2}))?(-(?P<version>[0-9]{3}))?")
default_pref.enable()
## helper methods ## helper methods
def getUserFolder(self): def getUserFolder(self):
return self.getPortal().acl_users return self.getPortal().acl_users
def createObjects(self): def login(self, quiet=QUIET, run=RUN_ALL_TEST):
if not hasattr(self.getPortal().person_module,'1'): """
p1=self.getPortal().person_module.newContent(portal_type='Person',id='1',first_name='John',last_name='McCartney',reference='john',career_role='internal') Create a new manager user and login.
get_transaction().commit() """
self.tic() user_name = 'dms_user'
user_folder = self.portal.acl_users
def getTestUser(self): user_folder._doAddUser(user_name, '', ['Manager', 'Owner', 'Assignor'], [])
user = self.getUserFolder().getUserById('john') user = user_folder.getUserById(user_name).__of__(user_folder)
self.failIf(user is None)
return user
def login(self, quiet=0, run=run_all_test):
uf = self.getPortal().acl_users
uf._doAddUser('seb', '', ['Manager'], [])
user = uf.getUserById('seb').__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
def _addRoleToDoc(self,doc): def createTestDocument(self, file_name=None, reference='TEST', version='002', language='en'):
role=doc.newContent(portal_type='Role Definition') """
role._edit(agent='person_module/1',role_name='Assignor') Creates a text document
"""
def createTestDocument(self):
dm=self.getPortal().document_module dm=self.getPortal().document_module
doctext=dm.newContent(portal_type='Text') doctext=dm.newContent(portal_type='Text Document')
doctext._getServerCoordinate=lambda:('127.0.0.1',8080) if file_name is not None:
f=FileObject(os.getenv('INSTANCE_HOME')+'/../Products/ERP5OOo/tests/test.doc') f = open(makeFilePath(file_name))
f.filename='test.doc' doctext.setTextContent(f.read())
doctext._edit(file=f)
f.close() f.close()
doctext.convert() doctext.setReference(reference)
doctext.setVersion(version)
doctext.setLanguage(language)
return doctext return doctext
def getDocument(self, id):
"""
Returns a document with given ID in the
document module.
"""
document_module = self.portal.document_module
return getattr(document_module, id)
## steps
def stepTic(self, sequence=None, sequence_list=None, **kw):
self.tic()
## tests ## tests
def test_01_HasEverything(self, quiet=0, run=run_all_test): def test_01_HasEverything(self, quiet=QUIET, run=RUN_ALL_TEST):
"""
Standard test to make sure we have everything we need - all the tools etc
"""
if not run: return if not run: return
if not quiet: printAndLog('\nTest Has Everything ')
ZopeTestCase._print('\nTest Has Everything ')
LOG('Testing... ',0,'testHasEverything')
self.failUnless(self.getCategoryTool()!=None) self.failUnless(self.getCategoryTool()!=None)
self.failUnless(self.getSimulationTool()!=None) self.failUnless(self.getSimulationTool()!=None)
self.failUnless(self.getTypeTool()!=None) self.failUnless(self.getTypeTool()!=None)
...@@ -163,18 +219,119 @@ class TestDocument(ERP5TypeTestCase): ...@@ -163,18 +219,119 @@ class TestDocument(ERP5TypeTestCase):
self.failUnless(self.getCatalogTool()!=None) self.failUnless(self.getCatalogTool()!=None)
self.failUnless(self.getWorkflowTool()!=None) self.failUnless(self.getWorkflowTool()!=None)
def test_02_ObjectCreation(self,quiet=0,run=run_all_test): def test_02_RevisionSystem(self,quiet=QUIET,run=RUN_ALL_TEST):
if not quiet: """
ZopeTestCase._print('\nTest Object Creation') Test revision mechanism
LOG('Testing... ',0,'test_02_ObjectCreation') """
dm=self.getPortal().document_module if not run: return
doctext=dm.newContent(portal_type='Text') printAndLog('\nTest Revision System')
self._addRoleToDoc(doctext) # create a test document
get_transaction().commit() # revision should be 1
doctext.updateLocalRolesOnSecurityGroups() # upload file (can be the same) into it
self.tic() # revision should now be 2
u=self.getTestUser() # edit the document with any value or no values
self.failUnless('Assignor' in u.getRolesInContext(doctext)) # revision should now be 3
# contribute the same file through portal_contributions
# there should still be only one document, with revision 4 (because it should have done mergeRevision)
# getRevisionList should return (1, 2, 3, 4)
def test_03_Versioning(self,quiet=QUIET,run=RUN_ALL_TEST):
"""
Test versioning
"""
if not run: return
printAndLog('\nTest Versioning System')
# create a test document, set coordinates (reference=TEST, version=002, language=en)
# create a second test document, set coordinates (reference=TEST, version=002, language=en)
# create a third test document, set its reference to ANOTHER
# run isVersionUnique on all three (should return False, False, True)
# change version of the second doc to 003
# run isVersionUnique on all three (should return True)
# run getLatestVersionValue on first and second (should return the second)
# run getVersionValueList on first and second (should return the two)
# run getVersionValueList on third (should return the third)
def test_04_VersioningWithLanguage(self,quiet=QUIET,run=RUN_ALL_TEST):
"""
Test versioning with multi-language support
"""
if not run: return
printAndLog('\nTest Versioning With Language')
# create empty test documents, set their coordinates as follows:
# (1) TEST, 002, en
# (2) TEST, 002, fr
# (3) TEST, 002, pl
# (4) TEST, 003, en
# (5) TEST, 003, sp
# the following calls should produce the following output:
# getOriginalLanguage() = 'en'
# getLanguageList = ('en', 'fr', 'pl', 'sp')
# getLatestVersionValue() = 4
# getLatestVersionValue('en') = 4
# getLatestVersionValue('fr') = 2
# getLatestVersionValue('pl') = 3
# getLatestVersionValue('ru') = None
# Set user language with Localizer to 'sp'
# getLatestVersionValue() = 5
def test_05_UniqueReference(self,quiet=QUIET,run=RUN_ALL_TEST):
"""
Test automatic setting of unique reference
"""
if not run: return
printAndLog('\nTest Automatic Setting Unique Reference')
# create three empty test documents
# run setUniqueReference on the second
# reference of the second doc should now be TEST-auto-2
# run setUniqueReference('uniq') on the third
# reference of the third doc should now be TEST-uniq-1
def test_06_testExplicitRelations(self,quiet=QUIET,run=RUN_ALL_TEST):
"""
Test explicit relations.
Explicit relations are just like any other relation, so no need to test them here
except for similarity cloud which we test.
"""
if not run: return
printAndLog('\nTest Explicit Relations')
# create test documents:
# (1) TEST, 002, en
# (2) TEST, 003, en
# (3) ONE, 001, en
# (4) TWO, 001, en
# (5) THREE, 001, en
# set 3 similar to 1, 4 to 3, 5 to 4
# getSimilarCloudValueList on 4 should return 2, 3 and 5
# getSimilarCloudValueList(depth=1) on 4 should return 3 and 5
def test_07_testImplicitRelations(self,quiet=QUIET,run=RUN_ALL_TEST):
"""
Test implicit (wiki-like) relations.
"""
# XXX this test should be extended to check more elaborate language selection
if not run: return
printAndLog('\nTest Implicit Relations')
# create docs to be referenced:
# (1) TEST, 002, en
# (2) TEST, 002, fr
# (3) TEST, 003, en
# create docs to contain references in text_content:
# REF, 001, en; "I use reference to look up TEST"
# REF, 002, en; "I use reference to look up TEST"
# REFLANG, 001, en: "I use reference and language to look up TEST-fr"
# REFVER, 001, en: "I use reference and version to look up TEST-002"
# REFVERLANG, 001, en: "I use reference, version and language to look up TEST-002-en"
printAndLog('\nTesting Implicit Predecessors')
# the implicit predecessors should be:
# for (1): REF-002, REFVER, REFVERLANG
# for (2): REF-002, REFLANG, REFVER
# for (3): REF-002
printAndLog('\nTesting Implicit Successors')
# the implicit successors should be:
# for REF: (3)
# for REFLANG: (2)
# for REFVER: (3)
# for REFVERLANG: (3)
if __name__ == '__main__': if __name__ == '__main__':
framework() framework()
......
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