Skip to content

Commit

Permalink
Move Common Tags to common_tag file
Browse files Browse the repository at this point in the history
- Add COMMENT_REQUIRED and SUBMISSION_REVIEW_INSTANCE_FIELD tag
- Update Tests
  • Loading branch information
DavisRayM committed Aug 20, 2018
1 parent 73a3a9e commit 7e0a6d5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
9 changes: 4 additions & 5 deletions onadata/libs/serializers/submission_review_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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)
4 changes: 4 additions & 0 deletions onadata/libs/utils/common_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 7e0a6d5

Please sign in to comment.