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

Extend OOoParser so that it's possible to feed the parser with content as

string, not only with a file object.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16678 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5c9f5d33
...@@ -236,6 +236,10 @@ class OOoParser: ...@@ -236,6 +236,10 @@ class OOoParser:
self.ns = {} self.ns = {}
self.filename = None self.filename = None
security.declareProtected(Permissions.ImportExportObjects, 'openFromString')
def openFromString(self, text_content):
return self.openFile(StringIO(text_content))
security.declareProtected(Permissions.ImportExportObjects, 'openFile') security.declareProtected(Permissions.ImportExportObjects, 'openFile')
def openFile(self, file_descriptor): def openFile(self, file_descriptor):
""" """
......
...@@ -36,6 +36,7 @@ from Testing import ZopeTestCase ...@@ -36,6 +36,7 @@ from Testing import ZopeTestCase
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.Sequence import SequenceList from Products.ERP5Type.tests.Sequence import SequenceList
from Products.ERP5OOo.OOoUtils import OOoParser
ooodoc_coordinates = ('127.0.0.1', 8008) ooodoc_coordinates = ('127.0.0.1', 8008)
...@@ -198,6 +199,28 @@ class TestOOoImport(ERP5TypeTestCase): ...@@ -198,6 +199,28 @@ class TestOOoImport(ERP5TypeTestCase):
self.assertEquals(1, france.getIntIndex()) self.assertEquals(1, france.getIntIndex())
# simple 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_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestOOoImport)) suite.addTest(unittest.makeSuite(TestOOoImport))
......
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