Used operator.attrgetter() in test_qs_combinators.

This commit is contained in:
Laurent Tramoy 2020-05-26 08:50:19 +02:00 committed by Mariusz Felisiak
parent 33c365781a
commit 50f71ccb36
1 changed files with 3 additions and 4 deletions

View File

@ -1,3 +1,5 @@
import operator
from django.db import DatabaseError, NotSupportedError, connection from django.db import DatabaseError, NotSupportedError, connection
from django.db.models import Exists, F, IntegerField, OuterRef, Value from django.db.models import Exists, F, IntegerField, OuterRef, Value
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
@ -11,11 +13,8 @@ class QuerySetSetOperationTests(TestCase):
def setUpTestData(cls): def setUpTestData(cls):
Number.objects.bulk_create(Number(num=i, other_num=10 - i) for i in range(10)) Number.objects.bulk_create(Number(num=i, other_num=10 - i) for i in range(10))
def number_transform(self, value):
return value.num
def assertNumbersEqual(self, queryset, expected_numbers, ordered=True): def assertNumbersEqual(self, queryset, expected_numbers, ordered=True):
self.assertQuerysetEqual(queryset, expected_numbers, self.number_transform, ordered) self.assertQuerysetEqual(queryset, expected_numbers, operator.attrgetter('num'), ordered)
def test_simple_union(self): def test_simple_union(self):
qs1 = Number.objects.filter(num__lte=1) qs1 = Number.objects.filter(num__lte=1)