'Test cross-component effect of master resource filter'

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

    s3db = current.s3db
    assertEqual = self.assertEqual
    assertTrue = self.assertTrue
    project_project = s3db.project_project
    org_organisation = s3db.org_organisation
    project_task_project = s3db.project_task_project
    project_task = s3db.project_task
    q1 = (FS('organisation_id$name') == 'test')
    q2 = (FS('task.description') == 'test')
    resource = s3db.resource('project_project', filter=q1)
    resource.add_filter(q2)
    component = resource.components['task']
    component.build_query()
    rfilter = component.rfilter
    query = rfilter.get_query()
    expected = (((project_task.deleted != True) & (project_task.id > 0)) & (((project_project.deleted != True) & (project_project.id > 0)) & ((org_organisation.name == 'test') & (project_task.description == 'test'))))
    assertEqual(query, expected)
    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), 2)
    assertTrue(('org_organisation' in tablenames))
    assertTrue(('project_project' in tablenames))
    assertTrue(isinstance(left['org_organisation'], list))
    assertEqual(len(left['org_organisation']), 1)
    expected = org_organisation.on((project_project.organisation_id == org_organisation.id))
    assertEqual(str(left['org_organisation'][0]), str(expected))
    assertTrue(isinstance(left['project_project'], list))
    assertEqual(len(left['project_project']), 2)
    expected = project_task_project.on((project_task_project.task_id == project_task.id))
    assertEqual(str(left['project_project'][0]), str(expected))
    expected = project_project.on(((project_task_project.project_id == project_project.id) & (project_task_project.deleted != True)))
    assertEqual(str(left['project_project'][1]), str(expected))
    rows = component.select(None, limit=1, as_rows=True)
