Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #10250 -- Added a regression test to ensure that GROUP BY state…

…ments are correctly quoted under MySQL. This appears to have been corrected inadvertently since the original report, but the extra regression test will make sure it stays that way.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10043 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6d17020c1a1bd94e107defc698adc445084d01d6 1 parent 5eccc59
Russell Keith-Magee authored March 12, 2009
70  tests/modeltests/aggregation/models.py
@@ -7,54 +7,44 @@
7 7
     from django.utils.itercompat import sorted      # For Python 2.3
8 8
 
9 9
 class Author(models.Model):
10  
-   name = models.CharField(max_length=100)
11  
-   age = models.IntegerField()
12  
-   friends = models.ManyToManyField('self', blank=True)
  10
+    name = models.CharField(max_length=100)
  11
+    age = models.IntegerField()
  12
+    friends = models.ManyToManyField('self', blank=True)
13 13
 
14  
-   def __unicode__(self):
15  
-      return self.name
  14
+    def __unicode__(self):
  15
+        return self.name
16 16
 
17 17
 class Publisher(models.Model):
18  
-   name = models.CharField(max_length=300)
19  
-   num_awards = models.IntegerField()
  18
+    name = models.CharField(max_length=300)
  19
+    num_awards = models.IntegerField()
20 20
 
21  
-   def __unicode__(self):
22  
-      return self.name
  21
+    def __unicode__(self):
  22
+        return self.name
23 23
 
24 24
 class Book(models.Model):
25  
-   isbn = models.CharField(max_length=9)
26  
-   name = models.CharField(max_length=300)
27  
-   pages = models.IntegerField()
28  
-   rating = models.FloatField()
29  
-   price = models.DecimalField(decimal_places=2, max_digits=6)
30  
-   authors = models.ManyToManyField(Author)
31  
-   contact = models.ForeignKey(Author, related_name='book_contact_set')
32  
-   publisher = models.ForeignKey(Publisher)
33  
-   pubdate = models.DateField()
34  
-
35  
-   def __unicode__(self):
36  
-      return self.name
  25
+    isbn = models.CharField(max_length=9)
  26
+    name = models.CharField(max_length=300)
  27
+    pages = models.IntegerField()
  28
+    rating = models.FloatField()
  29
+    price = models.DecimalField(decimal_places=2, max_digits=6)
  30
+    authors = models.ManyToManyField(Author)
  31
+    contact = models.ForeignKey(Author, related_name='book_contact_set')
  32
+    publisher = models.ForeignKey(Publisher)
  33
+    pubdate = models.DateField()
  34
+
  35
+    def __unicode__(self):
  36
+        return self.name
37 37
 
38 38
 class Store(models.Model):
39  
-   name = models.CharField(max_length=300)
40  
-   books = models.ManyToManyField(Book)
41  
-   original_opening = models.DateTimeField()
42  
-   friday_night_closing = models.TimeField()
  39
+    name = models.CharField(max_length=300)
  40
+    books = models.ManyToManyField(Book)
  41
+    original_opening = models.DateTimeField()
  42
+    friday_night_closing = models.TimeField()
43 43
 
44  
-   def __unicode__(self):
45  
-      return self.name
  44
+    def __unicode__(self):
  45
+        return self.name
46 46
 
47  
-class Entries(models.Model):
48  
-   EntryID = models.AutoField(primary_key=True, db_column='Entry ID')
49  
-   Entry = models.CharField(unique=True, max_length=50)
50  
-   Exclude = models.BooleanField()
51  
-
52  
-class Clues(models.Model):
53  
-   ID = models.AutoField(primary_key=True)
54  
-   EntryID = models.ForeignKey(Entries, verbose_name='Entry', db_column = 'Entry ID')
55  
-   Clue = models.CharField(max_length=150)
56  
-
57  
-# Tests on 'aggergate'
  47
+# Tests on 'aggregate'
58 48
 # Different backends and numbers.
59 49
 __test__ = {'API_TESTS': """
60 50
 >>> from django.core import management
@@ -351,10 +341,6 @@ class Clues(models.Model):
351 341
 # Cheating: [a for a in Author.objects.all().annotate(num_coleagues=Count('book__authors__id'), num_books=Count('book__id', distinct=True)) if a.num_coleagues - a.num_books > 0]
352 342
 # F-Syntax is required. Will be fixed after F objects are available
353 343
 
354  
-# Tests on fields with non-default table and column names.
355  
->>> Clues.objects.values('EntryID__Entry').annotate(Appearances=Count('EntryID'), Distinct_Clues=Count('Clue', distinct=True))
356  
-[]
357  
-
358 344
 # Aggregates also work on dates, times and datetimes
359 345
 >>> Publisher.objects.annotate(earliest_book=Min('book__pubdate')).exclude(earliest_book=None).order_by('earliest_book').values()
360 346
 [{'earliest_book': datetime.date(1991, 10, 15), 'num_awards': 9, 'id': 4, 'name': u'Morgan Kaufmann'}, {'earliest_book': datetime.date(1995, 1, 15), 'num_awards': 7, 'id': 3, 'name': u'Prentice Hall'}, {'earliest_book': datetime.date(2007, 12, 6), 'num_awards': 3, 'id': 1, 'name': u'Apress'}, {'earliest_book': datetime.date(2008, 3, 3), 'num_awards': 1, 'id': 2, 'name': u'Sams'}]
78  tests/regressiontests/aggregation_regress/models.py
@@ -8,47 +8,56 @@
8 8
     from django.utils.itercompat import sorted      # For Python 2.3
9 9
 
10 10
 class Author(models.Model):
11  
-   name = models.CharField(max_length=100)
12  
-   age = models.IntegerField()
13  
-   friends = models.ManyToManyField('self', blank=True)
  11
+    name = models.CharField(max_length=100)
  12
+    age = models.IntegerField()
  13
+    friends = models.ManyToManyField('self', blank=True)
14 14
 
15  
-   def __unicode__(self):
16  
-      return self.name
  15
+    def __unicode__(self):
  16
+        return self.name
17 17
 
18 18
 class Publisher(models.Model):
19  
-   name = models.CharField(max_length=300)
20  
-   num_awards = models.IntegerField()
  19
+    name = models.CharField(max_length=300)
  20
+    num_awards = models.IntegerField()
21 21
 
22  
-   def __unicode__(self):
23  
-      return self.name
  22
+    def __unicode__(self):
  23
+        return self.name
24 24
 
25 25
 class Book(models.Model):
26  
-   isbn = models.CharField(max_length=9)
27  
-   name = models.CharField(max_length=300)
28  
-   pages = models.IntegerField()
29  
-   rating = models.FloatField()
30  
-   price = models.DecimalField(decimal_places=2, max_digits=6)
31  
-   authors = models.ManyToManyField(Author)
32  
-   contact = models.ForeignKey(Author, related_name='book_contact_set')
33  
-   publisher = models.ForeignKey(Publisher)
34  
-   pubdate = models.DateField()
35  
-
36  
-   class Meta:
37  
-       ordering = ('name',)
38  
-
39  
-   def __unicode__(self):
40  
-      return self.name
  26
+    isbn = models.CharField(max_length=9)
  27
+    name = models.CharField(max_length=300)
  28
+    pages = models.IntegerField()
  29
+    rating = models.FloatField()
  30
+    price = models.DecimalField(decimal_places=2, max_digits=6)
  31
+    authors = models.ManyToManyField(Author)
  32
+    contact = models.ForeignKey(Author, related_name='book_contact_set')
  33
+    publisher = models.ForeignKey(Publisher)
  34
+    pubdate = models.DateField()
  35
+
  36
+    class Meta:
  37
+        ordering = ('name',)
  38
+
  39
+    def __unicode__(self):
  40
+        return self.name
41 41
 
42 42
 class Store(models.Model):
43  
-   name = models.CharField(max_length=300)
44  
-   books = models.ManyToManyField(Book)
45  
-   original_opening = models.DateTimeField()
46  
-   friday_night_closing = models.TimeField()
  43
+    name = models.CharField(max_length=300)
  44
+    books = models.ManyToManyField(Book)
  45
+    original_opening = models.DateTimeField()
  46
+    friday_night_closing = models.TimeField()
47 47
 
48  
-   def __unicode__(self):
49  
-      return self.name
  48
+    def __unicode__(self):
  49
+        return self.name
  50
+
  51
+class Entries(models.Model):
  52
+    EntryID = models.AutoField(primary_key=True, db_column='Entry ID')
  53
+    Entry = models.CharField(unique=True, max_length=50)
  54
+    Exclude = models.BooleanField()
  55
+
  56
+class Clues(models.Model):
  57
+    ID = models.AutoField(primary_key=True)
  58
+    EntryID = models.ForeignKey(Entries, verbose_name='Entry', db_column = 'Entry ID')
  59
+    Clue = models.CharField(max_length=150)
50 60
 
51  
-#Extra does not play well with values. Modify the tests if/when this is fixed.
52 61
 __test__ = {'API_TESTS': """
53 62
 >>> from django.core import management
54 63
 >>> from django.db.models import get_app, F
@@ -188,6 +197,13 @@ def __unicode__(self):
188 197
 >>> Publisher.objects.annotate(num_books=Count('book')).exclude(num_books__lt=F('num_awards')/2).order_by('name').values('name','num_books','num_awards')
189 198
 [{'num_books': 2, 'name': u'Apress', 'num_awards': 3}, {'num_books': 0, 'name': u"Jonno's House of Books", 'num_awards': 0}, {'num_books': 1, 'name': u'Sams', 'num_awards': 1}]
190 199
 
  200
+# Tests on fields with non-default table and column names.
  201
+>>> Clues.objects.values('EntryID__Entry').annotate(Appearances=Count('EntryID'), Distinct_Clues=Count('Clue', distinct=True))
  202
+[]
  203
+
  204
+>>> Entries.objects.annotate(clue_count=Count('clues__ID'))
  205
+[]
  206
+
191 207
 # Regression for #10089: Check handling of empty result sets with aggregates
192 208
 >>> Book.objects.filter(id__in=[]).count()
193 209
 0

0 notes on commit 6d17020

Please sign in to comment.
Something went wrong with that request. Please try again.