def generate_multiple_etdrs_annotations(retina_grader=False): graders = (UserFactory(), UserFactory()) if retina_grader: add_to_graders_group(graders) etdrss1 = ETDRSGridAnnotationFactory.create_batch(10, grader=graders[0]) etdrss2 = ETDRSGridAnnotationFactory.create_batch(5, grader=graders[1]) return MultipleETDRSAnnotations( grader1=graders[0], grader2=graders[1], etdrss1=etdrss1, etdrss2=etdrss2, )
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 generate_annotation_set(retina_grader=False): grader = UserFactory() if retina_grader: add_to_graders_group([grader]) measurement = MeasurementAnnotationFactory(grader=grader) boolean = BooleanClassificationAnnotationFactory(grader=grader) integer = IntegerClassificationAnnotationFactory(grader=grader) polygon = PolygonAnnotationSetFactory(grader=grader) coordinatelist = CoordinateListAnnotationFactory(grader=grader) landmark = LandmarkAnnotationSetFactory(grader=grader) etdrs = ETDRSGridAnnotationFactory(grader=grader) # Create child models for polygon annotation set SinglePolygonAnnotationFactory.create_batch(10, annotation_set=polygon) # Create child models for landmark annotation set (3 per image) for i in range(5): image = ImageFactory() SingleLandmarkAnnotationFactory(annotation_set=landmark, image=image) return AnnotationSet( grader=grader, measurement=measurement, boolean=boolean, polygon=polygon, coordinatelist=coordinatelist, landmark=landmark, etdrs=etdrs, integer=integer, )
def test_default_model_str(self): etdrs = ETDRSGridAnnotationFactory() assert str(etdrs) == "<{} by {} on {} for {}>".format( etdrs.__class__.__name__, etdrs.grader.username, etdrs.created.strftime("%Y-%m-%d at %H:%M:%S"), etdrs.image, )
def generate_annotation_set(retina_grader=False, image=False): grader = UserFactory() if retina_grader: add_to_graders_group([grader]) create_options = {"grader": grader} if image: create_options_with_image = {"image": image, **create_options} else: create_options_with_image = create_options measurement = MeasurementAnnotationFactory(**create_options_with_image) boolean = BooleanClassificationAnnotationFactory( **create_options_with_image ) integer = IntegerClassificationAnnotationFactory( **create_options_with_image ) polygon = PolygonAnnotationSetFactory(**create_options_with_image) coordinatelist = CoordinateListAnnotationFactory( **create_options_with_image ) etdrs = ETDRSGridAnnotationFactory(**create_options_with_image) landmark = LandmarkAnnotationSetFactory(**create_options) # Create child models for polygon annotation set SinglePolygonAnnotationFactory.create_batch(10, annotation_set=polygon) # Create child models for landmark annotation set (3 per image) single_landmarks = [] for i in range(5): if i > 0 or not image: image = ImageFactory() single_landmarks.append( SingleLandmarkAnnotationFactory( annotation_set=landmark, image=image ) ) return AnnotationSet( grader=grader, measurement=measurement, boolean=boolean, polygon=polygon, coordinatelist=coordinatelist, landmark=landmark, singlelandmarks=single_landmarks, etdrs=etdrs, integer=integer, )
def create_load_data(data_type, ds, grader): if data_type == "Registration": model = LandmarkAnnotationSetFactory(grader=grader) SingleLandmarkAnnotationFactory( annotation_set=model, image=ds["image_cf"] ), if ds["archive"].name == "Australia": # Australia does not allow obs images so create a new cf image for Australia test img = ImageFactory(study=ds["study"]) SingleLandmarkAnnotationFactory(annotation_set=model, image=img) else: SingleLandmarkAnnotationFactory( annotation_set=model, image=ds["image_obs"] ), elif data_type == "ETDRS": model = ETDRSGridAnnotationFactory(grader=grader, image=ds["image_cf"]) elif data_type == "GA" or data_type == "kappa": model_macualar = PolygonAnnotationSetFactory( grader=grader, image=ds["image_cf"], name="macular" ) SinglePolygonAnnotationFactory(annotation_set=model_macualar) SinglePolygonAnnotationFactory(annotation_set=model_macualar) SinglePolygonAnnotationFactory(annotation_set=model_macualar) model_peripapillary = PolygonAnnotationSetFactory( grader=grader, image=ds["image_cf"], name="peripapillary" ) SinglePolygonAnnotationFactory(annotation_set=model_peripapillary) SinglePolygonAnnotationFactory(annotation_set=model_peripapillary) SinglePolygonAnnotationFactory(annotation_set=model_peripapillary) model = [model_macualar, model_peripapillary] elif data_type == "Measure": model = [ MeasurementAnnotationFactory(grader=grader, image=ds["image_cf"]), MeasurementAnnotationFactory(grader=grader, image=ds["image_cf"]), MeasurementAnnotationFactory(grader=grader, image=ds["image_cf"]), ] elif data_type == "Fovea": model = BooleanClassificationAnnotationFactory( grader=grader, image=ds["image_cf"], name="fovea_affected" ) return model
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