Exemplo n.º 1
0
    def test_no_operator(self):
        klass = load_model(FIELDS['longitudinal_model'])
        tree = trees.create(klass)
        p = pipeline.LongitudinalQueryProcessor(tree=tree, study_models=STUDY_MODELS)

        qs = p.get_queryset()
        self.assertEqual(qs, None, 'No timeline if no event')
Exemplo n.º 2
0
    def test(self):
        mt = trees.create(Specimen)

        qs, alias = mt.add_joins(Link)
        self.assertEqual(str(qs.query), 'SELECT "specimen"."ALIQUOT_ID" FROM "specimen" LEFT OUTER JOIN "link" ON ("specimen"."ALIQUOT_ID" = "link"."ALIQUOT_ID")')

        qs, alias = mt.add_joins(Subject)
        self.assertEqual(str(qs.query), 'SELECT "specimen"."ALIQUOT_ID" FROM "specimen" LEFT OUTER JOIN "link" ON ("specimen"."ALIQUOT_ID" = "link"."ALIQUOT_ID") {join} "subject" ON ("link"."study_id" = "subject"."study_id")'.format(join=get_join_type()))
Exemplo n.º 3
0
    def setUp(self):
        ## Context
        klass = load_model(FIELDS['longitudinal_model'])
        tree = trees.create(klass)
        ctx = DataContext.objects.filter(name='default')[0]

        ## Get timeline
        long_events = DataContext.objects.filter(name='events')[0]
        p = pipeline.LongitudinalQueryProcessor(tree=tree, context=ctx, long_events=long_events, study_models=STUDY_MODELS)
        qs = p.get_queryset()

        ## Cache the results
        self.klass = klass
        self.tree = tree
        self.ctx = ctx
        self.long_events = long_events
        self.p = p
        self.qs = qs
Exemplo n.º 4
0
    def test(self):
        mt = trees.create(Specimen)

        qs, alias = mt.add_joins(Link)

        # Django 1.6 decided it likes to put extra whitespace around parens
        # for some reason so we do all the comparisons here after removing
        # all whitespace from the strings to avoid test failures because of
        # arbitrary whitespace from Django >= 1.6.
        self.assertEqual(
            str(qs.query).replace(' ', ''),
            'SELECT "specimen"."ALIQUOT_ID" FROM "specimen" LEFT OUTER JOIN '
            '"link" ON ("specimen"."ALIQUOT_ID" = "link"."ALIQUOT_ID")'.
            replace(' ', ''))

        qs, alias = mt.add_joins(Subject)
        self.assertEqual(
            str(qs.query).replace(' ', ''),
            'SELECT "specimen"."ALIQUOT_ID" FROM "specimen" LEFT OUTER JOIN '
            '"link" ON ("specimen"."ALIQUOT_ID" = "link"."ALIQUOT_ID") LEFT '
            'OUTER JOIN "subject" ON ("link"."study_id" = '
            '"subject"."study_id")'.replace(' ', ''))
Exemplo n.º 5
0
    def test(self):
        mt = trees.create(Specimen)

        qs, alias = mt.add_joins(Link)

        # Django 1.6 decided it likes to put extra whitespace around parens
        # for some reason so we do all the comparisons here after removing
        # all whitespace from the strings to avoid test failures because of
        # arbitrary whitespace from Django >= 1.6.
        self.assertEqual(
            str(qs.query).replace(' ', ''),
            'SELECT "specimen"."ALIQUOT_ID" FROM "specimen" LEFT OUTER JOIN '
            '"link" ON ("specimen"."ALIQUOT_ID" = "link"."ALIQUOT_ID")'
            .replace(' ', ''))

        qs, alias = mt.add_joins(Subject)
        self.assertEqual(
            str(qs.query).replace(' ', ''),
            'SELECT "specimen"."ALIQUOT_ID" FROM "specimen" LEFT OUTER JOIN '
            '"link" ON ("specimen"."ALIQUOT_ID" = "link"."ALIQUOT_ID") {join} '
            '"subject" ON ("link"."study_id" = "subject"."study_id")'
            .format(join=get_join_type())
            .replace(' ', ''))
Exemplo n.º 6
0
 def setUp(self):
     self.office_mt = trees.create(models.Office)
     self.title_mt = trees.create(models.Title)
     self.employee_mt = trees.create(models.Employee)
     self.project_mt = trees.create(models.Project)
     self.meeting_mt = trees.create(models.Meeting)
Exemplo n.º 7
0
    def test_get_join_types(self):
        """
        Django 1.6 decided it likes to put extra whitespace around parens
        for some reason so we do all the comparisons here after removing
        all whitespace from the strings to avoid test failures because of
        arbitrary whitespace from Django >= 1.6.
        """

        self.office_mt = trees.create(models.Office)

        title_qs, alias = self.office_mt.add_joins(models.Title)
        self.assertEqual(
            str(title_qs.query).replace(' ', ''),
            'SELECT "tests_office"."id", "tests_office"."location" FROM '
            '"tests_office" LEFT OUTER JOIN "tests_employee" ON '
            '("tests_office"."id" = "tests_employee"."office_id") {join} '
            '"tests_title" ON ("tests_employee"."title_id" = '
            '"tests_title"."id")'
            .format(join=get_join_type())
            .replace(' ', ''))

        employee_qs, alias = self.office_mt.add_joins(models.Employee)
        self.assertEqual(
            str(employee_qs.query).replace(' ', ''),
            'SELECT "tests_office"."id", "tests_office"."location" FROM '
            '"tests_office" LEFT OUTER JOIN "tests_employee" ON '
            '("tests_office"."id" = "tests_employee"."office_id")'
            .replace(' ', ''))

        project_qs, alias = self.office_mt.add_joins(models.Project)
        self.assertEqual(
            str(project_qs.query).replace(' ', ''),
            'SELECT "tests_office"."id", "tests_office"."location" FROM '
            '"tests_office" LEFT OUTER JOIN "tests_employee" ON '
            '("tests_office"."id" = "tests_employee"."office_id") LEFT OUTER '
            'JOIN "tests_project_employees" ON ("tests_employee"."id" = '
            '"tests_project_employees"."employee_id") LEFT OUTER JOIN '
            '"tests_project" ON ("tests_project_employees"."project_id" = '
            '"tests_project"."id")'
            .replace(' ', ''))

        meeting_qs, alias = self.office_mt.add_joins(models.Meeting)
        self.assertEqual(
            str(meeting_qs.query).replace(' ', ''),
            'SELECT "tests_office"."id", "tests_office"."location" FROM '
            '"tests_office" LEFT OUTER JOIN "tests_meeting" ON '
            '("tests_office"."id" = "tests_meeting"."office_id")'
            .replace(' ', ''))

        self.title_mt = trees.create(models.Title)

        office_qs, alias = self.title_mt.add_joins(models.Office)
        self.assertEqual(
            str(office_qs.query).replace(' ', ''),
            'SELECT "tests_title"."id", "tests_title"."name", '
            '"tests_title"."salary" FROM "tests_title" LEFT OUTER JOIN '
            '"tests_employee" ON ("tests_title"."id" = '
            '"tests_employee"."title_id") {join} "tests_office" ON '
            '("tests_employee"."office_id" = "tests_office"."id")'
            .format(join=get_join_type())
            .replace(' ', ''))

        employee_qs, alias = self.title_mt.add_joins(models.Employee)
        self.assertEqual(
            str(employee_qs.query).replace(' ', ''),
            'SELECT "tests_title"."id", "tests_title"."name", '
            '"tests_title"."salary" FROM "tests_title" LEFT OUTER JOIN '
            '"tests_employee" ON ("tests_title"."id" = '
            '"tests_employee"."title_id")'
            .replace(' ', ''))

        project_qs, alias = self.title_mt.add_joins(models.Project)
        self.assertEqual(
            str(project_qs.query).replace(' ', ''),
            'SELECT "tests_title"."id", "tests_title"."name", '
            '"tests_title"."salary" FROM "tests_title" LEFT OUTER JOIN '
            '"tests_employee" ON ("tests_title"."id" = '
            '"tests_employee"."title_id") LEFT OUTER JOIN '
            '"tests_project_employees" ON ("tests_employee"."id" = '
            '"tests_project_employees"."employee_id") LEFT OUTER JOIN '
            '"tests_project" ON ("tests_project_employees"."project_id" = '
            '"tests_project"."id")'
            .replace(' ', ''))

        meeting_qs, alias = self.title_mt.add_joins(models.Meeting)
        self.assertEqual(
            str(meeting_qs.query).replace(' ', ''),
            'SELECT "tests_title"."id", "tests_title"."name", '
            '"tests_title"."salary" FROM "tests_title" LEFT OUTER JOIN '
            '"tests_employee" ON ("tests_title"."id" = '
            '"tests_employee"."title_id") LEFT OUTER JOIN '
            '"tests_meeting_attendees" ON ("tests_employee"."id" = '
            '"tests_meeting_attendees"."employee_id") LEFT OUTER JOIN '
            '"tests_meeting" ON ("tests_meeting_attendees"."meeting_id" = '
            '"tests_meeting"."id")'
            .replace(' ', ''))

        self.employee_mt = trees.create(models.Employee)

        title_qs, alias = self.employee_mt.add_joins(models.Title)
        self.assertEqual(
            str(title_qs.query).replace(' ', ''),
            'SELECT "tests_employee"."id", "tests_employee"."firstName", '
            '"tests_employee"."last_name", "tests_employee"."title_id", '
            '"tests_employee"."office_id", "tests_employee"."manager_id" FROM '
            '"tests_employee" INNER JOIN "tests_title" ON '
            '("tests_employee"."title_id" = "tests_title"."id")'
            .replace(' ', ''))

        office_qs, alias = self.employee_mt.add_joins(models.Office)
        self.assertEqual(
            str(office_qs.query).replace(' ', ''),
            'SELECT "tests_employee"."id", "tests_employee"."firstName", '
            '"tests_employee"."last_name", "tests_employee"."title_id", '
            '"tests_employee"."office_id", "tests_employee"."manager_id" FROM '
            '"tests_employee" INNER JOIN "tests_office" ON '
            '("tests_employee"."office_id" = "tests_office"."id")'
            .replace(' ', ''))

        project_qs, alias = self.employee_mt.add_joins(models.Project)
        self.assertEqual(
            str(project_qs.query).replace(' ', ''),
            'SELECT "tests_employee"."id", "tests_employee"."firstName", '
            '"tests_employee"."last_name", "tests_employee"."title_id", '
            '"tests_employee"."office_id", "tests_employee"."manager_id" FROM '
            '"tests_employee" LEFT OUTER JOIN "tests_project_employees" ON '
            '("tests_employee"."id" = '
            '"tests_project_employees"."employee_id") LEFT OUTER JOIN '
            '"tests_project" ON ("tests_project_employees"."project_id" = '
            '"tests_project"."id")'
            .replace(' ', ''))

        meeting_qs, alias = self.employee_mt.add_joins(models.Meeting)
        self.assertEqual(
            str(meeting_qs.query).replace(' ', ''),
            'SELECT "tests_employee"."id", "tests_employee"."firstName", '
            '"tests_employee"."last_name", "tests_employee"."title_id", '
            '"tests_employee"."office_id", "tests_employee"."manager_id" '
            'FROM "tests_employee" LEFT OUTER JOIN "tests_meeting_attendees" '
            'ON ("tests_employee"."id" = '
            '"tests_meeting_attendees"."employee_id") LEFT OUTER JOIN '
            '"tests_meeting" ON ("tests_meeting_attendees"."meeting_id" = '
            '"tests_meeting"."id")'
            .replace(' ', ''))

        self.project_mt = trees.create(models.Project)

        title_qs, alias = self.project_mt.add_joins(models.Title)
        self.assertEqual(
            str(title_qs.query).replace(' ', ''),
            'SELECT "tests_project"."id", "tests_project"."name", '
            '"tests_project"."manager_id", "tests_project"."due_date" FROM '
            '"tests_project" LEFT OUTER JOIN "tests_project_employees" ON '
            '("tests_project"."id" = "tests_project_employees"."project_id") '
            'LEFT OUTER JOIN "tests_employee" ON '
            '("tests_project_employees"."employee_id" = '
            '"tests_employee"."id") {join} "tests_title" ON '
            '("tests_employee"."title_id" = "tests_title"."id")'
            .format(join=get_join_type())
            .replace(' ', ''))

        office_qs, alias = self.project_mt.add_joins(models.Office)
        self.assertEqual(
            str(office_qs.query).replace(' ', ''),
            'SELECT "tests_project"."id", "tests_project"."name", '
            '"tests_project"."manager_id", "tests_project"."due_date" FROM '
            '"tests_project" LEFT OUTER JOIN "tests_project_employees" ON '
            '("tests_project"."id" = "tests_project_employees"."project_id") '
            'LEFT OUTER JOIN "tests_employee" ON '
            '("tests_project_employees"."employee_id" = '
            '"tests_employee"."id") {join} "tests_office" ON '
            '("tests_employee"."office_id" = "tests_office"."id")'
            .format(join=get_join_type())
            .replace(' ', ''))

        employee_qs, alias = self.project_mt.add_joins(models.Employee)
        self.assertEqual(
            str(employee_qs.query).replace(' ', ''),
            'SELECT "tests_project"."id", "tests_project"."name", '
            '"tests_project"."manager_id", "tests_project"."due_date" FROM '
            '"tests_project" LEFT OUTER JOIN "tests_project_employees" ON '
            '("tests_project"."id" = "tests_project_employees"."project_id") '
            'LEFT OUTER JOIN "tests_employee" ON '
            '("tests_project_employees"."employee_id" = '
            '"tests_employee"."id")'
            .replace(' ', ''))

        meeting_qs, alias = self.project_mt.add_joins(models.Meeting)
        self.assertEqual(
            str(meeting_qs.query).replace(' ', ''),
            'SELECT "tests_project"."id", "tests_project"."name", '
            '"tests_project"."manager_id", "tests_project"."due_date" FROM '
            '"tests_project" LEFT OUTER JOIN "tests_meeting" ON '
            '("tests_project"."id" = "tests_meeting"."project_id")'
            .replace(' ', ''))

        self.meeting_mt = trees.create(models.Meeting)

        title_qs, alias = self.meeting_mt.add_joins(models.Title)
        self.assertEqual(
            str(title_qs.query).replace(' ', ''),
            'SELECT "tests_meeting"."id", "tests_meeting"."project_id", '
            '"tests_meeting"."office_id", "tests_meeting"."start_time", '
            '"tests_meeting"."end_time" FROM "tests_meeting" LEFT OUTER JOIN '
            '"tests_meeting_attendees" ON ("tests_meeting"."id" = '
            '"tests_meeting_attendees"."meeting_id") LEFT OUTER JOIN '
            '"tests_employee" ON ("tests_meeting_attendees"."employee_id" = '
            '"tests_employee"."id") {join} "tests_title" ON '
            '("tests_employee"."title_id" = "tests_title"."id")'
            .format(join=get_join_type())
            .replace(' ', ''))

        office_qs, alias = self.meeting_mt.add_joins(models.Office)
        self.assertEqual(
            str(office_qs.query).replace(' ', ''),
            'SELECT "tests_meeting"."id", "tests_meeting"."project_id", '
            '"tests_meeting"."office_id", "tests_meeting"."start_time", '
            '"tests_meeting"."end_time" FROM "tests_meeting" INNER JOIN '
            '"tests_office" ON ("tests_meeting"."office_id" = '
            '"tests_office"."id")'
            .replace(' ', ''))

        employee_qs, alias = self.meeting_mt.add_joins(models.Employee)
        self.assertEqual(
            str(employee_qs.query).replace(' ', ''),
            'SELECT "tests_meeting"."id", "tests_meeting"."project_id", '
            '"tests_meeting"."office_id", "tests_meeting"."start_time", '
            '"tests_meeting"."end_time" FROM "tests_meeting" LEFT OUTER JOIN '
            '"tests_meeting_attendees" ON ("tests_meeting"."id" = '
            '"tests_meeting_attendees"."meeting_id") LEFT OUTER JOIN '
            '"tests_employee" ON ("tests_meeting_attendees"."employee_id" = '
            '"tests_employee"."id")'
            .replace(' ', ''))

        project_qs, alias = self.meeting_mt.add_joins(models.Project)
        self.assertEqual(
            str(project_qs.query).replace(' ', ''),
            'SELECT "tests_meeting"."id", "tests_meeting"."project_id", '
            '"tests_meeting"."office_id", "tests_meeting"."start_time", '
            '"tests_meeting"."end_time" FROM "tests_meeting" LEFT OUTER JOIN '
            '"tests_project" ON ("tests_meeting"."project_id" = '
            '"tests_project"."id")'
            .replace(' ', ''))
Exemplo n.º 8
0
 def setUp(self):
     self.office_mt = trees.create(models.Office)
     self.title_mt = trees.create(models.Title)
     self.employee_mt = trees.create(models.Employee)
     self.project_mt = trees.create(models.Project)
     self.meeting_mt = trees.create(models.Meeting)
Exemplo n.º 9
0
    def test_get_join_types(self):
        """
        Django 1.6 decided it likes to put extra whitespace around parens
        for some reason so we do all the comparisons here after removing
        all whitespace from the strings to avoid test failures because of
        arbitrary whitespace from Django >= 1.6.
        """

        self.office_mt = trees.create(models.Office)

        title_qs, alias = self.office_mt.add_joins(models.Title)
        self.assertEqual(
            str(title_qs.query).replace(' ', ''),
            'SELECT "tests_office"."id", "tests_office"."location" FROM '
            '"tests_office" LEFT OUTER JOIN "tests_employee" ON '
            '("tests_office"."id" = "tests_employee"."office_id") LEFT OUTER '
            'JOIN "tests_title" ON ("tests_employee"."title_id" = '
            '"tests_title"."id")'.replace(' ', ''))

        employee_qs, alias = self.office_mt.add_joins(models.Employee)
        self.assertEqual(
            str(employee_qs.query).replace(' ', ''),
            'SELECT "tests_office"."id", "tests_office"."location" FROM '
            '"tests_office" LEFT OUTER JOIN "tests_employee" ON '
            '("tests_office"."id" = "tests_employee"."office_id")'.replace(
                ' ', ''))

        project_qs, alias = self.office_mt.add_joins(models.Project)
        self.assertEqual(
            str(project_qs.query).replace(' ', ''),
            'SELECT "tests_office"."id", "tests_office"."location" FROM '
            '"tests_office" LEFT OUTER JOIN "tests_employee" ON '
            '("tests_office"."id" = "tests_employee"."office_id") LEFT OUTER '
            'JOIN "tests_project_employees" ON ("tests_employee"."id" = '
            '"tests_project_employees"."employee_id") LEFT OUTER JOIN '
            '"tests_project" ON ("tests_project_employees"."project_id" = '
            '"tests_project"."id")'.replace(' ', ''))

        meeting_qs, alias = self.office_mt.add_joins(models.Meeting)
        self.assertEqual(
            str(meeting_qs.query).replace(' ', ''),
            'SELECT "tests_office"."id", "tests_office"."location" FROM '
            '"tests_office" LEFT OUTER JOIN "tests_meeting" ON '
            '("tests_office"."id" = "tests_meeting"."office_id")'.replace(
                ' ', ''))

        self.title_mt = trees.create(models.Title)

        office_qs, alias = self.title_mt.add_joins(models.Office)
        self.assertEqual(
            str(office_qs.query).replace(' ', ''),
            'SELECT "tests_title"."id", "tests_title"."name", '
            '"tests_title"."salary" FROM "tests_title" LEFT OUTER JOIN '
            '"tests_employee" ON ("tests_title"."id" = '
            '"tests_employee"."title_id") LEFT OUTER JOIN "tests_office" ON '
            '("tests_employee"."office_id" = "tests_office"."id")'.replace(
                ' ', ''))

        employee_qs, alias = self.title_mt.add_joins(models.Employee)
        self.assertEqual(
            str(employee_qs.query).replace(' ', ''),
            'SELECT "tests_title"."id", "tests_title"."name", '
            '"tests_title"."salary" FROM "tests_title" LEFT OUTER JOIN '
            '"tests_employee" ON ("tests_title"."id" = '
            '"tests_employee"."title_id")'.replace(' ', ''))

        project_qs, alias = self.title_mt.add_joins(models.Project)
        self.assertEqual(
            str(project_qs.query).replace(' ', ''),
            'SELECT "tests_title"."id", "tests_title"."name", '
            '"tests_title"."salary" FROM "tests_title" LEFT OUTER JOIN '
            '"tests_employee" ON ("tests_title"."id" = '
            '"tests_employee"."title_id") LEFT OUTER JOIN '
            '"tests_project_employees" ON ("tests_employee"."id" = '
            '"tests_project_employees"."employee_id") LEFT OUTER JOIN '
            '"tests_project" ON ("tests_project_employees"."project_id" = '
            '"tests_project"."id")'.replace(' ', ''))

        meeting_qs, alias = self.title_mt.add_joins(models.Meeting)
        self.assertEqual(
            str(meeting_qs.query).replace(' ', ''),
            'SELECT "tests_title"."id", "tests_title"."name", '
            '"tests_title"."salary" FROM "tests_title" LEFT OUTER JOIN '
            '"tests_employee" ON ("tests_title"."id" = '
            '"tests_employee"."title_id") LEFT OUTER JOIN '
            '"tests_meeting_attendees" ON ("tests_employee"."id" = '
            '"tests_meeting_attendees"."employee_id") LEFT OUTER JOIN '
            '"tests_meeting" ON ("tests_meeting_attendees"."meeting_id" = '
            '"tests_meeting"."id")'.replace(' ', ''))

        self.employee_mt = trees.create(models.Employee)

        title_qs, alias = self.employee_mt.add_joins(models.Title)
        self.assertEqual(
            str(title_qs.query).replace(' ', ''),
            'SELECT "tests_employee"."id", "tests_employee"."firstName", '
            '"tests_employee"."last_name", "tests_employee"."title_id", '
            '"tests_employee"."office_id", "tests_employee"."manager_id" FROM '
            '"tests_employee" INNER JOIN "tests_title" ON '
            '("tests_employee"."title_id" = "tests_title"."id")'.replace(
                ' ', ''))

        office_qs, alias = self.employee_mt.add_joins(models.Office)
        self.assertEqual(
            str(office_qs.query).replace(' ', ''),
            'SELECT "tests_employee"."id", "tests_employee"."firstName", '
            '"tests_employee"."last_name", "tests_employee"."title_id", '
            '"tests_employee"."office_id", "tests_employee"."manager_id" FROM '
            '"tests_employee" INNER JOIN "tests_office" ON '
            '("tests_employee"."office_id" = "tests_office"."id")'.replace(
                ' ', ''))

        project_qs, alias = self.employee_mt.add_joins(models.Project)
        self.assertEqual(
            str(project_qs.query).replace(' ', ''),
            'SELECT "tests_employee"."id", "tests_employee"."firstName", '
            '"tests_employee"."last_name", "tests_employee"."title_id", '
            '"tests_employee"."office_id", "tests_employee"."manager_id" FROM '
            '"tests_employee" LEFT OUTER JOIN "tests_project_employees" ON '
            '("tests_employee"."id" = '
            '"tests_project_employees"."employee_id") LEFT OUTER JOIN '
            '"tests_project" ON ("tests_project_employees"."project_id" = '
            '"tests_project"."id")'.replace(' ', ''))

        meeting_qs, alias = self.employee_mt.add_joins(models.Meeting)
        self.assertEqual(
            str(meeting_qs.query).replace(' ', ''),
            'SELECT "tests_employee"."id", "tests_employee"."firstName", '
            '"tests_employee"."last_name", "tests_employee"."title_id", '
            '"tests_employee"."office_id", "tests_employee"."manager_id" '
            'FROM "tests_employee" LEFT OUTER JOIN "tests_meeting_attendees" '
            'ON ("tests_employee"."id" = '
            '"tests_meeting_attendees"."employee_id") LEFT OUTER JOIN '
            '"tests_meeting" ON ("tests_meeting_attendees"."meeting_id" = '
            '"tests_meeting"."id")'.replace(' ', ''))

        self.project_mt = trees.create(models.Project)

        title_qs, alias = self.project_mt.add_joins(models.Title)
        self.assertEqual(
            str(title_qs.query).replace(' ', ''),
            'SELECT "tests_project"."id", "tests_project"."name", '
            '"tests_project"."manager_id", "tests_project"."due_date" FROM '
            '"tests_project" LEFT OUTER JOIN "tests_project_employees" ON '
            '("tests_project"."id" = "tests_project_employees"."project_id") '
            'LEFT OUTER JOIN "tests_employee" ON '
            '("tests_project_employees"."employee_id" = '
            '"tests_employee"."id") LEFT OUTER JOIN "tests_title" ON '
            '("tests_employee"."title_id" = "tests_title"."id")'.replace(
                ' ', ''))

        office_qs, alias = self.project_mt.add_joins(models.Office)
        self.assertEqual(
            str(office_qs.query).replace(' ', ''),
            'SELECT "tests_project"."id", "tests_project"."name", '
            '"tests_project"."manager_id", "tests_project"."due_date" FROM '
            '"tests_project" LEFT OUTER JOIN "tests_project_employees" ON '
            '("tests_project"."id" = "tests_project_employees"."project_id") '
            'LEFT OUTER JOIN "tests_employee" ON '
            '("tests_project_employees"."employee_id" = '
            '"tests_employee"."id") LEFT OUTER JOIN "tests_office" ON '
            '("tests_employee"."office_id" = "tests_office"."id")'.replace(
                ' ', ''))

        employee_qs, alias = self.project_mt.add_joins(models.Employee)
        self.assertEqual(
            str(employee_qs.query).replace(' ', ''),
            'SELECT "tests_project"."id", "tests_project"."name", '
            '"tests_project"."manager_id", "tests_project"."due_date" FROM '
            '"tests_project" LEFT OUTER JOIN "tests_project_employees" ON '
            '("tests_project"."id" = "tests_project_employees"."project_id") '
            'LEFT OUTER JOIN "tests_employee" ON '
            '("tests_project_employees"."employee_id" = '
            '"tests_employee"."id")'.replace(' ', ''))

        meeting_qs, alias = self.project_mt.add_joins(models.Meeting)
        self.assertEqual(
            str(meeting_qs.query).replace(' ', ''),
            'SELECT "tests_project"."id", "tests_project"."name", '
            '"tests_project"."manager_id", "tests_project"."due_date" FROM '
            '"tests_project" LEFT OUTER JOIN "tests_meeting" ON '
            '("tests_project"."id" = "tests_meeting"."project_id")'.replace(
                ' ', ''))

        self.meeting_mt = trees.create(models.Meeting)

        title_qs, alias = self.meeting_mt.add_joins(models.Title)
        self.assertEqual(
            str(title_qs.query).replace(' ', ''),
            'SELECT "tests_meeting"."id", "tests_meeting"."project_id", '
            '"tests_meeting"."office_id", "tests_meeting"."start_time", '
            '"tests_meeting"."end_time" FROM "tests_meeting" LEFT OUTER JOIN '
            '"tests_meeting_attendees" ON ("tests_meeting"."id" = '
            '"tests_meeting_attendees"."meeting_id") LEFT OUTER JOIN '
            '"tests_employee" ON ("tests_meeting_attendees"."employee_id" = '
            '"tests_employee"."id") LEFT OUTER JOIN "tests_title" ON '
            '("tests_employee"."title_id" = "tests_title"."id")'.replace(
                ' ', ''))

        office_qs, alias = self.meeting_mt.add_joins(models.Office)
        self.assertEqual(
            str(office_qs.query).replace(' ', ''),
            'SELECT "tests_meeting"."id", "tests_meeting"."project_id", '
            '"tests_meeting"."office_id", "tests_meeting"."start_time", '
            '"tests_meeting"."end_time" FROM "tests_meeting" INNER JOIN '
            '"tests_office" ON ("tests_meeting"."office_id" = '
            '"tests_office"."id")'.replace(' ', ''))

        employee_qs, alias = self.meeting_mt.add_joins(models.Employee)
        self.assertEqual(
            str(employee_qs.query).replace(' ', ''),
            'SELECT "tests_meeting"."id", "tests_meeting"."project_id", '
            '"tests_meeting"."office_id", "tests_meeting"."start_time", '
            '"tests_meeting"."end_time" FROM "tests_meeting" LEFT OUTER JOIN '
            '"tests_meeting_attendees" ON ("tests_meeting"."id" = '
            '"tests_meeting_attendees"."meeting_id") LEFT OUTER JOIN '
            '"tests_employee" ON ("tests_meeting_attendees"."employee_id" = '
            '"tests_employee"."id")'.replace(' ', ''))

        project_qs, alias = self.meeting_mt.add_joins(models.Project)
        self.assertEqual(
            str(project_qs.query).replace(' ', ''),
            'SELECT "tests_meeting"."id", "tests_meeting"."project_id", '
            '"tests_meeting"."office_id", "tests_meeting"."start_time", '
            '"tests_meeting"."end_time" FROM "tests_meeting" LEFT OUTER JOIN '
            '"tests_project" ON ("tests_meeting"."project_id" = '
            '"tests_project"."id")'.replace(' ', ''))