diff options
| author | Tom Christie | 2014-09-24 20:53:37 +0100 | 
|---|---|---|
| committer | Tom Christie | 2014-09-24 20:53:37 +0100 | 
| commit | fb1546ee50953faae8af505a0c90da00ac08ad92 (patch) | |
| tree | 8840488b273557672cba6f403f37b4f2d0630697 /tests/test_fields.py | |
| parent | 127c0bd3d68860dd6567d81047257fbc3e70b4b9 (diff) | |
| download | django-rest-framework-fb1546ee50953faae8af505a0c90da00ac08ad92.tar.bz2 | |
Enforce field_name != source
Diffstat (limited to 'tests/test_fields.py')
| -rw-r--r-- | tests/test_fields.py | 13 | 
1 files changed, 12 insertions, 1 deletions
| diff --git a/tests/test_fields.py b/tests/test_fields.py index 91f3f5db..c2e03023 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1,6 +1,6 @@  from decimal import Decimal  from django.utils import timezone -from rest_framework import fields +from rest_framework import fields, serializers  import datetime  import django  import pytest @@ -69,6 +69,17 @@ class TestFieldOptions:          output = field.run_validation()          assert output is 123 +    def test_redundant_source(self): +        class ExampleSerializer(serializers.Serializer): +            example_field = serializers.CharField(source='example_field') +        with pytest.raises(AssertionError) as exc_info: +            ExampleSerializer() +        assert str(exc_info.value) == ( +            "It is redundant to specify `source='example_field'` on field " +            "'CharField' in serializer 'ExampleSerializer', as it is the " +            "same the field name. Remove the `source` keyword argument." +        ) +  # Tests for field input and output values.  # ---------------------------------------- | 
