Permalink
Browse files

Comment tests for non-supported features.

Currently it's not possible to use joins and expressions 
inside the only clause.
  • Loading branch information...
1 parent 440b150 commit 9620b58342a2526b52e6ba57e661942cfdff595c @henriquebastos committed Dec 26, 2012
Showing with 34 additions and 0 deletions.
  1. +34 −0 tests/aggregation/tests.py
View
@@ -118,6 +118,40 @@ def test_annotate_basic(self):
)
self.assertEqual(b.mean_age, 34.5)
+ '''
+ def test_f_expression(self):
+ publishers = Publisher.objects.annotate(avg_rating=Avg(F('book__rating') - 0))
+ publishers = publishers.values_list('id', 'avg_rating').order_by('id')
+ self.assertEqual(list(publishers), [(1, 4.25), (2, 3.0), (3, 4.0), (4, 5.0), (5, None)])
+
+ def test_only_condition_with_join(self):
+ # Test extra-select
+ books = Book.objects.annotate(mean_age=Avg("authors__age"))
+ books = books.annotate(mean_age2=Avg('authors__age', only=Q(authors__age__gte=0)))
+ books = books.extra(select={'testparams': 'publisher_id = %s'}, select_params=[1])
+ b = books.get(pk=1)
+ self.assertEqual(b.mean_age, 34.5)
+ self.assertEqual(b.mean_age2, 34.5)
+ self.assertEqual(b.testparams, True)
+
+ def test_relabel_aliases(self):
+ # Test relabel_aliases
+ excluded_authors = Author.objects.annotate(book_rating=Min(F('book__rating') + 5, only=Q(pk__gte=1)))
+ excluded_authors = excluded_authors.filter(book_rating__lt=0)
+ books = books.exclude(authors__in=excluded_authors)
+ b = books.get(pk=1)
+ self.assertEqual(b.mean_age, 34.5)
+
+ def test_joins_in_f(self):
+ # Test joins in F-based annotation
+ books = Book.objects.annotate(oldest=Max(F('authors__age')))
+ books = books.values_list('rating', 'oldest').order_by('rating', 'oldest')
+ self.assertEqual(
+ list(books),
+ [(3.0, 45), (4.0, 29), (4.0, 37), (4.0, 57), (4.5, 35), (5.0, 57)]
+ )
+ '''
+
def test_annotate_m2m(self):
books = Book.objects.filter(rating__lt=4.5).annotate(Avg("authors__age")).order_by("name")
self.assertQuerysetEqual(

0 comments on commit 9620b58

Please sign in to comment.