Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexander Emmerich
erp5
Commits
aaca1dce
Commit
aaca1dce
authored
Jan 09, 2013
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move OOoParser tests to a simple unittest
parent
e5855dae
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
115 additions
and
66 deletions
+115
-66
product/ERP5OOo/tests/testOOoImport.py
product/ERP5OOo/tests/testOOoImport.py
+2
-66
product/ERP5OOo/tests/testOOoParser.py
product/ERP5OOo/tests/testOOoParser.py
+113
-0
No files found.
product/ERP5OOo/tests/testOOoImport.py
View file @
aaca1dce
...
...
@@ -33,26 +33,18 @@ import os
from
AccessControl.SecurityManagement
import
newSecurityManager
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
_getConversionServerDict
from
Products.ERP5Type.tests.utils
import
FileUpload
from
Products.ERP5Type.tests.Sequence
import
SequenceList
from
Products.ERP5OOo.OOoUtils
import
OOoParser
from
Products.ERP5Form.PreferenceTool
import
Priority
from
DateTime
import
DateTime
class
FileUploadTest
(
file
):
__allow_access_to_unprotected_subobjects__
=
1
def
__init__
(
self
,
path
,
name
):
self
.
filename
=
name
file
.
__init__
(
self
,
path
,
'rb'
)
self
.
headers
=
{}
def
makeFilePath
(
name
):
return
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'test_document'
,
name
)
def
makeFileUpload
(
name
):
path
=
makeFilePath
(
name
)
return
FileUpload
Test
(
path
,
name
)
return
FileUpload
(
path
,
name
)
class
TestOOoImportMixin
(
ERP5TypeTestCase
):
gender_base_cat_id
=
'gender'
...
...
@@ -766,62 +758,6 @@ class TestOOoImport(TestOOoImportMixin):
self
.
assertEquals
([
'france'
],
list
(
region
.
europe
.
france
.
europe
.
objectIds
()))
self
.
assertEquals
([],
list
(
region
.
europe
.
france
.
europe
.
france
.
objectIds
()))
# OOoParser tests
def
test_getSpreadSheetMapping
(
self
):
parser
=
OOoParser
()
parser
.
openFile
(
open
(
makeFilePath
(
'import_data_list.ods'
),
'rb'
))
mapping
=
parser
.
getSpreadsheetsMapping
()
self
.
assertEquals
([
'Person'
],
mapping
.
keys
())
person_mapping
=
mapping
[
'Person'
]
self
.
assertTrue
(
isinstance
(
person_mapping
,
list
))
self
.
assertTrue
(
102
,
len
(
person_mapping
))
self
.
assertEquals
(
person_mapping
[
0
],
[
'Title'
,
'First Name'
,
'Last Name'
,
'Default Email Text'
])
self
.
assertEquals
(
person_mapping
[
1
],
[
'John Doe 0'
,
'John'
,
'Doe 0'
,
'john.doe0@foo.com'
])
def
test_openFromString
(
self
):
parser
=
OOoParser
()
parser
.
openFromString
(
open
(
makeFilePath
(
'import_data_list.ods'
),
'rb'
).
read
())
mapping
=
parser
.
getSpreadsheetsMapping
()
self
.
assertEquals
([
'Person'
],
mapping
.
keys
())
def
test_getSpreadSheetMappingStyle
(
self
):
parser
=
OOoParser
()
parser
.
openFile
(
open
(
makeFilePath
(
'import_data_list_with_style.ods'
),
'rb'
))
mapping
=
parser
.
getSpreadsheetsMapping
()
self
.
assertEquals
([
'Feuille1'
],
mapping
.
keys
())
self
.
assertEquals
(
mapping
[
'Feuille1'
][
1
],
[
'a line with style'
])
self
.
assertEquals
(
mapping
[
'Feuille1'
][
2
],
[
'a line with multiple styles'
])
self
.
assertEquals
(
mapping
[
'Feuille1'
][
3
],
[
'http://www.erp5.org'
])
self
.
assertEquals
(
mapping
[
'Feuille1'
][
4
],
[
'john.doe@example.com'
])
def
test_getSpreadSheetMappingDataTypes
(
self
):
parser
=
OOoParser
()
parser
.
openFile
(
open
(
makeFilePath
(
'import_data_list_data_type.ods'
),
'rb'
))
mapping
=
parser
.
getSpreadsheetsMapping
()
self
.
assertEquals
([
'Feuille1'
],
mapping
.
keys
())
self
.
assertEquals
(
mapping
[
'Feuille1'
][
0
],
[
'1234.5678'
])
self
.
assertEquals
(
mapping
[
'Feuille1'
][
1
],
[
'1234.5678'
])
self
.
assertEquals
(
mapping
[
'Feuille1'
][
2
],
[
'0.1'
])
self
.
assertEquals
(
mapping
[
'Feuille1'
][
3
],
[
'2008-11-14'
])
self
.
assertEquals
(
mapping
[
'Feuille1'
][
4
],
[
'2008-11-14T10:20:30'
])
# supported by DateTime
self
.
assertEquals
(
mapping
[
'Feuille1'
][
5
],
[
'PT12H34M56S'
])
# maybe not good, this is raw format
self
.
assertEquals
(
mapping
[
'Feuille1'
][
6
],
[
'With note'
])
# Base_getCategoriesSpreadSheetMapping tests
def
test_Base_getCategoriesSpreadSheetMapping
(
self
):
# test structure returned by Base_getCategoriesSpreadSheetMapping
...
...
product/ERP5OOo/tests/testOOoParser.py
0 → 100644
View file @
aaca1dce
# -*- coding: utf-8 -*-
##############################################################################
# Copyright (c) 2012 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import
unittest
import
os
from
DateTime
import
DateTime
from
Products.ERP5OOo.OOoUtils
import
OOoParser
def
makeFilePath
(
name
):
return
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'test_document'
,
name
)
class
TestOOoParser
(
unittest
.
TestCase
):
""" OOoParser tests
"""
def
test_getSpreadSheetMapping
(
self
):
parser
=
OOoParser
()
parser
.
openFile
(
open
(
makeFilePath
(
'import_data_list.ods'
),
'rb'
))
mapping
=
parser
.
getSpreadsheetsMapping
()
self
.
assertEquals
([
'Person'
],
mapping
.
keys
())
person_mapping
=
mapping
[
'Person'
]
self
.
assertTrue
(
isinstance
(
person_mapping
,
list
))
self
.
assertTrue
(
102
,
len
(
person_mapping
))
self
.
assertEquals
(
person_mapping
[
0
],
[
'Title'
,
'First Name'
,
'Last Name'
,
'Default Email Text'
])
self
.
assertEquals
(
person_mapping
[
1
],
[
'John Doe 0'
,
'John'
,
'Doe 0'
,
'john.doe0@foo.com'
])
def
test_openFromString
(
self
):
parser
=
OOoParser
()
parser
.
openFromString
(
open
(
makeFilePath
(
'import_data_list.ods'
),
'rb'
).
read
())
mapping
=
parser
.
getSpreadsheetsMapping
()
self
.
assertEquals
([
'Person'
],
mapping
.
keys
())
def
test_getSpreadSheetMappingStyle
(
self
):
parser
=
OOoParser
()
parser
.
openFile
(
open
(
makeFilePath
(
'import_data_list_with_style.ods'
),
'rb'
))
mapping
=
parser
.
getSpreadsheetsMapping
()
self
.
assertEquals
([
'Feuille1'
],
mapping
.
keys
())
self
.
assertEquals
(
mapping
[
'Feuille1'
][
1
],
[
'a line with style'
])
self
.
assertEquals
(
mapping
[
'Feuille1'
][
2
],
[
'a line with multiple styles'
])
self
.
assertEquals
(
mapping
[
'Feuille1'
][
3
],
[
'http://www.erp5.org'
])
self
.
assertEquals
(
mapping
[
'Feuille1'
][
4
],
[
'john.doe@example.com'
])
def
test_getSpreadSheetMappingDataTypes
(
self
):
parser
=
OOoParser
()
parser
.
openFile
(
open
(
makeFilePath
(
'import_data_list_data_type.ods'
),
'rb'
))
mapping
=
parser
.
getSpreadsheetsMapping
()
self
.
assertEquals
([
'Feuille1'
],
mapping
.
keys
())
self
.
assertEquals
(
mapping
[
'Feuille1'
][
0
],
[
'1234.5678'
])
self
.
assertEquals
(
mapping
[
'Feuille1'
][
1
],
[
'1234.5678'
])
self
.
assertEquals
(
mapping
[
'Feuille1'
][
2
],
[
'0.1'
])
self
.
assertEquals
(
mapping
[
'Feuille1'
][
3
],
[
'2008-11-14'
])
self
.
assertEquals
(
mapping
[
'Feuille1'
][
4
],
[
'2008-11-14T10:20:30'
])
# supported by DateTime
self
.
assertEquals
(
mapping
[
'Feuille1'
][
5
],
[
'PT12H34M56S'
])
# maybe not good, this is raw format
self
.
assertEquals
(
mapping
[
'Feuille1'
][
6
],
[
'With note'
])
def
test_BigSpreadSheet_can_be_parsed
(
self
,):
"""Test than OOoimport can parse a file with more than 40000 lines
"""
parser
=
OOoParser
()
parser
.
openFile
(
open
(
makeFilePath
(
'import_big_spreadsheet.ods'
),
'rb'
))
mapping
=
parser
.
getSpreadsheetsMapping
()
not_ok
=
1
for
spread
,
values
in
mapping
.
iteritems
():
self
.
assertEquals
(
len
(
values
),
41001
)
not_ok
=
0
if
not_ok
:
self
.
fail
(
'Spreadsheet not read!'
)
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
TestOOoParser
))
return
suite
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment