'Test cross-component effect of master resource filter'

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

    s3db = current.s3db
    assertEqual = self.assertEqual
    assertTrue = self.assertTrue
    pr_identity = s3db.pr_identity
    pr_person = s3db.pr_person
    org_organisation = s3db.org_organisation
    hrm_human_resource = s3db.hrm_human_resource
    q1 = (FS('human_resource.organisation_id$name') == 'test')
    q2 = (FS('identity.value') == 'test')
    resource = s3db.resource('pr_person', filter=q1)
    resource.add_filter(q2)
    component = resource.components['identity']
    component.build_query()
    rfilter = component.rfilter
    query = rfilter.get_query()
    expected = (((pr_identity.deleted != True) & (pr_identity.id > 0)) & (((pr_person.deleted != True) & (pr_person.id > 0)) & ((org_organisation.name == 'test') & (pr_identity.value == 'test'))))
    assertEqual(query, expected)
    join = rfilter.get_joins(left=False, as_list=False)
    assertEqual(join, {})
    expected_h = hrm_human_resource.on(((hrm_human_resource.person_id == pr_person.id) & (hrm_human_resource.deleted != True)))
    expected_o = org_organisation.on((hrm_human_resource.organisation_id == org_organisation.id))
    expected_p = pr_person.on((pr_identity.person_id == pr_person.id))
    left = rfilter.get_joins(left=True, as_list=False)
    tablenames = left.keys()
    assertEqual(len(tablenames), 3)
    assertTrue(('hrm_human_resource' in tablenames))
    assertTrue(('org_organisation' in tablenames))
    assertTrue(('pr_person' in tablenames))
    assertTrue(isinstance(left['hrm_human_resource'], list))
    assertEqual(len(left['hrm_human_resource']), 1)
    assertEqual(str(left['hrm_human_resource'][0]), str(expected_h))
    assertTrue(isinstance(left['org_organisation'], list))
    assertEqual(len(left['org_organisation']), 1)
    assertEqual(str(left['org_organisation'][0]), str(expected_o))
    assertEqual(len(left['pr_person']), 1)
    assertEqual(str(left['pr_person'][0]), str(expected_p))
    rows = component.select(None, limit=1, as_rows=True)
