diff --git a/onadata/libs/serializers/submission_review_serializer.py b/onadata/libs/serializers/submission_review_serializer.py index 5b816a28dd..e010a6abe1 100644 --- a/onadata/libs/serializers/submission_review_serializer.py +++ b/onadata/libs/serializers/submission_review_serializer.py @@ -7,6 +7,8 @@ from onadata.apps.logger.models import SubmissionReview from onadata.libs.serializers.note_serializer import NoteSerializer +from onadata.libs.utils.common_tags import (COMMENT_REQUIRED, + SUBMISSION_REVIEW_INSTANCE_FIELD) class SubmissionReviewSerializer(serializers.ModelSerializer): @@ -33,10 +35,7 @@ def validate(self, attrs): if status == SubmissionReview.REJECTED: if note_text is None: - raise exceptions.ValidationError({ - 'note': - 'Can\'t reject a submission without a comment.' - }) + raise exceptions.ValidationError({'note': COMMENT_REQUIRED}) return attrs def create(self, validated_data): @@ -46,7 +45,7 @@ def create(self, validated_data): note_data = validated_data.pop('note') note_data['instance'] = validated_data.get('instance') note_data['created_by'] = validated_data.get('created_by') - note_data['instance_field'] = "_review_status" + note_data['instance_field'] = SUBMISSION_REVIEW_INSTANCE_FIELD note = NoteSerializer.create( NoteSerializer(), validated_data=note_data) diff --git a/onadata/libs/tests/serializers/test_submission_review_serializer.py b/onadata/libs/tests/serializers/test_submission_review_serializer.py index df43854ec8..8cade5ef32 100644 --- a/onadata/libs/tests/serializers/test_submission_review_serializer.py +++ b/onadata/libs/tests/serializers/test_submission_review_serializer.py @@ -10,6 +10,8 @@ from onadata.apps.main.tests.test_base import TestBase from onadata.libs.serializers.submission_review_serializer import \ SubmissionReviewSerializer +from onadata.libs.utils.common_tags import (COMMENT_REQUIRED, + SUBMISSION_REVIEW_INSTANCE_FIELD) class TestSubmissionReviewSerializer(TestBase): @@ -44,8 +46,8 @@ def _create_submission_review(self): note = submission_review.note self.assertEqual(instance, submission_review.instance) - self.assertEqual(submission_review.note_text, "Hey there") - self.assertEqual(note.instance_field, "_review_status") + self.assertEqual("Hey there", submission_review.note_text) + self.assertEqual(SUBMISSION_REVIEW_INSTANCE_FIELD, note.instance_field) self.assertEqual(note.instance, submission_review.instance) return serializer_instance.data @@ -66,8 +68,7 @@ def test_validate_bad_data(self): SubmissionReviewSerializer().validate(data) no_comment_error_detail = no_comment.exception.detail['note'] - self.assertEqual(no_comment_error_detail, - 'Can\'t reject a submission without a comment.') + self.assertEqual(COMMENT_REQUIRED, no_comment_error_detail) def test_submission_review_create(self): """ @@ -104,4 +105,4 @@ def test_submission_review_update(self): # Doesnt create a new note self.assertEqual(len(Note.objects.all()), 1) - self.assertNotEqual(new_review.note_text, old_note_text) + self.assertNotEqual(old_note_text, new_review.note_text) diff --git a/onadata/libs/utils/common_tags.py b/onadata/libs/utils/common_tags.py index 5604d5866f..65b4599dc3 100644 --- a/onadata/libs/utils/common_tags.py +++ b/onadata/libs/utils/common_tags.py @@ -119,3 +119,7 @@ 'kml': 'vnd.google-earth.kml+xml', OSM: OSM } + +# Submission Review Tags +COMMENT_REQUIRED = 'Can\'t reject a submission without a comment.' +SUBMISSION_REVIEW_INSTANCE_FIELD = '_review_status'