summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarkus Holtermann <info@markusholtermann.eu>2015-08-22 23:40:34 +1000
committerMarkus Holtermann <info@markusholtermann.eu>2015-08-27 17:06:21 +1000
commite1427cc609fa6ab247501b101cfb3c0092aba55b (patch)
treecd3a323b08fcb8301b267ce5aa784da41d2339e2 /tests
parent91f701f4fc324cd2feb7dbf151338a358ca0ea18 (diff)
Fixed #24590 -- Cached calls to swappable_setting.
Moved the lookup in Field.swappable_setting to Apps, and added an lru_cache to cache the results. Refs #24743 Thanks Marten Kenbeek for the initial work on the patch. Thanks Aymeric Augustin and Tim Graham for the review.
Diffstat (limited to 'tests')
-rw-r--r--tests/field_deconstruction/tests.py36
1 files changed, 20 insertions, 16 deletions
diff --git a/tests/field_deconstruction/tests.py b/tests/field_deconstruction/tests.py
index c1cc083fc5..5e04552ff4 100644
--- a/tests/field_deconstruction/tests.py
+++ b/tests/field_deconstruction/tests.py
@@ -1,7 +1,9 @@
from __future__ import unicode_literals
+from django.apps import apps
from django.db import models
from django.test import SimpleTestCase, override_settings
+from django.test.utils import isolate_lru_cache
from django.utils import six
@@ -219,14 +221,15 @@ class FieldDeconstructionTests(SimpleTestCase):
@override_settings(AUTH_USER_MODEL="auth.Permission")
def test_foreign_key_swapped(self):
- # It doesn't matter that we swapped out user for permission;
- # there's no validation. We just want to check the setting stuff works.
- field = models.ForeignKey("auth.Permission", models.CASCADE)
- name, path, args, kwargs = field.deconstruct()
- self.assertEqual(path, "django.db.models.ForeignKey")
- self.assertEqual(args, [])
- self.assertEqual(kwargs, {"to": "auth.Permission", "on_delete": models.CASCADE})
- self.assertEqual(kwargs['to'].setting_name, "AUTH_USER_MODEL")
+ with isolate_lru_cache(apps.get_swappable_settings_name):
+ # It doesn't matter that we swapped out user for permission;
+ # there's no validation. We just want to check the setting stuff works.
+ field = models.ForeignKey("auth.Permission", models.CASCADE)
+ name, path, args, kwargs = field.deconstruct()
+ self.assertEqual(path, "django.db.models.ForeignKey")
+ self.assertEqual(args, [])
+ self.assertEqual(kwargs, {"to": "auth.Permission", "on_delete": models.CASCADE})
+ self.assertEqual(kwargs['to'].setting_name, "AUTH_USER_MODEL")
def test_image_field(self):
field = models.ImageField(upload_to="foo/barness", width_field="width", height_field="height")
@@ -297,14 +300,15 @@ class FieldDeconstructionTests(SimpleTestCase):
@override_settings(AUTH_USER_MODEL="auth.Permission")
def test_many_to_many_field_swapped(self):
- # It doesn't matter that we swapped out user for permission;
- # there's no validation. We just want to check the setting stuff works.
- field = models.ManyToManyField("auth.Permission")
- name, path, args, kwargs = field.deconstruct()
- self.assertEqual(path, "django.db.models.ManyToManyField")
- self.assertEqual(args, [])
- self.assertEqual(kwargs, {"to": "auth.Permission"})
- self.assertEqual(kwargs['to'].setting_name, "AUTH_USER_MODEL")
+ with isolate_lru_cache(apps.get_swappable_settings_name):
+ # It doesn't matter that we swapped out user for permission;
+ # there's no validation. We just want to check the setting stuff works.
+ field = models.ManyToManyField("auth.Permission")
+ name, path, args, kwargs = field.deconstruct()
+ self.assertEqual(path, "django.db.models.ManyToManyField")
+ self.assertEqual(args, [])
+ self.assertEqual(kwargs, {"to": "auth.Permission"})
+ self.assertEqual(kwargs['to'].setting_name, "AUTH_USER_MODEL")
def test_null_boolean_field(self):
field = models.NullBooleanField()