'Test application of extra filters'

def testApplyExtraFilter(self):

    assertTrue = self.assertTrue
    assertEqual = self.assertEqual
    assertNotEqual = self.assertNotEqual
    test_expression = 'test    filter    expression'
    seen = []
    def test_filter(resource, ids, expression):
        '    Test    filter    method    '
        assertNotEqual(resource, None)
        assertEqual(resource.tablename, 'select_master')
        efilters = resource.rfilter.efilters
        assertEqual(efilters, [])
        assertTrue((type(ids) is list))
        assertNotEqual(len(ids), 0)
        seen.extend(ids)
        assertEqual(expression, test_expression)
        result = [item for item in ids if ((item > 3) and ((item % 2) == 0))]
        if result:
            result.insert(0, result[(-1)])
        result.reverse()
        return result
    resource = current.s3db.resource('select_master')
    resource.add_extra_filter(test_filter, test_expression)
    apply_extra_filters = resource.rfilter.apply_extra_filters
    test_set = [1, 2, 3, 4, 5, 6, 7, 8]
    seen = []
    subset = apply_extra_filters(test_set)
    assertEqual(subset, [4, 6, 8])
    assertEqual(seen, test_set)
    seen = []
    subset = apply_extra_filters(test_set, limit=2)
    assertEqual(subset, [4, 6])
    assertEqual(seen, [1, 2, 3, 4, 5, 6])
    seen = []
    subset = apply_extra_filters(test_set, limit=10)
    assertEqual(subset, [4, 6, 8])
    assertEqual(seen, test_set)
