1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +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 Upper
from django.test import TestCase
from django.test.utils import register_lookup
from ..models import Author
@@ -28,8 +29,7 @@ class UpperTests(TestCase):
)
def test_transform(self):
try:
CharField.register_lookup(Upper)
with register_lookup(CharField, Upper):
Author.objects.create(name='John Smith', alias='smithj')
Author.objects.create(name='Rhonda')
authors = Author.objects.filter(name__upper__exact='JOHN SMITH')
@@ -39,5 +39,3 @@ class UpperTests(TestCase):
],
lambda a: a.name
)
finally:
CharField._unregister_lookup(Upper)