'Test update detection for multiple name matches if no parent
item has been specified in source (ambiguous => should reject
the item)'

def testMultipleNameMatchesWithoutParentItemAmbiguous(self):

    db = current.db
    s3db = current.s3db
    assertEqual = self.assertEqual
    assertNotEqual = self.assertNotEqual
    assertTrue = self.assertTrue
    otable = s3db.org_organisation
    btable = s3db.org_organisation_branch
    query = ((otable.name == 'DeDupBranch2') & (otable.deleted != True))
    rows = db(query).select(otable.id, otable.comments)
    assertEqual(len(rows), 2)
    for row in rows:
        assertEqual(row.comments, None)
    xmlstr = '\n<s3xml>\n                <resource    name="org_organisation">\n                                <data    field="name">DeDupBranch2</data>\n                                <data    field="comments">updated</data>\n                </resource>\n</s3xml>'
    xmltree = etree.ElementTree(etree.fromstring(xmlstr))
    resource = s3db.resource('org_organisation')
    result = resource.import_xml(xmltree, ignore_errors=True)
    result = json.loads(result)
    msg = result['message']
    error_tree = resource.error_tree
    assertNotEqual(error_tree, None)
    elements = error_tree.xpath("resource[data[@field='name']/text()='DeDupBranch2']")
    assertEqual(len(elements), 1)
    attrib = elements[0].attrib
    assertTrue(('error' in attrib))
    assertTrue((attrib['error'] in msg))
    query = ((otable.name == 'DeDupBranch2') & (otable.deleted != True))
    rows = db(query).select(otable.id, otable.comments)
    assertEqual(len(rows), 2)
    for row in rows:
        assertEqual(row.comments, None)
