diff options
| author | Tom Christie | 2014-12-15 09:18:11 +0000 |
|---|---|---|
| committer | Tom Christie | 2014-12-15 09:18:11 +0000 |
| commit | 4778463e32550f3bf9aa350925b1260343bced99 (patch) | |
| tree | 5ea0a151d588d603e5d86b75c48692e35e6d5a02 /tests/test_serializer.py | |
| parent | 26131a7aea39bb517393b3b6774372d6aebd6885 (diff) | |
| parent | a72f812d80a4000e86a5ad96001f3fbf43fe310a (diff) | |
| download | django-rest-framework-4778463e32550f3bf9aa350925b1260343bced99.tar.bz2 | |
Merge branch 'master' into version-3.1
Diffstat (limited to 'tests/test_serializer.py')
| -rw-r--r-- | tests/test_serializer.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test_serializer.py b/tests/test_serializer.py index 6dabaf42..56b39095 100644 --- a/tests/test_serializer.py +++ b/tests/test_serializer.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals from rest_framework import serializers import pytest @@ -175,3 +176,24 @@ class TestStarredSource: instance = {'a': 1, 'b': 2, 'c': 3, 'd': 4} serializer = self.Serializer(instance) assert serializer.data == self.data + + +class TestIncorrectlyConfigured: + def test_incorrect_field_name(self): + class ExampleSerializer(serializers.Serializer): + incorrect_name = serializers.IntegerField() + + class ExampleObject: + def __init__(self): + self.correct_name = 123 + + instance = ExampleObject() + serializer = ExampleSerializer(instance) + with pytest.raises(AttributeError) as exc_info: + serializer.data + msg = str(exc_info.value) + assert msg.startswith( + "Got AttributeError when attempting to get a value for field `incorrect_name` on serializer `ExampleSerializer`.\n" + "The serializer field might be named incorrectly and not match any attribute or key on the `ExampleObject` instance.\n" + "Original exception text was:" + ) |
