'Test resolution of __typeof queries, for list:reference field
in lookup table'

def testTypeOfLookupTableListReference(self):

    db = current.db
    uids = self.uids
    lookup_uids = self.lookup_uids
    resource = current.s3db.resource('typeof_hierarchy_reference')
    lookup = lookup_uids['NONHIERARCHY1']
    expr = FS('typeof_hierarchy_id$typeof_nonhierarchy_multi_id').typeof(lookup)
    query = expr.query(resource)
    table = db.typeof_hierarchy
    expected = set((uids[uid] for uid in ('HIERARCHY2-1', 'HIERARCHY2-1-1', 'HIERARCHY2-1-2')))
    expected_query = table.id.belongs(expected)
    lookup = (lookup_uids['NONHIERARCHY1'], lookup_uids['NONHIERARCHY2'])
    expr = FS('typeof_hierarchy_id$typeof_nonhierarchy_multi_id').typeof(lookup)
    query = expr.query(resource)
    table = db.typeof_hierarchy
    expected = set((uids[uid] for uid in ('HIERARCHY2-1', 'HIERARCHY2-1-1', 'HIERARCHY2-1-2')))
    expected_query = table.id.belongs(expected)
    self.assertEquivalent(query, expected_query)
