Beispiel #1
0
    def create_zaak(self, **kwargs):
        from openzaak.components.zaken.tests.factories import ZaakFactory
        from openzaak.tests.utils import mock_service_oas_get

        zaak = ZaakFactory.create(**kwargs)

        mock_service_oas_get(self.adapter, APITypes.zrc, self.base_zaak)
        mock_service_oas_get(self.adapter, APITypes.ztc, self.base_zaaktype)

        if kwargs.get("zaaktype") is not None and isinstance(
                kwargs.get("zaaktype"), str):
            zaaktype_url = kwargs.get("zaaktype")
            zaaktype_identificatie = zaaktype_url.split("/")[-1]
        else:
            zaaktype_url = make_absolute_uri(reverse(zaak.zaaktype))
            zaaktype_identificatie = zaak.zaaktype.identificatie

        self.adapter.get(
            make_absolute_uri(reverse(zaak)),
            json={
                "url": make_absolute_uri(reverse(zaak)),
                "identificatie": zaak.identificatie,
                "zaaktype": zaaktype_url,
            },
        )

        self.adapter.get(
            zaaktype_url,
            json={
                "url": zaaktype_url,
                "identificatie": zaaktype_identificatie,
                "omschrijving": "Melding Openbare Ruimte",
            },
        )
        return zaak
Beispiel #2
0
    def create_besluit(self, **kwargs):
        from openzaak.components.besluiten.tests.factories import BesluitFactory
        from openzaak.tests.utils import mock_service_oas_get

        zaak = self.create_zaak()
        besluit = BesluitFactory.create(zaak=zaak, **kwargs)
        mock_service_oas_get(self.adapter, APITypes.brc, self.base_besluit)
        self.adapter.get(
            make_absolute_uri(reverse(besluit)),
            json={"zaak": make_absolute_uri(reverse(zaak))},
        )

        return besluit
    def test_duplicate_object(self):
        """
        Test the (informatieobject, object) unique together validation.
        """
        io = EnkelvoudigInformatieObjectFactory.create()
        io_url = f"http://testserver{reverse(io)}"
        self.adapter.get(io_url, json=serialise_eio(io, io_url))

        self.create_zaak_besluit_services()
        besluit = self.create_besluit()
        BesluitInformatieObjectFactory.create(informatieobject=io_url,
                                              besluit=besluit)
        besluit_url = make_absolute_uri(reverse(besluit))

        content = {
            "informatieobject": io_url,
            "besluit": besluit_url,
        }

        # Send to the API
        response = self.client.post(self.list_url, content)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST,
                         response.data)

        error = get_validation_errors(response, "nonFieldErrors")
        self.assertEqual(error["code"], "unique")
    def test_read_with_objecttype_besluit(self):
        self.create_zaak_besluit_services()
        besluit = self.create_besluit()
        eio = EnkelvoudigInformatieObjectFactory.create()
        eio_path = reverse(eio)
        eio_url = f"http://testserver{eio_path}"
        # relate the two
        self.adapter.get(eio_url, json=serialise_eio(eio, eio_url))
        BesluitInformatieObjectFactory.create(besluit=besluit,
                                              informatieobject=eio_url)

        # get OIO created via signals
        oio = ObjectInformatieObject.objects.get()

        oio_url = reverse("objectinformatieobject-detail",
                          kwargs={"uuid": oio.uuid})
        besluit_url = reverse(besluit)

        response = self.client.get(oio_url)

        expeceted_response_data = {
            "url": f"http://testserver{oio_url}",
            "object": make_absolute_uri(besluit_url),
            "informatieobject": eio_url,
            "object_type": "besluit",
        }

        self.assertEqual(response.status_code, status.HTTP_200_OK,
                         response.data)
        self.assertEqual(response.data, expeceted_response_data)
    def test_create(self):
        self.create_zaak_besluit_services()
        besluit = self.create_besluit()

        io = EnkelvoudigInformatieObjectFactory.create(
            informatieobjecttype__concept=False)
        io_url = f"http://testserver{reverse(io)}"
        self.adapter.get(io_url, json=serialise_eio(io, io_url))

        besluit.besluittype.informatieobjecttypen.add(io.informatieobjecttype)
        besluit_url = make_absolute_uri(reverse(besluit))
        content = {
            "informatieobject": io_url,
            "besluit": besluit_url,
        }

        # Send to the API
        response = self.client.post(self.list_url, content)

        # Test response
        self.assertEqual(response.status_code, status.HTTP_201_CREATED,
                         response.data)

        # Test database
        self.assertEqual(BesluitInformatieObject.objects.count(), 1)
        stored_object = BesluitInformatieObject.objects.get()
        self.assertEqual(stored_object.besluit, besluit)

        expected_url = reverse(stored_object)

        expected_response = content.copy()
        expected_response.update({"url": f"http://testserver{expected_url}"})
        self.assertEqual(response.json(), expected_response)
    def test_create_no_url_mapping(self):
        self.create_zaak_besluit_services()
        besluit = self.create_besluit()

        io = EnkelvoudigInformatieObjectFactory.create(
            informatieobjecttype__concept=False)
        io_url = f"http://testserver{reverse(io)}"
        self.adapter.get(io_url, json=serialise_eio(io, io_url))

        besluit.besluittype.informatieobjecttypen.add(io.informatieobjecttype)
        besluit_url = make_absolute_uri(reverse(besluit))
        content = {
            "informatieobject": io_url,
            "besluit": besluit_url,
        }

        # Remove all available mappings
        UrlMapping.objects.all().delete()

        # Send to the API
        response = self.client.post(
            reverse("besluitinformatieobject-list", kwargs={"version": "1"}),
            content)

        # Test response
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST,
                         response.data)
        self.assertEqual(
            response.data["detail"],
            "CMIS-adapter could not shrink one of the URL fields.",
        )
Beispiel #7
0
 def get_url(self):
     oio_path = reverse(
         "objectinformatieobject-detail",
         kwargs={
             "version": "1",
             "uuid": self.uuid
         },
     )
     return make_absolute_uri(oio_path)
Beispiel #8
0
 def create_from(self, relation):
     object_type = self.RELATIONS[type(relation)]
     relation_object = getattr(relation, object_type)
     data = {
         "informatieobject": relation._informatieobject_url,
         "object_type": f"{object_type}",
         f"{object_type}": make_absolute_uri(reverse(relation_object)),
     }
     return self.create(**data)
Beispiel #9
0
 def to_representation(self, instance):
     ret = super().to_representation(instance)
     # With Alfresco, the URL of the Gebruiksrechten and EnkelvoudigInformatieObject
     # cannot be retrieved using the latest_version property of the canonical object
     if settings.CMIS_ENABLED:
         path = reverse(
             "gebruiksrechten-detail", kwargs={"version": 1, "uuid": instance.uuid}
         )
         ret["url"] = make_absolute_uri(path, request=self.context.get("request"))
         ret["informatieobject"] = instance.get_informatieobject_url()
     return ret
Beispiel #10
0
    def _mock_zaak(self):
        mock_service_oas_get(self.adapter, APITypes.zrc, self.base_zaak)
        mock_service_oas_get(self.adapter, APITypes.ztc, self.base_zaaktype)

        self.adapter.get(
            make_absolute_uri(reverse(self.zaak)),
            json={
                "url": make_absolute_uri(reverse(self.zaak)),
                "identificatie": self.zaak.identificatie,
                "zaaktype": make_absolute_uri(reverse(self.zaak.zaaktype)),
            },
        )

        self.adapter.get(
            make_absolute_uri(reverse(self.zaak.zaaktype)),
            json={
                "url": make_absolute_uri(reverse(self.zaak.zaaktype)),
                "identificatie": self.zaak.zaaktype.identificatie,
                "omschrijving": "Melding Openbare Ruimte",
            },
        )
Beispiel #11
0
 def to_representation(self, instance):
     ret = super().to_representation(instance)
     # With Alfresco, the URL cannot be retrieved using the
     # latest_version property of the canonical object
     if settings.CMIS_ENABLED:
         path = reverse(
             "enkelvoudiginformatieobject-detail",
             kwargs={"version": "1", "uuid": instance.uuid},
         )
         # Following what is done in drc_cmis/client/convert.py
         ret["url"] = make_absolute_uri(path, request=self.context.get("request"))
     return ret
Beispiel #12
0
    def process_filters(self, data):

        converted_data = {}

        if data.get("object_type"):
            object_type = data.pop("object_type")
            if data.get(object_type):
                relation_object = data.pop(object_type)
            else:
                relation_object = data.pop("object")
            relation_url = get_object_url(relation_object)
            if relation_url is None:
                relation_url = make_absolute_uri(reverse(relation_object))
            converted_data["object_type"] = object_type
            converted_data[f"{object_type}"] = relation_url

        for key, value in data.items():
            split_key = key.split("__")
            split_key[0] = split_key[0].strip("_")
            if len(split_key) > 1 and split_key[1] not in ["exact", "in"]:
                raise NotImplementedError(
                    "Fields lookups other than exact are not implemented yet.")

            # If the value is a queryset, extract the objects
            if split_key[0] == "informatieobject" and isinstance(
                    value, CMISQuerySet):
                list_value = []
                for item in value:
                    list_value.append(make_absolute_uri(reverse(item)))
                value = list_value

            if split_key[0] in ["besluit", "zaak"]:
                converted_data[split_key[0]] = make_absolute_uri(
                    reverse(value))
            elif split_key[0] in ["besluit_url", "zaak_url"]:
                converted_data[split_key[0].split("_")[0]] = value
            else:
                converted_data[split_key[0]] = value

        return converted_data
Beispiel #13
0
    def to_representation(self, instance):
        object_type = instance.object_type
        self.set_object_properties(object_type)
        ret = super().to_representation(instance)
        if settings.CMIS_ENABLED:
            # Objects without a primary key will have 'None' as the URL, so it is added manually
            path = reverse(
                "objectinformatieobject-detail",
                kwargs={"version": 1, "uuid": instance.uuid},
            )
            ret["url"] = make_absolute_uri(path, request=self.context.get("request"))
            ret["informatieobject"] = instance.get_informatieobject_url()

        return ret
Beispiel #14
0
def get_object_url(informatie_obj_type: InformatieObjectType,
                   request: Optional[Request] = None):
    """
    Retrieves the url for the informatieobjecttypes and virtual informatieobjecttype (used for external
    informatieobjecttype).
    """
    # Case in which the informatie_object_type is already a url
    if isinstance(informatie_obj_type, str):
        return informatie_obj_type
    elif isinstance(informatie_obj_type, ProxyMixin):
        return informatie_obj_type._initial_data["url"]
    elif isinstance(informatie_obj_type, InformatieObjectType):
        path = informatie_obj_type.get_absolute_api_url()
        return make_absolute_uri(path, request=request)
Beispiel #15
0
    def test_create_bio_limited_to_authorized_besluiten(self):
        informatieobject = EnkelvoudigInformatieObjectFactory.create(
            informatieobjecttype__concept=False
        )
        informatieobject_url = f"http://testserver{reverse(informatieobject)}"
        self.adapter.get(
            informatieobject_url,
            json=serialise_eio(informatieobject, informatieobject_url),
        )

        self.create_zaak_besluit_services()
        besluit1 = self.create_besluit(**{"besluittype": self.besluittype})
        besluit2 = self.create_besluit()

        self.besluittype.informatieobjecttypen.add(
            informatieobject.informatieobjecttype
        )
        besluit2.besluittype.informatieobjecttypen.add(
            informatieobject.informatieobjecttype
        )

        besluit_url1 = make_absolute_uri(reverse(besluit1))
        besluit_url2 = make_absolute_uri(reverse(besluit2))

        url1 = reverse("besluitinformatieobject-list")
        url2 = reverse("besluitinformatieobject-list")

        data1 = {"informatieobject": informatieobject_url, "besluit": besluit_url1}
        data2 = {"informatieobject": informatieobject_url, "besluit": besluit_url2}

        response1 = self.client.post(url1, data1)
        response2 = self.client.post(url2, data2)

        self.assertEqual(response1.status_code, status.HTTP_201_CREATED, response1.data)
        self.assertEqual(
            response2.status_code, status.HTTP_403_FORBIDDEN, response2.data
        )
Beispiel #16
0
    def create_besluit_without_zaak(self, **kwargs):
        from openzaak.components.besluiten.tests.factories import BesluitFactory
        from openzaak.tests.utils import mock_service_oas_get

        besluit = BesluitFactory.create(**kwargs)
        mock_service_oas_get(self.adapter, APITypes.brc, self.base_besluit)
        self.adapter.get(
            make_absolute_uri(reverse(besluit)),
            json={
                "verantwoordelijke_organisatie": "517439943",
                "identificatie": "123123",
                "besluittype": "http://testserver/besluittype/some-random-id",
                "datum": "2018-09-06",
                "toelichting": "Vergunning verleend.",
                "ingangsdatum": "2018-10-01",
                "vervaldatum": "2018-11-01",
            },
        )

        return besluit
Beispiel #17
0
    def process_filters(self, data):

        converted_data = {}

        for key, value in data.items():
            split_key = key.split("__")
            split_key[0] = split_key[0].strip("_")
            if len(split_key) > 1 and split_key[1] not in ["exact", "in"]:
                raise NotImplementedError(f"Filter on '{key}' is not implemented yet")

            # If the value is a queryset, extract the objects
            if split_key[0] == "informatieobject" and isinstance(value, CMISQuerySet):
                list_value = []
                for item in value:
                    list_value.append(make_absolute_uri(reverse(item)))
                value = list_value

            converted_data[split_key[0]] = value

        return converted_data