diff --git a/product/ERP5SyncML/Conduit/ERP5Conduit.py b/product/ERP5SyncML/Conduit/ERP5Conduit.py index 7650e60e21a0bf1849137ed56d0291cf6bc6926e..fbcbd952969782ec546052ad6f750f74750de2c3 100755 --- a/product/ERP5SyncML/Conduit/ERP5Conduit.py +++ b/product/ERP5SyncML/Conduit/ERP5Conduit.py @@ -674,7 +674,7 @@ class ERP5Conduit(XMLSyncUtilsMixin): """ if type(xml) in (type('a'),type(u'a')): LOG('Conduit.convertToXml xml',0,repr(xml)) - if xml is type(u'a'): + if type(xml) is type(u'a'): xml = xml.encode('utf-8') xml = parseString(xml) LOG('Conduit.convertToXml not failed',0,'ok') diff --git a/product/ERP5SyncML/Subscription.py b/product/ERP5SyncML/Subscription.py index 403bafbe1b88412bd3f4c5ae381f28f71231a199..21219fb5099fa5bbfb69416209cae0514d518b5a 100755 --- a/product/ERP5SyncML/Subscription.py +++ b/product/ERP5SyncML/Subscription.py @@ -252,10 +252,14 @@ class Signature(SyncCode): # and we just get the confirmation self.setXML(self.getTempXML()) self.setTempXML(None) + self.setPartialXML(None) self.setSubscriberXupdate(None) self.setPublisherXupdate(None) if len(self.getConflictList())>0: self.resetConflictList() + if status == self.NOT_SYNCHRONIZED: + self.setTempXML(None) + self.setPartialXML(None) elif status in (self.PUB_CONFLICT_MERGE,self.SENT): # We have a solution for the conflict, don't need to keep the list self.resetConflictList() @@ -393,9 +397,11 @@ class Signature(SyncCode): Set the partial string we will have to deliver in the future """ - #LOG('Subscriber.setPartialXML before',0,'partial_xml: %s' % str(self.partial_xml)) + LOG('Subscriber.setPartialXML before',0,'partial_xml: %s' % str(self.partial_xml)) + if type(xml) is type(u'a'): + xml = xml.encode('utf-8') self.partial_xml = xml - #LOG('Subscriber.setPartialXML after',0,'partial_xml: %s' % str(self.partial_xml)) + LOG('Subscriber.setPartialXML after',0,'partial_xml: %s' % str(self.partial_xml)) def getPartialXML(self): """ diff --git a/product/ERP5SyncML/XMLSyncUtils.py b/product/ERP5SyncML/XMLSyncUtils.py index 42cbbdb0b072e0553c3244ab1dd6adb1ac236595..e3fec60375437b1177872b79ba8fb39a8ae386b6 100755 --- a/product/ERP5SyncML/XMLSyncUtils.py +++ b/product/ERP5SyncML/XMLSyncUtils.py @@ -446,7 +446,10 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject): #if subnode3.data.find('<!--')>=0: # data = subnode3.data # data = data[data.find('<!--')+4:data.rfind('-->')] - return subnode3.data + xml = subnode3.data + if type(xml) is type(u'a'): + xml = xml.encode('utf-8') + return xml return None @@ -713,7 +716,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject): LOG('SyncModif',0,'data_subnode: %s' % data_subnode) #data_subnode = FromXml(data_subnode) data_subnode = parseString(data_subnode) - data_subnode = data_subnode.childNodes[1] # Because we just created a new xml + data_subnode = data_subnode.childNodes[0] # Because we just created a new xml # document, with childNodes[0] a DocumentType and childNodes[1] the Element Node else: data_subnode = self.getDataSubNode(next_action) @@ -787,8 +790,8 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject): signature.setStatus(self.PARTIAL) #LOG('SyncModif',0,'setPartialXML: %s' % str(previous_partial)) previous_partial = signature.getPartialXML() or '' - if previous_partial.find(partial_data)<0: - previous_partial += partial_data + #if previous_partial.find(partial_data)<0: # XXX bad thing + previous_partial += partial_data signature.setPartialXML(previous_partial) #LOG('SyncModif',0,'previous_partial: %s' % str(previous_partial)) LOG('SyncModif',0,'waiting more data for :%s' % signature.getId()) diff --git a/product/ERP5SyncML/tests/testERP5SyncML.py b/product/ERP5SyncML/tests/testERP5SyncML.py index 6059630543181c9b8adfe4e7c01fa2ec83ff3357..c7bf1f7dda98f25dbdd47b40ecad584a9a8c00b0 100755 --- a/product/ERP5SyncML/tests/testERP5SyncML.py +++ b/product/ERP5SyncML/tests/testERP5SyncML.py @@ -46,6 +46,7 @@ from Testing import ZopeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from AccessControl.SecurityManagement import newSecurityManager, noSecurityManager from Products.ERP5SyncML.Conduit.ERP5Conduit import ERP5Conduit +from Products.ERP5SyncML.SyncCode import SyncCode from zLOG import LOG import time @@ -408,10 +409,11 @@ class TestERP5SyncML(ERP5TypeTestCase): for sub in portal_sync.getSubscriptionList(): for m in sub.getSignatureList(): self.assertEquals(m.getTempXML(),None) + self.assertEquals(m.getPartialXML(),None) for pub in portal_sync.getPublicationList(): for sub in pub.getSubscriberList(): for m in sub.getSignatureList(): - self.assertEquals(m.getTempXML(),None) + self.assertEquals(m.getPartialXML(),None) def checkSynchronizationStateIsConflict(self, quiet=0, run=run_all_test): portal_sync = self.getSynchronizationTool() @@ -1000,6 +1002,41 @@ class TestERP5SyncML(ERP5TypeTestCase): self.assertEqual(role_1_s,role_1_c) self.assertEqual(role_2_s,role_2_c) + def testPartialData(self, quiet=0, run=run_all_test): + """ + We will do a first synchronization, then we will do a change, then + we will modify the SyncCode max_line value so it + it will generate many messages + """ + if not run: return + self.testFirstSynchronization(quiet=1,run=1) + if not quiet: + ZopeTestCase._print('\nTest Partial Data ') + LOG('Testing... ',0,'testPartialData') + previous_max_lines = SyncCode.MAX_LINES + SyncCode.MAX_LINES = 10 + self.populatePersonServerWithSubObject(quiet=1,run=1) + self.synchronize(self.sub_id1) + self.synchronize(self.sub_id2) + self.checkSynchronizationStateIsSynchronized() + person_client1 = self.getPersonClient1() + person1_c = person_client1._getOb(self.id1) + sub_person1_c = person1_c._getOb(self.id1) + sub_sub_person1 = sub_person1_c._getOb(self.id1) + sub_sub_person2 = sub_person1_c._getOb(self.id2) + # remove ('','portal...','person_server') + len_path = len(sub_sub_person1.getPhysicalPath()) - 3 + self.failUnless(len_path==3) + len_path = len(sub_sub_person2.getPhysicalPath()) - 3 + self.failUnless(len_path==3) + self.failUnless(sub_sub_person1.getDescription()==self.description1) + self.failUnless(sub_sub_person1.getFirstName()==self.first_name1) + self.failUnless(sub_sub_person1.getLastName()==self.last_name1) + self.failUnless(sub_sub_person2.getDescription()==self.description2) + self.failUnless(sub_sub_person2.getFirstName()==self.first_name2) + self.failUnless(sub_sub_person2.getLastName()==self.last_name2) + SyncCode.MAX_LINES = previous_max_lines + # We may add a test in order to check if the slow_sync mode works fine, ie # if we do have both object on the client and server side, we must make sure # that the server first sends is own data