Add simplest possible failing test

This commit is contained in:
jhg14 2017-09-04 15:41:04 +01:00
parent 3c1bf6bfd5
commit 4345894445

View File

@ -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)