testERP5SyncMLVCard.py 9.48 KB
Newer Older
1
# -*- coding: utf-8 -*-
2 3
##############################################################################
# vim: set fileencoding=utf-8
Aurel's avatar
Aurel committed
4
#
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
# Copyright (c) 2007 Nexedi SARL and Contributors. All Rights Reserved.
#          Fabien Morin <fabien.morin@gmail.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################

from testERP5SyncML import TestERP5SyncMLMixin

33
class TestERP5SyncMLVCard(TestERP5SyncMLMixin):
34 35 36 37 38 39

  def getBusinessTemplateList(self):
    """
      Return the list of business templates.

      the business template sync_crm give 3 folders:
Aurel's avatar
Aurel committed
40
      /person_server
41 42 43
      /person_client1 : empty
      /person_client2 : empty
    """
44
    return ('erp5_base', 'erp5_syncml',)
Aurel's avatar
Aurel committed
45

46 47 48 49
  def afterSetUp(self):
    self.portal.z_drop_syncml()
    self.portal.z_create_syncml()

Nicolas Delaby's avatar
Nicolas Delaby committed
50 51
  def getTitle(self):
    return 'testERP5SyncMLVCard'
52

53
  def addVCardPublication(self):
54
    portal_sync = self.getSynchronizationTool()
55 56 57 58 59 60 61 62 63 64 65 66 67 68
    if getattr(portal_sync, self.pub_id, None) is None:
      pub = portal_sync.newContent(portal_type='SyncML Publication',
                             id=self.pub_id,
                             url_string=self.publication_url,
                             source='person_server',
                             source_reference='Person',
                             list_method_id='objectValues',
                             xml_binding_generator_method_id='Person_exportAsVCard',
                             conduit_module_id='SharedVCardConduit',
                             synchronisation_id_generator_method_id='generateNewId')
      pub.validate()
      self.tic()

  def addVCardSubscription1(self):
69
    portal_sync = self.getSynchronizationTool()
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    if getattr(portal_sync, self.sub_id1, None) is None:
      sub = portal_sync.newContent(portal_type='SyncML Subscription',
                             id=self.sub_id1,
                             url_string=self.publication_url,
                             subscription_url_string=self.subscription_url1,
                             source='person_client1',
                             source_reference='Person',
                             destination_reference='Person',
                             list_method_id='objectValues',
                             xml_binding_generator_method_id='Person_exportAsVCard',
                             conduit_module_id='SharedVCardConduit',
                             synchronisation_id_generator_method_id='generateNewId',
                             user_id='fab',
                             password='myPassword')
      sub.validate()
      self.tic()

  def addVCardSubscription2(self):
88
    portal_sync = self.getSynchronizationTool()
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    if getattr(portal_sync, self.sub_id2, None) is None:
      sub = portal_sync.newContent(portal_type='SyncML Subscription',
                             id=self.sub_id2,
                             url_string=self.publication_url,
                             subscription_url_string=self.subscription_url2,
                             source='person_client2',
                             source_reference='Person',
                             destination_reference='Person',
                             list_method_id='objectValues',
                             xml_binding_generator_method_id='Person_exportAsVCard',
                             conduit_module_id='SharedVCardConduit',
                             synchronisation_id_generator_method_id='generateNewId',
                             user_id='fab',
                             password='myPassword')
      sub.validate()
      self.tic()

  def test_04_FirstVCardSynchronization(self):
107 108 109
    # We will try to populate the folder person_client1
    # with the data form person_server
    self.login()
110 111 112 113 114 115 116 117 118 119 120
    self.deletePublicationAndSubscriptionList()
    if 'person_server' in self.portal.objectIds():
      self.portal._delObject('person_server')
    if 'person_client1' in self.portal.objectIds():
      self.portal._delObject('person_client1')
    if 'person_client2' in self.portal.objectIds():
      self.portal._delObject('person_client2')
    self.addVCardPublication()
    self.addVCardSubscription1()
    self.addVCardSubscription2()
    nb_person = self.populatePersonServer()
121
    portal_sync = self.getSynchronizationTool()
122
    for sub in portal_sync.searchFolder(portal_type='SyncML Subscription'):
123
      self.assertEqual(sub.getSyncmlAlertCode(), 'two_way')
124 125
    # Synchronize the first client
    nb_message1 = self.synchronize(self.sub_id1)
126
    for sub in portal_sync.searchFolder(portal_type='SyncML Subscription'):
127 128
      self.assertEqual(sub.getSyncmlAlertCode(), 'two_way')
    self.assertEqual(nb_message1, self.nb_message_first_synchronization)
129 130
    # Synchronize the second client
    nb_message2 = self.synchronize(self.sub_id2)
131
    for sub in portal_sync.searchFolder(portal_type='SyncML Subscription'):
132 133
      self.assertEqual(sub.getSyncmlAlertCode(), 'two_way')
    self.assertEqual(nb_message2, self.nb_message_first_synchronization)
134 135
    self.checkFirstSynchronization(id='1', nb_person=nb_person)

136
  def test_05_basicVCardSynchronization(self):
137 138 139 140
    """
    synchronize two ERP5Sites using VCards
    """

141
    self.test_04_FirstVCardSynchronization()
142 143 144
    person_server = self.getPersonServer()
    person1_s = person_server._getOb(self.id1)
    person_client1 = self.getPersonClient1()
Aurel's avatar
Aurel committed
145
    person1_c = person_client1._getOb('1') #The new person is added with a
146 147
                                           #generate id (the first is 1)

Aurel's avatar
Aurel committed
148
    # try to synchronize
149 150 151 152 153 154 155
    kw = {'first_name':self.first_name3,'last_name':self.last_name3}
    person1_c.edit(**kw)
    #before synchornization, First and Last name souldn't be the same
    self.verifyFirstNameAndLastNameAreNotSynchronized(self.first_name3,
      self.last_name3, person1_s, person1_c)
    self.synchronize(self.sub_id1)
    #after synchronization, a new person is create on the server
156
    person1_s = person_server._getOb('1')
157 158 159

    #after the synchro, the client and server should be synchronized
    self.checkSynchronizationStateIsSynchronized()
160 161 162 163
    self.assertEqual(person1_s.getFirstName(), self.first_name3)
    self.assertEqual(person1_s.getLastName(), self.last_name3)
    self.assertEqual(person1_c.getFirstName(), self.first_name3)
    self.assertEqual(person1_c.getLastName(), self.last_name3)
164

165
  def test_05_verifyNoDuplicateDataWhenAdding(self):
166
    """
Aurel's avatar
Aurel committed
167
    this test permit to verify that if the server already have the person,
168 169
    he don't add it a second time
    """
170
    self.test_04_FirstVCardSynchronization()
171
    portal_sync = self.getSynchronizationTool()
172
    pub = portal_sync[self.pub_id]
173 174 175
    person_server = self.getPersonServer()
    person1_s = person_server._getOb(self.id1)
    person_client1 = self.getPersonClient1()
Aurel's avatar
Aurel committed
176
    person1_c = person_client1._getOb('1') #The new person is added with a
177 178
                                           #generate id (the first is 1)

Aurel's avatar
Aurel committed
179
    # try to synchronize
180 181 182 183
    kw = {'first_name':self.first_name3,'last_name':self.last_name3}
    person1_c.edit(**kw)
    person1_s.edit(**kw) #the same person is added on client AND server
    #before synchornization, First and Last name souldn't be the same
184 185 186 187
    self.assertEqual(person1_s.getFirstName(), self.first_name3)
    self.assertEqual(person1_s.getLastName(), self.last_name3)
    self.assertEqual(person1_c.getFirstName(), self.first_name3)
    self.assertEqual(person1_c.getLastName(), self.last_name3)
Aurel's avatar
Aurel committed
188
    nb_person_serv_before_sync = len(pub.getDocumentList())
189
    self.synchronize(self.sub_id1)
Aurel's avatar
Aurel committed
190
    #after synchronization, no new person is created on server because it
191
    #already have this person
Aurel's avatar
Aurel committed
192
    #person1_s = person_server._getOb('1') #The new person is added on the
193 194 195 196
                                      #serverwith a generate id (the first is 1)

    #after the synchro, the client and server should be synchronized
    self.checkSynchronizationStateIsSynchronized()
197 198 199 200
    self.assertEqual(person1_s.getFirstName(), self.first_name3)
    self.assertEqual(person1_s.getLastName(), self.last_name3)
    self.assertEqual(person1_c.getFirstName(), self.first_name3)
    self.assertEqual(person1_c.getLastName(), self.last_name3)
201

Aurel's avatar
Aurel committed
202
    nb_person_serv_after_sync = len(pub.getDocumentList())
203 204
    #the number of person on server before and after the synchronization should
    #be the same
Aurel's avatar
Aurel committed
205
    nb_person_serv_after_sync = len(pub.getDocumentList())
206
    self.assertEqual(nb_person_serv_after_sync, nb_person_serv_before_sync)
207

208

209 210 211 212 213
import unittest
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestERP5SyncMLVCard))
  return suite