mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Add test for hyperlinked reverse FK create. Refs #511
This commit is contained in:
parent
0176fab475
commit
18590a1568
|
@ -51,7 +51,7 @@ class ForeignKeySource(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class ForeignKeyTargetSerializer(serializers.HyperlinkedModelSerializer):
|
class ForeignKeyTargetSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
sources = serializers.ManyHyperlinkedRelatedField(view_name='foreignkeysource-detail', read_only=True)
|
sources = serializers.ManyHyperlinkedRelatedField(view_name='foreignkeysource-detail')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ForeignKeyTarget
|
model = ForeignKeyTarget
|
||||||
|
@ -253,24 +253,23 @@ class HyperlinkedForeignKeyTests(TestCase):
|
||||||
]
|
]
|
||||||
self.assertEquals(serializer.data, expected)
|
self.assertEquals(serializer.data, expected)
|
||||||
|
|
||||||
# TODO: Check this - is this a bug or is the test incorrect?
|
def test_reverse_foreign_key_create(self):
|
||||||
# def test_reverse_foreign_key_create(self):
|
data = {'url': '/foreignkeytarget/3/', 'name': u'target-3', 'sources': ['/foreignkeysource/1/', '/foreignkeysource/3/']}
|
||||||
# data = {'url': '/foreignkeytarget/3/', 'name': u'target-3', 'sources': ['/foreignkeysource/1/', '/foreignkeysource/3/']}
|
serializer = ForeignKeyTargetSerializer(data=data)
|
||||||
# serializer = ForeignKeyTargetSerializer(data=data)
|
self.assertTrue(serializer.is_valid())
|
||||||
# self.assertTrue(serializer.is_valid())
|
obj = serializer.save()
|
||||||
# obj = serializer.save()
|
self.assertEquals(serializer.data, data)
|
||||||
# self.assertEquals(serializer.data, data)
|
self.assertEqual(obj.name, u'target-3')
|
||||||
# self.assertEqual(obj.name, u'target-3')
|
|
||||||
|
|
||||||
# # Ensure target 4 is added, and everything else is as expected
|
# Ensure target 4 is added, and everything else is as expected
|
||||||
# queryset = ForeignKeyTarget.objects.all()
|
queryset = ForeignKeyTarget.objects.all()
|
||||||
# serializer = ForeignKeyTargetSerializer(queryset)
|
serializer = ForeignKeyTargetSerializer(queryset)
|
||||||
# expected = [
|
expected = [
|
||||||
# {'url': '/foreignkeytarget/1/', 'name': u'target-1', 'sources': ['/foreignkeysource/2/']},
|
{'url': '/foreignkeytarget/1/', 'name': u'target-1', 'sources': ['/foreignkeysource/2/']},
|
||||||
# {'url': '/foreignkeytarget/2/', 'name': u'target-2', 'sources': []},
|
{'url': '/foreignkeytarget/2/', 'name': u'target-2', 'sources': []},
|
||||||
# {'url': '/foreignkeytarget/3/', 'name': u'target-3', 'sources': ['/foreignkeysource/1/', '/foreignkeysource/3/']},
|
{'url': '/foreignkeytarget/3/', 'name': u'target-3', 'sources': ['/foreignkeysource/1/', '/foreignkeysource/3/']},
|
||||||
# ]
|
]
|
||||||
# self.assertEquals(serializer.data, expected)
|
self.assertEquals(serializer.data, expected)
|
||||||
|
|
||||||
def test_foreign_key_update_with_invalid_null(self):
|
def test_foreign_key_update_with_invalid_null(self):
|
||||||
data = {'url': '/foreignkeysource/1/', 'name': u'source-1', 'target': None}
|
data = {'url': '/foreignkeysource/1/', 'name': u'source-1', 'target': None}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user