Skip to content
Snippets Groups Projects
Commit dcf823e3 authored by Bastien Abadie's avatar Bastien Abadie
Browse files

Merge branch 'classification-create-return-id-state' into 'master'

Return UUID and state on classification creation

Closes #451

See merge request !954
parents 7e471868 68ba42cb
No related branches found
No related tags found
1 merge request!954Return UUID and state on classification creation
......@@ -128,17 +128,21 @@ class ClassificationCreateSerializer(serializers.ModelSerializer):
'Required for non-manual sources. '
'Will be ignored and set to True for classifications on a `manual` source.',
)
state = EnumField(ClassificationState, read_only=True)
class Meta:
model = Classification
fields = (
'id',
'element',
'ml_class',
'source',
'worker_version',
'confidence',
'high_confidence',
'state',
)
read_only_fields = ('id', 'state')
validators = [
UniqueTogetherValidator(
queryset=Classification.objects.filter(worker_version_id__isnull=True),
......
......@@ -57,6 +57,16 @@ class TestClasses(FixtureAPITestCase):
self.assertEqual(classification.state, ClassificationState.Validated)
self.assertEqual(classification.confidence, 1)
self.assertTrue(classification.high_confidence)
self.assertDictEqual(response.json(), {
'id': str(classification.id),
'element': str(self.element.id),
'ml_class': str(self.text.id),
'source': 'manual',
'worker_version': None,
'state': ClassificationState.Validated.value,
'confidence': 1,
'high_confidence': True,
})
def test_classification_exists(self):
"""
......@@ -90,12 +100,21 @@ class TestClasses(FixtureAPITestCase):
'ml_class': str(self.text.id),
'source': 'manual',
'confidence': 0.5,
'high_confidence': False
'high_confidence': False,
'state': 'rejected',
})
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
data = response.json()
self.assertEqual(data['confidence'], 1)
self.assertEqual(data['high_confidence'], True)
classification = self.element.classifications.get()
self.assertDictEqual(response.json(), {
'id': str(classification.id),
'element': str(self.element.id),
'ml_class': str(self.text.id),
'source': 'manual',
'worker_version': None,
'state': ClassificationState.Validated.value,
'confidence': 1,
'high_confidence': True,
})
def test_classification_creation_without_permission(self):
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment