'Test export of a resource as element tree'

def testExportTree(self):

    assertEqual = self.assertEqual
    assertTrue = self.assertTrue
    xml = current.xml
    auth = current.auth
    auth.override = True
    xmlstr = '\n<s3xml>\n                <resource    name="org_organisation">\n                                <data    field="name">TestExportTreeOrganisation1</data>\n                                <resource    name="org_office"    uuid="ETO1">\n                                                <data    field="name">TestExportTreeOffice1</data>\n                                </resource>\n                </resource>\n</s3xml>'
    try:
        xmltree = etree.ElementTree(etree.fromstring(xmlstr))
        resource = current.s3db.resource('org_organisation')
        resource.import_xml(xmltree)
        resource = current.s3db.resource('org_office', uid='ETO1')
        tree = resource.export_tree(start=0, limit=1, dereference=False)
        root = tree.getroot()
        assertEqual(root.tag, xml.TAG.root)
        attrib = root.attrib
        assertEqual(len(attrib), 5)
        assertEqual(attrib['success'], 'true')
        assertEqual(attrib['start'], '0')
        assertEqual(attrib['limit'], '1')
        assertEqual(attrib['results'], '1')
        assertTrue(('url' in attrib))
        assertEqual(len(root), 1)
        for child in root:
            assertEqual(child.tag, xml.TAG.resource)
            attrib = child.attrib
            assertEqual(attrib['name'], 'org_office')
            assertTrue(('uuid' in attrib))
    finally:
        current.db.rollback()
        auth.override = False
