mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Add failing test for named attribute
Fix test crudely Remove comment
This commit is contained in:
parent
7cd59147ea
commit
3c1bf6bfd5
|
@ -1010,7 +1010,9 @@ class ModelSerializer(Serializer):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
extra_field_kwargs = extra_kwargs.get(field_name, {})
|
extra_field_kwargs = extra_kwargs.get(field_name, {})
|
||||||
source = extra_field_kwargs.get('source', '*') != '*' or field_name
|
source = extra_field_kwargs.get('source', '*')
|
||||||
|
if source == '*':
|
||||||
|
source = field_name
|
||||||
|
|
||||||
# Determine the serializer field class and keyword arguments.
|
# Determine the serializer field class and keyword arguments.
|
||||||
field_class, field_kwargs = self.build_field(
|
field_class, field_kwargs = self.build_field(
|
||||||
|
|
|
@ -557,6 +557,39 @@ class TestRelationalFieldMappings(TestCase):
|
||||||
self.maxDiff = None
|
self.maxDiff = None
|
||||||
self.assertEqual(unicode_repr(TestSerializer()), expected)
|
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):
|
def test_nested_unique_together_relations(self):
|
||||||
class TestSerializer(serializers.HyperlinkedModelSerializer):
|
class TestSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user