Browse Source

WIP

pull/110/head
Hironsan 5 years ago
parent
commit
accbaa83b1
1 changed files with 32 additions and 0 deletions
  1. 32
      app/server/tests/test_serializers.py

32
app/server/tests/test_serializers.py

@ -0,0 +1,32 @@
from django.test import TestCase
from mixer.backend.django import mixer
from ..serializers import LabelSerializer
from ..models import Label, DocumentAnnotation, SequenceAnnotation, Seq2seqAnnotation
from ..serializers import ClassificationDocumentSerializer, DocumentAnnotationSerializer
from ..serializers import SequenceDocumentSerializer, SequenceAnnotationSerializer
from ..serializers import Seq2seqDocumentSerializer, Seq2seqAnnotationSerializer
class TestLabelSerializer(TestCase):
def test_create(self):
label = mixer.blend('server.Label')
serializer = LabelSerializer(label)
self.assertIsInstance(serializer.data, dict)
def test_annotation(self):
from rest_framework import serializers
from ..models import Seq2seqDocument
class HogeSerializer(serializers.ModelSerializer):
seq2seq_annotations = Seq2seqAnnotationSerializer(many=True)
class Meta:
model = Seq2seqDocument
fields = ('id', 'text', 'seq2seq_annotations')
doc = mixer.blend('server.Seq2seqDocument')
ann = mixer.blend('server.Seq2seqAnnotation')
doc.seq2seq_annotations.add(ann)
serializer = HogeSerializer(doc)
print(serializer.data)
Loading…
Cancel
Save