def test_serializer(self): self.assertEquals(OpinionQuestionOption.objects.count(), 0) oqo = OpinionQuestionOption(text='test', sequence=1) oqo.save() self.assertEquals(OpinionQuestionOption.objects.count(), 1) serialized = OpinionQuestionOptionSerializer(oqo) serialized_data = serialized.data self.assertTrue(isinstance(serialized_data, dict)) for prop, value in {'text': 'test', 'sequence': 1}.items(): self.assertEquals(serialized_data[prop], value) oqo.delete() self.assertEquals(OpinionQuestionOption.objects.count(), 0)
def test_serializer_can_serialize_related_entities(self): oq = self._create_basic_oq() oqo = OpinionQuestionOption(text='opt1', sequence=1) oqo.save() oq.options.add(oqo) self.assertEquals(oq.options.count(), 1) serializer = OpinionQuestionSerializer(oq) serialized_data = serializer.data self.assertTrue(isinstance(serialized_data['options'], list)) self.assertEquals(len(serialized_data['options']), 1) self.assertEquals(serialized_data['options'][0], OpinionQuestionOptionSerializer(oqo).data) self._delete_basic_oq(oq)