'Test selection of fields in load() with fields and skip'

def testLoadFieldSelection(self):

    assertEqual = self.assertEqual
    assertTrue = self.assertTrue
    assertFalse = self.assertFalse
    s3db = current.s3db
    auth = current.auth
    auth.override = True
    xmlstr = '\n<s3xml>\n                <resource    name="org_office"    uuid="LOADTESTOFFICE">\n                                <data    field="name">LoadTestOffice</data>\n                                <reference    field="organisation_id"    resource="org_organisation">\n                                                <resource    name="org_organisation">\n                                                                <data    field="name">LoadTestOrganisation</data>\n                                                </resource>\n                                </reference>\n                </resource>\n</s3xml>'
    xmltree = etree.ElementTree(etree.fromstring(xmlstr))
    try:
        resource = s3db.resource('org_office')
        resource.import_xml(xmltree)
        resource = s3db.resource('org_office', uid='LOADTESTOFFICE')
        rows = resource.load(fields=['name'])
        assertEqual(len(rows), 1)
        row = rows[0]
        assertTrue(hasattr(row, 'id'))
        assertTrue(hasattr(row, 'name'))
        assertTrue(hasattr(row, 'created_on'))
        assertTrue(hasattr(row, 'pe_id'))
        assertFalse(hasattr(row, 'organisation_id'))
        rows = resource.load(skip=['name'])
        assertEqual(len(rows), 1)
        row = rows[0]
        assertTrue(hasattr(row, 'id'))
        assertFalse(hasattr(row, 'name'))
        assertTrue(hasattr(row, 'created_on'))
        assertTrue(hasattr(row, 'pe_id'))
        assertTrue(hasattr(row, 'organisation_id'))
        rows = resource.load(fields=['name', 'organisation_id'], skip=['organisation_id'])
        assertEqual(len(rows), 1)
        row = rows[0]
        assertTrue(hasattr(row, 'id'))
        assertTrue(hasattr(row, 'name'))
        assertTrue(hasattr(row, 'created_on'))
        assertTrue(hasattr(row, 'pe_id'))
        assertFalse(hasattr(row, 'organisation_id'))
        rows = resource.load(fields=['name', 'organisation_id'], skip=['created_on'])
        assertEqual(len(rows), 1)
        row = rows[0]
        assertTrue(hasattr(row, 'id'))
        assertTrue(hasattr(row, 'name'))
        assertTrue(hasattr(row, 'created_on'))
        assertTrue(hasattr(row, 'pe_id'))
        assertTrue(hasattr(row, 'organisation_id'))
        rows = resource.load(fields=['name', 'organisation_id'], skip=['id'])
        assertEqual(len(rows), 1)
        row = rows[0]
        assertTrue(hasattr(row, 'id'))
        assertTrue(hasattr(row, 'name'))
        assertTrue(hasattr(row, 'created_on'))
        assertTrue(hasattr(row, 'pe_id'))
        assertTrue(hasattr(row, 'organisation_id'))
        rows = resource.load(fields=['name', 'organisation_id'], skip=['pe_id'])
        assertEqual(len(rows), 1)
        row = rows[0]
        assertTrue(hasattr(row, 'id'))
        assertTrue(hasattr(row, 'name'))
        assertTrue(hasattr(row, 'created_on'))
        assertTrue(hasattr(row, 'pe_id'))
        assertTrue(hasattr(row, 'organisation_id'))
    finally:
        auth.override = False
        current.db.rollback()
