Esempio n. 1
0
    def test_create_view_no_od(
        self, MultipleRetinaETDRSAnnotations, rf, user_type
    ):
        model_build = ETDRSGridAnnotationFactory.build(
            grader=MultipleRetinaETDRSAnnotations.grader1,
            image=MultipleRetinaETDRSAnnotations.etdrss1[0].image,
        )
        model_serialized = ETDRSGridAnnotationSerializer(model_build).data
        model_serialized["grader"] = MultipleRetinaETDRSAnnotations.grader1.id
        model_serialized["image"] = str(model_serialized["image"])
        model_serialized["optic_disk"] = []
        model_json = json.dumps(model_serialized)

        response = view_test(
            "create",
            user_type,
            self.namespace,
            self.basename,
            MultipleRetinaETDRSAnnotations.grader1,
            None,
            rf,
            ETDRSGridAnnotationViewSet,
            model_json,
        )
        if user_type in ("retina_grader", "retina_admin"):
            model_serialized["id"] = response.data["id"]
            response.data["image"] = str(response.data["image"])
            assert response.data == model_serialized
Esempio n. 2
0
    def test_create_view_wrong_user_id(
        self, MultipleRetinaETDRSAnnotations, rf, user_type
    ):
        other_user = UserFactory()
        model_build = ETDRSGridAnnotationFactory.build(
            grader=other_user,
            image=MultipleRetinaETDRSAnnotations.etdrss1[0].image,
        )
        model_serialized = ETDRSGridAnnotationSerializer(model_build).data
        model_serialized["grader"] = MultipleRetinaETDRSAnnotations.grader2.id
        model_serialized["image"] = str(model_serialized["image"])
        model_json = json.dumps(model_serialized)

        response = view_test(
            "create",
            user_type,
            self.namespace,
            self.basename,
            MultipleRetinaETDRSAnnotations.grader1,
            None,
            rf,
            ETDRSGridAnnotationViewSet,
            model_json,
            check_response_status_code=False,
        )
        if user_type == "retina_admin":
            model_serialized["id"] = response.data["id"]
            response.data["image"] = str(response.data["image"])
            assert response.data == model_serialized
        elif user_type == "retina_grader":
            assert response.status_code == status.HTTP_400_BAD_REQUEST
            assert (
                str(response.data["grader"][0])
                == "User is not allowed to create annotation for other grader"
            )
        else:
            assert response.status_code == status.HTTP_403_FORBIDDEN