Ejemplo n.º 1
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
        }
        request = HttpRequest()
        request.user = self.user

        serializer_instance = SubmissionReviewSerializer(data=data, context={
            "request": request})
        serializer_instance.is_valid()
        serializer_instance.save()
        instance.refresh_from_db()
        instance_review = instance.get_latest_review()

        self.assertNotIn(u'_review_comment', instance.json.keys())
        self.assertIn(u'_review_status', instance.json.keys())
        self.assertIn(u'_review_date', instance.json.keys())
        self.assertEqual(SubmissionReview.APPROVED,
                         instance.json[u'_review_status'])
        self.assertEqual(SubmissionReview.APPROVED, instance_review.status)
        comment = instance_review.get_note_text()
        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, context={
            "request": request})
        serializer_instance.is_valid()
        serializer_instance.save()
        instance.refresh_from_db()
        instance_review = instance.get_latest_review()

        self.assertIn(u'_review_comment', instance.json.keys())
        self.assertIn(u'_review_status', instance.json.keys())
        self.assertIn(u'_review_date', instance.json.keys())
        self.assertEqual(SubmissionReview.APPROVED,
                         instance.json[u'_review_status'])
        self.assertEqual(SubmissionReview.APPROVED, instance_review.status)
        comment = instance_review.get_note_text()
        self.assertEqual("Hey There", comment)
        self.assertTrue(instance.has_a_review)
Ejemplo n.º 2
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.º 3
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.º 4
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)
    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)