From 43458944452fe11132fa1ab5f2bf1934b8fc108f Mon Sep 17 00:00:00 2001 From: jhg14 Date: Mon, 4 Sep 2017 15:41:04 +0100 Subject: [PATCH] Add simplest possible failing test --- tests/test_model_serializer.py | 55 ++++++++++++++-------------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/tests/test_model_serializer.py b/tests/test_model_serializer.py index ce054f695..430be71c6 100644 --- a/tests/test_model_serializer.py +++ b/tests/test_model_serializer.py @@ -557,39 +557,6 @@ class TestRelationalFieldMappings(TestCase): self.maxDiff = None self.assertEqual(unicode_repr(TestSerializer()), expected) - def test_nested_hyperlinked_relations_named_source(self): - class TestSerializer(serializers.HyperlinkedModelSerializer): - class Meta: - model = RelationalModel - depth = 1 - fields = '__all__' - - extra_kwargs = { - 'url': { - 'source': 'url' - }} - - expected = dedent(""" - TestSerializer(): - url = HyperlinkedIdentityField(source='url', view_name='relationalmodel-detail') - foreign_key = NestedSerializer(read_only=True): - url = HyperlinkedIdentityField(view_name='foreignkeytargetmodel-detail') - name = CharField(max_length=100) - one_to_one = NestedSerializer(read_only=True): - url = HyperlinkedIdentityField(view_name='onetoonetargetmodel-detail') - name = CharField(max_length=100) - many_to_many = NestedSerializer(many=True, read_only=True): - url = HyperlinkedIdentityField(view_name='manytomanytargetmodel-detail') - name = CharField(max_length=100) - through = NestedSerializer(many=True, read_only=True): - url = HyperlinkedIdentityField(view_name='throughtargetmodel-detail') - name = CharField(max_length=100) - """) - self.maxDiff = None - self.assertEqual(unicode_repr(TestSerializer()), expected) - - - def test_nested_unique_together_relations(self): class TestSerializer(serializers.HyperlinkedModelSerializer): class Meta: @@ -1168,3 +1135,25 @@ class Test5004UniqueChoiceField(TestCase): serializer = TestUniqueChoiceSerializer(data={'name': 'choice1'}) assert not serializer.is_valid() assert serializer.errors == {'name': ['unique choice model with this name already exists.']} + +class TestFieldSource(TestCase): + + def test_named_field_source(self): + class TestSerializer(serializers.ModelSerializer): + + class Meta: + model = RegularFieldsModel + fields = ('number_field',) + extra_kwargs = { + 'number_field': { + 'source': 'integer_field' + } + } + + expected = dedent(""" + TestSerializer(): + number_field = IntegerField(source='integer_field') + """) + self.maxDiff = None + self.assertEqual(unicode_repr(TestSerializer()), expected) +