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()
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()
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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"]
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
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
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