Commit 2f7d0ece authored by Aurel's avatar Aurel

fix unicode errors & do some cleanup

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