Пример #1
0
def test_image_file_cleanup():
    filename = f"{uuid.uuid4()}.zraw"

    i = ImageFactory()
    f = ImageFileFactory(image=i)
    f.file.save(filename, File(get_temporary_image()))

    storage = f.file.storage
    filepath = f.file.name

    assert storage.exists(name=filepath)

    i.delete()

    assert not storage.exists(name=filepath)
Пример #2
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
Пример #3
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
Пример #4
0
 def images(self, create, extracted, **kwargs):
     # See https://factoryboy.readthedocs.io/en/latest/recipes.html#simple-many-to-many-relationship
     if not create:
         return
     if extracted:
         for image in extracted:
             self.images.add(image)
     if create and not extracted:
         self.images.add(ImageFactory())
Пример #5
0
    def test_retina_user_no_registration(self):
        image = ImageFactory()
        kwargs = {"image_id": image.id}
        url = reverse(
            "retina:api:octobs-registration-detail-view", kwargs=kwargs
        )
        request = self.rf.get(url)
        force_authenticate(request, user=self.retina_user)
        response = self.view(request, **kwargs)

        assert response.status_code == status.HTTP_404_NOT_FOUND
Пример #6
0
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 get_response_status(client,
                        reverse_name,
                        data,
                        user="******",
                        annotation_data=None):
    auth_header = get_auth_token_header(user)
    url = reverse(reverse_name)

    if annotation_data:
        # create objects that need to exist in database before request is made
        patient = PatientFactory(name=data.get("patient_identifier"))
        existing_models = {"studies": [], "series": [], "images": []}
        images = []
        for data_row in data.get("data"):
            if (data_row.get("study_identifier")
                    not in existing_models["studies"]):
                study = StudyFactory(name=data_row.get("study_identifier"),
                                     patient=patient)
                existing_models["studies"].append(study.name)
            else:
                study = Study.objects.get(
                    name=data_row.get("study_identifier"))

            if (data_row.get("image_identifier")
                    not in existing_models["images"]):
                image = ImageFactory(name=data_row.get("image_identifier"),
                                     study=study)
                existing_models["images"].append(image.name)
                images.append(image)
        archive = ArchiveFactory(name=data.get("archive_identifier"),
                                 images=images)

        response = client.post(
            url,
            data=json.dumps(data),
            content_type="application/json",
            **auth_header,
        )
    else:
        response = client.post(url, data=data, **auth_header)
    return response.status_code
Пример #8
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
Пример #9
0
 def test_retina_image_str(self):
     model = ImageFactory()
     assert str(model) == f"Image {model.name} {model.shape_without_color}"