Commit 9611005c authored by Nicolas Delaby's avatar Nicolas Delaby

Update importing test

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14003 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 050719ee
......@@ -85,7 +85,7 @@ class FileUploadTest(file):
self.headers = {}
def makeFilePath(name):
return os.getenv('INSTANCE_HOME') + '/../Products/ERP5OOo/tests/data/' + name
return os.getenv('INSTANCE_HOME') + '/../Products/ERP5OOo/tests/test_document/' + name
def makeFileUpload(name):
path = makeFilePath(name)
......@@ -125,60 +125,6 @@ class TestOOoImport(ERP5TypeTestCase):
self.portal = self.getPortal()
self.portal_categories = self.getCategoryTool()
self.portal_catalog = self.getCatalogTool()
self.createCategories()
self.createPreferences()
self.createTools()
self.unpackData()
def unpackData(self):
"""
Unpack the content of testIngestion_docs.zip
"""
join = os.path.join
base_path = join(os.getenv('INSTANCE_HOME'), '..', 'Products', 'ERP5OOo', 'tests')
zf = zipfile.ZipFile(join(base_path, 'testIngestion_docs.zip'))
data_dir = join(base_path, 'data')
if not os.path.isdir(data_dir):
os.mkdir(data_dir)
for name in zf.namelist():
fname = join(data_dir, name)
if not os.path.exists(fname):
try:
f = open(fname, 'w')
f.write(zf.read(name))
finally:
f.close()
def createTools(self):
"""
Set up contribution tool and content type registry
"""
# XXX portal_contributions is not created in bootstrap
# so we have to create it here
# before we delete in case it was created before and --saved
try:
self.portal._delObject('portal_contributions')
except AttributeError:
pass
addTool = self.portal.manage_addProduct['ERP5'].manage_addTool
addTool('ERP5 Contribution Tool', None)
# the same for portal_mailin
try:
self.portal._delObject('portal_mailin')
except AttributeError:
pass
addTool = self.portal.manage_addProduct['CMFMailIn'].manage_addTool
addTool('CMF Mail In Tool', None)
mailin = self.portal.portal_mailin
mailin.edit_configuration('Document_ingestEmail')
def createPreferences(self):
default_pref = self.portal.portal_preferences.default_site_preference
default_pref.setPreferredOoodocServerAddress(ooodoc_coordinates[0])
default_pref.setPreferredOoodocServerPortNumber(ooodoc_coordinates[1])
default_pref.setPreferredDocumentFileNameRegularExpression("(?P<reference>[A-Z]{3,6})-(?P<language>[a-z]{2})-(?P<version>[0-9]{3})")
default_pref.enable()
##################################
## Useful methods
......@@ -194,94 +140,15 @@ class TestOOoImport(ERP5TypeTestCase):
user = user_folder.getUserById(user_name).__of__(user_folder)
newSecurityManager(None, user)
def createCategories(self):
"""
Create some categories for testing.
"""
self.category_list = [
# Role categories
{'path' : 'role/internal'
,'title': 'Internal'
}
,{'path' : 'function/musician/wind/saxophone'
,'title': 'Saxophone'
}
,{'path' : 'group/medium'
,'title': 'Medium'
}
,{'path' : 'site/arctic/spitsbergen'
,'title': 'Spitsbergen'
}
,{'path' : 'group/anybody'
,'title': 'Anybody'
}
]
# Create categories
# Note : this code was taken from the CategoryTool_importCategoryFile python
# script (packaged in erp5_core).
for category in self.category_list:
keys = category.keys()
if 'path' in keys:
base_path_obj = self.portal_categories
is_base_category = True
for category_id in category['path'].split('/'):
# The current category is not existing
if category_id not in base_path_obj.contentIds():
# Create the category
if is_base_category:
category_type = 'Base Category'
else:
category_type = 'Category'
base_path_obj.newContent( portal_type = category_type
, id = category_id
, immediate_reindex = 1
)
base_path_obj = base_path_obj[category_id]
is_base_category = False
new_category = base_path_obj
# Set the category properties
for key in keys:
if key != 'path':
method_id = "set" + convertToUpperCase(key)
value = category[key]
if value not in ('', None):
if hasattr(new_category, method_id):
method = getattr(new_category, method_id)
method(value.encode('UTF-8'))
get_transaction().commit()
self.tic()
def getCategoryList(self, base_category=None):
"""
Get a list of categories with same base categories.
"""
categories = []
if base_category != None:
for category in self.category_list:
if category["path"].split('/')[0] == base_category:
categories.append(category)
return categories
def checkObjectCatalogged(self, portal_type, reference):
"""
make sure this object is already in the catalog
"""
res = self.portal_catalog(portal_type=portal_type, reference=reference)
self.assertEquals(len(res), 1)
self.assertEquals(res[0].getReference(), reference)
##################################
## Basic steps
##################################
def stepTic(self, sequence=None, sequence_list=None, **kw):
self.tic()
def stepImportRawDataFile(self, sequence=None, sequence_list=None, **kw):
f = makeFileUpload('TEST-en-003.ods')
f = makeFileUpload('import_data_list.ods')
person_module = self.getPortal().person_module
#purge existing persons
person_module.manage_delObjects([id for id in person_module.getObjectIds()])
......@@ -297,13 +164,13 @@ class TestOOoImport(ERP5TypeTestCase):
'portal_type_property_list':'Person.default_email_text'}
)
person_module.ERP5Site_importObjectFromOOo(import_file=f, listbox=listbox)
def stepCheckActivitiesCount(self, sequence=None, sequence_list=None, **kw):
message_list = self.getPortal().portal_activities.getMessageList()
self.assertEqual(1,len(message_list))
method_id = message_list[0].method_id
self.assertEqual('ERP5Site_importObjectFromOOoActivity',method_id)
def stepCheckImportedPersonList(self, sequence=None, sequence_list=None, **kw):
person_module = self.getPortal().person_module
for i in range(101):
......@@ -343,6 +210,3 @@ else:
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestOOoImport))
return suite
# vim: filetype=python syntax=python shiftwidth=2
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