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 IntegerField
from django.db.models.functions import Chr, Left, Ord
from django.test import TestCase
from django.test.utils import register_lookup
from ..models import Author
@@ -23,10 +24,7 @@ class ChrTests(TestCase):
self.assertCountEqual(authors.exclude(first_initial=Chr(ord('É'))), [self.john, self.rhonda])
def test_transform(self):
try:
IntegerField.register_lookup(Chr)
with register_lookup(IntegerField, Chr):
authors = Author.objects.annotate(name_code_point=Ord('name'))
self.assertCountEqual(authors.filter(name_code_point__chr=Chr(ord('J'))), [self.john])
self.assertCountEqual(authors.exclude(name_code_point__chr=Chr(ord('J'))), [self.elena, self.rhonda])
finally:
IntegerField._unregister_lookup(Chr)