def test_to_representation_if_id_only(self):
        ''' Test EphemeralSerializer.to_representation() in id_only mode '''
        eo = EphemeralObject({'pk': 1, 'values': None})
        data = CountsSerializer(request_fields=True).to_representation(eo)

        self.assertEqual(data, eo.pk)
    def test_data_count_field_returns_none_if_null_values(self):
        eo = EphemeralObject({'pk': 1, 'values': None})
        data = CountsSerializer(eo, envelope=True).data['counts']

        self.assertEqual(data['count'], None)
        self.assertEqual(data['unique_count'], None)
 def test_data_count_raises_exception_if_wrong_type(self):
     eo = EphemeralObject({'pk': 1, 'values': {}})
     with self.assertRaises(TypeError):
         CountsSerializer(eo, envelope=True).data
    def test_data_count_field(self):
        eo = EphemeralObject({'pk': 1, 'values': [1, 1, 2]})
        data = CountsSerializer(eo, envelope=True).data['counts']

        self.assertEqual(data['count'], 3)
        self.assertEqual(data['unique_count'], 2)