title: Django Rest Framework: Test serializers
body: <p>In my project <a href="https://github.com/be-ndee/coach-server" rel="noreferrer">coach</a> I have a problem with testing the Information serializer. I have the following serializer classes in the file <code>running/serializes.py</code>:</p>
  
  <pre><code>class Velocity(serializers.ModelSerializer):
      class Meta:
          model = VelocityModel
          fields = ("id", "minimum", "average", "maximum")
  
  
  class Information(serializers.ModelSerializer):
      heart_beat = HeartBeat(read_only=True)
      velocity = Velocity(read_only=True)
  
      class Meta:
          model = InformationModel
          fields = ("id", "distance", "velocity", "heart_beat", "calories")
  </code></pre>
  
  <p>In my test I have this:</p>
  
  <pre><code>from running import models, serializers
  
  @patch("running.serializers.Velocity")
  def test_contains_id(self, mock_velocity):
      # mocking stuff
      returned_data = {}
      mock_velocity.data = PropertyMock(return_value=returned_data)
  
      # creating instances of the models
      self.velocity = models.Velocity(minimum=8, average=10, maximum=12)
      self.velocity.save()
      self.heart_beat = models.HeartBeat(minimum=120, average=130, maximum=140)
      self.heart_beat.save()
      self.information = models.Information(distance=3.7, velocity=self.velocity, heart_beat=self.heart_beat, calories=132)
      self.information.save()
  
      # create the actual serializer
      self.information_serializer = serializers.Information(self.information)
  
      self.assertEqual(self.information_serializer.data["velocity"], returned_data)
  </code></pre>
  
  <p>So I want to test, that the data returned by the InformationSerializer (<code>self.information_serializer.data</code>), has a key <code>"velocity"</code>, which points on the data returned by the VelocitySerializer (<code>mock_velocity.data</code>).</p>
  
  <p>But <code>self.information_serializer.data["velocity"]</code> just contains the data, saved in the models (<code>OrderedDict([('id', 1), ('minimum', 8.0), ('average', 10.0), ('maximum', 12.0)])</code>. I don't know where is my fault...</p>
  
  <p>Also another question would be, do I really need to test this? Because I'm questioning myself, if I'm testing more the Django Rest Framework than my serializers?!</p>
  
  <p>So how to go on? Thanks in advance!</p>