mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #18269 -- Applied unicode_literals for Python 3 compatibility.
Thanks Vinay Sajip for the support of his django3 branch and Jannis Leidel for the review.
This commit is contained in:
parent
706fd9adc0
commit
4a103086d5
401 changed files with 6647 additions and 6157 deletions
|
@ -1,4 +1,4 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import datetime
|
||||
import pickle
|
||||
|
@ -119,7 +119,7 @@ class AggregationTests(TestCase):
|
|||
self.assertObjectAttrs(obj,
|
||||
contact_id=3,
|
||||
id=2,
|
||||
isbn=u'067232959',
|
||||
isbn='067232959',
|
||||
mean_auth_age=45.0,
|
||||
name='Sams Teach Yourself Django in 24 Hours',
|
||||
pages=528,
|
||||
|
@ -136,9 +136,9 @@ class AggregationTests(TestCase):
|
|||
self.assertObjectAttrs(obj,
|
||||
contact_id=3,
|
||||
id=2,
|
||||
isbn=u'067232959',
|
||||
isbn='067232959',
|
||||
mean_auth_age=45.0,
|
||||
name=u'Sams Teach Yourself Django in 24 Hours',
|
||||
name='Sams Teach Yourself Django in 24 Hours',
|
||||
pages=528,
|
||||
price=Decimal("23.09"),
|
||||
pubdate=datetime.date(2008, 3, 3),
|
||||
|
@ -156,9 +156,9 @@ class AggregationTests(TestCase):
|
|||
self.assertEqual(obj, {
|
||||
"contact_id": 3,
|
||||
"id": 2,
|
||||
"isbn": u"067232959",
|
||||
"isbn": "067232959",
|
||||
"mean_auth_age": 45.0,
|
||||
"name": u"Sams Teach Yourself Django in 24 Hours",
|
||||
"name": "Sams Teach Yourself Django in 24 Hours",
|
||||
"pages": 528,
|
||||
"price": Decimal("23.09"),
|
||||
"pubdate": datetime.date(2008, 3, 3),
|
||||
|
@ -175,9 +175,9 @@ class AggregationTests(TestCase):
|
|||
self.assertEqual(obj, {
|
||||
'contact_id': 3,
|
||||
'id': 2,
|
||||
'isbn': u'067232959',
|
||||
'isbn': '067232959',
|
||||
'mean_auth_age': 45.0,
|
||||
'name': u'Sams Teach Yourself Django in 24 Hours',
|
||||
'name': 'Sams Teach Yourself Django in 24 Hours',
|
||||
'pages': 528,
|
||||
'price': Decimal("23.09"),
|
||||
'pubdate': datetime.date(2008, 3, 3),
|
||||
|
@ -189,13 +189,13 @@ class AggregationTests(TestCase):
|
|||
# unless it is explicitly named
|
||||
obj = Book.objects.annotate(mean_auth_age=Avg('authors__age')).extra(select={'price_per_page' : 'price / pages'}).values('name').get(pk=1)
|
||||
self.assertEqual(obj, {
|
||||
"name": u'The Definitive Guide to Django: Web Development Done Right',
|
||||
"name": 'The Definitive Guide to Django: Web Development Done Right',
|
||||
})
|
||||
|
||||
obj = Book.objects.annotate(mean_auth_age=Avg('authors__age')).extra(select={'price_per_page' : 'price / pages'}).values('name','mean_auth_age').get(pk=1)
|
||||
self.assertEqual(obj, {
|
||||
'mean_auth_age': 34.5,
|
||||
'name': u'The Definitive Guide to Django: Web Development Done Right',
|
||||
'name': 'The Definitive Guide to Django: Web Development Done Right',
|
||||
})
|
||||
|
||||
# If an annotation isn't included in the values, it can still be used
|
||||
|
@ -203,7 +203,7 @@ class AggregationTests(TestCase):
|
|||
qs = Book.objects.annotate(n_authors=Count('authors')).values('name').filter(n_authors__gt=2)
|
||||
self.assertQuerysetEqual(
|
||||
qs, [
|
||||
{"name": u'Python Web Development with Django'}
|
||||
{"name": 'Python Web Development with Django'}
|
||||
],
|
||||
lambda b: b,
|
||||
)
|
||||
|
@ -213,7 +213,7 @@ class AggregationTests(TestCase):
|
|||
obj = Book.objects.values('name').annotate(mean_auth_age=Avg('authors__age')).extra(select={'price_per_page' : 'price / pages'}).get(pk=1)
|
||||
self.assertEqual(obj, {
|
||||
'mean_auth_age': 34.5,
|
||||
'name': u'The Definitive Guide to Django: Web Development Done Right',
|
||||
'name': 'The Definitive Guide to Django: Web Development Done Right',
|
||||
})
|
||||
|
||||
# Check that all of the objects are getting counted (allow_nulls) and
|
||||
|
@ -298,8 +298,8 @@ class AggregationTests(TestCase):
|
|||
self.assertEqual(obj, {
|
||||
'contact_id': 8,
|
||||
'id': 5,
|
||||
'isbn': u'013790395',
|
||||
'name': u'Artificial Intelligence: A Modern Approach',
|
||||
'isbn': '013790395',
|
||||
'name': 'Artificial Intelligence: A Modern Approach',
|
||||
'num_authors': 2,
|
||||
'pages': 1132,
|
||||
'price': Decimal("82.8"),
|
||||
|
@ -338,8 +338,8 @@ class AggregationTests(TestCase):
|
|||
qs = Publisher.objects.annotate(num_books=Count('book')).filter(num_books__lt=F('num_awards')/2).order_by('name').values('name','num_books','num_awards')
|
||||
self.assertQuerysetEqual(
|
||||
qs, [
|
||||
{'num_books': 1, 'name': u'Morgan Kaufmann', 'num_awards': 9},
|
||||
{'num_books': 2, 'name': u'Prentice Hall', 'num_awards': 7}
|
||||
{'num_books': 1, 'name': 'Morgan Kaufmann', 'num_awards': 9},
|
||||
{'num_books': 2, 'name': 'Prentice Hall', 'num_awards': 7}
|
||||
],
|
||||
lambda p: p,
|
||||
)
|
||||
|
@ -347,9 +347,9 @@ class AggregationTests(TestCase):
|
|||
qs = Publisher.objects.annotate(num_books=Count('book')).exclude(num_books__lt=F('num_awards')/2).order_by('name').values('name','num_books','num_awards')
|
||||
self.assertQuerysetEqual(
|
||||
qs, [
|
||||
{'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}
|
||||
{'num_books': 2, 'name': 'Apress', 'num_awards': 3},
|
||||
{'num_books': 0, 'name': "Jonno's House of Books", 'num_awards': 0},
|
||||
{'num_books': 1, 'name': 'Sams', 'num_awards': 1}
|
||||
],
|
||||
lambda p: p,
|
||||
)
|
||||
|
@ -358,8 +358,8 @@ class AggregationTests(TestCase):
|
|||
qs = Publisher.objects.annotate(num_books=Count('book')).filter(num_awards__gt=2*F('num_books')).order_by('name').values('name','num_books','num_awards')
|
||||
self.assertQuerysetEqual(
|
||||
qs, [
|
||||
{'num_books': 1, 'name': u'Morgan Kaufmann', 'num_awards': 9},
|
||||
{'num_books': 2, 'name': u'Prentice Hall', 'num_awards': 7}
|
||||
{'num_books': 1, 'name': 'Morgan Kaufmann', 'num_awards': 9},
|
||||
{'num_books': 2, 'name': 'Prentice Hall', 'num_awards': 7}
|
||||
],
|
||||
lambda p: p,
|
||||
)
|
||||
|
@ -367,9 +367,9 @@ class AggregationTests(TestCase):
|
|||
qs = Publisher.objects.annotate(num_books=Count('book')).exclude(num_books__lt=F('num_awards')/2).order_by('name').values('name','num_books','num_awards')
|
||||
self.assertQuerysetEqual(
|
||||
qs, [
|
||||
{'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}
|
||||
{'num_books': 2, 'name': 'Apress', 'num_awards': 3},
|
||||
{'num_books': 0, 'name': "Jonno's House of Books", 'num_awards': 0},
|
||||
{'num_books': 1, 'name': 'Sams', 'num_awards': 1}
|
||||
],
|
||||
lambda p: p,
|
||||
)
|
||||
|
@ -399,7 +399,7 @@ class AggregationTests(TestCase):
|
|||
qs = Publisher.objects.filter(pk=5).annotate(num_authors=Count('book__authors'), avg_authors=Avg('book__authors'), max_authors=Max('book__authors'), max_price=Max('book__price'), max_rating=Max('book__rating')).values()
|
||||
self.assertQuerysetEqual(
|
||||
qs, [
|
||||
{'max_authors': None, 'name': u"Jonno's House of Books", 'num_awards': 0, 'max_price': None, 'num_authors': 0, 'max_rating': None, 'id': 5, 'avg_authors': None}
|
||||
{'max_authors': None, 'name': "Jonno's House of Books", 'num_awards': 0, 'max_price': None, 'num_authors': 0, 'max_rating': None, 'id': 5, 'avg_authors': None}
|
||||
],
|
||||
lambda p: p
|
||||
)
|
||||
|
@ -424,10 +424,10 @@ class AggregationTests(TestCase):
|
|||
qs = Book.objects.filter(rating__lt=4.5).select_related().annotate(Avg('authors__age'))
|
||||
self.assertQuerysetEqual(
|
||||
qs, [
|
||||
(u'Artificial Intelligence: A Modern Approach', 51.5, u'Prentice Hall', u'Peter Norvig'),
|
||||
(u'Practical Django Projects', 29.0, u'Apress', u'James Bennett'),
|
||||
(u'Python Web Development with Django', Approximate(30.333, places=2), u'Prentice Hall', u'Jeffrey Forcier'),
|
||||
(u'Sams Teach Yourself Django in 24 Hours', 45.0, u'Sams', u'Brad Dayley')
|
||||
('Artificial Intelligence: A Modern Approach', 51.5, 'Prentice Hall', 'Peter Norvig'),
|
||||
('Practical Django Projects', 29.0, 'Apress', 'James Bennett'),
|
||||
('Python Web Development with Django', Approximate(30.333, places=2), 'Prentice Hall', 'Jeffrey Forcier'),
|
||||
('Sams Teach Yourself Django in 24 Hours', 45.0, 'Sams', 'Brad Dayley')
|
||||
],
|
||||
lambda b: (b.name, b.authors__age__avg, b.publisher.name, b.contact.name)
|
||||
)
|
||||
|
@ -491,19 +491,19 @@ class AggregationTests(TestCase):
|
|||
# But age isn't included in the ValuesQuerySet, so it is.
|
||||
results = Author.objects.values('name').annotate(age=Count('book_contact_set')).order_by('name')
|
||||
self.assertEqual(len(results), 9)
|
||||
self.assertEqual(results[0]['name'], u'Adrian Holovaty')
|
||||
self.assertEqual(results[0]['name'], 'Adrian Holovaty')
|
||||
self.assertEqual(results[0]['age'], 1)
|
||||
|
||||
# Same problem, but aggregating over m2m fields
|
||||
results = Author.objects.values('name').annotate(age=Avg('friends__age')).order_by('name')
|
||||
self.assertEqual(len(results), 9)
|
||||
self.assertEqual(results[0]['name'], u'Adrian Holovaty')
|
||||
self.assertEqual(results[0]['name'], 'Adrian Holovaty')
|
||||
self.assertEqual(results[0]['age'], 32.0)
|
||||
|
||||
# Same problem, but colliding with an m2m field
|
||||
results = Author.objects.values('name').annotate(friends=Count('friends')).order_by('name')
|
||||
self.assertEqual(len(results), 9)
|
||||
self.assertEqual(results[0]['name'], u'Adrian Holovaty')
|
||||
self.assertEqual(results[0]['name'], 'Adrian Holovaty')
|
||||
self.assertEqual(results[0]['friends'], 2)
|
||||
|
||||
def test_reverse_relation_name_conflict(self):
|
||||
|
@ -531,12 +531,12 @@ class AggregationTests(TestCase):
|
|||
books.aggregate(Avg("authors__age"))
|
||||
self.assertQuerysetEqual(
|
||||
books.all(), [
|
||||
u'Artificial Intelligence: A Modern Approach',
|
||||
u'Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp',
|
||||
u'Practical Django Projects',
|
||||
u'Python Web Development with Django',
|
||||
u'Sams Teach Yourself Django in 24 Hours',
|
||||
u'The Definitive Guide to Django: Web Development Done Right'
|
||||
'Artificial Intelligence: A Modern Approach',
|
||||
'Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp',
|
||||
'Practical Django Projects',
|
||||
'Python Web Development with Django',
|
||||
'Sams Teach Yourself Django in 24 Hours',
|
||||
'The Definitive Guide to Django: Web Development Done Right'
|
||||
],
|
||||
lambda b: b.name
|
||||
)
|
||||
|
@ -632,8 +632,8 @@ class AggregationTests(TestCase):
|
|||
qs = HardbackBook.objects.annotate(n_authors=Count('book_ptr__authors')).values('name', 'n_authors')
|
||||
self.assertQuerysetEqual(
|
||||
qs, [
|
||||
{'n_authors': 2, 'name': u'Artificial Intelligence: A Modern Approach'},
|
||||
{'n_authors': 1, 'name': u'Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp'}
|
||||
{'n_authors': 2, 'name': 'Artificial Intelligence: A Modern Approach'},
|
||||
{'n_authors': 1, 'name': 'Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp'}
|
||||
],
|
||||
lambda h: h
|
||||
)
|
||||
|
@ -641,8 +641,8 @@ class AggregationTests(TestCase):
|
|||
qs = HardbackBook.objects.annotate(n_authors=Count('authors')).values('name', 'n_authors')
|
||||
self.assertQuerysetEqual(
|
||||
qs, [
|
||||
{'n_authors': 2, 'name': u'Artificial Intelligence: A Modern Approach'},
|
||||
{'n_authors': 1, 'name': u'Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp'}
|
||||
{'n_authors': 2, 'name': 'Artificial Intelligence: A Modern Approach'},
|
||||
{'n_authors': 1, 'name': 'Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp'}
|
||||
],
|
||||
lambda h: h,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue