Fixed #27203 -- Replaced assertQuerysetEqual(..., lambda o: o) with assertSequenceEqual().
This commit is contained in:
parent
8b050cf9dc
commit
0c1f71635f
|
@ -295,11 +295,10 @@ class AggregationTests(TestCase):
|
|||
# If an annotation isn't included in the values, it can still be used
|
||||
# in a filter
|
||||
qs = Book.objects.annotate(n_authors=Count('authors')).values('name').filter(n_authors__gt=2)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
qs, [
|
||||
{"name": 'Python Web Development with Django'}
|
||||
],
|
||||
lambda b: b,
|
||||
)
|
||||
|
||||
# The annotations are added to values output if values() precedes
|
||||
|
@ -326,7 +325,7 @@ class AggregationTests(TestCase):
|
|||
.order_by('oldest', 'price')
|
||||
.annotate(Max('publisher__num_awards'))
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
qs, [
|
||||
{'price': Decimal("30"), 'oldest': 35, 'publisher__num_awards__max': 3},
|
||||
{'price': Decimal("29.69"), 'oldest': 37, 'publisher__num_awards__max': 7},
|
||||
|
@ -334,7 +333,6 @@ class AggregationTests(TestCase):
|
|||
{'price': Decimal("75"), 'oldest': 57, 'publisher__num_awards__max': 9},
|
||||
{'price': Decimal("82.8"), 'oldest': 57, 'publisher__num_awards__max': 7}
|
||||
],
|
||||
lambda b: b,
|
||||
)
|
||||
|
||||
def test_aggrate_annotation(self):
|
||||
|
@ -474,12 +472,11 @@ class AggregationTests(TestCase):
|
|||
.order_by('name')
|
||||
.values('name', 'num_books', 'num_awards')
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
qs, [
|
||||
{'num_books': 1, 'name': 'Morgan Kaufmann', 'num_awards': 9},
|
||||
{'num_books': 2, 'name': 'Prentice Hall', 'num_awards': 7}
|
||||
],
|
||||
lambda p: p,
|
||||
)
|
||||
|
||||
qs = (
|
||||
|
@ -489,13 +486,12 @@ class AggregationTests(TestCase):
|
|||
.order_by('name')
|
||||
.values('name', 'num_books', 'num_awards')
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
qs, [
|
||||
{'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,
|
||||
)
|
||||
|
||||
# ... and where the F() references an aggregate
|
||||
|
@ -506,12 +502,11 @@ class AggregationTests(TestCase):
|
|||
.order_by('name')
|
||||
.values('name', 'num_books', 'num_awards')
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
qs, [
|
||||
{'num_books': 1, 'name': 'Morgan Kaufmann', 'num_awards': 9},
|
||||
{'num_books': 2, 'name': 'Prentice Hall', 'num_awards': 7}
|
||||
],
|
||||
lambda p: p,
|
||||
)
|
||||
|
||||
qs = (
|
||||
|
@ -521,13 +516,12 @@ class AggregationTests(TestCase):
|
|||
.order_by('name')
|
||||
.values('name', 'num_books', 'num_awards')
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
qs, [
|
||||
{'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,
|
||||
)
|
||||
|
||||
def test_db_col_table(self):
|
||||
|
@ -548,8 +542,7 @@ class AggregationTests(TestCase):
|
|||
e = Entries.objects.create(Entry='foo')
|
||||
c = Clues.objects.create(EntryID=e, Clue='bar')
|
||||
qs = Clues.objects.select_related('EntryID').annotate(Count('ID'))
|
||||
self.assertQuerysetEqual(
|
||||
qs, [c], lambda x: x)
|
||||
self.assertSequenceEqual(qs, [c])
|
||||
self.assertEqual(qs[0].EntryID, e)
|
||||
self.assertIs(qs[0].EntryID.Exclude, False)
|
||||
|
||||
|
@ -588,7 +581,7 @@ class AggregationTests(TestCase):
|
|||
max_rating=Max('book__rating'),
|
||||
).values()
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
qs,
|
||||
[{
|
||||
'max_authors': None,
|
||||
|
@ -600,7 +593,6 @@ class AggregationTests(TestCase):
|
|||
'id': self.p5.id,
|
||||
'avg_authors': None,
|
||||
}],
|
||||
lambda p: p
|
||||
)
|
||||
|
||||
def test_more_more(self):
|
||||
|
@ -640,14 +632,13 @@ class AggregationTests(TestCase):
|
|||
# Regression for #10132 - If the values() clause only mentioned extra
|
||||
# (select=) columns, those columns are used for grouping
|
||||
qs = Book.objects.extra(select={'pub': 'publisher_id'}).values('pub').annotate(Count('id')).order_by('pub')
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
qs, [
|
||||
{'pub': self.b1.id, 'id__count': 2},
|
||||
{'pub': self.b2.id, 'id__count': 1},
|
||||
{'pub': self.b3.id, 'id__count': 2},
|
||||
{'pub': self.b4.id, 'id__count': 1}
|
||||
],
|
||||
lambda b: b
|
||||
)
|
||||
|
||||
qs = (
|
||||
|
@ -657,14 +648,13 @@ class AggregationTests(TestCase):
|
|||
.annotate(Count('id'))
|
||||
.order_by('pub')
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
qs, [
|
||||
{'pub': self.p1.id, 'id__count': 2},
|
||||
{'pub': self.p2.id, 'id__count': 1},
|
||||
{'pub': self.p3.id, 'id__count': 2},
|
||||
{'pub': self.p4.id, 'id__count': 1}
|
||||
],
|
||||
lambda b: b
|
||||
)
|
||||
|
||||
# Regression for #10182 - Queries with aggregate calls are correctly
|
||||
|
@ -768,12 +758,11 @@ class AggregationTests(TestCase):
|
|||
|
||||
# Regression for #10248 - Annotations work with dates()
|
||||
qs = Book.objects.annotate(num_authors=Count('authors')).filter(num_authors=2).dates('pubdate', 'day')
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
qs, [
|
||||
datetime.date(1995, 1, 15),
|
||||
datetime.date(2007, 12, 6),
|
||||
],
|
||||
lambda b: b
|
||||
)
|
||||
|
||||
# Regression for #10290 - extra selects with parameters can be used for
|
||||
|
@ -867,7 +856,7 @@ class AggregationTests(TestCase):
|
|||
)
|
||||
|
||||
qs = HardbackBook.objects.annotate(n_authors=Count('book_ptr__authors')).values('name', 'n_authors')
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
qs,
|
||||
[
|
||||
{'n_authors': 2, 'name': 'Artificial Intelligence: A Modern Approach'},
|
||||
|
@ -876,11 +865,10 @@ class AggregationTests(TestCase):
|
|||
'name': 'Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp'
|
||||
}
|
||||
],
|
||||
lambda h: h
|
||||
)
|
||||
|
||||
qs = HardbackBook.objects.annotate(n_authors=Count('authors')).values('name', 'n_authors')
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
qs,
|
||||
[
|
||||
{'n_authors': 2, 'name': 'Artificial Intelligence: A Modern Approach'},
|
||||
|
@ -889,7 +877,6 @@ class AggregationTests(TestCase):
|
|||
'name': 'Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp'
|
||||
}
|
||||
],
|
||||
lambda h: h,
|
||||
)
|
||||
|
||||
# Regression for #10766 - Shouldn't be able to reference an aggregate
|
||||
|
@ -1391,16 +1378,14 @@ class JoinPromotionTests(TestCase):
|
|||
b = Bravo.objects.create()
|
||||
c = Charlie.objects.create(bravo=b)
|
||||
qs = Charlie.objects.select_related('alfa').annotate(Count('bravo__charlie'))
|
||||
self.assertQuerysetEqual(
|
||||
qs, [c], lambda x: x)
|
||||
self.assertSequenceEqual(qs, [c])
|
||||
self.assertIs(qs[0].alfa, None)
|
||||
a = Alfa.objects.create()
|
||||
c.alfa = a
|
||||
c.save()
|
||||
# Force re-evaluation
|
||||
qs = qs.all()
|
||||
self.assertQuerysetEqual(
|
||||
qs, [c], lambda x: x)
|
||||
self.assertSequenceEqual(qs, [c])
|
||||
self.assertEqual(qs[0].alfa, a)
|
||||
|
||||
def test_existing_join_not_promoted(self):
|
||||
|
|
|
@ -234,8 +234,8 @@ class LookupTests(TestCase):
|
|||
YearTransform.register_lookup(Exactly, custom_lookup_name)
|
||||
qs1 = Author.objects.filter(birthdate__testyear__exactly=1981)
|
||||
qs2 = Author.objects.filter(birthdate__justtheyear__isactually=1981)
|
||||
self.assertQuerysetEqual(qs1, [a1], lambda x: x)
|
||||
self.assertQuerysetEqual(qs2, [a1], lambda x: x)
|
||||
self.assertSequenceEqual(qs1, [a1])
|
||||
self.assertSequenceEqual(qs2, [a1])
|
||||
finally:
|
||||
YearTransform._unregister_lookup(Exactly)
|
||||
YearTransform._unregister_lookup(Exactly, custom_lookup_name)
|
||||
|
@ -248,22 +248,10 @@ class LookupTests(TestCase):
|
|||
a3 = Author.objects.create(name='a3', age=3)
|
||||
a4 = Author.objects.create(name='a4', age=4)
|
||||
with register_lookup(models.IntegerField, Div3Lookup):
|
||||
self.assertQuerysetEqual(
|
||||
Author.objects.filter(age__div3=0),
|
||||
[a3], lambda x: x
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
Author.objects.filter(age__div3=1).order_by('age'),
|
||||
[a1, a4], lambda x: x
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
Author.objects.filter(age__div3=2),
|
||||
[a2], lambda x: x
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
Author.objects.filter(age__div3=3),
|
||||
[], lambda x: x
|
||||
)
|
||||
self.assertSequenceEqual(Author.objects.filter(age__div3=0), [a3])
|
||||
self.assertSequenceEqual(Author.objects.filter(age__div3=1).order_by('age'), [a1, a4])
|
||||
self.assertSequenceEqual(Author.objects.filter(age__div3=2), [a2])
|
||||
self.assertSequenceEqual(Author.objects.filter(age__div3=3), [])
|
||||
|
||||
@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific SQL used")
|
||||
def test_birthdate_month(self):
|
||||
|
@ -272,26 +260,11 @@ class LookupTests(TestCase):
|
|||
a3 = Author.objects.create(name='a3', birthdate=date(2012, 1, 31))
|
||||
a4 = Author.objects.create(name='a4', birthdate=date(2012, 3, 1))
|
||||
with register_lookup(models.DateField, InMonth):
|
||||
self.assertQuerysetEqual(
|
||||
Author.objects.filter(birthdate__inmonth=date(2012, 1, 15)),
|
||||
[a3], lambda x: x
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
Author.objects.filter(birthdate__inmonth=date(2012, 2, 1)),
|
||||
[a2], lambda x: x
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
Author.objects.filter(birthdate__inmonth=date(1981, 2, 28)),
|
||||
[a1], lambda x: x
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
Author.objects.filter(birthdate__inmonth=date(2012, 3, 12)),
|
||||
[a4], lambda x: x
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
Author.objects.filter(birthdate__inmonth=date(2012, 4, 1)),
|
||||
[], lambda x: x
|
||||
)
|
||||
self.assertSequenceEqual(Author.objects.filter(birthdate__inmonth=date(2012, 1, 15)), [a3])
|
||||
self.assertSequenceEqual(Author.objects.filter(birthdate__inmonth=date(2012, 2, 1)), [a2])
|
||||
self.assertSequenceEqual(Author.objects.filter(birthdate__inmonth=date(1981, 2, 28)), [a1])
|
||||
self.assertSequenceEqual(Author.objects.filter(birthdate__inmonth=date(2012, 3, 12)), [a4])
|
||||
self.assertSequenceEqual(Author.objects.filter(birthdate__inmonth=date(2012, 4, 1)), [])
|
||||
|
||||
def test_div3_extract(self):
|
||||
with register_lookup(models.IntegerField, Div3Transform):
|
||||
|
@ -300,24 +273,12 @@ class LookupTests(TestCase):
|
|||
a3 = Author.objects.create(name='a3', age=3)
|
||||
a4 = Author.objects.create(name='a4', age=4)
|
||||
baseqs = Author.objects.order_by('name')
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(age__div3=2),
|
||||
[a2], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(age__div3__lte=3),
|
||||
[a1, a2, a3, a4], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(age__div3__in=[0, 2]),
|
||||
[a2, a3], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(age__div3__in=[2, 4]),
|
||||
[a2], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(age__div3__gte=3),
|
||||
[], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(age__div3__range=(1, 2)),
|
||||
[a1, a2, a4], lambda x: x)
|
||||
self.assertSequenceEqual(baseqs.filter(age__div3=2), [a2])
|
||||
self.assertSequenceEqual(baseqs.filter(age__div3__lte=3), [a1, a2, a3, a4])
|
||||
self.assertSequenceEqual(baseqs.filter(age__div3__in=[0, 2]), [a2, a3])
|
||||
self.assertSequenceEqual(baseqs.filter(age__div3__in=[2, 4]), [a2])
|
||||
self.assertSequenceEqual(baseqs.filter(age__div3__gte=3), [])
|
||||
self.assertSequenceEqual(baseqs.filter(age__div3__range=(1, 2)), [a1, a2, a4])
|
||||
|
||||
def test_foreignobject_lookup_registration(self):
|
||||
field = Article._meta.get_field('author')
|
||||
|
@ -383,24 +344,12 @@ class BilateralTransformTests(TestCase):
|
|||
a3 = Author.objects.create(name='a3', age=3)
|
||||
a4 = Author.objects.create(name='a4', age=4)
|
||||
baseqs = Author.objects.order_by('name')
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(age__div3=2),
|
||||
[a2], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(age__div3__lte=3),
|
||||
[a3], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(age__div3__in=[0, 2]),
|
||||
[a2, a3], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(age__div3__in=[2, 4]),
|
||||
[a1, a2, a4], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(age__div3__gte=3),
|
||||
[a1, a2, a3, a4], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(age__div3__range=(1, 2)),
|
||||
[a1, a2, a4], lambda x: x)
|
||||
self.assertSequenceEqual(baseqs.filter(age__div3=2), [a2])
|
||||
self.assertSequenceEqual(baseqs.filter(age__div3__lte=3), [a3])
|
||||
self.assertSequenceEqual(baseqs.filter(age__div3__in=[0, 2]), [a2, a3])
|
||||
self.assertSequenceEqual(baseqs.filter(age__div3__in=[2, 4]), [a1, a2, a4])
|
||||
self.assertSequenceEqual(baseqs.filter(age__div3__gte=3), [a1, a2, a3, a4])
|
||||
self.assertSequenceEqual(baseqs.filter(age__div3__range=(1, 2)), [a1, a2, a4])
|
||||
|
||||
def test_bilateral_order(self):
|
||||
with register_lookup(models.IntegerField, Mult3BilateralTransform, Div3BilateralTransform):
|
||||
|
@ -410,13 +359,9 @@ class BilateralTransformTests(TestCase):
|
|||
a4 = Author.objects.create(name='a4', age=4)
|
||||
baseqs = Author.objects.order_by('name')
|
||||
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(age__mult3__div3=42),
|
||||
# mult3__div3 always leads to 0
|
||||
[a1, a2, a3, a4], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(age__div3__mult3=42),
|
||||
[a3], lambda x: x)
|
||||
# mult3__div3 always leads to 0
|
||||
self.assertSequenceEqual(baseqs.filter(age__mult3__div3=42), [a1, a2, a3, a4])
|
||||
self.assertSequenceEqual(baseqs.filter(age__div3__mult3=42), [a3])
|
||||
|
||||
def test_bilateral_fexpr(self):
|
||||
with register_lookup(models.IntegerField, Mult3BilateralTransform):
|
||||
|
@ -425,13 +370,9 @@ class BilateralTransformTests(TestCase):
|
|||
a3 = Author.objects.create(name='a3', age=3, average_rating=1.5)
|
||||
a4 = Author.objects.create(name='a4', age=4)
|
||||
baseqs = Author.objects.order_by('name')
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(age__mult3=models.F('age')),
|
||||
[a1, a2, a3, a4], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
# Same as age >= average_rating
|
||||
baseqs.filter(age__mult3__gte=models.F('average_rating')),
|
||||
[a2, a3], lambda x: x)
|
||||
self.assertSequenceEqual(baseqs.filter(age__mult3=models.F('age')), [a1, a2, a3, a4])
|
||||
# Same as age >= average_rating
|
||||
self.assertSequenceEqual(baseqs.filter(age__mult3__gte=models.F('average_rating')), [a2, a3])
|
||||
|
||||
|
||||
@override_settings(USE_TZ=True)
|
||||
|
@ -441,9 +382,7 @@ class DateTimeLookupTests(TestCase):
|
|||
with register_lookup(models.PositiveIntegerField, DateTimeTransform):
|
||||
ut = MySQLUnixTimestamp.objects.create(timestamp=time.time())
|
||||
y2k = timezone.make_aware(datetime(2000, 1, 1))
|
||||
self.assertQuerysetEqual(
|
||||
MySQLUnixTimestamp.objects.filter(timestamp__as_datetime__gt=y2k),
|
||||
[ut], lambda x: x)
|
||||
self.assertSequenceEqual(MySQLUnixTimestamp.objects.filter(timestamp__as_datetime__gt=y2k), [ut])
|
||||
|
||||
|
||||
class YearLteTests(TestCase):
|
||||
|
@ -460,21 +399,13 @@ class YearLteTests(TestCase):
|
|||
@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific SQL used")
|
||||
def test_year_lte(self):
|
||||
baseqs = Author.objects.order_by('name')
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(birthdate__testyear__lte=2012),
|
||||
[self.a1, self.a2, self.a3, self.a4], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(birthdate__testyear=2012),
|
||||
[self.a2, self.a3, self.a4], lambda x: x)
|
||||
self.assertSequenceEqual(baseqs.filter(birthdate__testyear__lte=2012), [self.a1, self.a2, self.a3, self.a4])
|
||||
self.assertSequenceEqual(baseqs.filter(birthdate__testyear=2012), [self.a2, self.a3, self.a4])
|
||||
|
||||
self.assertNotIn('BETWEEN', str(baseqs.filter(birthdate__testyear=2012).query))
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(birthdate__testyear__lte=2011),
|
||||
[self.a1], lambda x: x)
|
||||
self.assertSequenceEqual(baseqs.filter(birthdate__testyear__lte=2011), [self.a1])
|
||||
# The non-optimized version works, too.
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(birthdate__testyear__lt=2012),
|
||||
[self.a1], lambda x: x)
|
||||
self.assertSequenceEqual(baseqs.filter(birthdate__testyear__lt=2012), [self.a1])
|
||||
|
||||
@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific SQL used")
|
||||
def test_year_lte_fexpr(self):
|
||||
|
@ -485,12 +416,8 @@ class YearLteTests(TestCase):
|
|||
self.a4.age = 2013
|
||||
self.a4.save()
|
||||
baseqs = Author.objects.order_by('name')
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(birthdate__testyear__lte=models.F('age')),
|
||||
[self.a3, self.a4], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
baseqs.filter(birthdate__testyear__lt=models.F('age')),
|
||||
[self.a4], lambda x: x)
|
||||
self.assertSequenceEqual(baseqs.filter(birthdate__testyear__lte=models.F('age')), [self.a3, self.a4])
|
||||
self.assertSequenceEqual(baseqs.filter(birthdate__testyear__lt=models.F('age')), [self.a4])
|
||||
|
||||
def test_year_lte_sql(self):
|
||||
# This test will just check the generated SQL for __lte. This
|
||||
|
@ -624,6 +551,5 @@ class SubqueryTransformTests(TestCase):
|
|||
a2 = Author.objects.create(name='a2', age=2)
|
||||
Author.objects.create(name='a3', age=3)
|
||||
Author.objects.create(name='a4', age=4)
|
||||
self.assertQuerysetEqual(
|
||||
Author.objects.order_by('name').filter(id__in=Author.objects.filter(age__div3=2)),
|
||||
[a2], lambda x: x)
|
||||
qs = Author.objects.order_by('name').filter(id__in=Author.objects.filter(age__div3=2))
|
||||
self.assertSequenceEqual(qs, [a2])
|
||||
|
|
|
@ -46,44 +46,39 @@ class DatesTests(TestCase):
|
|||
c = Category.objects.create(name="serious-news")
|
||||
c.articles.add(a1, a3)
|
||||
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Comment.objects.dates("article__pub_date", "year"), [
|
||||
datetime.date(2005, 1, 1),
|
||||
datetime.date(2010, 1, 1),
|
||||
],
|
||||
lambda d: d,
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Comment.objects.dates("article__pub_date", "month"), [
|
||||
datetime.date(2005, 7, 1),
|
||||
datetime.date(2010, 7, 1),
|
||||
],
|
||||
lambda d: d
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Comment.objects.dates("article__pub_date", "day"), [
|
||||
datetime.date(2005, 7, 28),
|
||||
datetime.date(2010, 7, 28),
|
||||
],
|
||||
lambda d: d
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Article.objects.dates("comments__pub_date", "day"), [
|
||||
datetime.date(2005, 7, 28),
|
||||
datetime.date(2005, 7, 29),
|
||||
datetime.date(2005, 8, 29),
|
||||
datetime.date(2010, 7, 28),
|
||||
],
|
||||
lambda d: d
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
Article.objects.dates("comments__approval_date", "day"), []
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Category.objects.dates("articles__pub_date", "day"), [
|
||||
datetime.date(2005, 7, 28),
|
||||
],
|
||||
lambda d: d,
|
||||
)
|
||||
|
||||
def test_dates_fails_when_no_arguments_are_provided(self):
|
||||
|
@ -120,10 +115,10 @@ class DatesTests(TestCase):
|
|||
datetime.datetime(2015, 10, 22, 18, 2),
|
||||
]
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Article.objects.dates('pub_datetime', 'day', order='ASC'), [
|
||||
"datetime.date(2015, 10, 21)",
|
||||
"datetime.date(2015, 10, 22)",
|
||||
datetime.date(2015, 10, 21),
|
||||
datetime.date(2015, 10, 22),
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
@ -49,44 +49,39 @@ class DateTimesTests(TestCase):
|
|||
c = Category.objects.create(name="serious-news")
|
||||
c.articles.add(a1, a3)
|
||||
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Comment.objects.datetimes("article__pub_date", "year"), [
|
||||
datetime.datetime(2005, 1, 1),
|
||||
datetime.datetime(2010, 1, 1),
|
||||
],
|
||||
lambda d: d,
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Comment.objects.datetimes("article__pub_date", "month"), [
|
||||
datetime.datetime(2005, 7, 1),
|
||||
datetime.datetime(2010, 7, 1),
|
||||
],
|
||||
lambda d: d
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Comment.objects.datetimes("article__pub_date", "day"), [
|
||||
datetime.datetime(2005, 7, 28),
|
||||
datetime.datetime(2010, 7, 28),
|
||||
],
|
||||
lambda d: d
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Article.objects.datetimes("comments__pub_date", "day"), [
|
||||
datetime.datetime(2005, 7, 28),
|
||||
datetime.datetime(2005, 7, 29),
|
||||
datetime.datetime(2005, 8, 29),
|
||||
datetime.datetime(2010, 7, 28),
|
||||
],
|
||||
lambda d: d
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
Article.objects.datetimes("comments__approval_date", "day"), []
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Category.objects.datetimes("articles__pub_date", "day"), [
|
||||
datetime.datetime(2005, 7, 28),
|
||||
],
|
||||
lambda d: d,
|
||||
)
|
||||
|
||||
@skipIf(pytz is None, "this test requires pytz")
|
||||
|
|
|
@ -116,16 +116,10 @@ class DistinctOnTests(TestCase):
|
|||
def test_distinct_on_in_ordered_subquery(self):
|
||||
qs = Staff.objects.distinct('name').order_by('name', 'id')
|
||||
qs = Staff.objects.filter(pk__in=qs).order_by('name')
|
||||
self.assertQuerysetEqual(
|
||||
qs, [self.p1_o1, self.p2_o1, self.p3_o1],
|
||||
lambda x: x
|
||||
)
|
||||
self.assertSequenceEqual(qs, [self.p1_o1, self.p2_o1, self.p3_o1])
|
||||
qs = Staff.objects.distinct('name').order_by('name', '-id')
|
||||
qs = Staff.objects.filter(pk__in=qs).order_by('name')
|
||||
self.assertQuerysetEqual(
|
||||
qs, [self.p1_o2, self.p2_o1, self.p3_o1],
|
||||
lambda x: x
|
||||
)
|
||||
self.assertSequenceEqual(qs, [self.p1_o2, self.p2_o1, self.p3_o1])
|
||||
|
||||
def test_distinct_on_get_ordering_preserved(self):
|
||||
"""
|
||||
|
|
|
@ -79,7 +79,7 @@ class BasicExpressionsTests(TestCase):
|
|||
# We can filter on attribute relationships on same model obj, e.g.
|
||||
# find companies where the number of employees is greater
|
||||
# than the number of chairs.
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
self.company_query.filter(num_employees__gt=F("num_chairs")), [
|
||||
{
|
||||
"num_chairs": 5,
|
||||
|
@ -92,14 +92,13 @@ class BasicExpressionsTests(TestCase):
|
|||
"num_employees": 32
|
||||
},
|
||||
],
|
||||
lambda o: o
|
||||
)
|
||||
|
||||
def test_update(self):
|
||||
# We can set one field to have the value of another field
|
||||
# Make sure we have enough chairs
|
||||
self.company_query.update(num_chairs=F("num_employees"))
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
self.company_query, [
|
||||
{
|
||||
"num_chairs": 2300,
|
||||
|
@ -117,14 +116,13 @@ class BasicExpressionsTests(TestCase):
|
|||
"num_employees": 32
|
||||
}
|
||||
],
|
||||
lambda o: o
|
||||
)
|
||||
|
||||
def test_arithmetic(self):
|
||||
# We can perform arithmetic operations in expressions
|
||||
# Make sure we have 2 spare chairs
|
||||
self.company_query.update(num_chairs=F("num_employees") + 2)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
self.company_query, [
|
||||
{
|
||||
'num_chairs': 2302,
|
||||
|
@ -142,7 +140,6 @@ class BasicExpressionsTests(TestCase):
|
|||
'num_employees': 32
|
||||
}
|
||||
],
|
||||
lambda o: o,
|
||||
)
|
||||
|
||||
def test_order_of_operations(self):
|
||||
|
@ -150,7 +147,7 @@ class BasicExpressionsTests(TestCase):
|
|||
self. company_query.update(
|
||||
num_chairs=F('num_employees') + 2 * F('num_employees')
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
self.company_query, [
|
||||
{
|
||||
'num_chairs': 6900,
|
||||
|
@ -168,7 +165,6 @@ class BasicExpressionsTests(TestCase):
|
|||
'num_employees': 32
|
||||
}
|
||||
],
|
||||
lambda o: o,
|
||||
)
|
||||
|
||||
def test_parenthesis_priority(self):
|
||||
|
@ -176,7 +172,7 @@ class BasicExpressionsTests(TestCase):
|
|||
self.company_query.update(
|
||||
num_chairs=((F('num_employees') + 2) * F('num_employees'))
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
self.company_query, [
|
||||
{
|
||||
'num_chairs': 5294600,
|
||||
|
@ -194,7 +190,6 @@ class BasicExpressionsTests(TestCase):
|
|||
'num_employees': 32
|
||||
}
|
||||
],
|
||||
lambda o: o,
|
||||
)
|
||||
|
||||
def test_update_with_fk(self):
|
||||
|
@ -349,12 +344,9 @@ class BasicExpressionsTests(TestCase):
|
|||
Employee.objects.create(firstname="John", lastname="Doe")
|
||||
e2 = Employee.objects.create(firstname="Jack", lastname="Jackson")
|
||||
e3 = Employee.objects.create(firstname="Jack", lastname="jackson")
|
||||
self.assertQuerysetEqual(
|
||||
Employee.objects.filter(lastname__startswith=F('firstname')),
|
||||
[e2], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
Employee.objects.filter(lastname__istartswith=F('firstname')).order_by('pk'),
|
||||
[e2, e3], lambda x: x)
|
||||
self.assertSequenceEqual(Employee.objects.filter(lastname__startswith=F('firstname')), [e2])
|
||||
qs = Employee.objects.filter(lastname__istartswith=F('firstname')).order_by('pk')
|
||||
self.assertSequenceEqual(qs, [e2, e3])
|
||||
|
||||
def test_ticket_18375_join_reuse(self):
|
||||
# Test that reverse multijoin F() references and the lookup target
|
||||
|
|
|
@ -169,10 +169,9 @@ class ExtraRegressTests(TestCase):
|
|||
when=datetime.datetime(2008, 9, 28, 10, 30, 0)
|
||||
)
|
||||
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
RevisionableModel.objects.extra(select={"the_answer": 'id'}).datetimes('when', 'month'),
|
||||
[datetime.datetime(2008, 9, 1, 0, 0)],
|
||||
transform=lambda d: d,
|
||||
)
|
||||
|
||||
def test_values_with_extra(self):
|
||||
|
@ -432,12 +431,8 @@ class ExtraRegressTests(TestCase):
|
|||
qs = TestObject.objects.extra(
|
||||
select={'second_extra': 'second'}
|
||||
).values_list('id', flat=True).distinct()
|
||||
self.assertQuerysetEqual(
|
||||
qs.order_by('second_extra'), [t1.pk, t2.pk], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
qs.order_by('-second_extra'), [t2.pk, t1.pk], lambda x: x)
|
||||
self.assertSequenceEqual(qs.order_by('second_extra'), [t1.pk, t2.pk])
|
||||
self.assertSequenceEqual(qs.order_by('-second_extra'), [t2.pk, t1.pk])
|
||||
# Note: the extra ordering must appear in select clause, so we get two
|
||||
# non-distinct results here (this is on purpose, see #7070).
|
||||
self.assertQuerysetEqual(
|
||||
qs.order_by('-second_extra').values_list('first', flat=True),
|
||||
['a', 'a'], lambda x: x)
|
||||
self.assertSequenceEqual(qs.order_by('-second_extra').values_list('first', flat=True), ['a', 'a'])
|
||||
|
|
|
@ -153,16 +153,22 @@ class MultiColumnFKTests(TestCase):
|
|||
group_id=self.cia.id)
|
||||
Friendship.objects.create(from_friend_country_id=self.usa.id, from_friend_id=self.bob.id,
|
||||
to_friend_country_id=self.usa.id, to_friend_id=self.jim.id)
|
||||
self.assertQuerysetEqual(Membership.objects.filter(
|
||||
person__in=Person.objects.filter(
|
||||
from_friend__in=Friendship.objects.filter(
|
||||
to_friend__in=Person.objects.all()))),
|
||||
[m1], lambda x: x)
|
||||
self.assertQuerysetEqual(Membership.objects.exclude(
|
||||
person__in=Person.objects.filter(
|
||||
from_friend__in=Friendship.objects.filter(
|
||||
to_friend__in=Person.objects.all()))),
|
||||
[m2], lambda x: x)
|
||||
self.assertSequenceEqual(
|
||||
Membership.objects.filter(
|
||||
person__in=Person.objects.filter(
|
||||
from_friend__in=Friendship.objects.filter(to_friend__in=Person.objects.all())
|
||||
)
|
||||
),
|
||||
[m1]
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
Membership.objects.exclude(
|
||||
person__in=Person.objects.filter(
|
||||
from_friend__in=Friendship.objects.filter(to_friend__in=Person.objects.all())
|
||||
)
|
||||
),
|
||||
[m2]
|
||||
)
|
||||
|
||||
def test_select_related_foreignkey_forward_works(self):
|
||||
Membership.objects.create(membership_country=self.usa, person=self.bob, group=self.cia)
|
||||
|
@ -380,9 +386,9 @@ class MultiColumnFKTests(TestCase):
|
|||
na = NewsArticle.objects.create(pub_date=datetime.date.today())
|
||||
ArticleTranslation.objects.create(
|
||||
article=na, lang="fi", title="foo", body="bar")
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
NewsArticle.objects.select_related('active_translation'),
|
||||
[na], lambda x: x
|
||||
[na]
|
||||
)
|
||||
with self.assertNumQueries(1):
|
||||
self.assertEqual(
|
||||
|
|
|
@ -149,18 +149,10 @@ class GenericRelationTests(TestCase):
|
|||
hs4 = HasLinkThing.objects.create()
|
||||
l1 = Link.objects.create(content_object=hs3)
|
||||
l2 = Link.objects.create(content_object=hs4)
|
||||
self.assertQuerysetEqual(
|
||||
HasLinkThing.objects.filter(links=l1),
|
||||
[hs3], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
HasLinkThing.objects.filter(links=l2),
|
||||
[hs4], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
HasLinkThing.objects.exclude(links=l2),
|
||||
[hs1, hs2, hs3], lambda x: x, ordered=False)
|
||||
self.assertQuerysetEqual(
|
||||
HasLinkThing.objects.exclude(links=l1),
|
||||
[hs1, hs2, hs4], lambda x: x, ordered=False)
|
||||
self.assertSequenceEqual(HasLinkThing.objects.filter(links=l1), [hs3])
|
||||
self.assertSequenceEqual(HasLinkThing.objects.filter(links=l2), [hs4])
|
||||
self.assertSequenceEqual(HasLinkThing.objects.exclude(links=l2), [hs1, hs2, hs3])
|
||||
self.assertSequenceEqual(HasLinkThing.objects.exclude(links=l1), [hs1, hs2, hs4])
|
||||
|
||||
def test_ticket_20564(self):
|
||||
b1 = B.objects.create()
|
||||
|
@ -171,14 +163,8 @@ class GenericRelationTests(TestCase):
|
|||
c3 = C.objects.create(b=b3)
|
||||
A.objects.create(flag=None, content_object=b1)
|
||||
A.objects.create(flag=True, content_object=b2)
|
||||
self.assertQuerysetEqual(
|
||||
C.objects.filter(b__a__flag=None),
|
||||
[c1, c3], lambda x: x
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
C.objects.exclude(b__a__flag=None),
|
||||
[c2], lambda x: x
|
||||
)
|
||||
self.assertSequenceEqual(C.objects.filter(b__a__flag=None), [c1, c3])
|
||||
self.assertSequenceEqual(C.objects.exclude(b__a__flag=None), [c2])
|
||||
|
||||
def test_ticket_20564_nullable_fk(self):
|
||||
b1 = B.objects.create()
|
||||
|
@ -191,22 +177,10 @@ class GenericRelationTests(TestCase):
|
|||
A.objects.create(flag=None, content_object=b1)
|
||||
A.objects.create(flag=True, content_object=b1)
|
||||
A.objects.create(flag=True, content_object=b2)
|
||||
self.assertQuerysetEqual(
|
||||
D.objects.exclude(b__a__flag=None),
|
||||
[d2], lambda x: x
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
D.objects.filter(b__a__flag=None),
|
||||
[d1, d3, d4], lambda x: x
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
B.objects.filter(a__flag=None),
|
||||
[b1, b3], lambda x: x
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
B.objects.exclude(a__flag=None),
|
||||
[b2], lambda x: x
|
||||
)
|
||||
self.assertSequenceEqual(D.objects.exclude(b__a__flag=None), [d2])
|
||||
self.assertSequenceEqual(D.objects.filter(b__a__flag=None), [d1, d3, d4])
|
||||
self.assertSequenceEqual(B.objects.filter(a__flag=None), [b1, b3])
|
||||
self.assertSequenceEqual(B.objects.exclude(a__flag=None), [b2])
|
||||
|
||||
def test_extra_join_condition(self):
|
||||
# A crude check that content_type_id is taken in account in the
|
||||
|
@ -249,9 +223,7 @@ class GenericRelationTests(TestCase):
|
|||
hs2 = HasLinkThing.objects.create()
|
||||
l = Link.objects.create(content_object=hs2)
|
||||
self.assertNotEqual(l.object_id, l.pk)
|
||||
self.assertQuerysetEqual(
|
||||
HasLinkThing.objects.filter(links=l.pk),
|
||||
[hs2], lambda x: x)
|
||||
self.assertSequenceEqual(HasLinkThing.objects.filter(links=l.pk), [hs2])
|
||||
|
||||
def test_editable_generic_rel(self):
|
||||
GenericRelationForm = modelform_factory(HasLinkThing, fields='__all__')
|
||||
|
|
|
@ -428,7 +428,7 @@ class DistanceTest(TestCase):
|
|||
qs = SouthTexasCity.objects.distance(Point(3, 3)).order_by(
|
||||
'distance'
|
||||
).values_list('name', flat=True).filter(name__in=('San Antonio', 'Pearland'))
|
||||
self.assertQuerysetEqual(qs, ['San Antonio', 'Pearland'], lambda x: x)
|
||||
self.assertSequenceEqual(qs, ['San Antonio', 'Pearland'])
|
||||
|
||||
|
||||
'''
|
||||
|
@ -643,7 +643,7 @@ class DistanceFunctionsTests(TestCase):
|
|||
qs = SouthTexasCity.objects.annotate(distance=Distance('point', Point(3, 3, srid=32140))).order_by(
|
||||
'distance'
|
||||
).values_list('name', flat=True).filter(name__in=('San Antonio', 'Pearland'))
|
||||
self.assertQuerysetEqual(qs, ['San Antonio', 'Pearland'], lambda x: x)
|
||||
self.assertSequenceEqual(qs, ['San Antonio', 'Pearland'])
|
||||
|
||||
@skipUnlessDBFeature("has_Length_function")
|
||||
def test_length(self):
|
||||
|
|
|
@ -137,9 +137,7 @@ class LookupTests(TestCase):
|
|||
def test_values(self):
|
||||
# values() returns a list of dictionaries instead of object instances --
|
||||
# and you can specify which fields you want to retrieve.
|
||||
def identity(x):
|
||||
return x
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Article.objects.values('headline'),
|
||||
[
|
||||
{'headline': 'Article 5'},
|
||||
|
@ -150,14 +148,12 @@ class LookupTests(TestCase):
|
|||
{'headline': 'Article 7'},
|
||||
{'headline': 'Article 1'},
|
||||
],
|
||||
transform=identity
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Article.objects.filter(pub_date__exact=datetime(2005, 7, 27)).values('id'),
|
||||
[{'id': self.a2.id}, {'id': self.a3.id}, {'id': self.a7.id}],
|
||||
transform=identity
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Article.objects.values('id', 'headline'),
|
||||
[
|
||||
{'id': self.a5.id, 'headline': 'Article 5'},
|
||||
|
@ -168,12 +164,11 @@ class LookupTests(TestCase):
|
|||
{'id': self.a7.id, 'headline': 'Article 7'},
|
||||
{'id': self.a1.id, 'headline': 'Article 1'},
|
||||
],
|
||||
transform=identity
|
||||
)
|
||||
# You can use values() with iterator() for memory savings,
|
||||
# because iterator() uses database-level iteration.
|
||||
self.assertQuerysetEqual(
|
||||
Article.objects.values('id', 'headline').iterator(),
|
||||
self.assertSequenceEqual(
|
||||
list(Article.objects.values('id', 'headline').iterator()),
|
||||
[
|
||||
{'headline': 'Article 5', 'id': self.a5.id},
|
||||
{'headline': 'Article 6', 'id': self.a6.id},
|
||||
|
@ -183,10 +178,9 @@ class LookupTests(TestCase):
|
|||
{'headline': 'Article 7', 'id': self.a7.id},
|
||||
{'headline': 'Article 1', 'id': self.a1.id},
|
||||
],
|
||||
transform=identity
|
||||
)
|
||||
# The values() method works with "extra" fields specified in extra(select).
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Article.objects.extra(select={'id_plus_one': 'id + 1'}).values('id', 'id_plus_one'),
|
||||
[
|
||||
{'id': self.a5.id, 'id_plus_one': self.a5.id + 1},
|
||||
|
@ -197,7 +191,6 @@ class LookupTests(TestCase):
|
|||
{'id': self.a7.id, 'id_plus_one': self.a7.id + 1},
|
||||
{'id': self.a1.id, 'id_plus_one': self.a1.id + 1},
|
||||
],
|
||||
transform=identity
|
||||
)
|
||||
data = {
|
||||
'id_plus_one': 'id+1',
|
||||
|
@ -209,7 +202,7 @@ class LookupTests(TestCase):
|
|||
'id_plus_seven': 'id+7',
|
||||
'id_plus_eight': 'id+8',
|
||||
}
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Article.objects.filter(id=self.a1.id).extra(select=data).values(*data.keys()),
|
||||
[{
|
||||
'id_plus_one': self.a1.id + 1,
|
||||
|
@ -220,10 +213,10 @@ class LookupTests(TestCase):
|
|||
'id_plus_six': self.a1.id + 6,
|
||||
'id_plus_seven': self.a1.id + 7,
|
||||
'id_plus_eight': self.a1.id + 8,
|
||||
}], transform=identity
|
||||
}],
|
||||
)
|
||||
# You can specify fields from forward and reverse relations, just like filter().
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Article.objects.values('headline', 'author__name'),
|
||||
[
|
||||
{'headline': self.a5.headline, 'author__name': self.au2.name},
|
||||
|
@ -233,9 +226,9 @@ class LookupTests(TestCase):
|
|||
{'headline': self.a3.headline, 'author__name': self.au1.name},
|
||||
{'headline': self.a7.headline, 'author__name': self.au2.name},
|
||||
{'headline': self.a1.headline, 'author__name': self.au1.name},
|
||||
], transform=identity
|
||||
],
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Author.objects.values('name', 'article__headline').order_by('name', 'article__headline'),
|
||||
[
|
||||
{'name': self.au1.name, 'article__headline': self.a1.headline},
|
||||
|
@ -245,9 +238,9 @@ class LookupTests(TestCase):
|
|||
{'name': self.au2.name, 'article__headline': self.a5.headline},
|
||||
{'name': self.au2.name, 'article__headline': self.a6.headline},
|
||||
{'name': self.au2.name, 'article__headline': self.a7.headline},
|
||||
], transform=identity
|
||||
],
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
(
|
||||
Author.objects
|
||||
.values('name', 'article__headline', 'article__tag__name')
|
||||
|
@ -263,7 +256,7 @@ class LookupTests(TestCase):
|
|||
{'name': self.au2.name, 'article__headline': self.a5.headline, 'article__tag__name': self.t3.name},
|
||||
{'name': self.au2.name, 'article__headline': self.a6.headline, 'article__tag__name': self.t3.name},
|
||||
{'name': self.au2.name, 'article__headline': self.a7.headline, 'article__tag__name': self.t3.name},
|
||||
], transform=identity
|
||||
],
|
||||
)
|
||||
# However, an exception FieldDoesNotExist will be thrown if you specify
|
||||
# a non-existent field name in values() (a field that is neither in the
|
||||
|
@ -271,7 +264,7 @@ class LookupTests(TestCase):
|
|||
with self.assertRaises(FieldError):
|
||||
Article.objects.extra(select={'id_plus_one': 'id + 1'}).values('id', 'id_plus_two')
|
||||
# If you don't specify field names to values(), all are returned.
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Article.objects.filter(id=self.a5.id).values(),
|
||||
[{
|
||||
'id': self.a5.id,
|
||||
|
@ -279,7 +272,6 @@ class LookupTests(TestCase):
|
|||
'headline': 'Article 5',
|
||||
'pub_date': datetime(2005, 8, 1, 9, 0)
|
||||
}],
|
||||
transform=identity
|
||||
)
|
||||
|
||||
def test_values_list(self):
|
||||
|
@ -287,9 +279,7 @@ class LookupTests(TestCase):
|
|||
# returned as a list of tuples, rather than a list of dictionaries.
|
||||
# Within each tuple, the order of the elements is the same as the order
|
||||
# of fields in the values_list() call.
|
||||
def identity(x):
|
||||
return x
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Article.objects.values_list('headline'),
|
||||
[
|
||||
('Article 5',),
|
||||
|
@ -299,24 +289,21 @@ class LookupTests(TestCase):
|
|||
('Article 3',),
|
||||
('Article 7',),
|
||||
('Article 1',),
|
||||
], transform=identity
|
||||
],
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Article.objects.values_list('id').order_by('id'),
|
||||
[(self.a1.id,), (self.a2.id,), (self.a3.id,), (self.a4.id,), (self.a5.id,), (self.a6.id,), (self.a7.id,)],
|
||||
transform=identity
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Article.objects.values_list('id', flat=True).order_by('id'),
|
||||
[self.a1.id, self.a2.id, self.a3.id, self.a4.id, self.a5.id, self.a6.id, self.a7.id],
|
||||
transform=identity
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').values_list('id'),
|
||||
[(self.a1.id,), (self.a2.id,), (self.a3.id,), (self.a4.id,), (self.a5.id,), (self.a6.id,), (self.a7.id,)],
|
||||
transform=identity
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').values_list('id_plus_one', 'id'),
|
||||
[
|
||||
(self.a1.id + 1, self.a1.id),
|
||||
|
@ -327,9 +314,8 @@ class LookupTests(TestCase):
|
|||
(self.a6.id + 1, self.a6.id),
|
||||
(self.a7.id + 1, self.a7.id)
|
||||
],
|
||||
transform=identity
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').values_list('id', 'id_plus_one'),
|
||||
[
|
||||
(self.a1.id, self.a1.id + 1),
|
||||
|
@ -340,10 +326,9 @@ class LookupTests(TestCase):
|
|||
(self.a6.id, self.a6.id + 1),
|
||||
(self.a7.id, self.a7.id + 1)
|
||||
],
|
||||
transform=identity
|
||||
)
|
||||
args = ('name', 'article__headline', 'article__tag__name')
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Author.objects.values_list(*args).order_by(*args),
|
||||
[
|
||||
(self.au1.name, self.a1.headline, self.t1.name),
|
||||
|
@ -355,7 +340,7 @@ class LookupTests(TestCase):
|
|||
(self.au2.name, self.a5.headline, self.t3.name),
|
||||
(self.au2.name, self.a6.headline, self.t3.name),
|
||||
(self.au2.name, self.a7.headline, self.t3.name),
|
||||
], transform=identity
|
||||
],
|
||||
)
|
||||
with self.assertRaises(TypeError):
|
||||
Article.objects.values_list('id', 'headline', flat=True)
|
||||
|
@ -812,6 +797,4 @@ class LookupTransactionTests(TransactionTestCase):
|
|||
# NOTE: Needs to be created after the article has been saved.
|
||||
cursor.execute(
|
||||
'CREATE FULLTEXT INDEX myisam_article_ft ON myisam_article (headline)')
|
||||
self.assertQuerysetEqual(
|
||||
MyISAMArticle.objects.filter(headline__search='Reinhardt'),
|
||||
[dr], lambda x: x)
|
||||
self.assertSequenceEqual(MyISAMArticle.objects.filter(headline__search='Reinhardt'), [dr])
|
||||
|
|
|
@ -204,13 +204,13 @@ class M2mThroughTests(TestCase):
|
|||
CustomMembership.objects.create(person=self.bob, group=self.rock)
|
||||
CustomMembership.objects.create(person=self.jane, group=self.roll)
|
||||
CustomMembership.objects.create(person=self.jim, group=self.roll)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
self.rock.custom_members.order_by('custom_person_related_name'),
|
||||
[self.jim, self.bob], lambda x: x
|
||||
[self.jim, self.bob]
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
self.roll.custom_members.order_by('custom_person_related_name'),
|
||||
[self.jane, self.jim], lambda x: x
|
||||
[self.jane, self.jim]
|
||||
)
|
||||
|
||||
def test_query_first_model_by_intermediate_model_attribute(self):
|
||||
|
@ -460,10 +460,7 @@ class M2mThroughToFieldsTests(TestCase):
|
|||
|
||||
def test_retrieval(self):
|
||||
# Forward retrieval
|
||||
self.assertQuerysetEqual(
|
||||
self.curry.ingredients.all(),
|
||||
[self.pea, self.potato, self.tomato], lambda x: x
|
||||
)
|
||||
self.assertSequenceEqual(self.curry.ingredients.all(), [self.pea, self.potato, self.tomato])
|
||||
# Backward retrieval
|
||||
self.assertEqual(self.tomato.recipes.get(), self.curry)
|
||||
|
||||
|
|
|
@ -32,12 +32,11 @@ class ModelInheritanceTests(TestCase):
|
|||
|
||||
# The children inherit the Meta class of their parents (if they don't
|
||||
# specify their own).
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Worker.objects.values("name"), [
|
||||
{"name": "Barney"},
|
||||
{"name": "Fred"},
|
||||
],
|
||||
lambda o: o
|
||||
)
|
||||
|
||||
# Since Student does not subclass CommonInfo's Meta, it has the effect
|
||||
|
@ -313,11 +312,10 @@ class ModelInheritanceDataTests(TestCase):
|
|||
|
||||
def test_values_works_on_parent_model_fields(self):
|
||||
# The values() command also works on fields from parent models.
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
ItalianRestaurant.objects.values("name", "rating"), [
|
||||
{"rating": 4, "name": "Ristorante Miron"},
|
||||
],
|
||||
lambda o: o
|
||||
)
|
||||
|
||||
def test_select_related_works_on_parent_model_fields(self):
|
||||
|
|
|
@ -487,15 +487,9 @@ class ModelInheritanceTest(TestCase):
|
|||
)
|
||||
s = Supplier.objects.create(restaurant=r)
|
||||
with self.assertNumQueries(1):
|
||||
self.assertQuerysetEqual(
|
||||
Supplier.objects.filter(restaurant=r),
|
||||
[s], lambda x: x,
|
||||
)
|
||||
self.assertSequenceEqual(Supplier.objects.filter(restaurant=r), [s])
|
||||
with self.assertNumQueries(1):
|
||||
self.assertQuerysetEqual(
|
||||
r.supplier_set.all(),
|
||||
[s], lambda x: x,
|
||||
)
|
||||
self.assertSequenceEqual(r.supplier_set.all(), [s])
|
||||
|
||||
def test_queries_on_parent_access(self):
|
||||
italian_restaurant = ItalianRestaurant.objects.create(
|
||||
|
|
|
@ -519,12 +519,12 @@ class OneToOneTests(TestCase):
|
|||
# Test that subquery using primary key and a query against the
|
||||
# same model works correctly.
|
||||
q2 = Restaurant.objects.filter(place_id__in=q1)
|
||||
self.assertQuerysetEqual(q2, [r], lambda x: x)
|
||||
self.assertSequenceEqual(q2, [r])
|
||||
# Test that subquery using 'pk__in' instead of 'place_id__in' work, too.
|
||||
q2 = Restaurant.objects.filter(
|
||||
pk__in=Restaurant.objects.filter(place__id=r.place.pk)
|
||||
)
|
||||
self.assertQuerysetEqual(q2, [r], lambda x: x)
|
||||
self.assertSequenceEqual(q2, [r])
|
||||
|
||||
def test_rel_pk_exact(self):
|
||||
r = Restaurant.objects.first()
|
||||
|
@ -534,5 +534,5 @@ class OneToOneTests(TestCase):
|
|||
def test_primary_key_to_field_filter(self):
|
||||
target = Target.objects.create(name='foo')
|
||||
pointer = ToFieldPointer.objects.create(target=target)
|
||||
self.assertQuerysetEqual(ToFieldPointer.objects.filter(target=target), [pointer], lambda x: x)
|
||||
self.assertQuerysetEqual(ToFieldPointer.objects.filter(pk__exact=pointer), [pointer], lambda x: x)
|
||||
self.assertSequenceEqual(ToFieldPointer.objects.filter(target=target), [pointer])
|
||||
self.assertSequenceEqual(ToFieldPointer.objects.filter(pk__exact=pointer), [pointer])
|
||||
|
|
|
@ -231,11 +231,10 @@ class OrLookupsTests(TestCase):
|
|||
3
|
||||
)
|
||||
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Article.objects.filter(Q(headline__startswith='Hello'), Q(headline__contains='bye')).values(), [
|
||||
{"headline": "Hello and goodbye", "id": self.a3, "pub_date": datetime(2005, 11, 29)},
|
||||
],
|
||||
lambda o: o,
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
|
|
|
@ -323,4 +323,4 @@ class OrderingTests(TestCase):
|
|||
self.a2.save()
|
||||
r1 = Reference.objects.create(article_id=self.a1.pk)
|
||||
r2 = Reference.objects.create(article_id=self.a2.pk)
|
||||
self.assertQuerysetEqual(Reference.objects.all(), [r2, r1], lambda x: x)
|
||||
self.assertSequenceEqual(Reference.objects.all(), [r2, r1])
|
||||
|
|
|
@ -303,14 +303,8 @@ class ProxyModelTests(TestCase):
|
|||
issue = Issue.objects.create(assignee=tu)
|
||||
self.assertEqual(tu.issues.get(), issue)
|
||||
self.assertEqual(ptu.issues.get(), issue)
|
||||
self.assertQuerysetEqual(
|
||||
TrackerUser.objects.filter(issues=issue),
|
||||
[tu], lambda x: x
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
ProxyTrackerUser.objects.filter(issues=issue),
|
||||
[ptu], lambda x: x
|
||||
)
|
||||
self.assertSequenceEqual(TrackerUser.objects.filter(issues=issue), [tu])
|
||||
self.assertSequenceEqual(ProxyTrackerUser.objects.filter(issues=issue), [ptu])
|
||||
|
||||
def test_proxy_bug(self):
|
||||
contributor = ProxyTrackerUser.objects.create(name='Contributor', status='contrib')
|
||||
|
|
|
@ -33,12 +33,7 @@ from .models import (
|
|||
)
|
||||
|
||||
|
||||
class BaseQuerysetTest(TestCase):
|
||||
def assertValueQuerysetEqual(self, qs, values):
|
||||
return self.assertQuerysetEqual(qs, values, transform=lambda x: x)
|
||||
|
||||
|
||||
class Queries1Tests(BaseQuerysetTest):
|
||||
class Queries1Tests(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
generic = NamedCategory.objects.create(name="Generic")
|
||||
|
@ -533,7 +528,7 @@ class Queries1Tests(BaseQuerysetTest):
|
|||
# are multiple values in the ordering cols), as in this example. This
|
||||
# isn't a bug; it's a warning to be careful with the selection of
|
||||
# ordering columns.
|
||||
self.assertValueQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Note.objects.values('misc').distinct().order_by('note', '-misc'),
|
||||
[{'misc': 'foo'}, {'misc': 'bar'}, {'misc': 'foo'}]
|
||||
)
|
||||
|
@ -543,21 +538,12 @@ class Queries1Tests(BaseQuerysetTest):
|
|||
# returned as "foo_id" keys, not "foo". For consistency, you should be
|
||||
# able to pass "foo_id" in the fields list and have it work, too. We
|
||||
# actually allow both "foo" and "foo_id".
|
||||
|
||||
# The *_id version is returned by default.
|
||||
self.assertIn('note_id', ExtraInfo.objects.values()[0])
|
||||
|
||||
# You can also pass it in explicitly.
|
||||
self.assertValueQuerysetEqual(
|
||||
ExtraInfo.objects.values('note_id'),
|
||||
[{'note_id': 1}, {'note_id': 2}]
|
||||
)
|
||||
|
||||
self.assertSequenceEqual(ExtraInfo.objects.values('note_id'), [{'note_id': 1}, {'note_id': 2}])
|
||||
# ...or use the field name.
|
||||
self.assertValueQuerysetEqual(
|
||||
ExtraInfo.objects.values('note'),
|
||||
[{'note': 1}, {'note': 2}]
|
||||
)
|
||||
self.assertSequenceEqual(ExtraInfo.objects.values('note'), [{'note': 1}, {'note': 2}])
|
||||
|
||||
def test_ticket2902(self):
|
||||
# Parameters can be given to extra_select, *if* you use an OrderedDict.
|
||||
|
@ -655,7 +641,7 @@ class Queries1Tests(BaseQuerysetTest):
|
|||
def test_ticket7098(self):
|
||||
# Make sure semi-deprecated ordering by related models syntax still
|
||||
# works.
|
||||
self.assertValueQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Item.objects.values('note__note').order_by('queries_note.note', 'id'),
|
||||
[{'note__note': 'n2'}, {'note__note': 'n3'}, {'note__note': 'n3'}, {'note__note': 'n3'}]
|
||||
)
|
||||
|
@ -787,7 +773,7 @@ class Queries1Tests(BaseQuerysetTest):
|
|||
|
||||
def test_ticket9985(self):
|
||||
# qs.values_list(...).values(...) combinations should work.
|
||||
self.assertValueQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Note.objects.values_list("note", flat=True).values("id").order_by("id"),
|
||||
[{'id': 1}, {'id': 2}, {'id': 3}]
|
||||
)
|
||||
|
@ -1303,7 +1289,7 @@ class Queries2Tests(TestCase):
|
|||
self.assertTrue(run())
|
||||
|
||||
|
||||
class Queries3Tests(BaseQuerysetTest):
|
||||
class Queries3Tests(TestCase):
|
||||
def test_ticket7107(self):
|
||||
# This shouldn't create an infinite loop.
|
||||
self.assertQuerysetEqual(Valid.objects.all(), [])
|
||||
|
@ -1322,7 +1308,7 @@ class Queries3Tests(BaseQuerysetTest):
|
|||
Valid.objects.values().defer()
|
||||
|
||||
|
||||
class Queries4Tests(BaseQuerysetTest):
|
||||
class Queries4Tests(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
generic = NamedCategory.objects.create(name="Generic")
|
||||
|
@ -1419,7 +1405,7 @@ class Queries4Tests(BaseQuerysetTest):
|
|||
expected_null_charfield_repr = ''
|
||||
else:
|
||||
expected_null_charfield_repr = None
|
||||
self.assertValueQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Report.objects.values_list("creator__extra__info", flat=True).order_by("name"),
|
||||
['e1', 'e2', expected_null_charfield_repr],
|
||||
)
|
||||
|
@ -1458,9 +1444,7 @@ class Queries4Tests(BaseQuerysetTest):
|
|||
CategoryItem.objects.create(category=c1)
|
||||
CategoryItem.objects.create(category=c2)
|
||||
CategoryItem.objects.create(category=c1)
|
||||
self.assertQuerysetEqual(
|
||||
SimpleCategory.objects.order_by('categoryitem', 'pk'),
|
||||
[c1, c2, c1], lambda x: x)
|
||||
self.assertSequenceEqual(SimpleCategory.objects.order_by('categoryitem', 'pk'), [c1, c2, c1])
|
||||
|
||||
def test_ticket10181(self):
|
||||
# Avoid raising an EmptyResultSet if an inner query is probably
|
||||
|
@ -1481,7 +1465,7 @@ class Queries4Tests(BaseQuerysetTest):
|
|||
|
||||
qs = CategoryItem.objects.filter(category__specialcategory__isnull=False)
|
||||
self.assertEqual(qs.count(), 2)
|
||||
self.assertQuerysetEqual(qs, [ci2.pk, ci3.pk], lambda x: x.pk, False)
|
||||
self.assertSequenceEqual(qs, [ci2, ci3])
|
||||
|
||||
def test_ticket15316_exclude_false(self):
|
||||
c1 = SimpleCategory.objects.create(name="category1")
|
||||
|
@ -1494,7 +1478,7 @@ class Queries4Tests(BaseQuerysetTest):
|
|||
|
||||
qs = CategoryItem.objects.exclude(category__specialcategory__isnull=False)
|
||||
self.assertEqual(qs.count(), 1)
|
||||
self.assertQuerysetEqual(qs, [ci1.pk], lambda x: x.pk)
|
||||
self.assertSequenceEqual(qs, [ci1])
|
||||
|
||||
def test_ticket15316_filter_true(self):
|
||||
c1 = SimpleCategory.objects.create(name="category1")
|
||||
|
@ -1507,7 +1491,7 @@ class Queries4Tests(BaseQuerysetTest):
|
|||
|
||||
qs = CategoryItem.objects.filter(category__specialcategory__isnull=True)
|
||||
self.assertEqual(qs.count(), 1)
|
||||
self.assertQuerysetEqual(qs, [ci1.pk], lambda x: x.pk)
|
||||
self.assertSequenceEqual(qs, [ci1])
|
||||
|
||||
def test_ticket15316_exclude_true(self):
|
||||
c1 = SimpleCategory.objects.create(name="category1")
|
||||
|
@ -1520,7 +1504,7 @@ class Queries4Tests(BaseQuerysetTest):
|
|||
|
||||
qs = CategoryItem.objects.exclude(category__specialcategory__isnull=True)
|
||||
self.assertEqual(qs.count(), 2)
|
||||
self.assertQuerysetEqual(qs, [ci2.pk, ci3.pk], lambda x: x.pk, False)
|
||||
self.assertSequenceEqual(qs, [ci2, ci3])
|
||||
|
||||
def test_ticket15316_one2one_filter_false(self):
|
||||
c = SimpleCategory.objects.create(name="cat")
|
||||
|
@ -1536,7 +1520,7 @@ class Queries4Tests(BaseQuerysetTest):
|
|||
|
||||
qs = CategoryItem.objects.filter(category__onetoonecategory__isnull=False)
|
||||
self.assertEqual(qs.count(), 2)
|
||||
self.assertQuerysetEqual(qs, [ci2.pk, ci3.pk], lambda x: x.pk, False)
|
||||
self.assertSequenceEqual(qs, [ci2, ci3])
|
||||
|
||||
def test_ticket15316_one2one_exclude_false(self):
|
||||
c = SimpleCategory.objects.create(name="cat")
|
||||
|
@ -1552,7 +1536,7 @@ class Queries4Tests(BaseQuerysetTest):
|
|||
|
||||
qs = CategoryItem.objects.exclude(category__onetoonecategory__isnull=False)
|
||||
self.assertEqual(qs.count(), 1)
|
||||
self.assertQuerysetEqual(qs, [ci1.pk], lambda x: x.pk)
|
||||
self.assertSequenceEqual(qs, [ci1])
|
||||
|
||||
def test_ticket15316_one2one_filter_true(self):
|
||||
c = SimpleCategory.objects.create(name="cat")
|
||||
|
@ -1568,7 +1552,7 @@ class Queries4Tests(BaseQuerysetTest):
|
|||
|
||||
qs = CategoryItem.objects.filter(category__onetoonecategory__isnull=True)
|
||||
self.assertEqual(qs.count(), 1)
|
||||
self.assertQuerysetEqual(qs, [ci1.pk], lambda x: x.pk)
|
||||
self.assertSequenceEqual(qs, [ci1])
|
||||
|
||||
def test_ticket15316_one2one_exclude_true(self):
|
||||
c = SimpleCategory.objects.create(name="cat")
|
||||
|
@ -1584,7 +1568,7 @@ class Queries4Tests(BaseQuerysetTest):
|
|||
|
||||
qs = CategoryItem.objects.exclude(category__onetoonecategory__isnull=True)
|
||||
self.assertEqual(qs.count(), 2)
|
||||
self.assertQuerysetEqual(qs, [ci2.pk, ci3.pk], lambda x: x.pk, False)
|
||||
self.assertSequenceEqual(qs, [ci2, ci3])
|
||||
|
||||
|
||||
class Queries5Tests(TestCase):
|
||||
|
@ -2150,16 +2134,15 @@ class EmptyQuerySetTests(TestCase):
|
|||
self.assertQuerysetEqual(q.values_list(), [])
|
||||
|
||||
|
||||
class ValuesQuerysetTests(BaseQuerysetTest):
|
||||
class ValuesQuerysetTests(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
Number.objects.create(num=72)
|
||||
cls.identity = staticmethod(lambda x: x)
|
||||
|
||||
def test_flat_values_list(self):
|
||||
qs = Number.objects.values_list("num")
|
||||
qs = qs.values_list("num", flat=True)
|
||||
self.assertValueQuerysetEqual(qs, [72])
|
||||
self.assertSequenceEqual(qs, [72])
|
||||
|
||||
def test_extra_values(self):
|
||||
# testing for ticket 14930 issues
|
||||
|
@ -2168,14 +2151,14 @@ class ValuesQuerysetTests(BaseQuerysetTest):
|
|||
select_params=(1, 2))
|
||||
qs = qs.order_by('value_minus_x')
|
||||
qs = qs.values('num')
|
||||
self.assertQuerysetEqual(qs, [{'num': 72}], self.identity)
|
||||
self.assertSequenceEqual(qs, [{'num': 72}])
|
||||
|
||||
def test_extra_values_order_twice(self):
|
||||
# testing for ticket 14930 issues
|
||||
qs = Number.objects.extra(select={'value_plus_one': 'num+1', 'value_minus_one': 'num-1'})
|
||||
qs = qs.order_by('value_minus_one').order_by('value_plus_one')
|
||||
qs = qs.values('num')
|
||||
self.assertQuerysetEqual(qs, [{'num': 72}], self.identity)
|
||||
self.assertSequenceEqual(qs, [{'num': 72}])
|
||||
|
||||
def test_extra_values_order_multiple(self):
|
||||
# Postgres doesn't allow constants in order by, so check for that.
|
||||
|
@ -2186,7 +2169,7 @@ class ValuesQuerysetTests(BaseQuerysetTest):
|
|||
})
|
||||
qs = qs.order_by('value_plus_one', 'value_minus_one', 'constant_value')
|
||||
qs = qs.values('num')
|
||||
self.assertQuerysetEqual(qs, [{'num': 72}], self.identity)
|
||||
self.assertSequenceEqual(qs, [{'num': 72}])
|
||||
|
||||
def test_extra_values_order_in_extra(self):
|
||||
# testing for ticket 14930 issues
|
||||
|
@ -2203,7 +2186,7 @@ class ValuesQuerysetTests(BaseQuerysetTest):
|
|||
order_by=['value_plus_x'])
|
||||
qs = qs.filter(num=72)
|
||||
qs = qs.values('num')
|
||||
self.assertQuerysetEqual(qs, [{'num': 72}], self.identity)
|
||||
self.assertSequenceEqual(qs, [{'num': 72}])
|
||||
|
||||
def test_extra_multiple_select_params_values_order_by(self):
|
||||
# testing for 23259 issue
|
||||
|
@ -2213,21 +2196,21 @@ class ValuesQuerysetTests(BaseQuerysetTest):
|
|||
qs = qs.order_by('value_minus_x')
|
||||
qs = qs.filter(num=1)
|
||||
qs = qs.values('num')
|
||||
self.assertQuerysetEqual(qs, [], self.identity)
|
||||
self.assertSequenceEqual(qs, [])
|
||||
|
||||
def test_extra_values_list(self):
|
||||
# testing for ticket 14930 issues
|
||||
qs = Number.objects.extra(select={'value_plus_one': 'num+1'})
|
||||
qs = qs.order_by('value_plus_one')
|
||||
qs = qs.values_list('num')
|
||||
self.assertQuerysetEqual(qs, [(72,)], self.identity)
|
||||
self.assertSequenceEqual(qs, [(72,)])
|
||||
|
||||
def test_flat_extra_values_list(self):
|
||||
# testing for ticket 14930 issues
|
||||
qs = Number.objects.extra(select={'value_plus_one': 'num+1'})
|
||||
qs = qs.order_by('value_plus_one')
|
||||
qs = qs.values_list('num', flat=True)
|
||||
self.assertQuerysetEqual(qs, [72], self.identity)
|
||||
self.assertSequenceEqual(qs, [72])
|
||||
|
||||
def test_field_error_values_list(self):
|
||||
# see #23443
|
||||
|
@ -2352,7 +2335,7 @@ class QuerySetSupportsPythonIdioms(TestCase):
|
|||
self.assertQuerysetEqual(s1 & s2, [])
|
||||
|
||||
|
||||
class WeirdQuerysetSlicingTests(BaseQuerysetTest):
|
||||
class WeirdQuerysetSlicingTests(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
Number.objects.create(num=1)
|
||||
|
@ -2505,7 +2488,7 @@ class IsNullTests(TestCase):
|
|||
)
|
||||
|
||||
|
||||
class ConditionalTests(BaseQuerysetTest):
|
||||
class ConditionalTests(TestCase):
|
||||
"""Tests whose execution depend on different environment conditions like
|
||||
Python version or DB backend features"""
|
||||
|
||||
|
@ -2696,11 +2679,11 @@ class ExcludeTests(TestCase):
|
|||
|
||||
alex_tech_employers = alex.employers.filter(
|
||||
employment__title__in=('Engineer', 'Developer')).distinct().order_by('name')
|
||||
self.assertQuerysetEqual(alex_tech_employers, [google, oracle], lambda x: x)
|
||||
self.assertSequenceEqual(alex_tech_employers, [google, oracle])
|
||||
|
||||
alex_nontech_employers = alex.employers.exclude(
|
||||
employment__title__in=('Engineer', 'Developer')).distinct().order_by('name')
|
||||
self.assertQuerysetEqual(alex_nontech_employers, [google, intel, microsoft], lambda x: x)
|
||||
self.assertSequenceEqual(alex_nontech_employers, [google, intel, microsoft])
|
||||
|
||||
|
||||
class ExcludeTest17600(TestCase):
|
||||
|
@ -3056,8 +3039,7 @@ class NullJoinPromotionOrTest(TestCase):
|
|||
)
|
||||
self.assertEqual(str(qs.query).count('LEFT OUTER JOIN'), 2)
|
||||
self.assertEqual(str(qs.query).count(' JOIN '), 2)
|
||||
self.assertQuerysetEqual(
|
||||
qs.order_by('name'), [r2, r1], lambda x: x)
|
||||
self.assertSequenceEqual(qs.order_by('name'), [r2, r1])
|
||||
|
||||
def test_ticket_21748(self):
|
||||
i1 = Identifier.objects.create(name='i1')
|
||||
|
@ -3066,12 +3048,8 @@ class NullJoinPromotionOrTest(TestCase):
|
|||
Program.objects.create(identifier=i1)
|
||||
Channel.objects.create(identifier=i1)
|
||||
Program.objects.create(identifier=i2)
|
||||
self.assertQuerysetEqual(
|
||||
Identifier.objects.filter(program=None, channel=None),
|
||||
[i3], lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
Identifier.objects.exclude(program=None, channel=None).order_by('name'),
|
||||
[i1, i2], lambda x: x)
|
||||
self.assertSequenceEqual(Identifier.objects.filter(program=None, channel=None), [i3])
|
||||
self.assertSequenceEqual(Identifier.objects.exclude(program=None, channel=None).order_by('name'), [i1, i2])
|
||||
|
||||
def test_ticket_21748_double_negated_and(self):
|
||||
i1 = Identifier.objects.create(name='i1')
|
||||
|
@ -3192,7 +3170,7 @@ class DisjunctionPromotionTests(TestCase):
|
|||
self.assertEqual(str(qs.query).count(' INNER JOIN '), 0)
|
||||
self.assertEqual(str(qs.query).count(' LEFT OUTER JOIN '), 2)
|
||||
with self.assertNumQueries(1):
|
||||
self.assertQuerysetEqual(qs, [basea], lambda x: x)
|
||||
self.assertSequenceEqual(qs, [basea])
|
||||
self.assertEqual(qs[0].a, fk1)
|
||||
self.assertIs(qs[0].b, None)
|
||||
|
||||
|
@ -3412,9 +3390,7 @@ class ValuesSubqueryTests(TestCase):
|
|||
|
||||
# The query below should match o1 as it has related order_item
|
||||
# with id == status.
|
||||
self.assertQuerysetEqual(
|
||||
Order.objects.filter(items__in=OrderItem.objects.values_list('status')),
|
||||
[o1.pk], lambda x: x.pk)
|
||||
self.assertSequenceEqual(Order.objects.filter(items__in=OrderItem.objects.values_list('status')), [o1])
|
||||
|
||||
|
||||
class DoubleInSubqueryTests(TestCase):
|
||||
|
@ -3428,8 +3404,7 @@ class DoubleInSubqueryTests(TestCase):
|
|||
leaf_as = LeafA.objects.filter(data='foo').values_list('pk', flat=True)
|
||||
joins = Join.objects.filter(a__in=leaf_as).values_list('b__id', flat=True)
|
||||
qs = LeafB.objects.filter(pk__in=joins)
|
||||
self.assertQuerysetEqual(
|
||||
qs, [lfb1], lambda x: x)
|
||||
self.assertSequenceEqual(qs, [lfb1])
|
||||
|
||||
|
||||
class Ticket18785Tests(TestCase):
|
||||
|
@ -3457,10 +3432,8 @@ class Ticket20788Tests(TestCase):
|
|||
chapter2 = Chapter.objects.create(paragraph=paragraph2)
|
||||
book2 = Book.objects.create(chapter=chapter2)
|
||||
|
||||
sentences_not_in_pub = Book.objects.exclude(
|
||||
chapter__paragraph__page=page)
|
||||
self.assertQuerysetEqual(
|
||||
sentences_not_in_pub, [book2], lambda x: x)
|
||||
sentences_not_in_pub = Book.objects.exclude(chapter__paragraph__page=page)
|
||||
self.assertSequenceEqual(sentences_not_in_pub, [book2])
|
||||
|
||||
|
||||
class Ticket12807Tests(TestCase):
|
||||
|
@ -3470,7 +3443,7 @@ class Ticket12807Tests(TestCase):
|
|||
# The ORed condition below should have no effect on the query - the
|
||||
# ~Q(pk__in=[]) will always be True.
|
||||
qs = Paragraph.objects.filter((Q(pk=p2.pk) | ~Q(pk__in=[])) & Q(pk=p1.pk))
|
||||
self.assertQuerysetEqual(qs, [p1], lambda x: x)
|
||||
self.assertSequenceEqual(qs, [p1])
|
||||
|
||||
|
||||
class RelatedLookupTypeTests(TestCase):
|
||||
|
@ -3581,10 +3554,7 @@ class Ticket14056Tests(TestCase):
|
|||
[s1, s3, s2] if connection.features.nulls_order_largest
|
||||
else [s2, s1, s3]
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
SharedConnection.objects.order_by('-pointera__connection', 'pk'),
|
||||
expected_ordering, lambda x: x
|
||||
)
|
||||
self.assertSequenceEqual(SharedConnection.objects.order_by('-pointera__connection', 'pk'), expected_ordering)
|
||||
|
||||
|
||||
class Ticket20955Tests(TestCase):
|
||||
|
@ -3615,7 +3585,7 @@ class Ticket21203Tests(TestCase):
|
|||
p = Ticket21203Parent.objects.create(parent_bool=True)
|
||||
c = Ticket21203Child.objects.create(parent=p)
|
||||
qs = Ticket21203Child.objects.select_related('parent').defer('parent__created')
|
||||
self.assertQuerysetEqual(qs, [c], lambda x: x)
|
||||
self.assertSequenceEqual(qs, [c])
|
||||
self.assertIs(qs[0].parent.parent_bool, True)
|
||||
|
||||
|
||||
|
@ -3654,15 +3624,8 @@ class ForeignKeyToBaseExcludeTests(TestCase):
|
|||
sc3 = SpecialCategory.objects.create(special_name='sc3', name='sc3')
|
||||
c1 = CategoryItem.objects.create(category=sc1)
|
||||
CategoryItem.objects.create(category=sc2)
|
||||
self.assertQuerysetEqual(
|
||||
SpecialCategory.objects.exclude(
|
||||
categoryitem__id=c1.pk).order_by('name'),
|
||||
[sc2, sc3], lambda x: x
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
SpecialCategory.objects.filter(categoryitem__id=c1.pk),
|
||||
[sc1], lambda x: x
|
||||
)
|
||||
self.assertSequenceEqual(SpecialCategory.objects.exclude(categoryitem__id=c1.pk).order_by('name'), [sc2, sc3])
|
||||
self.assertSequenceEqual(SpecialCategory.objects.filter(categoryitem__id=c1.pk), [sc1])
|
||||
|
||||
|
||||
class ReverseM2MCustomPkTests(TestCase):
|
||||
|
@ -3670,12 +3633,8 @@ class ReverseM2MCustomPkTests(TestCase):
|
|||
cpt1 = CustomPkTag.objects.create(id='cpt1', tag='cpt1')
|
||||
cp1 = CustomPk.objects.create(name='cp1', extra='extra')
|
||||
cp1.custompktag_set.add(cpt1)
|
||||
self.assertQuerysetEqual(
|
||||
CustomPk.objects.filter(custompktag=cpt1), [cp1],
|
||||
lambda x: x)
|
||||
self.assertQuerysetEqual(
|
||||
CustomPkTag.objects.filter(custom_pk=cp1), [cpt1],
|
||||
lambda x: x)
|
||||
self.assertSequenceEqual(CustomPk.objects.filter(custompktag=cpt1), [cp1])
|
||||
self.assertSequenceEqual(CustomPkTag.objects.filter(custom_pk=cp1), [cpt1])
|
||||
|
||||
|
||||
class Ticket22429Tests(TestCase):
|
||||
|
@ -3690,7 +3649,7 @@ class Ticket22429Tests(TestCase):
|
|||
cr.students.add(st1)
|
||||
|
||||
queryset = Student.objects.filter(~Q(classroom__school=F('school')))
|
||||
self.assertQuerysetEqual(queryset, [st2], lambda x: x)
|
||||
self.assertSequenceEqual(queryset, [st2])
|
||||
|
||||
|
||||
class Ticket23605Tests(TestCase):
|
||||
|
@ -3724,9 +3683,9 @@ class Ticket23605Tests(TestCase):
|
|||
)
|
||||
))).filter(ticket23605b__field_b1=True))
|
||||
qs1 = Ticket23605A.objects.filter(complex_q)
|
||||
self.assertQuerysetEqual(qs1, [a1], lambda x: x)
|
||||
self.assertSequenceEqual(qs1, [a1])
|
||||
qs2 = Ticket23605A.objects.exclude(complex_q)
|
||||
self.assertQuerysetEqual(qs2, [a2], lambda x: x)
|
||||
self.assertSequenceEqual(qs2, [a2])
|
||||
|
||||
|
||||
class TestTicket24279(TestCase):
|
||||
|
@ -3756,15 +3715,10 @@ class TestTicket24605(TestCase):
|
|||
i3 = Individual.objects.create(alive=True)
|
||||
i4 = Individual.objects.create(alive=False)
|
||||
|
||||
self.assertQuerysetEqual(
|
||||
Individual.objects.filter(Q(alive=False), Q(related_individual__isnull=True)),
|
||||
[i4], lambda x: x
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
Individual.objects.exclude(
|
||||
Q(alive=False), Q(related_individual__isnull=True)
|
||||
).order_by('pk'),
|
||||
[i1, i2, i3], lambda x: x
|
||||
self.assertSequenceEqual(Individual.objects.filter(Q(alive=False), Q(related_individual__isnull=True)), [i4])
|
||||
self.assertSequenceEqual(
|
||||
Individual.objects.exclude(Q(alive=False), Q(related_individual__isnull=True)).order_by('pk'),
|
||||
[i1, i2, i3]
|
||||
)
|
||||
|
||||
|
||||
|
@ -3830,7 +3784,4 @@ class Ticket23622Tests(TestCase):
|
|||
set(Ticket23605A.objects.filter(qx).values_list('pk', flat=True)),
|
||||
set(Ticket23605A.objects.filter(qy).values_list('pk', flat=True))
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
Ticket23605A.objects.filter(qx),
|
||||
[a2], lambda x: x
|
||||
)
|
||||
self.assertSequenceEqual(Ticket23605A.objects.filter(qx), [a2])
|
||||
|
|
|
@ -109,11 +109,11 @@ class PickleabilityTestCase(TestCase):
|
|||
|
||||
# First pickling
|
||||
groups = pickle.loads(pickle.dumps(groups))
|
||||
self.assertQuerysetEqual(groups, [g], lambda x: x)
|
||||
self.assertSequenceEqual(groups, [g])
|
||||
|
||||
# Second pickling
|
||||
groups = pickle.loads(pickle.dumps(groups))
|
||||
self.assertQuerysetEqual(groups, [g], lambda x: x)
|
||||
self.assertSequenceEqual(groups, [g])
|
||||
|
||||
def test_pickle_prefetch_related_with_m2m_and_objects_deletion(self):
|
||||
"""
|
||||
|
@ -127,7 +127,7 @@ class PickleabilityTestCase(TestCase):
|
|||
|
||||
m2ms = M2MModel.objects.prefetch_related('groups')
|
||||
m2ms = pickle.loads(pickle.dumps(m2ms))
|
||||
self.assertQuerysetEqual(m2ms, [m2m], lambda x: x)
|
||||
self.assertSequenceEqual(m2ms, [m2m])
|
||||
|
||||
def test_annotation_with_callable_default(self):
|
||||
# Happening.when has a callable default of datetime.datetime.now.
|
||||
|
|
|
@ -187,7 +187,7 @@ class SelectRelatedRegressTests(TestCase):
|
|||
c_a=a, c_b=b)
|
||||
results = C.objects.all().only('name', 'lots_of_text', 'c_a', 'c_b', 'c_b__lots_of_text',
|
||||
'c_a__name', 'c_b__name').select_related()
|
||||
self.assertQuerysetEqual(results, [c], lambda x: x)
|
||||
self.assertSequenceEqual(results, [c])
|
||||
with self.assertNumQueries(0):
|
||||
qs_c = results[0]
|
||||
self.assertEqual(qs_c.name, 'c')
|
||||
|
|
|
@ -78,9 +78,6 @@ class StringLookupTests(TestCase):
|
|||
"""
|
||||
a = Article(name='IP test', text='The body', submitted_from='192.0.2.100')
|
||||
a.save()
|
||||
self.assertQuerysetEqual(
|
||||
Article.objects.filter(submitted_from__contains='192.0.2'),
|
||||
[a], lambda x: x
|
||||
)
|
||||
self.assertSequenceEqual(Article.objects.filter(submitted_from__contains='192.0.2'), [a])
|
||||
# Test that the searches do not match the subnet mask (/32 in this case)
|
||||
self.assertEqual(Article.objects.filter(submitted_from__contains='32').count(), 0)
|
||||
|
|
|
@ -200,42 +200,30 @@ class LegacyDatabaseTests(TestCase):
|
|||
def test_query_datetimes(self):
|
||||
Event.objects.create(dt=datetime.datetime(2011, 1, 1, 1, 30, 0))
|
||||
Event.objects.create(dt=datetime.datetime(2011, 1, 1, 4, 30, 0))
|
||||
self.assertQuerysetEqual(
|
||||
Event.objects.datetimes('dt', 'year'),
|
||||
[datetime.datetime(2011, 1, 1, 0, 0, 0)],
|
||||
transform=lambda d: d)
|
||||
self.assertQuerysetEqual(
|
||||
Event.objects.datetimes('dt', 'month'),
|
||||
[datetime.datetime(2011, 1, 1, 0, 0, 0)],
|
||||
transform=lambda d: d)
|
||||
self.assertQuerysetEqual(
|
||||
Event.objects.datetimes('dt', 'day'),
|
||||
[datetime.datetime(2011, 1, 1, 0, 0, 0)],
|
||||
transform=lambda d: d)
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(Event.objects.datetimes('dt', 'year'), [datetime.datetime(2011, 1, 1, 0, 0, 0)])
|
||||
self.assertSequenceEqual(Event.objects.datetimes('dt', 'month'), [datetime.datetime(2011, 1, 1, 0, 0, 0)])
|
||||
self.assertSequenceEqual(Event.objects.datetimes('dt', 'day'), [datetime.datetime(2011, 1, 1, 0, 0, 0)])
|
||||
self.assertSequenceEqual(
|
||||
Event.objects.datetimes('dt', 'hour'),
|
||||
[datetime.datetime(2011, 1, 1, 1, 0, 0),
|
||||
datetime.datetime(2011, 1, 1, 4, 0, 0)],
|
||||
transform=lambda d: d)
|
||||
self.assertQuerysetEqual(
|
||||
datetime.datetime(2011, 1, 1, 4, 0, 0)]
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
Event.objects.datetimes('dt', 'minute'),
|
||||
[datetime.datetime(2011, 1, 1, 1, 30, 0),
|
||||
datetime.datetime(2011, 1, 1, 4, 30, 0)],
|
||||
transform=lambda d: d)
|
||||
self.assertQuerysetEqual(
|
||||
datetime.datetime(2011, 1, 1, 4, 30, 0)]
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
Event.objects.datetimes('dt', 'second'),
|
||||
[datetime.datetime(2011, 1, 1, 1, 30, 0),
|
||||
datetime.datetime(2011, 1, 1, 4, 30, 0)],
|
||||
transform=lambda d: d)
|
||||
datetime.datetime(2011, 1, 1, 4, 30, 0)]
|
||||
)
|
||||
|
||||
def test_raw_sql(self):
|
||||
# Regression test for #17755
|
||||
dt = datetime.datetime(2011, 9, 1, 13, 20, 30)
|
||||
event = Event.objects.create(dt=dt)
|
||||
self.assertQuerysetEqual(
|
||||
Event.objects.raw('SELECT * FROM timezones_event WHERE dt = %s', [dt]),
|
||||
[event],
|
||||
transform=lambda d: d)
|
||||
self.assertSequenceEqual(list(Event.objects.raw('SELECT * FROM timezones_event WHERE dt = %s', [dt])), [event])
|
||||
|
||||
def test_cursor_execute_accepts_naive_datetime(self):
|
||||
dt = datetime.datetime(2011, 9, 1, 13, 20, 30)
|
||||
|
@ -469,78 +457,75 @@ class NewDatabaseTests(TestCase):
|
|||
def test_query_datetimes(self):
|
||||
Event.objects.create(dt=datetime.datetime(2011, 1, 1, 1, 30, 0, tzinfo=EAT))
|
||||
Event.objects.create(dt=datetime.datetime(2011, 1, 1, 4, 30, 0, tzinfo=EAT))
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Event.objects.datetimes('dt', 'year'),
|
||||
[datetime.datetime(2011, 1, 1, 0, 0, 0, tzinfo=EAT)],
|
||||
transform=lambda d: d)
|
||||
self.assertQuerysetEqual(
|
||||
[datetime.datetime(2011, 1, 1, 0, 0, 0, tzinfo=EAT)]
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
Event.objects.datetimes('dt', 'month'),
|
||||
[datetime.datetime(2011, 1, 1, 0, 0, 0, tzinfo=EAT)],
|
||||
transform=lambda d: d)
|
||||
self.assertQuerysetEqual(
|
||||
[datetime.datetime(2011, 1, 1, 0, 0, 0, tzinfo=EAT)]
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
Event.objects.datetimes('dt', 'day'),
|
||||
[datetime.datetime(2011, 1, 1, 0, 0, 0, tzinfo=EAT)],
|
||||
transform=lambda d: d)
|
||||
self.assertQuerysetEqual(
|
||||
[datetime.datetime(2011, 1, 1, 0, 0, 0, tzinfo=EAT)]
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
Event.objects.datetimes('dt', 'hour'),
|
||||
[datetime.datetime(2011, 1, 1, 1, 0, 0, tzinfo=EAT),
|
||||
datetime.datetime(2011, 1, 1, 4, 0, 0, tzinfo=EAT)],
|
||||
transform=lambda d: d)
|
||||
self.assertQuerysetEqual(
|
||||
datetime.datetime(2011, 1, 1, 4, 0, 0, tzinfo=EAT)]
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
Event.objects.datetimes('dt', 'minute'),
|
||||
[datetime.datetime(2011, 1, 1, 1, 30, 0, tzinfo=EAT),
|
||||
datetime.datetime(2011, 1, 1, 4, 30, 0, tzinfo=EAT)],
|
||||
transform=lambda d: d)
|
||||
self.assertQuerysetEqual(
|
||||
datetime.datetime(2011, 1, 1, 4, 30, 0, tzinfo=EAT)]
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
Event.objects.datetimes('dt', 'second'),
|
||||
[datetime.datetime(2011, 1, 1, 1, 30, 0, tzinfo=EAT),
|
||||
datetime.datetime(2011, 1, 1, 4, 30, 0, tzinfo=EAT)],
|
||||
transform=lambda d: d)
|
||||
datetime.datetime(2011, 1, 1, 4, 30, 0, tzinfo=EAT)]
|
||||
)
|
||||
|
||||
@skipUnlessDBFeature('has_zoneinfo_database')
|
||||
def test_query_datetimes_in_other_timezone(self):
|
||||
Event.objects.create(dt=datetime.datetime(2011, 1, 1, 1, 30, 0, tzinfo=EAT))
|
||||
Event.objects.create(dt=datetime.datetime(2011, 1, 1, 4, 30, 0, tzinfo=EAT))
|
||||
with timezone.override(UTC):
|
||||
self.assertQuerysetEqual(
|
||||
self.assertSequenceEqual(
|
||||
Event.objects.datetimes('dt', 'year'),
|
||||
[datetime.datetime(2010, 1, 1, 0, 0, 0, tzinfo=UTC),
|
||||
datetime.datetime(2011, 1, 1, 0, 0, 0, tzinfo=UTC)],
|
||||
transform=lambda d: d)
|
||||
self.assertQuerysetEqual(
|
||||
datetime.datetime(2011, 1, 1, 0, 0, 0, tzinfo=UTC)]
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
Event.objects.datetimes('dt', 'month'),
|
||||
[datetime.datetime(2010, 12, 1, 0, 0, 0, tzinfo=UTC),
|
||||
datetime.datetime(2011, 1, 1, 0, 0, 0, tzinfo=UTC)],
|
||||
transform=lambda d: d)
|
||||
self.assertQuerysetEqual(
|
||||
datetime.datetime(2011, 1, 1, 0, 0, 0, tzinfo=UTC)]
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
Event.objects.datetimes('dt', 'day'),
|
||||
[datetime.datetime(2010, 12, 31, 0, 0, 0, tzinfo=UTC),
|
||||
datetime.datetime(2011, 1, 1, 0, 0, 0, tzinfo=UTC)],
|
||||
transform=lambda d: d)
|
||||
self.assertQuerysetEqual(
|
||||
datetime.datetime(2011, 1, 1, 0, 0, 0, tzinfo=UTC)]
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
Event.objects.datetimes('dt', 'hour'),
|
||||
[datetime.datetime(2010, 12, 31, 22, 0, 0, tzinfo=UTC),
|
||||
datetime.datetime(2011, 1, 1, 1, 0, 0, tzinfo=UTC)],
|
||||
transform=lambda d: d)
|
||||
self.assertQuerysetEqual(
|
||||
datetime.datetime(2011, 1, 1, 1, 0, 0, tzinfo=UTC)]
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
Event.objects.datetimes('dt', 'minute'),
|
||||
[datetime.datetime(2010, 12, 31, 22, 30, 0, tzinfo=UTC),
|
||||
datetime.datetime(2011, 1, 1, 1, 30, 0, tzinfo=UTC)],
|
||||
transform=lambda d: d)
|
||||
self.assertQuerysetEqual(
|
||||
datetime.datetime(2011, 1, 1, 1, 30, 0, tzinfo=UTC)]
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
Event.objects.datetimes('dt', 'second'),
|
||||
[datetime.datetime(2010, 12, 31, 22, 30, 0, tzinfo=UTC),
|
||||
datetime.datetime(2011, 1, 1, 1, 30, 0, tzinfo=UTC)],
|
||||
transform=lambda d: d)
|
||||
datetime.datetime(2011, 1, 1, 1, 30, 0, tzinfo=UTC)]
|
||||
)
|
||||
|
||||
def test_raw_sql(self):
|
||||
# Regression test for #17755
|
||||
dt = datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT)
|
||||
event = Event.objects.create(dt=dt)
|
||||
self.assertQuerysetEqual(
|
||||
Event.objects.raw('SELECT * FROM timezones_event WHERE dt = %s', [dt]),
|
||||
[event],
|
||||
transform=lambda d: d)
|
||||
self.assertSequenceEqual(list(Event.objects.raw('SELECT * FROM timezones_event WHERE dt = %s', [dt])), [event])
|
||||
|
||||
@skipUnlessDBFeature('supports_timezones')
|
||||
def test_cursor_execute_accepts_aware_datetime(self):
|
||||
|
|
Loading…
Reference in New Issue