Esempio n. 1
0
 def test_update_method_new_slas_get_added_existing_get_updated(self):
     annotation_set_dict, annotation_set_obj = self.save_annotation_set()
     old_slas = list(annotation_set_obj.singlelandmarkannotation_set.all())
     image3 = ImageFactory()
     new_slas = [
         {
             "image": image3.id,
             "landmarks": [[2, 2], [3, 3], [4, 4]]
         },
         {
             "image": old_slas[0].image.id,
             "landmarks": [[4, 4], [5, 5], [6, 6]],
         },
     ]
     updated_set = {
         **annotation_set_dict,
         "singlelandmarkannotation_set": new_slas,
     }
     serializer = LandmarkAnnotationSetSerializer(annotation_set_obj,
                                                  data=updated_set)
     serializer.is_valid()
     saved_set = None
     try:
         saved_set = serializer.save()
     except Exception as e:
         pytest.fail(f"Saving serializer failed with error: {str(e)}")
     assert saved_set.singlelandmarkannotation_set.count() == 3
     assert saved_set.singlelandmarkannotation_set.filter(
         image=image3).exists()
     assert saved_set.singlelandmarkannotation_set.get(
         image__id=old_slas[0].image.id).landmarks == [[4.0,
                                                        4.0], [5.0, 5.0],
                                                       [6.0, 6.0]]
Esempio n. 2
0
 def test_create_method(self):
     annotation_set = self.create_annotation_set()
     serializer = LandmarkAnnotationSetSerializer(data=annotation_set)
     serializer.is_valid()
     assert serializer.errors == {}
     try:
         obj = serializer.save()
         assert obj.singlelandmarkannotation_set.count() == 2
     except Exception as e:
         pytest.fail(f"Saving serializer failed with error: {str(e)}")
Esempio n. 3
0
    def test_admin_authenticated(self):
        force_authenticate(self.request, user=self.retina_admin)
        response = self.view(self.request, **self.kwargs)

        expected_response = LandmarkAnnotationSetSerializer(
            [
                self.annotation_set.landmarkset1,
                self.annotation_set.landmarkset3,
            ],
            many=True,
        ).data
        expected_response.sort(key=lambda k: k["id"])

        assert response.status_code == status.HTTP_200_OK
        response.data.sort(key=lambda k: k["id"])
        assert response.data == expected_response
Esempio n. 4
0
    def test_admin_authenticated(self):
        force_authenticate(self.request, user=self.retina_admin)
        response = self.view(self.request, **self.kwargs)

        expected_response = LandmarkAnnotationSetSerializer(
            [
                self.annotation_set.landmarkset1,
                self.annotation_set.landmarkset3,
            ],
            many=True,
        ).data
        expected_response.sort(key=lambda k: k["id"])

        assert response.status_code == status.HTTP_200_OK
        response.data.sort(key=lambda k: k["id"])
        assert response.data == expected_response
Esempio n. 5
0
 def test_update_method_instance_fields_do_not_change(self):
     annotation_set_dict, annotation_set_obj = self.save_annotation_set()
     other_user = UserFactory()
     updated_set = {
         **annotation_set_dict,
         "id": annotation_set_obj.id,
         "grader": other_user.id,
     }
     serializer = LandmarkAnnotationSetSerializer(annotation_set_obj,
                                                  data=updated_set)
     serializer.is_valid()
     saved_set = None
     try:
         saved_set = serializer.save()
     except Exception as e:
         pytest.fail(f"Saving serializer failed with error: {str(e)}")
     assert saved_set.grader == annotation_set_obj.grader
Esempio n. 6
0
 def test_update_method_removes_empty_sla(self):
     annotation_set_dict, annotation_set_obj = self.save_annotation_set()
     old_slas = list(annotation_set_obj.singlelandmarkannotation_set.all())
     new_slas = [{"image": old_slas[0].image.id, "landmarks": []}]
     updated_set = {
         **annotation_set_dict,
         "singlelandmarkannotation_set": new_slas,
     }
     serializer = LandmarkAnnotationSetSerializer(annotation_set_obj,
                                                  data=updated_set)
     serializer.is_valid()
     saved_set = None
     try:
         saved_set = serializer.save()
     except Exception as e:
         pytest.fail(f"Saving serializer failed with error: {str(e)}")
     assert saved_set.singlelandmarkannotation_set.count() == 1
     assert not saved_set.singlelandmarkannotation_set.filter(
         image=old_slas[0].image.id).exists()
Esempio n. 7
0
 def test_serialization(self, multiple_landmark_annotation_sets):
     serialized_model = LandmarkAnnotationSetSerializer(
         instance=multiple_landmark_annotation_sets.landmarkset1)
     assert serialized_model.data.get("id") is not None
     assert serialized_model.data.get("created") is not None
     assert (serialized_model.data.get("grader") ==
             multiple_landmark_annotation_sets.grader1.id)
     assert (len(
         serialized_model.data.get("singlelandmarkannotation_set")) == 2)
     assert (
         serialized_model.data["singlelandmarkannotation_set"][0].get("id")
         is not None)
     assert (serialized_model.data["singlelandmarkannotation_set"][0].get(
         "image") is not None)
     assert (serialized_model.data["singlelandmarkannotation_set"][0].get(
         "landmarks") is not None)
     assert (len(serialized_model.data["singlelandmarkannotation_set"][0]
                 ["landmarks"]) > 0)
     assert (len(serialized_model.data["singlelandmarkannotation_set"][0]
                 ["landmarks"][0]) == 2)
Esempio n. 8
0
    def test_retina_grader_one_set(self):
        kwargs = {"user_id": self.annotation_set.landmarkset2.grader.id}
        url_no_params = reverse(
            "retina:api:landmark-annotation-images-list-view", kwargs=kwargs
        )
        url = "{}?image_ids={}".format(
            url_no_params, self.annotation_set.landmarkset2images[0].id
        )
        request = self.rf.get(url)
        force_authenticate(
            request, user=self.annotation_set.landmarkset2.grader
        )
        response = self.view(request, **kwargs)
        expected_response = [
            LandmarkAnnotationSetSerializer(
                instance=self.annotation_set.landmarkset2
            ).data
        ]

        assert response.status_code == status.HTTP_200_OK
        assert response.data == expected_response
Esempio n. 9
0
 def save_annotation_set(self):
     annotation_set_dict = self.create_annotation_set()
     serializer = LandmarkAnnotationSetSerializer(data=annotation_set_dict)
     serializer.is_valid()
     annotation_set_obj = serializer.save()
     return annotation_set_dict, annotation_set_obj