Esempio n. 1
0
    def test_create_assessmentitem_with_file_question(self):
        self.client.force_authenticate(user=self.user)
        assessmentitem = self.assessmentitem_metadata
        image_file = testdata.fileobj_exercise_image()
        image_file.uploaded_by = self.user
        image_file.save()
        question = "![alt_text](${}/{}.{})".format(
            exercises.IMG_PLACEHOLDER, image_file.checksum, image_file.file_format_id
        )

        assessmentitem["question"] = question
        response = self.client.post(
            self.sync_url,
            [
                generate_create_event(
                    [assessmentitem["contentnode"], assessmentitem["assessment_id"]],
                    ASSESSMENTITEM,
                    assessmentitem,
                )
            ],
            format="json",
        )
        self.assertEqual(response.status_code, 200, response.content)
        try:
            ai = models.AssessmentItem.objects.get(
                assessment_id=assessmentitem["assessment_id"]
            )
        except models.AssessmentItem.DoesNotExist:
            self.fail("AssessmentItem was not created")
        try:
            file = ai.files.get()
            self.assertEqual(file.id, image_file.id)
        except models.File.DoesNotExist:
            self.fail("File was not updated")
Esempio n. 2
0
    def test_update_assessmentitem_remove_file(self):

        assessmentitem = models.AssessmentItem.objects.create(
            **self.assessmentitem_db_metadata
        )
        image_file = testdata.fileobj_exercise_image()
        image_file.assessment_item = assessmentitem
        image_file.save()
        question = "A different question"

        self.client.force_authenticate(user=self.user)
        response = self.client.post(
            self.sync_url,
            [
                generate_update_event(
                    [assessmentitem.contentnode_id, assessmentitem.assessment_id],
                    ASSESSMENTITEM,
                    {"question": question},
                )
            ],
            format="json",
        )
        self.assertEqual(response.status_code, 200, response.content)
        try:
            assessmentitem.files.get()
            self.fail("File was not removed")
        except models.File.DoesNotExist:
            pass
Esempio n. 3
0
    def test_update_assessmentitem_with_file_no_permissions(self):

        assessmentitem = models.AssessmentItem.objects.create(
            **self.assessmentitem_db_metadata
        )
        image_file = testdata.fileobj_exercise_image()
        question = "![alt_text](${}/{}.{})".format(
            exercises.IMG_PLACEHOLDER, image_file.checksum, image_file.file_format_id
        )

        self.client.force_authenticate(user=self.user)
        response = self.client.post(
            self.sync_url,
            [
                generate_update_event(
                    [assessmentitem.contentnode_id, assessmentitem.assessment_id],
                    ASSESSMENTITEM,
                    {"question": question},
                )
            ],
            format="json",
        )
        self.assertEqual(response.status_code, 400, response.content)
        try:
            file = assessmentitem.files.get()
            self.assertNotEqual(file.id, image_file.id)
            self.fail("File was updated")
        except models.File.DoesNotExist:
            pass
Esempio n. 4
0
    def test_create_assessmentitem_with_file_no_permission(self):
        self.client.force_authenticate(user=self.user)
        assessmentitem = self.assessmentitem_metadata
        image_file = testdata.fileobj_exercise_image()
        question = "![alt_text](${}/{}.{})".format(
            exercises.IMG_PLACEHOLDER, image_file.checksum, image_file.file_format_id
        )
        assessmentitem["question"] = question
        response = self.client.post(
            self.sync_url,
            [
                generate_create_event(
                    [assessmentitem["contentnode"], assessmentitem["assessment_id"]],
                    ASSESSMENTITEM,
                    assessmentitem,
                )
            ],
            format="json",
        )
        self.assertEqual(response.status_code, 400, response.content)
        try:
            models.AssessmentItem.objects.get(
                assessment_id=assessmentitem["assessment_id"]
            )
            self.fail("AssessmentItem was created")
        except models.AssessmentItem.DoesNotExist:
            pass

        self.assertIsNone(image_file.assessment_item)
Esempio n. 5
0
    def test_update_assessmentitem_remove_file(self):

        assessmentitem = models.AssessmentItem.objects.create(
            **self.assessmentitem_db_metadata
        )
        image_file = testdata.fileobj_exercise_image()
        image_file.assessment_item = assessmentitem
        image_file.save()
        question = "A different question"

        self.client.force_authenticate(user=self.user)
        response = self.client.patch(
            reverse("assessmentitem-detail", kwargs={"pk": assessmentitem.id}),
            {"question": question},
            format="json",
        )
        self.assertEqual(response.status_code, 200, response.content)
        try:
            assessmentitem.files.get()
            self.fail("File was not removed")
        except models.File.DoesNotExist:
            pass
Esempio n. 6
0
    def test_update_assessmentitem_with_file_no_permissions(self):

        assessmentitem = models.AssessmentItem.objects.create(
            **self.assessmentitem_db_metadata
        )
        image_file = testdata.fileobj_exercise_image()
        question = "![alt_text](${}/{}.{})".format(
            exercises.IMG_PLACEHOLDER, image_file.checksum, image_file.file_format_id
        )

        self.client.force_authenticate(user=self.user)
        response = self.client.patch(
            reverse("assessmentitem-detail", kwargs={"pk": assessmentitem.id}),
            {"question": question},
            format="json",
        )
        self.assertEqual(response.status_code, 400, response.content)
        try:
            file = assessmentitem.files.get()
            self.assertNotEqual(file.id, image_file.id)
            self.fail("File was updated")
        except models.File.DoesNotExist:
            pass