From accbaa83b18a5e4e9ce90c6caa294461afb26d1b Mon Sep 17 00:00:00 2001 From: Hironsan Date: Mon, 18 Feb 2019 15:39:53 +0900 Subject: [PATCH] WIP --- app/server/tests/test_serializers.py | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 app/server/tests/test_serializers.py diff --git a/app/server/tests/test_serializers.py b/app/server/tests/test_serializers.py new file mode 100644 index 00000000..616f987d --- /dev/null +++ b/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)