Commit 3e886e86 authored by Nicolas Delaby's avatar Nicolas Delaby

Improve test:

 * use _getConversionServerDict to setup preference
 * use lxml to parse xml documents
 * use OOoBuilder to extract content from ODF archive


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35265 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent adae6fde
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2007 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Bartek Gorny <bg@erp5.pl> # Bartek Gorny <bg@erp5.pl>
# Jean-Paul Smets <jp@nexedi.com> # Jean-Paul Smets <jp@nexedi.com>
# Ivan Tyagov <ivan@nexedi.com> # Ivan Tyagov <ivan@nexedi.com>
...@@ -31,22 +31,21 @@ ...@@ -31,22 +31,21 @@
import unittest import unittest
import os, cStringIO, zipfile import os, cStringIO, zipfile
from xml.dom.minidom import parseString from lxml import etree
import transaction import transaction
from Testing import ZopeTestCase from Testing import ZopeTestCase
from DateTime import DateTime from DateTime import DateTime
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Type.Utils import convertToUpperCase from Products.ERP5Type.Utils import convertToUpperCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase,\
_getConversionServerDict
from Products.ERP5Type.tests.Sequence import SequenceList from Products.ERP5Type.tests.Sequence import SequenceList
from Products.ERP5Type.tests.utils import FileUpload from Products.ERP5Type.tests.utils import FileUpload
from Products.ERP5OOo.Document.OOoDocument import ConversionError from Products.ERP5OOo.Document.OOoDocument import ConversionError
from Products.ERP5OOo.OOoUtils import OOoBuilder
from zLOG import LOG, INFO, ERROR from zLOG import LOG, INFO, ERROR
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
# Define the conversion server host
conversion_server_host = ('127.0.0.1', 8008)
# test files' home # test files' home
TEST_FILES_HOME = os.path.join(os.path.dirname(__file__), 'test_document') TEST_FILES_HOME = os.path.join(os.path.dirname(__file__), 'test_document')
FILE_NAME_REGULAR_EXPRESSION = "(?P<reference>[A-Z&é@{]{3,7})-(?P<language>[a-z]{2})-(?P<version>[0-9]{3})" FILE_NAME_REGULAR_EXPRESSION = "(?P<reference>[A-Z&é@{]{3,7})-(?P<language>[a-z]{2})-(?P<version>[0-9]{3})"
...@@ -125,8 +124,9 @@ class TestIngestion(ERP5TypeTestCase): ...@@ -125,8 +124,9 @@ class TestIngestion(ERP5TypeTestCase):
def setSystemPreference(self): def setSystemPreference(self):
default_pref = self.portal.portal_preferences.default_site_preference default_pref = self.portal.portal_preferences.default_site_preference
default_pref.setPreferredOoodocServerAddress(conversion_server_host[0]) conversion_dict = _getConversionServerDict()
default_pref.setPreferredOoodocServerPortNumber(conversion_server_host[1]) default_pref.setPreferredOoodocServerAddress(conversion_dict['hostname'])
default_pref.setPreferredOoodocServerPortNumber(conversion_dict['port'])
default_pref.setPreferredDocumentFileNameRegularExpression(FILE_NAME_REGULAR_EXPRESSION) default_pref.setPreferredDocumentFileNameRegularExpression(FILE_NAME_REGULAR_EXPRESSION)
default_pref.setPreferredDocumentReferenceRegularExpression(REFERENCE_REGULAR_EXPRESSION) default_pref.setPreferredDocumentReferenceRegularExpression(REFERENCE_REGULAR_EXPRESSION)
if default_pref.getPreferenceState() != 'global': if default_pref.getPreferenceState() != 'global':
...@@ -684,18 +684,15 @@ class TestIngestion(ERP5TypeTestCase): ...@@ -684,18 +684,15 @@ class TestIngestion(ERP5TypeTestCase):
# need oood for getting/setting metadata... # need oood for getting/setting metadata...
document = self.getDocument('one') document = self.getDocument('one')
newcontent = document.getBaseData() newcontent = document.getBaseData()
cs = cStringIO.StringIO() builder = OOoBuilder(newcontent)
cs.write(str(newcontent)) xml_tree = etree.fromstring(builder.extract('meta.xml'))
z = zipfile.ZipFile(cs) title = xml_tree.find('*/{%s}title' % xml_tree.nsmap['dc']).text
s = z.read('meta.xml') self.assertEquals(title, 'another title')
xmlob = parseString(s) subject = xml_tree.find('*/{%s}keyword' % xml_tree.nsmap['meta']).text
title = xmlob.getElementsByTagName('dc:title')[0].childNodes[0].data
self.assertEquals(title, u'another title')
subject = xmlob.getElementsByTagName('meta:keyword')[0].childNodes[0].data
self.assertEquals(subject, u'another subject') self.assertEquals(subject, u'another subject')
description = xmlob.getElementsByTagName('dc:description')[0].childNodes[0].data description = xml_tree.find('*/{%s}description' % xml_tree.nsmap['dc']).text
self.assertEquals(description, u'another description') self.assertEquals(description, u'another description')
def stepIngestTextFormats(self, sequence=None, sequence_list=None, **kw): def stepIngestTextFormats(self, sequence=None, sequence_list=None, **kw):
""" """
ingest all supported text formats ingest all supported text formats
...@@ -1010,8 +1007,9 @@ class TestIngestion(ERP5TypeTestCase): ...@@ -1010,8 +1007,9 @@ class TestIngestion(ERP5TypeTestCase):
if not run: return if not run: return
if not quiet: printAndLog('test_01_PreferenceSetup') if not quiet: printAndLog('test_01_PreferenceSetup')
preference_tool = self.portal.portal_preferences preference_tool = self.portal.portal_preferences
self.assertEquals(preference_tool.getPreferredOoodocServerAddress(), conversion_server_host[0]) conversion_dict = _getConversionServerDict()
self.assertEquals(preference_tool.getPreferredOoodocServerPortNumber(), conversion_server_host[1]) self.assertEquals(preference_tool.getPreferredOoodocServerAddress(), conversion_dict['hostname'])
self.assertEquals(preference_tool.getPreferredOoodocServerPortNumber(), conversion_dict['port'])
self.assertEquals(preference_tool.getPreferredDocumentFileNameRegularExpression(), FILE_NAME_REGULAR_EXPRESSION) self.assertEquals(preference_tool.getPreferredDocumentFileNameRegularExpression(), FILE_NAME_REGULAR_EXPRESSION)
self.assertEquals(preference_tool.getPreferredDocumentReferenceRegularExpression(), REFERENCE_REGULAR_EXPRESSION) self.assertEquals(preference_tool.getPreferredDocumentReferenceRegularExpression(), REFERENCE_REGULAR_EXPRESSION)
......
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