Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 freakboy3742 authored
70 tests/modeltests/aggregation/models.py
View
@@ -7,54 +7,44 @@
from django.utils.itercompat import sorted # For Python 2.3
class Author(models.Model):
- name = models.CharField(max_length=100)
- age = models.IntegerField()
- friends = models.ManyToManyField('self', blank=True)
+ name = models.CharField(max_length=100)
+ age = models.IntegerField()
+ friends = models.ManyToManyField('self', blank=True)
- def __unicode__(self):
- return self.name
+ def __unicode__(self):
+ return self.name
class Publisher(models.Model):
- name = models.CharField(max_length=300)
- num_awards = models.IntegerField()
+ name = models.CharField(max_length=300)
+ num_awards = models.IntegerField()
- def __unicode__(self):
- return self.name
+ def __unicode__(self):
+ return self.name
class Book(models.Model):
- isbn = models.CharField(max_length=9)
- name = models.CharField(max_length=300)
- pages = models.IntegerField()
- rating = models.FloatField()
- price = models.DecimalField(decimal_places=2, max_digits=6)
- authors = models.ManyToManyField(Author)
- contact = models.ForeignKey(Author, related_name='book_contact_set')
- publisher = models.ForeignKey(Publisher)
- pubdate = models.DateField()
-
- def __unicode__(self):
- return self.name
+ isbn = models.CharField(max_length=9)
+ name = models.CharField(max_length=300)
+ pages = models.IntegerField()
+ rating = models.FloatField()
+ price = models.DecimalField(decimal_places=2, max_digits=6)
+ authors = models.ManyToManyField(Author)
+ contact = models.ForeignKey(Author, related_name='book_contact_set')
+ publisher = models.ForeignKey(Publisher)
+ pubdate = models.DateField()
+
+ def __unicode__(self):
+ return self.name
class Store(models.Model):
- name = models.CharField(max_length=300)
- books = models.ManyToManyField(Book)
- original_opening = models.DateTimeField()
- friday_night_closing = models.TimeField()
+ name = models.CharField(max_length=300)
+ books = models.ManyToManyField(Book)
+ original_opening = models.DateTimeField()
+ friday_night_closing = models.TimeField()
- def __unicode__(self):
- return self.name
+ def __unicode__(self):
+ return self.name
-class Entries(models.Model):
- EntryID = models.AutoField(primary_key=True, db_column='Entry ID')
- Entry = models.CharField(unique=True, max_length=50)
- Exclude = models.BooleanField()
-
-class Clues(models.Model):
- ID = models.AutoField(primary_key=True)
- EntryID = models.ForeignKey(Entries, verbose_name='Entry', db_column = 'Entry ID')
- Clue = models.CharField(max_length=150)
-
-# Tests on 'aggergate'
+# Tests on 'aggregate'
# Different backends and numbers.
__test__ = {'API_TESTS': """
>>> from django.core import management
@@ -351,10 +341,6 @@ class Clues(models.Model):
# 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]
# F-Syntax is required. Will be fixed after F objects are available
-# Tests on fields with non-default table and column names.
->>> Clues.objects.values('EntryID__Entry').annotate(Appearances=Count('EntryID'), Distinct_Clues=Count('Clue', distinct=True))
-[]
-
# Aggregates also work on dates, times and datetimes
>>> Publisher.objects.annotate(earliest_book=Min('book__pubdate')).exclude(earliest_book=None).order_by('earliest_book').values()
[{'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
View
@@ -8,47 +8,56 @@
from django.utils.itercompat import sorted # For Python 2.3
class Author(models.Model):
- name = models.CharField(max_length=100)
- age = models.IntegerField()
- friends = models.ManyToManyField('self', blank=True)
+ name = models.CharField(max_length=100)
+ age = models.IntegerField()
+ friends = models.ManyToManyField('self', blank=True)
- def __unicode__(self):
- return self.name
+ def __unicode__(self):
+ return self.name
class Publisher(models.Model):
- name = models.CharField(max_length=300)
- num_awards = models.IntegerField()
+ name = models.CharField(max_length=300)
+ num_awards = models.IntegerField()
- def __unicode__(self):
- return self.name
+ def __unicode__(self):
+ return self.name
class Book(models.Model):
- isbn = models.CharField(max_length=9)
- name = models.CharField(max_length=300)
- pages = models.IntegerField()
- rating = models.FloatField()
- price = models.DecimalField(decimal_places=2, max_digits=6)
- authors = models.ManyToManyField(Author)
- contact = models.ForeignKey(Author, related_name='book_contact_set')
- publisher = models.ForeignKey(Publisher)
- pubdate = models.DateField()
-
- class Meta:
- ordering = ('name',)
-
- def __unicode__(self):
- return self.name
+ isbn = models.CharField(max_length=9)
+ name = models.CharField(max_length=300)
+ pages = models.IntegerField()
+ rating = models.FloatField()
+ price = models.DecimalField(decimal_places=2, max_digits=6)
+ authors = models.ManyToManyField(Author)
+ contact = models.ForeignKey(Author, related_name='book_contact_set')
+ publisher = models.ForeignKey(Publisher)
+ pubdate = models.DateField()
+
+ class Meta:
+ ordering = ('name',)
+
+ def __unicode__(self):
+ return self.name
class Store(models.Model):
- name = models.CharField(max_length=300)
- books = models.ManyToManyField(Book)
- original_opening = models.DateTimeField()
- friday_night_closing = models.TimeField()
+ name = models.CharField(max_length=300)
+ books = models.ManyToManyField(Book)
+ original_opening = models.DateTimeField()
+ friday_night_closing = models.TimeField()
- def __unicode__(self):
- return self.name
+ def __unicode__(self):
+ return self.name
+
+class Entries(models.Model):
+ EntryID = models.AutoField(primary_key=True, db_column='Entry ID')
+ Entry = models.CharField(unique=True, max_length=50)
+ Exclude = models.BooleanField()
+
+class Clues(models.Model):
+ ID = models.AutoField(primary_key=True)
+ EntryID = models.ForeignKey(Entries, verbose_name='Entry', db_column = 'Entry ID')
+ Clue = models.CharField(max_length=150)
-#Extra does not play well with values. Modify the tests if/when this is fixed.
__test__ = {'API_TESTS': """
>>> from django.core import management
>>> from django.db.models import get_app, F
@@ -188,6 +197,13 @@ def __unicode__(self):
>>> Publisher.objects.annotate(num_books=Count('book')).exclude(num_books__lt=F('num_awards')/2).order_by('name').values('name','num_books','num_awards')
[{'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}]
+# Tests on fields with non-default table and column names.
+>>> Clues.objects.values('EntryID__Entry').annotate(Appearances=Count('EntryID'), Distinct_Clues=Count('Clue', distinct=True))
+[]
+
+>>> Entries.objects.annotate(clue_count=Count('clues__ID'))
+[]
+
# Regression for #10089: Check handling of empty result sets with aggregates
>>> Book.objects.filter(id__in=[]).count()
0
Please sign in to comment.
Something went wrong with that request. Please try again.