aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/tests/serializer.py
diff options
context:
space:
mode:
authorTom Christie2013-02-26 11:46:07 -0800
committerTom Christie2013-02-26 11:46:07 -0800
commitd59ed6491535d8e3c2fb334835259326a6d0bc7c (patch)
tree2251b21b1f298cc3cfefa88cb8c27c81604390c3 /rest_framework/tests/serializer.py
parent80b0234793321f828979d30015151c8d7900fc9f (diff)
parente476dcb8c70f3792f01214f8d4a13c9316e11341 (diff)
downloaddjango-rest-framework-d59ed6491535d8e3c2fb334835259326a6d0bc7c.tar.bz2
Merge pull request #683 from dbrgn/serializer_exception_msg
Improved exception message for missing serializer model meta option
Diffstat (limited to 'rest_framework/tests/serializer.py')
-rw-r--r--rest_framework/tests/serializer.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/rest_framework/tests/serializer.py b/rest_framework/tests/serializer.py
index 671494b5..36703fd9 100644
--- a/rest_framework/tests/serializer.py
+++ b/rest_framework/tests/serializer.py
@@ -91,6 +91,11 @@ class PositiveIntegerAsChoiceSerializer(serializers.ModelSerializer):
fields = ['some_integer']
+class BrokenModelSerializer(serializers.ModelSerializer):
+ class Meta:
+ fields = ['some_field']
+
+
class BasicTests(TestCase):
def setUp(self):
self.comment = Comment(
@@ -353,6 +358,18 @@ class ValidationTests(TestCase):
self.assertIn('created', serializer.errors)
+ def test_missing_model_field_exception_msg(self):
+ """
+ Assert that a meaningful exception message is outputted when the model
+ field is missing (e.g. when mistyping ``model``).
+ """
+ try:
+ serializer = BrokenModelSerializer()
+ except AssertionError as e:
+ self.assertEquals(e.args[0], "Serializer class 'BrokenModelSerializer' is missing 'model' Meta option")
+ except:
+ self.fail('Wrong exception type thrown.')
+
class CustomValidationTests(TestCase):
class CommentSerializerWithFieldValidator(CommentSerializer):