'Test simple component filter construction (check query in resource)'

@unittest.skipIf((not current.deployment_settings.has_module('hrm')), 'hrm    module    disabled')
def testSimpleComponentFilterConstruction2(self):

    s3db = current.s3db
    assertEqual = self.assertEqual
    assertTrue = self.assertTrue
    pr_person = s3db.pr_person
    hrm_competency = s3db.hrm_competency
    resource = current.s3db.resource('pr_person', id=1, components=['competency'], filter=(FS('competency.id') == 1))
    component = resource.components['competency']
    query = component.get_query()
    expected = (((hrm_competency.deleted != True) & (hrm_competency.id > 0)) & ((((pr_person.deleted != True) & (pr_person.id > 0)) & (pr_person.id == 1)) & (hrm_competency.id == 1)))
    assertEqual(str(query), str(expected))
    rfilter = component.rfilter
    join = rfilter.get_joins(left=False, as_list=False)
    assertEqual(join, {})
    left = rfilter.get_joins(left=True, as_list=False)
    tablenames = left.keys()
    assertEqual(len(tablenames), 1)
    assertTrue(('pr_person' in tablenames))
    expected = pr_person.on((pr_person.id == hrm_competency.person_id))
    assertTrue(isinstance(left['pr_person'], list))
    assertEqual(len(left['pr_person']), 1)
    assertEqual(str(left['pr_person'][0]), str(expected))
