mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-12-03 15:04:08 +03:00
Make nested tests consistent with pk and hyperlink tests
This commit is contained in:
parent
37acea5240
commit
04119245ec
|
@ -35,18 +35,17 @@ class ReverseForeignKeyTests(TestCase):
|
||||||
for idx in range(1, 4):
|
for idx in range(1, 4):
|
||||||
source = ForeignKeySource(name='source-%d' % idx, target=target)
|
source = ForeignKeySource(name='source-%d' % idx, target=target)
|
||||||
source.save()
|
source.save()
|
||||||
self.target_data = {'id': 1, 'name': u'target-1', 'sources': [
|
|
||||||
|
def test_reverse_foreign_key_retrieve(self):
|
||||||
|
queryset = ForeignKeyTarget.objects.all()
|
||||||
|
serializer = ForeignKeyTargetSerializer(queryset)
|
||||||
|
expected = [
|
||||||
|
{'id': 1, 'name': u'target-1', 'sources': [
|
||||||
{'id': 1, 'name': u'source-1', 'target': 1},
|
{'id': 1, 'name': u'source-1', 'target': 1},
|
||||||
{'id': 2, 'name': u'source-2', 'target': 1},
|
{'id': 2, 'name': u'source-2', 'target': 1},
|
||||||
{'id': 3, 'name': u'source-3', 'target': 1},
|
{'id': 3, 'name': u'source-3', 'target': 1},
|
||||||
|
]},
|
||||||
|
{'id': 2, 'name': u'target-2', 'sources': [
|
||||||
]}
|
]}
|
||||||
self.new_target_data = {'id': 2, 'name': u'target-2', 'sources': []}
|
]
|
||||||
self.data = [self.target_data, self.new_target_data]
|
self.assertEquals(serializer.data, expected)
|
||||||
|
|
||||||
def check_serialized_targets(self, data):
|
|
||||||
queryset = ForeignKeyTarget.objects.all()
|
|
||||||
serializer = ForeignKeyTargetSerializer(queryset)
|
|
||||||
self.assertEquals(serializer.data, data)
|
|
||||||
|
|
||||||
def test_reverse_foreign_key_retrieve(self):
|
|
||||||
self.check_serialized_targets(self.data)
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user