'Test Representation of reference, single value,
without linkto'

def testRepresentReferenceSingleNoLinkto(self):

    s3db = current.s3db
    resource = s3db.resource(self.tablename, id=[fac.id for fac in self.facs])
    table = resource.table
    org_id_renderer = S3Represent(lookup='org_organisation')
    table.organisation_id.represent = org_id_renderer
    fac_type_renderer = S3Represent(lookup='org_facility_type', multiple=True)
    table.facility_type_id.represent = fac_type_renderer
    loc_id_renderer = S3Represent(lookup='gis_location', linkto=URL(c='gis', f='location', args=['[id]']))
    table.location_id.represent = loc_id_renderer
    current.xml.show_ids = True
    tree = resource.export_tree(dereference=False)
    root = tree.getroot()
    locations = self.locations
    fac_types = self.fac_types
    org = self.org
    for fac in self.facs:
        elem = root.findall(("resource[@id='%s']" % fac.id))
        elem = (elem[0] if len(elem) else None)
        self.assertNotEqual(elem, None)
        find = (lambda name: elem.findall(("reference[@field='%s']" % name)))
        organisation_id = find('organisation_id')
        organisation_id = (organisation_id[0] if len(organisation_id) else None)
        self.assertNotEqual(organisation_id, None)
        self.assertEqual(organisation_id.text, org.name)
        location_id = find('location_id')
        location_id = (location_id[0] if len(location_id) else None)
        self.assertNotEqual(location_id, None)
        location = locations[fac.location_id]
        self.assertEqual(location_id.text, location.name)
        facility_type_id = find('facility_type_id')
        facility_type_id = (facility_type_id[0] if len(facility_type_id) else None)
        self.assertNotEqual(facility_type_id, None)
        ftypes = ',    '.join([fac_types[i].name for i in fac.facility_type_id])
        self.assertEqual(facility_type_id.text, ftypes)
    self.assertEqual(org_id_renderer.queries, 1)
    self.assertEqual(fac_type_renderer.queries, 1)
    self.assertEqual(loc_id_renderer.queries, 1)
