Adding < django 1.6 flags in code and test
parent
a16345874e
commit
d714040331
|
|
@ -100,7 +100,8 @@ def translate_polymorphic_filter_definitions_in_args(queryset_model, args, using
|
||||||
|
|
||||||
Returns: modified Q objects
|
Returns: modified Q objects
|
||||||
"""
|
"""
|
||||||
return [translate_polymorphic_Q_object(queryset_model, q.clone(), using=using) for q in args]
|
q_objects = [q if django.VERSION < (1, 6) else q.clone() for q in args]
|
||||||
|
return [translate_polymorphic_Q_object(queryset_model, q, using=using) for q in q_objects]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -824,6 +824,7 @@ class PolymorphicTests(TestCase):
|
||||||
self.assertEqual(repr(objects[0]), '<Model2B: id 2, field1 (CharField), field2 (CharField)>')
|
self.assertEqual(repr(objects[0]), '<Model2B: id 2, field1 (CharField), field2 (CharField)>')
|
||||||
self.assertEqual(repr(objects[1]), '<Model2C: id 3, field1 (CharField), field2 (CharField), field3 (CharField)>')
|
self.assertEqual(repr(objects[1]), '<Model2C: id 3, field1 (CharField), field2 (CharField), field3 (CharField)>')
|
||||||
|
|
||||||
|
@skipIf(django.VERSION < (1, 6), "Django 1.4 and 1.5 don't support q.clone()")
|
||||||
def test_query_filter_exclude_is_immutable(self):
|
def test_query_filter_exclude_is_immutable(self):
|
||||||
# given
|
# given
|
||||||
q_to_reuse = Q(Model2B___field2='something')
|
q_to_reuse = Q(Model2B___field2='something')
|
||||||
|
|
@ -1127,32 +1128,32 @@ class PolymorphicTests(TestCase):
|
||||||
|
|
||||||
# test that we can delete the object
|
# test that we can delete the object
|
||||||
t.delete()
|
t.delete()
|
||||||
|
|
||||||
def test_polymorphic__aggregate(self):
|
def test_polymorphic__aggregate(self):
|
||||||
""" test ModelX___field syntax on aggregate (should work for annotate either) """
|
""" test ModelX___field syntax on aggregate (should work for annotate either) """
|
||||||
|
|
||||||
Model2A.objects.create(field1='A1')
|
Model2A.objects.create(field1='A1')
|
||||||
Model2B.objects.create(field1='A1', field2='B2')
|
Model2B.objects.create(field1='A1', field2='B2')
|
||||||
Model2B.objects.create(field1='A1', field2='B2')
|
Model2B.objects.create(field1='A1', field2='B2')
|
||||||
|
|
||||||
# aggregate using **kwargs
|
# aggregate using **kwargs
|
||||||
result = Model2A.objects.aggregate(cnt=Count('Model2B___field2'))
|
result = Model2A.objects.aggregate(cnt=Count('Model2B___field2'))
|
||||||
self.assertEqual(result, {'cnt': 2})
|
self.assertEqual(result, {'cnt': 2})
|
||||||
|
|
||||||
# aggregate using **args
|
# aggregate using **args
|
||||||
with self.assertRaisesMessage(AssertionError, 'PolymorphicModel: annotate()/aggregate(): ___ model lookup supported for keyword arguments only'):
|
with self.assertRaisesMessage(AssertionError, 'PolymorphicModel: annotate()/aggregate(): ___ model lookup supported for keyword arguments only'):
|
||||||
Model2A.objects.aggregate(Count('Model2B___field2'))
|
Model2A.objects.aggregate(Count('Model2B___field2'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@skipIf(django.VERSION < (1,8,), "This test needs Django >=1.8")
|
@skipIf(django.VERSION < (1,8,), "This test needs Django >=1.8")
|
||||||
def test_polymorphic__complex_aggregate(self):
|
def test_polymorphic__complex_aggregate(self):
|
||||||
""" test (complex expression on) aggregate (should work for annotate either) """
|
""" test (complex expression on) aggregate (should work for annotate either) """
|
||||||
|
|
||||||
Model2A.objects.create(field1='A1')
|
Model2A.objects.create(field1='A1')
|
||||||
Model2B.objects.create(field1='A1', field2='B2')
|
Model2B.objects.create(field1='A1', field2='B2')
|
||||||
Model2B.objects.create(field1='A1', field2='B2')
|
Model2B.objects.create(field1='A1', field2='B2')
|
||||||
|
|
||||||
# aggregate using **kwargs
|
# aggregate using **kwargs
|
||||||
result = Model2A.objects.aggregate(
|
result = Model2A.objects.aggregate(
|
||||||
cnt_a1=Count(Case(When(field1='A1', then=1))),
|
cnt_a1=Count(Case(When(field1='A1', then=1))),
|
||||||
|
|
@ -1167,7 +1168,7 @@ class PolymorphicTests(TestCase):
|
||||||
complexagg = Count(expression)*10
|
complexagg = Count(expression)*10
|
||||||
complexagg.default_alias = 'complexagg'
|
complexagg.default_alias = 'complexagg'
|
||||||
return complexagg
|
return complexagg
|
||||||
|
|
||||||
with self.assertRaisesMessage(AssertionError, 'PolymorphicModel: annotate()/aggregate(): ___ model lookup supported for keyword arguments only'):
|
with self.assertRaisesMessage(AssertionError, 'PolymorphicModel: annotate()/aggregate(): ___ model lookup supported for keyword arguments only'):
|
||||||
Model2A.objects.aggregate(ComplexAgg('Model2B___field2'))
|
Model2A.objects.aggregate(ComplexAgg('Model2B___field2'))
|
||||||
|
|
||||||
|
|
@ -1186,7 +1187,7 @@ class PolymorphicTests(TestCase):
|
||||||
Model2C(field1='C1', field2='C2', field3='C3').save(using='secondary')
|
Model2C(field1='C1', field2='C2', field3='C3').save(using='secondary')
|
||||||
Model2B.objects.create(field1='B1', field2='B2')
|
Model2B.objects.create(field1='B1', field2='B2')
|
||||||
Model2D(field1='D1', field2='D2', field3='D3', field4='D4').save('secondary')
|
Model2D(field1='D1', field2='D2', field3='D3', field4='D4').save('secondary')
|
||||||
|
|
||||||
default_objects = list(Model2A.objects.order_by('id'))
|
default_objects = list(Model2A.objects.order_by('id'))
|
||||||
self.assertEqual(len(default_objects), 2)
|
self.assertEqual(len(default_objects), 2)
|
||||||
self.assertEqual(repr(default_objects[0]), '<Model2B: id 1, field1 (CharField), field2 (CharField)>')
|
self.assertEqual(repr(default_objects[0]), '<Model2B: id 1, field1 (CharField), field2 (CharField)>')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue