'Test update detection for single name match with parent
specified in source (matching parent => should update branch)'

def testSingleNameMatchWithParentItemMatch(self):

    db = current.db
    s3db = current.s3db
    assertEqual = self.assertEqual
    otable = s3db.org_organisation
    btable = s3db.org_organisation_branch
    query = (otable.name == 'DeDupBranch4')
    rows = db(query).select(otable.id, otable.comments)
    assertEqual(len(rows), 1)
    assertEqual(rows.first().comments, None)
    branch_id = rows.first().id
    query = (((btable.branch_id == branch_id) & (btable.deleted != True)) & (otable.id == btable.organisation_id))
    rows = db(query).select(otable.id, otable.uuid)
    assertEqual(len(rows), 1)
    assertEqual(rows.first().uuid, 'DEDUPORGC')
    xmlstr = '\n<s3xml>\n                <resource    name="org_organisation"    tuid="PARENT">\n                                <data    field="name">DeDupOrgC</data>\n                </resource>\n                <resource    name="org_organisation">\n                                <data    field="name">DeDupBranch4</data>\n                                <data    field="comments">updated</data>\n                                <resource    name="org_organisation_branch"    alias="parent">\n                                                <reference    field="organisation_id"    resource="org_organisation"    tuid="PARENT"/>\n                                </resource>\n                </resource>\n</s3xml>'
    xmltree = etree.ElementTree(etree.fromstring(xmlstr))
    resource = s3db.resource('org_organisation')
    resource.import_xml(xmltree, ignore_errors=True)
    query = (otable.name == 'DeDupBranch4')
    rows = db(query).select(otable.id, otable.comments)
    assertEqual(len(rows), 1)
    assertEqual(rows.first().comments, 'updated')
    branch_id = rows.first().id
    query = (((btable.branch_id == branch_id) & (btable.deleted != True)) & (otable.id == btable.organisation_id))
    rows = db(query).select(otable.id, otable.uuid)
    assertEqual(len(rows), 1)
    assertEqual(rows.first().uuid, 'DEDUPORGC')
