Ejemplo n.º 1
0
    def _create_submission_review(self):
        """
        Utility to create a submission review
        """

        self._publish_transportation_form_and_submit_instance()

        instance = Instance.objects.first()

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

        serializer_instance = SubmissionReviewSerializer(data=data)
        self.assertFalse(Note.objects.filter(instance=instance).exists())

        self.assertTrue(serializer_instance.is_valid())

        submission_review = serializer_instance.save()

        # Creates Note Object
        self.assertTrue(Note.objects.filter(instance=instance).exists())

        note = submission_review.note
        self.assertEqual(instance, submission_review.instance)
        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
Ejemplo n.º 2
0
    def test_submission_review_update(self):
        """
        Test:
            - We can update a submission review
            - Updating a Submission Review Doesnt Create
              a new Note
        """
        data = self._create_submission_review()
        submission_review = SubmissionReview.objects.first()
        old_note_text = submission_review.note_text

        data['note'] = "Goodbye"

        self.assertEqual(len(Note.objects.all()), 1)
        request = HttpRequest()
        request.user = self.user
        serializer_instance = SubmissionReviewSerializer(
            instance=submission_review, data=data,
            context={"request": request})
        self.assertTrue(serializer_instance.is_valid())
        new_review = serializer_instance.save()

        # Doesnt create a new note
        self.assertEqual(len(Note.objects.all()), 1)
        self.assertNotEqual(old_note_text, new_review.note_text)
Ejemplo n.º 3
0
    def test_instance_json_updated_on_review(self):
        """Test:
            -no review comment or status on instance json
            before submission review
            -instance json review fields update on review save
            -instance review methods
            """
        self._publish_transportation_form_and_submit_instance()
        instance = Instance.objects.first()
        self.assertNotIn(u'_review_status', instance.json.keys())
        self.assertNotIn(u'_review_comment', instance.json.keys())
        self.assertFalse(instance.has_a_review)

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

        serializer_instance = SubmissionReviewSerializer(data=data)
        serializer_instance.is_valid()
        serializer_instance.save()
        instance.refresh_from_db()
        status, comment = instance.get_review_status_and_comment()

        self.assertNotIn(u'_review_comment', instance.json.keys())
        self.assertIn(u'_review_status', instance.json.keys())
        self.assertEqual(SubmissionReview.APPROVED,
                         instance.json[u'_review_status'])
        self.assertEqual(SubmissionReview.APPROVED, status)
        self.assertEqual(None, comment)
        self.assertTrue(instance.has_a_review)

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

        serializer_instance = SubmissionReviewSerializer(data=data)
        serializer_instance.is_valid()
        serializer_instance.save()
        instance.refresh_from_db()
        status, comment = instance.get_review_status_and_comment()

        self.assertIn(u'_review_comment', instance.json.keys())
        self.assertIn(u'_review_status', instance.json.keys())
        self.assertEqual(SubmissionReview.APPROVED,
                         instance.json[u'_review_status'])
        self.assertEqual(SubmissionReview.APPROVED, status)
        self.assertEqual("Hey There", comment)
        self.assertTrue(instance.has_a_review)
    def test_submission_review_update(self):
        """
        Test:
            - We can update a submission review
            - Updating a Submission Review Doesnt Create
              a new Note
        """
        data = self._create_submission_review()
        submission_review = SubmissionReview.objects.first()
        old_note_text = submission_review.note_text

        data['note'] = "Goodbye"

        self.assertEqual(len(Note.objects.all()), 1)
        serializer_instance = SubmissionReviewSerializer(
            instance=submission_review, data=data)
        self.assertTrue(serializer_instance.is_valid())
        new_review = serializer_instance.save()

        # Doesnt create a new note
        self.assertEqual(len(Note.objects.all()), 1)
        self.assertNotEqual(old_note_text, new_review.note_text)
Ejemplo n.º 5
0
    def test_validate_bad_data(self):
        """
        Test:
            - Rejects Rejected Submission Reviews with no comments
        """

        self._publish_transportation_form_and_submit_instance()

        instance = Instance.objects.first()

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

        with self.assertRaises(ValidationError) as no_comment:
            SubmissionReviewSerializer().validate(data)

            no_comment_error_detail = no_comment.exception.detail['note']
            self.assertEqual(COMMENT_REQUIRED, no_comment_error_detail)
Ejemplo n.º 6
0
    def test_instance_json_updated_on_review(self):
        """Test:
            -no review comment or status on instance json
            before submission review
            -instance json review fields update on review save
            -instance review methods
            """
        self._publish_transportation_form_and_submit_instance()
        instance = Instance.objects.first()
        self.assertNotIn(u'_review_status', instance.json.keys())
        self.assertNotIn(u'_review_comment', instance.json.keys())
        self.assertFalse(instance.has_a_review)

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

        serializer_instance = SubmissionReviewSerializer(data=data)
        serializer_instance.is_valid()
        serializer_instance.save()
        instance.refresh_from_db()
        status, comment = instance.get_review_status_and_comment()

        self.assertNotIn(u'_review_comment', instance.json.keys())
        self.assertIn(u'_review_status', instance.json.keys())
        self.assertEqual(SubmissionReview.APPROVED,
                         instance.json[u'_review_status'])
        self.assertEqual(SubmissionReview.APPROVED, status)
        self.assertEqual(None, comment)
        self.assertTrue(instance.has_a_review)

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

        serializer_instance = SubmissionReviewSerializer(data=data)
        serializer_instance.is_valid()
        serializer_instance.save()
        instance.refresh_from_db()
        status, comment = instance.get_review_status_and_comment()

        self.assertIn(u'_review_comment', instance.json.keys())
        self.assertIn(u'_review_status', instance.json.keys())
        self.assertEqual(SubmissionReview.APPROVED,
                         instance.json[u'_review_status'])
        self.assertEqual(SubmissionReview.APPROVED, status)
        self.assertEqual("Hey There", comment)
        self.assertTrue(instance.has_a_review)
Ejemplo n.º 7
0
    def test_approved_and_pending_status_allows_blank_in_note(self):
        self._publish_transportation_form()
        self._make_submissions()

        instance = Instance.objects.first()

        data = {"instance": instance.id, "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)

        # bulk creation of approved submissions without comments
        list_data = [{
            "instance": instance.id,
            "status": SubmissionReview.APPROVED
        }, {
            "instance": instance.id + 1,
            "status": SubmissionReview.APPROVED
        }]
        serializer_instance = SubmissionReviewSerializer(data=list_data,
                                                         many=True)
        self.assertTrue(serializer_instance.is_valid())