summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2011-04-26 16:49:32 +0000
committerAlex Gaynor <alex.gaynor@gmail.com>2011-04-26 16:49:32 +0000
commit930371e91b03f91691fa5e2e4f428cb72469e191 (patch)
tree05c740455fc84e8341a1efa6007ef517374e58ce /tests
parent1b6670dd590ef8f235166ce966d28ac49f322c54 (diff)
Fixed #15889 -- when trying to access to access a serializer that doesn't exist, raise a new SerializerDoesNotExist exception. Thanks to Mathieu Agopian for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16104 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/serializers_regress/tests.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/tests/regressiontests/serializers_regress/tests.py b/tests/regressiontests/serializers_regress/tests.py
index de57a6f0de..97b2a792eb 100644
--- a/tests/regressiontests/serializers_regress/tests.py
+++ b/tests/regressiontests/serializers_regress/tests.py
@@ -6,7 +6,7 @@ test case that is capable of testing the capabilities of
the serializers. This includes all valid data values, plus
forward, backwards and self references.
"""
-
+from __future__ import with_statement
import datetime
import decimal
@@ -17,6 +17,7 @@ except ImportError:
from django.conf import settings
from django.core import serializers, management
+from django.core.serializers import SerializerDoesNotExist
from django.db import transaction, DEFAULT_DB_ALIAS, connection
from django.test import TestCase
from django.utils.functional import curry
@@ -350,7 +351,28 @@ if connection.features.allows_primary_key_0:
# Dynamically create serializer tests to ensure that all
# registered serializers are automatically tested.
class SerializerTests(TestCase):
- pass
+ def test_get_unknown_serializer(self):
+ """
+ #15889: get_serializer('nonsense') raises a SerializerDoesNotExist
+ """
+ with self.assertRaises(SerializerDoesNotExist):
+ serializers.get_serializer("nonsense")
+
+ with self.assertRaises(KeyError):
+ serializers.get_serializer("nonsense")
+
+ # SerializerDoesNotExist is instantiated with the nonexistent format
+ with self.assertRaises(SerializerDoesNotExist) as cm:
+ serializers.get_serializer("nonsense")
+ self.assertEqual(cm.exception.args, ("nonsense",))
+
+ def test_unregister_unkown_serializer(self):
+ with self.assertRaises(SerializerDoesNotExist):
+ serializers.unregister_serializer("nonsense")
+
+ def test_get_unkown_deserializer(self):
+ with self.assertRaises(SerializerDoesNotExist):
+ serializers.get_deserializer("nonsense")
def serializerTest(format, self):