From 58cb73e1464730004cf70962f397761b2efbeaf7 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Fri, 10 Dec 2021 10:13:06 +0900 Subject: [PATCH] Update label serializer to include task_type --- backend/api/serializers.py | 10 +++++++++- backend/api/tests/test_serializers.py | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 backend/api/tests/test_serializers.py diff --git a/backend/api/serializers.py b/backend/api/serializers.py index aa3be273..8f6ba68a 100644 --- a/backend/api/serializers.py +++ b/backend/api/serializers.py @@ -60,7 +60,15 @@ class LabelSerializer(serializers.ModelSerializer): class Meta: model = Label - fields = ('id', 'text', 'prefix_key', 'suffix_key', 'background_color', 'text_color') + fields = ( + 'id', + 'text', + 'prefix_key', + 'suffix_key', + 'background_color', + 'text_color', + 'task_type', + ) class CommentSerializer(serializers.ModelSerializer): diff --git a/backend/api/tests/test_serializers.py b/backend/api/tests/test_serializers.py new file mode 100644 index 00000000..5133515e --- /dev/null +++ b/backend/api/tests/test_serializers.py @@ -0,0 +1,20 @@ +from django.test import TestCase + +from ..models import SEQUENCE_LABELING, Label +from ..serializers import LabelSerializer +from .api.utils import prepare_project + + +class TestLabelSerializer(TestCase): + + def test_create_label(self): + project = prepare_project(SEQUENCE_LABELING) + data = { + 'text': 'example', + 'task_type': 'Span' + } + serializer = LabelSerializer(data=data) + serializer.is_valid() + label = serializer.save(project=project.item) + created = Label.objects.get(pk=label.id) + self.assertEqual(label, created)