예제 #1
0
 def test_destroy_view(self, TwoRetinaPolygonAnnotationSets, rf, user_type):
     view_test(
         "destroy",
         user_type,
         self.namespace,
         self.basename,
         TwoRetinaPolygonAnnotationSets.grader1,
         TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first(),
         rf,
         SinglePolygonViewSet,
     )
     if user_type in ("retina_grader", "retina_admin"):
         assert not PolygonAnnotationSet.objects.filter(
             id=TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first().id
         ).exists()
예제 #2
0
 def test_destroy_view(self, MultipleRetinaETDRSAnnotations, rf, user_type):
     view_test(
         "destroy",
         user_type,
         self.namespace,
         self.basename,
         MultipleRetinaETDRSAnnotations.grader1,
         MultipleRetinaETDRSAnnotations.etdrss1[0],
         rf,
         ETDRSGridAnnotationViewSet,
     )
     if user_type in ("retina_grader", "retina_admin"):
         assert not ETDRSGridAnnotation.objects.filter(
             id=MultipleRetinaETDRSAnnotations.etdrss1[0].id
         ).exists()
예제 #3
0
 def test_destroy_view(self, TwoRetinaPolygonAnnotationSets, rf, user_type):
     view_test(
         "destroy",
         user_type,
         self.namespace,
         self.basename,
         TwoRetinaPolygonAnnotationSets.grader1,
         TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first(),
         rf,
         SinglePolygonViewSet,
     )
     if user_type in ("retina_grader", "retina_admin"):
         assert not PolygonAnnotationSet.objects.filter(
             id=TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first().id
         ).exists()
예제 #4
0
    def test_update_view(self, TwoRetinaPolygonAnnotationSets, rf, user_type):
        model_serialized = SinglePolygonAnnotationSerializer(
            TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first()
        ).data
        annotation_set = PolygonAnnotationSetFactory(
            grader=TwoRetinaPolygonAnnotationSets.grader1
        )
        model_serialized["annotation_set"] = str(annotation_set.id)
        model_json = json.dumps(model_serialized)

        response = view_test(
            "update",
            user_type,
            self.namespace,
            self.basename,
            TwoRetinaPolygonAnnotationSets.grader1,
            TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first(),
            rf,
            SinglePolygonViewSet,
            model_json,
        )

        if user_type in ("retina_grader", "retina_admin"):
            response.data["annotation_set"] = str(
                response.data["annotation_set"]
            )
            assert response.data == model_serialized
예제 #5
0
    def test_create_view(self, TwoRetinaPolygonAnnotationSets, rf, user_type):
        model_build = SinglePolygonAnnotationFactory.build()
        model_serialized = SinglePolygonAnnotationSerializer(model_build).data
        annotation_set = PolygonAnnotationSetFactory(
            grader=TwoRetinaPolygonAnnotationSets.grader1
        )
        model_serialized["annotation_set"] = str(annotation_set.id)
        model_json = json.dumps(model_serialized)

        response = view_test(
            "create",
            user_type,
            self.namespace,
            self.basename,
            TwoRetinaPolygonAnnotationSets.grader1,
            None,
            rf,
            SinglePolygonViewSet,
            model_json,
        )
        if user_type in ("retina_grader", "retina_admin"):
            model_serialized["id"] = response.data["id"]
            response.data["annotation_set"] = str(
                response.data["annotation_set"]
            )
            assert response.data == model_serialized
예제 #6
0
 def test_list_view(self, TwoRetinaPolygonAnnotationSets, rf, user_type):
     response = view_test(
         "list",
         user_type,
         self.namespace,
         self.basename,
         TwoRetinaPolygonAnnotationSets.grader1,
         None,
         rf,
         SinglePolygonViewSet,
     )
     if user_type == "retina_grader":
         serialized_data = SinglePolygonAnnotationSerializer(
             TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.all(),
             many=True,
         ).data
         assert len(response.data) == len(serialized_data)
         response.data.sort(key=lambda k: k["id"])
         serialized_data.sort(key=lambda k: k["id"])
         assert response.data == serialized_data
     elif user_type == "retina_admin":
         serialized_data = SinglePolygonAnnotationSerializer(
             TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.all()
             | TwoRetinaPolygonAnnotationSets.polygonset2.singlepolygonannotation_set.all(),
             many=True,
         ).data
         assert response.data == serialized_data
예제 #7
0
    def test_partial_update_view(
        self, TwoRetinaPolygonAnnotationSets, rf, user_type
    ):
        model_serialized = PolygonAnnotationSetSerializer(
            instance=TwoRetinaPolygonAnnotationSets.polygonset1
        ).data
        image = ImageFactory()
        model_serialized["image"] = str(image.id)
        model_serialized["singlepolygonannotation_set"] = []
        model_json = json.dumps(model_serialized)

        response = view_test(
            "partial_update",
            user_type,
            self.namespace,
            self.basename,
            TwoRetinaPolygonAnnotationSets.grader1,
            TwoRetinaPolygonAnnotationSets.polygonset1,
            rf,
            PolygonAnnotationSetViewSet,
            model_json,
        )

        if user_type in ("retina_grader", "retina_admin"):
            response.data["image"] = str(response.data["image"])
            response.data["singlepolygonannotation_set"] = []
            assert response.data == model_serialized
예제 #8
0
    def test_create_view_wrong_user_id(
        self, TwoRetinaPolygonAnnotationSets, rf, user_type
    ):
        model_build = PolygonAnnotationSetFactory.build()
        model_serialized = PolygonAnnotationSetSerializer(model_build).data
        image = ImageFactory()
        model_serialized["image"] = str(image.id)
        other_user = UserFactory()
        model_serialized["grader"] = other_user.id
        model_json = json.dumps(model_serialized)

        response = view_test(
            "create",
            user_type,
            self.namespace,
            self.basename,
            TwoRetinaPolygonAnnotationSets.grader1,
            TwoRetinaPolygonAnnotationSets.polygonset1,
            rf,
            PolygonAnnotationSetViewSet,
            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
예제 #9
0
    def test_partial_update_view(
        self, TwoRetinaPolygonAnnotationSets, rf, user_type
    ):
        model_serialized = SinglePolygonAnnotationSerializer(
            TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first()
        ).data
        annotation_set = SinglePolygonAnnotationFactory()
        model_serialized["value"] = annotation_set.value
        partial_model = copy.deepcopy(model_serialized)
        del partial_model["annotation_set"]
        del partial_model["id"]
        model_json = json.dumps(partial_model)

        response = view_test(
            "partial_update",
            user_type,
            self.namespace,
            self.basename,
            TwoRetinaPolygonAnnotationSets.grader1,
            TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first(),
            rf,
            SinglePolygonViewSet,
            model_json,
        )

        if user_type in ("retina_grader", "retina_admin"):
            assert response.data == model_serialized
예제 #10
0
    def test_update_view_wrong_user_id(
        self, MultipleRetinaETDRSAnnotations, rf, user_type
    ):
        model_serialized = ETDRSGridAnnotationSerializer(
            MultipleRetinaETDRSAnnotations.etdrss1[0]
        ).data
        other_user = UserFactory()
        model_serialized["grader"] = other_user.id
        model_serialized["image"] = str(model_serialized["image"])
        model_json = json.dumps(model_serialized)

        response = view_test(
            "update",
            user_type,
            self.namespace,
            self.basename,
            MultipleRetinaETDRSAnnotations.grader1,
            MultipleRetinaETDRSAnnotations.etdrss1[0],
            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
예제 #11
0
 def test_list_view(self, MultipleRetinaETDRSAnnotations, rf, user_type):
     response = view_test(
         "list",
         user_type,
         self.namespace,
         self.basename,
         MultipleRetinaETDRSAnnotations.grader1,
         None,
         rf,
         ETDRSGridAnnotationViewSet,
     )
     if user_type == "retina_grader":
         serialized_data = ETDRSGridAnnotationSerializer(
             MultipleRetinaETDRSAnnotations.etdrss1, many=True
         ).data
         assert len(response.data) == len(serialized_data)
         serialized_data.sort(key=lambda k: k["created"], reverse=True)
         assert response.data == serialized_data
     elif user_type == "retina_admin":
         serialized_data = ETDRSGridAnnotationSerializer(
             [
                 *MultipleRetinaETDRSAnnotations.etdrss1,
                 *MultipleRetinaETDRSAnnotations.etdrss2,
             ],
             many=True,
         ).data
         serialized_data.sort(key=lambda k: k["created"], reverse=True)
         assert len(response.data) == len(serialized_data)
         assert response.data == serialized_data
예제 #12
0
    def test_create_view_wrong_user_id(
        self, TwoRetinaPolygonAnnotationSets, rf, user_type
    ):
        model_build = PolygonAnnotationSetFactory.build()
        model_serialized = PolygonAnnotationSetSerializer(model_build).data
        image = ImageFactory()
        model_serialized["image"] = str(image.id)
        other_user = UserFactory()
        model_serialized["grader"] = other_user.id
        model_json = json.dumps(model_serialized)

        response = view_test(
            "create",
            user_type,
            self.namespace,
            self.basename,
            TwoRetinaPolygonAnnotationSets.grader1,
            TwoRetinaPolygonAnnotationSets.polygonset1,
            rf,
            PolygonAnnotationSetViewSet,
            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
예제 #13
0
    def test_create_view_wrong_user_id(
        self, TwoRetinaPolygonAnnotationSets, rf, user_type
    ):
        model_build = SinglePolygonAnnotationFactory.build()
        model_serialized = SinglePolygonAnnotationSerializer(model_build).data
        other_user = UserFactory()
        annotation_set = PolygonAnnotationSetFactory(grader=other_user)
        model_serialized["annotation_set"] = str(annotation_set.id)
        model_json = json.dumps(model_serialized)

        response = view_test(
            "create",
            user_type,
            self.namespace,
            self.basename,
            TwoRetinaPolygonAnnotationSets.grader1,
            None,
            rf,
            SinglePolygonViewSet,
            model_json,
            check_response_status_code=False,
        )
        if user_type == "retina_admin":
            assert response.data["value"] == model_serialized["value"]
        elif user_type == "retina_grader":
            assert response.status_code == status.HTTP_400_BAD_REQUEST
            assert (
                str(response.data["non_field_errors"][0])
                == "User is not allowed to create annotation for other grader"
            )
        else:
            assert response.status_code == status.HTTP_403_FORBIDDEN
예제 #14
0
 def test_list_view(self, TwoRetinaPolygonAnnotationSets, rf, user_type):
     response = view_test(
         "list",
         user_type,
         self.namespace,
         self.basename,
         TwoRetinaPolygonAnnotationSets.grader1,
         None,
         rf,
         SinglePolygonViewSet,
     )
     if user_type == "retina_grader":
         serialized_data = SinglePolygonAnnotationSerializer(
             TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.all(),
             many=True,
         ).data
         assert len(response.data) == len(serialized_data)
         serialized_data.sort(key=lambda k: k["created"], reverse=True)
         assert response.data == serialized_data
     elif user_type == "retina_admin":
         serialized_data = SinglePolygonAnnotationSerializer(
             TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.all()
             | TwoRetinaPolygonAnnotationSets.polygonset2.singlepolygonannotation_set.all(),
             many=True,
         ).data
         serialized_data.sort(key=lambda k: k["created"], reverse=True)
         assert response.data == serialized_data
예제 #15
0
    def test_partial_update_view(
        self, MultipleRetinaETDRSAnnotations, rf, user_type
    ):
        model_serialized = ETDRSGridAnnotationSerializer(
            MultipleRetinaETDRSAnnotations.etdrss1[0]
        ).data
        partial_model = copy.deepcopy(model_serialized)
        del partial_model["image"]
        del partial_model["id"]
        del partial_model["grader"]
        del partial_model["optic_disk"]
        model_json = json.dumps(partial_model)

        response = view_test(
            "partial_update",
            user_type,
            self.namespace,
            self.basename,
            MultipleRetinaETDRSAnnotations.grader1,
            MultipleRetinaETDRSAnnotations.etdrss1[0],
            rf,
            ETDRSGridAnnotationViewSet,
            model_json,
        )

        if user_type in ("retina_grader", "retina_admin"):
            assert response.data == model_serialized
예제 #16
0
 def test_list_view(self, TwoRetinaPolygonAnnotationSets, rf, user_type):
     response = view_test(
         "list",
         user_type,
         self.namespace,
         self.basename,
         TwoRetinaPolygonAnnotationSets.grader1,
         TwoRetinaPolygonAnnotationSets.polygonset1,
         rf,
         PolygonAnnotationSetViewSet,
     )
     if user_type == "retina_grader":
         serialized_data = PolygonAnnotationSetSerializer(
             TwoRetinaPolygonAnnotationSets.polygonset1
         ).data
         assert response.data == [serialized_data]
     if user_type == "retina_admin":
         serialized_data = PolygonAnnotationSetSerializer(
             [
                 TwoRetinaPolygonAnnotationSets.polygonset1,
                 TwoRetinaPolygonAnnotationSets.polygonset2,
             ],
             many=True,
         ).data
         serialized_data_sorted = sorted(
             serialized_data, key=lambda k: k["created"], reverse=True
         )
         assert response.data == serialized_data_sorted
예제 #17
0
    def test_update_view(self, TwoRetinaPolygonAnnotationSets, rf, user_type):
        model_serialized = SinglePolygonAnnotationSerializer(
            TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first()
        ).data
        annotation_set = PolygonAnnotationSetFactory(
            grader=TwoRetinaPolygonAnnotationSets.grader1
        )
        model_serialized["annotation_set"] = str(annotation_set.id)
        model_json = json.dumps(model_serialized)

        response = view_test(
            "update",
            user_type,
            self.namespace,
            self.basename,
            TwoRetinaPolygonAnnotationSets.grader1,
            TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first(),
            rf,
            SinglePolygonViewSet,
            model_json,
        )

        if user_type in ("retina_grader", "retina_admin"):
            response.data["annotation_set"] = str(
                response.data["annotation_set"]
            )
            assert response.data == model_serialized
예제 #18
0
    def test_partial_update_view(
        self, TwoRetinaPolygonAnnotationSets, rf, user_type
    ):
        model_serialized = SinglePolygonAnnotationSerializer(
            TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first()
        ).data
        annotation_set = SinglePolygonAnnotationFactory()
        model_serialized["value"] = annotation_set.value
        partial_model = copy.deepcopy(model_serialized)
        del partial_model["annotation_set"]
        del partial_model["id"]
        model_json = json.dumps(partial_model)

        response = view_test(
            "partial_update",
            user_type,
            self.namespace,
            self.basename,
            TwoRetinaPolygonAnnotationSets.grader1,
            TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first(),
            rf,
            SinglePolygonViewSet,
            model_json,
        )

        if user_type in ("retina_grader", "retina_admin"):
            assert response.data == model_serialized
예제 #19
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
예제 #20
0
    def test_partial_update_view(
        self, TwoRetinaPolygonAnnotationSets, rf, user_type
    ):
        model_serialized = PolygonAnnotationSetSerializer(
            instance=TwoRetinaPolygonAnnotationSets.polygonset1
        ).data
        image = ImageFactory()
        model_serialized["image"] = str(image.id)
        model_serialized["singlepolygonannotation_set"] = []
        model_json = json.dumps(model_serialized)

        response = view_test(
            "partial_update",
            user_type,
            self.namespace,
            self.basename,
            TwoRetinaPolygonAnnotationSets.grader1,
            TwoRetinaPolygonAnnotationSets.polygonset1,
            rf,
            PolygonAnnotationSetViewSet,
            model_json,
        )

        if user_type in ("retina_grader", "retina_admin"):
            response.data["image"] = str(response.data["image"])
            response.data["singlepolygonannotation_set"] = []
            assert response.data == model_serialized
예제 #21
0
 def test_list_view(self, TwoRetinaPolygonAnnotationSets, rf, user_type):
     response = view_test(
         "list",
         user_type,
         self.namespace,
         self.basename,
         TwoRetinaPolygonAnnotationSets.grader1,
         TwoRetinaPolygonAnnotationSets.polygonset1,
         rf,
         PolygonAnnotationSetViewSet,
     )
     if user_type in ("retina_grader", "retina_admin"):
         serialized_data = PolygonAnnotationSetSerializer(
             TwoRetinaPolygonAnnotationSets.polygonset1
         ).data
         assert response.data[0] == serialized_data
예제 #22
0
 def test_retrieve_view(
     self, TwoRetinaPolygonAnnotationSets, rf, user_type
 ):
     response = view_test(
         "retrieve",
         user_type,
         self.namespace,
         self.basename,
         TwoRetinaPolygonAnnotationSets.grader1,
         TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first(),
         rf,
         SinglePolygonViewSet,
     )
     if user_type == "retina_grader" or user_type == "retina_admin":
         model_serialized = SinglePolygonAnnotationSerializer(
             TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first()
         ).data
         assert response.data == model_serialized
예제 #23
0
 def test_retrieve_view(
     self, MultipleRetinaETDRSAnnotations, rf, user_type
 ):
     response = view_test(
         "retrieve",
         user_type,
         self.namespace,
         self.basename,
         MultipleRetinaETDRSAnnotations.grader1,
         MultipleRetinaETDRSAnnotations.etdrss1[0],
         rf,
         ETDRSGridAnnotationViewSet,
     )
     if user_type == "retina_grader" or user_type == "retina_admin":
         model_serialized = ETDRSGridAnnotationSerializer(
             MultipleRetinaETDRSAnnotations.etdrss1[0]
         ).data
         assert response.data == model_serialized
예제 #24
0
 def test_retrieve_view(
     self, TwoRetinaPolygonAnnotationSets, rf, user_type
 ):
     response = view_test(
         "retrieve",
         user_type,
         self.namespace,
         self.basename,
         TwoRetinaPolygonAnnotationSets.grader1,
         TwoRetinaPolygonAnnotationSets.polygonset1,
         rf,
         PolygonAnnotationSetViewSet,
     )
     if user_type == "retina_grader" or user_type == "retina_admin":
         model_serialized = PolygonAnnotationSetSerializer(
             instance=TwoRetinaPolygonAnnotationSets.polygonset1
         ).data
         assert response.data == model_serialized
예제 #25
0
 def test_retrieve_view(
     self, TwoRetinaPolygonAnnotationSets, rf, user_type
 ):
     response = view_test(
         "retrieve",
         user_type,
         self.namespace,
         self.basename,
         TwoRetinaPolygonAnnotationSets.grader1,
         TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first(),
         rf,
         SinglePolygonViewSet,
     )
     if user_type == "retina_grader" or user_type == "retina_admin":
         model_serialized = SinglePolygonAnnotationSerializer(
             TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first()
         ).data
         assert response.data == model_serialized
예제 #26
0
 def test_retrieve_view(
     self, TwoRetinaPolygonAnnotationSets, rf, user_type
 ):
     response = view_test(
         "retrieve",
         user_type,
         self.namespace,
         self.basename,
         TwoRetinaPolygonAnnotationSets.grader1,
         TwoRetinaPolygonAnnotationSets.polygonset1,
         rf,
         PolygonAnnotationSetViewSet,
     )
     if user_type == "retina_grader" or user_type == "retina_admin":
         model_serialized = PolygonAnnotationSetSerializer(
             instance=TwoRetinaPolygonAnnotationSets.polygonset1
         ).data
         assert response.data == model_serialized
예제 #27
0
 def test_destroy_view_wrong_user(
     self, TwoRetinaPolygonAnnotationSets, rf, user_type
 ):
     response = view_test(
         "destroy",
         user_type,
         self.namespace,
         self.basename,
         TwoRetinaPolygonAnnotationSets.grader2,
         TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first(),
         rf,
         SinglePolygonViewSet,
         check_response_status_code=False,
     )
     if user_type == "retina_admin":
         assert not PolygonAnnotationSet.objects.filter(
             id=TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first().id
         ).exists()
     elif user_type == "retina_grader":
         assert response.status_code == status.HTTP_404_NOT_FOUND
     else:
         assert response.status_code == status.HTTP_403_FORBIDDEN
예제 #28
0
 def test_destroy_view_wrong_user(
     self, MultipleRetinaETDRSAnnotations, rf, user_type
 ):
     response = view_test(
         "destroy",
         user_type,
         self.namespace,
         self.basename,
         MultipleRetinaETDRSAnnotations.grader2,
         MultipleRetinaETDRSAnnotations.etdrss1[0],
         rf,
         ETDRSGridAnnotationViewSet,
         check_response_status_code=False,
     )
     if user_type == "retina_admin":
         assert not ETDRSGridAnnotation.objects.filter(
             id=MultipleRetinaETDRSAnnotations.etdrss1[0].id
         ).exists()
     elif user_type == "retina_grader":
         assert response.status_code == status.HTTP_404_NOT_FOUND
     else:
         assert response.status_code == status.HTTP_403_FORBIDDEN
예제 #29
0
    def test_create_view(self, TwoRetinaPolygonAnnotationSets, rf, user_type):
        model_build = SinglePolygonAnnotationFactory.build()
        model_serialized = SinglePolygonAnnotationSerializer(model_build).data
        annotation_set = PolygonAnnotationSetFactory(
            grader=TwoRetinaPolygonAnnotationSets.grader1
        )
        model_serialized["annotation_set"] = str(annotation_set.id)
        model_json = json.dumps(model_serialized)

        response = view_test(
            "create",
            user_type,
            self.namespace,
            self.basename,
            TwoRetinaPolygonAnnotationSets.grader1,
            None,
            rf,
            SinglePolygonViewSet,
            model_json,
        )
        if user_type in ("retina_grader", "retina_admin"):
            assert response.data["value"] == model_serialized["value"]
예제 #30
0
 def test_destroy_view_wrong_user(
     self, TwoRetinaPolygonAnnotationSets, rf, user_type
 ):
     response = view_test(
         "destroy",
         user_type,
         self.namespace,
         self.basename,
         TwoRetinaPolygonAnnotationSets.grader2,
         TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first(),
         rf,
         SinglePolygonViewSet,
         check_response_status_code=False,
     )
     if user_type == "retina_admin":
         assert not PolygonAnnotationSet.objects.filter(
             id=TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first().id
         ).exists()
     elif user_type == "retina_grader":
         assert response.status_code == status.HTTP_404_NOT_FOUND
     else:
         assert response.status_code == status.HTTP_403_FORBIDDEN
예제 #31
0
    def test_update_view(self, MultipleRetinaETDRSAnnotations, rf, user_type):
        model_serialized = ETDRSGridAnnotationSerializer(
            MultipleRetinaETDRSAnnotations.etdrss1[0]
        ).data
        model_serialized["image"] = str(model_serialized["image"])
        model_serialized["fovea"] = [123, 456]
        model_json = json.dumps(model_serialized)

        response = view_test(
            "update",
            user_type,
            self.namespace,
            self.basename,
            MultipleRetinaETDRSAnnotations.grader1,
            MultipleRetinaETDRSAnnotations.etdrss1[0],
            rf,
            ETDRSGridAnnotationViewSet,
            model_json,
        )

        if user_type in ("retina_grader", "retina_admin"):
            response.data["image"] = str(response.data["image"])
            assert response.data == model_serialized
예제 #32
0
    def test_create_view(self, TwoRetinaPolygonAnnotationSets, rf, user_type):
        model_build = PolygonAnnotationSetFactory.build()
        model_serialized = PolygonAnnotationSetSerializer(model_build).data
        image = ImageFactory()
        model_serialized["image"] = str(image.id)
        model_serialized["grader"] = TwoRetinaPolygonAnnotationSets.grader1.id
        model_json = json.dumps(model_serialized)

        response = view_test(
            "create",
            user_type,
            self.namespace,
            self.basename,
            TwoRetinaPolygonAnnotationSets.grader1,
            TwoRetinaPolygonAnnotationSets.polygonset1,
            rf,
            PolygonAnnotationSetViewSet,
            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
예제 #33
0
    def test_create_view(self, TwoRetinaPolygonAnnotationSets, rf, user_type):
        model_build = PolygonAnnotationSetFactory.build()
        model_serialized = PolygonAnnotationSetSerializer(model_build).data
        image = ImageFactory()
        model_serialized["image"] = str(image.id)
        model_serialized["grader"] = TwoRetinaPolygonAnnotationSets.grader1.id
        model_json = json.dumps(model_serialized)

        response = view_test(
            "create",
            user_type,
            self.namespace,
            self.basename,
            TwoRetinaPolygonAnnotationSets.grader1,
            TwoRetinaPolygonAnnotationSets.polygonset1,
            rf,
            PolygonAnnotationSetViewSet,
            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
예제 #34
0
    def test_update_view_wrong_user_id(
        self, TwoRetinaPolygonAnnotationSets, rf, user_type
    ):
        model_serialized = SinglePolygonAnnotationSerializer(
            TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first()
        ).data
        annotation_set = PolygonAnnotationSetFactory()
        model_serialized["annotation_set"] = str(annotation_set.id)
        model_json = json.dumps(model_serialized)

        response = view_test(
            "update",
            user_type,
            self.namespace,
            self.basename,
            TwoRetinaPolygonAnnotationSets.grader1,
            TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first(),
            rf,
            SinglePolygonViewSet,
            model_json,
            check_response_status_code=False,
        )
        if user_type == "retina_admin":
            model_serialized["id"] = response.data["id"]
            response.data["annotation_set"] = str(
                response.data["annotation_set"]
            )
            assert response.data == model_serialized
        elif user_type == "retina_grader":
            assert response.status_code == status.HTTP_400_BAD_REQUEST
            assert (
                str(response.data["non_field_errors"][0])
                == "User is not allowed to create annotation for other grader"
            )
        else:
            assert response.status_code == status.HTTP_403_FORBIDDEN
예제 #35
0
    def test_update_view_wrong_user_id(
        self, TwoRetinaPolygonAnnotationSets, rf, user_type
    ):
        model_serialized = SinglePolygonAnnotationSerializer(
            TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first()
        ).data
        annotation_set = PolygonAnnotationSetFactory()
        model_serialized["annotation_set"] = str(annotation_set.id)
        model_json = json.dumps(model_serialized)

        response = view_test(
            "update",
            user_type,
            self.namespace,
            self.basename,
            TwoRetinaPolygonAnnotationSets.grader1,
            TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first(),
            rf,
            SinglePolygonViewSet,
            model_json,
            check_response_status_code=False,
        )
        if user_type == "retina_admin":
            model_serialized["id"] = response.data["id"]
            response.data["annotation_set"] = str(
                response.data["annotation_set"]
            )
            assert response.data == model_serialized
        elif user_type == "retina_grader":
            assert response.status_code == status.HTTP_400_BAD_REQUEST
            assert (
                str(response.data["non_field_errors"][0])
                == "User is not allowed to create annotation for other grader"
            )
        else:
            assert response.status_code == status.HTTP_403_FORBIDDEN