diff options
| author | Tim Graham <timograham@gmail.com> | 2013-08-19 09:35:26 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-08-22 17:49:11 -0400 |
| commit | 616a4d385a79d6809b618dcc8bcbda05b032d5fc (patch) | |
| tree | ee40caee925ddc8ab4823edb2611945ae66443ae /tests | |
| parent | 1b236048b9a915296dc13081fad7bb75d0ff1f4d (diff) | |
[1.5.x] Fixed #20922 -- Allowed customizing the serializer used by contrib.sessions
Added settings.SESSION_SERIALIZER which is the import path of a serializer
to use for sessions.
Thanks apollo13, carljm, shaib, akaariai, charettes, and dstufft for reviews.
Backport of b0ce6fe656 from master
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/defer_regress/tests.py | 40 | ||||
| -rw-r--r-- | tests/regressiontests/utils/module_loading.py | 20 |
2 files changed, 41 insertions, 19 deletions
diff --git a/tests/regressiontests/defer_regress/tests.py b/tests/regressiontests/defer_regress/tests.py index d4d722035f..0bd0eedf01 100644 --- a/tests/regressiontests/defer_regress/tests.py +++ b/tests/regressiontests/defer_regress/tests.py @@ -7,6 +7,7 @@ from django.contrib.sessions.backends.db import SessionStore from django.db.models import Count from django.db.models.loading import cache from django.test import TestCase +from django.test.utils import override_settings from .models import (ResolveThis, Item, RelatedItem, Child, Leaf, Proxy, SimpleItem, Feature, ItemAndSimpleItem, OneToOneItem, SpecialFeature) @@ -80,24 +81,6 @@ class DeferRegressionTest(TestCase): self.assertEqual(results[0].child.name, "c1") self.assertEqual(results[0].second_child.name, "c2") - # Test for #12163 - Pickling error saving session with unsaved model - # instances. - SESSION_KEY = '2b1189a188b44ad18c35e1baac6ceead' - - item = Item() - item._deferred = False - s = SessionStore(SESSION_KEY) - s.clear() - s["item"] = item - s.save() - - s = SessionStore(SESSION_KEY) - s.modified = True - s.save() - - i2 = s["item"] - self.assertFalse(i2._deferred) - # Regression for #11936 - loading.get_models should not return deferred # models by default. klasses = sorted( @@ -159,6 +142,27 @@ class DeferRegressionTest(TestCase): ] ) + @override_settings(SESSION_SERIALIZER='django.contrib.sessions.serializers.PickleSerializer') + def test_ticket_12163(self): + # Test for #12163 - Pickling error saving session with unsaved model + # instances. + SESSION_KEY = '2b1189a188b44ad18c35e1baac6ceead' + + item = Item() + item._deferred = False + s = SessionStore(SESSION_KEY) + s.clear() + s["item"] = item + s.save() + + s = SessionStore(SESSION_KEY) + s.modified = True + s.save() + + i2 = s["item"] + self.assertFalse(i2._deferred) + + def test_ticket_16409(self): # Regression for #16409 - make sure defer() and only() work with annotate() self.assertIsInstance(list(SimpleItem.objects.annotate(Count('feature')).defer('name')), list) self.assertIsInstance(list(SimpleItem.objects.annotate(Count('feature')).only('name')), list) diff --git a/tests/regressiontests/utils/module_loading.py b/tests/regressiontests/utils/module_loading.py index 3fc92b0862..a9e3706bb9 100644 --- a/tests/regressiontests/utils/module_loading.py +++ b/tests/regressiontests/utils/module_loading.py @@ -3,9 +3,10 @@ import sys import imp from zipimport import zipimporter +from django.core.exceptions import ImproperlyConfigured from django.utils import unittest from django.utils.importlib import import_module -from django.utils.module_loading import module_has_submodule +from django.utils.module_loading import import_by_path, module_has_submodule from django.utils._os import upath @@ -103,6 +104,23 @@ class EggLoader(unittest.TestCase): self.assertFalse(module_has_submodule(egg_module, 'no_such_module')) self.assertRaises(ImportError, import_module, 'egg_module.sub1.sub2.no_such_module') + +class ModuleImportTestCase(unittest.TestCase): + def test_import_by_path(self): + cls = import_by_path( + 'django.utils.module_loading.import_by_path') + self.assertEqual(cls, import_by_path) + + # Test exceptions raised + for path in ('no_dots_in_path', 'unexistent.path', + 'tests.regressiontests.utils.unexistent'): + self.assertRaises(ImproperlyConfigured, import_by_path, path) + + with self.assertRaises(ImproperlyConfigured) as cm: + import_by_path('unexistent.module.path', error_prefix="Foo") + self.assertTrue(str(cm.exception).startswith('Foo')) + + class ProxyFinder(object): def __init__(self): self._cache = {} |
