summaryrefslogtreecommitdiff
path: root/tests/custom_lookups
diff options
context:
space:
mode:
authorRyan P Kilby <rpkilby@ncsu.edu>2016-08-11 14:16:48 -0400
committerTim Graham <timograham@gmail.com>2016-08-11 14:16:48 -0400
commit7aeb7390fc4231119494a9ebdee3c6ee0d5af053 (patch)
treeac6fed4d48bd5f0e6ca0957d60db4d46e133b767 /tests/custom_lookups
parentff0a5aff4f5eb2f55fa4c45d316084ee4d462d6d (diff)
downloaddjango-7aeb7390fc4231119494a9ebdee3c6ee0d5af053.tar.gz
Fixed #26891 -- Fixed lookup registration for ForeignObject.
Diffstat (limited to 'tests/custom_lookups')
-rw-r--r--tests/custom_lookups/models.py4
-rw-r--r--tests/custom_lookups/tests.py24
2 files changed, 27 insertions, 1 deletions
diff --git a/tests/custom_lookups/models.py b/tests/custom_lookups/models.py
index 82a835e160..97979dd953 100644
--- a/tests/custom_lookups/models.py
+++ b/tests/custom_lookups/models.py
@@ -13,6 +13,10 @@ class Author(models.Model):
return self.name
+class Article(models.Model):
+ author = models.ForeignKey(Author, on_delete=models.CASCADE)
+
+
@python_2_unicode_compatible
class MySQLUnixTimestamp(models.Model):
timestamp = models.PositiveIntegerField()
diff --git a/tests/custom_lookups/tests.py b/tests/custom_lookups/tests.py
index c538d23b76..da9274904c 100644
--- a/tests/custom_lookups/tests.py
+++ b/tests/custom_lookups/tests.py
@@ -10,7 +10,7 @@ from django.db import connection, models
from django.test import TestCase, override_settings
from django.utils import timezone
-from .models import Author, MySQLUnixTimestamp
+from .models import Article, Author, MySQLUnixTimestamp
@contextlib.contextmanager
@@ -319,6 +319,28 @@ class LookupTests(TestCase):
baseqs.filter(age__div3__range=(1, 2)),
[a1, a2, a4], lambda x: x)
+ def test_foreignobject_lookup_registration(self):
+ field = Article._meta.get_field('author')
+
+ with register_lookup(models.ForeignObject, Exactly):
+ self.assertIs(field.get_lookup('exactly'), Exactly)
+
+ # ForeignObject should ignore regular Field lookups
+ with register_lookup(models.Field, Exactly):
+ self.assertIsNone(field.get_lookup('exactly'))
+
+ def test_lookups_caching(self):
+ field = Article._meta.get_field('author')
+
+ # clear and re-cache
+ field.get_lookups.cache_clear()
+ self.assertNotIn('exactly', field.get_lookups())
+
+ # registration should bust the cache
+ with register_lookup(models.ForeignObject, Exactly):
+ # getting the lookups again should re-cache
+ self.assertIn('exactly', field.get_lookups())
+
class BilateralTransformTests(TestCase):