'Verify import items without name match create new records'

def testNoNameMatch(self):

    db = current.db
    s3db = current.s3db
    assertEqual = self.assertEqual
    otable = s3db.org_organisation
    btable = s3db.org_organisation_branch
    query = (((otable.name == 'DeDupOrgD') | (otable.name == 'DeDupBranch5')) & (otable.deleted != True))
    rows = db(query).select(otable.id)
    assertEqual(len(rows), 0)
    xmlstr = '\n<s3xml>\n                <resource    name="org_organisation"    tuid="DEDUPORGD">\n                                <data    field="name">DeDupOrgD</data>\n                </resource>\n                <resource    name="org_organisation"    tuid="DEDUPBRANCHD5">\n                                <data    field="name">DeDupBranch5</data>\n                                <resource    name="org_organisation_branch"    alias="parent">\n                                                <reference    field="organisation_id"    resource="org_organisation"    tuid="DEDUPORGD"/>\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 == 'DeDupOrgD') & (otable.deleted != True))
    rows = db(query).select(otable.id)
    assertEqual(len(rows), 1)
    organisation_id = rows.first().id
    query = ((btable.branch_id == organisation_id) & (btable.deleted != True))
    rows = db(query).select(btable.id)
    assertEqual(len(rows), 0)
    query = ((otable.name == 'DeDupBranch5') & (otable.deleted != True))
    rows = db(query).select(otable.id)
    assertEqual(len(rows), 1)
    branch_id = rows.first().id
    query = (((btable.organisation_id == organisation_id) & (btable.branch_id == branch_id)) & (btable.deleted != True))
    rows = db(query).select(btable.id)
    assertEqual(len(rows), 1)
