def test_query_traversing_to_fk_object(self):
     qs = 'Entry(%s) Entry.blog' % self.entries[0].pk
     query = Query(qs)
     result = query()
     self.assertEquals(result[0][0][1], -1)
     assertQueryResultsEqual(self, result[0][0][0], [(self.blogs[0], None)])
     self.assertEquals(result[1], Blog)
  def test_recursive_traversal_does_not_get_stuck_in_loop(self):
    blog = Blog(name='Weird CS Terms')
    blog.save()
    headlines = ('Foo', 'Bar', 'Baz', 'Faz')
    entries = [Entry(headline=headline, blog=blog) for headline in headlines]
    for entry in entries:
      entry.save()
    entries[1].response_to = entries[0]
    entries[1].save()
    entries[2].response_to = entries[1]
    entries[2].save()
    entries[3].response_to = entries[2]
    entries[3].save()
    entries[0].response_to = entries[3]
    entries[0].save()

    qs = 'Entry(id__in=[%s]) Entry.responses*' % (entries[0].id,)
    query = Query(qs)
    result = query()
    self.assertEquals(result[0][0][1], -1)
    assertQueryResultsEqual(self, result[0][0][0],
                            [(entries[0], None),
                             (entries[1], None),
                             (entries[2], None),
                             (entries[3], None),
                            ])
    self.assertEquals(result[1], Entry)
Beispiel #3
0
    def test_recursive_traversal_on_same_model_from_multiple_objects(self):
        blog = Blog(name='Weird CS Terms')
        blog.save()
        headlines = ('Foo', 'Bar', 'Baz', 'Faz')
        entries = [
            Entry(headline=headline, blog=blog) for headline in headlines
        ]
        for entry in entries:
            entry.save()
        entries[1].response_to = entries[0]
        entries[1].save()
        entries[2].response_to = entries[1]
        entries[2].save()
        entries[3].response_to = entries[2]
        entries[3].save()

        qs = 'Entry(id__in=[%s,%s]) Entry.responses*' % (self.entries[0].id,
                                                         entries[0].id)
        query = Query(qs)
        result = query()
        self.assertEquals(result[0][0][1], -1)
        assertQueryResultsEqual(self, result[0][0][0], [
            (self.entries[0], None),
            (self.entries[1], None),
            (self.entries[2], None),
            (self.entries[3], None),
            (entries[0], None),
            (entries[1], None),
            (entries[2], None),
            (entries[3], None),
        ])
        self.assertEquals(result[1], Entry)
Beispiel #4
0
 def test_implicit_filter(self):
   qs = 'Blog(%s) Blog.authors(name__icontains="Smith")' % self.blogs[0].pk
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0], [(self.authors[0], None)])
   self.assertEquals(result[1], Author)
Beispiel #5
0
    def test_recursive_traversal_does_not_get_stuck_in_loop(self):
        blog = Blog(name='Weird CS Terms')
        blog.save()
        headlines = ('Foo', 'Bar', 'Baz', 'Faz')
        entries = [
            Entry(headline=headline, blog=blog) for headline in headlines
        ]
        for entry in entries:
            entry.save()
        entries[1].response_to = entries[0]
        entries[1].save()
        entries[2].response_to = entries[1]
        entries[2].save()
        entries[3].response_to = entries[2]
        entries[3].save()
        entries[0].response_to = entries[3]
        entries[0].save()

        qs = 'Entry(id__in=[%s]) Entry.responses*' % (entries[0].id, )
        query = Query(qs)
        result = query()
        self.assertEquals(result[0][0][1], -1)
        assertQueryResultsEqual(self, result[0][0][0], [
            (entries[0], None),
            (entries[1], None),
            (entries[2], None),
            (entries[3], None),
        ])
        self.assertEquals(result[1], Entry)
Beispiel #6
0
 def test_query_starting_with_filter(self):
   qs = 'Entry(id=%s)' % self.entries[0].pk
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0], [(self.entries[0], None)])
   self.assertEquals(result[1], Entry)
 def test_recursive_search_for_last_nodes_of_relationship(self):
   qs = 'Blog(%s) Blog.entry_set(headline__icontains="MySQL") Entry.responses$' % self.blog.pk
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0], [(self.entries[3], None)])
   self.assertEquals(result[1], Entry)
    def test_join_m2m_relationship(self):
        # M2M relationship defined is symmetrical, which means if A is friend of B,
        # B is also friend of A. Below asserts check this assumption.
        self.assertItemsEqual(self.authors[0].friends.all(),
                              [self.authors[1], self.authors[2]])
        self.assertItemsEqual(self.authors[1].friends.all(),
                              [self.authors[0], self.authors[2]])
        self.assertItemsEqual(self.authors[2].friends.all(),
                              [self.authors[0], self.authors[1]])

        qs = 'Blog(%s) Blog.entry_set Entry.authors, Author.friends' % self.blogs[
            0].pk
        query = Query(qs)
        result = query()
        self.assertEquals(result[0][0][1], -1)
        assertQueryResultsEqual(self, result[0][0][0], [
            (self.authors[0], None),
            (self.authors[1], None),
            (self.authors[2], None),
        ])
        self.assertEquals(result[0][1][1], 0)
        assertQueryResultsEqual(self, result[0][1][0], [
            (self.authors[1], self.authors[0].pk),
            (self.authors[2], self.authors[0].pk),
            (self.authors[0], self.authors[1].pk),
            (self.authors[2], self.authors[1].pk),
            (self.authors[0], self.authors[2].pk),
            (self.authors[1], self.authors[2].pk),
        ])
        self.assertEquals(result[1], Author)
Beispiel #9
0
 def test_explicit_chained_filters(self):
   qs = 'Blog(%s) Blog.authors.filter(name__icontains="Jo").exclude(name__icontains="Smith")' % self.blogs[0].pk
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0], [(self.authors[2], None)])
   self.assertEquals(result[1], Author)
Beispiel #10
0
  def test_recursive_traversal_on_same_model_from_multiple_objects(self):
    blog = Blog(name='Weird CS Terms')
    blog.save()
    headlines = ('Foo', 'Bar', 'Baz', 'Faz')
    entries = [Entry(headline=headline, blog=blog) for headline in headlines]
    for entry in entries:
      entry.save()
    entries[1].response_to = entries[0]
    entries[1].save()
    entries[2].response_to = entries[1]
    entries[2].save()
    entries[3].response_to = entries[2]
    entries[3].save()

    qs = 'Entry(id__in=[%s,%s]) Entry.responses*' % (self.entries[0].id, entries[0].id)
    query = Query(qs)
    result = query()
    self.assertEquals(result[0][0][1], -1)
    assertQueryResultsEqual(self, result[0][0][0],
                            [(self.entries[0], None),
                             (self.entries[1], None),
                             (self.entries[2], None),
                             (self.entries[3], None),
                             (entries[0], None),
                             (entries[1], None),
                             (entries[2], None),
                             (entries[3], None),
                            ])
    self.assertEquals(result[1], Entry)
Beispiel #11
0
 def test_query_traversing_to_fk_object(self):
   qs = 'Entry(%s) Entry.blog' % self.entries[0].pk
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0], [(self.blogs[0], None)])
   self.assertEquals(result[1], Blog)
Beispiel #12
0
  def test_join_m2m_relationship(self):
    # M2M relationship defined is symmetrical, which means if A is friend of B,
    # B is also friend of A. Below asserts check this assumption.
    self.assertItemsEqual(self.authors[0].friends.all(), [self.authors[1], self.authors[2]])
    self.assertItemsEqual(self.authors[1].friends.all(), [self.authors[0], self.authors[2]])
    self.assertItemsEqual(self.authors[2].friends.all(), [self.authors[0], self.authors[1]])

    qs = 'Blog(%s) Blog.entry_set Entry.authors, Author.friends' % self.blogs[0].pk
    query = Query(qs)
    result = query()
    self.assertEquals(result[0][0][1], -1)
    assertQueryResultsEqual(self, result[0][0][0],
                            [
                              (self.authors[0], None),
                              (self.authors[1], None),
                              (self.authors[2], None),
                            ])
    self.assertEquals(result[0][1][1], 0)
    assertQueryResultsEqual(self, result[0][1][0],
                            [
                              (self.authors[1], self.authors[0].pk),
                              (self.authors[2], self.authors[0].pk),
                              (self.authors[0], self.authors[1].pk),
                              (self.authors[2], self.authors[1].pk),
                              (self.authors[0], self.authors[2].pk),
                              (self.authors[1], self.authors[2].pk),
                            ])
    self.assertEquals(result[1], Author)
Beispiel #13
0
 def test_exclude(self):
   f = dict(method='exclude', kwargs=dict(name__icontains='Smith'))
   authors = traverse(self.entries, Entry.authors, filters=[f])
   assertQueryResultsEqual(self, authors, [(self.authors[1], self.entries[1].pk),
                                           (self.authors[2], self.entries[1].pk),
                                           (self.authors[2], self.entries[2].pk),
                                           (self.authors[1], self.entries[0].pk)])
Beispiel #14
0
 def test_recursive_m2m_to_self_avoids_loops(self):
   qs = 'Blog(%s) Blog.entry_set Entry.authors, Author.friends*' % self.blogs[0].pk
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0],
                           [
                             (self.authors[0], None),
                             (self.authors[1], None),
                             (self.authors[2], None),
                           ])
   self.assertEquals(result[0][1][1], 0)
   assertQueryResultsEqual(self, result[0][1][0],
                           [
                             (self.authors[1], self.authors[0].pk),
                             (self.authors[2], self.authors[0].pk),
                             (self.authors[0], self.authors[0].pk),
                             (self.authors[0], self.authors[1].pk),
                             (self.authors[1], self.authors[1].pk),
                             (self.authors[2], self.authors[1].pk),
                             (self.authors[0], self.authors[2].pk),
                             (self.authors[2], self.authors[2].pk),
                             (self.authors[1], self.authors[2].pk),
                           ])
   self.assertEquals(result[1], Author)
Beispiel #15
0
 def test_query_traversing_with_filters(self):
   qs = 'Blog(%s) Blog.authors(name__icontains="Smith") Author.entry_set' % self.blogs[0].pk
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0], [(self.entries[0], None),
                                                   (self.entries[2], None)])
   self.assertEquals(result[1], Entry)
 def test_can_traverse_from_M2M_objects_with_exclusions(self):
     f = dict(method='exclude', kwargs=dict(headline__icontains='Graph'))
     entries = traverse(self.authors, Author.entry_set, filters=[f])
     assertQueryResultsEqual(self, entries,
                             [(self.entries[0], self.authors[0].pk),
                              (self.entries[0], self.authors[1].pk),
                              (self.entries[1], self.authors[1].pk),
                              (self.entries[1], self.authors[2].pk)])
 def test_can_traverse_to_M2M_objects_with_exclusions(self):
     f = dict(method='exclude', kwargs=dict(name__icontains='Smith'))
     authors = traverse(self.entries, Entry.authors, filters=[f])
     assertQueryResultsEqual(self, authors,
                             [(self.authors[1], self.entries[0].pk),
                              (self.authors[1], self.entries[1].pk),
                              (self.authors[2], self.entries[1].pk),
                              (self.authors[2], self.entries[2].pk)])
Beispiel #18
0
 def test_recursive_search_with_filter_finds_starting_node(self):
   qs = 'Blog(%s) Blog.entry_set(headline__icontains="MySQL") \
         Entry.responses(headline__icontains="MySQL")*' % self.blog.pk
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0], [(self.entries[0], None)])
   self.assertEquals(result[1], Entry)
Beispiel #19
0
 def test_recursive_search_for_last_nodes_of_relationship(self):
     qs = 'Blog(%s) Blog.entry_set(headline__icontains="MySQL") Entry.responses$' % self.blog.pk
     query = Query(qs)
     result = query()
     self.assertEquals(result[0][0][1], -1)
     assertQueryResultsEqual(self, result[0][0][0],
                             [(self.entries[3], None)])
     self.assertEquals(result[1], Entry)
Beispiel #20
0
 def test_query_starting_with_id(self):
   qs = 'Blog(%s)' % self.blog.pk
   query = Query(qs)
   result = query()
   self.assertEquals(len(result[0]), 1)
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0], [(self.blog, None)])
   self.assertEquals(result[1], Blog)
 def test_query_starting_with_filter(self):
     qs = 'Entry(id=%s)' % self.entries[0].pk
     query = Query(qs)
     result = query()
     self.assertEquals(result[0][0][1], -1)
     assertQueryResultsEqual(self, result[0][0][0],
                             [(self.entries[0], None)])
     self.assertEquals(result[1], Entry)
Beispiel #22
0
 def test_reverse_of_fk_to_self(self):
   qs = 'Blog(%s) Blog.entry_set(headline__icontains="Postgres") Entry.responses' % self.blog.pk
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0],
                           [(self.entries[2], None)])
   self.assertEquals(result[1], Entry)
Beispiel #23
0
 def test_page_then_get_related(self):
     qs = 'Blog(id__isnull=False).order(name).first(2), Blog.entry_set'
     query = Query(qs)
     result = query()
     assertQueryResultsEqual(self, result[0][0][0], [(self.blogs[0], None),
                                                     (self.blogs[2], None)])
     assertQueryResultsEqual(self, result[0][1][0], [(self.entries[0], 1),
                                                     (self.entries[2], 3)])
Beispiel #24
0
 def test_recursive_search_for_first_node_matching_filter(self):
   qs = 'Blog(%s) Blog.entry_set(headline__icontains="MySQL") \
         Entry.responses(headline__icontains="graph")?' % self.blog.pk
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0], [(self.entries[2], None)])
   self.assertEquals(result[1], Entry)
Beispiel #25
0
 def test_implicit_filter(self):
     qs = 'Blog(%s) Blog.authors(name__icontains="Smith")' % self.blogs[0].pk
     query = Query(qs)
     result = query()
     self.assertEquals(result[0][0][1], -1)
     assertQueryResultsEqual(self, result[0][0][0],
                             [(self.authors[0], None)])
     self.assertEquals(result[1], Author)
Beispiel #26
0
 def test_explicit_avg_and_filter(self):
   qs = 'Blog(%s) Blog.entry_set.avg(authors__age).filter(authors__age__avg__gt=25)' % self.blogs[0].pk
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0], [(self.entries[1], None),
                                                   (self.entries[2], None)])
   self.assertEquals(result[1], Entry)
 def test_can_traverse_to_M2M_objects_and_returns_traversed_pair(self):
     authors = traverse(self.entries, Entry.authors)
     assertQueryResultsEqual(self, authors,
                             [(self.authors[0], self.entries[0].pk),
                              (self.authors[1], self.entries[0].pk),
                              (self.authors[1], self.entries[1].pk),
                              (self.authors[2], self.entries[1].pk),
                              (self.authors[2], self.entries[2].pk),
                              (self.authors[0], self.entries[2].pk)])
 def test_can_traverse_from_M2M_objects_and_returns_traversed_pair(self):
     entries = traverse(self.authors, Author.entry_set)
     assertQueryResultsEqual(self, entries,
                             [(self.entries[0], self.authors[0].pk),
                              (self.entries[0], self.authors[1].pk),
                              (self.entries[1], self.authors[1].pk),
                              (self.entries[1], self.authors[2].pk),
                              (self.entries[2], self.authors[2].pk),
                              (self.entries[2], self.authors[0].pk)])
Beispiel #29
0
 def test_recursive_search_for_first_node_matching_filter(self):
     qs = 'Blog(%s) Blog.entry_set(headline__icontains="MySQL") \
       Entry.responses(headline__icontains="graph")?' % self.blog.pk
     query = Query(qs)
     result = query()
     self.assertEquals(result[0][0][1], -1)
     assertQueryResultsEqual(self, result[0][0][0],
                             [(self.entries[2], None)])
     self.assertEquals(result[1], Entry)
Beispiel #30
0
 def test_recursive_search_with_filter_finds_starting_node(self):
     qs = 'Blog(%s) Blog.entry_set(headline__icontains="MySQL") \
       Entry.responses(headline__icontains="MySQL")*' % self.blog.pk
     query = Query(qs)
     result = query()
     self.assertEquals(result[0][0][1], -1)
     assertQueryResultsEqual(self, result[0][0][0],
                             [(self.entries[0], None)])
     self.assertEquals(result[1], Entry)
Beispiel #31
0
 def test_explicit_chained_filters(self):
     qs = 'Blog(%s) Blog.authors.filter(name__icontains="Jo").exclude(name__icontains="Smith")' % self.blogs[
         0].pk
     query = Query(qs)
     result = query()
     self.assertEquals(result[0][0][1], -1)
     assertQueryResultsEqual(self, result[0][0][0],
                             [(self.authors[2], None)])
     self.assertEquals(result[1], Author)
Beispiel #32
0
 def test_query_traversing_to_M2M_objects(self):
   qs = 'Blog(%s) Blog.entry_set Entry.authors' % self.blogs[0].pk
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0], [(self.authors[0], None),
                                                   (self.authors[1], None),
                                                   (self.authors[2], None)])
   self.assertEquals(result[1], Author)
Beispiel #33
0
 def test_query_traversing_from_fk_objects(self):
   qs = 'Blog(%s) Blog.entry_set' % self.blogs[0].pk
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0], [(self.entries[0], None),
                                                   (self.entries[1], None),
                                                   (self.entries[2], None)])
   self.assertEquals(result[1], Entry)
 def test_query_traversing_with_filters(self):
     qs = 'Blog(%s) Blog.authors(name__icontains="Smith") Author.entry_set' % self.blogs[
         0].pk
     query = Query(qs)
     result = query()
     self.assertEquals(result[0][0][1], -1)
     assertQueryResultsEqual(self, result[0][0][0],
                             [(self.entries[0], None),
                              (self.entries[2], None)])
     self.assertEquals(result[1], Entry)
Beispiel #35
0
 def test_filtering_queries_without_join(self):
   qs = 'Blog(%s) +(Blog.entry_set) Blog.entry_set' % self.blogs[0].pk
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0], [(self.entries[0], None),
                                                   (self.entries[1], None),
                                                   (self.entries[2], None)])
   self.assertEquals(len(result[0]), 1)
   self.assertEquals(result[1], Entry)
Beispiel #36
0
 def test_recursive_search_with_filter_stops_traversal_after_mismatch(self):
   qs = 'Blog(%s) Blog.entry_set(headline__icontains="MySQL") \
         Entry.responses(headline__icontains="relational")*' % self.blog.pk
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0],
                           [(self.entries[0], None),
                            (self.entries[1], None)])
   self.assertEquals(result[1], Entry)
 def test_query_traversing_to_M2M_objects(self):
     qs = 'Blog(%s) Blog.entry_set Entry.authors' % self.blogs[0].pk
     query = Query(qs)
     result = query()
     self.assertEquals(result[0][0][1], -1)
     assertQueryResultsEqual(self, result[0][0][0],
                             [(self.authors[0], None),
                              (self.authors[1], None),
                              (self.authors[2], None)])
     self.assertEquals(result[1], Author)
Beispiel #38
0
 def test_recursive_search_with_filter_stops_traversal_after_mismatch(self):
     qs = 'Blog(%s) Blog.entry_set(headline__icontains="MySQL") \
       Entry.responses(headline__icontains="relational")*' % self.blog.pk
     query = Query(qs)
     result = query()
     self.assertEquals(result[0][0][1], -1)
     assertQueryResultsEqual(self, result[0][0][0],
                             [(self.entries[0], None),
                              (self.entries[1], None)])
     self.assertEquals(result[1], Entry)
 def test_query_traversing_with_function_and_from_M2M_objects(self):
     qs = 'Blog(%s) Blog.authors Author.entry_set' % self.blogs[0].pk
     query = Query(qs)
     result = query()
     self.assertEquals(result[0][0][1], -1)
     assertQueryResultsEqual(self, result[0][0][0],
                             [(self.entries[0], None),
                              (self.entries[1], None),
                              (self.entries[2], None)])
     self.assertEquals(result[1], Entry)
Beispiel #40
0
 def test_first_set_of_results_are_unique_and_not_separated_by_objects_from_first_relation(self):
   qs = 'Blog(name__icontains="Databases") Blog.entry_set Entry.authors'
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0], [(self.authors[0], None),
                                                   (self.authors[1], None),
                                                   (self.authors[2], None)])
   self.assertEquals(len(result[0]), 1)
   self.assertEquals(result[1], Author)
Beispiel #41
0
 def test_explicit_avg_and_filter(self):
     qs = 'Blog(%s) Blog.entry_set.avg(authors__age).filter(authors__age__avg__gt=25)' % self.blogs[
         0].pk
     query = Query(qs)
     result = query()
     self.assertEquals(result[0][0][1], -1)
     assertQueryResultsEqual(self, result[0][0][0],
                             [(self.entries[1], None),
                              (self.entries[2], None)])
     self.assertEquals(result[1], Entry)
 def test_filtering_queries_without_join(self):
     qs = 'Blog(%s) +(Blog.entry_set) Blog.entry_set' % self.blogs[0].pk
     query = Query(qs)
     result = query()
     self.assertEquals(result[0][0][1], -1)
     assertQueryResultsEqual(self, result[0][0][0],
                             [(self.entries[0], None),
                              (self.entries[1], None),
                              (self.entries[2], None)])
     self.assertEquals(len(result[0]), 1)
     self.assertEquals(result[1], Entry)
    def test_or_queries_matching_nothing(self):
        qs = 'Blog(%s), ' % self.blogs[0].pk +\
             '(Blog.entry_set(headline__icontains="Foo")) | (Blog.entry_set(headline__icontains="Bar")), '+\
             'Entry.authors'
        query = Query(qs)
        result = query()
        self.assertEquals(len(result[0]), 3)

        assertQueryResultsEqual(self, result[0][0][0], [(self.blogs[0], None)])
        self.assertEquals(result[0][1], ([], 0, None))
        self.assertEquals(result[0][2], ([], 1, None))
Beispiel #44
0
  def test_returns_empty_result_for_each_part_of_sub_queries_after_no_match(self):
    qs = 'Blog(%s) ?(Blog.entry_set(headline__icontains="Noop")) \
                   Blog.entry_set(headline__icontains="Noop"), Entry.authors' % self.blogs[0].pk
    query = Query(qs)
    result = query()
    self.assertEquals(len(result[0]), 4)

    assertQueryResultsEqual(self, result[0][0][0], [(self.blogs[0], None)])
    self.assertEquals(result[0][1], ([(None, self.blogs[0].pk)], 0, None))
    self.assertEquals(result[0][2], ([], 0, None))
    self.assertEquals(result[0][3], ([], 2, None))
Beispiel #45
0
 def test_recursive_traversal_with_filter_does_not_return_starting_node_if_it_does_not_pass_filter(self):
   qs = 'Blog(%s) Blog.entry_set(headline__icontains="MySQL") \
         Entry.responses(headline__icontains="graph")**' % self.blog.pk
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0],
                           [(self.entries[2], None),
                            (self.entries[3], None),
                           ])
   self.assertEquals(result[1], Entry)
Beispiel #46
0
  def test_or_queries_matching_nothing(self):
    qs = 'Blog(%s), ' % self.blogs[0].pk +\
         '(Blog.entry_set(headline__icontains="Foo")) | (Blog.entry_set(headline__icontains="Bar")), '+\
         'Entry.authors'
    query = Query(qs)
    result = query()
    self.assertEquals(len(result[0]), 3)

    assertQueryResultsEqual(self, result[0][0][0], [(self.blogs[0], None)])
    self.assertEquals(result[0][1], ([], 0, None))
    self.assertEquals(result[0][2], ([], 1, None))
 def test_query_with_m2m_relationship(self):
     qs = 'Blog(%s) Blog.entry_set Entry.authors Author.friends' % self.blogs[
         0].pk
     query = Query(qs)
     result = query()
     self.assertEquals(result[0][0][1], -1)
     assertQueryResultsEqual(self, result[0][0][0], [
         (self.authors[1], None),
         (self.authors[2], None),
         (self.authors[0], None),
     ])
     self.assertEquals(result[1], Author)
Beispiel #48
0
  def test_count_and_filter(self):
    f1 = dict(method='count', field='authors')
    f2 = dict(method='filter', kwargs=dict(authors__count=3))
    entries = traverse(self.blogs, Blog.entry_set, filters=[f1, f2])
    assertQueryResultsEqual(self, entries, [])

    f1 = dict(method='count', field='authors')
    f2 = dict(method='filter', kwargs=dict(authors__count=2))
    entries = traverse(self.blogs, Blog.entry_set, filters=[f1, f2])
    assertQueryResultsEqual(self, entries, [(self.entries[0], self.blogs[0].pk),
                                            (self.entries[1], self.blogs[0].pk),
                                            (self.entries[2], self.blogs[0].pk)])
Beispiel #49
0
 def test_first_set_of_results_are_unique_and_not_separated_by_objects_from_first_relation(
         self):
     qs = 'Blog(name__icontains="Databases") Blog.entry_set Entry.authors'
     query = Query(qs)
     result = query()
     self.assertEquals(result[0][0][1], -1)
     assertQueryResultsEqual(self, result[0][0][0],
                             [(self.authors[0], None),
                              (self.authors[1], None),
                              (self.authors[2], None)])
     self.assertEquals(len(result[0]), 1)
     self.assertEquals(result[1], Author)
Beispiel #50
0
 def test_recursive_traversal_from_same_model(self):
   qs = 'Entry(%s) Entry.responses*' % self.entries[0].id
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0],
                           [(self.entries[0], None),
                            (self.entries[1], None),
                            (self.entries[2], None),
                            (self.entries[3], None),
                           ])
   self.assertEquals(result[1], Entry)
Beispiel #51
0
 def test_recursive_search_with_no_criteria(self):
   qs = 'Blog(%s) Blog.entry_set(headline__icontains="MySQL") Entry.responses*' % self.blog.pk
   query = Query(qs)
   result = query()
   self.assertEquals(result[0][0][1], -1)
   assertQueryResultsEqual(self, result[0][0][0],
                           [(self.entries[0], None),
                            (self.entries[1], None),
                            (self.entries[2], None),
                            (self.entries[3], None),
                           ])
   self.assertEquals(result[1], Entry)
Beispiel #52
0
 def test_recursive_traversal_with_filter_does_not_return_starting_node_if_it_does_not_pass_filter(
         self):
     qs = 'Blog(%s) Blog.entry_set(headline__icontains="MySQL") \
       Entry.responses(headline__icontains="graph")**' % self.blog.pk
     query = Query(qs)
     result = query()
     self.assertEquals(result[0][0][1], -1)
     assertQueryResultsEqual(self, result[0][0][0], [
         (self.entries[2], None),
         (self.entries[3], None),
     ])
     self.assertEquals(result[1], Entry)
Beispiel #53
0
 def test_recursive_traversal_from_same_model(self):
     qs = 'Entry(%s) Entry.responses*' % self.entries[0].id
     query = Query(qs)
     result = query()
     self.assertEquals(result[0][0][1], -1)
     assertQueryResultsEqual(self, result[0][0][0], [
         (self.entries[0], None),
         (self.entries[1], None),
         (self.entries[2], None),
         (self.entries[3], None),
     ])
     self.assertEquals(result[1], Entry)
Beispiel #54
0
 def test_can_traverse_to_fk_objects_and_returns_traversed_pair(self):
     blogs = traverse(self.entries, Entry.blog)
     assertQueryResultsEqual(
         self,
         blogs,
         [
             (self.blogs[0], self.entries[0].pk),
             (self.blogs[0], self.entries[1].pk),
             (self.blogs[0], self.entries[2].pk),
             (self.blogs[1], self.entries[3].pk),
         ],
     )
Beispiel #55
0
 def test_can_traverse_to_fk_objects_with_exclusions(self):
     f = dict(method="exclude", kwargs=dict(name__icontains="graph"))
     blogs = traverse(self.entries, Entry.blog, filters=[f])
     assertQueryResultsEqual(
         self,
         blogs,
         [
             (self.blogs[0], self.entries[0].pk),
             (self.blogs[0], self.entries[1].pk),
             (self.blogs[0], self.entries[2].pk),
         ],
     )
Beispiel #56
0
 def test_can_traverse_from_fk_objects_and_returns_traversed_pair(self):
     entries = traverse(self.blogs, Blog.entry_set)
     assertQueryResultsEqual(
         self,
         entries,
         [
             (self.entries[0], self.blogs[0].pk),
             (self.entries[1], self.blogs[0].pk),
             (self.entries[2], self.blogs[0].pk),
             (self.entries[3], self.blogs[1].pk),
         ],
     )
Beispiel #57
0
 def test_recursive_search_with_no_criteria(self):
     qs = 'Blog(%s) Blog.entry_set(headline__icontains="MySQL") Entry.responses*' % self.blog.pk
     query = Query(qs)
     result = query()
     self.assertEquals(result[0][0][1], -1)
     assertQueryResultsEqual(self, result[0][0][0], [
         (self.entries[0], None),
         (self.entries[1], None),
         (self.entries[2], None),
         (self.entries[3], None),
     ])
     self.assertEquals(result[1], Entry)
    def test_returns_empty_result_for_each_part_of_sub_queries_after_no_match(
            self):
        qs = 'Blog(%s) ?(Blog.entry_set(headline__icontains="Noop")) \
                   Blog.entry_set(headline__icontains="Noop"), Entry.authors' % self.blogs[
            0].pk
        query = Query(qs)
        result = query()
        self.assertEquals(len(result[0]), 4)

        assertQueryResultsEqual(self, result[0][0][0], [(self.blogs[0], None)])
        self.assertEquals(result[0][1], ([(None, self.blogs[0].pk)], 0, None))
        self.assertEquals(result[0][2], ([], 0, None))
        self.assertEquals(result[0][3], ([], 2, None))
    def test_joining_with_or_queries_at_the_end(self):
        qs = 'Blog(%s), ' % self.blogs[0].pk +\
             '(Blog.entry_set(headline__icontains="MySQL")) | (Blog.entry_set(headline__icontains="Postgres"))'
        query = Query(qs)
        result = query()

        self.assertEquals(len(result[0]), 2)

        self.assertEquals(result[0][0][1], -1)
        assertQueryResultsEqual(self, result[0][0][0], [(self.blogs[0], None)])

        self.assertEquals(result[0][1][1], 0)
        assertQueryResultsEqual(self, result[0][1][0],
                                [(self.entries[0], self.blogs[0].pk),
                                 (self.entries[1], self.blogs[0].pk)])

        self.assertEquals(result[1], Entry)