Commit aeceac29 authored by Jérome Perrin's avatar Jérome Perrin

ooo_import: py3

parent 4b5ce30f
......@@ -17,7 +17,7 @@ if active_process_path is None:
active_process_value = context.getPortalObject().restrictedTraverse(active_process_path)
result_list = [[x.method_id, x.result] for x in active_process_value.getResultList()]
result_list.sort()
result_list.sort(key=str)
for [method_id, result] in result_list:
safe_id = context.Base_getSafeIdFromString('result %s' % num)
......
......@@ -153,7 +153,9 @@ else:
if property_value:
# Create a new property value
property_id = column_mapping[line_property_index]
imported_line_property_dict[property_id] = property_value.encode('UTF-8')
if six.PY2:
property_value = property_value.encode('UTF-8')
imported_line_property_dict[property_id] = property_value
# If the line is not empty, activate an activity for it
......
......@@ -16,6 +16,7 @@
from ZODB.POSException import ConflictError
from Products.ERP5Type.Message import Message
import six
#Create new ERP5 objects In Activity from OOo document
imported_line = object_url = None
......@@ -46,7 +47,7 @@ else:
# Separate categories from properties
imported_line_category_dict = {}
for prop_key in imported_line_property_dict.keys():
for prop_key in list(six.iterkeys(imported_line_property_dict)):
if prop_key in base_category_list:
imported_line_category_dict[prop_key] = imported_line_property_dict.pop(prop_key)
......@@ -67,7 +68,7 @@ else:
success = 0
# Save the categories
for category, value in imported_line_category_dict.items():
for category, value in list(six.iteritems(imported_line_category_dict)):
category_dict = context.ERP5Site_getCategoriesFullPath(
category_dict={category: value})
if category_dict not in (None, {}):
......
......@@ -38,17 +38,21 @@ from Products.ERP5OOo.OOoUtils import OOoParser
from DateTime import DateTime
import six
def makeFilePath(name):
return os.path.join(os.path.dirname(__file__), 'test_document', name)
def makeFileUpload(name):
path = makeFilePath(name)
return FileUpload(path, name)
class TestOOoImportMixin(ERP5TypeTestCase):
gender_base_cat_id = 'gender'
function_base_cat_id = 'function'
def makeFileUpload(self, name):
path = makeFilePath(name)
fu = FileUpload(path, name)
self.addCleanup(fu.close)
return fu
def afterSetUp(self):
"""
Initialize the ERP5 site.
......@@ -91,6 +95,7 @@ class TestOOoImportMixin(ERP5TypeTestCase):
self.portal.portal_categories.gender,
self.portal.portal_categories.region,
]:
parent.setLastId('0')
parent.deleteContent(list(parent.objectIds()))
self.tic()
......@@ -119,7 +124,7 @@ class TestOOoImport(TestOOoImportMixin):
## Basic steps
##################################
def stepImportRawDataFile(self, sequence=None, sequence_list=None, **kw):
f = makeFileUpload('import_data_list.ods')
f = self.makeFileUpload('import_data_list.ods')
person_module = self.getPortal().person_module
listbox=(
{ 'listbox_key': '001',
......@@ -285,7 +290,7 @@ class TestOOoImport(TestOOoImportMixin):
sorted([organisation_list[i].getEmailText() for i in range(num)]))
def stepImportFileNoMapping(self, sequence=None, sequence_list=None, **kw):
f = makeFileUpload('import_data_list.ods')
f = self.makeFileUpload('import_data_list.ods')
person_module = self.getPortal().person_module
listbox = (
......@@ -302,7 +307,7 @@ class TestOOoImport(TestOOoImportMixin):
'portal_status_message=Please%20Define%20a%20mapping.'))
def stepImportFileWithBlankLine(self, sequence=None, sequence_list=None, **kw):
f = makeFileUpload('import_data_list_blank_line.ods')
f = self.makeFileUpload('import_data_list_blank_line.ods')
person_module = self.getPortal().person_module
listbox=(
{ 'listbox_key': '001',
......@@ -317,7 +322,7 @@ class TestOOoImport(TestOOoImportMixin):
person_module.Base_importFile(import_file=f, listbox=listbox)
def stepImportFileWithCategory(self, sequence=None, sequence_list=None, **kw):
f = makeFileUpload('import_data_with_categories.ods')
f = self.makeFileUpload('import_data_with_categories.ods')
# create some regions
region = self.portal.portal_categories.region
europe = region.newContent(portal_type='Category',
......@@ -343,7 +348,7 @@ class TestOOoImport(TestOOoImportMixin):
person_module.Base_importFile(import_file=f, listbox=listbox)
def stepImportFileWithDates(self, sequence=None, sequence_list=None, **kw):
f = makeFileUpload('import_data_with_dates.ods')
f = self.makeFileUpload('import_data_with_dates.ods')
person_module = self.getPortal().person_module
listbox=(
{ 'listbox_key': '001',
......@@ -362,7 +367,7 @@ class TestOOoImport(TestOOoImportMixin):
This test make sure that either floats (1000,9), sientific numbers (1,00E+003)
or percentage (19%) are correctly imported .
"""
f = makeFileUpload('import_float_and_percentage.ods')
f = self.makeFileUpload('import_float_and_percentage.ods')
currency_module = self.getPortal().currency_module
listbox=(
{ 'listbox_key': '001',
......@@ -373,7 +378,7 @@ class TestOOoImport(TestOOoImportMixin):
currency_module.Base_importFile(import_file=f, listbox=listbox)
def stepImportOrganisation(self, sequence=None, sequence_list=None, **kw):
f = makeFileUpload('import_organisation_list.ods')
f = self.makeFileUpload('import_organisation_list.ods')
organisation_module = self.getPortal().organisation_module
listbox=(
{ 'listbox_key': '001',
......@@ -403,7 +408,7 @@ class TestOOoImport(TestOOoImportMixin):
user = user_folder.getUserById(user_name).__of__(user_folder)
newSecurityManager(None, user)
f = makeFileUpload('import_data_with_categories.ods')
f = self.makeFileUpload('import_data_with_categories.ods')
person_module = self.getPortal().person_module
listbox=(
{ 'listbox_key': '001',
......@@ -420,7 +425,7 @@ class TestOOoImport(TestOOoImportMixin):
person_module.Base_importFile(import_file=f, listbox=listbox)
def stepImportFileWithFreeText(self, sequence=None, sequence_list=None, **kw):
f = makeFileUpload('import_data_with_categories.ods')
f = self.makeFileUpload('import_data_with_categories.ods')
person_module = self.getPortal().person_module
listbox=(
{ 'listbox_key': '001',
......@@ -435,7 +440,7 @@ class TestOOoImport(TestOOoImportMixin):
person_module.Base_importFile(import_file=f, listbox=listbox)
def stepImportFileWithAccentuatedText(self, sequence=None, sequence_list=None, **kw):
f = makeFileUpload('import_data_accentuated_text.ods')
f = self.makeFileUpload('import_data_accentuated_text.ods')
person_module = self.getPortal().person_module
listbox=(
{ 'listbox_key': '001',
......@@ -450,7 +455,7 @@ class TestOOoImport(TestOOoImportMixin):
person_module.Base_importFile(import_file=f, listbox=listbox)
def stepImportXLSFile(self, sequence=None, sequence_list=None, **kw):
f = makeFileUpload('import_data_list.xls')
f = self.makeFileUpload('import_data_list.xls')
person_module = self.getPortal().person_module
listbox=(
{ 'listbox_key': '001',
......@@ -465,7 +470,7 @@ class TestOOoImport(TestOOoImportMixin):
person_module.Base_importFile(import_file=f, listbox=listbox)
def stepImportBigFile_1(self, sequence=None, sequence_list=None, **kw):
f = makeFileUpload('import_data_big_file_1.ods')
f = self.makeFileUpload('import_data_big_file_1.ods')
person_module = self.getPortal().person_module
listbox=(
{ 'listbox_key': '001',
......@@ -480,7 +485,7 @@ class TestOOoImport(TestOOoImportMixin):
person_module.Base_importFile(import_file=f, listbox=listbox)
def stepImportBigFile_2(self, sequence=None, sequence_list=None, **kw):
f = makeFileUpload('import_data_big_file_2.ods')
f = self.makeFileUpload('import_data_big_file_2.ods')
person_module = self.getPortal().person_module
listbox=(
{ 'listbox_key': '001',
......@@ -631,7 +636,7 @@ class TestOOoImport(TestOOoImportMixin):
def test_CategoryTool_importCategoryFile(self):
# tests simple use of CategoryTool_importCategoryFile script
self.portal.portal_categories.CategoryTool_importCategoryFile(
import_file=makeFileUpload('import_region_category.sxc'))
import_file=self.makeFileUpload('import_region_category.sxc'))
self.tic()
region = self.portal.portal_categories.region
self.assertEqual(2, len(region))
......@@ -651,7 +656,7 @@ class TestOOoImport(TestOOoImportMixin):
region.newContent(id='dummy_region')
self.tic()
self.portal.portal_categories.CategoryTool_importCategoryFile(
import_file=makeFileUpload('import_region_category.sxc'),
import_file=self.makeFileUpload('import_region_category.sxc'),
existing_category_list='delete')
self.tic()
self.assertEqual(2, len(region))
......@@ -674,7 +679,7 @@ class TestOOoImport(TestOOoImportMixin):
)
self.tic()
self.portal.portal_categories.CategoryTool_importCategoryFile(
import_file=makeFileUpload('import_region_category.sxc'),
import_file=self.makeFileUpload('import_region_category.sxc'),
existing_category_list='delete')
self.tic()
self.assertEqual(3, len(region))
......@@ -690,7 +695,7 @@ class TestOOoImport(TestOOoImportMixin):
)
self.tic()
self.portal.portal_categories.CategoryTool_importCategoryFile(
import_file=makeFileUpload('import_region_category.sxc'),
import_file=self.makeFileUpload('import_region_category.sxc'),
existing_category_list='force_delete')
self.tic()
self.assertEqual(2, len(region))
......@@ -702,7 +707,7 @@ class TestOOoImport(TestOOoImportMixin):
region.newContent(id='dummy_region')
self.tic()
self.portal.portal_categories.CategoryTool_importCategoryFile(
import_file=makeFileUpload('import_region_category.sxc'),
import_file=self.makeFileUpload('import_region_category.sxc'),
existing_category_list='expire')
self.tic()
self.assertEqual(3, len(region))
......@@ -720,7 +725,7 @@ class TestOOoImport(TestOOoImportMixin):
def test_CategoryTool_importCategoryFileXLS(self):
# tests that CategoryTool_importCategoryFile supports .xls files
self.portal.portal_categories.CategoryTool_importCategoryFile(
import_file=makeFileUpload('import_region_category.xls'))
import_file=self.makeFileUpload('import_region_category.xls'))
self.tic()
region = self.portal.portal_categories.region
self.assertEqual(2, len(region))
......@@ -736,7 +741,7 @@ class TestOOoImport(TestOOoImportMixin):
def test_CategoryTool_importCategoryFile_PathStars(self):
# tests CategoryTool_importCategoryFile with * in the paths columns
self.portal.portal_categories.CategoryTool_importCategoryFile(
import_file=makeFileUpload('import_region_category_path_stars.sxc'))
import_file=self.makeFileUpload('import_region_category_path_stars.sxc'))
self.tic()
region = self.portal.portal_categories.region
self.assertEqual(2, len(region))
......@@ -753,7 +758,7 @@ class TestOOoImport(TestOOoImportMixin):
# tests CategoryTool_importCategoryFile with * in the paths columns, and no
# ID column, and non ascii titles
self.portal.portal_categories.CategoryTool_importCategoryFile(
import_file=makeFileUpload(
import_file=self.makeFileUpload(
'import_region_category_path_stars_non_ascii.sxc'))
self.tic()
region = self.portal.portal_categories.region
......@@ -772,7 +777,7 @@ class TestOOoImport(TestOOoImportMixin):
# categories ID at different level (a good candidate for an acquisition
# bug)
self.portal.portal_categories.CategoryTool_importCategoryFile(
import_file=makeFileUpload('import_region_category_duplicate_ids.sxc'))
import_file=self.makeFileUpload('import_region_category_duplicate_ids.sxc'))
self.tic()
region = self.portal.portal_categories.region
self.assertEqual(1, len(region))
......@@ -786,7 +791,7 @@ class TestOOoImport(TestOOoImportMixin):
def test_Base_getCategoriesSpreadSheetMapping(self):
# test structure returned by Base_getCategoriesSpreadSheetMapping
mapping = self.portal.Base_getCategoriesSpreadSheetMapping(
import_file=makeFileUpload('import_region_category.sxc'))
import_file=self.makeFileUpload('import_region_category.sxc'))
self.assertTrue(isinstance(mapping, dict))
self.assertEqual(['region'], list(mapping.keys()))
region = mapping['region']
......@@ -816,7 +821,7 @@ class TestOOoImport(TestOOoImportMixin):
def test_Base_getCategoriesSpreadSheetMapping_DuplicateIdsAtSameLevel(self):
# tests Base_getCategoriesSpreadSheetMapping when a document contain same
# categories ID at the same level, in that case, a ValueError is raised
import_file = makeFileUpload(
import_file = self.makeFileUpload(
'import_region_category_duplicate_ids_same_level.sxc')
try:
self.portal.portal_categories.Base_getCategoriesSpreadSheetMapping(
......@@ -834,7 +839,7 @@ class TestOOoImport(TestOOoImportMixin):
def on_invalid_spreadsheet(message):
message_list.append(message)
import_file = makeFileUpload(
import_file = self.makeFileUpload(
'import_region_category_duplicate_ids_same_level.sxc')
self.portal.portal_categories.Base_getCategoriesSpreadSheetMapping(import_file,
invalid_spreadsheet_error_handler=on_invalid_spreadsheet)
......@@ -845,7 +850,7 @@ class TestOOoImport(TestOOoImportMixin):
def test_Base_getCategoriesSpreadSheetMapping_WrongHierarchy(self):
# tests Base_getCategoriesSpreadSheetMapping when the spreadsheet has an
# invalid hierarchy (#788)
import_file = makeFileUpload(
import_file = self.makeFileUpload(
'import_region_category_wrong_hierarchy.sxc')
try:
self.portal.portal_categories.Base_getCategoriesSpreadSheetMapping(
......@@ -859,7 +864,7 @@ class TestOOoImport(TestOOoImportMixin):
def test_Base_getCategoriesSpreadSheetMapping_MultiplePaths(self):
# If multiple paths is defined (for instance more than one * in paths
# columns), then it should be an error and the error must be reported
import_file = makeFileUpload(
import_file = self.makeFileUpload(
'import_region_category_multiple_paths.ods')
try:
self.portal.portal_categories.Base_getCategoriesSpreadSheetMapping(
......@@ -871,7 +876,7 @@ class TestOOoImport(TestOOoImportMixin):
def test_Base_getCategoriesSpreadSheetMapping_Id_is_reserved_property_name(self):
# tests Base_getCategoriesSpreadSheetMapping reserved property name are only test for path column, not all.
import_file = makeFileUpload(
import_file = self.makeFileUpload(
'import_region_category_with_reserved_id_in_title.sxc')
mapping = self.portal.portal_categories.Base_getCategoriesSpreadSheetMapping(
import_file=import_file)
......@@ -897,7 +902,7 @@ class TestOOoImport(TestOOoImportMixin):
return True
self.portal.portal_categories.Base_getCategoriesSpreadSheetMapping(
import_file=makeFileUpload('import_category_with_reserved_id_in_id.sxc'),
import_file=self.makeFileUpload('import_category_with_reserved_id_in_id.sxc'),
invalid_spreadsheet_error_handler=on_invalid_spreadsheet)
self.assertEqual(message_set, {
......@@ -948,7 +953,7 @@ class TestOOoImportWeb(TestOOoImportMixin):
dummy_expired_region.expire()
self.tic()
self.portal.portal_categories.CategoryTool_importCategoryFile(
import_file=makeFileUpload('import_region_category.sxc'),
import_file=self.makeFileUpload('import_region_category.sxc'),
existing_category_list='expire')
self.tic()
self.assertEqual(4, len(region))
......
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