  
      def test_reverse_foreign_key_retrieve(self):
          queryset = ForeignKeyTarget.objects.all()
          serializer = ForeignKeyTargetSerializer(queryset)
          self.assertEquals(serializer.data, self.data)
  
      def test_reverse_foreign_key_create(self):
          data = deepcopy(self.new_target_data)
          data['sources'].append({'name': u'source-4', 'target': 2})
          instance = ForeignKeyTarget.objects.get(pk=2)
 
</s> remove         serializer = ForeignKeyTargetSerializer(instance, data=data)
        self.assertTrue(serializer.is_valid())
        self.assertEquals(serializer.data, data)
        serializer.save()
 </s> add         self.save_serialized_target(instance, data) </s> remove     def test_reverse_foreign_key_retrieve(self):
 </s> add     def save_serialized_target(self, instance, data):
        serializer = ForeignKeyTargetSerializer(instance, data=data)
        self.assertTrue(serializer.is_valid())
        self.assertEquals(serializer.data, data)
        serializer.save()

    def check_serialized_targets(self, data): </s> remove         self.assertEquals(serializer.data, expected)
 </s> add         self.check_serialized_targets(expected) </s> remove         queryset = ForeignKeyTarget.objects.all()
        serializer = ForeignKeyTargetSerializer(queryset)
 </s> add  </s> remove         serializer = ForeignKeyTargetSerializer(instance, data=data)
        self.assertTrue(serializer.is_valid())
        self.assertEquals(serializer.data, data)
        serializer.save()
 </s> add         self.save_serialized_target(instance, data)
        self.assertEquals(serializer.data, data)

    def test_reverse_foreign_key_retrieve(self):
        self.check_serialized_targets(self.data)
  
      def test_reverse_foreign_key_retrieve(self):
          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)
  
      def test_reverse_foreign_key_create(self):
          data = deepcopy(self.new_target_data)
          data['sources'].append({'name': u'source-4', 'target': 2})
          instance = ForeignKeyTarget.objects.get(pk=2)
keep keep keep keep replace keep keep keep keep keep
 Add two functions for more DRY reverse fk tests 
rest_framework/tests/nested_relations.py