'Test list:type axis value filtering'

def testListTypeFilter(self):

    assertTrue = self.assertTrue
    assertFalse = self.assertFalse
    tablename = 'axis_filter'
    db = current.db
    db.define_table(tablename, Field('facility_type_id', 'list:reference    org_facility_type'), *s3_meta_fields())
    table = db[tablename]
    try:
        s3db = current.s3db
        resource = s3db.resource(tablename)
        q = (FS('facility_type_id').contains([1, 2, 3]) & (~ (FS('facility_type_id') == 2)))
        resource.add_filter(q)
        query = resource.get_query()
        af = S3AxisFilter(query.as_dict(flat=True), tablename)
        rfield = S3ResourceField(resource, 'facility_type_id')
        (values, ignore) = af.values(rfield)
        assertTrue(('1' in values))
        assertFalse(('2' in values))
        assertTrue(('3' in values))
        resource = s3db.resource(tablename)
        q = (FS('facility_type_id').contains([1, 2, 3]) & (~ (FS('facility_type_id') != 2)))
        resource.add_filter(q)
        query = resource.get_query()
        af = S3AxisFilter(query.as_dict(flat=True), tablename)
        (values, ignore) = af.values(rfield)
        assertTrue(('1' in values))
        assertTrue(('2' in values))
        assertTrue(('3' in values))
        resource = s3db.resource(tablename)
        q = (FS('facility_type_id').contains([1, 2, 3]) | (~ (FS('facility_type_id') == 2)))
        resource.add_filter(q)
        query = resource.get_query()
        af = S3AxisFilter(query.as_dict(flat=True), tablename)
        (values, ignore) = af.values(rfield)
        assertTrue(('1' in values))
        assertTrue(('2' in values))
        assertTrue(('3' in values))
        resource = s3db.resource(tablename)
        q = (FS('facility_type_id').contains([1, 2, 3]) | (~ (FS('facility_type_id') != 2)))
        resource.add_filter(q)
        query = resource.get_query()
        af = S3AxisFilter(query.as_dict(flat=True), tablename)
        (values, ignore) = af.values(rfield)
        assertTrue(('1' in values))
        assertTrue(('2' in values))
        assertTrue(('3' in values))
    finally:
        try:
            table.drop()
        except:
            pass
