Commit 2f7d0ece authored by Aurel's avatar Aurel

fix unicode errors & do some cleanup

parent 8b7fde47
......@@ -32,7 +32,7 @@ import unittest
from zLOG import LOG
from Testing import ZopeTestCase
from AccessControl.SecurityManagement import newSecurityManager
import os
class TestOxatisSynchronization(ERP5TypeTestCase):
"""
......@@ -66,7 +66,7 @@ class TestOxatisSynchronization(ERP5TypeTestCase):
"""
self.portal = self.getPortal()
self.oxatis = self.portal.portal_integrations.oxatis
# Create a user for sync
acl_users = self.portal.acl_users
acl_users._doAddUser('TioSafeUser', 'TioSafeUserPassword', ['Manager'], [])
......@@ -85,7 +85,7 @@ class TestOxatisSynchronization(ERP5TypeTestCase):
self.oxatis.getResourceValue().validate()
self.default_resource_id = self.oxatis.getResourceValue().getId()
self.default_source_id = self.oxatis.getSourceAdministrationValue().getId()
for connector in self.oxatis.contentValues(portal_type="Web Service Connector"):
# use the test connector
connector.setTransport("oxatis_test")
......@@ -147,7 +147,7 @@ class TestOxatisSynchronization(ERP5TypeTestCase):
diff += "%s\n" %(line)
raise AssertionError, diff
def checkConflicts(self, module, nb_pub_conflicts=0, nb_sub_conflicts=0, in_conflict=True):
module = self.oxatis[module]
......@@ -190,7 +190,7 @@ class TestOxatisSynchronization(ERP5TypeTestCase):
if document.getTitle() not in excluded_title_list:
self.assertEqual(len([x for x in document.Base_getRelatedObjectList() if x.getPortalType() == "Sale Trade Condition"]), 1)
else:
self.assertEqual(len([x for x in document.Base_getRelatedObjectList() if x.getPortalType() == "Sale Trade Condition"]), 0)
self.assertEqual(len([x for x in document.Base_getRelatedObjectList() if x.getPortalType() == "Sale Trade Condition"]), 0)
def runPersonSync(self):
"""
......@@ -371,7 +371,7 @@ class TestOxatisSynchronization(ERP5TypeTestCase):
#
# Modify person on both side
# Modify person on both side
#
for person in self.portal.person_module.searchFolder(validation_state="validated"):
if person.getTitle() == "test-Aurélien Calonne":
......
......@@ -132,6 +132,8 @@ class SyncMLSignature(XMLObject):
if we want to know if an objects has changed or not
Returns 1 if MD5 are equals, else it returns 0
"""
if isinstance(xml_string, unicode):
xml_string = xml_string.encode('utf-8')
return ((md5.new(xml_string).hexdigest()) == self.getContentMd5())
security.declareProtected(Permissions.ModifyPortalContent, 'setPartialData')
......
......@@ -2165,18 +2165,20 @@ class SynchronizationTool(BaseTool):
if reset:
#After a reset we want copy the LAST XML view on Signature.
#this implementation is not sufficient, need to be improved.
if not isinstance(xml_object, str):
if not isinstance(xml_object, (str, unicode)):
xml_object = etree.tostring(xml_object, encoding='utf-8',
pretty_print=True)
else:
else:
xml_object = conduit.getXMLFromObjectWithId(object,
xml_mapping=\
domain.getXmlBindingGeneratorMethodId(),
context_document=subscriber.getPath())
#if signature.getValidationState() != 'synchronized':
if isinstance(xml_object, unicode):
xml_object = xml_object.encode('utf-8')
signature.synchronize()
signature.setReference(object.getPath())
signature.setData(xml_object)
signature.setData(str(xml_object))
xml_confirmation_list.append(self.SyncMLConfirmation(
cmd_id=cmd_id,
cmd='Add',
......
......@@ -26,7 +26,6 @@
##############################################################################
from Products.ERP5TioSafe.Conduit.TioSafeBaseConduit import TioSafeBaseConduit
from lxml import etree
class AccountERP5IntegrationConduit(TioSafeBaseConduit):
"""
......
......@@ -51,20 +51,24 @@ class TioSafeBaseConduit(ERP5Conduit):
XXX name of method is not good, because content is not necessarily XML
return a xml with id replaced by a new id
"""
if isinstance(xml, str):
xml = etree.XML(xml, parser=parser)
if isinstance(xml, str) or isinstance(xml, unicode):
xml = etree.XML(str(xml), parser=parser)
else:
# copy of xml object for modification
xml = deepcopy(xml)
object_element = xml.find('object')
if object_element:
if object_element and object_element != -1:
if attribute_name == 'id':
del object_element.attrib['gid']
else:
del object_element.attrib['id']
object_element.attrib[attribute_name] = new_id
if as_string:
return etree.tostring(xml, pretty_print=True, encoding="utf-8")
try:
return etree.tostring(xml, pretty_print=True, encoding="utf-8")
except:
import pdb
pdb.set_trace()
return xml
def _generateConflict(self, path, tag, xml, current_value, new_value, signature):
......
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2009 Nexedi SA and Contributors. All Rights Reserved.
# Hervé Poulain <herve@nexedi.com>
# Hervé Poulain <herve@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
......@@ -27,7 +28,7 @@
##############################################################################
from Products.ERP5TioSafe.Conduit.TioSafeBaseConduit import TioSafeBaseConduit
from lxml import etree
class TioSafeNodeConduit(TioSafeBaseConduit):
"""
......@@ -205,7 +206,7 @@ class TioSafeNodeConduit(TioSafeBaseConduit):
# value = DateTime(value).strftime(format)
keyword = {'person_id': document.getId(), tag: value, }
document.context.person_module.updatePerson(**keyword)
new_document = document.context.person_module[document.getId()]
document.updateProperties(new_document)
return conflict_list
......@@ -364,10 +365,8 @@ class TioSafeNodeConduit(TioSafeBaseConduit):
# value = DateTime(value).strftime(format)
keyword = {'person_id': document.getId(), tag:value, }
document.context.person_module.updatePerson(**keyword)
new_document = document.context.person_module[document.getId()]
document.updateProperties(new_document)
return conflict_list
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