Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow blank notes in reviewing Approved/Pending submissions #1626

Merged
merged 2 commits into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion onadata/libs/serializers/submission_review_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class SubmissionReviewSerializer(serializers.ModelSerializer):
"""
SubmissionReviewSerializer Class
"""
note = serializers.CharField(source='note.note', required=False)
note = serializers.CharField(
source='note.note', required=False, allow_blank=True)

class Meta:
"""
Expand Down Expand Up @@ -59,6 +60,7 @@ def update(self, instance, validated_data):
"""
Custom update method for SubmissionReviewSerializer
"""
__import__('ipdb').set_trace()
note = instance.note
note_data = validated_data.pop('note')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,36 @@ def test_submission_review_update(self):
# Doesnt create a new note
self.assertEqual(len(Note.objects.all()), 1)
self.assertNotEqual(old_note_text, new_review.note_text)

def test_approved_and_pending_status_allows_blank_in_note(self):
self._publish_transportation_form_and_submit_instance()

instance = Instance.objects.first()

data = {
"instance": instance.id,
"note": "",
"status": SubmissionReview.APPROVED
}

serializer_instance = SubmissionReviewSerializer(data=data)
self.assertTrue(serializer_instance.is_valid())
data = {
"instance": instance.id,
"note": "",
"status": SubmissionReview.PENDING
}
serializer_instance = SubmissionReviewSerializer(data=data)
self.assertTrue(serializer_instance.is_valid())
data = {
"instance": instance.id,
"note": "",
"status": SubmissionReview.REJECTED
}
serializer_instance = SubmissionReviewSerializer(data=data)
self.assertTrue(serializer_instance.is_valid())
with self.assertRaises(ValidationError) as no_comment:
serializer_instance.validate(data)

no_comment_error_detail = no_comment.exception.detail['note']
self.assertEqual(COMMENT_REQUIRED, no_comment_error_detail)