'Test selection of subset (pagination) with virtual filter'

def testSelectSubsetVirtualFilter(self):

    s3db = current.s3db
    assertTrue = self.assertTrue
    assertEqual = self.assertEqual
    subset = [item for item in self.test_data if (item[1] == 'A')]
    numitems = len(subset)
    names = [item[0] for item in subset]
    query = (FS('code') == 'A')
    resource = s3db.resource('select_master', filter=query)
    start = 2
    limit = 2
    subset_names = names[start:(start + limit)]
    data = resource.select(['name', 'status'], start=start, limit=limit, orderby='select_master.name')
    rows = data.rows
    assertEqual(len(rows), min((numitems - start), limit))
    assertTrue(all(((row['select_master.name'] in subset_names) for row in rows)))
    start = 1
    limit = 3
    subset_names = names[start:(start + limit)]
    data = resource.select(['name', 'status'], start=start, limit=limit, count=True, orderby='select_master.name')
    rows = data.rows
    assertEqual(len(rows), min((numitems - start), limit))
    assertTrue(all(((row['select_master.name'] in subset_names) for row in rows)))
    assertEqual(data.numrows, numitems)
    data = resource.select(['id', 'name', 'status'], start=start, limit=limit, getids=True, orderby='select_master.name')
    assertEqual(len(data.rows), min((numitems - start), limit))
    assertTrue(all(((row['select_master.name'] in subset_names) for row in rows)))
    assertEqual(len(data.ids), numitems)
