1
0
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:
Srinivas Reddy Thatiparthy (శ్రీనివాస్ రెడ్డి తాటిపర్తి)
2018-08-21 21:47:46 +05:30
committed by Tim Graham
parent 201017df30
commit 233c70f047
28 changed files with 78 additions and 143 deletions

View File

@@ -1,6 +1,7 @@
from django.db.models import CharField
from django.db.models.functions import LTrim, RTrim, Trim
from django.test import TestCase
from django.test.utils import register_lookup
from ..models import Author
@@ -32,9 +33,6 @@ class TrimTests(TestCase):
)
for transform, trimmed_name in tests:
with self.subTest(transform=transform):
try:
CharField.register_lookup(transform)
with register_lookup(CharField, transform):
authors = Author.objects.filter(**{'name__%s' % transform.lookup_name: trimmed_name})
self.assertQuerysetEqual(authors, [' John '], lambda a: a.name)
finally:
CharField._unregister_lookup(transform)