'Test S3Resource.select with fields in a filtered component'

@unittest.skipIf((not current.deployment_settings.has_module('org')), 'org    module    disabled')
def testSelectWithFilteredComponent(self):

    assertEqual = self.assertEqual
    assertTrue = self.assertTrue
    s3db = current.s3db
    auth = current.auth
    xmlstr = '\n<s3xml>\n                <resource    name="org_organisation"    uuid="FCTESTORG">\n                                <data    field="name">FilteredComponentsTestOrg</data>\n                                <resource    name="org_office"    uuid="FCTESTOFFICE">\n                                                <data    field="name">FilteredComponentsTestOffice</data>\n                                                <reference    field="office_type_id"    resource="org_office_type">\n                                                                <resource    name="org_office_type"    uuid="FCTESTTYPE">\n                                                                                <data    field="name">FilteredComponentsTestType</data>\n                                                                </resource>\n                                                </reference>\n                                </resource>\n                </resource>\n</s3xml>'
    xmltree = etree.ElementTree(etree.fromstring(xmlstr))
    auth.override = True
    resource = s3db.resource('org_organisation')
    resource.import_xml(xmltree)
    resource = s3db.resource('org_office_type', uid='FCTESTTYPE')
    row = resource.select(['id'], limit=1, as_rows=True)[0]
    type_id = row.id
    s3db.add_components('org_organisation', org_office={'name': 'test', 'joinby': 'organisation_id', 'filterby': {'office_type_id': type_id}})
    resource = current.s3db.resource('org_organisation', uid='FCTESTORG')
    fields = ['id', 'name', 'test.name', 'test.office_type_id$name']
    data = resource.select(fields, limit=None)
    result = data['rows']
    assertEqual(len(result), 1)
    result = result[0]
    assertTrue(('org_organisation.name' in result))
    assertEqual(result['org_organisation.name'], 'FilteredComponentsTestOrg')
    assertTrue(('org_test_office.name' in result))
    assertEqual(result['org_test_office.name'], 'FilteredComponentsTestOffice')
    assertTrue(('org_office_type.name' in result))
    assertEqual(result['org_office_type.name'], 'FilteredComponentsTestType')
    del current.model.components['org_organisation']['test']
    current.db.rollback()
    auth.override = False
