'Test wether the replaced_by UUID is exported with the deleted
record after merge'

def testExportOfReplacedBy(self):

    s3db = current.s3db
    resource = s3db.resource('org_office', uid=['TESTSYNCOFFICE1', 'TESTSYNCOFFICE2'])
    records = resource.select(['id', 'uuid'], limit=None)['rows']
    self.assertNotEqual(records, None)
    ids = dict([(record['org_office.uuid'], record['org_office.id']) for record in records])
    self.assertEqual(len(ids), 2)
    success = resource.merge(ids['TESTSYNCOFFICE1'], ids['TESTSYNCOFFICE2'])
    self.assertTrue(success)
    resource = s3db.resource('org_office', uid='TESTSYNCOFFICE2', include_deleted=True)
    xmlstr = resource.export_xml()
    xmltree = etree.ElementTree(etree.fromstring(xmlstr))
    office = xmltree.xpath("resource[@name='org_office'    and    @uuid='TESTSYNCOFFICE2']")
    self.assertEqual(len(office), 1)
    office = office[0]
    xml = current.xml
    self.assertEqual(office.get(xml.DELETED).lower(), 'true')
    self.assertEqual(office.get(xml.ATTRIBUTE['replaced_by']), 'TESTSYNCOFFICE1')
