You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.2 KiB

5 years ago
  1. from django.test import TestCase
  2. from mixer.backend.django import mixer
  3. from ..serializers import LabelSerializer
  4. from ..models import Label, DocumentAnnotation, SequenceAnnotation, Seq2seqAnnotation
  5. from ..serializers import ClassificationDocumentSerializer, DocumentAnnotationSerializer
  6. from ..serializers import SequenceDocumentSerializer, SequenceAnnotationSerializer
  7. from ..serializers import Seq2seqDocumentSerializer, Seq2seqAnnotationSerializer
  8. class TestLabelSerializer(TestCase):
  9. def test_create(self):
  10. label = mixer.blend('server.Label')
  11. serializer = LabelSerializer(label)
  12. self.assertIsInstance(serializer.data, dict)
  13. def test_annotation(self):
  14. from rest_framework import serializers
  15. from ..models import Seq2seqDocument
  16. class HogeSerializer(serializers.ModelSerializer):
  17. seq2seq_annotations = Seq2seqAnnotationSerializer(many=True)
  18. class Meta:
  19. model = Seq2seqDocument
  20. fields = ('id', 'text', 'seq2seq_annotations')
  21. doc = mixer.blend('server.Seq2seqDocument')
  22. ann = mixer.blend('server.Seq2seqAnnotation')
  23. doc.seq2seq_annotations.add(ann)
  24. serializer = HogeSerializer(doc)
  25. print(serializer.data)