Browse Source

Update label serializer to include task_type

pull/1619/head
Hironsan 2 years ago
parent
commit
58cb73e146
2 changed files with 29 additions and 1 deletions
  1. 10
      backend/api/serializers.py
  2. 20
      backend/api/tests/test_serializers.py

10
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):

20
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)
Loading…
Cancel
Save