mirror of
https://github.com/django/django.git
synced 2025-12-04 00:55:36 +00:00
Fixed #29658 -- Registered model lookups in tests with a context manager.
This commit is contained in:
parent
201017df30
commit
233c70f047
28 changed files with 78 additions and 143 deletions
|
|
@ -4,6 +4,7 @@ from decimal import Decimal
|
|||
from django.db.models import DecimalField
|
||||
from django.db.models.functions import Sqrt
|
||||
from django.test import TestCase
|
||||
from django.test.utils import register_lookup
|
||||
|
||||
from ..models import DecimalModel, FloatModel, IntegerModel
|
||||
|
||||
|
|
@ -41,11 +42,8 @@ class SqrtTests(TestCase):
|
|||
self.assertAlmostEqual(obj.big_sqrt, math.sqrt(obj.big))
|
||||
|
||||
def test_transform(self):
|
||||
try:
|
||||
DecimalField.register_lookup(Sqrt)
|
||||
with register_lookup(DecimalField, Sqrt):
|
||||
DecimalModel.objects.create(n1=Decimal('6.0'), n2=Decimal('0'))
|
||||
DecimalModel.objects.create(n1=Decimal('1.0'), n2=Decimal('0'))
|
||||
objs = DecimalModel.objects.filter(n1__sqrt__gt=2)
|
||||
self.assertQuerysetEqual(objs, [Decimal('6.0')], lambda a: a.n1)
|
||||
finally:
|
||||
DecimalField._unregister_lookup(Sqrt)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue