'Test standard URL query parsing'

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

    s3db = current.s3db
    assertEqual = self.assertEqual
    assertNotEqual = self.assertNotEqual
    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
    url_query = {'project.organisation_id$name__like': '*test*', 'task.description__like!': '*test*'}
    resource = current.s3db.resource('project_project', vars=url_query)
    rfilter = resource.rfilter
    joins = rfilter.get_joins(left=True)
    assertNotEqual(joins, None)
    assertTrue(isinstance(joins, list))
    expected = org_organisation.on((project_project.organisation_id == org_organisation.id))
    assertEqual(joins[0], str(expected))
    expected_l = project_task_project.on(((project_task_project.project_id == project_project.id) & (project_task_project.deleted != True)))
    expected_r = project_task.on((project_task_project.task_id == project_task.id))
    assertEqual(joins[1], str(expected_l))
    assertEqual(joins[2], str(expected_r))
    query = rfilter.get_query()
    expected = (((project_project.deleted != True) & (project_project.id > 0)) & (org_organisation.name.lower().like('%test%') & (~ project_task.description.lower().like('%test%'))))
    assertEqual(str(query), str(expected))
