mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #29658 -- Registered model lookups in tests with a context manager.
This commit is contained in:
committed by
Tim Graham
parent
201017df30
commit
233c70f047
@@ -3,6 +3,7 @@ from decimal import Decimal
|
||||
from django.db.models import DecimalField
|
||||
from django.db.models.functions import Round
|
||||
from django.test import TestCase
|
||||
from django.test.utils import register_lookup
|
||||
|
||||
from ..models import DecimalModel, FloatModel, IntegerModel
|
||||
|
||||
@@ -40,11 +41,8 @@ class RoundTests(TestCase):
|
||||
self.assertEqual(obj.big_round, round(obj.big))
|
||||
|
||||
def test_transform(self):
|
||||
try:
|
||||
DecimalField.register_lookup(Round)
|
||||
with register_lookup(DecimalField, Round):
|
||||
DecimalModel.objects.create(n1=Decimal('2.0'), n2=Decimal('0'))
|
||||
DecimalModel.objects.create(n1=Decimal('-1.0'), n2=Decimal('0'))
|
||||
objs = DecimalModel.objects.filter(n1__round__gt=0)
|
||||
self.assertQuerysetEqual(objs, [Decimal('2.0')], lambda a: a.n1)
|
||||
finally:
|
||||
DecimalField._unregister_lookup(Round)
|
||||
|
||||
Reference in New Issue
Block a user